Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 1 | /* |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 2 | * sec-irq.c |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2011 Samsung Electronics Co., Ltd |
| 5 | * http://www.samsung.com |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/irq.h> |
Sangbeom Kim | 54227bc | 2012-07-11 21:07:16 +0900 | [diff] [blame^] | 17 | #include <linux/mfd/samsung/core.h> |
| 18 | #include <linux/mfd/samsung/irq.h> |
| 19 | #include <linux/mfd/samsung/s5m8763.h> |
| 20 | #include <linux/mfd/samsung/s5m8767.h> |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 21 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 22 | struct sec_irq_data { |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 23 | int reg; |
| 24 | int mask; |
| 25 | }; |
| 26 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 27 | static struct sec_irq_data s5m8767_irqs[] = { |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 28 | [S5M8767_IRQ_PWRR] = { |
| 29 | .reg = 1, |
| 30 | .mask = S5M8767_IRQ_PWRR_MASK, |
| 31 | }, |
| 32 | [S5M8767_IRQ_PWRF] = { |
| 33 | .reg = 1, |
| 34 | .mask = S5M8767_IRQ_PWRF_MASK, |
| 35 | }, |
| 36 | [S5M8767_IRQ_PWR1S] = { |
| 37 | .reg = 1, |
| 38 | .mask = S5M8767_IRQ_PWR1S_MASK, |
| 39 | }, |
| 40 | [S5M8767_IRQ_JIGR] = { |
| 41 | .reg = 1, |
| 42 | .mask = S5M8767_IRQ_JIGR_MASK, |
| 43 | }, |
| 44 | [S5M8767_IRQ_JIGF] = { |
| 45 | .reg = 1, |
| 46 | .mask = S5M8767_IRQ_JIGF_MASK, |
| 47 | }, |
| 48 | [S5M8767_IRQ_LOWBAT2] = { |
| 49 | .reg = 1, |
| 50 | .mask = S5M8767_IRQ_LOWBAT2_MASK, |
| 51 | }, |
| 52 | [S5M8767_IRQ_LOWBAT1] = { |
| 53 | .reg = 1, |
| 54 | .mask = S5M8767_IRQ_LOWBAT1_MASK, |
| 55 | }, |
| 56 | [S5M8767_IRQ_MRB] = { |
| 57 | .reg = 2, |
| 58 | .mask = S5M8767_IRQ_MRB_MASK, |
| 59 | }, |
| 60 | [S5M8767_IRQ_DVSOK2] = { |
| 61 | .reg = 2, |
| 62 | .mask = S5M8767_IRQ_DVSOK2_MASK, |
| 63 | }, |
| 64 | [S5M8767_IRQ_DVSOK3] = { |
| 65 | .reg = 2, |
| 66 | .mask = S5M8767_IRQ_DVSOK3_MASK, |
| 67 | }, |
| 68 | [S5M8767_IRQ_DVSOK4] = { |
| 69 | .reg = 2, |
| 70 | .mask = S5M8767_IRQ_DVSOK4_MASK, |
| 71 | }, |
| 72 | [S5M8767_IRQ_RTC60S] = { |
| 73 | .reg = 3, |
| 74 | .mask = S5M8767_IRQ_RTC60S_MASK, |
| 75 | }, |
| 76 | [S5M8767_IRQ_RTCA1] = { |
| 77 | .reg = 3, |
| 78 | .mask = S5M8767_IRQ_RTCA1_MASK, |
| 79 | }, |
| 80 | [S5M8767_IRQ_RTCA2] = { |
| 81 | .reg = 3, |
| 82 | .mask = S5M8767_IRQ_RTCA2_MASK, |
| 83 | }, |
| 84 | [S5M8767_IRQ_SMPL] = { |
| 85 | .reg = 3, |
| 86 | .mask = S5M8767_IRQ_SMPL_MASK, |
| 87 | }, |
| 88 | [S5M8767_IRQ_RTC1S] = { |
| 89 | .reg = 3, |
| 90 | .mask = S5M8767_IRQ_RTC1S_MASK, |
| 91 | }, |
| 92 | [S5M8767_IRQ_WTSR] = { |
| 93 | .reg = 3, |
| 94 | .mask = S5M8767_IRQ_WTSR_MASK, |
| 95 | }, |
| 96 | }; |
| 97 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 98 | static struct sec_irq_data s5m8763_irqs[] = { |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 99 | [S5M8763_IRQ_DCINF] = { |
| 100 | .reg = 1, |
| 101 | .mask = S5M8763_IRQ_DCINF_MASK, |
| 102 | }, |
| 103 | [S5M8763_IRQ_DCINR] = { |
| 104 | .reg = 1, |
| 105 | .mask = S5M8763_IRQ_DCINR_MASK, |
| 106 | }, |
| 107 | [S5M8763_IRQ_JIGF] = { |
| 108 | .reg = 1, |
| 109 | .mask = S5M8763_IRQ_JIGF_MASK, |
| 110 | }, |
| 111 | [S5M8763_IRQ_JIGR] = { |
| 112 | .reg = 1, |
| 113 | .mask = S5M8763_IRQ_JIGR_MASK, |
| 114 | }, |
| 115 | [S5M8763_IRQ_PWRONF] = { |
| 116 | .reg = 1, |
| 117 | .mask = S5M8763_IRQ_PWRONF_MASK, |
| 118 | }, |
| 119 | [S5M8763_IRQ_PWRONR] = { |
| 120 | .reg = 1, |
| 121 | .mask = S5M8763_IRQ_PWRONR_MASK, |
| 122 | }, |
| 123 | [S5M8763_IRQ_WTSREVNT] = { |
| 124 | .reg = 2, |
| 125 | .mask = S5M8763_IRQ_WTSREVNT_MASK, |
| 126 | }, |
| 127 | [S5M8763_IRQ_SMPLEVNT] = { |
| 128 | .reg = 2, |
| 129 | .mask = S5M8763_IRQ_SMPLEVNT_MASK, |
| 130 | }, |
| 131 | [S5M8763_IRQ_ALARM1] = { |
| 132 | .reg = 2, |
| 133 | .mask = S5M8763_IRQ_ALARM1_MASK, |
| 134 | }, |
| 135 | [S5M8763_IRQ_ALARM0] = { |
| 136 | .reg = 2, |
| 137 | .mask = S5M8763_IRQ_ALARM0_MASK, |
| 138 | }, |
| 139 | [S5M8763_IRQ_ONKEY1S] = { |
| 140 | .reg = 3, |
| 141 | .mask = S5M8763_IRQ_ONKEY1S_MASK, |
| 142 | }, |
| 143 | [S5M8763_IRQ_TOPOFFR] = { |
| 144 | .reg = 3, |
| 145 | .mask = S5M8763_IRQ_TOPOFFR_MASK, |
| 146 | }, |
| 147 | [S5M8763_IRQ_DCINOVPR] = { |
| 148 | .reg = 3, |
| 149 | .mask = S5M8763_IRQ_DCINOVPR_MASK, |
| 150 | }, |
| 151 | [S5M8763_IRQ_CHGRSTF] = { |
| 152 | .reg = 3, |
| 153 | .mask = S5M8763_IRQ_CHGRSTF_MASK, |
| 154 | }, |
| 155 | [S5M8763_IRQ_DONER] = { |
| 156 | .reg = 3, |
| 157 | .mask = S5M8763_IRQ_DONER_MASK, |
| 158 | }, |
| 159 | [S5M8763_IRQ_CHGFAULT] = { |
| 160 | .reg = 3, |
| 161 | .mask = S5M8763_IRQ_CHGFAULT_MASK, |
| 162 | }, |
| 163 | [S5M8763_IRQ_LOBAT1] = { |
| 164 | .reg = 4, |
| 165 | .mask = S5M8763_IRQ_LOBAT1_MASK, |
| 166 | }, |
| 167 | [S5M8763_IRQ_LOBAT2] = { |
| 168 | .reg = 4, |
| 169 | .mask = S5M8763_IRQ_LOBAT2_MASK, |
| 170 | }, |
| 171 | }; |
| 172 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 173 | static inline struct sec_irq_data * |
| 174 | irq_to_s5m8767_irq(struct sec_pmic_dev *sec_pmic, int irq) |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 175 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 176 | return &s5m8767_irqs[irq - sec_pmic->irq_base]; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static void s5m8767_irq_lock(struct irq_data *data) |
| 180 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 181 | struct sec_pmic_dev *sec_pmic = irq_data_get_irq_chip_data(data); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 182 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 183 | mutex_lock(&sec_pmic->irqlock); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static void s5m8767_irq_sync_unlock(struct irq_data *data) |
| 187 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 188 | struct sec_pmic_dev *sec_pmic = irq_data_get_irq_chip_data(data); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 189 | int i; |
| 190 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 191 | for (i = 0; i < ARRAY_SIZE(sec_pmic->irq_masks_cur); i++) { |
| 192 | if (sec_pmic->irq_masks_cur[i] != sec_pmic->irq_masks_cache[i]) { |
| 193 | sec_pmic->irq_masks_cache[i] = sec_pmic->irq_masks_cur[i]; |
| 194 | sec_reg_write(sec_pmic, S5M8767_REG_INT1M + i, |
| 195 | sec_pmic->irq_masks_cur[i]); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 199 | mutex_unlock(&sec_pmic->irqlock); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static void s5m8767_irq_unmask(struct irq_data *data) |
| 203 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 204 | struct sec_pmic_dev *sec_pmic = irq_data_get_irq_chip_data(data); |
| 205 | struct sec_irq_data *irq_data = irq_to_s5m8767_irq(sec_pmic, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 206 | data->irq); |
| 207 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 208 | sec_pmic->irq_masks_cur[irq_data->reg - 1] &= ~irq_data->mask; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | static void s5m8767_irq_mask(struct irq_data *data) |
| 212 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 213 | struct sec_pmic_dev *sec_pmic = irq_data_get_irq_chip_data(data); |
| 214 | struct sec_irq_data *irq_data = irq_to_s5m8767_irq(sec_pmic, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 215 | data->irq); |
| 216 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 217 | sec_pmic->irq_masks_cur[irq_data->reg - 1] |= irq_data->mask; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static struct irq_chip s5m8767_irq_chip = { |
| 221 | .name = "s5m8767", |
| 222 | .irq_bus_lock = s5m8767_irq_lock, |
| 223 | .irq_bus_sync_unlock = s5m8767_irq_sync_unlock, |
| 224 | .irq_mask = s5m8767_irq_mask, |
| 225 | .irq_unmask = s5m8767_irq_unmask, |
| 226 | }; |
| 227 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 228 | static inline struct sec_irq_data * |
| 229 | irq_to_s5m8763_irq(struct sec_pmic_dev *sec_pmic, int irq) |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 230 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 231 | return &s5m8763_irqs[irq - sec_pmic->irq_base]; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static void s5m8763_irq_lock(struct irq_data *data) |
| 235 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 236 | struct sec_pmic_dev *sec_pmic = irq_data_get_irq_chip_data(data); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 237 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 238 | mutex_lock(&sec_pmic->irqlock); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static void s5m8763_irq_sync_unlock(struct irq_data *data) |
| 242 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 243 | struct sec_pmic_dev *sec_pmic = irq_data_get_irq_chip_data(data); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 244 | int i; |
| 245 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 246 | for (i = 0; i < ARRAY_SIZE(sec_pmic->irq_masks_cur); i++) { |
| 247 | if (sec_pmic->irq_masks_cur[i] != sec_pmic->irq_masks_cache[i]) { |
| 248 | sec_pmic->irq_masks_cache[i] = sec_pmic->irq_masks_cur[i]; |
| 249 | sec_reg_write(sec_pmic, S5M8763_REG_IRQM1 + i, |
| 250 | sec_pmic->irq_masks_cur[i]); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 254 | mutex_unlock(&sec_pmic->irqlock); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | static void s5m8763_irq_unmask(struct irq_data *data) |
| 258 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 259 | struct sec_pmic_dev *sec_pmic = irq_data_get_irq_chip_data(data); |
| 260 | struct sec_irq_data *irq_data = irq_to_s5m8763_irq(sec_pmic, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 261 | data->irq); |
| 262 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 263 | sec_pmic->irq_masks_cur[irq_data->reg - 1] &= ~irq_data->mask; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static void s5m8763_irq_mask(struct irq_data *data) |
| 267 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 268 | struct sec_pmic_dev *sec_pmic = irq_data_get_irq_chip_data(data); |
| 269 | struct sec_irq_data *irq_data = irq_to_s5m8763_irq(sec_pmic, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 270 | data->irq); |
| 271 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 272 | sec_pmic->irq_masks_cur[irq_data->reg - 1] |= irq_data->mask; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | static struct irq_chip s5m8763_irq_chip = { |
| 276 | .name = "s5m8763", |
| 277 | .irq_bus_lock = s5m8763_irq_lock, |
| 278 | .irq_bus_sync_unlock = s5m8763_irq_sync_unlock, |
| 279 | .irq_mask = s5m8763_irq_mask, |
| 280 | .irq_unmask = s5m8763_irq_unmask, |
| 281 | }; |
| 282 | |
| 283 | |
| 284 | static irqreturn_t s5m8767_irq_thread(int irq, void *data) |
| 285 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 286 | struct sec_pmic_dev *sec_pmic = data; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 287 | u8 irq_reg[NUM_IRQ_REGS-1]; |
| 288 | int ret; |
| 289 | int i; |
| 290 | |
| 291 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 292 | ret = sec_bulk_read(sec_pmic, S5M8767_REG_INT1, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 293 | NUM_IRQ_REGS - 1, irq_reg); |
| 294 | if (ret < 0) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 295 | dev_err(sec_pmic->dev, "Failed to read interrupt register: %d\n", |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 296 | ret); |
| 297 | return IRQ_NONE; |
| 298 | } |
| 299 | |
| 300 | for (i = 0; i < NUM_IRQ_REGS - 1; i++) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 301 | irq_reg[i] &= ~sec_pmic->irq_masks_cur[i]; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 302 | |
| 303 | for (i = 0; i < S5M8767_IRQ_NR; i++) { |
| 304 | if (irq_reg[s5m8767_irqs[i].reg - 1] & s5m8767_irqs[i].mask) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 305 | handle_nested_irq(sec_pmic->irq_base + i); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | return IRQ_HANDLED; |
| 309 | } |
| 310 | |
| 311 | static irqreturn_t s5m8763_irq_thread(int irq, void *data) |
| 312 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 313 | struct sec_pmic_dev *sec_pmic = data; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 314 | u8 irq_reg[NUM_IRQ_REGS]; |
| 315 | int ret; |
| 316 | int i; |
| 317 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 318 | ret = sec_bulk_read(sec_pmic, S5M8763_REG_IRQ1, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 319 | NUM_IRQ_REGS, irq_reg); |
| 320 | if (ret < 0) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 321 | dev_err(sec_pmic->dev, "Failed to read interrupt register: %d\n", |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 322 | ret); |
| 323 | return IRQ_NONE; |
| 324 | } |
| 325 | |
| 326 | for (i = 0; i < NUM_IRQ_REGS; i++) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 327 | irq_reg[i] &= ~sec_pmic->irq_masks_cur[i]; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 328 | |
| 329 | for (i = 0; i < S5M8763_IRQ_NR; i++) { |
| 330 | if (irq_reg[s5m8763_irqs[i].reg - 1] & s5m8763_irqs[i].mask) |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 331 | handle_nested_irq(sec_pmic->irq_base + i); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | return IRQ_HANDLED; |
| 335 | } |
| 336 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 337 | int sec_irq_resume(struct sec_pmic_dev *sec_pmic) |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 338 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 339 | if (sec_pmic->irq && sec_pmic->irq_base) { |
| 340 | switch (sec_pmic->device_type) { |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 341 | case S5M8763X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 342 | s5m8763_irq_thread(sec_pmic->irq_base, sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 343 | break; |
| 344 | case S5M8767X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 345 | s5m8767_irq_thread(sec_pmic->irq_base, sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 346 | break; |
| 347 | default: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 348 | dev_err(sec_pmic->dev, |
Jonghwan Choi | c7a1fcf | 2012-02-20 16:22:56 +0100 | [diff] [blame] | 349 | "Unknown device type %d\n", |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 350 | sec_pmic->device_type); |
Jonghwan Choi | c7a1fcf | 2012-02-20 16:22:56 +0100 | [diff] [blame] | 351 | return -EINVAL; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 352 | |
| 353 | } |
| 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 358 | int sec_irq_init(struct sec_pmic_dev *sec_pmic) |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 359 | { |
| 360 | int i; |
| 361 | int cur_irq; |
| 362 | int ret = 0; |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 363 | int type = sec_pmic->device_type; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 364 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 365 | if (!sec_pmic->irq) { |
| 366 | dev_warn(sec_pmic->dev, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 367 | "No interrupt specified, no interrupts\n"); |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 368 | sec_pmic->irq_base = 0; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 369 | return 0; |
| 370 | } |
| 371 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 372 | if (!sec_pmic->irq_base) { |
| 373 | dev_err(sec_pmic->dev, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 374 | "No interrupt base specified, no interrupts\n"); |
| 375 | return 0; |
| 376 | } |
| 377 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 378 | mutex_init(&sec_pmic->irqlock); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 379 | |
| 380 | switch (type) { |
| 381 | case S5M8763X: |
| 382 | for (i = 0; i < NUM_IRQ_REGS; i++) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 383 | sec_pmic->irq_masks_cur[i] = 0xff; |
| 384 | sec_pmic->irq_masks_cache[i] = 0xff; |
| 385 | sec_reg_write(sec_pmic, S5M8763_REG_IRQM1 + i, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 386 | 0xff); |
| 387 | } |
| 388 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 389 | sec_reg_write(sec_pmic, S5M8763_REG_STATUSM1, 0xff); |
| 390 | sec_reg_write(sec_pmic, S5M8763_REG_STATUSM2, 0xff); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 391 | |
| 392 | for (i = 0; i < S5M8763_IRQ_NR; i++) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 393 | cur_irq = i + sec_pmic->irq_base; |
| 394 | irq_set_chip_data(cur_irq, sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 395 | irq_set_chip_and_handler(cur_irq, &s5m8763_irq_chip, |
| 396 | handle_edge_irq); |
| 397 | irq_set_nested_thread(cur_irq, 1); |
| 398 | #ifdef CONFIG_ARM |
| 399 | set_irq_flags(cur_irq, IRQF_VALID); |
| 400 | #else |
| 401 | irq_set_noprobe(cur_irq); |
| 402 | #endif |
| 403 | } |
| 404 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 405 | ret = request_threaded_irq(sec_pmic->irq, NULL, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 406 | s5m8763_irq_thread, |
| 407 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 408 | "sec-pmic-irq", sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 409 | if (ret) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 410 | dev_err(sec_pmic->dev, "Failed to request IRQ %d: %d\n", |
| 411 | sec_pmic->irq, ret); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 412 | return ret; |
| 413 | } |
| 414 | break; |
| 415 | case S5M8767X: |
| 416 | for (i = 0; i < NUM_IRQ_REGS - 1; i++) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 417 | sec_pmic->irq_masks_cur[i] = 0xff; |
| 418 | sec_pmic->irq_masks_cache[i] = 0xff; |
| 419 | sec_reg_write(sec_pmic, S5M8767_REG_INT1M + i, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 420 | 0xff); |
| 421 | } |
| 422 | for (i = 0; i < S5M8767_IRQ_NR; i++) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 423 | cur_irq = i + sec_pmic->irq_base; |
| 424 | irq_set_chip_data(cur_irq, sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 425 | if (ret) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 426 | dev_err(sec_pmic->dev, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 427 | "Failed to irq_set_chip_data %d: %d\n", |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 428 | sec_pmic->irq, ret); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | irq_set_chip_and_handler(cur_irq, &s5m8767_irq_chip, |
| 433 | handle_edge_irq); |
| 434 | irq_set_nested_thread(cur_irq, 1); |
| 435 | #ifdef CONFIG_ARM |
| 436 | set_irq_flags(cur_irq, IRQF_VALID); |
| 437 | #else |
| 438 | irq_set_noprobe(cur_irq); |
| 439 | #endif |
| 440 | } |
| 441 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 442 | ret = request_threaded_irq(sec_pmic->irq, NULL, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 443 | s5m8767_irq_thread, |
| 444 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 445 | "sec-pmic-irq", sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 446 | if (ret) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 447 | dev_err(sec_pmic->dev, "Failed to request IRQ %d: %d\n", |
| 448 | sec_pmic->irq, ret); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 449 | return ret; |
| 450 | } |
| 451 | break; |
| 452 | default: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 453 | dev_err(sec_pmic->dev, |
| 454 | "Unknown device type %d\n", sec_pmic->device_type); |
Jonghwan Choi | c7a1fcf | 2012-02-20 16:22:56 +0100 | [diff] [blame] | 455 | return -EINVAL; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 456 | } |
| 457 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 458 | if (!sec_pmic->ono) |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 459 | return 0; |
| 460 | |
| 461 | switch (type) { |
| 462 | case S5M8763X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 463 | ret = request_threaded_irq(sec_pmic->ono, NULL, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 464 | s5m8763_irq_thread, |
| 465 | IRQF_TRIGGER_FALLING | |
| 466 | IRQF_TRIGGER_RISING | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 467 | IRQF_ONESHOT, "sec_pmic-ono", |
| 468 | sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 469 | break; |
| 470 | case S5M8767X: |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 471 | ret = request_threaded_irq(sec_pmic->ono, NULL, |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 472 | s5m8767_irq_thread, |
| 473 | IRQF_TRIGGER_FALLING | |
| 474 | IRQF_TRIGGER_RISING | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 475 | IRQF_ONESHOT, "sec_pmic-ono", sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 476 | break; |
| 477 | default: |
Jonghwan Choi | c7a1fcf | 2012-02-20 16:22:56 +0100 | [diff] [blame] | 478 | ret = -EINVAL; |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 479 | break; |
| 480 | } |
| 481 | |
Jonghwan Choi | c7a1fcf | 2012-02-20 16:22:56 +0100 | [diff] [blame] | 482 | if (ret) { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 483 | dev_err(sec_pmic->dev, "Failed to request IRQ %d: %d\n", |
| 484 | sec_pmic->ono, ret); |
Jonghwan Choi | c7a1fcf | 2012-02-20 16:22:56 +0100 | [diff] [blame] | 485 | return ret; |
| 486 | } |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 491 | void sec_irq_exit(struct sec_pmic_dev *sec_pmic) |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 492 | { |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 493 | if (sec_pmic->ono) |
| 494 | free_irq(sec_pmic->ono, sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 495 | |
Sangbeom Kim | 63063bf | 2012-07-11 21:06:55 +0900 | [diff] [blame] | 496 | if (sec_pmic->irq) |
| 497 | free_irq(sec_pmic->irq, sec_pmic); |
Sangbeom Kim | 5ac2ffa7 | 2011-12-23 17:28:09 +0900 | [diff] [blame] | 498 | } |