xref: /linux/drivers/mfd/da9063-irq.c (revision 7494de0454af50215bc46c93c83b88a32ca39fab)
1a0e08b86SKrystian Garbaciak /* da9063-irq.c: Interrupts support for Dialog DA9063
2a0e08b86SKrystian Garbaciak  *
3a0e08b86SKrystian Garbaciak  * Copyright 2012 Dialog Semiconductor Ltd.
4a0e08b86SKrystian Garbaciak  * Copyright 2013 Philipp Zabel, Pengutronix
5a0e08b86SKrystian Garbaciak  *
637778d83SSteve Twiss  * Author: Michal Hajduk, Dialog Semiconductor
7a0e08b86SKrystian Garbaciak  *
8a0e08b86SKrystian Garbaciak  *  This program is free software; you can redistribute  it and/or modify it
9a0e08b86SKrystian Garbaciak  *  under  the terms of  the GNU General  Public License as published by the
10a0e08b86SKrystian Garbaciak  *  Free Software Foundation;  either version 2 of the  License, or (at your
11a0e08b86SKrystian Garbaciak  *  option) any later version.
12a0e08b86SKrystian Garbaciak  *
13a0e08b86SKrystian Garbaciak  */
14a0e08b86SKrystian Garbaciak 
15a0e08b86SKrystian Garbaciak #include <linux/kernel.h>
16a0e08b86SKrystian Garbaciak #include <linux/module.h>
17a0e08b86SKrystian Garbaciak #include <linux/irq.h>
18a0e08b86SKrystian Garbaciak #include <linux/mfd/core.h>
19a0e08b86SKrystian Garbaciak #include <linux/interrupt.h>
20a0e08b86SKrystian Garbaciak #include <linux/regmap.h>
21a0e08b86SKrystian Garbaciak #include <linux/mfd/da9063/core.h>
22a0e08b86SKrystian Garbaciak #include <linux/mfd/da9063/pdata.h>
23a0e08b86SKrystian Garbaciak 
24a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_A_OFFSET	0
25a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_B_OFFSET	1
26a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_C_OFFSET	2
27a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_D_OFFSET	3
28a0e08b86SKrystian Garbaciak 
297ce7b26fSKrzysztof Kozlowski static const struct regmap_irq da9063_irqs[] = {
30a0e08b86SKrystian Garbaciak 	/* DA9063 event A register */
31a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_ONKEY] = {
32a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_A_OFFSET,
33a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_ONKEY,
34a0e08b86SKrystian Garbaciak 	},
35a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_ALARM] = {
36a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_A_OFFSET,
37a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_ALARM,
38a0e08b86SKrystian Garbaciak 	},
39a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_TICK] = {
40a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_A_OFFSET,
41a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_TICK,
42a0e08b86SKrystian Garbaciak 	},
43a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_ADC_RDY] = {
44a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_A_OFFSET,
45a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_ADC_RDY,
46a0e08b86SKrystian Garbaciak 	},
47a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_SEQ_RDY] = {
48a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_A_OFFSET,
49a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_SEQ_RDY,
50a0e08b86SKrystian Garbaciak 	},
51a0e08b86SKrystian Garbaciak 	/* DA9063 event B register */
52a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_WAKE] = {
53a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_B_OFFSET,
54a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_WAKE,
55a0e08b86SKrystian Garbaciak 	},
56a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_TEMP] = {
57a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_B_OFFSET,
58a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_TEMP,
59a0e08b86SKrystian Garbaciak 	},
60a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_COMP_1V2] = {
61a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_B_OFFSET,
62a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_COMP_1V2,
63a0e08b86SKrystian Garbaciak 	},
64a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_LDO_LIM] = {
65a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_B_OFFSET,
66a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_LDO_LIM,
67a0e08b86SKrystian Garbaciak 	},
68a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_REG_UVOV] = {
69a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_B_OFFSET,
70a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_UVOV,
71a0e08b86SKrystian Garbaciak 	},
7203b42710SSteve Twiss 	[DA9063_IRQ_DVC_RDY] = {
7303b42710SSteve Twiss 		.reg_offset = DA9063_REG_EVENT_B_OFFSET,
7403b42710SSteve Twiss 		.mask = DA9063_M_DVC_RDY,
7503b42710SSteve Twiss 	},
76a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_VDD_MON] = {
77a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_B_OFFSET,
78a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_VDD_MON,
79a0e08b86SKrystian Garbaciak 	},
80a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_WARN] = {
81a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_B_OFFSET,
82a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_VDD_WARN,
83a0e08b86SKrystian Garbaciak 	},
84a0e08b86SKrystian Garbaciak 	/* DA9063 event C register */
85a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI0] = {
86a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_C_OFFSET,
87a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI0,
88a0e08b86SKrystian Garbaciak 	},
89a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI1] = {
90a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_C_OFFSET,
91a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI1,
92a0e08b86SKrystian Garbaciak 	},
93a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI2] = {
94a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_C_OFFSET,
95a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI2,
96a0e08b86SKrystian Garbaciak 	},
97a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI3] = {
98a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_C_OFFSET,
99a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI3,
100a0e08b86SKrystian Garbaciak 	},
101a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI4] = {
102a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_C_OFFSET,
103a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI4,
104a0e08b86SKrystian Garbaciak 	},
105a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI5] = {
106a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_C_OFFSET,
107a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI5,
108a0e08b86SKrystian Garbaciak 	},
109a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI6] = {
110a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_C_OFFSET,
111a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI6,
112a0e08b86SKrystian Garbaciak 	},
113a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI7] = {
114a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_C_OFFSET,
115a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI7,
116a0e08b86SKrystian Garbaciak 	},
117a0e08b86SKrystian Garbaciak 	/* DA9063 event D register */
118a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI8] = {
119a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_D_OFFSET,
120a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI8,
121a0e08b86SKrystian Garbaciak 	},
122a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI9] = {
123a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_D_OFFSET,
124a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI9,
125a0e08b86SKrystian Garbaciak 	},
126a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI10] = {
127a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_D_OFFSET,
128a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI10,
129a0e08b86SKrystian Garbaciak 	},
130a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI11] = {
131a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_D_OFFSET,
132a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI11,
133a0e08b86SKrystian Garbaciak 	},
134a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI12] = {
135a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_D_OFFSET,
136a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI12,
137a0e08b86SKrystian Garbaciak 	},
138a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI13] = {
139a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_D_OFFSET,
140a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI13,
141a0e08b86SKrystian Garbaciak 	},
142a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI14] = {
143a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_D_OFFSET,
144a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI14,
145a0e08b86SKrystian Garbaciak 	},
146a0e08b86SKrystian Garbaciak 	[DA9063_IRQ_GPI15] = {
147a0e08b86SKrystian Garbaciak 		.reg_offset = DA9063_REG_EVENT_D_OFFSET,
148a0e08b86SKrystian Garbaciak 		.mask = DA9063_M_GPI15,
149a0e08b86SKrystian Garbaciak 	},
150a0e08b86SKrystian Garbaciak };
151a0e08b86SKrystian Garbaciak 
1527ce7b26fSKrzysztof Kozlowski static const struct regmap_irq_chip da9063_irq_chip = {
153a0e08b86SKrystian Garbaciak 	.name = "da9063-irq",
154a0e08b86SKrystian Garbaciak 	.irqs = da9063_irqs,
155a0e08b86SKrystian Garbaciak 	.num_irqs = DA9063_NUM_IRQ,
156a0e08b86SKrystian Garbaciak 
157a0e08b86SKrystian Garbaciak 	.num_regs = 4,
158a0e08b86SKrystian Garbaciak 	.status_base = DA9063_REG_EVENT_A,
159a0e08b86SKrystian Garbaciak 	.mask_base = DA9063_REG_IRQ_MASK_A,
160a0e08b86SKrystian Garbaciak 	.ack_base = DA9063_REG_EVENT_A,
161a0e08b86SKrystian Garbaciak 	.init_ack_masked = true,
162a0e08b86SKrystian Garbaciak };
163a0e08b86SKrystian Garbaciak 
164a0e08b86SKrystian Garbaciak int da9063_irq_init(struct da9063 *da9063)
165a0e08b86SKrystian Garbaciak {
166a0e08b86SKrystian Garbaciak 	int ret;
167a0e08b86SKrystian Garbaciak 
168a0e08b86SKrystian Garbaciak 	if (!da9063->chip_irq) {
169a0e08b86SKrystian Garbaciak 		dev_err(da9063->dev, "No IRQ configured\n");
170a0e08b86SKrystian Garbaciak 		return -EINVAL;
171a0e08b86SKrystian Garbaciak 	}
172a0e08b86SKrystian Garbaciak 
173*7494de04SMarek Vasut 	ret = devm_regmap_add_irq_chip(da9063->dev, da9063->regmap,
174*7494de04SMarek Vasut 			da9063->chip_irq,
175a0e08b86SKrystian Garbaciak 			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
176a0e08b86SKrystian Garbaciak 			da9063->irq_base, &da9063_irq_chip,
177a0e08b86SKrystian Garbaciak 			&da9063->regmap_irq);
178a0e08b86SKrystian Garbaciak 	if (ret) {
179a0e08b86SKrystian Garbaciak 		dev_err(da9063->dev, "Failed to reguest IRQ %d: %d\n",
180a0e08b86SKrystian Garbaciak 				da9063->chip_irq, ret);
181a0e08b86SKrystian Garbaciak 		return ret;
182a0e08b86SKrystian Garbaciak 	}
183a0e08b86SKrystian Garbaciak 
184a0e08b86SKrystian Garbaciak 	return 0;
185a0e08b86SKrystian Garbaciak }
186