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 * 6a0e08b86SKrystian Garbaciak * Author: Michal Hajduk <michal.hajduk@diasemi.com> 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 #define EVENTS_BUF_LEN 4 29a0e08b86SKrystian Garbaciak 30a0e08b86SKrystian Garbaciak static const u8 mask_events_buf[] = { [0 ... (EVENTS_BUF_LEN - 1)] = ~0 }; 31a0e08b86SKrystian Garbaciak 32a0e08b86SKrystian Garbaciak struct da9063_irq_data { 33a0e08b86SKrystian Garbaciak u16 reg; 34a0e08b86SKrystian Garbaciak u8 mask; 35a0e08b86SKrystian Garbaciak }; 36a0e08b86SKrystian Garbaciak 37*7ce7b26fSKrzysztof Kozlowski static const struct regmap_irq da9063_irqs[] = { 38a0e08b86SKrystian Garbaciak /* DA9063 event A register */ 39a0e08b86SKrystian Garbaciak [DA9063_IRQ_ONKEY] = { 40a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_A_OFFSET, 41a0e08b86SKrystian Garbaciak .mask = DA9063_M_ONKEY, 42a0e08b86SKrystian Garbaciak }, 43a0e08b86SKrystian Garbaciak [DA9063_IRQ_ALARM] = { 44a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_A_OFFSET, 45a0e08b86SKrystian Garbaciak .mask = DA9063_M_ALARM, 46a0e08b86SKrystian Garbaciak }, 47a0e08b86SKrystian Garbaciak [DA9063_IRQ_TICK] = { 48a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_A_OFFSET, 49a0e08b86SKrystian Garbaciak .mask = DA9063_M_TICK, 50a0e08b86SKrystian Garbaciak }, 51a0e08b86SKrystian Garbaciak [DA9063_IRQ_ADC_RDY] = { 52a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_A_OFFSET, 53a0e08b86SKrystian Garbaciak .mask = DA9063_M_ADC_RDY, 54a0e08b86SKrystian Garbaciak }, 55a0e08b86SKrystian Garbaciak [DA9063_IRQ_SEQ_RDY] = { 56a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_A_OFFSET, 57a0e08b86SKrystian Garbaciak .mask = DA9063_M_SEQ_RDY, 58a0e08b86SKrystian Garbaciak }, 59a0e08b86SKrystian Garbaciak /* DA9063 event B register */ 60a0e08b86SKrystian Garbaciak [DA9063_IRQ_WAKE] = { 61a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 62a0e08b86SKrystian Garbaciak .mask = DA9063_M_WAKE, 63a0e08b86SKrystian Garbaciak }, 64a0e08b86SKrystian Garbaciak [DA9063_IRQ_TEMP] = { 65a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 66a0e08b86SKrystian Garbaciak .mask = DA9063_M_TEMP, 67a0e08b86SKrystian Garbaciak }, 68a0e08b86SKrystian Garbaciak [DA9063_IRQ_COMP_1V2] = { 69a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 70a0e08b86SKrystian Garbaciak .mask = DA9063_M_COMP_1V2, 71a0e08b86SKrystian Garbaciak }, 72a0e08b86SKrystian Garbaciak [DA9063_IRQ_LDO_LIM] = { 73a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 74a0e08b86SKrystian Garbaciak .mask = DA9063_M_LDO_LIM, 75a0e08b86SKrystian Garbaciak }, 76a0e08b86SKrystian Garbaciak [DA9063_IRQ_REG_UVOV] = { 77a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 78a0e08b86SKrystian Garbaciak .mask = DA9063_M_UVOV, 79a0e08b86SKrystian Garbaciak }, 80a0e08b86SKrystian Garbaciak [DA9063_IRQ_VDD_MON] = { 81a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 82a0e08b86SKrystian Garbaciak .mask = DA9063_M_VDD_MON, 83a0e08b86SKrystian Garbaciak }, 84a0e08b86SKrystian Garbaciak [DA9063_IRQ_WARN] = { 85a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 86a0e08b86SKrystian Garbaciak .mask = DA9063_M_VDD_WARN, 87a0e08b86SKrystian Garbaciak }, 88a0e08b86SKrystian Garbaciak /* DA9063 event C register */ 89a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI0] = { 90a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 91a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI0, 92a0e08b86SKrystian Garbaciak }, 93a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI1] = { 94a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 95a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI1, 96a0e08b86SKrystian Garbaciak }, 97a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI2] = { 98a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 99a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI2, 100a0e08b86SKrystian Garbaciak }, 101a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI3] = { 102a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 103a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI3, 104a0e08b86SKrystian Garbaciak }, 105a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI4] = { 106a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 107a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI4, 108a0e08b86SKrystian Garbaciak }, 109a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI5] = { 110a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 111a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI5, 112a0e08b86SKrystian Garbaciak }, 113a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI6] = { 114a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 115a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI6, 116a0e08b86SKrystian Garbaciak }, 117a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI7] = { 118a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 119a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI7, 120a0e08b86SKrystian Garbaciak }, 121a0e08b86SKrystian Garbaciak /* DA9063 event D register */ 122a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI8] = { 123a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 124a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI8, 125a0e08b86SKrystian Garbaciak }, 126a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI9] = { 127a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 128a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI9, 129a0e08b86SKrystian Garbaciak }, 130a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI10] = { 131a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 132a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI10, 133a0e08b86SKrystian Garbaciak }, 134a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI11] = { 135a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 136a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI11, 137a0e08b86SKrystian Garbaciak }, 138a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI12] = { 139a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 140a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI12, 141a0e08b86SKrystian Garbaciak }, 142a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI13] = { 143a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 144a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI13, 145a0e08b86SKrystian Garbaciak }, 146a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI14] = { 147a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 148a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI14, 149a0e08b86SKrystian Garbaciak }, 150a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI15] = { 151a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 152a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI15, 153a0e08b86SKrystian Garbaciak }, 154a0e08b86SKrystian Garbaciak }; 155a0e08b86SKrystian Garbaciak 156*7ce7b26fSKrzysztof Kozlowski static const struct regmap_irq_chip da9063_irq_chip = { 157a0e08b86SKrystian Garbaciak .name = "da9063-irq", 158a0e08b86SKrystian Garbaciak .irqs = da9063_irqs, 159a0e08b86SKrystian Garbaciak .num_irqs = DA9063_NUM_IRQ, 160a0e08b86SKrystian Garbaciak 161a0e08b86SKrystian Garbaciak .num_regs = 4, 162a0e08b86SKrystian Garbaciak .status_base = DA9063_REG_EVENT_A, 163a0e08b86SKrystian Garbaciak .mask_base = DA9063_REG_IRQ_MASK_A, 164a0e08b86SKrystian Garbaciak .ack_base = DA9063_REG_EVENT_A, 165a0e08b86SKrystian Garbaciak .init_ack_masked = true, 166a0e08b86SKrystian Garbaciak }; 167a0e08b86SKrystian Garbaciak 168a0e08b86SKrystian Garbaciak int da9063_irq_init(struct da9063 *da9063) 169a0e08b86SKrystian Garbaciak { 170a0e08b86SKrystian Garbaciak int ret; 171a0e08b86SKrystian Garbaciak 172a0e08b86SKrystian Garbaciak if (!da9063->chip_irq) { 173a0e08b86SKrystian Garbaciak dev_err(da9063->dev, "No IRQ configured\n"); 174a0e08b86SKrystian Garbaciak return -EINVAL; 175a0e08b86SKrystian Garbaciak } 176a0e08b86SKrystian Garbaciak 177a0e08b86SKrystian Garbaciak ret = regmap_add_irq_chip(da9063->regmap, da9063->chip_irq, 178a0e08b86SKrystian Garbaciak IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, 179a0e08b86SKrystian Garbaciak da9063->irq_base, &da9063_irq_chip, 180a0e08b86SKrystian Garbaciak &da9063->regmap_irq); 181a0e08b86SKrystian Garbaciak if (ret) { 182a0e08b86SKrystian Garbaciak dev_err(da9063->dev, "Failed to reguest IRQ %d: %d\n", 183a0e08b86SKrystian Garbaciak da9063->chip_irq, ret); 184a0e08b86SKrystian Garbaciak return ret; 185a0e08b86SKrystian Garbaciak } 186a0e08b86SKrystian Garbaciak 187a0e08b86SKrystian Garbaciak return 0; 188a0e08b86SKrystian Garbaciak } 189a0e08b86SKrystian Garbaciak 190a0e08b86SKrystian Garbaciak void da9063_irq_exit(struct da9063 *da9063) 191a0e08b86SKrystian Garbaciak { 192a0e08b86SKrystian Garbaciak regmap_del_irq_chip(da9063->chip_irq, da9063->regmap_irq); 193a0e08b86SKrystian Garbaciak } 194