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