Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * twl6030-irq.c - TWL6030 irq support |
| 3 | * |
| 4 | * Copyright (C) 2005-2009 Texas Instruments, Inc. |
| 5 | * |
| 6 | * Modifications to defer interrupt handling to a kernel thread: |
| 7 | * Copyright (C) 2006 MontaVista Software, Inc. |
| 8 | * |
| 9 | * Based on tlv320aic23.c: |
| 10 | * Copyright (c) by Kai Svahn <kai.svahn@nokia.com> |
| 11 | * |
| 12 | * Code cleanup and modifications to IRQ handler. |
| 13 | * by syed khasim <x0khasim@ti.com> |
| 14 | * |
| 15 | * TWL6030 specific code and IRQ handling changes by |
| 16 | * Jagadeesh Bhaskar Pakaravoor <j-pakaravoor@ti.com> |
| 17 | * Balaji T K <balajitk@ti.com> |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify |
| 20 | * it under the terms of the GNU General Public License as published by |
| 21 | * the Free Software Foundation; either version 2 of the License, or |
| 22 | * (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 32 | */ |
| 33 | |
| 34 | #include <linux/init.h> |
Paul Gortmaker | 5d4a357 | 2011-07-10 12:41:10 -0400 | [diff] [blame] | 35 | #include <linux/export.h> |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 36 | #include <linux/interrupt.h> |
| 37 | #include <linux/irq.h> |
| 38 | #include <linux/kthread.h> |
| 39 | #include <linux/i2c/twl.h> |
kishore kadiyala | 72f2e2c | 2010-09-24 17:13:20 +0000 | [diff] [blame] | 40 | #include <linux/platform_device.h> |
Todd Poynor | ab2b926 | 2011-10-04 11:52:29 +0200 | [diff] [blame] | 41 | #include <linux/suspend.h> |
Benoit Cousson | 78518ff | 2012-02-29 19:40:31 +0100 | [diff] [blame] | 42 | #include <linux/of.h> |
| 43 | #include <linux/irqdomain.h> |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 44 | |
G, Manjunath Kondaiah | b0b4a7c | 2010-10-19 11:02:48 +0200 | [diff] [blame] | 45 | #include "twl-core.h" |
| 46 | |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 47 | /* |
| 48 | * TWL6030 (unlike its predecessors, which had two level interrupt handling) |
| 49 | * three interrupt registers INT_STS_A, INT_STS_B and INT_STS_C. |
| 50 | * It exposes status bits saying who has raised an interrupt. There are |
| 51 | * three mask registers that corresponds to these status registers, that |
| 52 | * enables/disables these interrupts. |
| 53 | * |
| 54 | * We set up IRQs starting at a platform-specified base. An interrupt map table, |
| 55 | * specifies mapping between interrupt number and the associated module. |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 56 | */ |
Benoit Cousson | 78518ff | 2012-02-29 19:40:31 +0100 | [diff] [blame] | 57 | #define TWL6030_NR_IRQS 20 |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 58 | |
| 59 | static int twl6030_interrupt_mapping[24] = { |
| 60 | PWR_INTR_OFFSET, /* Bit 0 PWRON */ |
| 61 | PWR_INTR_OFFSET, /* Bit 1 RPWRON */ |
| 62 | PWR_INTR_OFFSET, /* Bit 2 BAT_VLOW */ |
| 63 | RTC_INTR_OFFSET, /* Bit 3 RTC_ALARM */ |
| 64 | RTC_INTR_OFFSET, /* Bit 4 RTC_PERIOD */ |
| 65 | HOTDIE_INTR_OFFSET, /* Bit 5 HOT_DIE */ |
| 66 | SMPSLDO_INTR_OFFSET, /* Bit 6 VXXX_SHORT */ |
| 67 | SMPSLDO_INTR_OFFSET, /* Bit 7 VMMC_SHORT */ |
| 68 | |
| 69 | SMPSLDO_INTR_OFFSET, /* Bit 8 VUSIM_SHORT */ |
| 70 | BATDETECT_INTR_OFFSET, /* Bit 9 BAT */ |
| 71 | SIMDETECT_INTR_OFFSET, /* Bit 10 SIM */ |
| 72 | MMCDETECT_INTR_OFFSET, /* Bit 11 MMC */ |
| 73 | RSV_INTR_OFFSET, /* Bit 12 Reserved */ |
| 74 | MADC_INTR_OFFSET, /* Bit 13 GPADC_RT_EOC */ |
| 75 | MADC_INTR_OFFSET, /* Bit 14 GPADC_SW_EOC */ |
| 76 | GASGAUGE_INTR_OFFSET, /* Bit 15 CC_AUTOCAL */ |
| 77 | |
| 78 | USBOTG_INTR_OFFSET, /* Bit 16 ID_WKUP */ |
| 79 | USBOTG_INTR_OFFSET, /* Bit 17 VBUS_WKUP */ |
| 80 | USBOTG_INTR_OFFSET, /* Bit 18 ID */ |
Hema HK | 77b1d3f | 2010-12-10 17:55:37 +0530 | [diff] [blame] | 81 | USB_PRES_INTR_OFFSET, /* Bit 19 VBUS */ |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 82 | CHARGER_INTR_OFFSET, /* Bit 20 CHRG_CTRL */ |
Graeme Gregory | 6523b14 | 2011-05-12 14:27:56 +0100 | [diff] [blame] | 83 | CHARGERFAULT_INTR_OFFSET, /* Bit 21 EXT_CHRG */ |
| 84 | CHARGERFAULT_INTR_OFFSET, /* Bit 22 INT_CHRG */ |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 85 | RSV_INTR_OFFSET, /* Bit 23 Reserved */ |
| 86 | }; |
| 87 | /*----------------------------------------------------------------------*/ |
| 88 | |
| 89 | static unsigned twl6030_irq_base; |
Todd Poynor | ab2b926 | 2011-10-04 11:52:29 +0200 | [diff] [blame] | 90 | static int twl_irq; |
| 91 | static bool twl_irq_wake_enabled; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 92 | |
Todd Poynor | ab2b926 | 2011-10-04 11:52:29 +0200 | [diff] [blame] | 93 | static atomic_t twl6030_wakeirqs = ATOMIC_INIT(0); |
| 94 | |
| 95 | static int twl6030_irq_pm_notifier(struct notifier_block *notifier, |
| 96 | unsigned long pm_event, void *unused) |
| 97 | { |
| 98 | int chained_wakeups; |
| 99 | |
| 100 | switch (pm_event) { |
| 101 | case PM_SUSPEND_PREPARE: |
| 102 | chained_wakeups = atomic_read(&twl6030_wakeirqs); |
| 103 | |
| 104 | if (chained_wakeups && !twl_irq_wake_enabled) { |
| 105 | if (enable_irq_wake(twl_irq)) |
| 106 | pr_err("twl6030 IRQ wake enable failed\n"); |
| 107 | else |
| 108 | twl_irq_wake_enabled = true; |
| 109 | } else if (!chained_wakeups && twl_irq_wake_enabled) { |
| 110 | disable_irq_wake(twl_irq); |
| 111 | twl_irq_wake_enabled = false; |
| 112 | } |
| 113 | |
Todd Poynor | 782baa2 | 2011-09-26 16:44:24 -0700 | [diff] [blame] | 114 | disable_irq(twl_irq); |
Todd Poynor | ab2b926 | 2011-10-04 11:52:29 +0200 | [diff] [blame] | 115 | break; |
Todd Poynor | 782baa2 | 2011-09-26 16:44:24 -0700 | [diff] [blame] | 116 | |
| 117 | case PM_POST_SUSPEND: |
| 118 | enable_irq(twl_irq); |
| 119 | break; |
| 120 | |
Todd Poynor | ab2b926 | 2011-10-04 11:52:29 +0200 | [diff] [blame] | 121 | default: |
| 122 | break; |
| 123 | } |
| 124 | |
| 125 | return NOTIFY_DONE; |
| 126 | } |
| 127 | |
| 128 | static struct notifier_block twl6030_irq_pm_notifier_block = { |
| 129 | .notifier_call = twl6030_irq_pm_notifier, |
| 130 | }; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 131 | |
| 132 | /* |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 133 | * Threaded irq handler for the twl6030 interrupt. |
| 134 | * We query the interrupt controller in the twl6030 to determine |
| 135 | * which module is generating the interrupt request and call |
| 136 | * handle_nested_irq for that module. |
| 137 | */ |
| 138 | static irqreturn_t twl6030_irq_thread(int irq, void *data) |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 139 | { |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 140 | int i, ret; |
| 141 | union { |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 142 | u8 bytes[4]; |
| 143 | u32 int_sts; |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 144 | } sts; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 145 | |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 146 | /* read INT_STS_A, B and C in one shot using a burst read */ |
| 147 | ret = twl_i2c_read(TWL_MODULE_PIH, sts.bytes, REG_INT_STS_A, 3); |
| 148 | if (ret) { |
| 149 | pr_warn("twl6030_irq: I2C error %d reading PIH ISR\n", ret); |
| 150 | return IRQ_HANDLED; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 153 | sts.bytes[3] = 0; /* Only 24 bits are valid*/ |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 154 | |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 155 | /* |
| 156 | * Since VBUS status bit is not reliable for VBUS disconnect |
| 157 | * use CHARGER VBUS detection status bit instead. |
| 158 | */ |
| 159 | if (sts.bytes[2] & 0x10) |
| 160 | sts.bytes[2] |= 0x08; |
| 161 | |
| 162 | for (i = 0; sts.int_sts; sts.int_sts >>= 1, i++) |
| 163 | if (sts.int_sts & 0x1) { |
| 164 | int module_irq = twl6030_irq_base + |
| 165 | twl6030_interrupt_mapping[i]; |
| 166 | handle_nested_irq(module_irq); |
| 167 | pr_debug("twl6030_irq: PIH ISR %u, virq%u\n", |
| 168 | i, module_irq); |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | * NOTE: |
| 173 | * Simulation confirms that documentation is wrong w.r.t the |
| 174 | * interrupt status clear operation. A single *byte* write to |
| 175 | * any one of STS_A to STS_C register results in all three |
| 176 | * STS registers being reset. Since it does not matter which |
| 177 | * value is written, all three registers are cleared on a |
| 178 | * single byte write, so we just use 0x0 to clear. |
| 179 | */ |
| 180 | ret = twl_i2c_write_u8(TWL_MODULE_PIH, 0x00, REG_INT_STS_A); |
| 181 | if (ret) |
| 182 | pr_warn("twl6030_irq: I2C error in clearing PIH ISR\n"); |
| 183 | |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 184 | return IRQ_HANDLED; |
| 185 | } |
| 186 | |
| 187 | /*----------------------------------------------------------------------*/ |
| 188 | |
| 189 | static inline void activate_irq(int irq) |
| 190 | { |
| 191 | #ifdef CONFIG_ARM |
| 192 | /* ARM requires an extra step to clear IRQ_NOREQUEST, which it |
| 193 | * sets on behalf of every irq_chip. Also sets IRQ_NOPROBE. |
| 194 | */ |
| 195 | set_irq_flags(irq, IRQF_VALID); |
| 196 | #else |
| 197 | /* same effect on other architectures */ |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 198 | irq_set_noprobe(irq); |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 199 | #endif |
| 200 | } |
| 201 | |
Nishanth Menon | b8b8d79 | 2012-02-22 20:03:59 -0600 | [diff] [blame] | 202 | static int twl6030_irq_set_wake(struct irq_data *d, unsigned int on) |
Santosh Shilimkar | 49dcd07 | 2011-09-06 21:29:30 +0530 | [diff] [blame] | 203 | { |
Todd Poynor | ab2b926 | 2011-10-04 11:52:29 +0200 | [diff] [blame] | 204 | if (on) |
| 205 | atomic_inc(&twl6030_wakeirqs); |
| 206 | else |
| 207 | atomic_dec(&twl6030_wakeirqs); |
Santosh Shilimkar | 49dcd07 | 2011-09-06 21:29:30 +0530 | [diff] [blame] | 208 | |
Todd Poynor | ab2b926 | 2011-10-04 11:52:29 +0200 | [diff] [blame] | 209 | return 0; |
Santosh Shilimkar | 49dcd07 | 2011-09-06 21:29:30 +0530 | [diff] [blame] | 210 | } |
| 211 | |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 212 | int twl6030_interrupt_unmask(u8 bit_mask, u8 offset) |
| 213 | { |
| 214 | int ret; |
| 215 | u8 unmask_value; |
| 216 | ret = twl_i2c_read_u8(TWL_MODULE_PIH, &unmask_value, |
| 217 | REG_INT_STS_A + offset); |
| 218 | unmask_value &= (~(bit_mask)); |
| 219 | ret |= twl_i2c_write_u8(TWL_MODULE_PIH, unmask_value, |
| 220 | REG_INT_STS_A + offset); /* unmask INT_MSK_A/B/C */ |
| 221 | return ret; |
| 222 | } |
| 223 | EXPORT_SYMBOL(twl6030_interrupt_unmask); |
| 224 | |
| 225 | int twl6030_interrupt_mask(u8 bit_mask, u8 offset) |
| 226 | { |
| 227 | int ret; |
| 228 | u8 mask_value; |
| 229 | ret = twl_i2c_read_u8(TWL_MODULE_PIH, &mask_value, |
| 230 | REG_INT_STS_A + offset); |
| 231 | mask_value |= (bit_mask); |
| 232 | ret |= twl_i2c_write_u8(TWL_MODULE_PIH, mask_value, |
| 233 | REG_INT_STS_A + offset); /* mask INT_MSK_A/B/C */ |
| 234 | return ret; |
| 235 | } |
| 236 | EXPORT_SYMBOL(twl6030_interrupt_mask); |
| 237 | |
kishore kadiyala | 72f2e2c | 2010-09-24 17:13:20 +0000 | [diff] [blame] | 238 | int twl6030_mmc_card_detect_config(void) |
| 239 | { |
| 240 | int ret; |
| 241 | u8 reg_val = 0; |
| 242 | |
| 243 | /* Unmasking the Card detect Interrupt line for MMC1 from Phoenix */ |
| 244 | twl6030_interrupt_unmask(TWL6030_MMCDETECT_INT_MASK, |
| 245 | REG_INT_MSK_LINE_B); |
| 246 | twl6030_interrupt_unmask(TWL6030_MMCDETECT_INT_MASK, |
| 247 | REG_INT_MSK_STS_B); |
| 248 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 249 | * Initially Configuring MMC_CTRL for receiving interrupts & |
kishore kadiyala | 72f2e2c | 2010-09-24 17:13:20 +0000 | [diff] [blame] | 250 | * Card status on TWL6030 for MMC1 |
| 251 | */ |
| 252 | ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, ®_val, TWL6030_MMCCTRL); |
| 253 | if (ret < 0) { |
| 254 | pr_err("twl6030: Failed to read MMCCTRL, error %d\n", ret); |
| 255 | return ret; |
| 256 | } |
| 257 | reg_val &= ~VMMC_AUTO_OFF; |
| 258 | reg_val |= SW_FC; |
| 259 | ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, reg_val, TWL6030_MMCCTRL); |
| 260 | if (ret < 0) { |
| 261 | pr_err("twl6030: Failed to write MMCCTRL, error %d\n", ret); |
| 262 | return ret; |
| 263 | } |
| 264 | |
| 265 | /* Configuring PullUp-PullDown register */ |
| 266 | ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, ®_val, |
| 267 | TWL6030_CFG_INPUT_PUPD3); |
| 268 | if (ret < 0) { |
| 269 | pr_err("twl6030: Failed to read CFG_INPUT_PUPD3, error %d\n", |
| 270 | ret); |
| 271 | return ret; |
| 272 | } |
| 273 | reg_val &= ~(MMC_PU | MMC_PD); |
| 274 | ret = twl_i2c_write_u8(TWL6030_MODULE_ID0, reg_val, |
| 275 | TWL6030_CFG_INPUT_PUPD3); |
| 276 | if (ret < 0) { |
| 277 | pr_err("twl6030: Failed to write CFG_INPUT_PUPD3, error %d\n", |
| 278 | ret); |
| 279 | return ret; |
| 280 | } |
Benoit Cousson | bdd61bc | 2012-03-02 16:15:22 +0100 | [diff] [blame] | 281 | |
| 282 | return twl6030_irq_base + MMCDETECT_INTR_OFFSET; |
kishore kadiyala | 72f2e2c | 2010-09-24 17:13:20 +0000 | [diff] [blame] | 283 | } |
| 284 | EXPORT_SYMBOL(twl6030_mmc_card_detect_config); |
| 285 | |
| 286 | int twl6030_mmc_card_detect(struct device *dev, int slot) |
| 287 | { |
| 288 | int ret = -EIO; |
| 289 | u8 read_reg = 0; |
| 290 | struct platform_device *pdev = to_platform_device(dev); |
| 291 | |
| 292 | if (pdev->id) { |
| 293 | /* TWL6030 provide's Card detect support for |
| 294 | * only MMC1 controller. |
| 295 | */ |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 296 | pr_err("Unknown MMC controller %d in %s\n", pdev->id, __func__); |
kishore kadiyala | 72f2e2c | 2010-09-24 17:13:20 +0000 | [diff] [blame] | 297 | return ret; |
| 298 | } |
| 299 | /* |
| 300 | * BIT0 of MMC_CTRL on TWL6030 provides card status for MMC1 |
| 301 | * 0 - Card not present ,1 - Card present |
| 302 | */ |
| 303 | ret = twl_i2c_read_u8(TWL6030_MODULE_ID0, &read_reg, |
| 304 | TWL6030_MMCCTRL); |
| 305 | if (ret >= 0) |
| 306 | ret = read_reg & STS_MMC; |
| 307 | return ret; |
| 308 | } |
| 309 | EXPORT_SYMBOL(twl6030_mmc_card_detect); |
| 310 | |
Benoit Cousson | 78518ff | 2012-02-29 19:40:31 +0100 | [diff] [blame] | 311 | int twl6030_init_irq(struct device *dev, int irq_num) |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 312 | { |
Benoit Cousson | 78518ff | 2012-02-29 19:40:31 +0100 | [diff] [blame] | 313 | struct device_node *node = dev->of_node; |
| 314 | int nr_irqs, irq_base, irq_end; |
Benoit Cousson | ec1a07b | 2012-03-02 11:11:26 +0100 | [diff] [blame] | 315 | static struct irq_chip twl6030_irq_chip; |
Grygorii Strashko | a820e56 | 2013-07-25 16:15:48 +0300 | [diff] [blame^] | 316 | int status; |
Benoit Cousson | ec1a07b | 2012-03-02 11:11:26 +0100 | [diff] [blame] | 317 | int i; |
Peter Ujfalusi | 14591d8 | 2012-11-13 09:28:45 +0100 | [diff] [blame] | 318 | u8 mask[3]; |
Benoit Cousson | 78518ff | 2012-02-29 19:40:31 +0100 | [diff] [blame] | 319 | |
| 320 | nr_irqs = TWL6030_NR_IRQS; |
| 321 | |
| 322 | irq_base = irq_alloc_descs(-1, 0, nr_irqs, 0); |
| 323 | if (IS_ERR_VALUE(irq_base)) { |
| 324 | dev_err(dev, "Fail to allocate IRQ descs\n"); |
| 325 | return irq_base; |
| 326 | } |
| 327 | |
| 328 | irq_domain_add_legacy(node, nr_irqs, irq_base, 0, |
| 329 | &irq_domain_simple_ops, NULL); |
| 330 | |
| 331 | irq_end = irq_base + nr_irqs; |
| 332 | |
Peter Ujfalusi | 14591d8 | 2012-11-13 09:28:45 +0100 | [diff] [blame] | 333 | mask[0] = 0xFF; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 334 | mask[1] = 0xFF; |
| 335 | mask[2] = 0xFF; |
Benoit Cousson | ec1a07b | 2012-03-02 11:11:26 +0100 | [diff] [blame] | 336 | |
| 337 | /* mask all int lines */ |
Grygorii Strashko | a820e56 | 2013-07-25 16:15:48 +0300 | [diff] [blame^] | 338 | status = twl_i2c_write(TWL_MODULE_PIH, &mask[0], REG_INT_MSK_LINE_A, 3); |
Benoit Cousson | ec1a07b | 2012-03-02 11:11:26 +0100 | [diff] [blame] | 339 | /* mask all int sts */ |
Grygorii Strashko | a820e56 | 2013-07-25 16:15:48 +0300 | [diff] [blame^] | 340 | status |= twl_i2c_write(TWL_MODULE_PIH, &mask[0], REG_INT_MSK_STS_A, 3); |
Benoit Cousson | ec1a07b | 2012-03-02 11:11:26 +0100 | [diff] [blame] | 341 | /* clear INT_STS_A,B,C */ |
Grygorii Strashko | a820e56 | 2013-07-25 16:15:48 +0300 | [diff] [blame^] | 342 | status |= twl_i2c_write(TWL_MODULE_PIH, &mask[0], REG_INT_STS_A, 3); |
| 343 | |
| 344 | if (status < 0) { |
| 345 | dev_err(dev, "I2C err writing TWL_MODULE_PIH: %d\n", status); |
| 346 | return status; |
| 347 | } |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 348 | |
| 349 | twl6030_irq_base = irq_base; |
| 350 | |
Benoit Cousson | ec1a07b | 2012-03-02 11:11:26 +0100 | [diff] [blame] | 351 | /* |
| 352 | * install an irq handler for each of the modules; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 353 | * clone dummy irq_chip since PIH can't *do* anything |
| 354 | */ |
| 355 | twl6030_irq_chip = dummy_irq_chip; |
| 356 | twl6030_irq_chip.name = "twl6030"; |
Lennert Buytenhek | c45c685 | 2010-12-13 13:31:18 +0100 | [diff] [blame] | 357 | twl6030_irq_chip.irq_set_type = NULL; |
Santosh Shilimkar | 49dcd07 | 2011-09-06 21:29:30 +0530 | [diff] [blame] | 358 | twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 359 | |
| 360 | for (i = irq_base; i < irq_end; i++) { |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 361 | irq_set_chip_and_handler(i, &twl6030_irq_chip, |
| 362 | handle_simple_irq); |
Santosh Shilimkar | 49dcd07 | 2011-09-06 21:29:30 +0530 | [diff] [blame] | 363 | irq_set_chip_data(i, (void *)irq_num); |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 364 | irq_set_nested_thread(i, true); |
| 365 | irq_set_parent(i, irq_num); |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 366 | activate_irq(i); |
| 367 | } |
| 368 | |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 369 | dev_info(dev, "PIH (irq %d) nested IRQs %d..%d\n", |
| 370 | irq_num, irq_base, irq_end); |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 371 | |
| 372 | /* install an irq handler to demultiplex the TWL6030 interrupt */ |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 373 | status = request_threaded_irq(irq_num, NULL, twl6030_irq_thread, |
| 374 | IRQF_ONESHOT, "TWL6030-PIH", NULL); |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 375 | if (status < 0) { |
Benoit Cousson | ec1a07b | 2012-03-02 11:11:26 +0100 | [diff] [blame] | 376 | dev_err(dev, "could not claim irq %d: %d\n", irq_num, status); |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 377 | goto fail_irq; |
| 378 | } |
Axel Lin | 862de70 | 2011-08-11 15:21:00 +0800 | [diff] [blame] | 379 | |
Todd Poynor | ab2b926 | 2011-10-04 11:52:29 +0200 | [diff] [blame] | 380 | twl_irq = irq_num; |
| 381 | register_pm_notifier(&twl6030_irq_pm_notifier_block); |
Benoit Cousson | 78518ff | 2012-02-29 19:40:31 +0100 | [diff] [blame] | 382 | return irq_base; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 383 | |
Axel Lin | 862de70 | 2011-08-11 15:21:00 +0800 | [diff] [blame] | 384 | fail_irq: |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 385 | for (i = irq_base; i < irq_end; i++) |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 386 | irq_set_chip_and_handler(i, NULL, NULL); |
Benoit Cousson | ec1a07b | 2012-03-02 11:11:26 +0100 | [diff] [blame] | 387 | |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 388 | return status; |
| 389 | } |
| 390 | |
| 391 | int twl6030_exit_irq(void) |
| 392 | { |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 393 | |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 394 | if (twl_irq) { |
| 395 | unregister_pm_notifier(&twl6030_irq_pm_notifier_block); |
| 396 | free_irq(twl_irq, NULL); |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 397 | } |
Naga Venkata Srikanth V | 87343e5 | 2013-07-25 16:15:47 +0300 | [diff] [blame] | 398 | |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |