xref: /linux/drivers/mfd/da9063-irq.c (revision c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2)
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 
18a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_A_OFFSET	0
19a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_B_OFFSET	1
20a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_C_OFFSET	2
21a0e08b86SKrystian Garbaciak #define	DA9063_REG_EVENT_D_OFFSET	3
22a0e08b86SKrystian Garbaciak 
237ce7b26fSKrzysztof Kozlowski static const struct regmap_irq da9063_irqs[] = {
24a0e08b86SKrystian Garbaciak 	/* DA9063 event A register */
258b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ONKEY,
268b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ONKEY),
278b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ALARM,
288b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ALARM),
298b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_TICK,
308b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_TICK),
318b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ADC_RDY,
328b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ADC_RDY),
338b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_SEQ_RDY,
348b55734dSMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_SEQ_RDY),
35a0e08b86SKrystian Garbaciak 	/* DA9063 event B register */
368b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WAKE,
378b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_WAKE),
388b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_TEMP,
398b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_TEMP),
408b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_COMP_1V2,
418b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_COMP_1V2),
428b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_LDO_LIM,
438b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_LDO_LIM),
448b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_REG_UVOV,
458b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_UVOV),
468b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_DVC_RDY,
478b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_DVC_RDY),
488b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_VDD_MON,
498b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_MON),
508b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WARN,
518b55734dSMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_WARN),
52a0e08b86SKrystian Garbaciak 	/* DA9063 event C register */
538b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI0,
548b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI0),
558b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI1,
568b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI1),
578b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI2,
588b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI2),
598b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI3,
608b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI3),
618b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI4,
628b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI4),
638b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI5,
648b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI5),
658b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI6,
668b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI6),
678b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI7,
688b55734dSMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI7),
69a0e08b86SKrystian Garbaciak 	/* DA9063 event D register */
708b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI8,
718b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI8),
728b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI9,
738b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI9),
748b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI10,
758b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI10),
768b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI11,
778b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI11),
788b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI12,
798b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI12),
808b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI13,
818b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI13),
828b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI14,
838b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI14),
848b55734dSMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI15,
858b55734dSMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI15),
86a0e08b86SKrystian Garbaciak };
87a0e08b86SKrystian Garbaciak 
887ce7b26fSKrzysztof Kozlowski static const struct regmap_irq_chip da9063_irq_chip = {
89a0e08b86SKrystian Garbaciak 	.name = "da9063-irq",
90a0e08b86SKrystian Garbaciak 	.irqs = da9063_irqs,
91c727eea9SMarek Vasut 	.num_irqs = ARRAY_SIZE(da9063_irqs),
92a0e08b86SKrystian Garbaciak 	.num_regs = 4,
93a0e08b86SKrystian Garbaciak 	.status_base = DA9063_REG_EVENT_A,
94a0e08b86SKrystian Garbaciak 	.mask_base = DA9063_REG_IRQ_MASK_A,
95a0e08b86SKrystian Garbaciak 	.ack_base = DA9063_REG_EVENT_A,
96a0e08b86SKrystian Garbaciak 	.init_ack_masked = true,
97a0e08b86SKrystian Garbaciak };
98a0e08b86SKrystian Garbaciak 
994ad5a999SMarek Vasut static const struct regmap_irq da9063l_irqs[] = {
1004ad5a999SMarek Vasut 	/* DA9063 event A register */
1014ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ONKEY,
1024ad5a999SMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ONKEY),
1034ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_ADC_RDY,
1044ad5a999SMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_ADC_RDY),
1054ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_SEQ_RDY,
1064ad5a999SMarek Vasut 		       DA9063_REG_EVENT_A_OFFSET, DA9063_M_SEQ_RDY),
1074ad5a999SMarek Vasut 	/* DA9063 event B register */
1084ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WAKE,
1094ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_WAKE),
1104ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_TEMP,
1114ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_TEMP),
1124ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_COMP_1V2,
1134ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_COMP_1V2),
1144ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_LDO_LIM,
1154ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_LDO_LIM),
1164ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_REG_UVOV,
1174ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_UVOV),
1184ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_DVC_RDY,
1194ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_DVC_RDY),
1204ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_VDD_MON,
1214ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_MON),
1224ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_WARN,
1234ad5a999SMarek Vasut 		       DA9063_REG_EVENT_B_OFFSET, DA9063_M_VDD_WARN),
1244ad5a999SMarek Vasut 	/* DA9063 event C register */
1254ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI0,
1264ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI0),
1274ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI1,
1284ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI1),
1294ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI2,
1304ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI2),
1314ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI3,
1324ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI3),
1334ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI4,
1344ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI4),
1354ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI5,
1364ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI5),
1374ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI6,
1384ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI6),
1394ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI7,
1404ad5a999SMarek Vasut 		       DA9063_REG_EVENT_C_OFFSET, DA9063_M_GPI7),
1414ad5a999SMarek Vasut 	/* DA9063 event D register */
1424ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI8,
1434ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI8),
1444ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI9,
1454ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI9),
1464ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI10,
1474ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI10),
1484ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI11,
1494ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI11),
1504ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI12,
1514ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI12),
1524ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI13,
1534ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI13),
1544ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI14,
1554ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI14),
1564ad5a999SMarek Vasut 	REGMAP_IRQ_REG(DA9063_IRQ_GPI15,
1574ad5a999SMarek Vasut 		       DA9063_REG_EVENT_D_OFFSET, DA9063_M_GPI15),
1584ad5a999SMarek Vasut };
1594ad5a999SMarek Vasut 
1604ad5a999SMarek Vasut static const struct regmap_irq_chip da9063l_irq_chip = {
1614ad5a999SMarek Vasut 	.name = "da9063l-irq",
1624ad5a999SMarek Vasut 	.irqs = da9063l_irqs,
1634ad5a999SMarek Vasut 	.num_irqs = ARRAY_SIZE(da9063l_irqs),
1644ad5a999SMarek Vasut 	.num_regs = 4,
1654ad5a999SMarek Vasut 	.status_base = DA9063_REG_EVENT_A,
1664ad5a999SMarek Vasut 	.mask_base = DA9063_REG_IRQ_MASK_A,
1674ad5a999SMarek Vasut 	.ack_base = DA9063_REG_EVENT_A,
1684ad5a999SMarek Vasut 	.init_ack_masked = true,
1694ad5a999SMarek Vasut };
1704ad5a999SMarek Vasut 
da9063_irq_init(struct da9063 * da9063)171a0e08b86SKrystian Garbaciak int da9063_irq_init(struct da9063 *da9063)
172a0e08b86SKrystian Garbaciak {
1734ad5a999SMarek Vasut 	const struct regmap_irq_chip *irq_chip;
174a0e08b86SKrystian Garbaciak 	int ret;
175a0e08b86SKrystian Garbaciak 
176a0e08b86SKrystian Garbaciak 	if (!da9063->chip_irq) {
177a0e08b86SKrystian Garbaciak 		dev_err(da9063->dev, "No IRQ configured\n");
178a0e08b86SKrystian Garbaciak 		return -EINVAL;
179a0e08b86SKrystian Garbaciak 	}
180a0e08b86SKrystian Garbaciak 
1814ad5a999SMarek Vasut 	if (da9063->type == PMIC_TYPE_DA9063)
1824ad5a999SMarek Vasut 		irq_chip = &da9063_irq_chip;
1834ad5a999SMarek Vasut 	else
1844ad5a999SMarek Vasut 		irq_chip = &da9063l_irq_chip;
1854ad5a999SMarek Vasut 
1867494de04SMarek Vasut 	ret = devm_regmap_add_irq_chip(da9063->dev, da9063->regmap,
1877494de04SMarek Vasut 			da9063->chip_irq,
188a0e08b86SKrystian Garbaciak 			IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
1894ad5a999SMarek Vasut 			da9063->irq_base, irq_chip, &da9063->regmap_irq);
190a0e08b86SKrystian Garbaciak 	if (ret) {
191a0e08b86SKrystian Garbaciak 		dev_err(da9063->dev, "Failed to reguest IRQ %d: %d\n",
192a0e08b86SKrystian Garbaciak 				da9063->chip_irq, ret);
193a0e08b86SKrystian Garbaciak 		return ret;
194a0e08b86SKrystian Garbaciak 	}
195a0e08b86SKrystian Garbaciak 
196a0e08b86SKrystian Garbaciak 	return 0;
197a0e08b86SKrystian Garbaciak }
198