1 // SPDX-License-Identifier: GPL-2.0+
3 // Copyright (c) 2011-2014 Samsung Electronics Co., Ltd
4 // http://www.samsung.com
6 #include <linux/device.h>
7 #include <linux/interrupt.h>
9 #include <linux/module.h>
10 #include <linux/regmap.h>
12 #include <linux/mfd/samsung/core.h>
13 #include <linux/mfd/samsung/irq.h>
14 #include <linux/mfd/samsung/s2mps11.h>
15 #include <linux/mfd/samsung/s2mps14.h>
16 #include <linux/mfd/samsung/s2mpu02.h>
17 #include <linux/mfd/samsung/s5m8767.h>
19 static const struct regmap_irq s2mps11_irqs
[] = {
20 [S2MPS11_IRQ_PWRONF
] = {
22 .mask
= S2MPS11_IRQ_PWRONF_MASK
,
24 [S2MPS11_IRQ_PWRONR
] = {
26 .mask
= S2MPS11_IRQ_PWRONR_MASK
,
28 [S2MPS11_IRQ_JIGONBF
] = {
30 .mask
= S2MPS11_IRQ_JIGONBF_MASK
,
32 [S2MPS11_IRQ_JIGONBR
] = {
34 .mask
= S2MPS11_IRQ_JIGONBR_MASK
,
36 [S2MPS11_IRQ_ACOKBF
] = {
38 .mask
= S2MPS11_IRQ_ACOKBF_MASK
,
40 [S2MPS11_IRQ_ACOKBR
] = {
42 .mask
= S2MPS11_IRQ_ACOKBR_MASK
,
44 [S2MPS11_IRQ_PWRON1S
] = {
46 .mask
= S2MPS11_IRQ_PWRON1S_MASK
,
50 .mask
= S2MPS11_IRQ_MRB_MASK
,
52 [S2MPS11_IRQ_RTC60S
] = {
54 .mask
= S2MPS11_IRQ_RTC60S_MASK
,
56 [S2MPS11_IRQ_RTCA1
] = {
58 .mask
= S2MPS11_IRQ_RTCA1_MASK
,
60 [S2MPS11_IRQ_RTCA0
] = {
62 .mask
= S2MPS11_IRQ_RTCA0_MASK
,
64 [S2MPS11_IRQ_SMPL
] = {
66 .mask
= S2MPS11_IRQ_SMPL_MASK
,
68 [S2MPS11_IRQ_RTC1S
] = {
70 .mask
= S2MPS11_IRQ_RTC1S_MASK
,
72 [S2MPS11_IRQ_WTSR
] = {
74 .mask
= S2MPS11_IRQ_WTSR_MASK
,
76 [S2MPS11_IRQ_INT120C
] = {
78 .mask
= S2MPS11_IRQ_INT120C_MASK
,
80 [S2MPS11_IRQ_INT140C
] = {
82 .mask
= S2MPS11_IRQ_INT140C_MASK
,
86 static const struct regmap_irq s2mps14_irqs
[] = {
87 [S2MPS14_IRQ_PWRONF
] = {
89 .mask
= S2MPS11_IRQ_PWRONF_MASK
,
91 [S2MPS14_IRQ_PWRONR
] = {
93 .mask
= S2MPS11_IRQ_PWRONR_MASK
,
95 [S2MPS14_IRQ_JIGONBF
] = {
97 .mask
= S2MPS11_IRQ_JIGONBF_MASK
,
99 [S2MPS14_IRQ_JIGONBR
] = {
101 .mask
= S2MPS11_IRQ_JIGONBR_MASK
,
103 [S2MPS14_IRQ_ACOKBF
] = {
105 .mask
= S2MPS11_IRQ_ACOKBF_MASK
,
107 [S2MPS14_IRQ_ACOKBR
] = {
109 .mask
= S2MPS11_IRQ_ACOKBR_MASK
,
111 [S2MPS14_IRQ_PWRON1S
] = {
113 .mask
= S2MPS11_IRQ_PWRON1S_MASK
,
115 [S2MPS14_IRQ_MRB
] = {
117 .mask
= S2MPS11_IRQ_MRB_MASK
,
119 [S2MPS14_IRQ_RTC60S
] = {
121 .mask
= S2MPS11_IRQ_RTC60S_MASK
,
123 [S2MPS14_IRQ_RTCA1
] = {
125 .mask
= S2MPS11_IRQ_RTCA1_MASK
,
127 [S2MPS14_IRQ_RTCA0
] = {
129 .mask
= S2MPS11_IRQ_RTCA0_MASK
,
131 [S2MPS14_IRQ_SMPL
] = {
133 .mask
= S2MPS11_IRQ_SMPL_MASK
,
135 [S2MPS14_IRQ_RTC1S
] = {
137 .mask
= S2MPS11_IRQ_RTC1S_MASK
,
139 [S2MPS14_IRQ_WTSR
] = {
141 .mask
= S2MPS11_IRQ_WTSR_MASK
,
143 [S2MPS14_IRQ_INT120C
] = {
145 .mask
= S2MPS11_IRQ_INT120C_MASK
,
147 [S2MPS14_IRQ_INT140C
] = {
149 .mask
= S2MPS11_IRQ_INT140C_MASK
,
151 [S2MPS14_IRQ_TSD
] = {
153 .mask
= S2MPS14_IRQ_TSD_MASK
,
157 static const struct regmap_irq s2mpu02_irqs
[] = {
158 [S2MPU02_IRQ_PWRONF
] = {
160 .mask
= S2MPS11_IRQ_PWRONF_MASK
,
162 [S2MPU02_IRQ_PWRONR
] = {
164 .mask
= S2MPS11_IRQ_PWRONR_MASK
,
166 [S2MPU02_IRQ_JIGONBF
] = {
168 .mask
= S2MPS11_IRQ_JIGONBF_MASK
,
170 [S2MPU02_IRQ_JIGONBR
] = {
172 .mask
= S2MPS11_IRQ_JIGONBR_MASK
,
174 [S2MPU02_IRQ_ACOKBF
] = {
176 .mask
= S2MPS11_IRQ_ACOKBF_MASK
,
178 [S2MPU02_IRQ_ACOKBR
] = {
180 .mask
= S2MPS11_IRQ_ACOKBR_MASK
,
182 [S2MPU02_IRQ_PWRON1S
] = {
184 .mask
= S2MPS11_IRQ_PWRON1S_MASK
,
186 [S2MPU02_IRQ_MRB
] = {
188 .mask
= S2MPS11_IRQ_MRB_MASK
,
190 [S2MPU02_IRQ_RTC60S
] = {
192 .mask
= S2MPS11_IRQ_RTC60S_MASK
,
194 [S2MPU02_IRQ_RTCA1
] = {
196 .mask
= S2MPS11_IRQ_RTCA1_MASK
,
198 [S2MPU02_IRQ_RTCA0
] = {
200 .mask
= S2MPS11_IRQ_RTCA0_MASK
,
202 [S2MPU02_IRQ_SMPL
] = {
204 .mask
= S2MPS11_IRQ_SMPL_MASK
,
206 [S2MPU02_IRQ_RTC1S
] = {
208 .mask
= S2MPS11_IRQ_RTC1S_MASK
,
210 [S2MPU02_IRQ_WTSR
] = {
212 .mask
= S2MPS11_IRQ_WTSR_MASK
,
214 [S2MPU02_IRQ_INT120C
] = {
216 .mask
= S2MPS11_IRQ_INT120C_MASK
,
218 [S2MPU02_IRQ_INT140C
] = {
220 .mask
= S2MPS11_IRQ_INT140C_MASK
,
222 [S2MPU02_IRQ_TSD
] = {
224 .mask
= S2MPS14_IRQ_TSD_MASK
,
228 static const struct regmap_irq s5m8767_irqs
[] = {
229 [S5M8767_IRQ_PWRR
] = {
231 .mask
= S5M8767_IRQ_PWRR_MASK
,
233 [S5M8767_IRQ_PWRF
] = {
235 .mask
= S5M8767_IRQ_PWRF_MASK
,
237 [S5M8767_IRQ_PWR1S
] = {
239 .mask
= S5M8767_IRQ_PWR1S_MASK
,
241 [S5M8767_IRQ_JIGR
] = {
243 .mask
= S5M8767_IRQ_JIGR_MASK
,
245 [S5M8767_IRQ_JIGF
] = {
247 .mask
= S5M8767_IRQ_JIGF_MASK
,
249 [S5M8767_IRQ_LOWBAT2
] = {
251 .mask
= S5M8767_IRQ_LOWBAT2_MASK
,
253 [S5M8767_IRQ_LOWBAT1
] = {
255 .mask
= S5M8767_IRQ_LOWBAT1_MASK
,
257 [S5M8767_IRQ_MRB
] = {
259 .mask
= S5M8767_IRQ_MRB_MASK
,
261 [S5M8767_IRQ_DVSOK2
] = {
263 .mask
= S5M8767_IRQ_DVSOK2_MASK
,
265 [S5M8767_IRQ_DVSOK3
] = {
267 .mask
= S5M8767_IRQ_DVSOK3_MASK
,
269 [S5M8767_IRQ_DVSOK4
] = {
271 .mask
= S5M8767_IRQ_DVSOK4_MASK
,
273 [S5M8767_IRQ_RTC60S
] = {
275 .mask
= S5M8767_IRQ_RTC60S_MASK
,
277 [S5M8767_IRQ_RTCA1
] = {
279 .mask
= S5M8767_IRQ_RTCA1_MASK
,
281 [S5M8767_IRQ_RTCA2
] = {
283 .mask
= S5M8767_IRQ_RTCA2_MASK
,
285 [S5M8767_IRQ_SMPL
] = {
287 .mask
= S5M8767_IRQ_SMPL_MASK
,
289 [S5M8767_IRQ_RTC1S
] = {
291 .mask
= S5M8767_IRQ_RTC1S_MASK
,
293 [S5M8767_IRQ_WTSR
] = {
295 .mask
= S5M8767_IRQ_WTSR_MASK
,
299 static const struct regmap_irq_chip s2mps11_irq_chip
= {
301 .irqs
= s2mps11_irqs
,
302 .num_irqs
= ARRAY_SIZE(s2mps11_irqs
),
304 .status_base
= S2MPS11_REG_INT1
,
305 .mask_base
= S2MPS11_REG_INT1M
,
306 .ack_base
= S2MPS11_REG_INT1
,
309 #define S2MPS1X_IRQ_CHIP_COMMON_DATA \
310 .irqs = s2mps14_irqs, \
311 .num_irqs = ARRAY_SIZE(s2mps14_irqs), \
313 .status_base = S2MPS14_REG_INT1, \
314 .mask_base = S2MPS14_REG_INT1M, \
315 .ack_base = S2MPS14_REG_INT1 \
317 static const struct regmap_irq_chip s2mps13_irq_chip = {
319 S2MPS1X_IRQ_CHIP_COMMON_DATA
,
322 static const struct regmap_irq_chip s2mps14_irq_chip
= {
324 S2MPS1X_IRQ_CHIP_COMMON_DATA
,
327 static const struct regmap_irq_chip s2mps15_irq_chip
= {
329 S2MPS1X_IRQ_CHIP_COMMON_DATA
,
332 static const struct regmap_irq_chip s2mpu02_irq_chip
= {
334 .irqs
= s2mpu02_irqs
,
335 .num_irqs
= ARRAY_SIZE(s2mpu02_irqs
),
337 .status_base
= S2MPU02_REG_INT1
,
338 .mask_base
= S2MPU02_REG_INT1M
,
339 .ack_base
= S2MPU02_REG_INT1
,
342 static const struct regmap_irq_chip s5m8767_irq_chip
= {
344 .irqs
= s5m8767_irqs
,
345 .num_irqs
= ARRAY_SIZE(s5m8767_irqs
),
347 .status_base
= S5M8767_REG_INT1
,
348 .mask_base
= S5M8767_REG_INT1M
,
349 .ack_base
= S5M8767_REG_INT1
,
352 int sec_irq_init(struct sec_pmic_dev
*sec_pmic
)
355 int type
= sec_pmic
->device_type
;
356 const struct regmap_irq_chip
*sec_irq_chip
;
358 if (!sec_pmic
->irq
) {
359 dev_warn(sec_pmic
->dev
,
360 "No interrupt specified, no interrupts\n");
366 sec_irq_chip
= &s5m8767_irq_chip
;
369 sec_irq_chip
= &s2mps14_irq_chip
;
372 sec_irq_chip
= &s2mps11_irq_chip
;
375 sec_irq_chip
= &s2mps13_irq_chip
;
378 sec_irq_chip
= &s2mps14_irq_chip
;
381 sec_irq_chip
= &s2mps15_irq_chip
;
384 sec_irq_chip
= &s2mpu02_irq_chip
;
387 dev_err(sec_pmic
->dev
, "Unknown device type %lu\n",
388 sec_pmic
->device_type
);
392 ret
= devm_regmap_add_irq_chip(sec_pmic
->dev
, sec_pmic
->regmap_pmic
,
393 sec_pmic
->irq
, IRQF_ONESHOT
,
394 0, sec_irq_chip
, &sec_pmic
->irq_data
);
396 dev_err(sec_pmic
->dev
, "Failed to register IRQ chip: %d\n", ret
);
401 * The rtc-s5m driver requests S2MPS14_IRQ_RTCA0 also for S2MPS11
402 * so the interrupt number must be consistent.
404 BUILD_BUG_ON(((enum s2mps14_irq
)S2MPS11_IRQ_RTCA0
) != S2MPS14_IRQ_RTCA0
);
408 EXPORT_SYMBOL_GPL(sec_irq_init
);
410 MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
411 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
412 MODULE_AUTHOR("Krzysztof Kozlowski <krzk@kernel.org>");
413 MODULE_DESCRIPTION("Interrupt support for the S5M MFD");
414 MODULE_LICENSE("GPL");