xref: /linux/drivers/mfd/da9063-irq.c (revision 8b55734dc8bdc2327d78fcace3811e64a7c7cfec)
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 */
31*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ONKEY,
32*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ONKEY),
33*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ALARM,
34*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ALARM),
35*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_TICK,
36*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_TICK),
37*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ADC_RDY,
38*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ADC_RDY),
39*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_SEQ_RDY,
40*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_SEQ_RDY),
41a0e08b86SKrystian Garbaciak 	/* DA9063 event B register */
42*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WAKE,
43*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_WAKE),
44*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_TEMP,
45*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_TEMP),
46*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_COMP_1V2,
47*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_COMP_1V2),
48*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_LDO_LIM,
49*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_LDO_LIM),
50*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_REG_UVOV,
51*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_UVOV),
52*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_DVC_RDY,
53*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_DVC_RDY),
54*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_VDD_MON,
55*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_MON),
56*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WARN,
57*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_WARN),
58a0e08b86SKrystian Garbaciak 	/* DA9063 event C register */
59*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI0,
60*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI0),
61*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI1,
62*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI1),
63*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI2,
64*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI2),
65*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI3,
66*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI3),
67*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI4,
68*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI4),
69*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI5,
70*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI5),
71*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI6,
72*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI6),
73*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI7,
74*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI7),
75a0e08b86SKrystian Garbaciak 	/* DA9063 event D register */
76*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI8,
77*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI8),
78*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI9,
79*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI9),
80*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI10,
81*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI10),
82*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI11,
83*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI11),
84*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI12,
85*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI12),
86*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI13,
87*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI13),
88*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI14,
89*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI14),
90*8b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI15,
91*8b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI15),
92a0e08b86SKrystian Garbaciak };
93a0e08b86SKrystian Garbaciak 
947ce7b26fSKrzysztof Kozlowski static const struct regmap_irq_chip da9063_irq_chip = {
95a0e08b86SKrystian Garbaciak 	.name = "da9063-irq",
96a0e08b86SKrystian Garbaciak 	.irqs = da9063_irqs,
97a0e08b86SKrystian Garbaciak 	.num_irqs = DA9063_NUM_IRQ,
98a0e08b86SKrystian Garbaciak 	.num_regs = 4,
99a0e08b86SKrystian Garbaciak 	.status_base = DA9063_REG_EVENT_A,
100a0e08b86SKrystian Garbaciak 	.mask_base = DA9063_REG_IRQ_MASK_A,
101a0e08b86SKrystian Garbaciak 	.ack_base = DA9063_REG_EVENT_A,
102a0e08b86SKrystian Garbaciak 	.init_ack_masked = true,
103a0e08b86SKrystian Garbaciak };
104a0e08b86SKrystian Garbaciak 
105a0e08b86SKrystian Garbaciak int da9063_irq_init(struct da9063 *da9063)
106a0e08b86SKrystian Garbaciak {
107a0e08b86SKrystian Garbaciak 	int ret;
108a0e08b86SKrystian Garbaciak 
109a0e08b86SKrystian Garbaciak 	if (!da9063->chip_irq) {
110a0e08b86SKrystian Garbaciak 		dev_err(da9063->dev, "No IRQ configured\n");
111a0e08b86SKrystian Garbaciak 		return -EINVAL;
112a0e08b86SKrystian Garbaciak 	}
113a0e08b86SKrystian Garbaciak 
1147494de04SMarek Vasut 	ret = devm_regmap_add_irq_chip(da9063->dev, da9063->regmap,
1157494de04SMarek Vasut 			da9063->chip_irq,
116a0e08b86SKrystian Garbaciak 			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
117a0e08b86SKrystian Garbaciak 			da9063->irq_base, &da9063_irq_chip,
118a0e08b86SKrystian Garbaciak 			&da9063->regmap_irq);
119a0e08b86SKrystian Garbaciak 	if (ret) {
120a0e08b86SKrystian Garbaciak 		dev_err(da9063->dev, "Failed to reguest IRQ %d: %d\n",
121a0e08b86SKrystian Garbaciak 				da9063->chip_irq, ret);
122a0e08b86SKrystian Garbaciak 		return ret;
123a0e08b86SKrystian Garbaciak 	}
124a0e08b86SKrystian Garbaciak 
125a0e08b86SKrystian Garbaciak 	return 0;
126a0e08b86SKrystian Garbaciak }
127