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> |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 14 | #include <linux/irqdomain.h> |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 15 | #include <linux/delay.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/mfd/core.h> |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 20 | #include <linux/mfd/abx500.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 21 | #include <linux/mfd/abx500/ab8500.h> |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 22 | #include <linux/mfd/dbx500-prcmu.h> |
Sundar R Iyer | 549931f | 2010-07-13 11:51:28 +0530 | [diff] [blame] | 23 | #include <linux/regulator/ab8500.h> |
Lee Jones | 6bc4a56 | 2012-05-17 14:45:13 +0100 | [diff] [blame] | 24 | #include <linux/of.h> |
| 25 | #include <linux/of_device.h> |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Interrupt register offsets |
| 29 | * Bank : 0x0E |
| 30 | */ |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 31 | #define AB8500_IT_SOURCE1_REG 0x00 |
| 32 | #define AB8500_IT_SOURCE2_REG 0x01 |
| 33 | #define AB8500_IT_SOURCE3_REG 0x02 |
| 34 | #define AB8500_IT_SOURCE4_REG 0x03 |
| 35 | #define AB8500_IT_SOURCE5_REG 0x04 |
| 36 | #define AB8500_IT_SOURCE6_REG 0x05 |
| 37 | #define AB8500_IT_SOURCE7_REG 0x06 |
| 38 | #define AB8500_IT_SOURCE8_REG 0x07 |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 39 | #define AB9540_IT_SOURCE13_REG 0x0C |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 40 | #define AB8500_IT_SOURCE19_REG 0x12 |
| 41 | #define AB8500_IT_SOURCE20_REG 0x13 |
| 42 | #define AB8500_IT_SOURCE21_REG 0x14 |
| 43 | #define AB8500_IT_SOURCE22_REG 0x15 |
| 44 | #define AB8500_IT_SOURCE23_REG 0x16 |
| 45 | #define AB8500_IT_SOURCE24_REG 0x17 |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * latch registers |
| 49 | */ |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 50 | #define AB8500_IT_LATCH1_REG 0x20 |
| 51 | #define AB8500_IT_LATCH2_REG 0x21 |
| 52 | #define AB8500_IT_LATCH3_REG 0x22 |
| 53 | #define AB8500_IT_LATCH4_REG 0x23 |
| 54 | #define AB8500_IT_LATCH5_REG 0x24 |
| 55 | #define AB8500_IT_LATCH6_REG 0x25 |
| 56 | #define AB8500_IT_LATCH7_REG 0x26 |
| 57 | #define AB8500_IT_LATCH8_REG 0x27 |
| 58 | #define AB8500_IT_LATCH9_REG 0x28 |
| 59 | #define AB8500_IT_LATCH10_REG 0x29 |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 60 | #define AB8500_IT_LATCH12_REG 0x2B |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 61 | #define AB9540_IT_LATCH13_REG 0x2C |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 62 | #define AB8500_IT_LATCH19_REG 0x32 |
| 63 | #define AB8500_IT_LATCH20_REG 0x33 |
| 64 | #define AB8500_IT_LATCH21_REG 0x34 |
| 65 | #define AB8500_IT_LATCH22_REG 0x35 |
| 66 | #define AB8500_IT_LATCH23_REG 0x36 |
| 67 | #define AB8500_IT_LATCH24_REG 0x37 |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * mask registers |
| 71 | */ |
| 72 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 73 | #define AB8500_IT_MASK1_REG 0x40 |
| 74 | #define AB8500_IT_MASK2_REG 0x41 |
| 75 | #define AB8500_IT_MASK3_REG 0x42 |
| 76 | #define AB8500_IT_MASK4_REG 0x43 |
| 77 | #define AB8500_IT_MASK5_REG 0x44 |
| 78 | #define AB8500_IT_MASK6_REG 0x45 |
| 79 | #define AB8500_IT_MASK7_REG 0x46 |
| 80 | #define AB8500_IT_MASK8_REG 0x47 |
| 81 | #define AB8500_IT_MASK9_REG 0x48 |
| 82 | #define AB8500_IT_MASK10_REG 0x49 |
| 83 | #define AB8500_IT_MASK11_REG 0x4A |
| 84 | #define AB8500_IT_MASK12_REG 0x4B |
| 85 | #define AB8500_IT_MASK13_REG 0x4C |
| 86 | #define AB8500_IT_MASK14_REG 0x4D |
| 87 | #define AB8500_IT_MASK15_REG 0x4E |
| 88 | #define AB8500_IT_MASK16_REG 0x4F |
| 89 | #define AB8500_IT_MASK17_REG 0x50 |
| 90 | #define AB8500_IT_MASK18_REG 0x51 |
| 91 | #define AB8500_IT_MASK19_REG 0x52 |
| 92 | #define AB8500_IT_MASK20_REG 0x53 |
| 93 | #define AB8500_IT_MASK21_REG 0x54 |
| 94 | #define AB8500_IT_MASK22_REG 0x55 |
| 95 | #define AB8500_IT_MASK23_REG 0x56 |
| 96 | #define AB8500_IT_MASK24_REG 0x57 |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 97 | |
Michel JAOUEN | 7ccfe9b | 2012-05-07 15:02:03 +0200 | [diff] [blame] | 98 | /* |
| 99 | * latch hierarchy registers |
| 100 | */ |
| 101 | #define AB8500_IT_LATCHHIER1_REG 0x60 |
| 102 | #define AB8500_IT_LATCHHIER2_REG 0x61 |
| 103 | #define AB8500_IT_LATCHHIER3_REG 0x62 |
| 104 | |
| 105 | #define AB8500_IT_LATCHHIER_NUM 3 |
| 106 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 107 | #define AB8500_REV_REG 0x80 |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 108 | #define AB8500_IC_NAME_REG 0x82 |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 109 | #define AB8500_SWITCH_OFF_STATUS 0x00 |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 110 | |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 111 | #define AB8500_TURN_ON_STATUS 0x00 |
| 112 | |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 113 | static bool no_bm; /* No battery management */ |
| 114 | module_param(no_bm, bool, S_IRUGO); |
| 115 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 116 | #define AB9540_MODEM_CTRL2_REG 0x23 |
| 117 | #define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT BIT(2) |
| 118 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 119 | /* |
| 120 | * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 121 | * numbers are indexed into this array with (num / 8). The interupts are |
| 122 | * defined in linux/mfd/ab8500.h |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 123 | * |
| 124 | * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at |
| 125 | * offset 0. |
| 126 | */ |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 127 | /* AB8500 support */ |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 128 | static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = { |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 129 | 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] | 130 | }; |
| 131 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 132 | /* AB9540 support */ |
| 133 | static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = { |
| 134 | 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24, |
| 135 | }; |
| 136 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 137 | static const char ab8500_version_str[][7] = { |
| 138 | [AB8500_VERSION_AB8500] = "AB8500", |
| 139 | [AB8500_VERSION_AB8505] = "AB8505", |
| 140 | [AB8500_VERSION_AB9540] = "AB9540", |
| 141 | [AB8500_VERSION_AB8540] = "AB8540", |
| 142 | }; |
| 143 | |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 144 | static int ab8500_prcmu_write(struct ab8500 *ab8500, u16 addr, u8 data) |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 145 | { |
| 146 | int ret; |
| 147 | |
| 148 | ret = prcmu_abb_write((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1); |
| 149 | if (ret < 0) |
| 150 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); |
| 151 | return ret; |
| 152 | } |
| 153 | |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 154 | static int ab8500_prcmu_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask, |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 155 | u8 data) |
| 156 | { |
| 157 | int ret; |
| 158 | |
| 159 | ret = prcmu_abb_write_masked((u8)(addr >> 8), (u8)(addr & 0xFF), &data, |
| 160 | &mask, 1); |
| 161 | if (ret < 0) |
| 162 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); |
| 163 | return ret; |
| 164 | } |
| 165 | |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 166 | static int ab8500_prcmu_read(struct ab8500 *ab8500, u16 addr) |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 167 | { |
| 168 | int ret; |
| 169 | u8 data; |
| 170 | |
| 171 | ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1); |
| 172 | if (ret < 0) { |
| 173 | dev_err(ab8500->dev, "prcmu i2c error %d\n", ret); |
| 174 | return ret; |
| 175 | } |
| 176 | return (int)data; |
| 177 | } |
| 178 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 179 | static int ab8500_get_chip_id(struct device *dev) |
| 180 | { |
Mattias Wallin | 6bce7bf | 2010-12-02 15:08:32 +0100 | [diff] [blame] | 181 | struct ab8500 *ab8500; |
| 182 | |
| 183 | if (!dev) |
| 184 | return -EINVAL; |
| 185 | ab8500 = dev_get_drvdata(dev->parent); |
| 186 | return ab8500 ? (int)ab8500->chip_id : -EINVAL; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static int set_register_interruptible(struct ab8500 *ab8500, u8 bank, |
| 190 | u8 reg, u8 data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 191 | { |
| 192 | int ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 193 | /* |
| 194 | * Put the u8 bank and u8 register together into a an u16. |
| 195 | * The bank on higher 8 bits and register in lower 8 bits. |
| 196 | * */ |
| 197 | u16 addr = ((u16)bank) << 8 | reg; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 198 | |
| 199 | dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data); |
| 200 | |
Rabin Vincent | 392cbd1 | 2012-03-08 14:01:46 +0100 | [diff] [blame] | 201 | mutex_lock(&ab8500->lock); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 202 | |
| 203 | ret = ab8500->write(ab8500, addr, data); |
| 204 | if (ret < 0) |
| 205 | dev_err(ab8500->dev, "failed to write reg %#x: %d\n", |
| 206 | addr, ret); |
| 207 | mutex_unlock(&ab8500->lock); |
| 208 | |
| 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | static int ab8500_set_register(struct device *dev, u8 bank, |
| 213 | u8 reg, u8 value) |
| 214 | { |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 215 | int ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 216 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); |
| 217 | |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 218 | atomic_inc(&ab8500->transfer_ongoing); |
| 219 | ret = set_register_interruptible(ab8500, bank, reg, value); |
| 220 | atomic_dec(&ab8500->transfer_ongoing); |
| 221 | return ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static int get_register_interruptible(struct ab8500 *ab8500, u8 bank, |
| 225 | u8 reg, u8 *value) |
| 226 | { |
| 227 | int ret; |
| 228 | /* put the u8 bank and u8 reg together into a an u16. |
| 229 | * bank on higher 8 bits and reg in lower */ |
| 230 | u16 addr = ((u16)bank) << 8 | reg; |
| 231 | |
Rabin Vincent | 392cbd1 | 2012-03-08 14:01:46 +0100 | [diff] [blame] | 232 | mutex_lock(&ab8500->lock); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 233 | |
| 234 | ret = ab8500->read(ab8500, addr); |
| 235 | if (ret < 0) |
| 236 | dev_err(ab8500->dev, "failed to read reg %#x: %d\n", |
| 237 | addr, ret); |
| 238 | else |
| 239 | *value = ret; |
| 240 | |
| 241 | mutex_unlock(&ab8500->lock); |
| 242 | dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret); |
| 243 | |
| 244 | return ret; |
| 245 | } |
| 246 | |
| 247 | static int ab8500_get_register(struct device *dev, u8 bank, |
| 248 | u8 reg, u8 *value) |
| 249 | { |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 250 | int ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 251 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); |
| 252 | |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 253 | atomic_inc(&ab8500->transfer_ongoing); |
| 254 | ret = get_register_interruptible(ab8500, bank, reg, value); |
| 255 | atomic_dec(&ab8500->transfer_ongoing); |
| 256 | return ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank, |
| 260 | u8 reg, u8 bitmask, u8 bitvalues) |
| 261 | { |
| 262 | int ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 263 | /* put the u8 bank and u8 reg together into a an u16. |
| 264 | * bank on higher 8 bits and reg in lower */ |
| 265 | u16 addr = ((u16)bank) << 8 | reg; |
| 266 | |
Rabin Vincent | 392cbd1 | 2012-03-08 14:01:46 +0100 | [diff] [blame] | 267 | mutex_lock(&ab8500->lock); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 268 | |
Mattias Nilsson | bc628fd | 2012-03-08 14:02:20 +0100 | [diff] [blame] | 269 | if (ab8500->write_masked == NULL) { |
| 270 | u8 data; |
| 271 | |
| 272 | ret = ab8500->read(ab8500, addr); |
| 273 | if (ret < 0) { |
| 274 | dev_err(ab8500->dev, "failed to read reg %#x: %d\n", |
| 275 | addr, ret); |
| 276 | goto out; |
| 277 | } |
| 278 | |
| 279 | data = (u8)ret; |
| 280 | data = (~bitmask & data) | (bitmask & bitvalues); |
| 281 | |
| 282 | ret = ab8500->write(ab8500, addr, data); |
| 283 | if (ret < 0) |
| 284 | dev_err(ab8500->dev, "failed to write reg %#x: %d\n", |
| 285 | addr, ret); |
| 286 | |
| 287 | dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, |
| 288 | data); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 289 | goto out; |
| 290 | } |
Mattias Nilsson | bc628fd | 2012-03-08 14:02:20 +0100 | [diff] [blame] | 291 | ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 292 | if (ret < 0) |
Mattias Nilsson | bc628fd | 2012-03-08 14:02:20 +0100 | [diff] [blame] | 293 | dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr, |
| 294 | ret); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 295 | out: |
| 296 | mutex_unlock(&ab8500->lock); |
| 297 | return ret; |
| 298 | } |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 299 | |
| 300 | static int ab8500_mask_and_set_register(struct device *dev, |
| 301 | u8 bank, u8 reg, u8 bitmask, u8 bitvalues) |
| 302 | { |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 303 | int ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 304 | struct ab8500 *ab8500 = dev_get_drvdata(dev->parent); |
| 305 | |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 306 | atomic_inc(&ab8500->transfer_ongoing); |
| 307 | ret= mask_and_set_register_interruptible(ab8500, bank, reg, |
| 308 | bitmask, bitvalues); |
| 309 | atomic_dec(&ab8500->transfer_ongoing); |
| 310 | return ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static struct abx500_ops ab8500_ops = { |
| 314 | .get_chip_id = ab8500_get_chip_id, |
| 315 | .get_register = ab8500_get_register, |
| 316 | .set_register = ab8500_set_register, |
| 317 | .get_register_page = NULL, |
| 318 | .set_register_page = NULL, |
| 319 | .mask_and_set_register = ab8500_mask_and_set_register, |
| 320 | .event_registers_startup_state_get = NULL, |
| 321 | .startup_irq_enabled = NULL, |
| 322 | }; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 323 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 324 | static void ab8500_irq_lock(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 325 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 326 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 327 | |
| 328 | mutex_lock(&ab8500->irq_lock); |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 329 | atomic_inc(&ab8500->transfer_ongoing); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 330 | } |
| 331 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 332 | static void ab8500_irq_sync_unlock(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 333 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 334 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 335 | int i; |
| 336 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 337 | for (i = 0; i < ab8500->mask_size; i++) { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 338 | u8 old = ab8500->oldmask[i]; |
| 339 | u8 new = ab8500->mask[i]; |
| 340 | int reg; |
| 341 | |
| 342 | if (new == old) |
| 343 | continue; |
| 344 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 345 | /* |
| 346 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 347 | * 2.0 |
| 348 | */ |
| 349 | if (ab8500->irq_reg_offset[i] == 11 && |
| 350 | is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 351 | continue; |
| 352 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 353 | ab8500->oldmask[i] = new; |
| 354 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 355 | reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i]; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 356 | set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 357 | } |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 358 | atomic_dec(&ab8500->transfer_ongoing); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 359 | mutex_unlock(&ab8500->irq_lock); |
| 360 | } |
| 361 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 362 | static void ab8500_irq_mask(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 363 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 364 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 365 | int offset = data->hwirq; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 366 | int index = offset / 8; |
| 367 | int mask = 1 << (offset % 8); |
| 368 | |
| 369 | ab8500->mask[index] |= mask; |
| 370 | } |
| 371 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 372 | static void ab8500_irq_unmask(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 373 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 374 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 375 | int offset = data->hwirq; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 376 | int index = offset / 8; |
| 377 | int mask = 1 << (offset % 8); |
| 378 | |
| 379 | ab8500->mask[index] &= ~mask; |
| 380 | } |
| 381 | |
| 382 | static struct irq_chip ab8500_irq_chip = { |
| 383 | .name = "ab8500", |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 384 | .irq_bus_lock = ab8500_irq_lock, |
| 385 | .irq_bus_sync_unlock = ab8500_irq_sync_unlock, |
| 386 | .irq_mask = ab8500_irq_mask, |
Virupax Sadashivpetimath | e6f9306 | 2011-10-11 10:49:17 +0200 | [diff] [blame] | 387 | .irq_disable = ab8500_irq_mask, |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 388 | .irq_unmask = ab8500_irq_unmask, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 389 | }; |
| 390 | |
Michel JAOUEN | 7ccfe9b | 2012-05-07 15:02:03 +0200 | [diff] [blame] | 391 | static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500, |
| 392 | int latch_offset, u8 latch_val) |
| 393 | { |
| 394 | int int_bit = __ffs(latch_val); |
| 395 | int line, i; |
| 396 | |
| 397 | do { |
| 398 | int_bit = __ffs(latch_val); |
| 399 | |
| 400 | for (i = 0; i < ab8500->mask_size; i++) |
| 401 | if (ab8500->irq_reg_offset[i] == latch_offset) |
| 402 | break; |
| 403 | |
| 404 | if (i >= ab8500->mask_size) { |
| 405 | dev_err(ab8500->dev, "Register offset 0x%2x not declared\n", |
| 406 | latch_offset); |
| 407 | return -ENXIO; |
| 408 | } |
| 409 | |
| 410 | line = (i << 3) + int_bit; |
| 411 | latch_val &= ~(1 << int_bit); |
| 412 | |
| 413 | handle_nested_irq(ab8500->irq_base + line); |
| 414 | } while (latch_val); |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500, |
| 420 | int hier_offset, u8 hier_val) |
| 421 | { |
| 422 | int latch_bit, status; |
| 423 | u8 latch_offset, latch_val; |
| 424 | |
| 425 | do { |
| 426 | latch_bit = __ffs(hier_val); |
| 427 | latch_offset = (hier_offset << 3) + latch_bit; |
| 428 | |
| 429 | /* Fix inconsistent ITFromLatch25 bit mapping... */ |
| 430 | if (unlikely(latch_offset == 17)) |
| 431 | latch_offset = 24; |
| 432 | |
| 433 | status = get_register_interruptible(ab8500, |
| 434 | AB8500_INTERRUPT, |
| 435 | AB8500_IT_LATCH1_REG + latch_offset, |
| 436 | &latch_val); |
| 437 | if (status < 0 || latch_val == 0) |
| 438 | goto discard; |
| 439 | |
| 440 | status = ab8500_handle_hierarchical_line(ab8500, |
| 441 | latch_offset, latch_val); |
| 442 | if (status < 0) |
| 443 | return status; |
| 444 | discard: |
| 445 | hier_val &= ~(1 << latch_bit); |
| 446 | } while (hier_val); |
| 447 | |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev) |
| 452 | { |
| 453 | struct ab8500 *ab8500 = dev; |
| 454 | u8 i; |
| 455 | |
| 456 | dev_vdbg(ab8500->dev, "interrupt\n"); |
| 457 | |
| 458 | /* Hierarchical interrupt version */ |
| 459 | for (i = 0; i < AB8500_IT_LATCHHIER_NUM; i++) { |
| 460 | int status; |
| 461 | u8 hier_val; |
| 462 | |
| 463 | status = get_register_interruptible(ab8500, AB8500_INTERRUPT, |
| 464 | AB8500_IT_LATCHHIER1_REG + i, &hier_val); |
| 465 | if (status < 0 || hier_val == 0) |
| 466 | continue; |
| 467 | |
| 468 | status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val); |
| 469 | if (status < 0) |
| 470 | break; |
| 471 | } |
| 472 | return IRQ_HANDLED; |
| 473 | } |
| 474 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 475 | static irqreturn_t ab8500_irq(int irq, void *dev) |
| 476 | { |
| 477 | struct ab8500 *ab8500 = dev; |
| 478 | int i; |
| 479 | |
| 480 | dev_vdbg(ab8500->dev, "interrupt\n"); |
| 481 | |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 482 | atomic_inc(&ab8500->transfer_ongoing); |
| 483 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 484 | for (i = 0; i < ab8500->mask_size; i++) { |
| 485 | int regoffset = ab8500->irq_reg_offset[i]; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 486 | int status; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 487 | u8 value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 488 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 489 | /* |
| 490 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 491 | * 2.0 |
| 492 | */ |
| 493 | if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 494 | continue; |
| 495 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 496 | status = get_register_interruptible(ab8500, AB8500_INTERRUPT, |
| 497 | AB8500_IT_LATCH1_REG + regoffset, &value); |
| 498 | if (status < 0 || value == 0) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 499 | continue; |
| 500 | |
| 501 | do { |
Mattias Wallin | 88aec4f | 2010-12-02 15:06:49 +0100 | [diff] [blame] | 502 | int bit = __ffs(value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 503 | int line = i * 8 + bit; |
| 504 | |
| 505 | handle_nested_irq(ab8500->irq_base + line); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 506 | value &= ~(1 << bit); |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 507 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 508 | } while (value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 509 | } |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 510 | atomic_dec(&ab8500->transfer_ongoing); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 511 | return IRQ_HANDLED; |
| 512 | } |
| 513 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 514 | /** |
| 515 | * ab8500_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ |
| 516 | * |
| 517 | * @ab8500: ab8500_irq controller to operate on. |
| 518 | * @irq: index of the interrupt requested in the chip IRQs |
| 519 | * |
| 520 | * Useful for drivers to request their own IRQs. |
| 521 | */ |
| 522 | int ab8500_irq_get_virq(struct ab8500 *ab8500, int irq) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 523 | { |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 524 | if (!ab8500) |
| 525 | return -EINVAL; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 526 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 527 | return irq_create_mapping(ab8500->domain, irq); |
| 528 | } |
| 529 | EXPORT_SYMBOL_GPL(ab8500_irq_get_virq); |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 530 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 531 | static int ab8500_irq_map(struct irq_domain *d, unsigned int virq, |
| 532 | irq_hw_number_t hwirq) |
| 533 | { |
| 534 | struct ab8500 *ab8500 = d->host_data; |
| 535 | |
| 536 | if (!ab8500) |
| 537 | return -EINVAL; |
| 538 | |
| 539 | irq_set_chip_data(virq, ab8500); |
| 540 | irq_set_chip_and_handler(virq, &ab8500_irq_chip, |
| 541 | handle_simple_irq); |
| 542 | irq_set_nested_thread(virq, 1); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 543 | #ifdef CONFIG_ARM |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 544 | set_irq_flags(virq, IRQF_VALID); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 545 | #else |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 546 | irq_set_noprobe(virq); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 547 | #endif |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 552 | static struct irq_domain_ops ab8500_irq_ops = { |
| 553 | .map = ab8500_irq_map, |
| 554 | .xlate = irq_domain_xlate_twocell, |
| 555 | }; |
| 556 | |
| 557 | static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 558 | { |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 559 | int num_irqs; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 560 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 561 | if (is_ab9540(ab8500)) |
| 562 | num_irqs = AB9540_NR_IRQS; |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 563 | else if (is_ab8505(ab8500)) |
| 564 | num_irqs = AB8505_NR_IRQS; |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 565 | else |
| 566 | num_irqs = AB8500_NR_IRQS; |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 567 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 568 | if (ab8500->irq_base) { |
| 569 | ab8500->domain = irq_domain_add_legacy( |
| 570 | NULL, num_irqs, ab8500->irq_base, |
| 571 | 0, &ab8500_irq_ops, ab8500); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 572 | } |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 573 | else { |
| 574 | ab8500->domain = irq_domain_add_linear( |
| 575 | np, num_irqs, &ab8500_irq_ops, ab8500); |
| 576 | } |
| 577 | |
| 578 | if (!ab8500->domain) { |
| 579 | dev_err(ab8500->dev, "Failed to create irqdomain\n"); |
| 580 | return -ENOSYS; |
| 581 | } |
| 582 | |
| 583 | return 0; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 584 | } |
| 585 | |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 586 | int ab8500_suspend(struct ab8500 *ab8500) |
| 587 | { |
| 588 | if (atomic_read(&ab8500->transfer_ongoing)) |
| 589 | return -EINVAL; |
| 590 | else |
| 591 | return 0; |
| 592 | } |
| 593 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 594 | /* AB8500 GPIO Resources */ |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 595 | static struct resource __devinitdata ab8500_gpio_resources[] = { |
Bibek Basu | 0cb3fcd | 2011-02-09 11:02:35 +0530 | [diff] [blame] | 596 | { |
| 597 | .name = "GPIO_INT6", |
| 598 | .start = AB8500_INT_GPIO6R, |
| 599 | .end = AB8500_INT_GPIO41F, |
| 600 | .flags = IORESOURCE_IRQ, |
| 601 | } |
| 602 | }; |
| 603 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 604 | /* AB9540 GPIO Resources */ |
| 605 | static struct resource __devinitdata ab9540_gpio_resources[] = { |
| 606 | { |
| 607 | .name = "GPIO_INT6", |
| 608 | .start = AB8500_INT_GPIO6R, |
| 609 | .end = AB8500_INT_GPIO41F, |
| 610 | .flags = IORESOURCE_IRQ, |
| 611 | }, |
| 612 | { |
| 613 | .name = "GPIO_INT14", |
| 614 | .start = AB9540_INT_GPIO50R, |
| 615 | .end = AB9540_INT_GPIO54R, |
| 616 | .flags = IORESOURCE_IRQ, |
| 617 | }, |
| 618 | { |
| 619 | .name = "GPIO_INT15", |
| 620 | .start = AB9540_INT_GPIO50F, |
| 621 | .end = AB9540_INT_GPIO54F, |
| 622 | .flags = IORESOURCE_IRQ, |
| 623 | } |
| 624 | }; |
| 625 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 626 | static struct resource __devinitdata ab8500_gpadc_resources[] = { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 627 | { |
| 628 | .name = "HW_CONV_END", |
| 629 | .start = AB8500_INT_GP_HW_ADC_CONV_END, |
| 630 | .end = AB8500_INT_GP_HW_ADC_CONV_END, |
| 631 | .flags = IORESOURCE_IRQ, |
| 632 | }, |
| 633 | { |
| 634 | .name = "SW_CONV_END", |
| 635 | .start = AB8500_INT_GP_SW_ADC_CONV_END, |
| 636 | .end = AB8500_INT_GP_SW_ADC_CONV_END, |
| 637 | .flags = IORESOURCE_IRQ, |
| 638 | }, |
| 639 | }; |
| 640 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 641 | static struct resource __devinitdata ab8500_rtc_resources[] = { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 642 | { |
| 643 | .name = "60S", |
| 644 | .start = AB8500_INT_RTC_60S, |
| 645 | .end = AB8500_INT_RTC_60S, |
| 646 | .flags = IORESOURCE_IRQ, |
| 647 | }, |
| 648 | { |
| 649 | .name = "ALARM", |
| 650 | .start = AB8500_INT_RTC_ALARM, |
| 651 | .end = AB8500_INT_RTC_ALARM, |
| 652 | .flags = IORESOURCE_IRQ, |
| 653 | }, |
| 654 | }; |
| 655 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 656 | static struct resource __devinitdata ab8500_poweronkey_db_resources[] = { |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 657 | { |
| 658 | .name = "ONKEY_DBF", |
| 659 | .start = AB8500_INT_PON_KEY1DB_F, |
| 660 | .end = AB8500_INT_PON_KEY1DB_F, |
| 661 | .flags = IORESOURCE_IRQ, |
| 662 | }, |
| 663 | { |
| 664 | .name = "ONKEY_DBR", |
| 665 | .start = AB8500_INT_PON_KEY1DB_R, |
| 666 | .end = AB8500_INT_PON_KEY1DB_R, |
| 667 | .flags = IORESOURCE_IRQ, |
| 668 | }, |
| 669 | }; |
| 670 | |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 671 | static struct resource __devinitdata ab8500_av_acc_detect_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 672 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 673 | .name = "ACC_DETECT_1DB_F", |
| 674 | .start = AB8500_INT_ACC_DETECT_1DB_F, |
| 675 | .end = AB8500_INT_ACC_DETECT_1DB_F, |
| 676 | .flags = IORESOURCE_IRQ, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 677 | }, |
| 678 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 679 | .name = "ACC_DETECT_1DB_R", |
| 680 | .start = AB8500_INT_ACC_DETECT_1DB_R, |
| 681 | .end = AB8500_INT_ACC_DETECT_1DB_R, |
| 682 | .flags = IORESOURCE_IRQ, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 683 | }, |
| 684 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 685 | .name = "ACC_DETECT_21DB_F", |
| 686 | .start = AB8500_INT_ACC_DETECT_21DB_F, |
| 687 | .end = AB8500_INT_ACC_DETECT_21DB_F, |
| 688 | .flags = IORESOURCE_IRQ, |
| 689 | }, |
| 690 | { |
| 691 | .name = "ACC_DETECT_21DB_R", |
| 692 | .start = AB8500_INT_ACC_DETECT_21DB_R, |
| 693 | .end = AB8500_INT_ACC_DETECT_21DB_R, |
| 694 | .flags = IORESOURCE_IRQ, |
| 695 | }, |
| 696 | { |
| 697 | .name = "ACC_DETECT_22DB_F", |
| 698 | .start = AB8500_INT_ACC_DETECT_22DB_F, |
| 699 | .end = AB8500_INT_ACC_DETECT_22DB_F, |
| 700 | .flags = IORESOURCE_IRQ, |
| 701 | }, |
| 702 | { |
| 703 | .name = "ACC_DETECT_22DB_R", |
| 704 | .start = AB8500_INT_ACC_DETECT_22DB_R, |
| 705 | .end = AB8500_INT_ACC_DETECT_22DB_R, |
| 706 | .flags = IORESOURCE_IRQ, |
| 707 | }, |
| 708 | }; |
| 709 | |
| 710 | static struct resource __devinitdata ab8500_charger_resources[] = { |
| 711 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 712 | .name = "MAIN_CH_UNPLUG_DET", |
| 713 | .start = AB8500_INT_MAIN_CH_UNPLUG_DET, |
| 714 | .end = AB8500_INT_MAIN_CH_UNPLUG_DET, |
| 715 | .flags = IORESOURCE_IRQ, |
| 716 | }, |
| 717 | { |
| 718 | .name = "MAIN_CHARGE_PLUG_DET", |
| 719 | .start = AB8500_INT_MAIN_CH_PLUG_DET, |
| 720 | .end = AB8500_INT_MAIN_CH_PLUG_DET, |
| 721 | .flags = IORESOURCE_IRQ, |
| 722 | }, |
| 723 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 724 | .name = "VBUS_DET_R", |
| 725 | .start = AB8500_INT_VBUS_DET_R, |
| 726 | .end = AB8500_INT_VBUS_DET_R, |
| 727 | .flags = IORESOURCE_IRQ, |
| 728 | }, |
| 729 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 730 | .name = "VBUS_DET_F", |
| 731 | .start = AB8500_INT_VBUS_DET_F, |
| 732 | .end = AB8500_INT_VBUS_DET_F, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 733 | .flags = IORESOURCE_IRQ, |
| 734 | }, |
| 735 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 736 | .name = "USB_LINK_STATUS", |
| 737 | .start = AB8500_INT_USB_LINK_STATUS, |
| 738 | .end = AB8500_INT_USB_LINK_STATUS, |
| 739 | .flags = IORESOURCE_IRQ, |
| 740 | }, |
| 741 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 742 | .name = "VBUS_OVV", |
| 743 | .start = AB8500_INT_VBUS_OVV, |
| 744 | .end = AB8500_INT_VBUS_OVV, |
| 745 | .flags = IORESOURCE_IRQ, |
| 746 | }, |
| 747 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 748 | .name = "USB_CH_TH_PROT_R", |
| 749 | .start = AB8500_INT_USB_CH_TH_PROT_R, |
| 750 | .end = AB8500_INT_USB_CH_TH_PROT_R, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 751 | .flags = IORESOURCE_IRQ, |
| 752 | }, |
| 753 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 754 | .name = "USB_CH_TH_PROT_F", |
| 755 | .start = AB8500_INT_USB_CH_TH_PROT_F, |
| 756 | .end = AB8500_INT_USB_CH_TH_PROT_F, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 757 | .flags = IORESOURCE_IRQ, |
| 758 | }, |
| 759 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 760 | .name = "MAIN_EXT_CH_NOT_OK", |
| 761 | .start = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 762 | .end = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 763 | .flags = IORESOURCE_IRQ, |
| 764 | }, |
| 765 | { |
| 766 | .name = "MAIN_CH_TH_PROT_R", |
| 767 | .start = AB8500_INT_MAIN_CH_TH_PROT_R, |
| 768 | .end = AB8500_INT_MAIN_CH_TH_PROT_R, |
| 769 | .flags = IORESOURCE_IRQ, |
| 770 | }, |
| 771 | { |
| 772 | .name = "MAIN_CH_TH_PROT_F", |
| 773 | .start = AB8500_INT_MAIN_CH_TH_PROT_F, |
| 774 | .end = AB8500_INT_MAIN_CH_TH_PROT_F, |
| 775 | .flags = IORESOURCE_IRQ, |
| 776 | }, |
| 777 | { |
| 778 | .name = "USB_CHARGER_NOT_OKR", |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 779 | .start = AB8500_INT_USB_CHARGER_NOT_OKR, |
| 780 | .end = AB8500_INT_USB_CHARGER_NOT_OKR, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 781 | .flags = IORESOURCE_IRQ, |
| 782 | }, |
| 783 | { |
| 784 | .name = "CH_WD_EXP", |
| 785 | .start = AB8500_INT_CH_WD_EXP, |
| 786 | .end = AB8500_INT_CH_WD_EXP, |
| 787 | .flags = IORESOURCE_IRQ, |
| 788 | }, |
| 789 | }; |
| 790 | |
| 791 | static struct resource __devinitdata ab8500_btemp_resources[] = { |
| 792 | { |
| 793 | .name = "BAT_CTRL_INDB", |
| 794 | .start = AB8500_INT_BAT_CTRL_INDB, |
| 795 | .end = AB8500_INT_BAT_CTRL_INDB, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 796 | .flags = IORESOURCE_IRQ, |
| 797 | }, |
| 798 | { |
| 799 | .name = "BTEMP_LOW", |
| 800 | .start = AB8500_INT_BTEMP_LOW, |
| 801 | .end = AB8500_INT_BTEMP_LOW, |
| 802 | .flags = IORESOURCE_IRQ, |
| 803 | }, |
| 804 | { |
| 805 | .name = "BTEMP_HIGH", |
| 806 | .start = AB8500_INT_BTEMP_HIGH, |
| 807 | .end = AB8500_INT_BTEMP_HIGH, |
| 808 | .flags = IORESOURCE_IRQ, |
| 809 | }, |
| 810 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 811 | .name = "BTEMP_LOW_MEDIUM", |
| 812 | .start = AB8500_INT_BTEMP_LOW_MEDIUM, |
| 813 | .end = AB8500_INT_BTEMP_LOW_MEDIUM, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 814 | .flags = IORESOURCE_IRQ, |
| 815 | }, |
| 816 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 817 | .name = "BTEMP_MEDIUM_HIGH", |
| 818 | .start = AB8500_INT_BTEMP_MEDIUM_HIGH, |
| 819 | .end = AB8500_INT_BTEMP_MEDIUM_HIGH, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 820 | .flags = IORESOURCE_IRQ, |
| 821 | }, |
| 822 | }; |
| 823 | |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 824 | static struct resource __devinitdata ab8500_fg_resources[] = { |
| 825 | { |
| 826 | .name = "NCONV_ACCU", |
| 827 | .start = AB8500_INT_CCN_CONV_ACC, |
| 828 | .end = AB8500_INT_CCN_CONV_ACC, |
| 829 | .flags = IORESOURCE_IRQ, |
| 830 | }, |
| 831 | { |
| 832 | .name = "BATT_OVV", |
| 833 | .start = AB8500_INT_BATT_OVV, |
| 834 | .end = AB8500_INT_BATT_OVV, |
| 835 | .flags = IORESOURCE_IRQ, |
| 836 | }, |
| 837 | { |
| 838 | .name = "LOW_BAT_F", |
| 839 | .start = AB8500_INT_LOW_BAT_F, |
| 840 | .end = AB8500_INT_LOW_BAT_F, |
| 841 | .flags = IORESOURCE_IRQ, |
| 842 | }, |
| 843 | { |
| 844 | .name = "LOW_BAT_R", |
| 845 | .start = AB8500_INT_LOW_BAT_R, |
| 846 | .end = AB8500_INT_LOW_BAT_R, |
| 847 | .flags = IORESOURCE_IRQ, |
| 848 | }, |
| 849 | { |
| 850 | .name = "CC_INT_CALIB", |
| 851 | .start = AB8500_INT_CC_INT_CALIB, |
| 852 | .end = AB8500_INT_CC_INT_CALIB, |
| 853 | .flags = IORESOURCE_IRQ, |
| 854 | }, |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 855 | { |
| 856 | .name = "CCEOC", |
| 857 | .start = AB8500_INT_CCEOC, |
| 858 | .end = AB8500_INT_CCEOC, |
| 859 | .flags = IORESOURCE_IRQ, |
| 860 | }, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 861 | }; |
| 862 | |
| 863 | static struct resource __devinitdata ab8500_chargalg_resources[] = {}; |
| 864 | |
Axel Lin | df72064 | 2011-11-10 09:56:18 +0800 | [diff] [blame] | 865 | #ifdef CONFIG_DEBUG_FS |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 866 | static struct resource __devinitdata ab8500_debug_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 867 | { |
| 868 | .name = "IRQ_FIRST", |
| 869 | .start = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 870 | .end = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 871 | .flags = IORESOURCE_IRQ, |
| 872 | }, |
| 873 | { |
| 874 | .name = "IRQ_LAST", |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 875 | .start = AB8500_INT_XTAL32K_KO, |
| 876 | .end = AB8500_INT_XTAL32K_KO, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 877 | .flags = IORESOURCE_IRQ, |
| 878 | }, |
| 879 | }; |
Axel Lin | df72064 | 2011-11-10 09:56:18 +0800 | [diff] [blame] | 880 | #endif |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 881 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 882 | static struct resource __devinitdata ab8500_usb_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 883 | { |
| 884 | .name = "ID_WAKEUP_R", |
| 885 | .start = AB8500_INT_ID_WAKEUP_R, |
| 886 | .end = AB8500_INT_ID_WAKEUP_R, |
| 887 | .flags = IORESOURCE_IRQ, |
| 888 | }, |
| 889 | { |
| 890 | .name = "ID_WAKEUP_F", |
| 891 | .start = AB8500_INT_ID_WAKEUP_F, |
| 892 | .end = AB8500_INT_ID_WAKEUP_F, |
| 893 | .flags = IORESOURCE_IRQ, |
| 894 | }, |
| 895 | { |
| 896 | .name = "VBUS_DET_F", |
| 897 | .start = AB8500_INT_VBUS_DET_F, |
| 898 | .end = AB8500_INT_VBUS_DET_F, |
| 899 | .flags = IORESOURCE_IRQ, |
| 900 | }, |
| 901 | { |
| 902 | .name = "VBUS_DET_R", |
| 903 | .start = AB8500_INT_VBUS_DET_R, |
| 904 | .end = AB8500_INT_VBUS_DET_R, |
| 905 | .flags = IORESOURCE_IRQ, |
| 906 | }, |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 907 | { |
| 908 | .name = "USB_LINK_STATUS", |
| 909 | .start = AB8500_INT_USB_LINK_STATUS, |
| 910 | .end = AB8500_INT_USB_LINK_STATUS, |
| 911 | .flags = IORESOURCE_IRQ, |
| 912 | }, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 913 | { |
| 914 | .name = "USB_ADP_PROBE_PLUG", |
| 915 | .start = AB8500_INT_ADP_PROBE_PLUG, |
| 916 | .end = AB8500_INT_ADP_PROBE_PLUG, |
| 917 | .flags = IORESOURCE_IRQ, |
| 918 | }, |
| 919 | { |
| 920 | .name = "USB_ADP_PROBE_UNPLUG", |
| 921 | .start = AB8500_INT_ADP_PROBE_UNPLUG, |
| 922 | .end = AB8500_INT_ADP_PROBE_UNPLUG, |
| 923 | .flags = IORESOURCE_IRQ, |
| 924 | }, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 925 | }; |
| 926 | |
Virupax Sadashivpetimath | 44f72e5 | 2012-04-17 09:30:14 +0200 | [diff] [blame] | 927 | static struct resource __devinitdata ab8505_iddet_resources[] = { |
| 928 | { |
| 929 | .name = "KeyDeglitch", |
| 930 | .start = AB8505_INT_KEYDEGLITCH, |
| 931 | .end = AB8505_INT_KEYDEGLITCH, |
| 932 | .flags = IORESOURCE_IRQ, |
| 933 | }, |
| 934 | { |
| 935 | .name = "KP", |
| 936 | .start = AB8505_INT_KP, |
| 937 | .end = AB8505_INT_KP, |
| 938 | .flags = IORESOURCE_IRQ, |
| 939 | }, |
| 940 | { |
| 941 | .name = "IKP", |
| 942 | .start = AB8505_INT_IKP, |
| 943 | .end = AB8505_INT_IKP, |
| 944 | .flags = IORESOURCE_IRQ, |
| 945 | }, |
| 946 | { |
| 947 | .name = "IKR", |
| 948 | .start = AB8505_INT_IKR, |
| 949 | .end = AB8505_INT_IKR, |
| 950 | .flags = IORESOURCE_IRQ, |
| 951 | }, |
| 952 | { |
| 953 | .name = "KeyStuck", |
| 954 | .start = AB8505_INT_KEYSTUCK, |
| 955 | .end = AB8505_INT_KEYSTUCK, |
| 956 | .flags = IORESOURCE_IRQ, |
| 957 | }, |
| 958 | }; |
| 959 | |
Robert Rosengren | 5cef8df | 2011-06-09 23:57:33 +0200 | [diff] [blame] | 960 | static struct resource __devinitdata ab8500_temp_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 961 | { |
| 962 | .name = "AB8500_TEMP_WARM", |
| 963 | .start = AB8500_INT_TEMP_WARM, |
| 964 | .end = AB8500_INT_TEMP_WARM, |
| 965 | .flags = IORESOURCE_IRQ, |
| 966 | }, |
| 967 | }; |
| 968 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 969 | static struct mfd_cell __devinitdata abx500_common_devs[] = { |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 970 | #ifdef CONFIG_DEBUG_FS |
| 971 | { |
| 972 | .name = "ab8500-debug", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 973 | .of_compatible = "stericsson,ab8500-debug", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 974 | .num_resources = ARRAY_SIZE(ab8500_debug_resources), |
| 975 | .resources = ab8500_debug_resources, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 976 | }, |
| 977 | #endif |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 978 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 979 | .name = "ab8500-sysctrl", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 980 | .of_compatible = "stericsson,ab8500-sysctrl", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 981 | }, |
| 982 | { |
| 983 | .name = "ab8500-regulator", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 984 | .of_compatible = "stericsson,ab8500-regulator", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 985 | }, |
| 986 | { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 987 | .name = "ab8500-gpadc", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 988 | .of_compatible = "stericsson,ab8500-gpadc", |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 989 | .num_resources = ARRAY_SIZE(ab8500_gpadc_resources), |
| 990 | .resources = ab8500_gpadc_resources, |
| 991 | }, |
| 992 | { |
| 993 | .name = "ab8500-rtc", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 994 | .of_compatible = "stericsson,ab8500-rtc", |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 995 | .num_resources = ARRAY_SIZE(ab8500_rtc_resources), |
| 996 | .resources = ab8500_rtc_resources, |
| 997 | }, |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 998 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 999 | .name = "ab8500-acc-det", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1000 | .of_compatible = "stericsson,ab8500-acc-det", |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 1001 | .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources), |
| 1002 | .resources = ab8500_av_acc_detect_resources, |
| 1003 | }, |
| 1004 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 1005 | .name = "ab8500-poweron-key", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1006 | .of_compatible = "stericsson,ab8500-poweron-key", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 1007 | .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources), |
| 1008 | .resources = ab8500_poweronkey_db_resources, |
| 1009 | }, |
| 1010 | { |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 1011 | .name = "ab8500-pwm", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1012 | .of_compatible = "stericsson,ab8500-pwm", |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 1013 | .id = 1, |
| 1014 | }, |
| 1015 | { |
| 1016 | .name = "ab8500-pwm", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1017 | .of_compatible = "stericsson,ab8500-pwm", |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 1018 | .id = 2, |
| 1019 | }, |
| 1020 | { |
| 1021 | .name = "ab8500-pwm", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1022 | .of_compatible = "stericsson,ab8500-pwm", |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 1023 | .id = 3, |
| 1024 | }, |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1025 | { |
| 1026 | .name = "ab8500-leds", |
| 1027 | .of_compatible = "stericsson,ab8500-leds", |
| 1028 | }, |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 1029 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 1030 | .name = "ab8500-denc", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1031 | .of_compatible = "stericsson,ab8500-denc", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 1032 | }, |
| 1033 | { |
| 1034 | .name = "ab8500-temp", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1035 | .of_compatible = "stericsson,ab8500-temp", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 1036 | .num_resources = ARRAY_SIZE(ab8500_temp_resources), |
| 1037 | .resources = ab8500_temp_resources, |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 1038 | }, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1039 | }; |
| 1040 | |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1041 | static struct mfd_cell __devinitdata ab8500_bm_devs[] = { |
| 1042 | { |
| 1043 | .name = "ab8500-charger", |
| 1044 | .num_resources = ARRAY_SIZE(ab8500_charger_resources), |
| 1045 | .resources = ab8500_charger_resources, |
| 1046 | }, |
| 1047 | { |
| 1048 | .name = "ab8500-btemp", |
| 1049 | .num_resources = ARRAY_SIZE(ab8500_btemp_resources), |
| 1050 | .resources = ab8500_btemp_resources, |
| 1051 | }, |
| 1052 | { |
| 1053 | .name = "ab8500-fg", |
| 1054 | .num_resources = ARRAY_SIZE(ab8500_fg_resources), |
| 1055 | .resources = ab8500_fg_resources, |
| 1056 | }, |
| 1057 | { |
| 1058 | .name = "ab8500-chargalg", |
| 1059 | .num_resources = ARRAY_SIZE(ab8500_chargalg_resources), |
| 1060 | .resources = ab8500_chargalg_resources, |
| 1061 | }, |
| 1062 | }; |
| 1063 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1064 | static struct mfd_cell __devinitdata ab8500_devs[] = { |
| 1065 | { |
| 1066 | .name = "ab8500-gpio", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1067 | .of_compatible = "stericsson,ab8500-gpio", |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1068 | .num_resources = ARRAY_SIZE(ab8500_gpio_resources), |
| 1069 | .resources = ab8500_gpio_resources, |
| 1070 | }, |
| 1071 | { |
| 1072 | .name = "ab8500-usb", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1073 | .of_compatible = "stericsson,ab8500-usb", |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1074 | .num_resources = ARRAY_SIZE(ab8500_usb_resources), |
| 1075 | .resources = ab8500_usb_resources, |
| 1076 | }, |
Virupax Sadashivpetimath | 44f72e5 | 2012-04-17 09:30:14 +0200 | [diff] [blame] | 1077 | { |
| 1078 | .name = "ab8500-codec", |
| 1079 | }, |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1080 | }; |
| 1081 | |
| 1082 | static struct mfd_cell __devinitdata ab9540_devs[] = { |
| 1083 | { |
| 1084 | .name = "ab8500-gpio", |
| 1085 | .num_resources = ARRAY_SIZE(ab9540_gpio_resources), |
| 1086 | .resources = ab9540_gpio_resources, |
| 1087 | }, |
| 1088 | { |
| 1089 | .name = "ab9540-usb", |
| 1090 | .num_resources = ARRAY_SIZE(ab8500_usb_resources), |
| 1091 | .resources = ab8500_usb_resources, |
| 1092 | }, |
Virupax Sadashivpetimath | 44f72e5 | 2012-04-17 09:30:14 +0200 | [diff] [blame] | 1093 | { |
| 1094 | .name = "ab9540-codec", |
| 1095 | }, |
| 1096 | }; |
| 1097 | |
| 1098 | /* Device list common to ab9540 and ab8505 */ |
| 1099 | static struct mfd_cell __devinitdata ab9540_ab8505_devs[] = { |
| 1100 | { |
| 1101 | .name = "ab-iddet", |
| 1102 | .num_resources = ARRAY_SIZE(ab8505_iddet_resources), |
| 1103 | .resources = ab8505_iddet_resources, |
| 1104 | }, |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1105 | }; |
| 1106 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1107 | static ssize_t show_chip_id(struct device *dev, |
| 1108 | struct device_attribute *attr, char *buf) |
| 1109 | { |
| 1110 | struct ab8500 *ab8500; |
| 1111 | |
| 1112 | ab8500 = dev_get_drvdata(dev); |
| 1113 | return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL); |
| 1114 | } |
| 1115 | |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1116 | /* |
| 1117 | * ab8500 has switched off due to (SWITCH_OFF_STATUS): |
| 1118 | * 0x01 Swoff bit programming |
| 1119 | * 0x02 Thermal protection activation |
| 1120 | * 0x04 Vbat lower then BattOk falling threshold |
| 1121 | * 0x08 Watchdog expired |
| 1122 | * 0x10 Non presence of 32kHz clock |
| 1123 | * 0x20 Battery level lower than power on reset threshold |
| 1124 | * 0x40 Power on key 1 pressed longer than 10 seconds |
| 1125 | * 0x80 DB8500 thermal shutdown |
| 1126 | */ |
| 1127 | static ssize_t show_switch_off_status(struct device *dev, |
| 1128 | struct device_attribute *attr, char *buf) |
| 1129 | { |
| 1130 | int ret; |
| 1131 | u8 value; |
| 1132 | struct ab8500 *ab8500; |
| 1133 | |
| 1134 | ab8500 = dev_get_drvdata(dev); |
| 1135 | ret = get_register_interruptible(ab8500, AB8500_RTC, |
| 1136 | AB8500_SWITCH_OFF_STATUS, &value); |
| 1137 | if (ret < 0) |
| 1138 | return ret; |
| 1139 | return sprintf(buf, "%#x\n", value); |
| 1140 | } |
| 1141 | |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 1142 | /* |
| 1143 | * ab8500 has turned on due to (TURN_ON_STATUS): |
| 1144 | * 0x01 PORnVbat |
| 1145 | * 0x02 PonKey1dbF |
| 1146 | * 0x04 PonKey2dbF |
| 1147 | * 0x08 RTCAlarm |
| 1148 | * 0x10 MainChDet |
| 1149 | * 0x20 VbusDet |
| 1150 | * 0x40 UsbIDDetect |
| 1151 | * 0x80 Reserved |
| 1152 | */ |
| 1153 | static ssize_t show_turn_on_status(struct device *dev, |
| 1154 | struct device_attribute *attr, char *buf) |
| 1155 | { |
| 1156 | int ret; |
| 1157 | u8 value; |
| 1158 | struct ab8500 *ab8500; |
| 1159 | |
| 1160 | ab8500 = dev_get_drvdata(dev); |
| 1161 | ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, |
| 1162 | AB8500_TURN_ON_STATUS, &value); |
| 1163 | if (ret < 0) |
| 1164 | return ret; |
| 1165 | return sprintf(buf, "%#x\n", value); |
| 1166 | } |
| 1167 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1168 | static ssize_t show_ab9540_dbbrstn(struct device *dev, |
| 1169 | struct device_attribute *attr, char *buf) |
| 1170 | { |
| 1171 | struct ab8500 *ab8500; |
| 1172 | int ret; |
| 1173 | u8 value; |
| 1174 | |
| 1175 | ab8500 = dev_get_drvdata(dev); |
| 1176 | |
| 1177 | ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2, |
| 1178 | AB9540_MODEM_CTRL2_REG, &value); |
| 1179 | if (ret < 0) |
| 1180 | return ret; |
| 1181 | |
| 1182 | return sprintf(buf, "%d\n", |
| 1183 | (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0); |
| 1184 | } |
| 1185 | |
| 1186 | static ssize_t store_ab9540_dbbrstn(struct device *dev, |
| 1187 | struct device_attribute *attr, const char *buf, size_t count) |
| 1188 | { |
| 1189 | struct ab8500 *ab8500; |
| 1190 | int ret = count; |
| 1191 | int err; |
| 1192 | u8 bitvalues; |
| 1193 | |
| 1194 | ab8500 = dev_get_drvdata(dev); |
| 1195 | |
| 1196 | if (count > 0) { |
| 1197 | switch (buf[0]) { |
| 1198 | case '0': |
| 1199 | bitvalues = 0; |
| 1200 | break; |
| 1201 | case '1': |
| 1202 | bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT; |
| 1203 | break; |
| 1204 | default: |
| 1205 | goto exit; |
| 1206 | } |
| 1207 | |
| 1208 | err = mask_and_set_register_interruptible(ab8500, |
| 1209 | AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG, |
| 1210 | AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues); |
| 1211 | if (err) |
| 1212 | dev_info(ab8500->dev, |
| 1213 | "Failed to set DBBRSTN %c, err %#x\n", |
| 1214 | buf[0], err); |
| 1215 | } |
| 1216 | |
| 1217 | exit: |
| 1218 | return ret; |
| 1219 | } |
| 1220 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1221 | static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL); |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1222 | 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] | 1223 | 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] | 1224 | static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR, |
| 1225 | show_ab9540_dbbrstn, store_ab9540_dbbrstn); |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1226 | |
| 1227 | static struct attribute *ab8500_sysfs_entries[] = { |
| 1228 | &dev_attr_chip_id.attr, |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1229 | &dev_attr_switch_off_status.attr, |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 1230 | &dev_attr_turn_on_status.attr, |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1231 | NULL, |
| 1232 | }; |
| 1233 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1234 | static struct attribute *ab9540_sysfs_entries[] = { |
| 1235 | &dev_attr_chip_id.attr, |
| 1236 | &dev_attr_switch_off_status.attr, |
| 1237 | &dev_attr_turn_on_status.attr, |
| 1238 | &dev_attr_dbbrstn.attr, |
| 1239 | NULL, |
| 1240 | }; |
| 1241 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1242 | static struct attribute_group ab8500_attr_group = { |
| 1243 | .attrs = ab8500_sysfs_entries, |
| 1244 | }; |
| 1245 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1246 | static struct attribute_group ab9540_attr_group = { |
| 1247 | .attrs = ab9540_sysfs_entries, |
| 1248 | }; |
| 1249 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1250 | static int __devinit ab8500_probe(struct platform_device *pdev) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1251 | { |
Jonas Aaberg | b04c530c | 2012-06-29 17:46:12 +0200 | [diff] [blame] | 1252 | static char *switch_off_status[] = { |
| 1253 | "Swoff bit programming", |
| 1254 | "Thermal protection activation", |
| 1255 | "Vbat lower then BattOk falling threshold", |
| 1256 | "Watchdog expired", |
| 1257 | "Non presence of 32kHz clock", |
| 1258 | "Battery level lower than power on reset threshold", |
| 1259 | "Power on key 1 pressed longer than 10 seconds", |
| 1260 | "DB8500 thermal shutdown"}; |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1261 | struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev); |
| 1262 | const struct platform_device_id *platid = platform_get_device_id(pdev); |
Lee Jones | 6bc4a56 | 2012-05-17 14:45:13 +0100 | [diff] [blame] | 1263 | enum ab8500_version version = AB8500_VERSION_UNDEFINED; |
| 1264 | struct device_node *np = pdev->dev.of_node; |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1265 | struct ab8500 *ab8500; |
| 1266 | struct resource *resource; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1267 | int ret; |
| 1268 | int i; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1269 | u8 value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1270 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1271 | ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL); |
| 1272 | if (!ab8500) |
| 1273 | return -ENOMEM; |
| 1274 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1275 | if (plat) |
| 1276 | ab8500->irq_base = plat->irq_base; |
| 1277 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1278 | ab8500->dev = &pdev->dev; |
| 1279 | |
| 1280 | resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1281 | if (!resource) { |
| 1282 | ret = -ENODEV; |
| 1283 | goto out_free_ab8500; |
| 1284 | } |
| 1285 | |
| 1286 | ab8500->irq = resource->start; |
| 1287 | |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 1288 | ab8500->read = ab8500_prcmu_read; |
| 1289 | ab8500->write = ab8500_prcmu_write; |
| 1290 | ab8500->write_masked = ab8500_prcmu_write_masked; |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1291 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1292 | mutex_init(&ab8500->lock); |
| 1293 | mutex_init(&ab8500->irq_lock); |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 1294 | atomic_set(&ab8500->transfer_ongoing, 0); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1295 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1296 | platform_set_drvdata(pdev, ab8500); |
| 1297 | |
Lee Jones | 6bc4a56 | 2012-05-17 14:45:13 +0100 | [diff] [blame] | 1298 | if (platid) |
| 1299 | version = platid->driver_data; |
Lee Jones | 6bc4a56 | 2012-05-17 14:45:13 +0100 | [diff] [blame] | 1300 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1301 | if (version != AB8500_VERSION_UNDEFINED) |
| 1302 | ab8500->version = version; |
| 1303 | else { |
| 1304 | ret = get_register_interruptible(ab8500, AB8500_MISC, |
| 1305 | AB8500_IC_NAME_REG, &value); |
| 1306 | if (ret < 0) |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1307 | goto out_free_ab8500; |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1308 | |
| 1309 | ab8500->version = value; |
| 1310 | } |
| 1311 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1312 | ret = get_register_interruptible(ab8500, AB8500_MISC, |
| 1313 | AB8500_REV_REG, &value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1314 | if (ret < 0) |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1315 | goto out_free_ab8500; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1316 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1317 | ab8500->chip_id = value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1318 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1319 | dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n", |
| 1320 | ab8500_version_str[ab8500->version], |
| 1321 | ab8500->chip_id >> 4, |
| 1322 | ab8500->chip_id & 0x0F); |
| 1323 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1324 | /* Configure AB8500 or AB9540 IRQ */ |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 1325 | if (is_ab9540(ab8500) || is_ab8505(ab8500)) { |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1326 | ab8500->mask_size = AB9540_NUM_IRQ_REGS; |
| 1327 | ab8500->irq_reg_offset = ab9540_irq_regoffset; |
| 1328 | } else { |
| 1329 | ab8500->mask_size = AB8500_NUM_IRQ_REGS; |
| 1330 | ab8500->irq_reg_offset = ab8500_irq_regoffset; |
| 1331 | } |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1332 | ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL); |
| 1333 | if (!ab8500->mask) |
| 1334 | return -ENOMEM; |
| 1335 | ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL); |
| 1336 | if (!ab8500->oldmask) { |
| 1337 | ret = -ENOMEM; |
| 1338 | goto out_freemask; |
| 1339 | } |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1340 | /* |
| 1341 | * ab8500 has switched off due to (SWITCH_OFF_STATUS): |
| 1342 | * 0x01 Swoff bit programming |
| 1343 | * 0x02 Thermal protection activation |
| 1344 | * 0x04 Vbat lower then BattOk falling threshold |
| 1345 | * 0x08 Watchdog expired |
| 1346 | * 0x10 Non presence of 32kHz clock |
| 1347 | * 0x20 Battery level lower than power on reset threshold |
| 1348 | * 0x40 Power on key 1 pressed longer than 10 seconds |
| 1349 | * 0x80 DB8500 thermal shutdown |
| 1350 | */ |
| 1351 | |
| 1352 | ret = get_register_interruptible(ab8500, AB8500_RTC, |
| 1353 | AB8500_SWITCH_OFF_STATUS, &value); |
| 1354 | if (ret < 0) |
| 1355 | return ret; |
Jonas Aaberg | b04c530c | 2012-06-29 17:46:12 +0200 | [diff] [blame] | 1356 | dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value); |
| 1357 | |
| 1358 | if (value) { |
| 1359 | for (i = 0; i < ARRAY_SIZE(switch_off_status); i++) { |
| 1360 | if (value & 1) |
| 1361 | printk(KERN_CONT " \"%s\"", |
| 1362 | switch_off_status[i]); |
| 1363 | value = value >> 1; |
| 1364 | |
| 1365 | } |
| 1366 | printk(KERN_CONT "\n"); |
| 1367 | } else { |
| 1368 | printk(KERN_CONT " None\n"); |
| 1369 | } |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1370 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1371 | if (plat && plat->init) |
| 1372 | plat->init(ab8500); |
| 1373 | |
| 1374 | /* Clear and mask all interrupts */ |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1375 | for (i = 0; i < ab8500->mask_size; i++) { |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1376 | /* |
| 1377 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 1378 | * 2.0 |
| 1379 | */ |
| 1380 | if (ab8500->irq_reg_offset[i] == 11 && |
| 1381 | is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 1382 | continue; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1383 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1384 | get_register_interruptible(ab8500, AB8500_INTERRUPT, |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1385 | AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i], |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 1386 | &value); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1387 | set_register_interruptible(ab8500, AB8500_INTERRUPT, |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1388 | AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1389 | } |
| 1390 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1391 | ret = abx500_register_ops(ab8500->dev, &ab8500_ops); |
| 1392 | if (ret) |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1393 | goto out_freeoldmask; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1394 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1395 | for (i = 0; i < ab8500->mask_size; i++) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1396 | ab8500->mask[i] = ab8500->oldmask[i] = 0xff; |
| 1397 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1398 | ret = ab8500_irq_init(ab8500, np); |
| 1399 | if (ret) |
| 1400 | goto out_freeoldmask; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1401 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1402 | /* Activate this feature only in ab9540 */ |
| 1403 | /* till tests are done on ab8500 1p2 or later*/ |
| 1404 | if (is_ab9540(ab8500)) { |
| 1405 | ret = request_threaded_irq(ab8500->irq, NULL, |
Michel JAOUEN | 7ccfe9b | 2012-05-07 15:02:03 +0200 | [diff] [blame] | 1406 | ab8500_hierarchical_irq, |
| 1407 | IRQF_ONESHOT | IRQF_NO_SUSPEND, |
| 1408 | "ab8500", ab8500); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1409 | } |
| 1410 | else { |
| 1411 | ret = request_threaded_irq(ab8500->irq, NULL, |
Michel JAOUEN | 7ccfe9b | 2012-05-07 15:02:03 +0200 | [diff] [blame] | 1412 | ab8500_irq, |
| 1413 | IRQF_ONESHOT | IRQF_NO_SUSPEND, |
| 1414 | "ab8500", ab8500); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1415 | if (ret) |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1416 | goto out_freeoldmask; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1417 | } |
| 1418 | |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1419 | ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs, |
| 1420 | ARRAY_SIZE(abx500_common_devs), NULL, |
| 1421 | ab8500->irq_base); |
| 1422 | if (ret) |
| 1423 | goto out_freeirq; |
| 1424 | |
| 1425 | if (is_ab9540(ab8500)) |
| 1426 | ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, |
| 1427 | ARRAY_SIZE(ab9540_devs), NULL, |
Lee Jones | 6bc4a56 | 2012-05-17 14:45:13 +0100 | [diff] [blame] | 1428 | ab8500->irq_base); |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1429 | else |
| 1430 | ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, |
| 1431 | ARRAY_SIZE(ab8500_devs), NULL, |
| 1432 | ab8500->irq_base); |
| 1433 | if (ret) |
| 1434 | goto out_freeirq; |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1435 | |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1436 | if (is_ab9540(ab8500) || is_ab8505(ab8500)) |
| 1437 | ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs, |
| 1438 | ARRAY_SIZE(ab9540_ab8505_devs), NULL, |
| 1439 | ab8500->irq_base); |
| 1440 | if (ret) |
| 1441 | goto out_freeirq; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1442 | |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1443 | if (!no_bm) { |
| 1444 | /* Add battery management devices */ |
| 1445 | ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs, |
| 1446 | ARRAY_SIZE(ab8500_bm_devs), NULL, |
| 1447 | ab8500->irq_base); |
| 1448 | if (ret) |
| 1449 | dev_err(ab8500->dev, "error adding bm devices\n"); |
| 1450 | } |
| 1451 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1452 | if (is_ab9540(ab8500)) |
| 1453 | ret = sysfs_create_group(&ab8500->dev->kobj, |
| 1454 | &ab9540_attr_group); |
| 1455 | else |
| 1456 | ret = sysfs_create_group(&ab8500->dev->kobj, |
| 1457 | &ab8500_attr_group); |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1458 | if (ret) |
| 1459 | dev_err(ab8500->dev, "error creating sysfs entries\n"); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1460 | |
| 1461 | return ret; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1462 | |
| 1463 | out_freeirq: |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1464 | free_irq(ab8500->irq, ab8500); |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1465 | out_freeoldmask: |
| 1466 | kfree(ab8500->oldmask); |
| 1467 | out_freemask: |
| 1468 | kfree(ab8500->mask); |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1469 | out_free_ab8500: |
| 1470 | kfree(ab8500); |
Linus Walleij | 6d95b7f | 2012-02-20 21:42:03 +0100 | [diff] [blame] | 1471 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1472 | return ret; |
| 1473 | } |
| 1474 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1475 | static int __devexit ab8500_remove(struct platform_device *pdev) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1476 | { |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1477 | struct ab8500 *ab8500 = platform_get_drvdata(pdev); |
| 1478 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1479 | if (is_ab9540(ab8500)) |
| 1480 | sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group); |
| 1481 | else |
| 1482 | sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1483 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1484 | mfd_remove_devices(ab8500->dev); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1485 | free_irq(ab8500->irq, ab8500); |
| 1486 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1487 | kfree(ab8500->oldmask); |
| 1488 | kfree(ab8500->mask); |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1489 | kfree(ab8500); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1490 | |
| 1491 | return 0; |
| 1492 | } |
| 1493 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1494 | static const struct platform_device_id ab8500_id[] = { |
| 1495 | { "ab8500-core", AB8500_VERSION_AB8500 }, |
| 1496 | { "ab8505-i2c", AB8500_VERSION_AB8505 }, |
| 1497 | { "ab9540-i2c", AB8500_VERSION_AB9540 }, |
| 1498 | { "ab8540-i2c", AB8500_VERSION_AB8540 }, |
| 1499 | { } |
| 1500 | }; |
| 1501 | |
| 1502 | static struct platform_driver ab8500_core_driver = { |
| 1503 | .driver = { |
| 1504 | .name = "ab8500-core", |
| 1505 | .owner = THIS_MODULE, |
| 1506 | }, |
| 1507 | .probe = ab8500_probe, |
| 1508 | .remove = __devexit_p(ab8500_remove), |
| 1509 | .id_table = ab8500_id, |
| 1510 | }; |
| 1511 | |
| 1512 | static int __init ab8500_core_init(void) |
| 1513 | { |
| 1514 | return platform_driver_register(&ab8500_core_driver); |
| 1515 | } |
| 1516 | |
| 1517 | static void __exit ab8500_core_exit(void) |
| 1518 | { |
| 1519 | platform_driver_unregister(&ab8500_core_driver); |
| 1520 | } |
Lee Jones | ba7cbc3 | 2012-06-11 16:25:00 +0100 | [diff] [blame] | 1521 | core_initcall(ab8500_core_init); |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1522 | module_exit(ab8500_core_exit); |
| 1523 | |
Mattias Wallin | adceed6 | 2011-03-02 11:51:11 +0100 | [diff] [blame] | 1524 | MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent"); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1525 | MODULE_DESCRIPTION("AB8500 MFD core"); |
| 1526 | MODULE_LICENSE("GPL v2"); |