xref: /linux/drivers/mfd/da9063-irq.c (revision 9efbc6f175c017324befce493d2962109a216552)
1*9efbc6f1SWolfram Sang // SPDX-License-Identifier: GPL-2.0+
2*9efbc6f1SWolfram Sang /* Interrupt support for Dialog DA9063
3a0e08b86SKrystian Garbaciak  *
4a0e08b86SKrystian Garbaciak  * Copyright 2012 Dialog Semiconductor Ltd.
5a0e08b86SKrystian Garbaciak  * Copyright 2013 Philipp Zabel, Pengutronix
6a0e08b86SKrystian Garbaciak  *
737778d83SSteve Twiss  * Author: Michal Hajduk, Dialog Semiconductor
8a0e08b86SKrystian Garbaciak  */
9a0e08b86SKrystian Garbaciak 
10a0e08b86SKrystian Garbaciak #include <linux/kernel.h>
11a0e08b86SKrystian Garbaciak #include <linux/module.h>
12a0e08b86SKrystian Garbaciak #include <linux/irq.h>
13a0e08b86SKrystian Garbaciak #include <linux/mfd/core.h>
14a0e08b86SKrystian Garbaciak #include <linux/interrupt.h>
15a0e08b86SKrystian Garbaciak #include <linux/regmap.h>
16a0e08b86SKrystian Garbaciak #include <linux/mfd/da9063/core.h>
17a0e08b86SKrystian Garbaciak #include <linux/mfd/da9063/pdata.h>
18a0e08b86SKrystian Garbaciak 
19a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_A_OFFSET	0
20a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_B_OFFSET	1
21a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_C_OFFSET	2
22a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_D_OFFSET	3
23a0e08b86SKrystian Garbaciak 
247ce7b26fSKrzysztof Kozlowski static const struct regmap_irq da9063_irqs[] = {
25a0e08b86SKrystian Garbaciak 	/* DA9063 event A register */
268b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ONKEY,
278b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ONKEY),
288b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ALARM,
298b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ALARM),
308b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_TICK,
318b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_TICK),
328b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ADC_RDY,
338b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ADC_RDY),
348b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_SEQ_RDY,
358b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_SEQ_RDY),
36a0e08b86SKrystian Garbaciak 	/* DA9063 event B register */
378b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WAKE,
388b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_WAKE),
398b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_TEMP,
408b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_TEMP),
418b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_COMP_1V2,
428b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_COMP_1V2),
438b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_LDO_LIM,
448b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_LDO_LIM),
458b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_REG_UVOV,
468b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_UVOV),
478b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_DVC_RDY,
488b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_DVC_RDY),
498b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_VDD_MON,
508b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_MON),
518b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WARN,
528b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_WARN),
53a0e08b86SKrystian Garbaciak 	/* DA9063 event C register */
548b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI0,
558b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI0),
568b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI1,
578b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI1),
588b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI2,
598b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI2),
608b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI3,
618b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI3),
628b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI4,
638b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI4),
648b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI5,
658b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI5),
668b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI6,
678b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI6),
688b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI7,
698b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI7),
70a0e08b86SKrystian Garbaciak 	/* DA9063 event D register */
718b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI8,
728b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI8),
738b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI9,
748b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI9),
758b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI10,
768b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI10),
778b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI11,
788b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI11),
798b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI12,
808b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI12),
818b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI13,
828b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI13),
838b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI14,
848b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI14),
858b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI15,
868b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI15),
87a0e08b86SKrystian Garbaciak };
88a0e08b86SKrystian Garbaciak 
897ce7b26fSKrzysztof Kozlowski static const struct regmap_irq_chip da9063_irq_chip = {
90a0e08b86SKrystian Garbaciak 	.name = "da9063-irq",
91a0e08b86SKrystian Garbaciak 	.irqs = da9063_irqs,
92c727eea9SMarek Vasut 	.num_irqs = ARRAY_SIZE(da9063_irqs),
93a0e08b86SKrystian Garbaciak 	.num_regs = 4,
94a0e08b86SKrystian Garbaciak 	.status_base = DA9063_REG_EVENT_A,
95a0e08b86SKrystian Garbaciak 	.mask_base = DA9063_REG_IRQ_MASK_A,
96a0e08b86SKrystian Garbaciak 	.ack_base = DA9063_REG_EVENT_A,
97a0e08b86SKrystian Garbaciak 	.init_ack_masked = true,
98a0e08b86SKrystian Garbaciak };
99a0e08b86SKrystian Garbaciak 
1004ad5a999SMarek Vasut static const struct regmap_irq da9063l_irqs[] = {
1014ad5a999SMarek Vasut 	/* DA9063 event A register */
1024ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ONKEY,
1034ad5a999SMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ONKEY),
1044ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ADC_RDY,
1054ad5a999SMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ADC_RDY),
1064ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_SEQ_RDY,
1074ad5a999SMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_SEQ_RDY),
1084ad5a999SMarek Vasut 	/* DA9063 event B register */
1094ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WAKE,
1104ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_WAKE),
1114ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_TEMP,
1124ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_TEMP),
1134ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_COMP_1V2,
1144ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_COMP_1V2),
1154ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_LDO_LIM,
1164ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_LDO_LIM),
1174ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_REG_UVOV,
1184ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_UVOV),
1194ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_DVC_RDY,
1204ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_DVC_RDY),
1214ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_VDD_MON,
1224ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_MON),
1234ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WARN,
1244ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_WARN),
1254ad5a999SMarek Vasut 	/* DA9063 event C register */
1264ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI0,
1274ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI0),
1284ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI1,
1294ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI1),
1304ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI2,
1314ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI2),
1324ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI3,
1334ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI3),
1344ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI4,
1354ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI4),
1364ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI5,
1374ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI5),
1384ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI6,
1394ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI6),
1404ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI7,
1414ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI7),
1424ad5a999SMarek Vasut 	/* DA9063 event D register */
1434ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI8,
1444ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI8),
1454ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI9,
1464ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI9),
1474ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI10,
1484ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI10),
1494ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI11,
1504ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI11),
1514ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI12,
1524ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI12),
1534ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI13,
1544ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI13),
1554ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI14,
1564ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI14),
1574ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI15,
1584ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI15),
1594ad5a999SMarek Vasut };
1604ad5a999SMarek Vasut 
1614ad5a999SMarek Vasut static const struct regmap_irq_chip da9063l_irq_chip = {
1624ad5a999SMarek Vasut 	.name = "da9063l-irq",
1634ad5a999SMarek Vasut 	.irqs = da9063l_irqs,
1644ad5a999SMarek Vasut 	.num_irqs = ARRAY_SIZE(da9063l_irqs),
1654ad5a999SMarek Vasut 	.num_regs = 4,
1664ad5a999SMarek Vasut 	.status_base = DA9063_REG_EVENT_A,
1674ad5a999SMarek Vasut 	.mask_base = DA9063_REG_IRQ_MASK_A,
1684ad5a999SMarek Vasut 	.ack_base = DA9063_REG_EVENT_A,
1694ad5a999SMarek Vasut 	.init_ack_masked = true,
1704ad5a999SMarek Vasut };
1714ad5a999SMarek Vasut 
172a0e08b86SKrystian Garbaciak int da9063_irq_init(struct da9063 *da9063)
173a0e08b86SKrystian Garbaciak {
1744ad5a999SMarek Vasut 	const struct regmap_irq_chip *irq_chip;
175a0e08b86SKrystian Garbaciak 	int ret;
176a0e08b86SKrystian Garbaciak 
177a0e08b86SKrystian Garbaciak 	if (!da9063->chip_irq) {
178a0e08b86SKrystian Garbaciak 		dev_err(da9063->dev, "No IRQ configured\n");
179a0e08b86SKrystian Garbaciak 		return -EINVAL;
180a0e08b86SKrystian Garbaciak 	}
181a0e08b86SKrystian Garbaciak 
1824ad5a999SMarek Vasut 	if (da9063->type == PMIC_TYPE_DA9063)
1834ad5a999SMarek Vasut 		irq_chip = &da9063_irq_chip;
1844ad5a999SMarek Vasut 	else
1854ad5a999SMarek Vasut 		irq_chip = &da9063l_irq_chip;
1864ad5a999SMarek Vasut 
1877494de04SMarek Vasut 	ret = devm_regmap_add_irq_chip(da9063->dev, da9063->regmap,
1887494de04SMarek Vasut 			da9063->chip_irq,
189a0e08b86SKrystian Garbaciak 			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
1904ad5a999SMarek Vasut 			da9063->irq_base, irq_chip, &da9063->regmap_irq);
191a0e08b86SKrystian Garbaciak 	if (ret) {
192a0e08b86SKrystian Garbaciak 		dev_err(da9063->dev, "Failed to reguest IRQ %d: %d\n",
193a0e08b86SKrystian Garbaciak 				da9063->chip_irq, ret);
194a0e08b86SKrystian Garbaciak 		return ret;
195a0e08b86SKrystian Garbaciak 	}
196a0e08b86SKrystian Garbaciak 
197a0e08b86SKrystian Garbaciak 	return 0;
198a0e08b86SKrystian Garbaciak }
199