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, |
Mian Yousaf Kaukab | 1d843a6 | 2012-01-27 11:35:41 +0100 | [diff] [blame^] | 322 | .dump_all_banks = ab8500_dump_all_banks, |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 323 | }; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 324 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 325 | static void ab8500_irq_lock(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 326 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 327 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 328 | |
| 329 | mutex_lock(&ab8500->irq_lock); |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 330 | atomic_inc(&ab8500->transfer_ongoing); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 331 | } |
| 332 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 333 | static void ab8500_irq_sync_unlock(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 334 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 335 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 336 | int i; |
| 337 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 338 | for (i = 0; i < ab8500->mask_size; i++) { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 339 | u8 old = ab8500->oldmask[i]; |
| 340 | u8 new = ab8500->mask[i]; |
| 341 | int reg; |
| 342 | |
| 343 | if (new == old) |
| 344 | continue; |
| 345 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 346 | /* |
| 347 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 348 | * 2.0 |
| 349 | */ |
| 350 | if (ab8500->irq_reg_offset[i] == 11 && |
| 351 | is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 352 | continue; |
| 353 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 354 | ab8500->oldmask[i] = new; |
| 355 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 356 | reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i]; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 357 | set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 358 | } |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 359 | atomic_dec(&ab8500->transfer_ongoing); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 360 | mutex_unlock(&ab8500->irq_lock); |
| 361 | } |
| 362 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 363 | static void ab8500_irq_mask(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 364 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 365 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 366 | int offset = data->hwirq; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 367 | int index = offset / 8; |
| 368 | int mask = 1 << (offset % 8); |
| 369 | |
| 370 | ab8500->mask[index] |= mask; |
| 371 | } |
| 372 | |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 373 | static void ab8500_irq_unmask(struct irq_data *data) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 374 | { |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 375 | struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 376 | int offset = data->hwirq; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 377 | int index = offset / 8; |
| 378 | int mask = 1 << (offset % 8); |
| 379 | |
| 380 | ab8500->mask[index] &= ~mask; |
| 381 | } |
| 382 | |
| 383 | static struct irq_chip ab8500_irq_chip = { |
| 384 | .name = "ab8500", |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 385 | .irq_bus_lock = ab8500_irq_lock, |
| 386 | .irq_bus_sync_unlock = ab8500_irq_sync_unlock, |
| 387 | .irq_mask = ab8500_irq_mask, |
Virupax Sadashivpetimath | e6f9306 | 2011-10-11 10:49:17 +0200 | [diff] [blame] | 388 | .irq_disable = ab8500_irq_mask, |
Mark Brown | 9505a0a | 2010-12-11 13:16:08 +0000 | [diff] [blame] | 389 | .irq_unmask = ab8500_irq_unmask, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 390 | }; |
| 391 | |
Michel JAOUEN | 7ccfe9b | 2012-05-07 15:02:03 +0200 | [diff] [blame] | 392 | static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500, |
| 393 | int latch_offset, u8 latch_val) |
| 394 | { |
| 395 | int int_bit = __ffs(latch_val); |
| 396 | int line, i; |
| 397 | |
| 398 | do { |
| 399 | int_bit = __ffs(latch_val); |
| 400 | |
| 401 | for (i = 0; i < ab8500->mask_size; i++) |
| 402 | if (ab8500->irq_reg_offset[i] == latch_offset) |
| 403 | break; |
| 404 | |
| 405 | if (i >= ab8500->mask_size) { |
| 406 | dev_err(ab8500->dev, "Register offset 0x%2x not declared\n", |
| 407 | latch_offset); |
| 408 | return -ENXIO; |
| 409 | } |
| 410 | |
| 411 | line = (i << 3) + int_bit; |
| 412 | latch_val &= ~(1 << int_bit); |
| 413 | |
| 414 | handle_nested_irq(ab8500->irq_base + line); |
| 415 | } while (latch_val); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500, |
| 421 | int hier_offset, u8 hier_val) |
| 422 | { |
| 423 | int latch_bit, status; |
| 424 | u8 latch_offset, latch_val; |
| 425 | |
| 426 | do { |
| 427 | latch_bit = __ffs(hier_val); |
| 428 | latch_offset = (hier_offset << 3) + latch_bit; |
| 429 | |
| 430 | /* Fix inconsistent ITFromLatch25 bit mapping... */ |
| 431 | if (unlikely(latch_offset == 17)) |
| 432 | latch_offset = 24; |
| 433 | |
| 434 | status = get_register_interruptible(ab8500, |
| 435 | AB8500_INTERRUPT, |
| 436 | AB8500_IT_LATCH1_REG + latch_offset, |
| 437 | &latch_val); |
| 438 | if (status < 0 || latch_val == 0) |
| 439 | goto discard; |
| 440 | |
| 441 | status = ab8500_handle_hierarchical_line(ab8500, |
| 442 | latch_offset, latch_val); |
| 443 | if (status < 0) |
| 444 | return status; |
| 445 | discard: |
| 446 | hier_val &= ~(1 << latch_bit); |
| 447 | } while (hier_val); |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev) |
| 453 | { |
| 454 | struct ab8500 *ab8500 = dev; |
| 455 | u8 i; |
| 456 | |
| 457 | dev_vdbg(ab8500->dev, "interrupt\n"); |
| 458 | |
| 459 | /* Hierarchical interrupt version */ |
| 460 | for (i = 0; i < AB8500_IT_LATCHHIER_NUM; i++) { |
| 461 | int status; |
| 462 | u8 hier_val; |
| 463 | |
| 464 | status = get_register_interruptible(ab8500, AB8500_INTERRUPT, |
| 465 | AB8500_IT_LATCHHIER1_REG + i, &hier_val); |
| 466 | if (status < 0 || hier_val == 0) |
| 467 | continue; |
| 468 | |
| 469 | status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val); |
| 470 | if (status < 0) |
| 471 | break; |
| 472 | } |
| 473 | return IRQ_HANDLED; |
| 474 | } |
| 475 | |
Lee Jones | 80633f0 | 2012-08-20 11:53:36 +0100 | [diff] [blame] | 476 | /** |
| 477 | * ab8500_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ |
| 478 | * |
| 479 | * @ab8500: ab8500_irq controller to operate on. |
| 480 | * @irq: index of the interrupt requested in the chip IRQs |
| 481 | * |
| 482 | * Useful for drivers to request their own IRQs. |
| 483 | */ |
| 484 | static int ab8500_irq_get_virq(struct ab8500 *ab8500, int irq) |
| 485 | { |
| 486 | if (!ab8500) |
| 487 | return -EINVAL; |
| 488 | |
| 489 | return irq_create_mapping(ab8500->domain, irq); |
| 490 | } |
| 491 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 492 | static irqreturn_t ab8500_irq(int irq, void *dev) |
| 493 | { |
| 494 | struct ab8500 *ab8500 = dev; |
| 495 | int i; |
| 496 | |
| 497 | dev_vdbg(ab8500->dev, "interrupt\n"); |
| 498 | |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 499 | atomic_inc(&ab8500->transfer_ongoing); |
| 500 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 501 | for (i = 0; i < ab8500->mask_size; i++) { |
| 502 | int regoffset = ab8500->irq_reg_offset[i]; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 503 | int status; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 504 | u8 value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 505 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 506 | /* |
| 507 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 508 | * 2.0 |
| 509 | */ |
| 510 | if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 511 | continue; |
| 512 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 513 | status = get_register_interruptible(ab8500, AB8500_INTERRUPT, |
| 514 | AB8500_IT_LATCH1_REG + regoffset, &value); |
| 515 | if (status < 0 || value == 0) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 516 | continue; |
| 517 | |
| 518 | do { |
Mattias Wallin | 88aec4f | 2010-12-02 15:06:49 +0100 | [diff] [blame] | 519 | int bit = __ffs(value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 520 | int line = i * 8 + bit; |
Lee Jones | 0a37fc5 | 2012-08-09 16:53:54 +0100 | [diff] [blame] | 521 | int virq = ab8500_irq_get_virq(ab8500, line); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 522 | |
Lee Jones | 0a37fc5 | 2012-08-09 16:53:54 +0100 | [diff] [blame] | 523 | handle_nested_irq(virq); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 524 | value &= ~(1 << bit); |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 525 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 526 | } while (value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 527 | } |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 528 | atomic_dec(&ab8500->transfer_ongoing); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 529 | return IRQ_HANDLED; |
| 530 | } |
| 531 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 532 | static int ab8500_irq_map(struct irq_domain *d, unsigned int virq, |
| 533 | irq_hw_number_t hwirq) |
| 534 | { |
| 535 | struct ab8500 *ab8500 = d->host_data; |
| 536 | |
| 537 | if (!ab8500) |
| 538 | return -EINVAL; |
| 539 | |
| 540 | irq_set_chip_data(virq, ab8500); |
| 541 | irq_set_chip_and_handler(virq, &ab8500_irq_chip, |
| 542 | handle_simple_irq); |
| 543 | irq_set_nested_thread(virq, 1); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 544 | #ifdef CONFIG_ARM |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 545 | set_irq_flags(virq, IRQF_VALID); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 546 | #else |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 547 | irq_set_noprobe(virq); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 548 | #endif |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 553 | static struct irq_domain_ops ab8500_irq_ops = { |
| 554 | .map = ab8500_irq_map, |
| 555 | .xlate = irq_domain_xlate_twocell, |
| 556 | }; |
| 557 | |
| 558 | static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 559 | { |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 560 | int num_irqs; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 561 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 562 | if (is_ab9540(ab8500)) |
| 563 | num_irqs = AB9540_NR_IRQS; |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 564 | else if (is_ab8505(ab8500)) |
| 565 | num_irqs = AB8505_NR_IRQS; |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 566 | else |
| 567 | num_irqs = AB8500_NR_IRQS; |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 568 | |
Linus Walleij | f1d11f3 | 2012-10-18 18:18:44 +0200 | [diff] [blame] | 569 | /* If ->irq_base is zero this will give a linear mapping */ |
| 570 | ab8500->domain = irq_domain_add_simple(NULL, |
| 571 | num_irqs, ab8500->irq_base, |
| 572 | &ab8500_irq_ops, ab8500); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 573 | |
| 574 | if (!ab8500->domain) { |
| 575 | dev_err(ab8500->dev, "Failed to create irqdomain\n"); |
| 576 | return -ENOSYS; |
| 577 | } |
| 578 | |
| 579 | return 0; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 580 | } |
| 581 | |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 582 | int ab8500_suspend(struct ab8500 *ab8500) |
| 583 | { |
| 584 | if (atomic_read(&ab8500->transfer_ongoing)) |
| 585 | return -EINVAL; |
| 586 | else |
| 587 | return 0; |
| 588 | } |
| 589 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 590 | static struct resource ab8500_gpadc_resources[] = { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 591 | { |
| 592 | .name = "HW_CONV_END", |
| 593 | .start = AB8500_INT_GP_HW_ADC_CONV_END, |
| 594 | .end = AB8500_INT_GP_HW_ADC_CONV_END, |
| 595 | .flags = IORESOURCE_IRQ, |
| 596 | }, |
| 597 | { |
| 598 | .name = "SW_CONV_END", |
| 599 | .start = AB8500_INT_GP_SW_ADC_CONV_END, |
| 600 | .end = AB8500_INT_GP_SW_ADC_CONV_END, |
| 601 | .flags = IORESOURCE_IRQ, |
| 602 | }, |
| 603 | }; |
| 604 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 605 | static struct resource ab8500_rtc_resources[] = { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 606 | { |
| 607 | .name = "60S", |
| 608 | .start = AB8500_INT_RTC_60S, |
| 609 | .end = AB8500_INT_RTC_60S, |
| 610 | .flags = IORESOURCE_IRQ, |
| 611 | }, |
| 612 | { |
| 613 | .name = "ALARM", |
| 614 | .start = AB8500_INT_RTC_ALARM, |
| 615 | .end = AB8500_INT_RTC_ALARM, |
| 616 | .flags = IORESOURCE_IRQ, |
| 617 | }, |
| 618 | }; |
| 619 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 620 | static struct resource ab8500_poweronkey_db_resources[] = { |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 621 | { |
| 622 | .name = "ONKEY_DBF", |
| 623 | .start = AB8500_INT_PON_KEY1DB_F, |
| 624 | .end = AB8500_INT_PON_KEY1DB_F, |
| 625 | .flags = IORESOURCE_IRQ, |
| 626 | }, |
| 627 | { |
| 628 | .name = "ONKEY_DBR", |
| 629 | .start = AB8500_INT_PON_KEY1DB_R, |
| 630 | .end = AB8500_INT_PON_KEY1DB_R, |
| 631 | .flags = IORESOURCE_IRQ, |
| 632 | }, |
| 633 | }; |
| 634 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 635 | static struct resource ab8500_av_acc_detect_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 636 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 637 | .name = "ACC_DETECT_1DB_F", |
| 638 | .start = AB8500_INT_ACC_DETECT_1DB_F, |
| 639 | .end = AB8500_INT_ACC_DETECT_1DB_F, |
| 640 | .flags = IORESOURCE_IRQ, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 641 | }, |
| 642 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 643 | .name = "ACC_DETECT_1DB_R", |
| 644 | .start = AB8500_INT_ACC_DETECT_1DB_R, |
| 645 | .end = AB8500_INT_ACC_DETECT_1DB_R, |
| 646 | .flags = IORESOURCE_IRQ, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 647 | }, |
| 648 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 649 | .name = "ACC_DETECT_21DB_F", |
| 650 | .start = AB8500_INT_ACC_DETECT_21DB_F, |
| 651 | .end = AB8500_INT_ACC_DETECT_21DB_F, |
| 652 | .flags = IORESOURCE_IRQ, |
| 653 | }, |
| 654 | { |
| 655 | .name = "ACC_DETECT_21DB_R", |
| 656 | .start = AB8500_INT_ACC_DETECT_21DB_R, |
| 657 | .end = AB8500_INT_ACC_DETECT_21DB_R, |
| 658 | .flags = IORESOURCE_IRQ, |
| 659 | }, |
| 660 | { |
| 661 | .name = "ACC_DETECT_22DB_F", |
| 662 | .start = AB8500_INT_ACC_DETECT_22DB_F, |
| 663 | .end = AB8500_INT_ACC_DETECT_22DB_F, |
| 664 | .flags = IORESOURCE_IRQ, |
| 665 | }, |
| 666 | { |
| 667 | .name = "ACC_DETECT_22DB_R", |
| 668 | .start = AB8500_INT_ACC_DETECT_22DB_R, |
| 669 | .end = AB8500_INT_ACC_DETECT_22DB_R, |
| 670 | .flags = IORESOURCE_IRQ, |
| 671 | }, |
| 672 | }; |
| 673 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 674 | static struct resource ab8500_charger_resources[] = { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 675 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 676 | .name = "MAIN_CH_UNPLUG_DET", |
| 677 | .start = AB8500_INT_MAIN_CH_UNPLUG_DET, |
| 678 | .end = AB8500_INT_MAIN_CH_UNPLUG_DET, |
| 679 | .flags = IORESOURCE_IRQ, |
| 680 | }, |
| 681 | { |
| 682 | .name = "MAIN_CHARGE_PLUG_DET", |
| 683 | .start = AB8500_INT_MAIN_CH_PLUG_DET, |
| 684 | .end = AB8500_INT_MAIN_CH_PLUG_DET, |
| 685 | .flags = IORESOURCE_IRQ, |
| 686 | }, |
| 687 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 688 | .name = "VBUS_DET_R", |
| 689 | .start = AB8500_INT_VBUS_DET_R, |
| 690 | .end = AB8500_INT_VBUS_DET_R, |
| 691 | .flags = IORESOURCE_IRQ, |
| 692 | }, |
| 693 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 694 | .name = "VBUS_DET_F", |
| 695 | .start = AB8500_INT_VBUS_DET_F, |
| 696 | .end = AB8500_INT_VBUS_DET_F, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 697 | .flags = IORESOURCE_IRQ, |
| 698 | }, |
| 699 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 700 | .name = "USB_LINK_STATUS", |
| 701 | .start = AB8500_INT_USB_LINK_STATUS, |
| 702 | .end = AB8500_INT_USB_LINK_STATUS, |
| 703 | .flags = IORESOURCE_IRQ, |
| 704 | }, |
| 705 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 706 | .name = "VBUS_OVV", |
| 707 | .start = AB8500_INT_VBUS_OVV, |
| 708 | .end = AB8500_INT_VBUS_OVV, |
| 709 | .flags = IORESOURCE_IRQ, |
| 710 | }, |
| 711 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 712 | .name = "USB_CH_TH_PROT_R", |
| 713 | .start = AB8500_INT_USB_CH_TH_PROT_R, |
| 714 | .end = AB8500_INT_USB_CH_TH_PROT_R, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 715 | .flags = IORESOURCE_IRQ, |
| 716 | }, |
| 717 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 718 | .name = "USB_CH_TH_PROT_F", |
| 719 | .start = AB8500_INT_USB_CH_TH_PROT_F, |
| 720 | .end = AB8500_INT_USB_CH_TH_PROT_F, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 721 | .flags = IORESOURCE_IRQ, |
| 722 | }, |
| 723 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 724 | .name = "MAIN_EXT_CH_NOT_OK", |
| 725 | .start = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 726 | .end = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 727 | .flags = IORESOURCE_IRQ, |
| 728 | }, |
| 729 | { |
| 730 | .name = "MAIN_CH_TH_PROT_R", |
| 731 | .start = AB8500_INT_MAIN_CH_TH_PROT_R, |
| 732 | .end = AB8500_INT_MAIN_CH_TH_PROT_R, |
| 733 | .flags = IORESOURCE_IRQ, |
| 734 | }, |
| 735 | { |
| 736 | .name = "MAIN_CH_TH_PROT_F", |
| 737 | .start = AB8500_INT_MAIN_CH_TH_PROT_F, |
| 738 | .end = AB8500_INT_MAIN_CH_TH_PROT_F, |
| 739 | .flags = IORESOURCE_IRQ, |
| 740 | }, |
| 741 | { |
| 742 | .name = "USB_CHARGER_NOT_OKR", |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 743 | .start = AB8500_INT_USB_CHARGER_NOT_OKR, |
| 744 | .end = AB8500_INT_USB_CHARGER_NOT_OKR, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 745 | .flags = IORESOURCE_IRQ, |
| 746 | }, |
| 747 | { |
| 748 | .name = "CH_WD_EXP", |
| 749 | .start = AB8500_INT_CH_WD_EXP, |
| 750 | .end = AB8500_INT_CH_WD_EXP, |
| 751 | .flags = IORESOURCE_IRQ, |
| 752 | }, |
| 753 | }; |
| 754 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 755 | static struct resource ab8500_btemp_resources[] = { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 756 | { |
| 757 | .name = "BAT_CTRL_INDB", |
| 758 | .start = AB8500_INT_BAT_CTRL_INDB, |
| 759 | .end = AB8500_INT_BAT_CTRL_INDB, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 760 | .flags = IORESOURCE_IRQ, |
| 761 | }, |
| 762 | { |
| 763 | .name = "BTEMP_LOW", |
| 764 | .start = AB8500_INT_BTEMP_LOW, |
| 765 | .end = AB8500_INT_BTEMP_LOW, |
| 766 | .flags = IORESOURCE_IRQ, |
| 767 | }, |
| 768 | { |
| 769 | .name = "BTEMP_HIGH", |
| 770 | .start = AB8500_INT_BTEMP_HIGH, |
| 771 | .end = AB8500_INT_BTEMP_HIGH, |
| 772 | .flags = IORESOURCE_IRQ, |
| 773 | }, |
| 774 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 775 | .name = "BTEMP_LOW_MEDIUM", |
| 776 | .start = AB8500_INT_BTEMP_LOW_MEDIUM, |
| 777 | .end = AB8500_INT_BTEMP_LOW_MEDIUM, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 778 | .flags = IORESOURCE_IRQ, |
| 779 | }, |
| 780 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 781 | .name = "BTEMP_MEDIUM_HIGH", |
| 782 | .start = AB8500_INT_BTEMP_MEDIUM_HIGH, |
| 783 | .end = AB8500_INT_BTEMP_MEDIUM_HIGH, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 784 | .flags = IORESOURCE_IRQ, |
| 785 | }, |
| 786 | }; |
| 787 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 788 | static struct resource ab8500_fg_resources[] = { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 789 | { |
| 790 | .name = "NCONV_ACCU", |
| 791 | .start = AB8500_INT_CCN_CONV_ACC, |
| 792 | .end = AB8500_INT_CCN_CONV_ACC, |
| 793 | .flags = IORESOURCE_IRQ, |
| 794 | }, |
| 795 | { |
| 796 | .name = "BATT_OVV", |
| 797 | .start = AB8500_INT_BATT_OVV, |
| 798 | .end = AB8500_INT_BATT_OVV, |
| 799 | .flags = IORESOURCE_IRQ, |
| 800 | }, |
| 801 | { |
| 802 | .name = "LOW_BAT_F", |
| 803 | .start = AB8500_INT_LOW_BAT_F, |
| 804 | .end = AB8500_INT_LOW_BAT_F, |
| 805 | .flags = IORESOURCE_IRQ, |
| 806 | }, |
| 807 | { |
| 808 | .name = "LOW_BAT_R", |
| 809 | .start = AB8500_INT_LOW_BAT_R, |
| 810 | .end = AB8500_INT_LOW_BAT_R, |
| 811 | .flags = IORESOURCE_IRQ, |
| 812 | }, |
| 813 | { |
| 814 | .name = "CC_INT_CALIB", |
| 815 | .start = AB8500_INT_CC_INT_CALIB, |
| 816 | .end = AB8500_INT_CC_INT_CALIB, |
| 817 | .flags = IORESOURCE_IRQ, |
| 818 | }, |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 819 | { |
| 820 | .name = "CCEOC", |
| 821 | .start = AB8500_INT_CCEOC, |
| 822 | .end = AB8500_INT_CCEOC, |
| 823 | .flags = IORESOURCE_IRQ, |
| 824 | }, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 825 | }; |
| 826 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 827 | static struct resource ab8500_chargalg_resources[] = {}; |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 828 | |
Axel Lin | df72064 | 2011-11-10 09:56:18 +0800 | [diff] [blame] | 829 | #ifdef CONFIG_DEBUG_FS |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 830 | static struct resource ab8500_debug_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 831 | { |
| 832 | .name = "IRQ_FIRST", |
| 833 | .start = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 834 | .end = AB8500_INT_MAIN_EXT_CH_NOT_OK, |
| 835 | .flags = IORESOURCE_IRQ, |
| 836 | }, |
| 837 | { |
| 838 | .name = "IRQ_LAST", |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 839 | .start = AB8500_INT_XTAL32K_KO, |
| 840 | .end = AB8500_INT_XTAL32K_KO, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 841 | .flags = IORESOURCE_IRQ, |
| 842 | }, |
| 843 | }; |
Axel Lin | df72064 | 2011-11-10 09:56:18 +0800 | [diff] [blame] | 844 | #endif |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 845 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 846 | static struct resource ab8500_usb_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 847 | { |
| 848 | .name = "ID_WAKEUP_R", |
| 849 | .start = AB8500_INT_ID_WAKEUP_R, |
| 850 | .end = AB8500_INT_ID_WAKEUP_R, |
| 851 | .flags = IORESOURCE_IRQ, |
| 852 | }, |
| 853 | { |
| 854 | .name = "ID_WAKEUP_F", |
| 855 | .start = AB8500_INT_ID_WAKEUP_F, |
| 856 | .end = AB8500_INT_ID_WAKEUP_F, |
| 857 | .flags = IORESOURCE_IRQ, |
| 858 | }, |
| 859 | { |
| 860 | .name = "VBUS_DET_F", |
| 861 | .start = AB8500_INT_VBUS_DET_F, |
| 862 | .end = AB8500_INT_VBUS_DET_F, |
| 863 | .flags = IORESOURCE_IRQ, |
| 864 | }, |
| 865 | { |
| 866 | .name = "VBUS_DET_R", |
| 867 | .start = AB8500_INT_VBUS_DET_R, |
| 868 | .end = AB8500_INT_VBUS_DET_R, |
| 869 | .flags = IORESOURCE_IRQ, |
| 870 | }, |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 871 | { |
| 872 | .name = "USB_LINK_STATUS", |
| 873 | .start = AB8500_INT_USB_LINK_STATUS, |
| 874 | .end = AB8500_INT_USB_LINK_STATUS, |
| 875 | .flags = IORESOURCE_IRQ, |
| 876 | }, |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 877 | { |
| 878 | .name = "USB_ADP_PROBE_PLUG", |
| 879 | .start = AB8500_INT_ADP_PROBE_PLUG, |
| 880 | .end = AB8500_INT_ADP_PROBE_PLUG, |
| 881 | .flags = IORESOURCE_IRQ, |
| 882 | }, |
| 883 | { |
| 884 | .name = "USB_ADP_PROBE_UNPLUG", |
| 885 | .start = AB8500_INT_ADP_PROBE_UNPLUG, |
| 886 | .end = AB8500_INT_ADP_PROBE_UNPLUG, |
| 887 | .flags = IORESOURCE_IRQ, |
| 888 | }, |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 889 | }; |
| 890 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 891 | static struct resource ab8505_iddet_resources[] = { |
Virupax Sadashivpetimath | 44f72e5 | 2012-04-17 09:30:14 +0200 | [diff] [blame] | 892 | { |
| 893 | .name = "KeyDeglitch", |
| 894 | .start = AB8505_INT_KEYDEGLITCH, |
| 895 | .end = AB8505_INT_KEYDEGLITCH, |
| 896 | .flags = IORESOURCE_IRQ, |
| 897 | }, |
| 898 | { |
| 899 | .name = "KP", |
| 900 | .start = AB8505_INT_KP, |
| 901 | .end = AB8505_INT_KP, |
| 902 | .flags = IORESOURCE_IRQ, |
| 903 | }, |
| 904 | { |
| 905 | .name = "IKP", |
| 906 | .start = AB8505_INT_IKP, |
| 907 | .end = AB8505_INT_IKP, |
| 908 | .flags = IORESOURCE_IRQ, |
| 909 | }, |
| 910 | { |
| 911 | .name = "IKR", |
| 912 | .start = AB8505_INT_IKR, |
| 913 | .end = AB8505_INT_IKR, |
| 914 | .flags = IORESOURCE_IRQ, |
| 915 | }, |
| 916 | { |
| 917 | .name = "KeyStuck", |
| 918 | .start = AB8505_INT_KEYSTUCK, |
| 919 | .end = AB8505_INT_KEYSTUCK, |
| 920 | .flags = IORESOURCE_IRQ, |
| 921 | }, |
| 922 | }; |
| 923 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 924 | static struct resource ab8500_temp_resources[] = { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 925 | { |
| 926 | .name = "AB8500_TEMP_WARM", |
| 927 | .start = AB8500_INT_TEMP_WARM, |
| 928 | .end = AB8500_INT_TEMP_WARM, |
| 929 | .flags = IORESOURCE_IRQ, |
| 930 | }, |
| 931 | }; |
| 932 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 933 | static struct mfd_cell abx500_common_devs[] = { |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 934 | #ifdef CONFIG_DEBUG_FS |
| 935 | { |
| 936 | .name = "ab8500-debug", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 937 | .of_compatible = "stericsson,ab8500-debug", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 938 | .num_resources = ARRAY_SIZE(ab8500_debug_resources), |
| 939 | .resources = ab8500_debug_resources, |
Mattias Wallin | 5814fc3 | 2010-09-13 16:05:04 +0200 | [diff] [blame] | 940 | }, |
| 941 | #endif |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 942 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 943 | .name = "ab8500-sysctrl", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 944 | .of_compatible = "stericsson,ab8500-sysctrl", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 945 | }, |
| 946 | { |
| 947 | .name = "ab8500-regulator", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 948 | .of_compatible = "stericsson,ab8500-regulator", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 949 | }, |
| 950 | { |
Ulf Hansson | 916a871c | 2012-11-22 11:35:40 +0100 | [diff] [blame] | 951 | .name = "abx500-clk", |
| 952 | .of_compatible = "stericsson,abx500-clk", |
| 953 | }, |
| 954 | { |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 955 | .name = "ab8500-gpadc", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 956 | .of_compatible = "stericsson,ab8500-gpadc", |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 957 | .num_resources = ARRAY_SIZE(ab8500_gpadc_resources), |
| 958 | .resources = ab8500_gpadc_resources, |
| 959 | }, |
| 960 | { |
| 961 | .name = "ab8500-rtc", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 962 | .of_compatible = "stericsson,ab8500-rtc", |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 963 | .num_resources = ARRAY_SIZE(ab8500_rtc_resources), |
| 964 | .resources = ab8500_rtc_resources, |
| 965 | }, |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 966 | { |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 967 | .name = "ab8500-acc-det", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 968 | .of_compatible = "stericsson,ab8500-acc-det", |
Linus Walleij | 6af75ec | 2011-06-09 23:57:45 +0200 | [diff] [blame] | 969 | .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources), |
| 970 | .resources = ab8500_av_acc_detect_resources, |
| 971 | }, |
| 972 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 973 | .name = "ab8500-poweron-key", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 974 | .of_compatible = "stericsson,ab8500-poweron-key", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 975 | .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources), |
| 976 | .resources = ab8500_poweronkey_db_resources, |
| 977 | }, |
| 978 | { |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 979 | .name = "ab8500-pwm", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 980 | .of_compatible = "stericsson,ab8500-pwm", |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 981 | .id = 1, |
| 982 | }, |
| 983 | { |
| 984 | .name = "ab8500-pwm", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 985 | .of_compatible = "stericsson,ab8500-pwm", |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 986 | .id = 2, |
| 987 | }, |
| 988 | { |
| 989 | .name = "ab8500-pwm", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 990 | .of_compatible = "stericsson,ab8500-pwm", |
Arun Murthy | f0f05b1 | 2010-09-06 12:24:52 +0530 | [diff] [blame] | 991 | .id = 3, |
| 992 | }, |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 993 | { |
| 994 | .name = "ab8500-leds", |
| 995 | .of_compatible = "stericsson,ab8500-leds", |
| 996 | }, |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 997 | { |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 998 | .name = "ab8500-denc", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 999 | .of_compatible = "stericsson,ab8500-denc", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 1000 | }, |
| 1001 | { |
| 1002 | .name = "ab8500-temp", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1003 | .of_compatible = "stericsson,ab8500-temp", |
Mattias Wallin | e098aded7 | 2010-12-02 15:40:31 +0100 | [diff] [blame] | 1004 | .num_resources = ARRAY_SIZE(ab8500_temp_resources), |
| 1005 | .resources = ab8500_temp_resources, |
Sundar R Iyer | 7768651 | 2010-09-05 12:18:47 -0700 | [diff] [blame] | 1006 | }, |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1007 | }; |
| 1008 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 1009 | static struct mfd_cell ab8500_bm_devs[] = { |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1010 | { |
| 1011 | .name = "ab8500-charger", |
Rajanikanth H.V | 4aef72d | 2012-11-18 19:17:47 -0800 | [diff] [blame] | 1012 | .of_compatible = "stericsson,ab8500-charger", |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1013 | .num_resources = ARRAY_SIZE(ab8500_charger_resources), |
| 1014 | .resources = ab8500_charger_resources, |
Rajanikanth H.V | 4aef72d | 2012-11-18 19:17:47 -0800 | [diff] [blame] | 1015 | #ifndef CONFIG_OF |
| 1016 | .platform_data = &ab8500_bm_data, |
| 1017 | .pdata_size = sizeof(ab8500_bm_data), |
| 1018 | #endif |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1019 | }, |
| 1020 | { |
| 1021 | .name = "ab8500-btemp", |
Rajanikanth H.V | bd9e8ab | 2012-11-18 19:16:58 -0800 | [diff] [blame] | 1022 | .of_compatible = "stericsson,ab8500-btemp", |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1023 | .num_resources = ARRAY_SIZE(ab8500_btemp_resources), |
| 1024 | .resources = ab8500_btemp_resources, |
Rajanikanth H.V | bd9e8ab | 2012-11-18 19:16:58 -0800 | [diff] [blame] | 1025 | #ifndef CONFIG_OF |
| 1026 | .platform_data = &ab8500_bm_data, |
| 1027 | .pdata_size = sizeof(ab8500_bm_data), |
| 1028 | #endif |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1029 | }, |
| 1030 | { |
| 1031 | .name = "ab8500-fg", |
Rajanikanth H.V | e0f1abe | 2012-11-18 18:45:41 -0800 | [diff] [blame] | 1032 | .of_compatible = "stericsson,ab8500-fg", |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1033 | .num_resources = ARRAY_SIZE(ab8500_fg_resources), |
| 1034 | .resources = ab8500_fg_resources, |
Rajanikanth H.V | e0f1abe | 2012-11-18 18:45:41 -0800 | [diff] [blame] | 1035 | #ifndef CONFIG_OF |
| 1036 | .platform_data = &ab8500_bm_data, |
| 1037 | .pdata_size = sizeof(ab8500_bm_data), |
| 1038 | #endif |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1039 | }, |
| 1040 | { |
| 1041 | .name = "ab8500-chargalg", |
Rajanikanth H.V | a12810a | 2012-10-31 15:40:33 +0000 | [diff] [blame] | 1042 | .of_compatible = "stericsson,ab8500-chargalg", |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1043 | .num_resources = ARRAY_SIZE(ab8500_chargalg_resources), |
| 1044 | .resources = ab8500_chargalg_resources, |
Rajanikanth H.V | a12810a | 2012-10-31 15:40:33 +0000 | [diff] [blame] | 1045 | #ifndef CONFIG_OF |
| 1046 | .platform_data = &ab8500_bm_data, |
| 1047 | .pdata_size = sizeof(ab8500_bm_data), |
| 1048 | #endif |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1049 | }, |
| 1050 | }; |
| 1051 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 1052 | static struct mfd_cell ab8500_devs[] = { |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1053 | { |
| 1054 | .name = "ab8500-gpio", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1055 | .of_compatible = "stericsson,ab8500-gpio", |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1056 | }, |
| 1057 | { |
| 1058 | .name = "ab8500-usb", |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1059 | .of_compatible = "stericsson,ab8500-usb", |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1060 | .num_resources = ARRAY_SIZE(ab8500_usb_resources), |
| 1061 | .resources = ab8500_usb_resources, |
| 1062 | }, |
Virupax Sadashivpetimath | 44f72e5 | 2012-04-17 09:30:14 +0200 | [diff] [blame] | 1063 | { |
| 1064 | .name = "ab8500-codec", |
Lee Jones | 81a21cd | 2012-07-27 13:38:51 +0100 | [diff] [blame] | 1065 | .of_compatible = "stericsson,ab8500-codec", |
Virupax Sadashivpetimath | 44f72e5 | 2012-04-17 09:30:14 +0200 | [diff] [blame] | 1066 | }, |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1067 | }; |
| 1068 | |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 1069 | static struct mfd_cell ab9540_devs[] = { |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1070 | { |
| 1071 | .name = "ab8500-gpio", |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1072 | }, |
| 1073 | { |
| 1074 | .name = "ab9540-usb", |
| 1075 | .num_resources = ARRAY_SIZE(ab8500_usb_resources), |
| 1076 | .resources = ab8500_usb_resources, |
| 1077 | }, |
Virupax Sadashivpetimath | 44f72e5 | 2012-04-17 09:30:14 +0200 | [diff] [blame] | 1078 | { |
| 1079 | .name = "ab9540-codec", |
| 1080 | }, |
| 1081 | }; |
| 1082 | |
| 1083 | /* Device list common to ab9540 and ab8505 */ |
Bill Pemberton | a9e9ce4 | 2012-11-19 13:24:21 -0500 | [diff] [blame] | 1084 | static struct mfd_cell ab9540_ab8505_devs[] = { |
Virupax Sadashivpetimath | 44f72e5 | 2012-04-17 09:30:14 +0200 | [diff] [blame] | 1085 | { |
| 1086 | .name = "ab-iddet", |
| 1087 | .num_resources = ARRAY_SIZE(ab8505_iddet_resources), |
| 1088 | .resources = ab8505_iddet_resources, |
| 1089 | }, |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1090 | }; |
| 1091 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1092 | static ssize_t show_chip_id(struct device *dev, |
| 1093 | struct device_attribute *attr, char *buf) |
| 1094 | { |
| 1095 | struct ab8500 *ab8500; |
| 1096 | |
| 1097 | ab8500 = dev_get_drvdata(dev); |
| 1098 | return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL); |
| 1099 | } |
| 1100 | |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1101 | /* |
| 1102 | * ab8500 has switched off due to (SWITCH_OFF_STATUS): |
| 1103 | * 0x01 Swoff bit programming |
| 1104 | * 0x02 Thermal protection activation |
| 1105 | * 0x04 Vbat lower then BattOk falling threshold |
| 1106 | * 0x08 Watchdog expired |
| 1107 | * 0x10 Non presence of 32kHz clock |
| 1108 | * 0x20 Battery level lower than power on reset threshold |
| 1109 | * 0x40 Power on key 1 pressed longer than 10 seconds |
| 1110 | * 0x80 DB8500 thermal shutdown |
| 1111 | */ |
| 1112 | static ssize_t show_switch_off_status(struct device *dev, |
| 1113 | struct device_attribute *attr, char *buf) |
| 1114 | { |
| 1115 | int ret; |
| 1116 | u8 value; |
| 1117 | struct ab8500 *ab8500; |
| 1118 | |
| 1119 | ab8500 = dev_get_drvdata(dev); |
| 1120 | ret = get_register_interruptible(ab8500, AB8500_RTC, |
| 1121 | AB8500_SWITCH_OFF_STATUS, &value); |
| 1122 | if (ret < 0) |
| 1123 | return ret; |
| 1124 | return sprintf(buf, "%#x\n", value); |
| 1125 | } |
| 1126 | |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 1127 | /* |
| 1128 | * ab8500 has turned on due to (TURN_ON_STATUS): |
| 1129 | * 0x01 PORnVbat |
| 1130 | * 0x02 PonKey1dbF |
| 1131 | * 0x04 PonKey2dbF |
| 1132 | * 0x08 RTCAlarm |
| 1133 | * 0x10 MainChDet |
| 1134 | * 0x20 VbusDet |
| 1135 | * 0x40 UsbIDDetect |
| 1136 | * 0x80 Reserved |
| 1137 | */ |
| 1138 | static ssize_t show_turn_on_status(struct device *dev, |
| 1139 | struct device_attribute *attr, char *buf) |
| 1140 | { |
| 1141 | int ret; |
| 1142 | u8 value; |
| 1143 | struct ab8500 *ab8500; |
| 1144 | |
| 1145 | ab8500 = dev_get_drvdata(dev); |
| 1146 | ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK, |
| 1147 | AB8500_TURN_ON_STATUS, &value); |
| 1148 | if (ret < 0) |
| 1149 | return ret; |
| 1150 | return sprintf(buf, "%#x\n", value); |
| 1151 | } |
| 1152 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1153 | static ssize_t show_ab9540_dbbrstn(struct device *dev, |
| 1154 | struct device_attribute *attr, char *buf) |
| 1155 | { |
| 1156 | struct ab8500 *ab8500; |
| 1157 | int ret; |
| 1158 | u8 value; |
| 1159 | |
| 1160 | ab8500 = dev_get_drvdata(dev); |
| 1161 | |
| 1162 | ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2, |
| 1163 | AB9540_MODEM_CTRL2_REG, &value); |
| 1164 | if (ret < 0) |
| 1165 | return ret; |
| 1166 | |
| 1167 | return sprintf(buf, "%d\n", |
| 1168 | (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0); |
| 1169 | } |
| 1170 | |
| 1171 | static ssize_t store_ab9540_dbbrstn(struct device *dev, |
| 1172 | struct device_attribute *attr, const char *buf, size_t count) |
| 1173 | { |
| 1174 | struct ab8500 *ab8500; |
| 1175 | int ret = count; |
| 1176 | int err; |
| 1177 | u8 bitvalues; |
| 1178 | |
| 1179 | ab8500 = dev_get_drvdata(dev); |
| 1180 | |
| 1181 | if (count > 0) { |
| 1182 | switch (buf[0]) { |
| 1183 | case '0': |
| 1184 | bitvalues = 0; |
| 1185 | break; |
| 1186 | case '1': |
| 1187 | bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT; |
| 1188 | break; |
| 1189 | default: |
| 1190 | goto exit; |
| 1191 | } |
| 1192 | |
| 1193 | err = mask_and_set_register_interruptible(ab8500, |
| 1194 | AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG, |
| 1195 | AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues); |
| 1196 | if (err) |
| 1197 | dev_info(ab8500->dev, |
| 1198 | "Failed to set DBBRSTN %c, err %#x\n", |
| 1199 | buf[0], err); |
| 1200 | } |
| 1201 | |
| 1202 | exit: |
| 1203 | return ret; |
| 1204 | } |
| 1205 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1206 | static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL); |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1207 | 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] | 1208 | 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] | 1209 | static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR, |
| 1210 | show_ab9540_dbbrstn, store_ab9540_dbbrstn); |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1211 | |
| 1212 | static struct attribute *ab8500_sysfs_entries[] = { |
| 1213 | &dev_attr_chip_id.attr, |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1214 | &dev_attr_switch_off_status.attr, |
Andrew Lynn | b4a3103 | 2011-10-11 10:49:47 +0200 | [diff] [blame] | 1215 | &dev_attr_turn_on_status.attr, |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1216 | NULL, |
| 1217 | }; |
| 1218 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1219 | static struct attribute *ab9540_sysfs_entries[] = { |
| 1220 | &dev_attr_chip_id.attr, |
| 1221 | &dev_attr_switch_off_status.attr, |
| 1222 | &dev_attr_turn_on_status.attr, |
| 1223 | &dev_attr_dbbrstn.attr, |
| 1224 | NULL, |
| 1225 | }; |
| 1226 | |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1227 | static struct attribute_group ab8500_attr_group = { |
| 1228 | .attrs = ab8500_sysfs_entries, |
| 1229 | }; |
| 1230 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1231 | static struct attribute_group ab9540_attr_group = { |
| 1232 | .attrs = ab9540_sysfs_entries, |
| 1233 | }; |
| 1234 | |
Bill Pemberton | f791be4 | 2012-11-19 13:23:04 -0500 | [diff] [blame] | 1235 | static int ab8500_probe(struct platform_device *pdev) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1236 | { |
Jonas Aaberg | b04c530c | 2012-06-29 17:46:12 +0200 | [diff] [blame] | 1237 | static char *switch_off_status[] = { |
| 1238 | "Swoff bit programming", |
| 1239 | "Thermal protection activation", |
| 1240 | "Vbat lower then BattOk falling threshold", |
| 1241 | "Watchdog expired", |
| 1242 | "Non presence of 32kHz clock", |
| 1243 | "Battery level lower than power on reset threshold", |
| 1244 | "Power on key 1 pressed longer than 10 seconds", |
| 1245 | "DB8500 thermal shutdown"}; |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1246 | struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev); |
| 1247 | const struct platform_device_id *platid = platform_get_device_id(pdev); |
Lee Jones | 6bc4a56 | 2012-05-17 14:45:13 +0100 | [diff] [blame] | 1248 | enum ab8500_version version = AB8500_VERSION_UNDEFINED; |
| 1249 | struct device_node *np = pdev->dev.of_node; |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1250 | struct ab8500 *ab8500; |
| 1251 | struct resource *resource; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1252 | int ret; |
| 1253 | int i; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1254 | u8 value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1255 | |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1256 | ab8500 = devm_kzalloc(&pdev->dev, sizeof *ab8500, GFP_KERNEL); |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1257 | if (!ab8500) |
| 1258 | return -ENOMEM; |
| 1259 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1260 | if (plat) |
| 1261 | ab8500->irq_base = plat->irq_base; |
| 1262 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1263 | ab8500->dev = &pdev->dev; |
| 1264 | |
| 1265 | resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1266 | if (!resource) |
| 1267 | return -ENODEV; |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1268 | |
| 1269 | ab8500->irq = resource->start; |
| 1270 | |
Lee Jones | 822672a | 2012-06-20 13:56:38 +0100 | [diff] [blame] | 1271 | ab8500->read = ab8500_prcmu_read; |
| 1272 | ab8500->write = ab8500_prcmu_write; |
| 1273 | ab8500->write_masked = ab8500_prcmu_write_masked; |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1274 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1275 | mutex_init(&ab8500->lock); |
| 1276 | mutex_init(&ab8500->irq_lock); |
Jonas Aaberg | 112a80d | 2012-04-17 09:30:33 +0200 | [diff] [blame] | 1277 | atomic_set(&ab8500->transfer_ongoing, 0); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1278 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1279 | platform_set_drvdata(pdev, ab8500); |
| 1280 | |
Lee Jones | 6bc4a56 | 2012-05-17 14:45:13 +0100 | [diff] [blame] | 1281 | if (platid) |
| 1282 | version = platid->driver_data; |
Lee Jones | 6bc4a56 | 2012-05-17 14:45:13 +0100 | [diff] [blame] | 1283 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1284 | if (version != AB8500_VERSION_UNDEFINED) |
| 1285 | ab8500->version = version; |
| 1286 | else { |
| 1287 | ret = get_register_interruptible(ab8500, AB8500_MISC, |
| 1288 | AB8500_IC_NAME_REG, &value); |
| 1289 | if (ret < 0) |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1290 | return ret; |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1291 | |
| 1292 | ab8500->version = value; |
| 1293 | } |
| 1294 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1295 | ret = get_register_interruptible(ab8500, AB8500_MISC, |
| 1296 | AB8500_REV_REG, &value); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1297 | if (ret < 0) |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1298 | return ret; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1299 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1300 | ab8500->chip_id = value; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1301 | |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1302 | dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n", |
| 1303 | ab8500_version_str[ab8500->version], |
| 1304 | ab8500->chip_id >> 4, |
| 1305 | ab8500->chip_id & 0x0F); |
| 1306 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1307 | /* Configure AB8500 or AB9540 IRQ */ |
Bengt Jonsson | a982362 | 2012-03-08 14:01:57 +0100 | [diff] [blame] | 1308 | if (is_ab9540(ab8500) || is_ab8505(ab8500)) { |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1309 | ab8500->mask_size = AB9540_NUM_IRQ_REGS; |
| 1310 | ab8500->irq_reg_offset = ab9540_irq_regoffset; |
| 1311 | } else { |
| 1312 | ab8500->mask_size = AB8500_NUM_IRQ_REGS; |
| 1313 | ab8500->irq_reg_offset = ab8500_irq_regoffset; |
| 1314 | } |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1315 | ab8500->mask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL); |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1316 | if (!ab8500->mask) |
| 1317 | return -ENOMEM; |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1318 | ab8500->oldmask = devm_kzalloc(&pdev->dev, ab8500->mask_size, GFP_KERNEL); |
| 1319 | if (!ab8500->oldmask) |
| 1320 | return -ENOMEM; |
| 1321 | |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1322 | /* |
| 1323 | * ab8500 has switched off due to (SWITCH_OFF_STATUS): |
| 1324 | * 0x01 Swoff bit programming |
| 1325 | * 0x02 Thermal protection activation |
| 1326 | * 0x04 Vbat lower then BattOk falling threshold |
| 1327 | * 0x08 Watchdog expired |
| 1328 | * 0x10 Non presence of 32kHz clock |
| 1329 | * 0x20 Battery level lower than power on reset threshold |
| 1330 | * 0x40 Power on key 1 pressed longer than 10 seconds |
| 1331 | * 0x80 DB8500 thermal shutdown |
| 1332 | */ |
| 1333 | |
| 1334 | ret = get_register_interruptible(ab8500, AB8500_RTC, |
| 1335 | AB8500_SWITCH_OFF_STATUS, &value); |
| 1336 | if (ret < 0) |
| 1337 | return ret; |
Jonas Aaberg | b04c530c | 2012-06-29 17:46:12 +0200 | [diff] [blame] | 1338 | dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value); |
| 1339 | |
| 1340 | if (value) { |
| 1341 | for (i = 0; i < ARRAY_SIZE(switch_off_status); i++) { |
| 1342 | if (value & 1) |
| 1343 | printk(KERN_CONT " \"%s\"", |
| 1344 | switch_off_status[i]); |
| 1345 | value = value >> 1; |
| 1346 | |
| 1347 | } |
| 1348 | printk(KERN_CONT "\n"); |
| 1349 | } else { |
| 1350 | printk(KERN_CONT " None\n"); |
| 1351 | } |
Mattias Wallin | e5c238c | 2011-03-02 11:52:36 +0100 | [diff] [blame] | 1352 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1353 | if (plat && plat->init) |
| 1354 | plat->init(ab8500); |
| 1355 | |
| 1356 | /* Clear and mask all interrupts */ |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1357 | for (i = 0; i < ab8500->mask_size; i++) { |
Linus Walleij | 0f620837 | 2012-02-20 21:42:10 +0100 | [diff] [blame] | 1358 | /* |
| 1359 | * Interrupt register 12 doesn't exist prior to AB8500 version |
| 1360 | * 2.0 |
| 1361 | */ |
| 1362 | if (ab8500->irq_reg_offset[i] == 11 && |
| 1363 | is_ab8500_1p1_or_earlier(ab8500)) |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 1364 | continue; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1365 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1366 | get_register_interruptible(ab8500, AB8500_INTERRUPT, |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1367 | AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i], |
Mattias Wallin | 92d50a4 | 2010-12-07 11:20:47 +0100 | [diff] [blame] | 1368 | &value); |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1369 | set_register_interruptible(ab8500, AB8500_INTERRUPT, |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1370 | AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1371 | } |
| 1372 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1373 | ret = abx500_register_ops(ab8500->dev, &ab8500_ops); |
| 1374 | if (ret) |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1375 | return ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 1376 | |
Linus Walleij | 2ced445 | 2012-02-20 21:42:17 +0100 | [diff] [blame] | 1377 | for (i = 0; i < ab8500->mask_size; i++) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1378 | ab8500->mask[i] = ab8500->oldmask[i] = 0xff; |
| 1379 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1380 | ret = ab8500_irq_init(ab8500, np); |
| 1381 | if (ret) |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1382 | return ret; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1383 | |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1384 | /* Activate this feature only in ab9540 */ |
| 1385 | /* till tests are done on ab8500 1p2 or later*/ |
| 1386 | if (is_ab9540(ab8500)) { |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1387 | ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, |
| 1388 | ab8500_hierarchical_irq, |
| 1389 | IRQF_ONESHOT | IRQF_NO_SUSPEND, |
| 1390 | "ab8500", ab8500); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1391 | } |
| 1392 | else { |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1393 | ret = devm_request_threaded_irq(&pdev->dev, ab8500->irq, NULL, |
| 1394 | ab8500_irq, |
| 1395 | IRQF_ONESHOT | IRQF_NO_SUSPEND, |
| 1396 | "ab8500", ab8500); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1397 | if (ret) |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1398 | return ret; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1399 | } |
| 1400 | |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1401 | ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs, |
| 1402 | ARRAY_SIZE(abx500_common_devs), NULL, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 1403 | ab8500->irq_base, ab8500->domain); |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1404 | if (ret) |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1405 | return ret; |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1406 | |
| 1407 | if (is_ab9540(ab8500)) |
| 1408 | ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs, |
| 1409 | ARRAY_SIZE(ab9540_devs), NULL, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 1410 | ab8500->irq_base, ab8500->domain); |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1411 | else |
| 1412 | ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs, |
| 1413 | ARRAY_SIZE(ab8500_devs), NULL, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 1414 | ab8500->irq_base, ab8500->domain); |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1415 | if (ret) |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1416 | return ret; |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1417 | |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1418 | if (is_ab9540(ab8500) || is_ab8505(ab8500)) |
| 1419 | ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs, |
| 1420 | ARRAY_SIZE(ab9540_ab8505_devs), NULL, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 1421 | ab8500->irq_base, ab8500->domain); |
Lee Jones | bad7699 | 2012-07-02 17:10:56 +0200 | [diff] [blame] | 1422 | if (ret) |
Lee Jones | 8c4203c | 2012-11-05 16:10:35 +0100 | [diff] [blame] | 1423 | return ret; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1424 | |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1425 | if (!no_bm) { |
| 1426 | /* Add battery management devices */ |
| 1427 | ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs, |
| 1428 | ARRAY_SIZE(ab8500_bm_devs), NULL, |
Mark Brown | 55692af | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 1429 | ab8500->irq_base, ab8500->domain); |
Rickard Andersson | 6ef9418 | 2012-04-17 09:30:57 +0200 | [diff] [blame] | 1430 | if (ret) |
| 1431 | dev_err(ab8500->dev, "error adding bm devices\n"); |
| 1432 | } |
| 1433 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1434 | if (is_ab9540(ab8500)) |
| 1435 | ret = sysfs_create_group(&ab8500->dev->kobj, |
| 1436 | &ab9540_attr_group); |
| 1437 | else |
| 1438 | ret = sysfs_create_group(&ab8500->dev->kobj, |
| 1439 | &ab8500_attr_group); |
Mattias Wallin | cca69b6 | 2010-12-02 15:09:36 +0100 | [diff] [blame] | 1440 | if (ret) |
| 1441 | dev_err(ab8500->dev, "error creating sysfs entries\n"); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1442 | |
| 1443 | return ret; |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1444 | } |
| 1445 | |
Bill Pemberton | 4740f73 | 2012-11-19 13:26:01 -0500 | [diff] [blame] | 1446 | static int ab8500_remove(struct platform_device *pdev) |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1447 | { |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1448 | struct ab8500 *ab8500 = platform_get_drvdata(pdev); |
| 1449 | |
Linus Walleij | d625552 | 2012-02-20 21:42:24 +0100 | [diff] [blame] | 1450 | if (is_ab9540(ab8500)) |
| 1451 | sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group); |
| 1452 | else |
| 1453 | sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group); |
Lee Jones | 06e589e | 2012-06-20 13:56:37 +0100 | [diff] [blame] | 1454 | |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1455 | mfd_remove_devices(ab8500->dev); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1456 | |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1460 | static const struct platform_device_id ab8500_id[] = { |
| 1461 | { "ab8500-core", AB8500_VERSION_AB8500 }, |
| 1462 | { "ab8505-i2c", AB8500_VERSION_AB8505 }, |
| 1463 | { "ab9540-i2c", AB8500_VERSION_AB9540 }, |
| 1464 | { "ab8540-i2c", AB8500_VERSION_AB8540 }, |
| 1465 | { } |
| 1466 | }; |
| 1467 | |
| 1468 | static struct platform_driver ab8500_core_driver = { |
| 1469 | .driver = { |
| 1470 | .name = "ab8500-core", |
| 1471 | .owner = THIS_MODULE, |
| 1472 | }, |
| 1473 | .probe = ab8500_probe, |
Bill Pemberton | 8444921 | 2012-11-19 13:20:24 -0500 | [diff] [blame] | 1474 | .remove = ab8500_remove, |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1475 | .id_table = ab8500_id, |
| 1476 | }; |
| 1477 | |
| 1478 | static int __init ab8500_core_init(void) |
| 1479 | { |
| 1480 | return platform_driver_register(&ab8500_core_driver); |
| 1481 | } |
| 1482 | |
| 1483 | static void __exit ab8500_core_exit(void) |
| 1484 | { |
| 1485 | platform_driver_unregister(&ab8500_core_driver); |
| 1486 | } |
Lee Jones | ba7cbc3 | 2012-06-11 16:25:00 +0100 | [diff] [blame] | 1487 | core_initcall(ab8500_core_init); |
Lee Jones | d28f1db | 2012-05-19 17:21:37 +0200 | [diff] [blame] | 1488 | module_exit(ab8500_core_exit); |
| 1489 | |
Mattias Wallin | adceed6 | 2011-03-02 11:51:11 +0100 | [diff] [blame] | 1490 | MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent"); |
Rabin Vincent | 6257926 | 2010-05-19 11:39:02 +0200 | [diff] [blame] | 1491 | MODULE_DESCRIPTION("AB8500 MFD core"); |
| 1492 | MODULE_LICENSE("GPL v2"); |