Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2010 |
| 3 | * |
| 4 | * License Terms: GNU General Public License v2 |
| 5 | * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com> |
| 6 | * Author: Rabin Vincent <rabin.vincent@stericsson.com> |
Mattias Wallin | adceed6 | 2011-03-02 11:51:11 +0100 | [diff] [blame] | 7 | * Author: Mattias Wallin <mattias.wallin@stericsson.com> |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/irq.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/mfd/core.h> |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 19 | #include <linux/mfd/abx500.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 20 | #include <linux/mfd/abx500/ab8500.h> |
Sundar R Iyer | 549931f | 2010-07-13 11:51:28 +0530 | [diff] [blame] | 21 | #include <linux/regulator/ab8500.h> |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * Interrupt register offsets |
| 25 | * Bank : 0x0E |
| 26 | */ |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 27 | #define AB8500_IT_SOURCE1_REG 0x00 |
| 28 | #define AB8500_IT_SOURCE2_REG 0x01 |
| 29 | #define AB8500_IT_SOURCE3_REG 0x02 |
| 30 | #define AB8500_IT_SOURCE4_REG 0x03 |
| 31 | #define AB8500_IT_SOURCE5_REG 0x04 |
| 32 | #define AB8500_IT_SOURCE6_REG 0x05 |
| 33 | #define AB8500_IT_SOURCE7_REG 0x06 |
| 34 | #define AB8500_IT_SOURCE8_REG 0x07 |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 35 | #define AB9540_IT_SOURCE13_REG 0x0C |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 36 | #define AB8500_IT_SOURCE19_REG 0x12 |
| 37 | #define AB8500_IT_SOURCE20_REG 0x13 |
| 38 | #define AB8500_IT_SOURCE21_REG 0x14 |
| 39 | #define AB8500_IT_SOURCE22_REG 0x15 |
| 40 | #define AB8500_IT_SOURCE23_REG 0x16 |
| 41 | #define AB8500_IT_SOURCE24_REG 0x17 |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * latch registers |
| 45 | */ |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 46 | #define AB8500_IT_LATCH1_REG 0x20 |
| 47 | #define AB8500_IT_LATCH2_REG 0x21 |
| 48 | #define AB8500_IT_LATCH3_REG 0x22 |
| 49 | #define AB8500_IT_LATCH4_REG 0x23 |
| 50 | #define AB8500_IT_LATCH5_REG 0x24 |
| 51 | #define AB8500_IT_LATCH6_REG 0x25 |
| 52 | #define AB8500_IT_LATCH7_REG 0x26 |
| 53 | #define AB8500_IT_LATCH8_REG 0x27 |
| 54 | #define AB8500_IT_LATCH9_REG 0x28 |
| 55 | #define AB8500_IT_LATCH10_REG 0x29 |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 56 | #define AB8500_IT_LATCH12_REG 0x2B |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 57 | #define AB9540_IT_LATCH13_REG 0x2C |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 58 | #define AB8500_IT_LATCH19_REG 0x32 |
| 59 | #define AB8500_IT_LATCH20_REG 0x33 |
| 60 | #define AB8500_IT_LATCH21_REG 0x34 |
| 61 | #define AB8500_IT_LATCH22_REG 0x35 |
| 62 | #define AB8500_IT_LATCH23_REG 0x36 |
| 63 | #define AB8500_IT_LATCH24_REG 0x37 |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * mask registers |
| 67 | */ |
| 68 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 69 | #define AB8500_IT_MASK1_REG 0x40 |
| 70 | #define AB8500_IT_MASK2_REG 0x41 |
| 71 | #define AB8500_IT_MASK3_REG 0x42 |
| 72 | #define AB8500_IT_MASK4_REG 0x43 |
| 73 | #define AB8500_IT_MASK5_REG 0x44 |
| 74 | #define AB8500_IT_MASK6_REG 0x45 |
| 75 | #define AB8500_IT_MASK7_REG 0x46 |
| 76 | #define AB8500_IT_MASK8_REG 0x47 |
| 77 | #define AB8500_IT_MASK9_REG 0x48 |
| 78 | #define AB8500_IT_MASK10_REG 0x49 |
| 79 | #define AB8500_IT_MASK11_REG 0x4A |
| 80 | #define AB8500_IT_MASK12_REG 0x4B |
| 81 | #define AB8500_IT_MASK13_REG 0x4C |
| 82 | #define AB8500_IT_MASK14_REG 0x4D |
| 83 | #define AB8500_IT_MASK15_REG 0x4E |
| 84 | #define AB8500_IT_MASK16_REG 0x4F |
| 85 | #define AB8500_IT_MASK17_REG 0x50 |
| 86 | #define AB8500_IT_MASK18_REG 0x51 |
| 87 | #define AB8500_IT_MASK19_REG 0x52 |
| 88 | #define AB8500_IT_MASK20_REG 0x53 |
| 89 | #define AB8500_IT_MASK21_REG 0x54 |
| 90 | #define AB8500_IT_MASK22_REG 0x55 |
| 91 | #define AB8500_IT_MASK23_REG 0x56 |
| 92 | #define AB8500_IT_MASK24_REG 0x57 |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 93 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 94 | #define AB8500_REV_REG 0x80 |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 95 | #define AB8500_IC_NAME_REG 0x82 |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 96 | #define AB8500_SWITCH_OFF_STATUS 0x00 |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 97 | |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 98 | #define AB8500_TURN_ON_STATUS 0x00 |
| 99 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 100 | #define AB9540_MODEM_CTRL2_REG 0x23 |
| 101 | #define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT BIT(2) |
| 102 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 103 | /* |
| 104 | * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 105 | * numbers are indexed into this array with (num / 8). The interupts are |
| 106 | * defined in linux/mfd/ab8500.h |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 107 | * |
| 108 | * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at |
| 109 | * offset 0. |
| 110 | */ |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 111 | /* AB8500 support */ |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 112 | static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = { |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 113 | 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 114 | }; |
| 115 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 116 | /* AB9540 support */ |
| 117 | static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = { |
| 118 | 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24, |
| 119 | }; |
| 120 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 121 | static const char ab8500_version_str[][7] = { |
| 122 | [AB8500_VERSION_AB8500] = "AB8500", |
| 123 | [AB8500_VERSION_AB8505] = "AB8505", |
| 124 | [AB8500_VERSION_AB9540] = "AB9540", |
| 125 | [AB8500_VERSION_AB8540] = "AB8540", |
| 126 | }; |
| 127 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 128 | static int ab8500_get_chip_id(struct device *dev) |
| 129 | { |
Mattias Wallin | 6bce7bf | 2010-12-02 15:08:32 +0100 | [diff] [blame] | 130 | struct ab8500 *ab8500; |
| 131 | |
| 132 | if (!dev) |
| 133 | return -EINVAL; |
| 134 | ab8500 = dev_get_drvdata(dev->parent); |
| 135 | return ab8500 ? (int)ab8500->chip_id : -EINVAL; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static int set_register_interruptible(struct ab8500 *ab8500, u8 bank, |
| 139 | u8 reg, u8 data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 140 | { |
| 141 | int ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 142 | /* |
| 143 | * Put the u8 bank and u8 register together into a an u16. |
| 144 | * The bank on higher 8 bits and register in lower 8 bits. |
| 145 | * */ |
| 146 | u16 addr = ((u16)bank) << 8 | reg; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 147 | |
| 148 | dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data); |
| 149 | |
Rabin Vincent | 392cbd1 | 2012-03-08 14:01:46 +0100 | [diff] [blame] | 150 | mutex_lock(&ab8500->lock); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 151 | |
| 152 | ret = ab8500->write(ab8500, addr, data); |
| 153 | if (ret < 0) |
| 154 | dev_err(ab8500->dev, "failed to write reg %#x: %d\n", |
| 155 | addr, ret); |
| 156 | mutex_unlock(&ab8500->lock); |
| 157 | |
| 158 | return ret; |
| 159 | } |
| 160 | |
| 161 | static int ab8500_set_register(struct device *dev, u8 bank, |
| 162 | u8 reg, u8 value) |
| 163 | { |
| 164 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); |
| 165 | |
| 166 | return set_register_interruptible(ab8500, bank, reg, value); |
| 167 | } |
| 168 | |
| 169 | static int get_register_interruptible(struct ab8500 *ab8500, u8 bank, |
| 170 | u8 reg, u8 *value) |
| 171 | { |
| 172 | int ret; |
| 173 | /* put the u8 bank and u8 reg together into a an u16. |
| 174 | * bank on higher 8 bits and reg in lower */ |
| 175 | u16 addr = ((u16)bank) << 8 | reg; |
| 176 | |
Rabin Vincent | 392cbd1 | 2012-03-08 14:01:46 +0100 | [diff] [blame] | 177 | mutex_lock(&ab8500->lock); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 178 | |
| 179 | ret = ab8500->read(ab8500, addr); |
| 180 | if (ret < 0) |
| 181 | dev_err(ab8500->dev, "failed to read reg %#x: %d\n", |
| 182 | addr, ret); |
| 183 | else |
| 184 | *value = ret; |
| 185 | |
| 186 | mutex_unlock(&ab8500->lock); |
| 187 | dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret); |
| 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | |
| 192 | static int ab8500_get_register(struct device *dev, u8 bank, |
| 193 | u8 reg, u8 *value) |
| 194 | { |
| 195 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); |
| 196 | |
| 197 | return get_register_interruptible(ab8500, bank, reg, value); |
| 198 | } |
| 199 | |
| 200 | static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank, |
| 201 | u8 reg, u8 bitmask, u8 bitvalues) |
| 202 | { |
| 203 | int ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 204 | /* put the u8 bank and u8 reg together into a an u16. |
| 205 | * bank on higher 8 bits and reg in lower */ |
| 206 | u16 addr = ((u16)bank) << 8 | reg; |
| 207 | |
Rabin Vincent | 392cbd1 | 2012-03-08 14:01:46 +0100 | [diff] [blame] | 208 | mutex_lock(&ab8500->lock); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 209 | |
Mattias Nilsson | bc628fd | 2012-03-08 14:02:20 +0100 | [diff] [blame] | 210 | if (ab8500->write_masked == NULL) { |
| 211 | u8 data; |
| 212 | |
| 213 | ret = ab8500->read(ab8500, addr); |
| 214 | if (ret < 0) { |
| 215 | dev_err(ab8500->dev, "failed to read reg %#x: %d\n", |
| 216 | addr, ret); |
| 217 | goto out; |
| 218 | } |
| 219 | |
| 220 | data = (u8)ret; |
| 221 | data = (~bitmask & data) | (bitmask & bitvalues); |
| 222 | |
| 223 | ret = ab8500->write(ab8500, addr, data); |
| 224 | if (ret < 0) |
| 225 | dev_err(ab8500->dev, "failed to write reg %#x: %d\n", |
| 226 | addr, ret); |
| 227 | |
| 228 | dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, |
| 229 | data); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 230 | goto out; |
| 231 | } |
Mattias Nilsson | bc628fd | 2012-03-08 14:02:20 +0100 | [diff] [blame] | 232 | ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 233 | if (ret < 0) |
Mattias Nilsson | bc628fd | 2012-03-08 14:02:20 +0100 | [diff] [blame] | 234 | dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr, |
| 235 | ret); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 236 | out: |
| 237 | mutex_unlock(&ab8500->lock); |
| 238 | return ret; |
| 239 | } |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 240 | |
| 241 | static int ab8500_mask_and_set_register(struct device *dev, |
| 242 | u8 bank, u8 reg, u8 bitmask, u8 bitvalues) |
| 243 | { |
| 244 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); |
| 245 | |
| 246 | return mask_and_set_register_interruptible(ab8500, bank, reg, |
| 247 | bitmask, bitvalues); |
| 248 | |
| 249 | } |
| 250 | |
| 251 | static struct abx500_ops ab8500_ops = { |
| 252 | .get_chip_id = ab8500_get_chip_id, |
| 253 | .get_register = ab8500_get_register, |
| 254 | .set_register = ab8500_set_register, |
| 255 | .get_register_page = NULL, |
| 256 | .set_register_page = NULL, |
| 257 | .mask_and_set_register = ab8500_mask_and_set_register, |
| 258 | .event_registers_startup_state_get = NULL, |
| 259 | .startup_irq_enabled = NULL, |
| 260 | }; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 261 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 262 | static void ab8500_irq_lock(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 263 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 264 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 265 | |
| 266 | mutex_lock(&ab8500->irq_lock); |
| 267 | } |
| 268 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 269 | static void ab8500_irq_sync_unlock(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 270 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 271 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 272 | int i; |
| 273 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 274 | for (i = 0; i < ab8500->mask_size; i++) { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 275 | u8 old = ab8500->oldmask[i]; |
| 276 | u8 new = ab8500->mask[i]; |
| 277 | int reg; |
| 278 | |
| 279 | if (new == old) |
| 280 | continue; |
| 281 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 282 | /* |
| 283 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 284 | * 2.0 |
| 285 | */ |
| 286 | if (ab8500->irq_reg_offset[i] == 11 && |
| 287 | is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 288 | continue; |
| 289 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 290 | ab8500->oldmask[i] = new; |
| 291 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 292 | reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i]; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 293 | set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | mutex_unlock(&ab8500->irq_lock); |
| 297 | } |
| 298 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 299 | static void ab8500_irq_mask(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 300 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 301 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
| 302 | int offset = data->irq - ab8500->irq_base; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 303 | int index = offset / 8; |
| 304 | int mask = 1 << (offset % 8); |
| 305 | |
| 306 | ab8500->mask[index] |= mask; |
| 307 | } |
| 308 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 309 | static void ab8500_irq_unmask(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 310 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 311 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
| 312 | int offset = data->irq - ab8500->irq_base; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 313 | int index = offset / 8; |
| 314 | int mask = 1 << (offset % 8); |
| 315 | |
| 316 | ab8500->mask[index] &= ~mask; |
| 317 | } |
| 318 | |
| 319 | static struct irq_chip ab8500_irq_chip = { |
| 320 | .name = "ab8500", |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 321 | .irq_bus_lock = ab8500_irq_lock, |
| 322 | .irq_bus_sync_unlock = ab8500_irq_sync_unlock, |
| 323 | .irq_mask = ab8500_irq_mask, |
Virupax Sadashivpetimath | e6f9306 | 2011-10-11 10:49:17 +0200 | [diff] [blame] | 324 | .irq_disable = ab8500_irq_mask, |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 325 | .irq_unmask = ab8500_irq_unmask, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 326 | }; |
| 327 | |
| 328 | static irqreturn_t ab8500_irq(int irq, void *dev) |
| 329 | { |
| 330 | struct ab8500 *ab8500 = dev; |
| 331 | int i; |
| 332 | |
| 333 | dev_vdbg(ab8500->dev, "interrupt\n"); |
| 334 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 335 | for (i = 0; i < ab8500->mask_size; i++) { |
| 336 | int regoffset = ab8500->irq_reg_offset[i]; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 337 | int status; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 338 | u8 value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 339 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 340 | /* |
| 341 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 342 | * 2.0 |
| 343 | */ |
| 344 | if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 345 | continue; |
| 346 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 347 | status = get_register_interruptible(ab8500, AB8500_INTERRUPT, |
| 348 | AB8500_IT_LATCH1_REG + regoffset, &value); |
| 349 | if (status < 0 || value == 0) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 350 | continue; |
| 351 | |
| 352 | do { |
Mattias Wallin | 88aec4f | 2010-12-02 15:06:49 +0100 | [diff] [blame] | 353 | int bit = __ffs(value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 354 | int line = i * 8 + bit; |
| 355 | |
| 356 | handle_nested_irq(ab8500->irq_base + line); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 357 | value &= ~(1 << bit); |
| 358 | } while (value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | return IRQ_HANDLED; |
| 362 | } |
| 363 | |
| 364 | static int ab8500_irq_init(struct ab8500 *ab8500) |
| 365 | { |
| 366 | int base = ab8500->irq_base; |
| 367 | int irq; |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 368 | int num_irqs; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 369 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 370 | if (is_ab9540(ab8500)) |
| 371 | num_irqs = AB9540_NR_IRQS; |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 372 | else if (is_ab8505(ab8500)) |
| 373 | num_irqs = AB8505_NR_IRQS; |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 374 | else |
| 375 | num_irqs = AB8500_NR_IRQS; |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 376 | |
| 377 | for (irq = base; irq < base + num_irqs; irq++) { |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 378 | irq_set_chip_data(irq, ab8500); |
| 379 | irq_set_chip_and_handler(irq, &ab8500_irq_chip, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 380 | handle_simple_irq); |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 381 | irq_set_nested_thread(irq, 1); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 382 | #ifdef CONFIG_ARM |
| 383 | set_irq_flags(irq, IRQF_VALID); |
| 384 | #else |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 385 | irq_set_noprobe(irq); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 386 | #endif |
| 387 | } |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static void ab8500_irq_remove(struct ab8500 *ab8500) |
| 393 | { |
| 394 | int base = ab8500->irq_base; |
| 395 | int irq; |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 396 | int num_irqs; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 397 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 398 | if (is_ab9540(ab8500)) |
| 399 | num_irqs = AB9540_NR_IRQS; |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 400 | else if (is_ab8505(ab8500)) |
| 401 | num_irqs = AB8505_NR_IRQS; |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 402 | else |
| 403 | num_irqs = AB8500_NR_IRQS; |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 404 | |
| 405 | for (irq = base; irq < base + num_irqs; irq++) { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 406 | #ifdef CONFIG_ARM |
| 407 | set_irq_flags(irq, 0); |
| 408 | #endif |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 409 | irq_set_chip_and_handler(irq, NULL, NULL); |
| 410 | irq_set_chip_data(irq, NULL); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 414 | /* AB8500 GPIO Resources */ |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 415 | static struct resource __devinitdata ab8500_gpio_resources[] = { |
Bibek Basu | 0cb3fcd | 2011-02-09 11:02:35 +0530 | [diff] [blame] | 416 | { |
| 417 | .name = "GPIO_INT6", |
| 418 | .start = AB8500_INT_GPIO6R, |
| 419 | .end = AB8500_INT_GPIO41F, |
| 420 | .flags = IORESOURCE_IRQ, |
| 421 | } |
| 422 | }; |
| 423 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 424 | /* AB9540 GPIO Resources */ |
| 425 | static struct resource __devinitdata ab9540_gpio_resources[] = { |
| 426 | { |
| 427 | .name = "GPIO_INT6", |
| 428 | .start = AB8500_INT_GPIO6R, |
| 429 | .end = AB8500_INT_GPIO41F, |
| 430 | .flags = IORESOURCE_IRQ, |
| 431 | }, |
| 432 | { |
| 433 | .name = "GPIO_INT14", |
| 434 | .start = AB9540_INT_GPIO50R, |
| 435 | .end = AB9540_INT_GPIO54R, |
| 436 | .flags = IORESOURCE_IRQ, |
| 437 | }, |
| 438 | { |
| 439 | .name = "GPIO_INT15", |
| 440 | .start = AB9540_INT_GPIO50F, |
| 441 | .end = AB9540_INT_GPIO54F, |
| 442 | .flags = IORESOURCE_IRQ, |
| 443 | } |
| 444 | }; |
| 445 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 446 | static struct resource __devinitdata ab8500_gpadc_resources[] = { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 447 | { |
| 448 | .name = "HW_CONV_END", |
| 449 | .start = AB8500_INT_GP_HW_ADC_CONV_END, |
| 450 | .end = AB8500_INT_GP_HW_ADC_CONV_END, |
| 451 | .flags = IORESOURCE_IRQ, |
| 452 | }, |
| 453 | { |
| 454 | .name = "SW_CONV_END", |
| 455 | .start = AB8500_INT_GP_SW_ADC_CONV_END, |
| 456 | .end = AB8500_INT_GP_SW_ADC_CONV_END, |
| 457 | .flags = IORESOURCE_IRQ, |
| 458 | }, |
| 459 | }; |
| 460 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 461 | static struct resource __devinitdata ab8500_rtc_resources[] = { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 462 | { |
| 463 | .name = "60S", |
| 464 | .start = AB8500_INT_RTC_60S, |
| 465 | .end = AB8500_INT_RTC_60S, |
| 466 | .flags = IORESOURCE_IRQ, |
| 467 | }, |
| 468 | { |
| 469 | .name = "ALARM", |
| 470 | .start = AB8500_INT_RTC_ALARM, |
| 471 | .end = AB8500_INT_RTC_ALARM, |
| 472 | .flags = IORESOURCE_IRQ, |
| 473 | }, |
| 474 | }; |
| 475 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 476 | static struct resource __devinitdata ab8500_poweronkey_db_resources[] = { |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 477 | { |
| 478 | .name = "ONKEY_DBF", |
| 479 | .start = AB8500_INT_PON_KEY1DB_F, |
| 480 | .end = AB8500_INT_PON_KEY1DB_F, |
| 481 | .flags = IORESOURCE_IRQ, |
| 482 | }, |
| 483 | { |
| 484 | .name = "ONKEY_DBR", |
| 485 | .start = AB8500_INT_PON_KEY1DB_R, |
| 486 | .end = AB8500_INT_PON_KEY1DB_R, |
| 487 | .flags = IORESOURCE_IRQ, |
| 488 | }, |
| 489 | }; |
| 490 | |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 491 | static struct resource __devinitdata ab8500_av_acc_detect_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 492 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 493 | .name = "ACC_DETECT_1DB_F", |
| 494 | .start = AB8500_INT_ACC_DETECT_1DB_F, |
| 495 | .end = AB8500_INT_ACC_DETECT_1DB_F, |
| 496 | .flags = IORESOURCE_IRQ, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 497 | }, |
| 498 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 499 | .name = "ACC_DETECT_1DB_R", |
| 500 | .start = AB8500_INT_ACC_DETECT_1DB_R, |
| 501 | .end = AB8500_INT_ACC_DETECT_1DB_R, |
| 502 | .flags = IORESOURCE_IRQ, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 503 | }, |
| 504 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 505 | .name = "ACC_DETECT_21DB_F", |
| 506 | .start = AB8500_INT_ACC_DETECT_21DB_F, |
| 507 | .end = AB8500_INT_ACC_DETECT_21DB_F, |
| 508 | .flags = IORESOURCE_IRQ, |
| 509 | }, |
| 510 | { |
| 511 | .name = "ACC_DETECT_21DB_R", |
| 512 | .start = AB8500_INT_ACC_DETECT_21DB_R, |
| 513 | .end = AB8500_INT_ACC_DETECT_21DB_R, |
| 514 | .flags = IORESOURCE_IRQ, |
| 515 | }, |
| 516 | { |
| 517 | .name = "ACC_DETECT_22DB_F", |
| 518 | .start = AB8500_INT_ACC_DETECT_22DB_F, |
| 519 | .end = AB8500_INT_ACC_DETECT_22DB_F, |
| 520 | .flags = IORESOURCE_IRQ, |
| 521 | }, |
| 522 | { |
| 523 | .name = "ACC_DETECT_22DB_R", |
| 524 | .start = AB8500_INT_ACC_DETECT_22DB_R, |
| 525 | .end = AB8500_INT_ACC_DETECT_22DB_R, |
| 526 | .flags = IORESOURCE_IRQ, |
| 527 | }, |
| 528 | }; |
| 529 | |
| 530 | static struct resource __devinitdata ab8500_charger_resources[] = { |
| 531 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 532 | .name = "MAIN_CH_UNPLUG_DET", |
| 533 | .start = AB8500_INT_MAIN_CH_UNPLUG_DET, |
| 534 | .end = AB8500_INT_MAIN_CH_UNPLUG_DET, |
| 535 | .flags = IORESOURCE_IRQ, |
| 536 | }, |
| 537 | { |
| 538 | .name = "MAIN_CHARGE_PLUG_DET", |
| 539 | .start = AB8500_INT_MAIN_CH_PLUG_DET, |
| 540 | .end = AB8500_INT_MAIN_CH_PLUG_DET, |
| 541 | .flags = IORESOURCE_IRQ, |
| 542 | }, |
| 543 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 544 | .name = "VBUS_DET_R", |
| 545 | .start = AB8500_INT_VBUS_DET_R, |
| 546 | .end = AB8500_INT_VBUS_DET_R, |
| 547 | .flags = IORESOURCE_IRQ, |
| 548 | }, |
| 549 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 550 | .name = "VBUS_DET_F", |
| 551 | .start = AB8500_INT_VBUS_DET_F, |
| 552 | .end = AB8500_INT_VBUS_DET_F, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 553 | .flags = IORESOURCE_IRQ, |
| 554 | }, |
| 555 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 556 | .name = "USB_LINK_STATUS", |
| 557 | .start = AB8500_INT_USB_LINK_STATUS, |
| 558 | .end = AB8500_INT_USB_LINK_STATUS, |
| 559 | .flags = IORESOURCE_IRQ, |
| 560 | }, |
| 561 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 562 | .name = "VBUS_OVV", |
| 563 | .start = AB8500_INT_VBUS_OVV, |
| 564 | .end = AB8500_INT_VBUS_OVV, |
| 565 | .flags = IORESOURCE_IRQ, |
| 566 | }, |
| 567 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 568 | .name = "USB_CH_TH_PROT_R", |
| 569 | .start = AB8500_INT_USB_CH_TH_PROT_R, |
| 570 | .end = AB8500_INT_USB_CH_TH_PROT_R, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 571 | .flags = IORESOURCE_IRQ, |
| 572 | }, |
| 573 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 574 | .name = "USB_CH_TH_PROT_F", |
| 575 | .start = AB8500_INT_USB_CH_TH_PROT_F, |
| 576 | .end = AB8500_INT_USB_CH_TH_PROT_F, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 577 | .flags = IORESOURCE_IRQ, |
| 578 | }, |
| 579 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 580 | .name = "MAIN_EXT_CH_NOT_OK", |
| 581 | .start = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 582 | .end = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 583 | .flags = IORESOURCE_IRQ, |
| 584 | }, |
| 585 | { |
| 586 | .name = "MAIN_CH_TH_PROT_R", |
| 587 | .start = AB8500_INT_MAIN_CH_TH_PROT_R, |
| 588 | .end = AB8500_INT_MAIN_CH_TH_PROT_R, |
| 589 | .flags = IORESOURCE_IRQ, |
| 590 | }, |
| 591 | { |
| 592 | .name = "MAIN_CH_TH_PROT_F", |
| 593 | .start = AB8500_INT_MAIN_CH_TH_PROT_F, |
| 594 | .end = AB8500_INT_MAIN_CH_TH_PROT_F, |
| 595 | .flags = IORESOURCE_IRQ, |
| 596 | }, |
| 597 | { |
| 598 | .name = "USB_CHARGER_NOT_OKR", |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 599 | .start = AB8500_INT_USB_CHARGER_NOT_OKR, |
| 600 | .end = AB8500_INT_USB_CHARGER_NOT_OKR, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 601 | .flags = IORESOURCE_IRQ, |
| 602 | }, |
| 603 | { |
| 604 | .name = "CH_WD_EXP", |
| 605 | .start = AB8500_INT_CH_WD_EXP, |
| 606 | .end = AB8500_INT_CH_WD_EXP, |
| 607 | .flags = IORESOURCE_IRQ, |
| 608 | }, |
| 609 | }; |
| 610 | |
| 611 | static struct resource __devinitdata ab8500_btemp_resources[] = { |
| 612 | { |
| 613 | .name = "BAT_CTRL_INDB", |
| 614 | .start = AB8500_INT_BAT_CTRL_INDB, |
| 615 | .end = AB8500_INT_BAT_CTRL_INDB, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 616 | .flags = IORESOURCE_IRQ, |
| 617 | }, |
| 618 | { |
| 619 | .name = "BTEMP_LOW", |
| 620 | .start = AB8500_INT_BTEMP_LOW, |
| 621 | .end = AB8500_INT_BTEMP_LOW, |
| 622 | .flags = IORESOURCE_IRQ, |
| 623 | }, |
| 624 | { |
| 625 | .name = "BTEMP_HIGH", |
| 626 | .start = AB8500_INT_BTEMP_HIGH, |
| 627 | .end = AB8500_INT_BTEMP_HIGH, |
| 628 | .flags = IORESOURCE_IRQ, |
| 629 | }, |
| 630 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 631 | .name = "BTEMP_LOW_MEDIUM", |
| 632 | .start = AB8500_INT_BTEMP_LOW_MEDIUM, |
| 633 | .end = AB8500_INT_BTEMP_LOW_MEDIUM, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 634 | .flags = IORESOURCE_IRQ, |
| 635 | }, |
| 636 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 637 | .name = "BTEMP_MEDIUM_HIGH", |
| 638 | .start = AB8500_INT_BTEMP_MEDIUM_HIGH, |
| 639 | .end = AB8500_INT_BTEMP_MEDIUM_HIGH, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 640 | .flags = IORESOURCE_IRQ, |
| 641 | }, |
| 642 | }; |
| 643 | |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 644 | static struct resource __devinitdata ab8500_fg_resources[] = { |
| 645 | { |
| 646 | .name = "NCONV_ACCU", |
| 647 | .start = AB8500_INT_CCN_CONV_ACC, |
| 648 | .end = AB8500_INT_CCN_CONV_ACC, |
| 649 | .flags = IORESOURCE_IRQ, |
| 650 | }, |
| 651 | { |
| 652 | .name = "BATT_OVV", |
| 653 | .start = AB8500_INT_BATT_OVV, |
| 654 | .end = AB8500_INT_BATT_OVV, |
| 655 | .flags = IORESOURCE_IRQ, |
| 656 | }, |
| 657 | { |
| 658 | .name = "LOW_BAT_F", |
| 659 | .start = AB8500_INT_LOW_BAT_F, |
| 660 | .end = AB8500_INT_LOW_BAT_F, |
| 661 | .flags = IORESOURCE_IRQ, |
| 662 | }, |
| 663 | { |
| 664 | .name = "LOW_BAT_R", |
| 665 | .start = AB8500_INT_LOW_BAT_R, |
| 666 | .end = AB8500_INT_LOW_BAT_R, |
| 667 | .flags = IORESOURCE_IRQ, |
| 668 | }, |
| 669 | { |
| 670 | .name = "CC_INT_CALIB", |
| 671 | .start = AB8500_INT_CC_INT_CALIB, |
| 672 | .end = AB8500_INT_CC_INT_CALIB, |
| 673 | .flags = IORESOURCE_IRQ, |
| 674 | }, |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 675 | { |
| 676 | .name = "CCEOC", |
| 677 | .start = AB8500_INT_CCEOC, |
| 678 | .end = AB8500_INT_CCEOC, |
| 679 | .flags = IORESOURCE_IRQ, |
| 680 | }, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 681 | }; |
| 682 | |
| 683 | static struct resource __devinitdata ab8500_chargalg_resources[] = {}; |
| 684 | |
Axel Lin | df72064 | 2011-11-10 09:56:18 +0800 | [diff] [blame] | 685 | #ifdef CONFIG_DEBUG_FS |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 686 | static struct resource __devinitdata ab8500_debug_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 687 | { |
| 688 | .name = "IRQ_FIRST", |
| 689 | .start = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 690 | .end = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 691 | .flags = IORESOURCE_IRQ, |
| 692 | }, |
| 693 | { |
| 694 | .name = "IRQ_LAST", |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 695 | .start = AB8500_INT_XTAL32K_KO, |
| 696 | .end = AB8500_INT_XTAL32K_KO, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 697 | .flags = IORESOURCE_IRQ, |
| 698 | }, |
| 699 | }; |
Axel Lin | df72064 | 2011-11-10 09:56:18 +0800 | [diff] [blame] | 700 | #endif |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 701 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 702 | static struct resource __devinitdata ab8500_usb_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 703 | { |
| 704 | .name = "ID_WAKEUP_R", |
| 705 | .start = AB8500_INT_ID_WAKEUP_R, |
| 706 | .end = AB8500_INT_ID_WAKEUP_R, |
| 707 | .flags = IORESOURCE_IRQ, |
| 708 | }, |
| 709 | { |
| 710 | .name = "ID_WAKEUP_F", |
| 711 | .start = AB8500_INT_ID_WAKEUP_F, |
| 712 | .end = AB8500_INT_ID_WAKEUP_F, |
| 713 | .flags = IORESOURCE_IRQ, |
| 714 | }, |
| 715 | { |
| 716 | .name = "VBUS_DET_F", |
| 717 | .start = AB8500_INT_VBUS_DET_F, |
| 718 | .end = AB8500_INT_VBUS_DET_F, |
| 719 | .flags = IORESOURCE_IRQ, |
| 720 | }, |
| 721 | { |
| 722 | .name = "VBUS_DET_R", |
| 723 | .start = AB8500_INT_VBUS_DET_R, |
| 724 | .end = AB8500_INT_VBUS_DET_R, |
| 725 | .flags = IORESOURCE_IRQ, |
| 726 | }, |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 727 | { |
| 728 | .name = "USB_LINK_STATUS", |
| 729 | .start = AB8500_INT_USB_LINK_STATUS, |
| 730 | .end = AB8500_INT_USB_LINK_STATUS, |
| 731 | .flags = IORESOURCE_IRQ, |
| 732 | }, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 733 | { |
| 734 | .name = "USB_ADP_PROBE_PLUG", |
| 735 | .start = AB8500_INT_ADP_PROBE_PLUG, |
| 736 | .end = AB8500_INT_ADP_PROBE_PLUG, |
| 737 | .flags = IORESOURCE_IRQ, |
| 738 | }, |
| 739 | { |
| 740 | .name = "USB_ADP_PROBE_UNPLUG", |
| 741 | .start = AB8500_INT_ADP_PROBE_UNPLUG, |
| 742 | .end = AB8500_INT_ADP_PROBE_UNPLUG, |
| 743 | .flags = IORESOURCE_IRQ, |
| 744 | }, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 745 | }; |
| 746 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 747 | static struct resource __devinitdata ab8500_temp_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 748 | { |
| 749 | .name = "AB8500_TEMP_WARM", |
| 750 | .start = AB8500_INT_TEMP_WARM, |
| 751 | .end = AB8500_INT_TEMP_WARM, |
| 752 | .flags = IORESOURCE_IRQ, |
| 753 | }, |
| 754 | }; |
| 755 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 756 | static struct mfd_cell __devinitdata abx500_common_devs[] = { |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 757 | #ifdef CONFIG_DEBUG_FS |
| 758 | { |
| 759 | .name = "ab8500-debug", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 760 | .num_resources = ARRAY_SIZE(ab8500_debug_resources), |
| 761 | .resources = ab8500_debug_resources, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 762 | }, |
| 763 | #endif |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 764 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 765 | .name = "ab8500-sysctrl", |
| 766 | }, |
| 767 | { |
| 768 | .name = "ab8500-regulator", |
| 769 | }, |
| 770 | { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 771 | .name = "ab8500-gpadc", |
| 772 | .num_resources = ARRAY_SIZE(ab8500_gpadc_resources), |
| 773 | .resources = ab8500_gpadc_resources, |
| 774 | }, |
| 775 | { |
| 776 | .name = "ab8500-rtc", |
| 777 | .num_resources = ARRAY_SIZE(ab8500_rtc_resources), |
| 778 | .resources = ab8500_rtc_resources, |
| 779 | }, |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 780 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 781 | .name = "ab8500-charger", |
| 782 | .num_resources = ARRAY_SIZE(ab8500_charger_resources), |
| 783 | .resources = ab8500_charger_resources, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 784 | }, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 785 | { |
| 786 | .name = "ab8500-btemp", |
| 787 | .num_resources = ARRAY_SIZE(ab8500_btemp_resources), |
| 788 | .resources = ab8500_btemp_resources, |
| 789 | }, |
| 790 | { |
| 791 | .name = "ab8500-fg", |
| 792 | .num_resources = ARRAY_SIZE(ab8500_fg_resources), |
| 793 | .resources = ab8500_fg_resources, |
| 794 | }, |
| 795 | { |
| 796 | .name = "ab8500-chargalg", |
| 797 | .num_resources = ARRAY_SIZE(ab8500_chargalg_resources), |
| 798 | .resources = ab8500_chargalg_resources, |
| 799 | }, |
| 800 | { |
| 801 | .name = "ab8500-acc-det", |
| 802 | .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources), |
| 803 | .resources = ab8500_av_acc_detect_resources, |
| 804 | }, |
| 805 | { |
| 806 | .name = "ab8500-codec", |
| 807 | }, |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 808 | |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 809 | { |
| 810 | .name = "ab8500-poweron-key", |
| 811 | .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources), |
| 812 | .resources = ab8500_poweronkey_db_resources, |
| 813 | }, |
| 814 | { |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 815 | .name = "ab8500-pwm", |
| 816 | .id = 1, |
| 817 | }, |
| 818 | { |
| 819 | .name = "ab8500-pwm", |
| 820 | .id = 2, |
| 821 | }, |
| 822 | { |
| 823 | .name = "ab8500-pwm", |
| 824 | .id = 3, |
| 825 | }, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 826 | { .name = "ab8500-leds", }, |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 827 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 828 | .name = "ab8500-denc", |
| 829 | }, |
| 830 | { |
| 831 | .name = "ab8500-temp", |
| 832 | .num_resources = ARRAY_SIZE(ab8500_temp_resources), |
| 833 | .resources = ab8500_temp_resources, |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 834 | }, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 835 | }; |
| 836 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 837 | static struct mfd_cell __devinitdata ab8500_devs[] = { |
| 838 | { |
| 839 | .name = "ab8500-gpio", |
| 840 | .num_resources = ARRAY_SIZE(ab8500_gpio_resources), |
| 841 | .resources = ab8500_gpio_resources, |
| 842 | }, |
| 843 | { |
| 844 | .name = "ab8500-usb", |
| 845 | .num_resources = ARRAY_SIZE(ab8500_usb_resources), |
| 846 | .resources = ab8500_usb_resources, |
| 847 | }, |
| 848 | }; |
| 849 | |
| 850 | static struct mfd_cell __devinitdata ab9540_devs[] = { |
| 851 | { |
| 852 | .name = "ab8500-gpio", |
| 853 | .num_resources = ARRAY_SIZE(ab9540_gpio_resources), |
| 854 | .resources = ab9540_gpio_resources, |
| 855 | }, |
| 856 | { |
| 857 | .name = "ab9540-usb", |
| 858 | .num_resources = ARRAY_SIZE(ab8500_usb_resources), |
| 859 | .resources = ab8500_usb_resources, |
| 860 | }, |
| 861 | }; |
| 862 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 863 | static ssize_t show_chip_id(struct device *dev, |
| 864 | struct device_attribute *attr, char *buf) |
| 865 | { |
| 866 | struct ab8500 *ab8500; |
| 867 | |
| 868 | ab8500 = dev_get_drvdata(dev); |
| 869 | return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL); |
| 870 | } |
| 871 | |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 872 | /* |
| 873 | * ab8500 has switched off due to (SWITCH_OFF_STATUS): |
| 874 | * 0x01 Swoff bit programming |
| 875 | * 0x02 Thermal protection activation |
| 876 | * 0x04 Vbat lower then BattOk falling threshold |
| 877 | * 0x08 Watchdog expired |
| 878 | * 0x10 Non presence of 32kHz clock |
| 879 | * 0x20 Battery level lower than power on reset threshold |
| 880 | * 0x40 Power on key 1 pressed longer than 10 seconds |
| 881 | * 0x80 DB8500 thermal shutdown |
| 882 | */ |
| 883 | static ssize_t show_switch_off_status(struct device *dev, |
| 884 | struct device_attribute *attr, char *buf) |
| 885 | { |
| 886 | int ret; |
| 887 | u8 value; |
| 888 | struct ab8500 *ab8500; |
| 889 | |
| 890 | ab8500 = dev_get_drvdata(dev); |
| 891 | ret = get_register_interruptible(ab8500, AB8500_RTC, |
| 892 | AB8500_SWITCH_OFF_STATUS, &value); |
| 893 | if (ret < 0) |
| 894 | return ret; |
| 895 | return sprintf(buf, "%#x\n", value); |
| 896 | } |
| 897 | |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 898 | /* |
| 899 | * ab8500 has turned on due to (TURN_ON_STATUS): |
| 900 | * 0x01 PORnVbat |
| 901 | * 0x02 PonKey1dbF |
| 902 | * 0x04 PonKey2dbF |
| 903 | * 0x08 RTCAlarm |
| 904 | * 0x10 MainChDet |
| 905 | * 0x20 VbusDet |
| 906 | * 0x40 UsbIDDetect |
| 907 | * 0x80 Reserved |
| 908 | */ |
| 909 | static ssize_t show_turn_on_status(struct device *dev, |
| 910 | struct device_attribute *attr, char *buf) |
| 911 | { |
| 912 | int ret; |
| 913 | u8 value; |
| 914 | struct ab8500 *ab8500; |
| 915 | |
| 916 | ab8500 = dev_get_drvdata(dev); |
| 917 | ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, |
| 918 | AB8500_TURN_ON_STATUS, &value); |
| 919 | if (ret < 0) |
| 920 | return ret; |
| 921 | return sprintf(buf, "%#x\n", value); |
| 922 | } |
| 923 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 924 | static ssize_t show_ab9540_dbbrstn(struct device *dev, |
| 925 | struct device_attribute *attr, char *buf) |
| 926 | { |
| 927 | struct ab8500 *ab8500; |
| 928 | int ret; |
| 929 | u8 value; |
| 930 | |
| 931 | ab8500 = dev_get_drvdata(dev); |
| 932 | |
| 933 | ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2, |
| 934 | AB9540_MODEM_CTRL2_REG, &value); |
| 935 | if (ret < 0) |
| 936 | return ret; |
| 937 | |
| 938 | return sprintf(buf, "%d\n", |
| 939 | (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0); |
| 940 | } |
| 941 | |
| 942 | static ssize_t store_ab9540_dbbrstn(struct device *dev, |
| 943 | struct device_attribute *attr, const char *buf, size_t count) |
| 944 | { |
| 945 | struct ab8500 *ab8500; |
| 946 | int ret = count; |
| 947 | int err; |
| 948 | u8 bitvalues; |
| 949 | |
| 950 | ab8500 = dev_get_drvdata(dev); |
| 951 | |
| 952 | if (count > 0) { |
| 953 | switch (buf[0]) { |
| 954 | case '0': |
| 955 | bitvalues = 0; |
| 956 | break; |
| 957 | case '1': |
| 958 | bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT; |
| 959 | break; |
| 960 | default: |
| 961 | goto exit; |
| 962 | } |
| 963 | |
| 964 | err = mask_and_set_register_interruptible(ab8500, |
| 965 | AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG, |
| 966 | AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues); |
| 967 | if (err) |
| 968 | dev_info(ab8500->dev, |
| 969 | "Failed to set DBBRSTN %c, err %#x\n", |
| 970 | buf[0], err); |
| 971 | } |
| 972 | |
| 973 | exit: |
| 974 | return ret; |
| 975 | } |
| 976 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 977 | static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL); |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 978 | static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL); |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 979 | static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL); |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 980 | static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR, |
| 981 | show_ab9540_dbbrstn, store_ab9540_dbbrstn); |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 982 | |
| 983 | static struct attribute *ab8500_sysfs_entries[] = { |
| 984 | &dev_attr_chip_id.attr, |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 985 | &dev_attr_switch_off_status.attr, |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 986 | &dev_attr_turn_on_status.attr, |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 987 | NULL, |
| 988 | }; |
| 989 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 990 | static struct attribute *ab9540_sysfs_entries[] = { |
| 991 | &dev_attr_chip_id.attr, |
| 992 | &dev_attr_switch_off_status.attr, |
| 993 | &dev_attr_turn_on_status.attr, |
| 994 | &dev_attr_dbbrstn.attr, |
| 995 | NULL, |
| 996 | }; |
| 997 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 998 | static struct attribute_group ab8500_attr_group = { |
| 999 | .attrs = ab8500_sysfs_entries, |
| 1000 | }; |
| 1001 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1002 | static struct attribute_group ab9540_attr_group = { |
| 1003 | .attrs = ab9540_sysfs_entries, |
| 1004 | }; |
| 1005 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1006 | int __devinit ab8500_init(struct ab8500 *ab8500, enum ab8500_version version) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1007 | { |
| 1008 | struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev); |
| 1009 | int ret; |
| 1010 | int i; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1011 | u8 value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1012 | |
| 1013 | if (plat) |
| 1014 | ab8500->irq_base = plat->irq_base; |
| 1015 | |
| 1016 | mutex_init(&ab8500->lock); |
| 1017 | mutex_init(&ab8500->irq_lock); |
| 1018 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1019 | if (version != AB8500_VERSION_UNDEFINED) |
| 1020 | ab8500->version = version; |
| 1021 | else { |
| 1022 | ret = get_register_interruptible(ab8500, AB8500_MISC, |
| 1023 | AB8500_IC_NAME_REG, &value); |
| 1024 | if (ret < 0) |
| 1025 | return ret; |
| 1026 | |
| 1027 | ab8500->version = value; |
| 1028 | } |
| 1029 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1030 | ret = get_register_interruptible(ab8500, AB8500_MISC, |
| 1031 | AB8500_REV_REG, &value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1032 | if (ret < 0) |
| 1033 | return ret; |
| 1034 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1035 | ab8500->chip_id = value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1036 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1037 | dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n", |
| 1038 | ab8500_version_str[ab8500->version], |
| 1039 | ab8500->chip_id >> 4, |
| 1040 | ab8500->chip_id & 0x0F); |
| 1041 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1042 | /* Configure AB8500 or AB9540 IRQ */ |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 1043 | if (is_ab9540(ab8500) || is_ab8505(ab8500)) { |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1044 | ab8500->mask_size = AB9540_NUM_IRQ_REGS; |
| 1045 | ab8500->irq_reg_offset = ab9540_irq_regoffset; |
| 1046 | } else { |
| 1047 | ab8500->mask_size = AB8500_NUM_IRQ_REGS; |
| 1048 | ab8500->irq_reg_offset = ab8500_irq_regoffset; |
| 1049 | } |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1050 | ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL); |
| 1051 | if (!ab8500->mask) |
| 1052 | return -ENOMEM; |
| 1053 | ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL); |
| 1054 | if (!ab8500->oldmask) { |
| 1055 | ret = -ENOMEM; |
| 1056 | goto out_freemask; |
| 1057 | } |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1058 | /* |
| 1059 | * ab8500 has switched off due to (SWITCH_OFF_STATUS): |
| 1060 | * 0x01 Swoff bit programming |
| 1061 | * 0x02 Thermal protection activation |
| 1062 | * 0x04 Vbat lower then BattOk falling threshold |
| 1063 | * 0x08 Watchdog expired |
| 1064 | * 0x10 Non presence of 32kHz clock |
| 1065 | * 0x20 Battery level lower than power on reset threshold |
| 1066 | * 0x40 Power on key 1 pressed longer than 10 seconds |
| 1067 | * 0x80 DB8500 thermal shutdown |
| 1068 | */ |
| 1069 | |
| 1070 | ret = get_register_interruptible(ab8500, AB8500_RTC, |
| 1071 | AB8500_SWITCH_OFF_STATUS, &value); |
| 1072 | if (ret < 0) |
| 1073 | return ret; |
| 1074 | dev_info(ab8500->dev, "switch off status: %#x", value); |
| 1075 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1076 | if (plat && plat->init) |
| 1077 | plat->init(ab8500); |
| 1078 | |
| 1079 | /* Clear and mask all interrupts */ |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1080 | for (i = 0; i < ab8500->mask_size; i++) { |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1081 | /* |
| 1082 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 1083 | * 2.0 |
| 1084 | */ |
| 1085 | if (ab8500->irq_reg_offset[i] == 11 && |
| 1086 | is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 1087 | continue; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1088 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1089 | get_register_interruptible(ab8500, AB8500_INTERRUPT, |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1090 | AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i], |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 1091 | &value); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1092 | set_register_interruptible(ab8500, AB8500_INTERRUPT, |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1093 | AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1094 | } |
| 1095 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1096 | ret = abx500_register_ops(ab8500->dev, &ab8500_ops); |
| 1097 | if (ret) |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1098 | goto out_freeoldmask; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1099 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1100 | for (i = 0; i < ab8500->mask_size; i++) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1101 | ab8500->mask[i] = ab8500->oldmask[i] = 0xff; |
| 1102 | |
| 1103 | if (ab8500->irq_base) { |
| 1104 | ret = ab8500_irq_init(ab8500); |
| 1105 | if (ret) |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1106 | goto out_freeoldmask; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1107 | |
| 1108 | ret = request_threaded_irq(ab8500->irq, NULL, ab8500_irq, |
Mattias Wallin | 4f07998 | 2010-12-02 15:10:27 +0100 | [diff] [blame] | 1109 | IRQF_ONESHOT | IRQF_NO_SUSPEND, |
| 1110 | "ab8500", ab8500); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1111 | if (ret) |
| 1112 | goto out_removeirq; |
| 1113 | } |
| 1114 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1115 | ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs, |
| 1116 | ARRAY_SIZE(abx500_common_devs), NULL, |
| 1117 | ab8500->irq_base); |
| 1118 | |
| 1119 | if (ret) |
| 1120 | goto out_freeirq; |
| 1121 | |
| 1122 | if (is_ab9540(ab8500)) |
| 1123 | ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, |
| 1124 | ARRAY_SIZE(ab9540_devs), NULL, |
| 1125 | ab8500->irq_base); |
| 1126 | else |
| 1127 | ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, |
| 1128 | ARRAY_SIZE(ab9540_devs), NULL, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1129 | ab8500->irq_base); |
| 1130 | if (ret) |
| 1131 | goto out_freeirq; |
| 1132 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1133 | if (is_ab9540(ab8500)) |
| 1134 | ret = sysfs_create_group(&ab8500->dev->kobj, |
| 1135 | &ab9540_attr_group); |
| 1136 | else |
| 1137 | ret = sysfs_create_group(&ab8500->dev->kobj, |
| 1138 | &ab8500_attr_group); |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1139 | if (ret) |
| 1140 | dev_err(ab8500->dev, "error creating sysfs entries\n"); |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1141 | else |
| 1142 | return ret; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1143 | |
| 1144 | out_freeirq: |
Linus Walleij | 6d95b7f | 2012-02-20 21:42:03 +0100 | [diff] [blame] | 1145 | if (ab8500->irq_base) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1146 | free_irq(ab8500->irq, ab8500); |
| 1147 | out_removeirq: |
Linus Walleij | 6d95b7f | 2012-02-20 21:42:03 +0100 | [diff] [blame] | 1148 | if (ab8500->irq_base) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1149 | ab8500_irq_remove(ab8500); |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1150 | out_freeoldmask: |
| 1151 | kfree(ab8500->oldmask); |
| 1152 | out_freemask: |
| 1153 | kfree(ab8500->mask); |
Linus Walleij | 6d95b7f | 2012-02-20 21:42:03 +0100 | [diff] [blame] | 1154 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1155 | return ret; |
| 1156 | } |
| 1157 | |
| 1158 | int __devexit ab8500_exit(struct ab8500 *ab8500) |
| 1159 | { |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1160 | if (is_ab9540(ab8500)) |
| 1161 | sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group); |
| 1162 | else |
| 1163 | sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1164 | mfd_remove_devices(ab8500->dev); |
| 1165 | if (ab8500->irq_base) { |
| 1166 | free_irq(ab8500->irq, ab8500); |
| 1167 | ab8500_irq_remove(ab8500); |
| 1168 | } |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1169 | kfree(ab8500->oldmask); |
| 1170 | kfree(ab8500->mask); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1171 | |
| 1172 | return 0; |
| 1173 | } |
| 1174 | |
Mattias Wallin | adceed6 | 2011-03-02 11:51:11 +0100 | [diff] [blame] | 1175 | MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent"); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1176 | MODULE_DESCRIPTION("AB8500 MFD core"); |
| 1177 | MODULE_LICENSE("GPL v2"); |