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