13 #include <linux/slab.h>
14 #include <linux/module.h>
26 #define MC13XXX_IRQSTAT0 0
27 #define MC13XXX_IRQSTAT0_ADCDONEI (1 << 0)
28 #define MC13XXX_IRQSTAT0_ADCBISDONEI (1 << 1)
29 #define MC13XXX_IRQSTAT0_TSI (1 << 2)
30 #define MC13783_IRQSTAT0_WHIGHI (1 << 3)
31 #define MC13783_IRQSTAT0_WLOWI (1 << 4)
32 #define MC13XXX_IRQSTAT0_CHGDETI (1 << 6)
33 #define MC13783_IRQSTAT0_CHGOVI (1 << 7)
34 #define MC13XXX_IRQSTAT0_CHGREVI (1 << 8)
35 #define MC13XXX_IRQSTAT0_CHGSHORTI (1 << 9)
36 #define MC13XXX_IRQSTAT0_CCCVI (1 << 10)
37 #define MC13XXX_IRQSTAT0_CHGCURRI (1 << 11)
38 #define MC13XXX_IRQSTAT0_BPONI (1 << 12)
39 #define MC13XXX_IRQSTAT0_LOBATLI (1 << 13)
40 #define MC13XXX_IRQSTAT0_LOBATHI (1 << 14)
41 #define MC13783_IRQSTAT0_UDPI (1 << 15)
42 #define MC13783_IRQSTAT0_USBI (1 << 16)
43 #define MC13783_IRQSTAT0_IDI (1 << 19)
44 #define MC13783_IRQSTAT0_SE1I (1 << 21)
45 #define MC13783_IRQSTAT0_CKDETI (1 << 22)
46 #define MC13783_IRQSTAT0_UDMI (1 << 23)
48 #define MC13XXX_IRQMASK0 1
49 #define MC13XXX_IRQMASK0_ADCDONEM MC13XXX_IRQSTAT0_ADCDONEI
50 #define MC13XXX_IRQMASK0_ADCBISDONEM MC13XXX_IRQSTAT0_ADCBISDONEI
51 #define MC13XXX_IRQMASK0_TSM MC13XXX_IRQSTAT0_TSI
52 #define MC13783_IRQMASK0_WHIGHM MC13783_IRQSTAT0_WHIGHI
53 #define MC13783_IRQMASK0_WLOWM MC13783_IRQSTAT0_WLOWI
54 #define MC13XXX_IRQMASK0_CHGDETM MC13XXX_IRQSTAT0_CHGDETI
55 #define MC13783_IRQMASK0_CHGOVM MC13783_IRQSTAT0_CHGOVI
56 #define MC13XXX_IRQMASK0_CHGREVM MC13XXX_IRQSTAT0_CHGREVI
57 #define MC13XXX_IRQMASK0_CHGSHORTM MC13XXX_IRQSTAT0_CHGSHORTI
58 #define MC13XXX_IRQMASK0_CCCVM MC13XXX_IRQSTAT0_CCCVI
59 #define MC13XXX_IRQMASK0_CHGCURRM MC13XXX_IRQSTAT0_CHGCURRI
60 #define MC13XXX_IRQMASK0_BPONM MC13XXX_IRQSTAT0_BPONI
61 #define MC13XXX_IRQMASK0_LOBATLM MC13XXX_IRQSTAT0_LOBATLI
62 #define MC13XXX_IRQMASK0_LOBATHM MC13XXX_IRQSTAT0_LOBATHI
63 #define MC13783_IRQMASK0_UDPM MC13783_IRQSTAT0_UDPI
64 #define MC13783_IRQMASK0_USBM MC13783_IRQSTAT0_USBI
65 #define MC13783_IRQMASK0_IDM MC13783_IRQSTAT0_IDI
66 #define MC13783_IRQMASK0_SE1M MC13783_IRQSTAT0_SE1I
67 #define MC13783_IRQMASK0_CKDETM MC13783_IRQSTAT0_CKDETI
68 #define MC13783_IRQMASK0_UDMM MC13783_IRQSTAT0_UDMI
70 #define MC13XXX_IRQSTAT1 3
71 #define MC13XXX_IRQSTAT1_1HZI (1 << 0)
72 #define MC13XXX_IRQSTAT1_TODAI (1 << 1)
73 #define MC13783_IRQSTAT1_ONOFD1I (1 << 3)
74 #define MC13783_IRQSTAT1_ONOFD2I (1 << 4)
75 #define MC13783_IRQSTAT1_ONOFD3I (1 << 5)
76 #define MC13XXX_IRQSTAT1_SYSRSTI (1 << 6)
77 #define MC13XXX_IRQSTAT1_RTCRSTI (1 << 7)
78 #define MC13XXX_IRQSTAT1_PCI (1 << 8)
79 #define MC13XXX_IRQSTAT1_WARMI (1 << 9)
80 #define MC13XXX_IRQSTAT1_MEMHLDI (1 << 10)
81 #define MC13783_IRQSTAT1_PWRRDYI (1 << 11)
82 #define MC13XXX_IRQSTAT1_THWARNLI (1 << 12)
83 #define MC13XXX_IRQSTAT1_THWARNHI (1 << 13)
84 #define MC13XXX_IRQSTAT1_CLKI (1 << 14)
85 #define MC13783_IRQSTAT1_SEMAFI (1 << 15)
86 #define MC13783_IRQSTAT1_MC2BI (1 << 17)
87 #define MC13783_IRQSTAT1_HSDETI (1 << 18)
88 #define MC13783_IRQSTAT1_HSLI (1 << 19)
89 #define MC13783_IRQSTAT1_ALSPTHI (1 << 20)
90 #define MC13783_IRQSTAT1_AHSSHORTI (1 << 21)
92 #define MC13XXX_IRQMASK1 4
93 #define MC13XXX_IRQMASK1_1HZM MC13XXX_IRQSTAT1_1HZI
94 #define MC13XXX_IRQMASK1_TODAM MC13XXX_IRQSTAT1_TODAI
95 #define MC13783_IRQMASK1_ONOFD1M MC13783_IRQSTAT1_ONOFD1I
96 #define MC13783_IRQMASK1_ONOFD2M MC13783_IRQSTAT1_ONOFD2I
97 #define MC13783_IRQMASK1_ONOFD3M MC13783_IRQSTAT1_ONOFD3I
98 #define MC13XXX_IRQMASK1_SYSRSTM MC13XXX_IRQSTAT1_SYSRSTI
99 #define MC13XXX_IRQMASK1_RTCRSTM MC13XXX_IRQSTAT1_RTCRSTI
100 #define MC13XXX_IRQMASK1_PCM MC13XXX_IRQSTAT1_PCI
101 #define MC13XXX_IRQMASK1_WARMM MC13XXX_IRQSTAT1_WARMI
102 #define MC13XXX_IRQMASK1_MEMHLDM MC13XXX_IRQSTAT1_MEMHLDI
103 #define MC13783_IRQMASK1_PWRRDYM MC13783_IRQSTAT1_PWRRDYI
104 #define MC13XXX_IRQMASK1_THWARNLM MC13XXX_IRQSTAT1_THWARNLI
105 #define MC13XXX_IRQMASK1_THWARNHM MC13XXX_IRQSTAT1_THWARNHI
106 #define MC13XXX_IRQMASK1_CLKM MC13XXX_IRQSTAT1_CLKI
107 #define MC13783_IRQMASK1_SEMAFM MC13783_IRQSTAT1_SEMAFI
108 #define MC13783_IRQMASK1_MC2BM MC13783_IRQSTAT1_MC2BI
109 #define MC13783_IRQMASK1_HSDETM MC13783_IRQSTAT1_HSDETI
110 #define MC13783_IRQMASK1_HSLM MC13783_IRQSTAT1_HSLI
111 #define MC13783_IRQMASK1_ALSPTHM MC13783_IRQSTAT1_ALSPTHI
112 #define MC13783_IRQMASK1_AHSSHORTM MC13783_IRQSTAT1_AHSSHORTI
114 #define MC13XXX_REVISION 7
115 #define MC13XXX_REVISION_REVMETAL (0x07 << 0)
116 #define MC13XXX_REVISION_REVFULL (0x03 << 3)
117 #define MC13XXX_REVISION_ICID (0x07 << 6)
118 #define MC13XXX_REVISION_FIN (0x03 << 9)
119 #define MC13XXX_REVISION_FAB (0x03 << 11)
120 #define MC13XXX_REVISION_ICIDCODE (0x3f << 13)
122 #define MC13XXX_ADC1 44
123 #define MC13XXX_ADC1_ADEN (1 << 0)
124 #define MC13XXX_ADC1_RAND (1 << 1)
125 #define MC13XXX_ADC1_ADSEL (1 << 3)
126 #define MC13XXX_ADC1_ASC (1 << 20)
127 #define MC13XXX_ADC1_ADTRIGIGN (1 << 21)
129 #define MC13XXX_ADC2 45
134 dev_dbg(mc13xxx->
dev,
"wait for %s from %pf\n",
135 __func__, __builtin_return_address(0));
140 __func__, __builtin_return_address(0));
147 __func__, __builtin_return_address(0));
162 dev_vdbg(mc13xxx->
dev,
"[0x%02x] -> 0x%06x\n", offset, *val);
172 dev_vdbg(mc13xxx->
dev,
"[0x%02x] <- 0x%06x\n", offset, val);
186 dev_vdbg(mc13xxx->
dev,
"[0x%02x] <- 0x%06x (mask: 0x%06x)\n",
197 u32 irqbit = 1 << (irq < 24 ? irq : irq - 24);
219 u32 irqbit = 1 << (irq < 24 ? irq : irq - 24);
229 if (!(mask & irqbit))
243 u32 irqbit = 1 << (irq < 24 ? irq : irq - 24);
255 *enabled = mask & irqbit;
265 *pending = stat & irqbit;
275 unsigned int val = 1 << (irq < 24 ? irq : irq - 24);
352 unsigned int offstat,
unsigned int offmask,
int baseirq)
365 while (stat & ~mask) {
373 handled = mc13xxx_irqhandler(mc13xxx, baseirq + irq);
378 "BUG: irq %u but no handler\n",
392 struct mc13xxx *mc13xxx =
data;
413 static const char *mc13xxx_chipname[] = {
418 #define maskval(reg, mask) (((reg) & (mask)) >> __ffs(mask))
419 static int mc13xxx_identify(
struct mc13xxx *mc13xxx)
434 icid = (icid >> 6) & 0x7;
453 "fin: %d, fab: %d, icid: %d/%d\n",
454 mc13xxx_chipname[mc13xxx->
ictype],
466 static const char *mc13xxx_get_chipname(
struct mc13xxx *mc13xxx)
468 return mc13xxx_chipname[mc13xxx->
ictype];
473 return mc13xxx->
flags;
477 #define MC13XXX_ADC1_CHAN0_SHIFT 5
478 #define MC13XXX_ADC1_CHAN1_SHIFT 8
479 #define MC13783_ADC1_ATO_SHIFT 11
480 #define MC13783_ADC1_ATOX (1 << 19)
487 static irqreturn_t mc13xxx_handler_adcdone(
int irq,
void *data)
498 #define MC13XXX_ADC_WORKING (1 << 0)
504 u32 adc0, adc1, old_adc0;
509 init_completion(&adcdone_data.
done);
557 dev_dbg(mc13xxx->
dev,
"%s: request irq\n", __func__);
559 mc13xxx_handler_adcdone, __func__, &adcdone_data);
577 for (i = 0; i < 4; ++
i) {
596 static int mc13xxx_add_subdevice_pdata(
struct mc13xxx *mc13xxx,
597 const char *
format,
void *
pdata,
size_t pdata_size)
600 const char *
name = mc13xxx_get_chipname(mc13xxx);
608 if (
snprintf(buf,
sizeof(buf), format, name) >
sizeof(buf))
618 static int mc13xxx_add_subdevice(
struct mc13xxx *mc13xxx,
const char *format)
620 return mc13xxx_add_subdevice_pdata(mc13xxx, format,
NULL, 0);
624 static int mc13xxx_probe_flags_dt(
struct mc13xxx *mc13xxx)
646 static inline int mc13xxx_probe_flags_dt(
struct mc13xxx *mc13xxx)
659 ret = mc13xxx_identify(mc13xxx);
686 if (mc13xxx_probe_flags_dt(mc13xxx) < 0 && pdata)
690 mc13xxx_add_subdevice(mc13xxx,
"%s-adc");
693 mc13xxx_add_subdevice_pdata(mc13xxx,
"%s-codec",
697 mc13xxx_add_subdevice(mc13xxx,
"%s-rtc");
700 mc13xxx_add_subdevice_pdata(mc13xxx,
"%s-ts",
704 mc13xxx_add_subdevice_pdata(mc13xxx,
"%s-regulator",
706 mc13xxx_add_subdevice_pdata(mc13xxx,
"%s-led",
708 mc13xxx_add_subdevice_pdata(mc13xxx,
"%s-pwrbutton",
711 mc13xxx_add_subdevice(mc13xxx,
"%s-regulator");
712 mc13xxx_add_subdevice(mc13xxx,
"%s-led");
713 mc13xxx_add_subdevice(mc13xxx,
"%s-pwrbutton");