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 377ce7b26fSKrzysztof 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 }, 80*03b42710SSteve Twiss [DA9063_IRQ_DVC_RDY] = { 81*03b42710SSteve Twiss .reg_offset = DA9063_REG_EVENT_B_OFFSET, 82*03b42710SSteve Twiss .mask = DA9063_M_DVC_RDY, 83*03b42710SSteve Twiss }, 84a0e08b86SKrystian Garbaciak [DA9063_IRQ_VDD_MON] = { 85a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 86a0e08b86SKrystian Garbaciak .mask = DA9063_M_VDD_MON, 87a0e08b86SKrystian Garbaciak }, 88a0e08b86SKrystian Garbaciak [DA9063_IRQ_WARN] = { 89a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_B_OFFSET, 90a0e08b86SKrystian Garbaciak .mask = DA9063_M_VDD_WARN, 91a0e08b86SKrystian Garbaciak }, 92a0e08b86SKrystian Garbaciak /* DA9063 event C register */ 93a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI0] = { 94a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 95a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI0, 96a0e08b86SKrystian Garbaciak }, 97a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI1] = { 98a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 99a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI1, 100a0e08b86SKrystian Garbaciak }, 101a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI2] = { 102a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 103a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI2, 104a0e08b86SKrystian Garbaciak }, 105a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI3] = { 106a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 107a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI3, 108a0e08b86SKrystian Garbaciak }, 109a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI4] = { 110a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 111a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI4, 112a0e08b86SKrystian Garbaciak }, 113a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI5] = { 114a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 115a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI5, 116a0e08b86SKrystian Garbaciak }, 117a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI6] = { 118a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 119a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI6, 120a0e08b86SKrystian Garbaciak }, 121a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI7] = { 122a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_C_OFFSET, 123a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI7, 124a0e08b86SKrystian Garbaciak }, 125a0e08b86SKrystian Garbaciak /* DA9063 event D register */ 126a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI8] = { 127a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 128a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI8, 129a0e08b86SKrystian Garbaciak }, 130a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI9] = { 131a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 132a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI9, 133a0e08b86SKrystian Garbaciak }, 134a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI10] = { 135a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 136a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI10, 137a0e08b86SKrystian Garbaciak }, 138a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI11] = { 139a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 140a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI11, 141a0e08b86SKrystian Garbaciak }, 142a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI12] = { 143a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 144a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI12, 145a0e08b86SKrystian Garbaciak }, 146a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI13] = { 147a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 148a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI13, 149a0e08b86SKrystian Garbaciak }, 150a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI14] = { 151a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 152a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI14, 153a0e08b86SKrystian Garbaciak }, 154a0e08b86SKrystian Garbaciak [DA9063_IRQ_GPI15] = { 155a0e08b86SKrystian Garbaciak .reg_offset = DA9063_REG_EVENT_D_OFFSET, 156a0e08b86SKrystian Garbaciak .mask = DA9063_M_GPI15, 157a0e08b86SKrystian Garbaciak }, 158a0e08b86SKrystian Garbaciak }; 159a0e08b86SKrystian Garbaciak 1607ce7b26fSKrzysztof Kozlowski static const struct regmap_irq_chip da9063_irq_chip = { 161a0e08b86SKrystian Garbaciak .name = "da9063-irq", 162a0e08b86SKrystian Garbaciak .irqs = da9063_irqs, 163a0e08b86SKrystian Garbaciak .num_irqs = DA9063_NUM_IRQ, 164a0e08b86SKrystian Garbaciak 165a0e08b86SKrystian Garbaciak .num_regs = 4, 166a0e08b86SKrystian Garbaciak .status_base = DA9063_REG_EVENT_A, 167a0e08b86SKrystian Garbaciak .mask_base = DA9063_REG_IRQ_MASK_A, 168a0e08b86SKrystian Garbaciak .ack_base = DA9063_REG_EVENT_A, 169a0e08b86SKrystian Garbaciak .init_ack_masked = true, 170a0e08b86SKrystian Garbaciak }; 171a0e08b86SKrystian Garbaciak 172a0e08b86SKrystian Garbaciak int da9063_irq_init(struct da9063 *da9063) 173a0e08b86SKrystian Garbaciak { 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 181a0e08b86SKrystian Garbaciak ret = regmap_add_irq_chip(da9063->regmap, da9063->chip_irq, 182a0e08b86SKrystian Garbaciak IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, 183a0e08b86SKrystian Garbaciak da9063->irq_base, &da9063_irq_chip, 184a0e08b86SKrystian Garbaciak &da9063->regmap_irq); 185a0e08b86SKrystian Garbaciak if (ret) { 186a0e08b86SKrystian Garbaciak dev_err(da9063->dev, "Failed to reguest IRQ %d: %d\n", 187a0e08b86SKrystian Garbaciak da9063->chip_irq, ret); 188a0e08b86SKrystian Garbaciak return ret; 189a0e08b86SKrystian Garbaciak } 190a0e08b86SKrystian Garbaciak 191a0e08b86SKrystian Garbaciak return 0; 192a0e08b86SKrystian Garbaciak } 193a0e08b86SKrystian Garbaciak 194a0e08b86SKrystian Garbaciak void da9063_irq_exit(struct da9063 *da9063) 195a0e08b86SKrystian Garbaciak { 196a0e08b86SKrystian Garbaciak regmap_del_irq_chip(da9063->chip_irq, da9063->regmap_irq); 197a0e08b86SKrystian Garbaciak } 198