4 * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd
5 * http://www.samsung.com
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
14 #include <linux/device.h>
15 #include <linux/interrupt.h>
16 #include <linux/irq.h>
17 #include <linux/regmap.h>
19 #include <linux/mfd/samsung/core.h>
20 #include <linux/mfd/samsung/irq.h>
21 #include <linux/mfd/samsung/s2mps11.h>
22 #include <linux/mfd/samsung/s2mps14.h>
23 #include <linux/mfd/samsung/s5m8763.h>
24 #include <linux/mfd/samsung/s5m8767.h>
26 static const struct regmap_irq s2mps11_irqs
[] = {
27 [S2MPS11_IRQ_PWRONF
] = {
29 .mask
= S2MPS11_IRQ_PWRONF_MASK
,
31 [S2MPS11_IRQ_PWRONR
] = {
33 .mask
= S2MPS11_IRQ_PWRONR_MASK
,
35 [S2MPS11_IRQ_JIGONBF
] = {
37 .mask
= S2MPS11_IRQ_JIGONBF_MASK
,
39 [S2MPS11_IRQ_JIGONBR
] = {
41 .mask
= S2MPS11_IRQ_JIGONBR_MASK
,
43 [S2MPS11_IRQ_ACOKBF
] = {
45 .mask
= S2MPS11_IRQ_ACOKBF_MASK
,
47 [S2MPS11_IRQ_ACOKBR
] = {
49 .mask
= S2MPS11_IRQ_ACOKBR_MASK
,
51 [S2MPS11_IRQ_PWRON1S
] = {
53 .mask
= S2MPS11_IRQ_PWRON1S_MASK
,
57 .mask
= S2MPS11_IRQ_MRB_MASK
,
59 [S2MPS11_IRQ_RTC60S
] = {
61 .mask
= S2MPS11_IRQ_RTC60S_MASK
,
63 [S2MPS11_IRQ_RTCA0
] = {
65 .mask
= S2MPS11_IRQ_RTCA0_MASK
,
67 [S2MPS11_IRQ_RTCA1
] = {
69 .mask
= S2MPS11_IRQ_RTCA1_MASK
,
71 [S2MPS11_IRQ_SMPL
] = {
73 .mask
= S2MPS11_IRQ_SMPL_MASK
,
75 [S2MPS11_IRQ_RTC1S
] = {
77 .mask
= S2MPS11_IRQ_RTC1S_MASK
,
79 [S2MPS11_IRQ_WTSR
] = {
81 .mask
= S2MPS11_IRQ_WTSR_MASK
,
83 [S2MPS11_IRQ_INT120C
] = {
85 .mask
= S2MPS11_IRQ_INT120C_MASK
,
87 [S2MPS11_IRQ_INT140C
] = {
89 .mask
= S2MPS11_IRQ_INT140C_MASK
,
93 static const struct regmap_irq s2mps14_irqs
[] = {
94 [S2MPS14_IRQ_PWRONF
] = {
96 .mask
= S2MPS11_IRQ_PWRONF_MASK
,
98 [S2MPS14_IRQ_PWRONR
] = {
100 .mask
= S2MPS11_IRQ_PWRONR_MASK
,
102 [S2MPS14_IRQ_JIGONBF
] = {
104 .mask
= S2MPS11_IRQ_JIGONBF_MASK
,
106 [S2MPS14_IRQ_JIGONBR
] = {
108 .mask
= S2MPS11_IRQ_JIGONBR_MASK
,
110 [S2MPS14_IRQ_ACOKBF
] = {
112 .mask
= S2MPS11_IRQ_ACOKBF_MASK
,
114 [S2MPS14_IRQ_ACOKBR
] = {
116 .mask
= S2MPS11_IRQ_ACOKBR_MASK
,
118 [S2MPS14_IRQ_PWRON1S
] = {
120 .mask
= S2MPS11_IRQ_PWRON1S_MASK
,
122 [S2MPS14_IRQ_MRB
] = {
124 .mask
= S2MPS11_IRQ_MRB_MASK
,
126 [S2MPS14_IRQ_RTC60S
] = {
128 .mask
= S2MPS11_IRQ_RTC60S_MASK
,
130 [S2MPS14_IRQ_RTCA1
] = {
132 .mask
= S2MPS11_IRQ_RTCA1_MASK
,
134 [S2MPS14_IRQ_RTCA0
] = {
136 .mask
= S2MPS11_IRQ_RTCA0_MASK
,
138 [S2MPS14_IRQ_SMPL
] = {
140 .mask
= S2MPS11_IRQ_SMPL_MASK
,
142 [S2MPS14_IRQ_RTC1S
] = {
144 .mask
= S2MPS11_IRQ_RTC1S_MASK
,
146 [S2MPS14_IRQ_WTSR
] = {
148 .mask
= S2MPS11_IRQ_WTSR_MASK
,
150 [S2MPS14_IRQ_INT120C
] = {
152 .mask
= S2MPS11_IRQ_INT120C_MASK
,
154 [S2MPS14_IRQ_INT140C
] = {
156 .mask
= S2MPS11_IRQ_INT140C_MASK
,
158 [S2MPS14_IRQ_TSD
] = {
160 .mask
= S2MPS14_IRQ_TSD_MASK
,
164 static const struct regmap_irq s5m8767_irqs
[] = {
165 [S5M8767_IRQ_PWRR
] = {
167 .mask
= S5M8767_IRQ_PWRR_MASK
,
169 [S5M8767_IRQ_PWRF
] = {
171 .mask
= S5M8767_IRQ_PWRF_MASK
,
173 [S5M8767_IRQ_PWR1S
] = {
175 .mask
= S5M8767_IRQ_PWR1S_MASK
,
177 [S5M8767_IRQ_JIGR
] = {
179 .mask
= S5M8767_IRQ_JIGR_MASK
,
181 [S5M8767_IRQ_JIGF
] = {
183 .mask
= S5M8767_IRQ_JIGF_MASK
,
185 [S5M8767_IRQ_LOWBAT2
] = {
187 .mask
= S5M8767_IRQ_LOWBAT2_MASK
,
189 [S5M8767_IRQ_LOWBAT1
] = {
191 .mask
= S5M8767_IRQ_LOWBAT1_MASK
,
193 [S5M8767_IRQ_MRB
] = {
195 .mask
= S5M8767_IRQ_MRB_MASK
,
197 [S5M8767_IRQ_DVSOK2
] = {
199 .mask
= S5M8767_IRQ_DVSOK2_MASK
,
201 [S5M8767_IRQ_DVSOK3
] = {
203 .mask
= S5M8767_IRQ_DVSOK3_MASK
,
205 [S5M8767_IRQ_DVSOK4
] = {
207 .mask
= S5M8767_IRQ_DVSOK4_MASK
,
209 [S5M8767_IRQ_RTC60S
] = {
211 .mask
= S5M8767_IRQ_RTC60S_MASK
,
213 [S5M8767_IRQ_RTCA1
] = {
215 .mask
= S5M8767_IRQ_RTCA1_MASK
,
217 [S5M8767_IRQ_RTCA2
] = {
219 .mask
= S5M8767_IRQ_RTCA2_MASK
,
221 [S5M8767_IRQ_SMPL
] = {
223 .mask
= S5M8767_IRQ_SMPL_MASK
,
225 [S5M8767_IRQ_RTC1S
] = {
227 .mask
= S5M8767_IRQ_RTC1S_MASK
,
229 [S5M8767_IRQ_WTSR
] = {
231 .mask
= S5M8767_IRQ_WTSR_MASK
,
235 static const struct regmap_irq s5m8763_irqs
[] = {
236 [S5M8763_IRQ_DCINF
] = {
238 .mask
= S5M8763_IRQ_DCINF_MASK
,
240 [S5M8763_IRQ_DCINR
] = {
242 .mask
= S5M8763_IRQ_DCINR_MASK
,
244 [S5M8763_IRQ_JIGF
] = {
246 .mask
= S5M8763_IRQ_JIGF_MASK
,
248 [S5M8763_IRQ_JIGR
] = {
250 .mask
= S5M8763_IRQ_JIGR_MASK
,
252 [S5M8763_IRQ_PWRONF
] = {
254 .mask
= S5M8763_IRQ_PWRONF_MASK
,
256 [S5M8763_IRQ_PWRONR
] = {
258 .mask
= S5M8763_IRQ_PWRONR_MASK
,
260 [S5M8763_IRQ_WTSREVNT
] = {
262 .mask
= S5M8763_IRQ_WTSREVNT_MASK
,
264 [S5M8763_IRQ_SMPLEVNT
] = {
266 .mask
= S5M8763_IRQ_SMPLEVNT_MASK
,
268 [S5M8763_IRQ_ALARM1
] = {
270 .mask
= S5M8763_IRQ_ALARM1_MASK
,
272 [S5M8763_IRQ_ALARM0
] = {
274 .mask
= S5M8763_IRQ_ALARM0_MASK
,
276 [S5M8763_IRQ_ONKEY1S
] = {
278 .mask
= S5M8763_IRQ_ONKEY1S_MASK
,
280 [S5M8763_IRQ_TOPOFFR
] = {
282 .mask
= S5M8763_IRQ_TOPOFFR_MASK
,
284 [S5M8763_IRQ_DCINOVPR
] = {
286 .mask
= S5M8763_IRQ_DCINOVPR_MASK
,
288 [S5M8763_IRQ_CHGRSTF
] = {
290 .mask
= S5M8763_IRQ_CHGRSTF_MASK
,
292 [S5M8763_IRQ_DONER
] = {
294 .mask
= S5M8763_IRQ_DONER_MASK
,
296 [S5M8763_IRQ_CHGFAULT
] = {
298 .mask
= S5M8763_IRQ_CHGFAULT_MASK
,
300 [S5M8763_IRQ_LOBAT1
] = {
302 .mask
= S5M8763_IRQ_LOBAT1_MASK
,
304 [S5M8763_IRQ_LOBAT2
] = {
306 .mask
= S5M8763_IRQ_LOBAT2_MASK
,
310 static const struct regmap_irq_chip s2mps11_irq_chip
= {
312 .irqs
= s2mps11_irqs
,
313 .num_irqs
= ARRAY_SIZE(s2mps11_irqs
),
315 .status_base
= S2MPS11_REG_INT1
,
316 .mask_base
= S2MPS11_REG_INT1M
,
317 .ack_base
= S2MPS11_REG_INT1
,
320 static const struct regmap_irq_chip s2mps14_irq_chip
= {
322 .irqs
= s2mps14_irqs
,
323 .num_irqs
= ARRAY_SIZE(s2mps14_irqs
),
325 .status_base
= S2MPS14_REG_INT1
,
326 .mask_base
= S2MPS14_REG_INT1M
,
327 .ack_base
= S2MPS14_REG_INT1
,
330 static const struct regmap_irq_chip s5m8767_irq_chip
= {
332 .irqs
= s5m8767_irqs
,
333 .num_irqs
= ARRAY_SIZE(s5m8767_irqs
),
335 .status_base
= S5M8767_REG_INT1
,
336 .mask_base
= S5M8767_REG_INT1M
,
337 .ack_base
= S5M8767_REG_INT1
,
340 static const struct regmap_irq_chip s5m8763_irq_chip
= {
342 .irqs
= s5m8763_irqs
,
343 .num_irqs
= ARRAY_SIZE(s5m8763_irqs
),
345 .status_base
= S5M8763_REG_IRQ1
,
346 .mask_base
= S5M8763_REG_IRQM1
,
347 .ack_base
= S5M8763_REG_IRQ1
,
350 int sec_irq_init(struct sec_pmic_dev
*sec_pmic
)
353 int type
= sec_pmic
->device_type
;
355 if (!sec_pmic
->irq
) {
356 dev_warn(sec_pmic
->dev
,
357 "No interrupt specified, no interrupts\n");
358 sec_pmic
->irq_base
= 0;
364 ret
= regmap_add_irq_chip(sec_pmic
->regmap_pmic
, sec_pmic
->irq
,
365 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
366 sec_pmic
->irq_base
, &s5m8763_irq_chip
,
367 &sec_pmic
->irq_data
);
370 ret
= regmap_add_irq_chip(sec_pmic
->regmap_pmic
, sec_pmic
->irq
,
371 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
372 sec_pmic
->irq_base
, &s5m8767_irq_chip
,
373 &sec_pmic
->irq_data
);
376 ret
= regmap_add_irq_chip(sec_pmic
->regmap_pmic
, sec_pmic
->irq
,
377 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
378 sec_pmic
->irq_base
, &s2mps11_irq_chip
,
379 &sec_pmic
->irq_data
);
382 ret
= regmap_add_irq_chip(sec_pmic
->regmap_pmic
, sec_pmic
->irq
,
383 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
384 sec_pmic
->irq_base
, &s2mps14_irq_chip
,
385 &sec_pmic
->irq_data
);
388 dev_err(sec_pmic
->dev
, "Unknown device type %lu\n",
389 sec_pmic
->device_type
);
394 dev_err(sec_pmic
->dev
, "Failed to register IRQ chip: %d\n", ret
);
401 void sec_irq_exit(struct sec_pmic_dev
*sec_pmic
)
403 regmap_del_irq_chip(sec_pmic
->irq
, sec_pmic
->irq_data
);