2 * Copyright (C) 2007-2011 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Low-level core for exclusive access to the AB5500 IC on the I2C bus
5 * and some basic chip-configuration.
6 * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
7 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
8 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
9 * Author: Rickard Andersson <rickard.andersson@stericsson.com>
10 * Author: Karl Komierowski <karl.komierowski@stericsson.com>
11 * Author: Bibek Basu <bibek.basu@stericsson.com>
13 * TODO: Event handling with irq_chip. Waiting for PRCMU fw support.
16 #include <linux/module.h>
17 #include <linux/mutex.h>
18 #include <linux/err.h>
19 #include <linux/platform_device.h>
20 #include <linux/slab.h>
21 #include <linux/device.h>
22 #include <linux/irq.h>
23 #include <linux/interrupt.h>
24 #include <linux/random.h>
25 #include <linux/mfd/abx500.h>
26 #include <linux/mfd/abx500/ab5500.h>
27 #include <linux/list.h>
28 #include <linux/bitops.h>
29 #include <linux/spinlock.h>
30 #include <linux/mfd/core.h>
31 #include <linux/version.h>
32 #include <linux/mfd/db5500-prcmu.h>
34 #include "ab5500-core.h"
35 #include "ab5500-debugfs.h"
37 #define AB5500_NUM_EVENT_REG 23
38 #define AB5500_IT_LATCH0_REG 0x40
39 #define AB5500_IT_MASK0_REG 0x60
42 * Permissible register ranges for reading and writing per device and bank.
44 * The ranges must be listed in increasing address order, and no overlaps are
45 * allowed. It is assumed that write permission implies read permission
46 * (i.e. only RO and RW permissions should be used). Ranges with write
47 * permission must not be split up.
50 #define NO_RANGE {.count = 0, .range = NULL,}
51 static struct ab5500_i2c_banks ab5500_bank_ranges
[AB5500_NUM_DEVICES
] = {
52 [AB5500_DEVID_USB
] = {
54 .bank
= (struct ab5500_i2c_ranges
[]) {
56 .bankid
= AB5500_BANK_USB
,
58 .range
= (struct ab5500_reg_range
[]) {
62 .perm
= AB5500_PERM_RW
,
67 .perm
= AB5500_PERM_RW
,
72 .perm
= AB5500_PERM_RW
,
77 .perm
= AB5500_PERM_RO
,
82 .perm
= AB5500_PERM_RO
,
87 .perm
= AB5500_PERM_RW
,
92 .perm
= AB5500_PERM_RO
,
97 .perm
= AB5500_PERM_RO
,
102 .perm
= AB5500_PERM_RO
,
107 .perm
= AB5500_PERM_RO
,
112 .perm
= AB5500_PERM_RO
,
117 .perm
= AB5500_PERM_RO
,
123 [AB5500_DEVID_ADC
] = {
125 .bank
= (struct ab5500_i2c_ranges
[]) {
127 .bankid
= AB5500_BANK_ADC
,
129 .range
= (struct ab5500_reg_range
[]) {
133 .perm
= AB5500_PERM_RO
,
138 .perm
= AB5500_PERM_RW
,
143 .perm
= AB5500_PERM_RO
,
148 .perm
= AB5500_PERM_RW
,
153 .perm
= AB5500_PERM_RW
,
158 .perm
= AB5500_PERM_RO
,
164 [AB5500_DEVID_LEDS
] = {
166 .bank
= (struct ab5500_i2c_ranges
[]) {
168 .bankid
= AB5500_BANK_LED
,
170 .range
= (struct ab5500_reg_range
[]) {
174 .perm
= AB5500_PERM_RW
,
180 [AB5500_DEVID_VIDEO
] = {
182 .bank
= (struct ab5500_i2c_ranges
[]) {
184 .bankid
= AB5500_BANK_VDENC
,
186 .range
= (struct ab5500_reg_range
[]) {
190 .perm
= AB5500_PERM_RW
,
195 .perm
= AB5500_PERM_RO
,
200 .perm
= AB5500_PERM_RW
,
205 .perm
= AB5500_PERM_RW
,
210 .perm
= AB5500_PERM_RW
,
215 .perm
= AB5500_PERM_RW
,
220 .perm
= AB5500_PERM_RW
,
225 .perm
= AB5500_PERM_RW
,
230 .perm
= AB5500_PERM_RW
,
235 .perm
= AB5500_PERM_RW
,
240 .perm
= AB5500_PERM_RW
,
245 .perm
= AB5500_PERM_RW
,
251 [AB5500_DEVID_REGULATORS
] = {
253 .bank
= (struct ab5500_i2c_ranges
[]) {
255 .bankid
= AB5500_BANK_STARTUP
,
257 .range
= (struct ab5500_reg_range
[]) {
261 .perm
= AB5500_PERM_RW
,
266 .perm
= AB5500_PERM_RW
,
271 .perm
= AB5500_PERM_RO
,
276 .perm
= AB5500_PERM_RW
,
281 .perm
= AB5500_PERM_RW
,
286 .perm
= AB5500_PERM_RW
,
291 .perm
= AB5500_PERM_RW
,
296 .perm
= AB5500_PERM_RW
,
301 .perm
= AB5500_PERM_RW
,
306 .perm
= AB5500_PERM_RW
,
311 .perm
= AB5500_PERM_RW
,
316 .perm
= AB5500_PERM_RW
,
321 .bankid
= AB5500_BANK_SIM_USBSIM
,
323 .range
= (struct ab5500_reg_range
[]) {
327 .perm
= AB5500_PERM_RW
,
333 [AB5500_DEVID_SIM
] = {
335 .bank
= (struct ab5500_i2c_ranges
[]) {
337 .bankid
= AB5500_BANK_SIM_USBSIM
,
339 .range
= (struct ab5500_reg_range
[]) {
343 .perm
= AB5500_PERM_RW
,
349 [AB5500_DEVID_RTC
] = {
351 .bank
= (struct ab5500_i2c_ranges
[]) {
353 .bankid
= AB5500_BANK_RTC
,
355 .range
= (struct ab5500_reg_range
[]) {
359 .perm
= AB5500_PERM_RW
,
364 .perm
= AB5500_PERM_RW
,
370 [AB5500_DEVID_CHARGER
] = {
372 .bank
= (struct ab5500_i2c_ranges
[]) {
374 .bankid
= AB5500_BANK_CHG
,
376 .range
= (struct ab5500_reg_range
[]) {
380 .perm
= AB5500_PERM_RO
,
385 .perm
= AB5500_PERM_RW
,
391 [AB5500_DEVID_FUELGAUGE
] = {
393 .bank
= (struct ab5500_i2c_ranges
[]) {
395 .bankid
= AB5500_BANK_FG_BATTCOM_ACC
,
397 .range
= (struct ab5500_reg_range
[]) {
401 .perm
= AB5500_PERM_RO
,
406 .perm
= AB5500_PERM_RW
,
412 [AB5500_DEVID_VIBRATOR
] = {
414 .bank
= (struct ab5500_i2c_ranges
[]) {
416 .bankid
= AB5500_BANK_VIBRA
,
418 .range
= (struct ab5500_reg_range
[]) {
422 .perm
= AB5500_PERM_RW
,
427 .perm
= AB5500_PERM_RW
,
433 [AB5500_DEVID_CODEC
] = {
435 .bank
= (struct ab5500_i2c_ranges
[]) {
437 .bankid
= AB5500_BANK_AUDIO_HEADSETUSB
,
439 .range
= (struct ab5500_reg_range
[]) {
443 .perm
= AB5500_PERM_RW
,
448 .perm
= AB5500_PERM_RW
,
454 [AB5500_DEVID_POWER
] = {
456 .bank
= (struct ab5500_i2c_ranges
[]) {
458 .bankid
= AB5500_BANK_STARTUP
,
460 .range
= (struct ab5500_reg_range
[]) {
464 .perm
= AB5500_PERM_RW
,
469 .bankid
= AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP
,
471 .range
= (struct ab5500_reg_range
[]) {
475 .perm
= AB5500_PERM_RW
,
483 #define AB5500_IRQ(bank, bit) ((bank) * 8 + (bit))
485 /* I appologize for the resource names beeing a mix of upper case
486 * and lower case but I want them to be exact as the documentation */
487 static struct mfd_cell ab5500_devs
[AB5500_NUM_DEVICES
] = {
488 [AB5500_DEVID_LEDS
] = {
489 .name
= "ab5500-leds",
490 .id
= AB5500_DEVID_LEDS
,
492 [AB5500_DEVID_POWER
] = {
493 .name
= "ab5500-power",
494 .id
= AB5500_DEVID_POWER
,
496 [AB5500_DEVID_REGULATORS
] = {
497 .name
= "ab5500-regulator",
498 .id
= AB5500_DEVID_REGULATORS
,
500 [AB5500_DEVID_SIM
] = {
501 .name
= "ab5500-sim",
502 .id
= AB5500_DEVID_SIM
,
504 .resources
= (struct resource
[]) {
507 .flags
= IORESOURCE_IRQ
,
508 .start
= AB5500_IRQ(2, 0), /*rising*/
509 .end
= AB5500_IRQ(2, 1), /*falling*/
513 [AB5500_DEVID_RTC
] = {
514 .name
= "ab5500-rtc",
515 .id
= AB5500_DEVID_RTC
,
517 .resources
= (struct resource
[]) {
520 .flags
= IORESOURCE_IRQ
,
521 .start
= AB5500_IRQ(1, 7),
522 .end
= AB5500_IRQ(1, 7),
526 [AB5500_DEVID_CHARGER
] = {
527 .name
= "ab5500-charger",
528 .id
= AB5500_DEVID_CHARGER
,
530 [AB5500_DEVID_ADC
] = {
531 .name
= "ab5500-adc",
532 .id
= AB5500_DEVID_ADC
,
534 .resources
= (struct resource
[]) {
537 .flags
= IORESOURCE_IRQ
,
538 .start
= AB5500_IRQ(0, 0),
539 .end
= AB5500_IRQ(0, 0),
543 .flags
= IORESOURCE_IRQ
,
544 .start
= AB5500_IRQ(0, 1),
545 .end
= AB5500_IRQ(0, 1),
549 .flags
= IORESOURCE_IRQ
,
550 .start
= AB5500_IRQ(0, 2),
551 .end
= AB5500_IRQ(0, 2),
555 .flags
= IORESOURCE_IRQ
,
556 .start
= AB5500_IRQ(0, 3),
557 .end
= AB5500_IRQ(0, 3),
561 .flags
= IORESOURCE_IRQ
,
562 .start
= AB5500_IRQ(0, 4),
563 .end
= AB5500_IRQ(0, 4),
567 .flags
= IORESOURCE_IRQ
,
568 .start
= AB5500_IRQ(0, 5),
569 .end
= AB5500_IRQ(0, 5),
573 .flags
= IORESOURCE_IRQ
,
574 .start
= AB5500_IRQ(0, 6),
575 .end
= AB5500_IRQ(0, 6),
579 .flags
= IORESOURCE_IRQ
,
580 .start
= AB5500_IRQ(0, 7),
581 .end
= AB5500_IRQ(0, 7),
584 .name
= "TRIGGER-VBAT",
585 .flags
= IORESOURCE_IRQ
,
586 .start
= AB5500_IRQ(0, 8),
587 .end
= AB5500_IRQ(0, 8),
590 .name
= "TRIGGER-VBAT-TXON",
591 .flags
= IORESOURCE_IRQ
,
592 .start
= AB5500_IRQ(0, 9),
593 .end
= AB5500_IRQ(0, 9),
597 [AB5500_DEVID_FUELGAUGE
] = {
598 .name
= "ab5500-fuelgauge",
599 .id
= AB5500_DEVID_FUELGAUGE
,
601 .resources
= (struct resource
[]) {
603 .name
= "Batt_attach",
604 .flags
= IORESOURCE_IRQ
,
605 .start
= AB5500_IRQ(7, 5),
606 .end
= AB5500_IRQ(7, 5),
609 .name
= "Batt_removal",
610 .flags
= IORESOURCE_IRQ
,
611 .start
= AB5500_IRQ(7, 6),
612 .end
= AB5500_IRQ(7, 6),
615 .name
= "UART_framing",
616 .flags
= IORESOURCE_IRQ
,
617 .start
= AB5500_IRQ(7, 7),
618 .end
= AB5500_IRQ(7, 7),
621 .name
= "UART_overrun",
622 .flags
= IORESOURCE_IRQ
,
623 .start
= AB5500_IRQ(8, 0),
624 .end
= AB5500_IRQ(8, 0),
627 .name
= "UART_Rdy_RX",
628 .flags
= IORESOURCE_IRQ
,
629 .start
= AB5500_IRQ(8, 1),
630 .end
= AB5500_IRQ(8, 1),
633 .name
= "UART_Rdy_TX",
634 .flags
= IORESOURCE_IRQ
,
635 .start
= AB5500_IRQ(8, 2),
636 .end
= AB5500_IRQ(8, 2),
640 [AB5500_DEVID_VIBRATOR
] = {
641 .name
= "ab5500-vibrator",
642 .id
= AB5500_DEVID_VIBRATOR
,
644 [AB5500_DEVID_CODEC
] = {
645 .name
= "ab5500-codec",
646 .id
= AB5500_DEVID_CODEC
,
648 .resources
= (struct resource
[]) {
650 .name
= "audio_spkr1_ovc",
651 .flags
= IORESOURCE_IRQ
,
652 .start
= AB5500_IRQ(9, 5),
653 .end
= AB5500_IRQ(9, 5),
656 .name
= "audio_plllocked",
657 .flags
= IORESOURCE_IRQ
,
658 .start
= AB5500_IRQ(9, 6),
659 .end
= AB5500_IRQ(9, 6),
662 .name
= "audio_spkr2_ovc",
663 .flags
= IORESOURCE_IRQ
,
664 .start
= AB5500_IRQ(17, 4),
665 .end
= AB5500_IRQ(17, 4),
669 [AB5500_DEVID_USB
] = {
670 .name
= "ab5500-usb",
671 .id
= AB5500_DEVID_USB
,
673 .resources
= (struct resource
[]) {
675 .name
= "Link_Update",
676 .flags
= IORESOURCE_IRQ
,
677 .start
= AB5500_IRQ(22, 1),
678 .end
= AB5500_IRQ(22, 1),
682 .flags
= IORESOURCE_IRQ
,
683 .start
= AB5500_IRQ(8, 3),
684 .end
= AB5500_IRQ(8, 4),
688 .flags
= IORESOURCE_IRQ
,
689 .start
= AB5500_IRQ(8, 5),
690 .end
= AB5500_IRQ(8, 5),
694 .flags
= IORESOURCE_IRQ
,
695 .start
= AB5500_IRQ(8, 6),
696 .end
= AB5500_IRQ(8, 6),
699 .name
= "CHGstate_10_PCVBUSchg",
700 .flags
= IORESOURCE_IRQ
,
701 .start
= AB5500_IRQ(8, 7),
702 .end
= AB5500_IRQ(8, 7),
705 .name
= "DCIOreverse_ovc",
706 .flags
= IORESOURCE_IRQ
,
707 .start
= AB5500_IRQ(9, 0),
708 .end
= AB5500_IRQ(9, 0),
711 .name
= "USBCharDetDone",
712 .flags
= IORESOURCE_IRQ
,
713 .start
= AB5500_IRQ(9, 1),
714 .end
= AB5500_IRQ(9, 1),
717 .name
= "DCIO_no_limit",
718 .flags
= IORESOURCE_IRQ
,
719 .start
= AB5500_IRQ(9, 2),
720 .end
= AB5500_IRQ(9, 2),
723 .name
= "USB_suspend",
724 .flags
= IORESOURCE_IRQ
,
725 .start
= AB5500_IRQ(9, 3),
726 .end
= AB5500_IRQ(9, 3),
729 .name
= "DCIOreverse_fwdcurrent",
730 .flags
= IORESOURCE_IRQ
,
731 .start
= AB5500_IRQ(9, 4),
732 .end
= AB5500_IRQ(9, 4),
735 .name
= "Vbus_Imeasmax_change",
736 .flags
= IORESOURCE_IRQ
,
737 .start
= AB5500_IRQ(9, 5),
738 .end
= AB5500_IRQ(9, 6),
742 .flags
= IORESOURCE_IRQ
,
743 .start
= AB5500_IRQ(14, 5),
744 .end
= AB5500_IRQ(14, 5),
747 .name
= "USBcharging_NOTok",
748 .flags
= IORESOURCE_IRQ
,
749 .start
= AB5500_IRQ(15, 3),
750 .end
= AB5500_IRQ(15, 3),
753 .name
= "usb_adp_sensoroff",
754 .flags
= IORESOURCE_IRQ
,
755 .start
= AB5500_IRQ(15, 6),
756 .end
= AB5500_IRQ(15, 6),
759 .name
= "usb_adp_probeplug",
760 .flags
= IORESOURCE_IRQ
,
761 .start
= AB5500_IRQ(15, 7),
762 .end
= AB5500_IRQ(15, 7),
765 .name
= "usb_adp_sinkerror",
766 .flags
= IORESOURCE_IRQ
,
767 .start
= AB5500_IRQ(16, 0),
768 .end
= AB5500_IRQ(16, 6),
771 .name
= "usb_adp_sourceerror",
772 .flags
= IORESOURCE_IRQ
,
773 .start
= AB5500_IRQ(16, 1),
774 .end
= AB5500_IRQ(16, 1),
777 .name
= "usb_idgnd_r",
778 .flags
= IORESOURCE_IRQ
,
779 .start
= AB5500_IRQ(16, 2),
780 .end
= AB5500_IRQ(16, 2),
783 .name
= "usb_idgnd_f",
784 .flags
= IORESOURCE_IRQ
,
785 .start
= AB5500_IRQ(16, 3),
786 .end
= AB5500_IRQ(16, 3),
789 .name
= "usb_iddetR1",
790 .flags
= IORESOURCE_IRQ
,
791 .start
= AB5500_IRQ(16, 4),
792 .end
= AB5500_IRQ(16, 5),
795 .name
= "usb_iddetR2",
796 .flags
= IORESOURCE_IRQ
,
797 .start
= AB5500_IRQ(16, 6),
798 .end
= AB5500_IRQ(16, 7),
801 .name
= "usb_iddetR3",
802 .flags
= IORESOURCE_IRQ
,
803 .start
= AB5500_IRQ(17, 0),
804 .end
= AB5500_IRQ(17, 1),
807 .name
= "usb_iddetR4",
808 .flags
= IORESOURCE_IRQ
,
809 .start
= AB5500_IRQ(17, 2),
810 .end
= AB5500_IRQ(17, 3),
813 .name
= "CharTempWindowOk",
814 .flags
= IORESOURCE_IRQ
,
815 .start
= AB5500_IRQ(17, 7),
816 .end
= AB5500_IRQ(18, 0),
819 .name
= "USB_SprDetect",
820 .flags
= IORESOURCE_IRQ
,
821 .start
= AB5500_IRQ(18, 1),
822 .end
= AB5500_IRQ(18, 1),
825 .name
= "usb_adp_probe_unplug",
826 .flags
= IORESOURCE_IRQ
,
827 .start
= AB5500_IRQ(18, 2),
828 .end
= AB5500_IRQ(18, 2),
831 .name
= "VBUSChDrop",
832 .flags
= IORESOURCE_IRQ
,
833 .start
= AB5500_IRQ(18, 3),
834 .end
= AB5500_IRQ(18, 4),
837 .name
= "dcio_char_rec_done",
838 .flags
= IORESOURCE_IRQ
,
839 .start
= AB5500_IRQ(18, 5),
840 .end
= AB5500_IRQ(18, 5),
843 .name
= "Charging_stopped_by_temp",
844 .flags
= IORESOURCE_IRQ
,
845 .start
= AB5500_IRQ(18, 6),
846 .end
= AB5500_IRQ(18, 6),
849 .name
= "CHGstate_11_SafeModeVBUS",
850 .flags
= IORESOURCE_IRQ
,
851 .start
= AB5500_IRQ(21, 1),
852 .end
= AB5500_IRQ(21, 2),
855 .name
= "CHGstate_12_comletedVBUS",
856 .flags
= IORESOURCE_IRQ
,
857 .start
= AB5500_IRQ(21, 2),
858 .end
= AB5500_IRQ(21, 2),
861 .name
= "CHGstate_13_completedVBUS",
862 .flags
= IORESOURCE_IRQ
,
863 .start
= AB5500_IRQ(21, 3),
864 .end
= AB5500_IRQ(21, 3),
867 .name
= "CHGstate_14_FullChgDCIO",
868 .flags
= IORESOURCE_IRQ
,
869 .start
= AB5500_IRQ(21, 4),
870 .end
= AB5500_IRQ(21, 4),
873 .name
= "CHGstate_15_SafeModeDCIO",
874 .flags
= IORESOURCE_IRQ
,
875 .start
= AB5500_IRQ(21, 5),
876 .end
= AB5500_IRQ(21, 5),
879 .name
= "CHGstate_16_OFFsuspendDCIO",
880 .flags
= IORESOURCE_IRQ
,
881 .start
= AB5500_IRQ(21, 6),
882 .end
= AB5500_IRQ(21, 6),
885 .name
= "CHGstate_17_completedDCIO",
886 .flags
= IORESOURCE_IRQ
,
887 .start
= AB5500_IRQ(21, 7),
888 .end
= AB5500_IRQ(21, 7),
892 [AB5500_DEVID_OTP
] = {
893 .name
= "ab5500-otp",
894 .id
= AB5500_DEVID_OTP
,
896 [AB5500_DEVID_VIDEO
] = {
897 .name
= "ab5500-video",
898 .id
= AB5500_DEVID_VIDEO
,
900 .resources
= (struct resource
[]) {
903 .flags
= IORESOURCE_IRQ
,
904 .start
= AB5500_IRQ(22, 2),
905 .end
= AB5500_IRQ(22, 2),
909 [AB5500_DEVID_DBIECI
] = {
910 .name
= "ab5500-dbieci",
911 .id
= AB5500_DEVID_DBIECI
,
913 .resources
= (struct resource
[]) {
916 .flags
= IORESOURCE_IRQ
,
917 .start
= AB5500_IRQ(14, 0),
918 .end
= AB5500_IRQ(14, 0),
922 .flags
= IORESOURCE_IRQ
,
923 .start
= AB5500_IRQ(14, 1),
924 .end
= AB5500_IRQ(14, 1),
928 .flags
= IORESOURCE_IRQ
,
929 .start
= AB5500_IRQ(14, 2),
930 .end
= AB5500_IRQ(14, 2),
934 .flags
= IORESOURCE_IRQ
,
935 .start
= AB5500_IRQ(14, 3),
936 .end
= AB5500_IRQ(14, 3),
939 .name
= "BSI_indicator",
940 .flags
= IORESOURCE_IRQ
,
941 .start
= AB5500_IRQ(14, 4),
942 .end
= AB5500_IRQ(14, 4),
946 .flags
= IORESOURCE_IRQ
,
947 .start
= AB5500_IRQ(14, 6),
948 .end
= AB5500_IRQ(14, 6),
952 .flags
= IORESOURCE_IRQ
,
953 .start
= AB5500_IRQ(14, 7),
954 .end
= AB5500_IRQ(14, 7),
958 .flags
= IORESOURCE_IRQ
,
959 .start
= AB5500_IRQ(15, 0),
960 .end
= AB5500_IRQ(15, 0),
964 .flags
= IORESOURCE_IRQ
,
965 .start
= AB5500_IRQ(15, 1),
966 .end
= AB5500_IRQ(15, 1),
970 .flags
= IORESOURCE_IRQ
,
971 .start
= AB5500_IRQ(15, 2),
972 .end
= AB5500_IRQ(15, 2),
976 [AB5500_DEVID_ONSWA
] = {
977 .name
= "ab5500-onswa",
978 .id
= AB5500_DEVID_ONSWA
,
980 .resources
= (struct resource
[]) {
982 .name
= "ONSWAn_rising",
983 .flags
= IORESOURCE_IRQ
,
984 .start
= AB5500_IRQ(1, 3),
985 .end
= AB5500_IRQ(1, 3),
988 .name
= "ONSWAn_falling",
989 .flags
= IORESOURCE_IRQ
,
990 .start
= AB5500_IRQ(1, 4),
991 .end
= AB5500_IRQ(1, 4),
998 * Functionality for getting/setting register values.
1000 int ab5500_get_register_interruptible_raw(struct ab5500
*ab
,
1006 if (bank
>= AB5500_NUM_BANKS
)
1009 err
= mutex_lock_interruptible(&ab
->access_mutex
);
1012 err
= db5500_prcmu_abb_read(bankinfo
[bank
].slave_addr
, reg
, value
, 1);
1014 mutex_unlock(&ab
->access_mutex
);
1018 static int get_register_page_interruptible(struct ab5500
*ab
, u8 bank
,
1019 u8 first_reg
, u8
*regvals
, u8 numregs
)
1023 if (bank
>= AB5500_NUM_BANKS
)
1026 err
= mutex_lock_interruptible(&ab
->access_mutex
);
1031 /* The hardware limit for get page is 4 */
1032 u8 curnum
= min_t(u8
, numregs
, 4u);
1034 err
= db5500_prcmu_abb_read(bankinfo
[bank
].slave_addr
,
1035 first_reg
, regvals
, curnum
);
1040 first_reg
+= curnum
;
1045 mutex_unlock(&ab
->access_mutex
);
1049 int ab5500_mask_and_set_register_interruptible_raw(struct ab5500
*ab
, u8 bank
,
1050 u8 reg
, u8 bitmask
, u8 bitvalues
)
1054 if (bank
>= AB5500_NUM_BANKS
)
1060 err
= mutex_lock_interruptible(&ab
->access_mutex
);
1064 if (bitmask
== 0xFF) /* No need to read in this case. */
1066 else { /* Read and modify the register value. */
1067 err
= db5500_prcmu_abb_read(bankinfo
[bank
].slave_addr
,
1072 buf
= ((~bitmask
& buf
) | (bitmask
& bitvalues
));
1074 /* Write the new value. */
1075 err
= db5500_prcmu_abb_write(bankinfo
[bank
].slave_addr
, reg
,
1078 mutex_unlock(&ab
->access_mutex
);
1084 set_register_interruptible(struct ab5500
*ab
, u8 bank
, u8 reg
, u8 value
)
1086 return ab5500_mask_and_set_register_interruptible_raw(ab
, bank
, reg
,
1091 * Read/write permission checking functions.
1093 static const struct ab5500_i2c_ranges
*get_bankref(u8 devid
, u8 bank
)
1097 if (devid
< AB5500_NUM_DEVICES
) {
1098 for (i
= 0; i
< ab5500_bank_ranges
[devid
].nbanks
; i
++) {
1099 if (ab5500_bank_ranges
[devid
].bank
[i
].bankid
== bank
)
1100 return &ab5500_bank_ranges
[devid
].bank
[i
];
1106 static bool page_write_allowed(u8 devid
, u8 bank
, u8 first_reg
, u8 last_reg
)
1108 u8 i
; /* range loop index */
1109 const struct ab5500_i2c_ranges
*bankref
;
1111 bankref
= get_bankref(devid
, bank
);
1112 if (bankref
== NULL
|| last_reg
< first_reg
)
1115 for (i
= 0; i
< bankref
->nranges
; i
++) {
1116 if (first_reg
< bankref
->range
[i
].first
)
1118 if ((last_reg
<= bankref
->range
[i
].last
) &&
1119 (bankref
->range
[i
].perm
& AB5500_PERM_WR
))
1125 static bool reg_write_allowed(u8 devid
, u8 bank
, u8 reg
)
1127 return page_write_allowed(devid
, bank
, reg
, reg
);
1130 static bool page_read_allowed(u8 devid
, u8 bank
, u8 first_reg
, u8 last_reg
)
1133 const struct ab5500_i2c_ranges
*bankref
;
1135 bankref
= get_bankref(devid
, bank
);
1136 if (bankref
== NULL
|| last_reg
< first_reg
)
1140 /* Find the range (if it exists in the list) that includes first_reg. */
1141 for (i
= 0; i
< bankref
->nranges
; i
++) {
1142 if (first_reg
< bankref
->range
[i
].first
)
1144 if (first_reg
<= bankref
->range
[i
].last
)
1147 /* Make sure that the entire range up to and including last_reg is
1148 * readable. This may span several of the ranges in the list.
1150 while ((i
< bankref
->nranges
) &&
1151 (bankref
->range
[i
].perm
& AB5500_PERM_RD
)) {
1152 if (last_reg
<= bankref
->range
[i
].last
)
1154 if ((++i
>= bankref
->nranges
) ||
1155 (bankref
->range
[i
].first
!=
1156 (bankref
->range
[i
- 1].last
+ 1))) {
1163 static bool reg_read_allowed(u8 devid
, u8 bank
, u8 reg
)
1165 return page_read_allowed(devid
, bank
, reg
, reg
);
1170 * The exported register access functionality.
1172 static int ab5500_get_chip_id(struct device
*dev
)
1174 struct ab5500
*ab
= dev_get_drvdata(dev
->parent
);
1176 return (int)ab
->chip_id
;
1179 static int ab5500_mask_and_set_register_interruptible(struct device
*dev
,
1180 u8 bank
, u8 reg
, u8 bitmask
, u8 bitvalues
)
1183 struct platform_device
*pdev
= to_platform_device(dev
);
1185 if ((AB5500_NUM_BANKS
<= bank
) ||
1186 !reg_write_allowed(pdev
->id
, bank
, reg
))
1189 ab
= dev_get_drvdata(dev
->parent
);
1190 return ab5500_mask_and_set_register_interruptible_raw(ab
, bank
, reg
,
1191 bitmask
, bitvalues
);
1194 static int ab5500_set_register_interruptible(struct device
*dev
, u8 bank
,
1197 return ab5500_mask_and_set_register_interruptible(dev
, bank
, reg
, 0xFF,
1201 static int ab5500_get_register_interruptible(struct device
*dev
, u8 bank
,
1205 struct platform_device
*pdev
= to_platform_device(dev
);
1207 if ((AB5500_NUM_BANKS
<= bank
) ||
1208 !reg_read_allowed(pdev
->id
, bank
, reg
))
1211 ab
= dev_get_drvdata(dev
->parent
);
1212 return ab5500_get_register_interruptible_raw(ab
, bank
, reg
, value
);
1215 static int ab5500_get_register_page_interruptible(struct device
*dev
, u8 bank
,
1216 u8 first_reg
, u8
*regvals
, u8 numregs
)
1219 struct platform_device
*pdev
= to_platform_device(dev
);
1221 if ((AB5500_NUM_BANKS
<= bank
) ||
1222 !page_read_allowed(pdev
->id
, bank
,
1223 first_reg
, (first_reg
+ numregs
- 1)))
1226 ab
= dev_get_drvdata(dev
->parent
);
1227 return get_register_page_interruptible(ab
, bank
, first_reg
, regvals
,
1232 ab5500_event_registers_startup_state_get(struct device
*dev
, u8
*event
)
1236 ab
= dev_get_drvdata(dev
->parent
);
1237 if (!ab
->startup_events_read
)
1238 return -EAGAIN
; /* Try again later */
1240 memcpy(event
, ab
->startup_events
, AB5500_NUM_EVENT_REG
);
1244 static struct abx500_ops ab5500_ops
= {
1245 .get_chip_id
= ab5500_get_chip_id
,
1246 .get_register
= ab5500_get_register_interruptible
,
1247 .set_register
= ab5500_set_register_interruptible
,
1248 .get_register_page
= ab5500_get_register_page_interruptible
,
1249 .set_register_page
= NULL
,
1250 .mask_and_set_register
= ab5500_mask_and_set_register_interruptible
,
1251 .event_registers_startup_state_get
=
1252 ab5500_event_registers_startup_state_get
,
1253 .startup_irq_enabled
= NULL
,
1257 * ab5500_setup : Basic set-up, datastructure creation/destruction
1258 * and I2C interface.This sets up a default config
1259 * in the AB5500 chip so that it will work as expected.
1260 * @ab : Pointer to ab5500 structure
1261 * @settings : Pointer to struct abx500_init_settings
1262 * @size : Size of init data
1264 static int __init
ab5500_setup(struct ab5500
*ab
,
1265 struct abx500_init_settings
*settings
, unsigned int size
)
1270 for (i
= 0; i
< size
; i
++) {
1271 err
= ab5500_mask_and_set_register_interruptible_raw(ab
,
1274 0xFF, settings
[i
].setting
);
1278 /* If event mask register update the event mask in ab5500 */
1279 if ((settings
[i
].bank
== AB5500_BANK_IT
) &&
1280 (AB5500_MASK_BASE
<= settings
[i
].reg
) &&
1281 (settings
[i
].reg
<= AB5500_MASK_END
)) {
1282 ab
->mask
[settings
[i
].reg
- AB5500_MASK_BASE
] =
1283 settings
[i
].setting
;
1290 struct ab_family_id
{
1295 static const struct ab_family_id ids
[] __initdata
= {
1311 static int __init
ab5500_probe(struct platform_device
*pdev
)
1314 struct ab5500_platform_data
*ab5500_plf_data
=
1315 pdev
->dev
.platform_data
;
1319 ab
= kzalloc(sizeof(struct ab5500
), GFP_KERNEL
);
1322 "could not allocate ab5500 device\n");
1326 /* Initialize data structure */
1327 mutex_init(&ab
->access_mutex
);
1328 mutex_init(&ab
->irq_lock
);
1329 ab
->dev
= &pdev
->dev
;
1331 platform_set_drvdata(pdev
, ab
);
1333 /* Read chip ID register */
1334 err
= ab5500_get_register_interruptible_raw(ab
,
1335 AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP
,
1336 AB5500_CHIP_ID
, &ab
->chip_id
);
1338 dev_err(&pdev
->dev
, "could not communicate with the analog "
1340 goto exit_no_detect
;
1343 for (i
= 0; ids
[i
].id
!= 0x0; i
++) {
1344 if (ids
[i
].id
== ab
->chip_id
) {
1345 snprintf(&ab
->chip_name
[0], sizeof(ab
->chip_name
) - 1,
1346 "AB5500 %s", ids
[i
].name
);
1350 if (ids
[i
].id
== 0x0) {
1351 dev_err(&pdev
->dev
, "unknown analog baseband chip id: 0x%x\n",
1353 dev_err(&pdev
->dev
, "driver not started!\n");
1354 goto exit_no_detect
;
1357 /* Clear and mask all interrupts */
1358 for (i
= 0; i
< AB5500_NUM_IRQ_REGS
; i
++) {
1359 u8 latchreg
= AB5500_IT_LATCH0_REG
+ i
;
1360 u8 maskreg
= AB5500_IT_MASK0_REG
+ i
;
1363 ab5500_get_register_interruptible_raw(ab
, AB5500_BANK_IT
,
1365 set_register_interruptible(ab
, AB5500_BANK_IT
, maskreg
, 0xff);
1366 ab
->mask
[i
] = ab
->oldmask
[i
] = 0xff;
1369 err
= abx500_register_ops(&pdev
->dev
, &ab5500_ops
);
1371 dev_err(&pdev
->dev
, "ab5500_register ops error\n");
1372 goto exit_no_detect
;
1375 /* Set up and register the platform devices. */
1376 for (i
= 0; i
< AB5500_NUM_DEVICES
; i
++) {
1377 ab5500_devs
[i
].platform_data
= ab5500_plf_data
->dev_data
[i
];
1378 ab5500_devs
[i
].pdata_size
=
1379 sizeof(ab5500_plf_data
->dev_data
[i
]);
1382 err
= mfd_add_devices(&pdev
->dev
, 0, ab5500_devs
,
1383 ARRAY_SIZE(ab5500_devs
), NULL
,
1384 ab5500_plf_data
->irq
.base
);
1386 dev_err(&pdev
->dev
, "ab5500_mfd_add_device error\n");
1387 goto exit_no_detect
;
1390 err
= ab5500_setup(ab
, ab5500_plf_data
->init_settings
,
1391 ab5500_plf_data
->init_settings_sz
);
1393 dev_err(&pdev
->dev
, "ab5500_setup error\n");
1394 goto exit_no_detect
;
1397 ab5500_setup_debugfs(ab
);
1399 dev_info(&pdev
->dev
, "detected AB chip: %s\n", &ab
->chip_name
[0]);
1407 static int __exit
ab5500_remove(struct platform_device
*pdev
)
1409 struct ab5500
*ab
= platform_get_drvdata(pdev
);
1411 ab5500_remove_debugfs();
1412 mfd_remove_devices(&pdev
->dev
);
1417 static struct platform_driver ab5500_driver
= {
1419 .name
= "ab5500-core",
1420 .owner
= THIS_MODULE
,
1422 .remove
= __exit_p(ab5500_remove
),
1425 static int __init
ab5500_core_init(void)
1427 return platform_driver_probe(&ab5500_driver
, ab5500_probe
);
1430 static void __exit
ab5500_core_exit(void)
1432 platform_driver_unregister(&ab5500_driver
);
1435 subsys_initcall(ab5500_core_init
);
1436 module_exit(ab5500_core_exit
);
1438 MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
1439 MODULE_DESCRIPTION("AB5500 core driver");
1440 MODULE_LICENSE("GPL");