2 * DA9052 interrupt support
4 * Author: Fabio Estevam <fabio.estevam@freescale.com>
5 * Based on arizona-irq.c, which is:
7 * Copyright 2012 Wolfson Microelectronics plc
9 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/device.h>
17 #include <linux/delay.h>
18 #include <linux/input.h>
19 #include <linux/interrupt.h>
20 #include <linux/irq.h>
21 #include <linux/irqdomain.h>
22 #include <linux/slab.h>
23 #include <linux/module.h>
25 #include <linux/mfd/da9052/da9052.h>
26 #include <linux/mfd/da9052/reg.h>
28 #define DA9052_NUM_IRQ_REGS 4
29 #define DA9052_IRQ_MASK_POS_1 0x01
30 #define DA9052_IRQ_MASK_POS_2 0x02
31 #define DA9052_IRQ_MASK_POS_3 0x04
32 #define DA9052_IRQ_MASK_POS_4 0x08
33 #define DA9052_IRQ_MASK_POS_5 0x10
34 #define DA9052_IRQ_MASK_POS_6 0x20
35 #define DA9052_IRQ_MASK_POS_7 0x40
36 #define DA9052_IRQ_MASK_POS_8 0x80
38 static struct regmap_irq da9052_irqs
[] = {
41 .mask
= DA9052_IRQ_MASK_POS_1
,
45 .mask
= DA9052_IRQ_MASK_POS_2
,
47 [DA9052_IRQ_DCINREM
] = {
49 .mask
= DA9052_IRQ_MASK_POS_3
,
51 [DA9052_IRQ_VBUSREM
] = {
53 .mask
= DA9052_IRQ_MASK_POS_4
,
55 [DA9052_IRQ_VDDLOW
] = {
57 .mask
= DA9052_IRQ_MASK_POS_5
,
59 [DA9052_IRQ_ALARM
] = {
61 .mask
= DA9052_IRQ_MASK_POS_6
,
63 [DA9052_IRQ_SEQRDY
] = {
65 .mask
= DA9052_IRQ_MASK_POS_7
,
67 [DA9052_IRQ_COMP1V2
] = {
69 .mask
= DA9052_IRQ_MASK_POS_8
,
71 [DA9052_IRQ_NONKEY
] = {
73 .mask
= DA9052_IRQ_MASK_POS_1
,
75 [DA9052_IRQ_IDFLOAT
] = {
77 .mask
= DA9052_IRQ_MASK_POS_2
,
79 [DA9052_IRQ_IDGND
] = {
81 .mask
= DA9052_IRQ_MASK_POS_3
,
83 [DA9052_IRQ_CHGEND
] = {
85 .mask
= DA9052_IRQ_MASK_POS_4
,
89 .mask
= DA9052_IRQ_MASK_POS_5
,
91 [DA9052_IRQ_ADC_EOM
] = {
93 .mask
= DA9052_IRQ_MASK_POS_6
,
95 [DA9052_IRQ_PENDOWN
] = {
97 .mask
= DA9052_IRQ_MASK_POS_7
,
99 [DA9052_IRQ_TSIREADY
] = {
101 .mask
= DA9052_IRQ_MASK_POS_8
,
103 [DA9052_IRQ_GPI0
] = {
105 .mask
= DA9052_IRQ_MASK_POS_1
,
107 [DA9052_IRQ_GPI1
] = {
109 .mask
= DA9052_IRQ_MASK_POS_2
,
111 [DA9052_IRQ_GPI2
] = {
113 .mask
= DA9052_IRQ_MASK_POS_3
,
115 [DA9052_IRQ_GPI3
] = {
117 .mask
= DA9052_IRQ_MASK_POS_4
,
119 [DA9052_IRQ_GPI4
] = {
121 .mask
= DA9052_IRQ_MASK_POS_5
,
123 [DA9052_IRQ_GPI5
] = {
125 .mask
= DA9052_IRQ_MASK_POS_6
,
127 [DA9052_IRQ_GPI6
] = {
129 .mask
= DA9052_IRQ_MASK_POS_7
,
131 [DA9052_IRQ_GPI7
] = {
133 .mask
= DA9052_IRQ_MASK_POS_8
,
135 [DA9052_IRQ_GPI8
] = {
137 .mask
= DA9052_IRQ_MASK_POS_1
,
139 [DA9052_IRQ_GPI9
] = {
141 .mask
= DA9052_IRQ_MASK_POS_2
,
143 [DA9052_IRQ_GPI10
] = {
145 .mask
= DA9052_IRQ_MASK_POS_3
,
147 [DA9052_IRQ_GPI11
] = {
149 .mask
= DA9052_IRQ_MASK_POS_4
,
151 [DA9052_IRQ_GPI12
] = {
153 .mask
= DA9052_IRQ_MASK_POS_5
,
155 [DA9052_IRQ_GPI13
] = {
157 .mask
= DA9052_IRQ_MASK_POS_6
,
159 [DA9052_IRQ_GPI14
] = {
161 .mask
= DA9052_IRQ_MASK_POS_7
,
163 [DA9052_IRQ_GPI15
] = {
165 .mask
= DA9052_IRQ_MASK_POS_8
,
169 static struct regmap_irq_chip da9052_regmap_irq_chip
= {
170 .name
= "da9052_irq",
171 .status_base
= DA9052_EVENT_A_REG
,
172 .mask_base
= DA9052_IRQ_MASK_A_REG
,
173 .ack_base
= DA9052_EVENT_A_REG
,
174 .num_regs
= DA9052_NUM_IRQ_REGS
,
176 .num_irqs
= ARRAY_SIZE(da9052_irqs
),
179 static int da9052_map_irq(struct da9052
*da9052
, int irq
)
181 return regmap_irq_get_virq(da9052
->irq_data
, irq
);
184 int da9052_enable_irq(struct da9052
*da9052
, int irq
)
186 irq
= da9052_map_irq(da9052
, irq
);
194 EXPORT_SYMBOL_GPL(da9052_enable_irq
);
196 int da9052_disable_irq(struct da9052
*da9052
, int irq
)
198 irq
= da9052_map_irq(da9052
, irq
);
206 EXPORT_SYMBOL_GPL(da9052_disable_irq
);
208 int da9052_disable_irq_nosync(struct da9052
*da9052
, int irq
)
210 irq
= da9052_map_irq(da9052
, irq
);
214 disable_irq_nosync(irq
);
218 EXPORT_SYMBOL_GPL(da9052_disable_irq_nosync
);
220 int da9052_request_irq(struct da9052
*da9052
, int irq
, char *name
,
221 irq_handler_t handler
, void *data
)
223 irq
= da9052_map_irq(da9052
, irq
);
227 return request_threaded_irq(irq
, NULL
, handler
,
228 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
231 EXPORT_SYMBOL_GPL(da9052_request_irq
);
233 void da9052_free_irq(struct da9052
*da9052
, int irq
, void *data
)
235 irq
= da9052_map_irq(da9052
, irq
);
241 EXPORT_SYMBOL_GPL(da9052_free_irq
);
243 static irqreturn_t
da9052_auxadc_irq(int irq
, void *irq_data
)
245 struct da9052
*da9052
= irq_data
;
247 complete(&da9052
->done
);
252 int da9052_irq_init(struct da9052
*da9052
)
256 ret
= regmap_add_irq_chip(da9052
->regmap
, da9052
->chip_irq
,
257 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
,
258 -1, &da9052_regmap_irq_chip
,
261 dev_err(da9052
->dev
, "regmap_add_irq_chip failed: %d\n", ret
);
265 enable_irq_wake(da9052
->chip_irq
);
267 ret
= da9052_request_irq(da9052
, DA9052_IRQ_ADC_EOM
, "adc-irq",
268 da9052_auxadc_irq
, da9052
);
271 dev_err(da9052
->dev
, "DA9052_IRQ_ADC_EOM failed: %d\n", ret
);
272 goto request_irq_err
;
278 regmap_del_irq_chip(da9052
->chip_irq
, da9052
->irq_data
);
284 int da9052_irq_exit(struct da9052
*da9052
)
286 da9052_free_irq(da9052
, DA9052_IRQ_ADC_EOM
, da9052
);
287 regmap_del_irq_chip(da9052
->chip_irq
, da9052
->irq_data
);