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