blob: 547fff4901ea87ea42d01b57b571b003cb764325 [file] [log] [blame]
Rabin Vincent62579262010-05-19 11:39:02 +02001/*
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 Wallinadceed62011-03-02 11:51:11 +01007 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
Rabin Vincent62579262010-05-19 11:39:02 +02008 */
9
10#include <linux/kernel.h>
11#include <linux/slab.h>
12#include <linux/init.h>
13#include <linux/irq.h>
Lee Jones06e589e2012-06-20 13:56:37 +010014#include <linux/irqdomain.h>
Rabin Vincent62579262010-05-19 11:39:02 +020015#include <linux/delay.h>
16#include <linux/interrupt.h>
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/mfd/core.h>
Mattias Wallin47c16972010-09-10 17:47:56 +020020#include <linux/mfd/abx500.h>
Linus Walleijee66e652011-12-02 14:16:33 +010021#include <linux/mfd/abx500/ab8500.h>
Lee Jonesd28f1db2012-05-19 17:21:37 +020022#include <linux/mfd/dbx500-prcmu.h>
Sundar R Iyer549931f2010-07-13 11:51:28 +053023#include <linux/regulator/ab8500.h>
Lee Jones6bc4a562012-05-17 14:45:13 +010024#include <linux/of.h>
25#include <linux/of_device.h>
Rabin Vincent62579262010-05-19 11:39:02 +020026
27/*
28 * Interrupt register offsets
29 * Bank : 0x0E
30 */
Mattias Wallin47c16972010-09-10 17:47:56 +020031#define AB8500_IT_SOURCE1_REG 0x00
32#define AB8500_IT_SOURCE2_REG 0x01
33#define AB8500_IT_SOURCE3_REG 0x02
34#define AB8500_IT_SOURCE4_REG 0x03
35#define AB8500_IT_SOURCE5_REG 0x04
36#define AB8500_IT_SOURCE6_REG 0x05
37#define AB8500_IT_SOURCE7_REG 0x06
38#define AB8500_IT_SOURCE8_REG 0x07
Linus Walleijd6255522012-02-20 21:42:24 +010039#define AB9540_IT_SOURCE13_REG 0x0C
Mattias Wallin47c16972010-09-10 17:47:56 +020040#define AB8500_IT_SOURCE19_REG 0x12
41#define AB8500_IT_SOURCE20_REG 0x13
42#define AB8500_IT_SOURCE21_REG 0x14
43#define AB8500_IT_SOURCE22_REG 0x15
44#define AB8500_IT_SOURCE23_REG 0x16
45#define AB8500_IT_SOURCE24_REG 0x17
Rabin Vincent62579262010-05-19 11:39:02 +020046
47/*
48 * latch registers
49 */
Mattias Wallin47c16972010-09-10 17:47:56 +020050#define AB8500_IT_LATCH1_REG 0x20
51#define AB8500_IT_LATCH2_REG 0x21
52#define AB8500_IT_LATCH3_REG 0x22
53#define AB8500_IT_LATCH4_REG 0x23
54#define AB8500_IT_LATCH5_REG 0x24
55#define AB8500_IT_LATCH6_REG 0x25
56#define AB8500_IT_LATCH7_REG 0x26
57#define AB8500_IT_LATCH8_REG 0x27
58#define AB8500_IT_LATCH9_REG 0x28
59#define AB8500_IT_LATCH10_REG 0x29
Mattias Wallin92d50a42010-12-07 11:20:47 +010060#define AB8500_IT_LATCH12_REG 0x2B
Linus Walleijd6255522012-02-20 21:42:24 +010061#define AB9540_IT_LATCH13_REG 0x2C
Mattias Wallin47c16972010-09-10 17:47:56 +020062#define AB8500_IT_LATCH19_REG 0x32
63#define AB8500_IT_LATCH20_REG 0x33
64#define AB8500_IT_LATCH21_REG 0x34
65#define AB8500_IT_LATCH22_REG 0x35
66#define AB8500_IT_LATCH23_REG 0x36
67#define AB8500_IT_LATCH24_REG 0x37
Rabin Vincent62579262010-05-19 11:39:02 +020068
69/*
70 * mask registers
71 */
72
Mattias Wallin47c16972010-09-10 17:47:56 +020073#define AB8500_IT_MASK1_REG 0x40
74#define AB8500_IT_MASK2_REG 0x41
75#define AB8500_IT_MASK3_REG 0x42
76#define AB8500_IT_MASK4_REG 0x43
77#define AB8500_IT_MASK5_REG 0x44
78#define AB8500_IT_MASK6_REG 0x45
79#define AB8500_IT_MASK7_REG 0x46
80#define AB8500_IT_MASK8_REG 0x47
81#define AB8500_IT_MASK9_REG 0x48
82#define AB8500_IT_MASK10_REG 0x49
83#define AB8500_IT_MASK11_REG 0x4A
84#define AB8500_IT_MASK12_REG 0x4B
85#define AB8500_IT_MASK13_REG 0x4C
86#define AB8500_IT_MASK14_REG 0x4D
87#define AB8500_IT_MASK15_REG 0x4E
88#define AB8500_IT_MASK16_REG 0x4F
89#define AB8500_IT_MASK17_REG 0x50
90#define AB8500_IT_MASK18_REG 0x51
91#define AB8500_IT_MASK19_REG 0x52
92#define AB8500_IT_MASK20_REG 0x53
93#define AB8500_IT_MASK21_REG 0x54
94#define AB8500_IT_MASK22_REG 0x55
95#define AB8500_IT_MASK23_REG 0x56
96#define AB8500_IT_MASK24_REG 0x57
Rabin Vincent62579262010-05-19 11:39:02 +020097
Michel JAOUEN7ccfe9b2012-05-07 15:02:03 +020098/*
99 * latch hierarchy registers
100 */
101#define AB8500_IT_LATCHHIER1_REG 0x60
102#define AB8500_IT_LATCHHIER2_REG 0x61
103#define AB8500_IT_LATCHHIER3_REG 0x62
104
105#define AB8500_IT_LATCHHIER_NUM 3
106
Mattias Wallin47c16972010-09-10 17:47:56 +0200107#define AB8500_REV_REG 0x80
Linus Walleij0f6208372012-02-20 21:42:10 +0100108#define AB8500_IC_NAME_REG 0x82
Mattias Walline5c238c2011-03-02 11:52:36 +0100109#define AB8500_SWITCH_OFF_STATUS 0x00
Rabin Vincent62579262010-05-19 11:39:02 +0200110
Andrew Lynnb4a31032011-10-11 10:49:47 +0200111#define AB8500_TURN_ON_STATUS 0x00
112
Rickard Andersson6ef94182012-04-17 09:30:57 +0200113static bool no_bm; /* No battery management */
114module_param(no_bm, bool, S_IRUGO);
115
Linus Walleijd6255522012-02-20 21:42:24 +0100116#define AB9540_MODEM_CTRL2_REG 0x23
117#define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT BIT(2)
118
Rabin Vincent62579262010-05-19 11:39:02 +0200119/*
120 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
Linus Walleij2ced4452012-02-20 21:42:17 +0100121 * numbers are indexed into this array with (num / 8). The interupts are
122 * defined in linux/mfd/ab8500.h
Rabin Vincent62579262010-05-19 11:39:02 +0200123 *
124 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
125 * offset 0.
126 */
Linus Walleij2ced4452012-02-20 21:42:17 +0100127/* AB8500 support */
Rabin Vincent62579262010-05-19 11:39:02 +0200128static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
Mattias Wallin92d50a42010-12-07 11:20:47 +0100129 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
Rabin Vincent62579262010-05-19 11:39:02 +0200130};
131
Linus Walleijd6255522012-02-20 21:42:24 +0100132/* AB9540 support */
133static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = {
134 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24,
135};
136
Linus Walleij0f6208372012-02-20 21:42:10 +0100137static const char ab8500_version_str[][7] = {
138 [AB8500_VERSION_AB8500] = "AB8500",
139 [AB8500_VERSION_AB8505] = "AB8505",
140 [AB8500_VERSION_AB9540] = "AB9540",
141 [AB8500_VERSION_AB8540] = "AB8540",
142};
143
Lee Jones822672a2012-06-20 13:56:38 +0100144static int ab8500_prcmu_write(struct ab8500 *ab8500, u16 addr, u8 data)
Lee Jonesd28f1db2012-05-19 17:21:37 +0200145{
146 int ret;
147
148 ret = prcmu_abb_write((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
149 if (ret < 0)
150 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
151 return ret;
152}
153
Lee Jones822672a2012-06-20 13:56:38 +0100154static int ab8500_prcmu_write_masked(struct ab8500 *ab8500, u16 addr, u8 mask,
Lee Jonesd28f1db2012-05-19 17:21:37 +0200155 u8 data)
156{
157 int ret;
158
159 ret = prcmu_abb_write_masked((u8)(addr >> 8), (u8)(addr & 0xFF), &data,
160 &mask, 1);
161 if (ret < 0)
162 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
163 return ret;
164}
165
Lee Jones822672a2012-06-20 13:56:38 +0100166static int ab8500_prcmu_read(struct ab8500 *ab8500, u16 addr)
Lee Jonesd28f1db2012-05-19 17:21:37 +0200167{
168 int ret;
169 u8 data;
170
171 ret = prcmu_abb_read((u8)(addr >> 8), (u8)(addr & 0xFF), &data, 1);
172 if (ret < 0) {
173 dev_err(ab8500->dev, "prcmu i2c error %d\n", ret);
174 return ret;
175 }
176 return (int)data;
177}
178
Mattias Wallin47c16972010-09-10 17:47:56 +0200179static int ab8500_get_chip_id(struct device *dev)
180{
Mattias Wallin6bce7bf2010-12-02 15:08:32 +0100181 struct ab8500 *ab8500;
182
183 if (!dev)
184 return -EINVAL;
185 ab8500 = dev_get_drvdata(dev->parent);
186 return ab8500 ? (int)ab8500->chip_id : -EINVAL;
Mattias Wallin47c16972010-09-10 17:47:56 +0200187}
188
189static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
190 u8 reg, u8 data)
Rabin Vincent62579262010-05-19 11:39:02 +0200191{
192 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200193 /*
194 * Put the u8 bank and u8 register together into a an u16.
195 * The bank on higher 8 bits and register in lower 8 bits.
196 * */
197 u16 addr = ((u16)bank) << 8 | reg;
Rabin Vincent62579262010-05-19 11:39:02 +0200198
199 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
200
Rabin Vincent392cbd12012-03-08 14:01:46 +0100201 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200202
203 ret = ab8500->write(ab8500, addr, data);
204 if (ret < 0)
205 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
206 addr, ret);
207 mutex_unlock(&ab8500->lock);
208
209 return ret;
210}
211
212static int ab8500_set_register(struct device *dev, u8 bank,
213 u8 reg, u8 value)
214{
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200215 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200216 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
217
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200218 atomic_inc(&ab8500->transfer_ongoing);
219 ret = set_register_interruptible(ab8500, bank, reg, value);
220 atomic_dec(&ab8500->transfer_ongoing);
221 return ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200222}
223
224static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
225 u8 reg, u8 *value)
226{
227 int ret;
228 /* put the u8 bank and u8 reg together into a an u16.
229 * bank on higher 8 bits and reg in lower */
230 u16 addr = ((u16)bank) << 8 | reg;
231
Rabin Vincent392cbd12012-03-08 14:01:46 +0100232 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200233
234 ret = ab8500->read(ab8500, addr);
235 if (ret < 0)
236 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
237 addr, ret);
238 else
239 *value = ret;
240
241 mutex_unlock(&ab8500->lock);
242 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
243
244 return ret;
245}
246
247static int ab8500_get_register(struct device *dev, u8 bank,
248 u8 reg, u8 *value)
249{
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200250 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200251 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
252
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200253 atomic_inc(&ab8500->transfer_ongoing);
254 ret = get_register_interruptible(ab8500, bank, reg, value);
255 atomic_dec(&ab8500->transfer_ongoing);
256 return ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200257}
258
259static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
260 u8 reg, u8 bitmask, u8 bitvalues)
261{
262 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200263 /* put the u8 bank and u8 reg together into a an u16.
264 * bank on higher 8 bits and reg in lower */
265 u16 addr = ((u16)bank) << 8 | reg;
266
Rabin Vincent392cbd12012-03-08 14:01:46 +0100267 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200268
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100269 if (ab8500->write_masked == NULL) {
270 u8 data;
271
272 ret = ab8500->read(ab8500, addr);
273 if (ret < 0) {
274 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
275 addr, ret);
276 goto out;
277 }
278
279 data = (u8)ret;
280 data = (~bitmask & data) | (bitmask & bitvalues);
281
282 ret = ab8500->write(ab8500, addr, data);
283 if (ret < 0)
284 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
285 addr, ret);
286
287 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr,
288 data);
Mattias Wallin47c16972010-09-10 17:47:56 +0200289 goto out;
290 }
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100291 ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues);
Rabin Vincent62579262010-05-19 11:39:02 +0200292 if (ret < 0)
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100293 dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr,
294 ret);
Rabin Vincent62579262010-05-19 11:39:02 +0200295out:
296 mutex_unlock(&ab8500->lock);
297 return ret;
298}
Mattias Wallin47c16972010-09-10 17:47:56 +0200299
300static int ab8500_mask_and_set_register(struct device *dev,
301 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
302{
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200303 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200304 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
305
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200306 atomic_inc(&ab8500->transfer_ongoing);
307 ret= mask_and_set_register_interruptible(ab8500, bank, reg,
308 bitmask, bitvalues);
309 atomic_dec(&ab8500->transfer_ongoing);
310 return ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200311}
312
313static struct abx500_ops ab8500_ops = {
314 .get_chip_id = ab8500_get_chip_id,
315 .get_register = ab8500_get_register,
316 .set_register = ab8500_set_register,
317 .get_register_page = NULL,
318 .set_register_page = NULL,
319 .mask_and_set_register = ab8500_mask_and_set_register,
320 .event_registers_startup_state_get = NULL,
321 .startup_irq_enabled = NULL,
322};
Rabin Vincent62579262010-05-19 11:39:02 +0200323
Mark Brown9505a0a2010-12-11 13:16:08 +0000324static void ab8500_irq_lock(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200325{
Mark Brown9505a0a2010-12-11 13:16:08 +0000326 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Rabin Vincent62579262010-05-19 11:39:02 +0200327
328 mutex_lock(&ab8500->irq_lock);
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200329 atomic_inc(&ab8500->transfer_ongoing);
Rabin Vincent62579262010-05-19 11:39:02 +0200330}
331
Mark Brown9505a0a2010-12-11 13:16:08 +0000332static void ab8500_irq_sync_unlock(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200333{
Mark Brown9505a0a2010-12-11 13:16:08 +0000334 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Rabin Vincent62579262010-05-19 11:39:02 +0200335 int i;
336
Linus Walleij2ced4452012-02-20 21:42:17 +0100337 for (i = 0; i < ab8500->mask_size; i++) {
Rabin Vincent62579262010-05-19 11:39:02 +0200338 u8 old = ab8500->oldmask[i];
339 u8 new = ab8500->mask[i];
340 int reg;
341
342 if (new == old)
343 continue;
344
Linus Walleij0f6208372012-02-20 21:42:10 +0100345 /*
346 * Interrupt register 12 doesn't exist prior to AB8500 version
347 * 2.0
348 */
349 if (ab8500->irq_reg_offset[i] == 11 &&
350 is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100351 continue;
352
Rabin Vincent62579262010-05-19 11:39:02 +0200353 ab8500->oldmask[i] = new;
354
Linus Walleij2ced4452012-02-20 21:42:17 +0100355 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
Mattias Wallin47c16972010-09-10 17:47:56 +0200356 set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
Rabin Vincent62579262010-05-19 11:39:02 +0200357 }
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200358 atomic_dec(&ab8500->transfer_ongoing);
Rabin Vincent62579262010-05-19 11:39:02 +0200359 mutex_unlock(&ab8500->irq_lock);
360}
361
Mark Brown9505a0a2010-12-11 13:16:08 +0000362static void ab8500_irq_mask(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200363{
Mark Brown9505a0a2010-12-11 13:16:08 +0000364 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Lee Jones06e589e2012-06-20 13:56:37 +0100365 int offset = data->hwirq;
Rabin Vincent62579262010-05-19 11:39:02 +0200366 int index = offset / 8;
367 int mask = 1 << (offset % 8);
368
369 ab8500->mask[index] |= mask;
370}
371
Mark Brown9505a0a2010-12-11 13:16:08 +0000372static void ab8500_irq_unmask(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200373{
Mark Brown9505a0a2010-12-11 13:16:08 +0000374 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Lee Jones06e589e2012-06-20 13:56:37 +0100375 int offset = data->hwirq;
Rabin Vincent62579262010-05-19 11:39:02 +0200376 int index = offset / 8;
377 int mask = 1 << (offset % 8);
378
379 ab8500->mask[index] &= ~mask;
380}
381
382static struct irq_chip ab8500_irq_chip = {
383 .name = "ab8500",
Mark Brown9505a0a2010-12-11 13:16:08 +0000384 .irq_bus_lock = ab8500_irq_lock,
385 .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
386 .irq_mask = ab8500_irq_mask,
Virupax Sadashivpetimathe6f93062011-10-11 10:49:17 +0200387 .irq_disable = ab8500_irq_mask,
Mark Brown9505a0a2010-12-11 13:16:08 +0000388 .irq_unmask = ab8500_irq_unmask,
Rabin Vincent62579262010-05-19 11:39:02 +0200389};
390
Michel JAOUEN7ccfe9b2012-05-07 15:02:03 +0200391static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500,
392 int latch_offset, u8 latch_val)
393{
394 int int_bit = __ffs(latch_val);
395 int line, i;
396
397 do {
398 int_bit = __ffs(latch_val);
399
400 for (i = 0; i < ab8500->mask_size; i++)
401 if (ab8500->irq_reg_offset[i] == latch_offset)
402 break;
403
404 if (i >= ab8500->mask_size) {
405 dev_err(ab8500->dev, "Register offset 0x%2x not declared\n",
406 latch_offset);
407 return -ENXIO;
408 }
409
410 line = (i << 3) + int_bit;
411 latch_val &= ~(1 << int_bit);
412
413 handle_nested_irq(ab8500->irq_base + line);
414 } while (latch_val);
415
416 return 0;
417}
418
419static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500,
420 int hier_offset, u8 hier_val)
421{
422 int latch_bit, status;
423 u8 latch_offset, latch_val;
424
425 do {
426 latch_bit = __ffs(hier_val);
427 latch_offset = (hier_offset << 3) + latch_bit;
428
429 /* Fix inconsistent ITFromLatch25 bit mapping... */
430 if (unlikely(latch_offset == 17))
431 latch_offset = 24;
432
433 status = get_register_interruptible(ab8500,
434 AB8500_INTERRUPT,
435 AB8500_IT_LATCH1_REG + latch_offset,
436 &latch_val);
437 if (status < 0 || latch_val == 0)
438 goto discard;
439
440 status = ab8500_handle_hierarchical_line(ab8500,
441 latch_offset, latch_val);
442 if (status < 0)
443 return status;
444discard:
445 hier_val &= ~(1 << latch_bit);
446 } while (hier_val);
447
448 return 0;
449}
450
451static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
452{
453 struct ab8500 *ab8500 = dev;
454 u8 i;
455
456 dev_vdbg(ab8500->dev, "interrupt\n");
457
458 /* Hierarchical interrupt version */
459 for (i = 0; i < AB8500_IT_LATCHHIER_NUM; i++) {
460 int status;
461 u8 hier_val;
462
463 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
464 AB8500_IT_LATCHHIER1_REG + i, &hier_val);
465 if (status < 0 || hier_val == 0)
466 continue;
467
468 status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val);
469 if (status < 0)
470 break;
471 }
472 return IRQ_HANDLED;
473}
474
Lee Jones80633f02012-08-20 11:53:36 +0100475/**
476 * ab8500_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ
477 *
478 * @ab8500: ab8500_irq controller to operate on.
479 * @irq: index of the interrupt requested in the chip IRQs
480 *
481 * Useful for drivers to request their own IRQs.
482 */
483static int ab8500_irq_get_virq(struct ab8500 *ab8500, int irq)
484{
485 if (!ab8500)
486 return -EINVAL;
487
488 return irq_create_mapping(ab8500->domain, irq);
489}
490
Rabin Vincent62579262010-05-19 11:39:02 +0200491static irqreturn_t ab8500_irq(int irq, void *dev)
492{
493 struct ab8500 *ab8500 = dev;
494 int i;
495
496 dev_vdbg(ab8500->dev, "interrupt\n");
497
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200498 atomic_inc(&ab8500->transfer_ongoing);
499
Linus Walleij2ced4452012-02-20 21:42:17 +0100500 for (i = 0; i < ab8500->mask_size; i++) {
501 int regoffset = ab8500->irq_reg_offset[i];
Rabin Vincent62579262010-05-19 11:39:02 +0200502 int status;
Mattias Wallin47c16972010-09-10 17:47:56 +0200503 u8 value;
Rabin Vincent62579262010-05-19 11:39:02 +0200504
Linus Walleij0f6208372012-02-20 21:42:10 +0100505 /*
506 * Interrupt register 12 doesn't exist prior to AB8500 version
507 * 2.0
508 */
509 if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100510 continue;
511
Mattias Wallin47c16972010-09-10 17:47:56 +0200512 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
513 AB8500_IT_LATCH1_REG + regoffset, &value);
514 if (status < 0 || value == 0)
Rabin Vincent62579262010-05-19 11:39:02 +0200515 continue;
516
517 do {
Mattias Wallin88aec4f2010-12-02 15:06:49 +0100518 int bit = __ffs(value);
Rabin Vincent62579262010-05-19 11:39:02 +0200519 int line = i * 8 + bit;
Lee Jones0a37fc52012-08-09 16:53:54 +0100520 int virq = ab8500_irq_get_virq(ab8500, line);
Rabin Vincent62579262010-05-19 11:39:02 +0200521
Lee Jones0a37fc52012-08-09 16:53:54 +0100522 handle_nested_irq(virq);
Mattias Wallin47c16972010-09-10 17:47:56 +0200523 value &= ~(1 << bit);
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200524
Mattias Wallin47c16972010-09-10 17:47:56 +0200525 } while (value);
Rabin Vincent62579262010-05-19 11:39:02 +0200526 }
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200527 atomic_dec(&ab8500->transfer_ongoing);
Rabin Vincent62579262010-05-19 11:39:02 +0200528 return IRQ_HANDLED;
529}
530
Lee Jones06e589e2012-06-20 13:56:37 +0100531static int ab8500_irq_map(struct irq_domain *d, unsigned int virq,
532 irq_hw_number_t hwirq)
533{
534 struct ab8500 *ab8500 = d->host_data;
535
536 if (!ab8500)
537 return -EINVAL;
538
539 irq_set_chip_data(virq, ab8500);
540 irq_set_chip_and_handler(virq, &ab8500_irq_chip,
541 handle_simple_irq);
542 irq_set_nested_thread(virq, 1);
Rabin Vincent62579262010-05-19 11:39:02 +0200543#ifdef CONFIG_ARM
Lee Jones06e589e2012-06-20 13:56:37 +0100544 set_irq_flags(virq, IRQF_VALID);
Rabin Vincent62579262010-05-19 11:39:02 +0200545#else
Lee Jones06e589e2012-06-20 13:56:37 +0100546 irq_set_noprobe(virq);
Rabin Vincent62579262010-05-19 11:39:02 +0200547#endif
Rabin Vincent62579262010-05-19 11:39:02 +0200548
549 return 0;
550}
551
Lee Jones06e589e2012-06-20 13:56:37 +0100552static struct irq_domain_ops ab8500_irq_ops = {
553 .map = ab8500_irq_map,
554 .xlate = irq_domain_xlate_twocell,
555};
556
557static int ab8500_irq_init(struct ab8500 *ab8500, struct device_node *np)
Rabin Vincent62579262010-05-19 11:39:02 +0200558{
Linus Walleij2ced4452012-02-20 21:42:17 +0100559 int num_irqs;
Rabin Vincent62579262010-05-19 11:39:02 +0200560
Linus Walleijd6255522012-02-20 21:42:24 +0100561 if (is_ab9540(ab8500))
562 num_irqs = AB9540_NR_IRQS;
Bengt Jonssona9823622012-03-08 14:01:57 +0100563 else if (is_ab8505(ab8500))
564 num_irqs = AB8505_NR_IRQS;
Linus Walleijd6255522012-02-20 21:42:24 +0100565 else
566 num_irqs = AB8500_NR_IRQS;
Linus Walleij2ced4452012-02-20 21:42:17 +0100567
Linus Walleijf1d11f32012-10-18 18:18:44 +0200568 /* If ->irq_base is zero this will give a linear mapping */
569 ab8500->domain = irq_domain_add_simple(NULL,
570 num_irqs, ab8500->irq_base,
571 &ab8500_irq_ops, ab8500);
Lee Jones06e589e2012-06-20 13:56:37 +0100572
573 if (!ab8500->domain) {
574 dev_err(ab8500->dev, "Failed to create irqdomain\n");
575 return -ENOSYS;
576 }
577
578 return 0;
Rabin Vincent62579262010-05-19 11:39:02 +0200579}
580
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200581int ab8500_suspend(struct ab8500 *ab8500)
582{
583 if (atomic_read(&ab8500->transfer_ongoing))
584 return -EINVAL;
585 else
586 return 0;
587}
588
Linus Walleijd6255522012-02-20 21:42:24 +0100589/* AB8500 GPIO Resources */
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200590static struct resource __devinitdata ab8500_gpio_resources[] = {
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530591 {
592 .name = "GPIO_INT6",
593 .start = AB8500_INT_GPIO6R,
594 .end = AB8500_INT_GPIO41F,
595 .flags = IORESOURCE_IRQ,
596 }
597};
598
Linus Walleijd6255522012-02-20 21:42:24 +0100599/* AB9540 GPIO Resources */
600static struct resource __devinitdata ab9540_gpio_resources[] = {
601 {
602 .name = "GPIO_INT6",
603 .start = AB8500_INT_GPIO6R,
604 .end = AB8500_INT_GPIO41F,
605 .flags = IORESOURCE_IRQ,
606 },
607 {
608 .name = "GPIO_INT14",
609 .start = AB9540_INT_GPIO50R,
610 .end = AB9540_INT_GPIO54R,
611 .flags = IORESOURCE_IRQ,
612 },
613 {
614 .name = "GPIO_INT15",
615 .start = AB9540_INT_GPIO50F,
616 .end = AB9540_INT_GPIO54F,
617 .flags = IORESOURCE_IRQ,
618 }
619};
620
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200621static struct resource __devinitdata ab8500_gpadc_resources[] = {
Rabin Vincent62579262010-05-19 11:39:02 +0200622 {
623 .name = "HW_CONV_END",
624 .start = AB8500_INT_GP_HW_ADC_CONV_END,
625 .end = AB8500_INT_GP_HW_ADC_CONV_END,
626 .flags = IORESOURCE_IRQ,
627 },
628 {
629 .name = "SW_CONV_END",
630 .start = AB8500_INT_GP_SW_ADC_CONV_END,
631 .end = AB8500_INT_GP_SW_ADC_CONV_END,
632 .flags = IORESOURCE_IRQ,
633 },
634};
635
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200636static struct resource __devinitdata ab8500_rtc_resources[] = {
Rabin Vincent62579262010-05-19 11:39:02 +0200637 {
638 .name = "60S",
639 .start = AB8500_INT_RTC_60S,
640 .end = AB8500_INT_RTC_60S,
641 .flags = IORESOURCE_IRQ,
642 },
643 {
644 .name = "ALARM",
645 .start = AB8500_INT_RTC_ALARM,
646 .end = AB8500_INT_RTC_ALARM,
647 .flags = IORESOURCE_IRQ,
648 },
649};
650
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200651static struct resource __devinitdata ab8500_poweronkey_db_resources[] = {
Sundar R Iyer77686512010-09-05 12:18:47 -0700652 {
653 .name = "ONKEY_DBF",
654 .start = AB8500_INT_PON_KEY1DB_F,
655 .end = AB8500_INT_PON_KEY1DB_F,
656 .flags = IORESOURCE_IRQ,
657 },
658 {
659 .name = "ONKEY_DBR",
660 .start = AB8500_INT_PON_KEY1DB_R,
661 .end = AB8500_INT_PON_KEY1DB_R,
662 .flags = IORESOURCE_IRQ,
663 },
664};
665
Linus Walleij6af75ec2011-06-09 23:57:45 +0200666static struct resource __devinitdata ab8500_av_acc_detect_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100667 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200668 .name = "ACC_DETECT_1DB_F",
669 .start = AB8500_INT_ACC_DETECT_1DB_F,
670 .end = AB8500_INT_ACC_DETECT_1DB_F,
671 .flags = IORESOURCE_IRQ,
Mattias Walline098aded72010-12-02 15:40:31 +0100672 },
673 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200674 .name = "ACC_DETECT_1DB_R",
675 .start = AB8500_INT_ACC_DETECT_1DB_R,
676 .end = AB8500_INT_ACC_DETECT_1DB_R,
677 .flags = IORESOURCE_IRQ,
Mattias Walline098aded72010-12-02 15:40:31 +0100678 },
679 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200680 .name = "ACC_DETECT_21DB_F",
681 .start = AB8500_INT_ACC_DETECT_21DB_F,
682 .end = AB8500_INT_ACC_DETECT_21DB_F,
683 .flags = IORESOURCE_IRQ,
684 },
685 {
686 .name = "ACC_DETECT_21DB_R",
687 .start = AB8500_INT_ACC_DETECT_21DB_R,
688 .end = AB8500_INT_ACC_DETECT_21DB_R,
689 .flags = IORESOURCE_IRQ,
690 },
691 {
692 .name = "ACC_DETECT_22DB_F",
693 .start = AB8500_INT_ACC_DETECT_22DB_F,
694 .end = AB8500_INT_ACC_DETECT_22DB_F,
695 .flags = IORESOURCE_IRQ,
696 },
697 {
698 .name = "ACC_DETECT_22DB_R",
699 .start = AB8500_INT_ACC_DETECT_22DB_R,
700 .end = AB8500_INT_ACC_DETECT_22DB_R,
701 .flags = IORESOURCE_IRQ,
702 },
703};
704
705static struct resource __devinitdata ab8500_charger_resources[] = {
706 {
Mattias Walline098aded72010-12-02 15:40:31 +0100707 .name = "MAIN_CH_UNPLUG_DET",
708 .start = AB8500_INT_MAIN_CH_UNPLUG_DET,
709 .end = AB8500_INT_MAIN_CH_UNPLUG_DET,
710 .flags = IORESOURCE_IRQ,
711 },
712 {
713 .name = "MAIN_CHARGE_PLUG_DET",
714 .start = AB8500_INT_MAIN_CH_PLUG_DET,
715 .end = AB8500_INT_MAIN_CH_PLUG_DET,
716 .flags = IORESOURCE_IRQ,
717 },
718 {
Mattias Walline098aded72010-12-02 15:40:31 +0100719 .name = "VBUS_DET_R",
720 .start = AB8500_INT_VBUS_DET_R,
721 .end = AB8500_INT_VBUS_DET_R,
722 .flags = IORESOURCE_IRQ,
723 },
724 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200725 .name = "VBUS_DET_F",
726 .start = AB8500_INT_VBUS_DET_F,
727 .end = AB8500_INT_VBUS_DET_F,
Mattias Walline098aded72010-12-02 15:40:31 +0100728 .flags = IORESOURCE_IRQ,
729 },
730 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200731 .name = "USB_LINK_STATUS",
732 .start = AB8500_INT_USB_LINK_STATUS,
733 .end = AB8500_INT_USB_LINK_STATUS,
734 .flags = IORESOURCE_IRQ,
735 },
736 {
Mattias Walline098aded72010-12-02 15:40:31 +0100737 .name = "VBUS_OVV",
738 .start = AB8500_INT_VBUS_OVV,
739 .end = AB8500_INT_VBUS_OVV,
740 .flags = IORESOURCE_IRQ,
741 },
742 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200743 .name = "USB_CH_TH_PROT_R",
744 .start = AB8500_INT_USB_CH_TH_PROT_R,
745 .end = AB8500_INT_USB_CH_TH_PROT_R,
Mattias Walline098aded72010-12-02 15:40:31 +0100746 .flags = IORESOURCE_IRQ,
747 },
748 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200749 .name = "USB_CH_TH_PROT_F",
750 .start = AB8500_INT_USB_CH_TH_PROT_F,
751 .end = AB8500_INT_USB_CH_TH_PROT_F,
Mattias Walline098aded72010-12-02 15:40:31 +0100752 .flags = IORESOURCE_IRQ,
753 },
754 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200755 .name = "MAIN_EXT_CH_NOT_OK",
756 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
757 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
758 .flags = IORESOURCE_IRQ,
759 },
760 {
761 .name = "MAIN_CH_TH_PROT_R",
762 .start = AB8500_INT_MAIN_CH_TH_PROT_R,
763 .end = AB8500_INT_MAIN_CH_TH_PROT_R,
764 .flags = IORESOURCE_IRQ,
765 },
766 {
767 .name = "MAIN_CH_TH_PROT_F",
768 .start = AB8500_INT_MAIN_CH_TH_PROT_F,
769 .end = AB8500_INT_MAIN_CH_TH_PROT_F,
770 .flags = IORESOURCE_IRQ,
771 },
772 {
773 .name = "USB_CHARGER_NOT_OKR",
Bengt Jonssona9823622012-03-08 14:01:57 +0100774 .start = AB8500_INT_USB_CHARGER_NOT_OKR,
775 .end = AB8500_INT_USB_CHARGER_NOT_OKR,
Linus Walleij6af75ec2011-06-09 23:57:45 +0200776 .flags = IORESOURCE_IRQ,
777 },
778 {
779 .name = "CH_WD_EXP",
780 .start = AB8500_INT_CH_WD_EXP,
781 .end = AB8500_INT_CH_WD_EXP,
782 .flags = IORESOURCE_IRQ,
783 },
784};
785
786static struct resource __devinitdata ab8500_btemp_resources[] = {
787 {
788 .name = "BAT_CTRL_INDB",
789 .start = AB8500_INT_BAT_CTRL_INDB,
790 .end = AB8500_INT_BAT_CTRL_INDB,
Mattias Walline098aded72010-12-02 15:40:31 +0100791 .flags = IORESOURCE_IRQ,
792 },
793 {
794 .name = "BTEMP_LOW",
795 .start = AB8500_INT_BTEMP_LOW,
796 .end = AB8500_INT_BTEMP_LOW,
797 .flags = IORESOURCE_IRQ,
798 },
799 {
800 .name = "BTEMP_HIGH",
801 .start = AB8500_INT_BTEMP_HIGH,
802 .end = AB8500_INT_BTEMP_HIGH,
803 .flags = IORESOURCE_IRQ,
804 },
805 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200806 .name = "BTEMP_LOW_MEDIUM",
807 .start = AB8500_INT_BTEMP_LOW_MEDIUM,
808 .end = AB8500_INT_BTEMP_LOW_MEDIUM,
Mattias Walline098aded72010-12-02 15:40:31 +0100809 .flags = IORESOURCE_IRQ,
810 },
811 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200812 .name = "BTEMP_MEDIUM_HIGH",
813 .start = AB8500_INT_BTEMP_MEDIUM_HIGH,
814 .end = AB8500_INT_BTEMP_MEDIUM_HIGH,
Mattias Walline098aded72010-12-02 15:40:31 +0100815 .flags = IORESOURCE_IRQ,
816 },
817};
818
Linus Walleij6af75ec2011-06-09 23:57:45 +0200819static struct resource __devinitdata ab8500_fg_resources[] = {
820 {
821 .name = "NCONV_ACCU",
822 .start = AB8500_INT_CCN_CONV_ACC,
823 .end = AB8500_INT_CCN_CONV_ACC,
824 .flags = IORESOURCE_IRQ,
825 },
826 {
827 .name = "BATT_OVV",
828 .start = AB8500_INT_BATT_OVV,
829 .end = AB8500_INT_BATT_OVV,
830 .flags = IORESOURCE_IRQ,
831 },
832 {
833 .name = "LOW_BAT_F",
834 .start = AB8500_INT_LOW_BAT_F,
835 .end = AB8500_INT_LOW_BAT_F,
836 .flags = IORESOURCE_IRQ,
837 },
838 {
839 .name = "LOW_BAT_R",
840 .start = AB8500_INT_LOW_BAT_R,
841 .end = AB8500_INT_LOW_BAT_R,
842 .flags = IORESOURCE_IRQ,
843 },
844 {
845 .name = "CC_INT_CALIB",
846 .start = AB8500_INT_CC_INT_CALIB,
847 .end = AB8500_INT_CC_INT_CALIB,
848 .flags = IORESOURCE_IRQ,
849 },
Bengt Jonssona9823622012-03-08 14:01:57 +0100850 {
851 .name = "CCEOC",
852 .start = AB8500_INT_CCEOC,
853 .end = AB8500_INT_CCEOC,
854 .flags = IORESOURCE_IRQ,
855 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200856};
857
858static struct resource __devinitdata ab8500_chargalg_resources[] = {};
859
Axel Lindf720642011-11-10 09:56:18 +0800860#ifdef CONFIG_DEBUG_FS
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200861static struct resource __devinitdata ab8500_debug_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100862 {
863 .name = "IRQ_FIRST",
864 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
865 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
866 .flags = IORESOURCE_IRQ,
867 },
868 {
869 .name = "IRQ_LAST",
Bengt Jonssona9823622012-03-08 14:01:57 +0100870 .start = AB8500_INT_XTAL32K_KO,
871 .end = AB8500_INT_XTAL32K_KO,
Mattias Walline098aded72010-12-02 15:40:31 +0100872 .flags = IORESOURCE_IRQ,
873 },
874};
Axel Lindf720642011-11-10 09:56:18 +0800875#endif
Mattias Walline098aded72010-12-02 15:40:31 +0100876
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200877static struct resource __devinitdata ab8500_usb_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100878 {
879 .name = "ID_WAKEUP_R",
880 .start = AB8500_INT_ID_WAKEUP_R,
881 .end = AB8500_INT_ID_WAKEUP_R,
882 .flags = IORESOURCE_IRQ,
883 },
884 {
885 .name = "ID_WAKEUP_F",
886 .start = AB8500_INT_ID_WAKEUP_F,
887 .end = AB8500_INT_ID_WAKEUP_F,
888 .flags = IORESOURCE_IRQ,
889 },
890 {
891 .name = "VBUS_DET_F",
892 .start = AB8500_INT_VBUS_DET_F,
893 .end = AB8500_INT_VBUS_DET_F,
894 .flags = IORESOURCE_IRQ,
895 },
896 {
897 .name = "VBUS_DET_R",
898 .start = AB8500_INT_VBUS_DET_R,
899 .end = AB8500_INT_VBUS_DET_R,
900 .flags = IORESOURCE_IRQ,
901 },
Mattias Wallin92d50a42010-12-07 11:20:47 +0100902 {
903 .name = "USB_LINK_STATUS",
904 .start = AB8500_INT_USB_LINK_STATUS,
905 .end = AB8500_INT_USB_LINK_STATUS,
906 .flags = IORESOURCE_IRQ,
907 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200908 {
909 .name = "USB_ADP_PROBE_PLUG",
910 .start = AB8500_INT_ADP_PROBE_PLUG,
911 .end = AB8500_INT_ADP_PROBE_PLUG,
912 .flags = IORESOURCE_IRQ,
913 },
914 {
915 .name = "USB_ADP_PROBE_UNPLUG",
916 .start = AB8500_INT_ADP_PROBE_UNPLUG,
917 .end = AB8500_INT_ADP_PROBE_UNPLUG,
918 .flags = IORESOURCE_IRQ,
919 },
Mattias Walline098aded72010-12-02 15:40:31 +0100920};
921
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +0200922static struct resource __devinitdata ab8505_iddet_resources[] = {
923 {
924 .name = "KeyDeglitch",
925 .start = AB8505_INT_KEYDEGLITCH,
926 .end = AB8505_INT_KEYDEGLITCH,
927 .flags = IORESOURCE_IRQ,
928 },
929 {
930 .name = "KP",
931 .start = AB8505_INT_KP,
932 .end = AB8505_INT_KP,
933 .flags = IORESOURCE_IRQ,
934 },
935 {
936 .name = "IKP",
937 .start = AB8505_INT_IKP,
938 .end = AB8505_INT_IKP,
939 .flags = IORESOURCE_IRQ,
940 },
941 {
942 .name = "IKR",
943 .start = AB8505_INT_IKR,
944 .end = AB8505_INT_IKR,
945 .flags = IORESOURCE_IRQ,
946 },
947 {
948 .name = "KeyStuck",
949 .start = AB8505_INT_KEYSTUCK,
950 .end = AB8505_INT_KEYSTUCK,
951 .flags = IORESOURCE_IRQ,
952 },
953};
954
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200955static struct resource __devinitdata ab8500_temp_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100956 {
957 .name = "AB8500_TEMP_WARM",
958 .start = AB8500_INT_TEMP_WARM,
959 .end = AB8500_INT_TEMP_WARM,
960 .flags = IORESOURCE_IRQ,
961 },
962};
963
Linus Walleijd6255522012-02-20 21:42:24 +0100964static struct mfd_cell __devinitdata abx500_common_devs[] = {
Mattias Wallin5814fc32010-09-13 16:05:04 +0200965#ifdef CONFIG_DEBUG_FS
966 {
967 .name = "ab8500-debug",
Lee Jonesbad76992012-07-02 17:10:56 +0200968 .of_compatible = "stericsson,ab8500-debug",
Mattias Walline098aded72010-12-02 15:40:31 +0100969 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
970 .resources = ab8500_debug_resources,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200971 },
972#endif
Rabin Vincent62579262010-05-19 11:39:02 +0200973 {
Mattias Walline098aded72010-12-02 15:40:31 +0100974 .name = "ab8500-sysctrl",
Lee Jonesbad76992012-07-02 17:10:56 +0200975 .of_compatible = "stericsson,ab8500-sysctrl",
Mattias Walline098aded72010-12-02 15:40:31 +0100976 },
977 {
978 .name = "ab8500-regulator",
Lee Jonesbad76992012-07-02 17:10:56 +0200979 .of_compatible = "stericsson,ab8500-regulator",
Mattias Walline098aded72010-12-02 15:40:31 +0100980 },
981 {
Rabin Vincent62579262010-05-19 11:39:02 +0200982 .name = "ab8500-gpadc",
Lee Jonesbad76992012-07-02 17:10:56 +0200983 .of_compatible = "stericsson,ab8500-gpadc",
Rabin Vincent62579262010-05-19 11:39:02 +0200984 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
985 .resources = ab8500_gpadc_resources,
986 },
987 {
988 .name = "ab8500-rtc",
Lee Jonesbad76992012-07-02 17:10:56 +0200989 .of_compatible = "stericsson,ab8500-rtc",
Rabin Vincent62579262010-05-19 11:39:02 +0200990 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
991 .resources = ab8500_rtc_resources,
992 },
Arun Murthyf0f05b12010-09-06 12:24:52 +0530993 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200994 .name = "ab8500-acc-det",
Lee Jonesbad76992012-07-02 17:10:56 +0200995 .of_compatible = "stericsson,ab8500-acc-det",
Linus Walleij6af75ec2011-06-09 23:57:45 +0200996 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
997 .resources = ab8500_av_acc_detect_resources,
998 },
999 {
Mattias Walline098aded72010-12-02 15:40:31 +01001000 .name = "ab8500-poweron-key",
Lee Jonesbad76992012-07-02 17:10:56 +02001001 .of_compatible = "stericsson,ab8500-poweron-key",
Mattias Walline098aded72010-12-02 15:40:31 +01001002 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
1003 .resources = ab8500_poweronkey_db_resources,
1004 },
1005 {
Arun Murthyf0f05b12010-09-06 12:24:52 +05301006 .name = "ab8500-pwm",
Lee Jonesbad76992012-07-02 17:10:56 +02001007 .of_compatible = "stericsson,ab8500-pwm",
Arun Murthyf0f05b12010-09-06 12:24:52 +05301008 .id = 1,
1009 },
1010 {
1011 .name = "ab8500-pwm",
Lee Jonesbad76992012-07-02 17:10:56 +02001012 .of_compatible = "stericsson,ab8500-pwm",
Arun Murthyf0f05b12010-09-06 12:24:52 +05301013 .id = 2,
1014 },
1015 {
1016 .name = "ab8500-pwm",
Lee Jonesbad76992012-07-02 17:10:56 +02001017 .of_compatible = "stericsson,ab8500-pwm",
Arun Murthyf0f05b12010-09-06 12:24:52 +05301018 .id = 3,
1019 },
Lee Jonesbad76992012-07-02 17:10:56 +02001020 {
1021 .name = "ab8500-leds",
1022 .of_compatible = "stericsson,ab8500-leds",
1023 },
Sundar R Iyer77686512010-09-05 12:18:47 -07001024 {
Mattias Walline098aded72010-12-02 15:40:31 +01001025 .name = "ab8500-denc",
Lee Jonesbad76992012-07-02 17:10:56 +02001026 .of_compatible = "stericsson,ab8500-denc",
Mattias Walline098aded72010-12-02 15:40:31 +01001027 },
1028 {
1029 .name = "ab8500-temp",
Lee Jonesbad76992012-07-02 17:10:56 +02001030 .of_compatible = "stericsson,ab8500-temp",
Mattias Walline098aded72010-12-02 15:40:31 +01001031 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
1032 .resources = ab8500_temp_resources,
Sundar R Iyer77686512010-09-05 12:18:47 -07001033 },
Rabin Vincent62579262010-05-19 11:39:02 +02001034};
1035
Rickard Andersson6ef94182012-04-17 09:30:57 +02001036static struct mfd_cell __devinitdata ab8500_bm_devs[] = {
1037 {
1038 .name = "ab8500-charger",
1039 .num_resources = ARRAY_SIZE(ab8500_charger_resources),
1040 .resources = ab8500_charger_resources,
1041 },
1042 {
1043 .name = "ab8500-btemp",
1044 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
1045 .resources = ab8500_btemp_resources,
1046 },
1047 {
1048 .name = "ab8500-fg",
1049 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
1050 .resources = ab8500_fg_resources,
1051 },
1052 {
1053 .name = "ab8500-chargalg",
1054 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
1055 .resources = ab8500_chargalg_resources,
1056 },
1057};
1058
Linus Walleijd6255522012-02-20 21:42:24 +01001059static struct mfd_cell __devinitdata ab8500_devs[] = {
1060 {
1061 .name = "ab8500-gpio",
Lee Jonesbad76992012-07-02 17:10:56 +02001062 .of_compatible = "stericsson,ab8500-gpio",
Linus Walleijd6255522012-02-20 21:42:24 +01001063 .num_resources = ARRAY_SIZE(ab8500_gpio_resources),
1064 .resources = ab8500_gpio_resources,
1065 },
1066 {
1067 .name = "ab8500-usb",
Lee Jonesbad76992012-07-02 17:10:56 +02001068 .of_compatible = "stericsson,ab8500-usb",
Linus Walleijd6255522012-02-20 21:42:24 +01001069 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1070 .resources = ab8500_usb_resources,
1071 },
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +02001072 {
1073 .name = "ab8500-codec",
Lee Jones81a21cd2012-07-27 13:38:51 +01001074 .of_compatible = "stericsson,ab8500-codec",
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +02001075 },
Linus Walleijd6255522012-02-20 21:42:24 +01001076};
1077
1078static struct mfd_cell __devinitdata ab9540_devs[] = {
1079 {
1080 .name = "ab8500-gpio",
1081 .num_resources = ARRAY_SIZE(ab9540_gpio_resources),
1082 .resources = ab9540_gpio_resources,
1083 },
1084 {
1085 .name = "ab9540-usb",
1086 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1087 .resources = ab8500_usb_resources,
1088 },
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +02001089 {
1090 .name = "ab9540-codec",
1091 },
1092};
1093
1094/* Device list common to ab9540 and ab8505 */
1095static struct mfd_cell __devinitdata ab9540_ab8505_devs[] = {
1096 {
1097 .name = "ab-iddet",
1098 .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
1099 .resources = ab8505_iddet_resources,
1100 },
Linus Walleijd6255522012-02-20 21:42:24 +01001101};
1102
Mattias Wallincca69b62010-12-02 15:09:36 +01001103static ssize_t show_chip_id(struct device *dev,
1104 struct device_attribute *attr, char *buf)
1105{
1106 struct ab8500 *ab8500;
1107
1108 ab8500 = dev_get_drvdata(dev);
1109 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
1110}
1111
Mattias Walline5c238c2011-03-02 11:52:36 +01001112/*
1113 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
1114 * 0x01 Swoff bit programming
1115 * 0x02 Thermal protection activation
1116 * 0x04 Vbat lower then BattOk falling threshold
1117 * 0x08 Watchdog expired
1118 * 0x10 Non presence of 32kHz clock
1119 * 0x20 Battery level lower than power on reset threshold
1120 * 0x40 Power on key 1 pressed longer than 10 seconds
1121 * 0x80 DB8500 thermal shutdown
1122 */
1123static ssize_t show_switch_off_status(struct device *dev,
1124 struct device_attribute *attr, char *buf)
1125{
1126 int ret;
1127 u8 value;
1128 struct ab8500 *ab8500;
1129
1130 ab8500 = dev_get_drvdata(dev);
1131 ret = get_register_interruptible(ab8500, AB8500_RTC,
1132 AB8500_SWITCH_OFF_STATUS, &value);
1133 if (ret < 0)
1134 return ret;
1135 return sprintf(buf, "%#x\n", value);
1136}
1137
Andrew Lynnb4a31032011-10-11 10:49:47 +02001138/*
1139 * ab8500 has turned on due to (TURN_ON_STATUS):
1140 * 0x01 PORnVbat
1141 * 0x02 PonKey1dbF
1142 * 0x04 PonKey2dbF
1143 * 0x08 RTCAlarm
1144 * 0x10 MainChDet
1145 * 0x20 VbusDet
1146 * 0x40 UsbIDDetect
1147 * 0x80 Reserved
1148 */
1149static ssize_t show_turn_on_status(struct device *dev,
1150 struct device_attribute *attr, char *buf)
1151{
1152 int ret;
1153 u8 value;
1154 struct ab8500 *ab8500;
1155
1156 ab8500 = dev_get_drvdata(dev);
1157 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
1158 AB8500_TURN_ON_STATUS, &value);
1159 if (ret < 0)
1160 return ret;
1161 return sprintf(buf, "%#x\n", value);
1162}
1163
Linus Walleijd6255522012-02-20 21:42:24 +01001164static ssize_t show_ab9540_dbbrstn(struct device *dev,
1165 struct device_attribute *attr, char *buf)
1166{
1167 struct ab8500 *ab8500;
1168 int ret;
1169 u8 value;
1170
1171 ab8500 = dev_get_drvdata(dev);
1172
1173 ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2,
1174 AB9540_MODEM_CTRL2_REG, &value);
1175 if (ret < 0)
1176 return ret;
1177
1178 return sprintf(buf, "%d\n",
1179 (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0);
1180}
1181
1182static ssize_t store_ab9540_dbbrstn(struct device *dev,
1183 struct device_attribute *attr, const char *buf, size_t count)
1184{
1185 struct ab8500 *ab8500;
1186 int ret = count;
1187 int err;
1188 u8 bitvalues;
1189
1190 ab8500 = dev_get_drvdata(dev);
1191
1192 if (count > 0) {
1193 switch (buf[0]) {
1194 case '0':
1195 bitvalues = 0;
1196 break;
1197 case '1':
1198 bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT;
1199 break;
1200 default:
1201 goto exit;
1202 }
1203
1204 err = mask_and_set_register_interruptible(ab8500,
1205 AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG,
1206 AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues);
1207 if (err)
1208 dev_info(ab8500->dev,
1209 "Failed to set DBBRSTN %c, err %#x\n",
1210 buf[0], err);
1211 }
1212
1213exit:
1214 return ret;
1215}
1216
Mattias Wallincca69b62010-12-02 15:09:36 +01001217static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
Mattias Walline5c238c2011-03-02 11:52:36 +01001218static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
Andrew Lynnb4a31032011-10-11 10:49:47 +02001219static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
Linus Walleijd6255522012-02-20 21:42:24 +01001220static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
1221 show_ab9540_dbbrstn, store_ab9540_dbbrstn);
Mattias Wallincca69b62010-12-02 15:09:36 +01001222
1223static struct attribute *ab8500_sysfs_entries[] = {
1224 &dev_attr_chip_id.attr,
Mattias Walline5c238c2011-03-02 11:52:36 +01001225 &dev_attr_switch_off_status.attr,
Andrew Lynnb4a31032011-10-11 10:49:47 +02001226 &dev_attr_turn_on_status.attr,
Mattias Wallincca69b62010-12-02 15:09:36 +01001227 NULL,
1228};
1229
Linus Walleijd6255522012-02-20 21:42:24 +01001230static struct attribute *ab9540_sysfs_entries[] = {
1231 &dev_attr_chip_id.attr,
1232 &dev_attr_switch_off_status.attr,
1233 &dev_attr_turn_on_status.attr,
1234 &dev_attr_dbbrstn.attr,
1235 NULL,
1236};
1237
Mattias Wallincca69b62010-12-02 15:09:36 +01001238static struct attribute_group ab8500_attr_group = {
1239 .attrs = ab8500_sysfs_entries,
1240};
1241
Linus Walleijd6255522012-02-20 21:42:24 +01001242static struct attribute_group ab9540_attr_group = {
1243 .attrs = ab9540_sysfs_entries,
1244};
1245
Lee Jonesd28f1db2012-05-19 17:21:37 +02001246static int __devinit ab8500_probe(struct platform_device *pdev)
Rabin Vincent62579262010-05-19 11:39:02 +02001247{
Jonas Aabergb04c530c2012-06-29 17:46:12 +02001248 static char *switch_off_status[] = {
1249 "Swoff bit programming",
1250 "Thermal protection activation",
1251 "Vbat lower then BattOk falling threshold",
1252 "Watchdog expired",
1253 "Non presence of 32kHz clock",
1254 "Battery level lower than power on reset threshold",
1255 "Power on key 1 pressed longer than 10 seconds",
1256 "DB8500 thermal shutdown"};
Lee Jonesd28f1db2012-05-19 17:21:37 +02001257 struct ab8500_platform_data *plat = dev_get_platdata(&pdev->dev);
1258 const struct platform_device_id *platid = platform_get_device_id(pdev);
Lee Jones6bc4a562012-05-17 14:45:13 +01001259 enum ab8500_version version = AB8500_VERSION_UNDEFINED;
1260 struct device_node *np = pdev->dev.of_node;
Lee Jonesd28f1db2012-05-19 17:21:37 +02001261 struct ab8500 *ab8500;
1262 struct resource *resource;
Rabin Vincent62579262010-05-19 11:39:02 +02001263 int ret;
1264 int i;
Mattias Wallin47c16972010-09-10 17:47:56 +02001265 u8 value;
Rabin Vincent62579262010-05-19 11:39:02 +02001266
Lee Jonesd28f1db2012-05-19 17:21:37 +02001267 ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL);
1268 if (!ab8500)
1269 return -ENOMEM;
1270
Rabin Vincent62579262010-05-19 11:39:02 +02001271 if (plat)
1272 ab8500->irq_base = plat->irq_base;
1273
Lee Jonesd28f1db2012-05-19 17:21:37 +02001274 ab8500->dev = &pdev->dev;
1275
1276 resource = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1277 if (!resource) {
1278 ret = -ENODEV;
1279 goto out_free_ab8500;
1280 }
1281
1282 ab8500->irq = resource->start;
1283
Lee Jones822672a2012-06-20 13:56:38 +01001284 ab8500->read = ab8500_prcmu_read;
1285 ab8500->write = ab8500_prcmu_write;
1286 ab8500->write_masked = ab8500_prcmu_write_masked;
Lee Jonesd28f1db2012-05-19 17:21:37 +02001287
Rabin Vincent62579262010-05-19 11:39:02 +02001288 mutex_init(&ab8500->lock);
1289 mutex_init(&ab8500->irq_lock);
Jonas Aaberg112a80d2012-04-17 09:30:33 +02001290 atomic_set(&ab8500->transfer_ongoing, 0);
Rabin Vincent62579262010-05-19 11:39:02 +02001291
Lee Jonesd28f1db2012-05-19 17:21:37 +02001292 platform_set_drvdata(pdev, ab8500);
1293
Lee Jones6bc4a562012-05-17 14:45:13 +01001294 if (platid)
1295 version = platid->driver_data;
Lee Jones6bc4a562012-05-17 14:45:13 +01001296
Linus Walleij0f6208372012-02-20 21:42:10 +01001297 if (version != AB8500_VERSION_UNDEFINED)
1298 ab8500->version = version;
1299 else {
1300 ret = get_register_interruptible(ab8500, AB8500_MISC,
1301 AB8500_IC_NAME_REG, &value);
1302 if (ret < 0)
Lee Jonesd28f1db2012-05-19 17:21:37 +02001303 goto out_free_ab8500;
Linus Walleij0f6208372012-02-20 21:42:10 +01001304
1305 ab8500->version = value;
1306 }
1307
Mattias Wallin47c16972010-09-10 17:47:56 +02001308 ret = get_register_interruptible(ab8500, AB8500_MISC,
1309 AB8500_REV_REG, &value);
Rabin Vincent62579262010-05-19 11:39:02 +02001310 if (ret < 0)
Lee Jonesd28f1db2012-05-19 17:21:37 +02001311 goto out_free_ab8500;
Rabin Vincent62579262010-05-19 11:39:02 +02001312
Mattias Wallin47c16972010-09-10 17:47:56 +02001313 ab8500->chip_id = value;
Rabin Vincent62579262010-05-19 11:39:02 +02001314
Linus Walleij0f6208372012-02-20 21:42:10 +01001315 dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n",
1316 ab8500_version_str[ab8500->version],
1317 ab8500->chip_id >> 4,
1318 ab8500->chip_id & 0x0F);
1319
Linus Walleijd6255522012-02-20 21:42:24 +01001320 /* Configure AB8500 or AB9540 IRQ */
Bengt Jonssona9823622012-03-08 14:01:57 +01001321 if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
Linus Walleijd6255522012-02-20 21:42:24 +01001322 ab8500->mask_size = AB9540_NUM_IRQ_REGS;
1323 ab8500->irq_reg_offset = ab9540_irq_regoffset;
1324 } else {
1325 ab8500->mask_size = AB8500_NUM_IRQ_REGS;
1326 ab8500->irq_reg_offset = ab8500_irq_regoffset;
1327 }
Linus Walleij2ced4452012-02-20 21:42:17 +01001328 ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL);
1329 if (!ab8500->mask)
1330 return -ENOMEM;
1331 ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL);
1332 if (!ab8500->oldmask) {
1333 ret = -ENOMEM;
1334 goto out_freemask;
1335 }
Mattias Walline5c238c2011-03-02 11:52:36 +01001336 /*
1337 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
1338 * 0x01 Swoff bit programming
1339 * 0x02 Thermal protection activation
1340 * 0x04 Vbat lower then BattOk falling threshold
1341 * 0x08 Watchdog expired
1342 * 0x10 Non presence of 32kHz clock
1343 * 0x20 Battery level lower than power on reset threshold
1344 * 0x40 Power on key 1 pressed longer than 10 seconds
1345 * 0x80 DB8500 thermal shutdown
1346 */
1347
1348 ret = get_register_interruptible(ab8500, AB8500_RTC,
1349 AB8500_SWITCH_OFF_STATUS, &value);
1350 if (ret < 0)
1351 return ret;
Jonas Aabergb04c530c2012-06-29 17:46:12 +02001352 dev_info(ab8500->dev, "switch off cause(s) (%#x): ", value);
1353
1354 if (value) {
1355 for (i = 0; i < ARRAY_SIZE(switch_off_status); i++) {
1356 if (value & 1)
1357 printk(KERN_CONT " \"%s\"",
1358 switch_off_status[i]);
1359 value = value >> 1;
1360
1361 }
1362 printk(KERN_CONT "\n");
1363 } else {
1364 printk(KERN_CONT " None\n");
1365 }
Mattias Walline5c238c2011-03-02 11:52:36 +01001366
Rabin Vincent62579262010-05-19 11:39:02 +02001367 if (plat && plat->init)
1368 plat->init(ab8500);
1369
1370 /* Clear and mask all interrupts */
Linus Walleij2ced4452012-02-20 21:42:17 +01001371 for (i = 0; i < ab8500->mask_size; i++) {
Linus Walleij0f6208372012-02-20 21:42:10 +01001372 /*
1373 * Interrupt register 12 doesn't exist prior to AB8500 version
1374 * 2.0
1375 */
1376 if (ab8500->irq_reg_offset[i] == 11 &&
1377 is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +01001378 continue;
Rabin Vincent62579262010-05-19 11:39:02 +02001379
Mattias Wallin47c16972010-09-10 17:47:56 +02001380 get_register_interruptible(ab8500, AB8500_INTERRUPT,
Linus Walleij2ced4452012-02-20 21:42:17 +01001381 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
Mattias Wallin92d50a42010-12-07 11:20:47 +01001382 &value);
Mattias Wallin47c16972010-09-10 17:47:56 +02001383 set_register_interruptible(ab8500, AB8500_INTERRUPT,
Linus Walleij2ced4452012-02-20 21:42:17 +01001384 AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
Rabin Vincent62579262010-05-19 11:39:02 +02001385 }
1386
Mattias Wallin47c16972010-09-10 17:47:56 +02001387 ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
1388 if (ret)
Linus Walleij2ced4452012-02-20 21:42:17 +01001389 goto out_freeoldmask;
Mattias Wallin47c16972010-09-10 17:47:56 +02001390
Linus Walleij2ced4452012-02-20 21:42:17 +01001391 for (i = 0; i < ab8500->mask_size; i++)
Rabin Vincent62579262010-05-19 11:39:02 +02001392 ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
1393
Lee Jones06e589e2012-06-20 13:56:37 +01001394 ret = ab8500_irq_init(ab8500, np);
1395 if (ret)
1396 goto out_freeoldmask;
Rabin Vincent62579262010-05-19 11:39:02 +02001397
Lee Jones06e589e2012-06-20 13:56:37 +01001398 /* Activate this feature only in ab9540 */
1399 /* till tests are done on ab8500 1p2 or later*/
1400 if (is_ab9540(ab8500)) {
1401 ret = request_threaded_irq(ab8500->irq, NULL,
Michel JAOUEN7ccfe9b2012-05-07 15:02:03 +02001402 ab8500_hierarchical_irq,
1403 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1404 "ab8500", ab8500);
Lee Jones06e589e2012-06-20 13:56:37 +01001405 }
1406 else {
1407 ret = request_threaded_irq(ab8500->irq, NULL,
Michel JAOUEN7ccfe9b2012-05-07 15:02:03 +02001408 ab8500_irq,
1409 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1410 "ab8500", ab8500);
Rabin Vincent62579262010-05-19 11:39:02 +02001411 if (ret)
Lee Jones06e589e2012-06-20 13:56:37 +01001412 goto out_freeoldmask;
Rabin Vincent62579262010-05-19 11:39:02 +02001413 }
1414
Lee Jonesbad76992012-07-02 17:10:56 +02001415 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs,
1416 ARRAY_SIZE(abx500_common_devs), NULL,
Mark Brown55692af2012-09-11 15:16:36 +08001417 ab8500->irq_base, ab8500->domain);
Lee Jonesbad76992012-07-02 17:10:56 +02001418 if (ret)
1419 goto out_freeirq;
1420
1421 if (is_ab9540(ab8500))
1422 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
1423 ARRAY_SIZE(ab9540_devs), NULL,
Mark Brown55692af2012-09-11 15:16:36 +08001424 ab8500->irq_base, ab8500->domain);
Lee Jonesbad76992012-07-02 17:10:56 +02001425 else
1426 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
1427 ARRAY_SIZE(ab8500_devs), NULL,
Mark Brown55692af2012-09-11 15:16:36 +08001428 ab8500->irq_base, ab8500->domain);
Lee Jonesbad76992012-07-02 17:10:56 +02001429 if (ret)
1430 goto out_freeirq;
Linus Walleijd6255522012-02-20 21:42:24 +01001431
Lee Jonesbad76992012-07-02 17:10:56 +02001432 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1433 ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs,
1434 ARRAY_SIZE(ab9540_ab8505_devs), NULL,
Mark Brown55692af2012-09-11 15:16:36 +08001435 ab8500->irq_base, ab8500->domain);
Lee Jonesbad76992012-07-02 17:10:56 +02001436 if (ret)
1437 goto out_freeirq;
Rabin Vincent62579262010-05-19 11:39:02 +02001438
Rickard Andersson6ef94182012-04-17 09:30:57 +02001439 if (!no_bm) {
1440 /* Add battery management devices */
1441 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
1442 ARRAY_SIZE(ab8500_bm_devs), NULL,
Mark Brown55692af2012-09-11 15:16:36 +08001443 ab8500->irq_base, ab8500->domain);
Rickard Andersson6ef94182012-04-17 09:30:57 +02001444 if (ret)
1445 dev_err(ab8500->dev, "error adding bm devices\n");
1446 }
1447
Linus Walleijd6255522012-02-20 21:42:24 +01001448 if (is_ab9540(ab8500))
1449 ret = sysfs_create_group(&ab8500->dev->kobj,
1450 &ab9540_attr_group);
1451 else
1452 ret = sysfs_create_group(&ab8500->dev->kobj,
1453 &ab8500_attr_group);
Mattias Wallincca69b62010-12-02 15:09:36 +01001454 if (ret)
1455 dev_err(ab8500->dev, "error creating sysfs entries\n");
Lee Jones06e589e2012-06-20 13:56:37 +01001456
1457 return ret;
Rabin Vincent62579262010-05-19 11:39:02 +02001458
1459out_freeirq:
Lee Jones06e589e2012-06-20 13:56:37 +01001460 free_irq(ab8500->irq, ab8500);
Linus Walleij2ced4452012-02-20 21:42:17 +01001461out_freeoldmask:
1462 kfree(ab8500->oldmask);
1463out_freemask:
1464 kfree(ab8500->mask);
Lee Jonesd28f1db2012-05-19 17:21:37 +02001465out_free_ab8500:
1466 kfree(ab8500);
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001467
Rabin Vincent62579262010-05-19 11:39:02 +02001468 return ret;
1469}
1470
Lee Jonesd28f1db2012-05-19 17:21:37 +02001471static int __devexit ab8500_remove(struct platform_device *pdev)
Rabin Vincent62579262010-05-19 11:39:02 +02001472{
Lee Jonesd28f1db2012-05-19 17:21:37 +02001473 struct ab8500 *ab8500 = platform_get_drvdata(pdev);
1474
Linus Walleijd6255522012-02-20 21:42:24 +01001475 if (is_ab9540(ab8500))
1476 sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
1477 else
1478 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
Lee Jones06e589e2012-06-20 13:56:37 +01001479
Rabin Vincent62579262010-05-19 11:39:02 +02001480 mfd_remove_devices(ab8500->dev);
Lee Jones06e589e2012-06-20 13:56:37 +01001481 free_irq(ab8500->irq, ab8500);
1482
Linus Walleij2ced4452012-02-20 21:42:17 +01001483 kfree(ab8500->oldmask);
1484 kfree(ab8500->mask);
Lee Jonesd28f1db2012-05-19 17:21:37 +02001485 kfree(ab8500);
Rabin Vincent62579262010-05-19 11:39:02 +02001486
1487 return 0;
1488}
1489
Lee Jonesd28f1db2012-05-19 17:21:37 +02001490static const struct platform_device_id ab8500_id[] = {
1491 { "ab8500-core", AB8500_VERSION_AB8500 },
1492 { "ab8505-i2c", AB8500_VERSION_AB8505 },
1493 { "ab9540-i2c", AB8500_VERSION_AB9540 },
1494 { "ab8540-i2c", AB8500_VERSION_AB8540 },
1495 { }
1496};
1497
1498static struct platform_driver ab8500_core_driver = {
1499 .driver = {
1500 .name = "ab8500-core",
1501 .owner = THIS_MODULE,
1502 },
1503 .probe = ab8500_probe,
1504 .remove = __devexit_p(ab8500_remove),
1505 .id_table = ab8500_id,
1506};
1507
1508static int __init ab8500_core_init(void)
1509{
1510 return platform_driver_register(&ab8500_core_driver);
1511}
1512
1513static void __exit ab8500_core_exit(void)
1514{
1515 platform_driver_unregister(&ab8500_core_driver);
1516}
Lee Jonesba7cbc32012-06-11 16:25:00 +01001517core_initcall(ab8500_core_init);
Lee Jonesd28f1db2012-05-19 17:21:37 +02001518module_exit(ab8500_core_exit);
1519
Mattias Wallinadceed62011-03-02 11:51:11 +01001520MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
Rabin Vincent62579262010-05-19 11:39:02 +02001521MODULE_DESCRIPTION("AB8500 MFD core");
1522MODULE_LICENSE("GPL v2");