Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #include <linux/bitops.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/irq.h> |
| 17 | #include <linux/mfd/core.h> |
| 18 | #include <linux/mfd/wcd9xxx/core.h> |
| 19 | #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h> |
| 20 | #include <linux/mfd/wcd9xxx/wcd9310_registers.h> |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 21 | #include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/irqdomain.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 25 | #include <linux/of.h> |
| 26 | #include <linux/of_irq.h> |
| 27 | #include <linux/slab.h> |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 28 | #include <linux/ratelimit.h> |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 29 | #include <mach/cpuidle.h> |
| 30 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 31 | #define BYTE_BIT_MASK(nr) (1UL << ((nr) % BITS_PER_BYTE)) |
| 32 | #define BIT_BYTE(nr) ((nr) / BITS_PER_BYTE) |
| 33 | |
Joonwoo Park | 18383dc | 2012-09-20 17:45:57 -0700 | [diff] [blame] | 34 | #define WCD9XXX_SYSTEM_RESUME_TIMEOUT_MS 100 |
| 35 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 36 | #ifdef CONFIG_OF |
| 37 | struct wcd9xxx_irq_drv_data { |
| 38 | struct irq_domain *domain; |
| 39 | int irq; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 40 | }; |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 41 | #endif |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 42 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 43 | static int virq_to_phyirq(struct wcd9xxx *wcd9xxx, int virq); |
| 44 | static int phyirq_to_virq(struct wcd9xxx *wcd9xxx, int irq); |
| 45 | static unsigned int wcd9xxx_irq_get_upstream_irq(struct wcd9xxx *wcd9xxx); |
| 46 | static void wcd9xxx_irq_put_upstream_irq(struct wcd9xxx *wcd9xxx); |
| 47 | static int wcd9xxx_map_irq(struct wcd9xxx *wcd9xxx, int irq); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 48 | |
| 49 | static void wcd9xxx_irq_lock(struct irq_data *data) |
| 50 | { |
| 51 | struct wcd9xxx *wcd9xxx = irq_data_get_irq_chip_data(data); |
| 52 | mutex_lock(&wcd9xxx->irq_lock); |
| 53 | } |
| 54 | |
| 55 | static void wcd9xxx_irq_sync_unlock(struct irq_data *data) |
| 56 | { |
| 57 | struct wcd9xxx *wcd9xxx = irq_data_get_irq_chip_data(data); |
| 58 | int i; |
| 59 | |
Simmi Pateriya | 4fd6993 | 2012-10-26 00:57:06 +0530 | [diff] [blame] | 60 | if (ARRAY_SIZE(wcd9xxx->irq_masks_cur) > WCD9XXX_NUM_IRQ_REGS || |
| 61 | ARRAY_SIZE(wcd9xxx->irq_masks_cache) > WCD9XXX_NUM_IRQ_REGS) { |
| 62 | pr_err("%s: Array Size out of bound\n", __func__); |
| 63 | return; |
| 64 | } |
| 65 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 66 | for (i = 0; i < ARRAY_SIZE(wcd9xxx->irq_masks_cur); i++) { |
| 67 | /* If there's been a change in the mask write it back |
| 68 | * to the hardware. |
| 69 | */ |
| 70 | if (wcd9xxx->irq_masks_cur[i] != wcd9xxx->irq_masks_cache[i]) { |
| 71 | wcd9xxx->irq_masks_cache[i] = wcd9xxx->irq_masks_cur[i]; |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 72 | wcd9xxx_reg_write(wcd9xxx, |
| 73 | WCD9XXX_A_INTR_MASK0 + i, |
| 74 | wcd9xxx->irq_masks_cur[i]); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | mutex_unlock(&wcd9xxx->irq_lock); |
| 79 | } |
| 80 | |
| 81 | static void wcd9xxx_irq_enable(struct irq_data *data) |
| 82 | { |
| 83 | struct wcd9xxx *wcd9xxx = irq_data_get_irq_chip_data(data); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 84 | int wcd9xxx_irq = virq_to_phyirq(wcd9xxx, data->irq); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 85 | wcd9xxx->irq_masks_cur[BIT_BYTE(wcd9xxx_irq)] &= |
| 86 | ~(BYTE_BIT_MASK(wcd9xxx_irq)); |
| 87 | } |
| 88 | |
| 89 | static void wcd9xxx_irq_disable(struct irq_data *data) |
| 90 | { |
| 91 | struct wcd9xxx *wcd9xxx = irq_data_get_irq_chip_data(data); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 92 | int wcd9xxx_irq = virq_to_phyirq(wcd9xxx, data->irq); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 93 | wcd9xxx->irq_masks_cur[BIT_BYTE(wcd9xxx_irq)] |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 94 | |= BYTE_BIT_MASK(wcd9xxx_irq); |
| 95 | } |
| 96 | |
| 97 | static void wcd9xxx_irq_mask(struct irq_data *d) |
| 98 | { |
| 99 | /* do nothing but required as linux calls irq_mask without NULL check */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static struct irq_chip wcd9xxx_irq_chip = { |
| 103 | .name = "wcd9xxx", |
| 104 | .irq_bus_lock = wcd9xxx_irq_lock, |
| 105 | .irq_bus_sync_unlock = wcd9xxx_irq_sync_unlock, |
| 106 | .irq_disable = wcd9xxx_irq_disable, |
| 107 | .irq_enable = wcd9xxx_irq_enable, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 108 | .irq_mask = wcd9xxx_irq_mask, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | enum wcd9xxx_pm_state wcd9xxx_pm_cmpxchg(struct wcd9xxx *wcd9xxx, |
| 112 | enum wcd9xxx_pm_state o, |
| 113 | enum wcd9xxx_pm_state n) |
| 114 | { |
| 115 | enum wcd9xxx_pm_state old; |
| 116 | mutex_lock(&wcd9xxx->pm_lock); |
| 117 | old = wcd9xxx->pm_state; |
| 118 | if (old == o) |
| 119 | wcd9xxx->pm_state = n; |
| 120 | mutex_unlock(&wcd9xxx->pm_lock); |
| 121 | return old; |
| 122 | } |
| 123 | EXPORT_SYMBOL_GPL(wcd9xxx_pm_cmpxchg); |
| 124 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 125 | bool wcd9xxx_lock_sleep(struct wcd9xxx *wcd9xxx) |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 126 | { |
| 127 | enum wcd9xxx_pm_state os; |
| 128 | |
Joonwoo Park | 18383dc | 2012-09-20 17:45:57 -0700 | [diff] [blame] | 129 | /* |
| 130 | * wcd9xxx_{lock/unlock}_sleep will be called by wcd9xxx_irq_thread |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 131 | * and its subroutines only motly. |
| 132 | * but btn0_lpress_fn is not wcd9xxx_irq_thread's subroutine and |
Joonwoo Park | 18383dc | 2012-09-20 17:45:57 -0700 | [diff] [blame] | 133 | * It can race with wcd9xxx_irq_thread. |
| 134 | * So need to embrace wlock_holders with mutex. |
| 135 | * |
| 136 | * If system didn't resume, we can simply return false so codec driver's |
| 137 | * IRQ handler can return without handling IRQ. |
| 138 | * As interrupt line is still active, codec will have another IRQ to |
| 139 | * retry shortly. |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 140 | */ |
| 141 | mutex_lock(&wcd9xxx->pm_lock); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 142 | if (wcd9xxx->wlock_holders++ == 0) { |
| 143 | pr_debug("%s: holding wake lock\n", __func__); |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 144 | pm_qos_update_request(&wcd9xxx->pm_qos_req, |
| 145 | msm_cpuidle_get_deep_idle_latency()); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 146 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 147 | mutex_unlock(&wcd9xxx->pm_lock); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 148 | if (!wait_event_timeout(wcd9xxx->pm_wq, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 149 | ((os = wcd9xxx_pm_cmpxchg(wcd9xxx, WCD9XXX_PM_SLEEPABLE, |
| 150 | WCD9XXX_PM_AWAKE)) == |
| 151 | WCD9XXX_PM_SLEEPABLE || |
| 152 | (os == WCD9XXX_PM_AWAKE)), |
Joonwoo Park | 18383dc | 2012-09-20 17:45:57 -0700 | [diff] [blame] | 153 | msecs_to_jiffies(WCD9XXX_SYSTEM_RESUME_TIMEOUT_MS))) { |
| 154 | pr_warn("%s: system didn't resume within %dms, s %d, w %d\n", |
| 155 | __func__, |
| 156 | WCD9XXX_SYSTEM_RESUME_TIMEOUT_MS, wcd9xxx->pm_state, |
| 157 | wcd9xxx->wlock_holders); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 158 | wcd9xxx_unlock_sleep(wcd9xxx); |
| 159 | return false; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 160 | } |
| 161 | wake_up_all(&wcd9xxx->pm_wq); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 162 | return true; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 163 | } |
| 164 | EXPORT_SYMBOL_GPL(wcd9xxx_lock_sleep); |
| 165 | |
| 166 | void wcd9xxx_unlock_sleep(struct wcd9xxx *wcd9xxx) |
| 167 | { |
| 168 | mutex_lock(&wcd9xxx->pm_lock); |
| 169 | if (--wcd9xxx->wlock_holders == 0) { |
Joonwoo Park | 18383dc | 2012-09-20 17:45:57 -0700 | [diff] [blame] | 170 | pr_debug("%s: releasing wake lock pm_state %d -> %d\n", |
| 171 | __func__, wcd9xxx->pm_state, WCD9XXX_PM_SLEEPABLE); |
| 172 | /* |
| 173 | * if wcd9xxx_lock_sleep failed, pm_state would be still |
| 174 | * WCD9XXX_PM_ASLEEP, don't overwrite |
| 175 | */ |
| 176 | if (likely(wcd9xxx->pm_state == WCD9XXX_PM_AWAKE)) |
| 177 | wcd9xxx->pm_state = WCD9XXX_PM_SLEEPABLE; |
Stephen Boyd | 2fcabf9 | 2012-05-30 10:41:11 -0700 | [diff] [blame] | 178 | pm_qos_update_request(&wcd9xxx->pm_qos_req, |
| 179 | PM_QOS_DEFAULT_VALUE); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 180 | } |
| 181 | mutex_unlock(&wcd9xxx->pm_lock); |
| 182 | wake_up_all(&wcd9xxx->pm_wq); |
| 183 | } |
| 184 | EXPORT_SYMBOL_GPL(wcd9xxx_unlock_sleep); |
| 185 | |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 186 | void wcd9xxx_nested_irq_lock(struct wcd9xxx *wcd9xxx) |
| 187 | { |
| 188 | mutex_lock(&wcd9xxx->nested_irq_lock); |
| 189 | } |
| 190 | |
| 191 | void wcd9xxx_nested_irq_unlock(struct wcd9xxx *wcd9xxx) |
| 192 | { |
| 193 | mutex_unlock(&wcd9xxx->nested_irq_lock); |
| 194 | } |
| 195 | |
Joonwoo Park | 055ae4f | 2013-05-28 19:09:56 -0700 | [diff] [blame^] | 196 | static bool wcd9xxx_is_mbhc_irq(struct wcd9xxx *wcd9xxx, int irqbit) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 197 | { |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 198 | if ((irqbit <= WCD9XXX_IRQ_MBHC_INSERTION) && |
Joonwoo Park | 055ae4f | 2013-05-28 19:09:56 -0700 | [diff] [blame^] | 199 | (irqbit >= WCD9XXX_IRQ_MBHC_REMOVAL)) |
| 200 | return true; |
| 201 | else if (wcd9xxx->codec_type->id_major == TAIKO_MAJOR && |
| 202 | irqbit == WCD9320_IRQ_MBHC_JACK_SWITCH) |
| 203 | return true; |
| 204 | else if (wcd9xxx->codec_type->id_major == TAPAN_MAJOR && |
| 205 | irqbit == WCD9306_IRQ_MBHC_JACK_SWITCH) |
| 206 | return true; |
| 207 | else |
| 208 | return false; |
| 209 | } |
| 210 | |
| 211 | static void wcd9xxx_irq_dispatch(struct wcd9xxx *wcd9xxx, int irqbit) |
| 212 | { |
| 213 | if (wcd9xxx_is_mbhc_irq(wcd9xxx, irqbit)) { |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 214 | wcd9xxx_nested_irq_lock(wcd9xxx); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 215 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_INTR_CLEAR0 + |
| 216 | BIT_BYTE(irqbit), |
| 217 | BYTE_BIT_MASK(irqbit)); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 218 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 219 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_INTR_MODE, 0x02); |
| 220 | handle_nested_irq(phyirq_to_virq(wcd9xxx, irqbit)); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 221 | wcd9xxx_nested_irq_unlock(wcd9xxx); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 222 | } else { |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 223 | wcd9xxx_nested_irq_lock(wcd9xxx); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 224 | handle_nested_irq(phyirq_to_virq(wcd9xxx, irqbit)); |
| 225 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_INTR_CLEAR0 + |
| 226 | BIT_BYTE(irqbit), |
| 227 | BYTE_BIT_MASK(irqbit)); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 228 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 229 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_INTR_MODE, 0x02); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 230 | wcd9xxx_nested_irq_unlock(wcd9xxx); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 234 | static int wcd9xxx_num_irq_regs(const struct wcd9xxx *wcd9xxx) |
| 235 | { |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 236 | return (wcd9xxx->codec_type->num_irqs / 8) + |
| 237 | ((wcd9xxx->codec_type->num_irqs % 8) ? 1 : 0); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 240 | static irqreturn_t wcd9xxx_irq_thread(int irq, void *data) |
| 241 | { |
| 242 | int ret; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 243 | int i; |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 244 | char linebuf[128]; |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 245 | struct wcd9xxx *wcd9xxx = data; |
| 246 | int num_irq_regs = wcd9xxx_num_irq_regs(wcd9xxx); |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 247 | u8 status[num_irq_regs], status1[num_irq_regs]; |
| 248 | static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 1); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 249 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 250 | if (unlikely(wcd9xxx_lock_sleep(wcd9xxx) == false)) { |
| 251 | dev_err(wcd9xxx->dev, "Failed to hold suspend\n"); |
| 252 | return IRQ_NONE; |
| 253 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 254 | ret = wcd9xxx_bulk_read(wcd9xxx, WCD9XXX_A_INTR_STATUS0, |
| 255 | num_irq_regs, status); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 256 | if (ret < 0) { |
| 257 | dev_err(wcd9xxx->dev, "Failed to read interrupt status: %d\n", |
| 258 | ret); |
Joonwoo Park | 0732919 | 2012-10-23 13:08:37 -0700 | [diff] [blame] | 259 | dev_err(wcd9xxx->dev, "Disable irq %d\n", wcd9xxx->irq); |
Joonwoo Park | 6183dbd | 2012-10-26 16:39:20 -0700 | [diff] [blame] | 260 | disable_irq_wake(wcd9xxx->irq); |
Joonwoo Park | 0732919 | 2012-10-23 13:08:37 -0700 | [diff] [blame] | 261 | disable_irq_nosync(wcd9xxx->irq); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 262 | wcd9xxx_unlock_sleep(wcd9xxx); |
| 263 | return IRQ_NONE; |
| 264 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 265 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 266 | /* Apply masking */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 267 | for (i = 0; i < num_irq_regs; i++) |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 268 | status[i] &= ~wcd9xxx->irq_masks_cur[i]; |
| 269 | |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 270 | memcpy(status1, status, sizeof(status1)); |
| 271 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 272 | /* Find out which interrupt was triggered and call that interrupt's |
| 273 | * handler function |
| 274 | */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 275 | if (status[BIT_BYTE(WCD9XXX_IRQ_SLIMBUS)] & |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 276 | BYTE_BIT_MASK(WCD9XXX_IRQ_SLIMBUS)) { |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 277 | wcd9xxx_irq_dispatch(wcd9xxx, WCD9XXX_IRQ_SLIMBUS); |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 278 | status1[BIT_BYTE(WCD9XXX_IRQ_SLIMBUS)] &= |
| 279 | ~BYTE_BIT_MASK(WCD9XXX_IRQ_SLIMBUS); |
| 280 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 281 | |
| 282 | /* Since codec has only one hardware irq line which is shared by |
| 283 | * codec's different internal interrupts, so it's possible master irq |
| 284 | * handler dispatches multiple nested irq handlers after breaking |
| 285 | * order. Dispatch MBHC interrupts order to follow MBHC state |
| 286 | * machine's order */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 287 | for (i = WCD9XXX_IRQ_MBHC_INSERTION; |
| 288 | i >= WCD9XXX_IRQ_MBHC_REMOVAL; i--) { |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 289 | if (status[BIT_BYTE(i)] & BYTE_BIT_MASK(i)) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 290 | wcd9xxx_irq_dispatch(wcd9xxx, i); |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 291 | status1[BIT_BYTE(i)] &= ~BYTE_BIT_MASK(i); |
| 292 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 293 | } |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 294 | for (i = WCD9XXX_IRQ_BG_PRECHARGE; i < wcd9xxx->codec_type->num_irqs; |
| 295 | i++) { |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 296 | if (status[BIT_BYTE(i)] & BYTE_BIT_MASK(i)) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 297 | wcd9xxx_irq_dispatch(wcd9xxx, i); |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 298 | status1[BIT_BYTE(i)] &= ~BYTE_BIT_MASK(i); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * As a failsafe if unhandled irq is found, clear it to prevent |
| 304 | * interrupt storm. |
| 305 | * Note that we can say there was an unhandled irq only when no irq |
| 306 | * handled by nested irq handler since Taiko supports qdsp as irqs' |
| 307 | * destination for few irqs. Therefore driver shouldn't clear pending |
| 308 | * irqs when few handled while few others not. |
| 309 | */ |
| 310 | if (unlikely(!memcmp(status, status1, sizeof(status)))) { |
| 311 | if (__ratelimit(&ratelimit)) { |
| 312 | pr_warn("%s: Unhandled irq found\n", __func__); |
| 313 | hex_dump_to_buffer(status, sizeof(status), 16, 1, |
| 314 | linebuf, sizeof(linebuf), false); |
| 315 | pr_warn("%s: status0 : %s\n", __func__, linebuf); |
| 316 | hex_dump_to_buffer(status1, sizeof(status1), 16, 1, |
| 317 | linebuf, sizeof(linebuf), false); |
| 318 | pr_warn("%s: status1 : %s\n", __func__, linebuf); |
| 319 | } |
| 320 | |
Joonwoo Park | 66485a9 | 2013-04-25 13:06:34 -0700 | [diff] [blame] | 321 | memset(status, 0xff, num_irq_regs); |
| 322 | wcd9xxx_bulk_write(wcd9xxx, WCD9XXX_A_INTR_CLEAR0, |
Joonwoo Park | 1c958f1a | 2013-04-23 19:41:46 -0700 | [diff] [blame] | 323 | num_irq_regs, status); |
Joonwoo Park | 66485a9 | 2013-04-25 13:06:34 -0700 | [diff] [blame] | 324 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
| 325 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_INTR_MODE, 0x02); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 326 | } |
| 327 | wcd9xxx_unlock_sleep(wcd9xxx); |
| 328 | |
| 329 | return IRQ_HANDLED; |
| 330 | } |
| 331 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 332 | void wcd9xxx_free_irq(struct wcd9xxx *wcd9xxx, int irq, void *data) |
| 333 | { |
| 334 | free_irq(phyirq_to_virq(wcd9xxx, irq), data); |
| 335 | } |
| 336 | |
| 337 | void wcd9xxx_enable_irq(struct wcd9xxx *wcd9xxx, int irq) |
| 338 | { |
| 339 | enable_irq(phyirq_to_virq(wcd9xxx, irq)); |
| 340 | } |
| 341 | |
| 342 | void wcd9xxx_disable_irq(struct wcd9xxx *wcd9xxx, int irq) |
| 343 | { |
| 344 | disable_irq_nosync(phyirq_to_virq(wcd9xxx, irq)); |
| 345 | } |
| 346 | |
| 347 | void wcd9xxx_disable_irq_sync(struct wcd9xxx *wcd9xxx, int irq) |
| 348 | { |
| 349 | disable_irq(phyirq_to_virq(wcd9xxx, irq)); |
| 350 | } |
| 351 | |
| 352 | static int wcd9xxx_irq_setup_downstream_irq(struct wcd9xxx *wcd9xxx) |
| 353 | { |
| 354 | int irq, virq, ret; |
| 355 | |
| 356 | pr_debug("%s: enter\n", __func__); |
| 357 | |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 358 | for (irq = 0; irq < wcd9xxx->codec_type->num_irqs; irq++) { |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 359 | /* Map OF irq */ |
| 360 | virq = wcd9xxx_map_irq(wcd9xxx, irq); |
| 361 | pr_debug("%s: irq %d -> %d\n", __func__, irq, virq); |
| 362 | if (virq == NO_IRQ) { |
| 363 | pr_err("%s, No interrupt specifier for irq %d\n", |
| 364 | __func__, irq); |
| 365 | return NO_IRQ; |
| 366 | } |
| 367 | |
| 368 | ret = irq_set_chip_data(virq, wcd9xxx); |
| 369 | if (ret) { |
| 370 | pr_err("%s: Failed to configure irq %d (%d)\n", |
| 371 | __func__, irq, ret); |
| 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | if (wcd9xxx->irq_level_high[irq]) |
| 376 | irq_set_chip_and_handler(virq, &wcd9xxx_irq_chip, |
| 377 | handle_level_irq); |
| 378 | else |
| 379 | irq_set_chip_and_handler(virq, &wcd9xxx_irq_chip, |
| 380 | handle_edge_irq); |
| 381 | |
| 382 | irq_set_nested_thread(virq, 1); |
| 383 | } |
| 384 | |
| 385 | pr_debug("%s: leave\n", __func__); |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 390 | int wcd9xxx_irq_init(struct wcd9xxx *wcd9xxx) |
| 391 | { |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 392 | int i, ret; |
| 393 | u8 irq_level[wcd9xxx_num_irq_regs(wcd9xxx)]; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 394 | |
| 395 | mutex_init(&wcd9xxx->irq_lock); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 396 | mutex_init(&wcd9xxx->nested_irq_lock); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 397 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 398 | wcd9xxx->irq = wcd9xxx_irq_get_upstream_irq(wcd9xxx); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 399 | if (!wcd9xxx->irq) { |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 400 | pr_warn("%s: irq driver is not yet initialized\n", __func__); |
| 401 | mutex_destroy(&wcd9xxx->irq_lock); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 402 | mutex_destroy(&wcd9xxx->nested_irq_lock); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 403 | return -EPROBE_DEFER; |
| 404 | } |
| 405 | pr_debug("%s: probed irq %d\n", __func__, wcd9xxx->irq); |
| 406 | |
| 407 | /* Setup downstream IRQs */ |
| 408 | ret = wcd9xxx_irq_setup_downstream_irq(wcd9xxx); |
| 409 | if (ret) { |
| 410 | pr_err("%s: Failed to setup downstream IRQ\n", __func__); |
| 411 | wcd9xxx_irq_put_upstream_irq(wcd9xxx); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 412 | mutex_destroy(&wcd9xxx->irq_lock); |
| 413 | mutex_destroy(&wcd9xxx->nested_irq_lock); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 414 | return ret; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 415 | } |
| 416 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 417 | /* All other wcd9xxx interrupts are edge triggered */ |
| 418 | wcd9xxx->irq_level_high[0] = true; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 419 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 420 | /* mask all the interrupts */ |
| 421 | memset(irq_level, 0, wcd9xxx_num_irq_regs(wcd9xxx)); |
Joonwoo Park | 1277cb6 | 2013-03-19 14:16:51 -0700 | [diff] [blame] | 422 | for (i = 0; i < wcd9xxx->codec_type->num_irqs; i++) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 423 | wcd9xxx->irq_masks_cur[BIT_BYTE(i)] |= BYTE_BIT_MASK(i); |
| 424 | wcd9xxx->irq_masks_cache[BIT_BYTE(i)] |= BYTE_BIT_MASK(i); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 425 | irq_level[BIT_BYTE(i)] |= |
| 426 | wcd9xxx->irq_level_high[i] << (i % BITS_PER_BYTE); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 427 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 428 | |
| 429 | for (i = 0; i < wcd9xxx_num_irq_regs(wcd9xxx); i++) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 430 | /* Initialize interrupt mask and level registers */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 431 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_INTR_LEVEL0 + i, |
| 432 | irq_level[i]); |
| 433 | wcd9xxx_reg_write(wcd9xxx, WCD9XXX_A_INTR_MASK0 + i, |
| 434 | wcd9xxx->irq_masks_cur[i]); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | ret = request_threaded_irq(wcd9xxx->irq, NULL, wcd9xxx_irq_thread, |
| 438 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
| 439 | "wcd9xxx", wcd9xxx); |
| 440 | if (ret != 0) |
| 441 | dev_err(wcd9xxx->dev, "Failed to request IRQ %d: %d\n", |
| 442 | wcd9xxx->irq, ret); |
| 443 | else { |
| 444 | ret = enable_irq_wake(wcd9xxx->irq); |
| 445 | if (ret == 0) { |
| 446 | ret = device_init_wakeup(wcd9xxx->dev, 1); |
| 447 | if (ret) { |
| 448 | dev_err(wcd9xxx->dev, "Failed to init device" |
| 449 | "wakeup : %d\n", ret); |
| 450 | disable_irq_wake(wcd9xxx->irq); |
| 451 | } |
| 452 | } else |
| 453 | dev_err(wcd9xxx->dev, "Failed to set wake interrupt on" |
| 454 | " IRQ %d: %d\n", wcd9xxx->irq, ret); |
| 455 | if (ret) |
| 456 | free_irq(wcd9xxx->irq, wcd9xxx); |
| 457 | } |
| 458 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 459 | if (ret) { |
| 460 | pr_err("%s: Failed to init wcd9xxx irq\n", __func__); |
| 461 | wcd9xxx_irq_put_upstream_irq(wcd9xxx); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 462 | mutex_destroy(&wcd9xxx->irq_lock); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 463 | mutex_destroy(&wcd9xxx->nested_irq_lock); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 464 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 465 | |
| 466 | return ret; |
| 467 | } |
| 468 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 469 | int wcd9xxx_request_irq(struct wcd9xxx *wcd9xxx, int irq, irq_handler_t handler, |
| 470 | const char *name, void *data) |
| 471 | { |
| 472 | int virq; |
| 473 | |
| 474 | virq = phyirq_to_virq(wcd9xxx, irq); |
| 475 | |
| 476 | /* |
| 477 | * ARM needs us to explicitly flag the IRQ as valid |
| 478 | * and will set them noprobe when we do so. |
| 479 | */ |
| 480 | #ifdef CONFIG_ARM |
| 481 | set_irq_flags(virq, IRQF_VALID); |
| 482 | #else |
| 483 | set_irq_noprobe(virq); |
| 484 | #endif |
| 485 | |
| 486 | return request_threaded_irq(virq, NULL, handler, IRQF_TRIGGER_RISING, |
| 487 | name, data); |
| 488 | } |
| 489 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 490 | void wcd9xxx_irq_exit(struct wcd9xxx *wcd9xxx) |
| 491 | { |
| 492 | if (wcd9xxx->irq) { |
| 493 | disable_irq_wake(wcd9xxx->irq); |
| 494 | free_irq(wcd9xxx->irq, wcd9xxx); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 495 | /* Release parent's of node */ |
| 496 | wcd9xxx_irq_put_upstream_irq(wcd9xxx); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 497 | device_init_wakeup(wcd9xxx->dev, 0); |
| 498 | } |
| 499 | mutex_destroy(&wcd9xxx->irq_lock); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 500 | mutex_destroy(&wcd9xxx->nested_irq_lock); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 501 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 502 | |
| 503 | #ifndef CONFIG_OF |
| 504 | static int phyirq_to_virq(struct wcd9xxx *wcd9xxx, int offset) |
| 505 | { |
| 506 | return wcd9xxx->irq_base + offset; |
| 507 | } |
| 508 | |
| 509 | static int virq_to_phyirq(struct wcd9xxx *wcd9xxx, int virq) |
| 510 | { |
| 511 | return virq - wcd9xxx->irq_base; |
| 512 | } |
| 513 | |
| 514 | static unsigned int wcd9xxx_irq_get_upstream_irq(struct wcd9xxx *wcd9xxx) |
| 515 | { |
| 516 | return wcd9xxx->irq; |
| 517 | } |
| 518 | |
| 519 | static void wcd9xxx_irq_put_upstream_irq(struct wcd9xxx *wcd9xxx) |
| 520 | { |
| 521 | /* Do nothing */ |
| 522 | } |
| 523 | |
| 524 | static int wcd9xxx_map_irq(struct wcd9xxx *wcd9xxx, int irq) |
| 525 | { |
| 526 | return phyirq_to_virq(wcd9xxx, irq); |
| 527 | } |
| 528 | #else |
| 529 | int __init wcd9xxx_irq_of_init(struct device_node *node, |
| 530 | struct device_node *parent) |
| 531 | { |
| 532 | struct wcd9xxx_irq_drv_data *data; |
| 533 | |
| 534 | pr_debug("%s: node %s, node parent %s\n", __func__, |
| 535 | node->name, node->parent->name); |
| 536 | |
| 537 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 538 | if (!data) |
| 539 | return -ENOMEM; |
| 540 | |
| 541 | /* |
| 542 | * wcd9xxx_intc interrupt controller supports N to N irq mapping with |
| 543 | * single cell binding with irq numbers(offsets) only. |
| 544 | * Use irq_domain_simple_ops that has irq_domain_simple_map and |
| 545 | * irq_domain_xlate_onetwocell. |
| 546 | */ |
| 547 | data->domain = irq_domain_add_linear(node, WCD9XXX_MAX_NUM_IRQS, |
| 548 | &irq_domain_simple_ops, data); |
| 549 | if (!data->domain) { |
| 550 | kfree(data); |
| 551 | return -ENOMEM; |
| 552 | } |
| 553 | |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static struct wcd9xxx_irq_drv_data * |
| 558 | wcd9xxx_get_irq_drv_d(const struct wcd9xxx *wcd9xxx) |
| 559 | { |
| 560 | struct device_node *pnode; |
| 561 | struct irq_domain *domain; |
| 562 | |
| 563 | pnode = of_irq_find_parent(wcd9xxx->dev->of_node); |
| 564 | /* Shouldn't happen */ |
| 565 | if (unlikely(!pnode)) |
| 566 | return NULL; |
| 567 | |
| 568 | domain = irq_find_host(pnode); |
| 569 | return (struct wcd9xxx_irq_drv_data *)domain->host_data; |
| 570 | } |
| 571 | |
| 572 | static int phyirq_to_virq(struct wcd9xxx *wcd9xxx, int offset) |
| 573 | { |
| 574 | struct wcd9xxx_irq_drv_data *data; |
| 575 | |
| 576 | data = wcd9xxx_get_irq_drv_d(wcd9xxx); |
| 577 | if (!data) { |
| 578 | pr_warn("%s: not registered to interrupt controller\n", |
| 579 | __func__); |
| 580 | return -EINVAL; |
| 581 | } |
| 582 | return irq_linear_revmap(data->domain, offset); |
| 583 | } |
| 584 | |
| 585 | static int virq_to_phyirq(struct wcd9xxx *wcd9xxx, int virq) |
| 586 | { |
| 587 | struct irq_data *irq_data = irq_get_irq_data(virq); |
| 588 | return irq_data->hwirq; |
| 589 | } |
| 590 | |
| 591 | static unsigned int wcd9xxx_irq_get_upstream_irq(struct wcd9xxx *wcd9xxx) |
| 592 | { |
| 593 | struct wcd9xxx_irq_drv_data *data; |
| 594 | |
| 595 | /* Hold parent's of node */ |
| 596 | if (!of_node_get(of_irq_find_parent(wcd9xxx->dev->of_node))) |
| 597 | return -EINVAL; |
| 598 | |
| 599 | data = wcd9xxx_get_irq_drv_d(wcd9xxx); |
| 600 | if (!data) { |
| 601 | pr_err("%s: interrupt controller is not registerd\n", __func__); |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | rmb(); |
| 606 | return data->irq; |
| 607 | } |
| 608 | |
| 609 | static void wcd9xxx_irq_put_upstream_irq(struct wcd9xxx *wcd9xxx) |
| 610 | { |
| 611 | /* Hold parent's of node */ |
| 612 | of_node_put(of_irq_find_parent(wcd9xxx->dev->of_node)); |
| 613 | } |
| 614 | |
| 615 | static int wcd9xxx_map_irq(struct wcd9xxx *wcd9xxx, int irq) |
| 616 | { |
| 617 | return of_irq_to_resource(wcd9xxx->dev->of_node, irq, NULL); |
| 618 | } |
| 619 | |
| 620 | static int __devinit wcd9xxx_irq_probe(struct platform_device *pdev) |
| 621 | { |
| 622 | int irq; |
| 623 | struct irq_domain *domain; |
| 624 | struct wcd9xxx_irq_drv_data *data; |
| 625 | int ret = -EINVAL; |
| 626 | |
| 627 | irq = platform_get_irq_byname(pdev, "cdc-int"); |
| 628 | if (irq < 0) { |
| 629 | dev_err(&pdev->dev, "%s: Couldn't find cdc-int node(%d)\n", |
| 630 | __func__, irq); |
| 631 | return -EINVAL; |
| 632 | } else { |
| 633 | dev_dbg(&pdev->dev, "%s: virq = %d\n", __func__, irq); |
| 634 | domain = irq_find_host(pdev->dev.of_node); |
| 635 | data = (struct wcd9xxx_irq_drv_data *)domain->host_data; |
| 636 | data->irq = irq; |
| 637 | wmb(); |
| 638 | ret = 0; |
| 639 | } |
| 640 | |
| 641 | return ret; |
| 642 | } |
| 643 | |
| 644 | static int wcd9xxx_irq_remove(struct platform_device *pdev) |
| 645 | { |
| 646 | struct irq_domain *domain; |
| 647 | struct wcd9xxx_irq_drv_data *data; |
| 648 | |
| 649 | domain = irq_find_host(pdev->dev.of_node); |
| 650 | data = (struct wcd9xxx_irq_drv_data *)domain->host_data; |
| 651 | data->irq = 0; |
| 652 | wmb(); |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static const struct of_device_id of_match[] = { |
| 658 | { .compatible = "qcom,wcd9xxx-irq" }, |
| 659 | { } |
| 660 | }; |
| 661 | |
| 662 | static struct platform_driver wcd9xxx_irq_driver = { |
| 663 | .probe = wcd9xxx_irq_probe, |
| 664 | .remove = wcd9xxx_irq_remove, |
| 665 | .driver = { |
| 666 | .name = "wcd9xxx_intc", |
| 667 | .owner = THIS_MODULE, |
| 668 | .of_match_table = of_match_ptr(of_match), |
| 669 | }, |
| 670 | }; |
| 671 | |
| 672 | static int wcd9xxx_irq_drv_init(void) |
| 673 | { |
| 674 | return platform_driver_register(&wcd9xxx_irq_driver); |
| 675 | } |
| 676 | subsys_initcall(wcd9xxx_irq_drv_init); |
| 677 | |
| 678 | static void wcd9xxx_irq_drv_exit(void) |
| 679 | { |
| 680 | platform_driver_unregister(&wcd9xxx_irq_driver); |
| 681 | } |
| 682 | module_exit(wcd9xxx_irq_drv_exit); |
| 683 | #endif /* CONFIG_OF */ |