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