1 // SPDX-License-Identifier: GPL-2.0-only
3 * DA9052 interrupt support
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
6 * Based on arizona-irq.c, which is:
8 * Copyright 2012 Wolfson Microelectronics plc
10 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
13 #include <linux/device.h>
14 #include <linux/delay.h>
15 #include <linux/input.h>
16 #include <linux/interrupt.h>
17 #include <linux/irq.h>
18 #include <linux/irqdomain.h>
19 #include <linux/slab.h>
20 #include <linux/module.h>
22 #include <linux/mfd/da9052/da9052.h>
23 #include <linux/mfd/da9052/reg.h>
25 #define DA9052_NUM_IRQ_REGS 4
26 #define DA9052_IRQ_MASK_POS_1 0x01
27 #define DA9052_IRQ_MASK_POS_2 0x02
28 #define DA9052_IRQ_MASK_POS_3 0x04
29 #define DA9052_IRQ_MASK_POS_4 0x08
30 #define DA9052_IRQ_MASK_POS_5 0x10
31 #define DA9052_IRQ_MASK_POS_6 0x20
32 #define DA9052_IRQ_MASK_POS_7 0x40
33 #define DA9052_IRQ_MASK_POS_8 0x80
35 static const struct regmap_irq da9052_irqs
[] = {
38 .mask
= DA9052_IRQ_MASK_POS_1
,
42 .mask
= DA9052_IRQ_MASK_POS_2
,
44 [DA9052_IRQ_DCINREM
] = {
46 .mask
= DA9052_IRQ_MASK_POS_3
,
48 [DA9052_IRQ_VBUSREM
] = {
50 .mask
= DA9052_IRQ_MASK_POS_4
,
52 [DA9052_IRQ_VDDLOW
] = {
54 .mask
= DA9052_IRQ_MASK_POS_5
,
56 [DA9052_IRQ_ALARM
] = {
58 .mask
= DA9052_IRQ_MASK_POS_6
,
60 [DA9052_IRQ_SEQRDY
] = {
62 .mask
= DA9052_IRQ_MASK_POS_7
,
64 [DA9052_IRQ_COMP1V2
] = {
66 .mask
= DA9052_IRQ_MASK_POS_8
,
68 [DA9052_IRQ_NONKEY
] = {
70 .mask
= DA9052_IRQ_MASK_POS_1
,
72 [DA9052_IRQ_IDFLOAT
] = {
74 .mask
= DA9052_IRQ_MASK_POS_2
,
76 [DA9052_IRQ_IDGND
] = {
78 .mask
= DA9052_IRQ_MASK_POS_3
,
80 [DA9052_IRQ_CHGEND
] = {
82 .mask
= DA9052_IRQ_MASK_POS_4
,
86 .mask
= DA9052_IRQ_MASK_POS_5
,
88 [DA9052_IRQ_ADC_EOM
] = {
90 .mask
= DA9052_IRQ_MASK_POS_6
,
92 [DA9052_IRQ_PENDOWN
] = {
94 .mask
= DA9052_IRQ_MASK_POS_7
,
96 [DA9052_IRQ_TSIREADY
] = {
98 .mask
= DA9052_IRQ_MASK_POS_8
,
100 [DA9052_IRQ_GPI0
] = {
102 .mask
= DA9052_IRQ_MASK_POS_1
,
104 [DA9052_IRQ_GPI1
] = {
106 .mask
= DA9052_IRQ_MASK_POS_2
,
108 [DA9052_IRQ_GPI2
] = {
110 .mask
= DA9052_IRQ_MASK_POS_3
,
112 [DA9052_IRQ_GPI3
] = {
114 .mask
= DA9052_IRQ_MASK_POS_4
,
116 [DA9052_IRQ_GPI4
] = {
118 .mask
= DA9052_IRQ_MASK_POS_5
,
120 [DA9052_IRQ_GPI5
] = {
122 .mask
= DA9052_IRQ_MASK_POS_6
,
124 [DA9052_IRQ_GPI6
] = {
126 .mask
= DA9052_IRQ_MASK_POS_7
,
128 [DA9052_IRQ_GPI7
] = {
130 .mask
= DA9052_IRQ_MASK_POS_8
,
132 [DA9052_IRQ_GPI8
] = {
134 .mask
= DA9052_IRQ_MASK_POS_1
,
136 [DA9052_IRQ_GPI9
] = {
138 .mask
= DA9052_IRQ_MASK_POS_2
,
140 [DA9052_IRQ_GPI10
] = {
142 .mask
= DA9052_IRQ_MASK_POS_3
,
144 [DA9052_IRQ_GPI11
] = {
146 .mask
= DA9052_IRQ_MASK_POS_4
,
148 [DA9052_IRQ_GPI12
] = {
150 .mask
= DA9052_IRQ_MASK_POS_5
,
152 [DA9052_IRQ_GPI13
] = {
154 .mask
= DA9052_IRQ_MASK_POS_6
,
156 [DA9052_IRQ_GPI14
] = {
158 .mask
= DA9052_IRQ_MASK_POS_7
,
160 [DA9052_IRQ_GPI15
] = {
162 .mask
= DA9052_IRQ_MASK_POS_8
,
166 static const struct regmap_irq_chip da9052_regmap_irq_chip
= {
167 .name
= "da9052_irq",
168 .status_base
= DA9052_EVENT_A_REG
,
169 .mask_base
= DA9052_IRQ_MASK_A_REG
,
170 .ack_base
= DA9052_EVENT_A_REG
,
171 .num_regs
= DA9052_NUM_IRQ_REGS
,
173 .num_irqs
= ARRAY_SIZE(da9052_irqs
),
176 static int da9052_map_irq(struct da9052
*da9052
, int irq
)
178 return regmap_irq_get_virq(da9052
->irq_data
, irq
);
181 int da9052_enable_irq(struct da9052
*da9052
, int irq
)
183 irq
= da9052_map_irq(da9052
, irq
);
191 EXPORT_SYMBOL_GPL(da9052_enable_irq
);
193 int da9052_disable_irq(struct da9052
*da9052
, int irq
)
195 irq
= da9052_map_irq(da9052
, irq
);
203 EXPORT_SYMBOL_GPL(da9052_disable_irq
);
205 int da9052_disable_irq_nosync(struct da9052
*da9052
, int irq
)
207 irq
= da9052_map_irq(da9052
, irq
);
211 disable_irq_nosync(irq
);
215 EXPORT_SYMBOL_GPL(da9052_disable_irq_nosync
);
217 int da9052_request_irq(struct da9052
*da9052
, int irq
, char *name
,
218 irq_handler_t handler
, void *data
)
220 irq
= da9052_map_irq(da9052
, irq
);
224 return request_threaded_irq(irq
, NULL
, handler
,
225 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
228 EXPORT_SYMBOL_GPL(da9052_request_irq
);
230 void da9052_free_irq(struct da9052
*da9052
, int irq
, void *data
)
232 irq
= da9052_map_irq(da9052
, irq
);
238 EXPORT_SYMBOL_GPL(da9052_free_irq
);
240 static irqreturn_t
da9052_auxadc_irq(int irq
, void *irq_data
)
242 struct da9052
*da9052
= irq_data
;
244 complete(&da9052
->done
);
249 int da9052_irq_init(struct da9052
*da9052
)
253 ret
= regmap_add_irq_chip(da9052
->regmap
, da9052
->chip_irq
,
254 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
255 -1, &da9052_regmap_irq_chip
,
258 dev_err(da9052
->dev
, "regmap_add_irq_chip failed: %d\n", ret
);
262 enable_irq_wake(da9052
->chip_irq
);
264 ret
= da9052_request_irq(da9052
, DA9052_IRQ_ADC_EOM
, "adc-irq",
265 da9052_auxadc_irq
, da9052
);
268 dev_err(da9052
->dev
, "DA9052_IRQ_ADC_EOM failed: %d\n", ret
);
269 goto request_irq_err
;
275 regmap_del_irq_chip(da9052
->chip_irq
, da9052
->irq_data
);
281 int da9052_irq_exit(struct da9052
*da9052
)
283 da9052_free_irq(da9052
, DA9052_IRQ_ADC_EOM
, da9052
);
284 regmap_del_irq_chip(da9052
->chip_irq
, da9052
->irq_data
);