blob: 6a59919fc331683f28abae5a9b12e9490f9c0b4a [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>
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 Wallin47c16972010-09-10 17:47:56 +020019#include <linux/mfd/abx500.h>
Linus Walleijee66e652011-12-02 14:16:33 +010020#include <linux/mfd/abx500/ab8500.h>
Sundar R Iyer549931f2010-07-13 11:51:28 +053021#include <linux/regulator/ab8500.h>
Rabin Vincent62579262010-05-19 11:39:02 +020022
23/*
24 * Interrupt register offsets
25 * Bank : 0x0E
26 */
Mattias Wallin47c16972010-09-10 17:47:56 +020027#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 Walleijd6255522012-02-20 21:42:24 +010035#define AB9540_IT_SOURCE13_REG 0x0C
Mattias Wallin47c16972010-09-10 17:47:56 +020036#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 Vincent62579262010-05-19 11:39:02 +020042
43/*
44 * latch registers
45 */
Mattias Wallin47c16972010-09-10 17:47:56 +020046#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 Wallin92d50a42010-12-07 11:20:47 +010056#define AB8500_IT_LATCH12_REG 0x2B
Linus Walleijd6255522012-02-20 21:42:24 +010057#define AB9540_IT_LATCH13_REG 0x2C
Mattias Wallin47c16972010-09-10 17:47:56 +020058#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 Vincent62579262010-05-19 11:39:02 +020064
65/*
66 * mask registers
67 */
68
Mattias Wallin47c16972010-09-10 17:47:56 +020069#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 Vincent62579262010-05-19 11:39:02 +020093
Michel JAOUEN7ccfe9b2012-05-07 15:02:03 +020094/*
95 * latch hierarchy registers
96 */
97#define AB8500_IT_LATCHHIER1_REG 0x60
98#define AB8500_IT_LATCHHIER2_REG 0x61
99#define AB8500_IT_LATCHHIER3_REG 0x62
100
101#define AB8500_IT_LATCHHIER_NUM 3
102
Mattias Wallin47c16972010-09-10 17:47:56 +0200103#define AB8500_REV_REG 0x80
Linus Walleij0f6208372012-02-20 21:42:10 +0100104#define AB8500_IC_NAME_REG 0x82
Mattias Walline5c238c2011-03-02 11:52:36 +0100105#define AB8500_SWITCH_OFF_STATUS 0x00
Rabin Vincent62579262010-05-19 11:39:02 +0200106
Andrew Lynnb4a31032011-10-11 10:49:47 +0200107#define AB8500_TURN_ON_STATUS 0x00
108
Rickard Andersson6ef94182012-04-17 09:30:57 +0200109static bool no_bm; /* No battery management */
110module_param(no_bm, bool, S_IRUGO);
111
Linus Walleijd6255522012-02-20 21:42:24 +0100112#define AB9540_MODEM_CTRL2_REG 0x23
113#define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT BIT(2)
114
Rabin Vincent62579262010-05-19 11:39:02 +0200115/*
116 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
Linus Walleij2ced4452012-02-20 21:42:17 +0100117 * numbers are indexed into this array with (num / 8). The interupts are
118 * defined in linux/mfd/ab8500.h
Rabin Vincent62579262010-05-19 11:39:02 +0200119 *
120 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
121 * offset 0.
122 */
Linus Walleij2ced4452012-02-20 21:42:17 +0100123/* AB8500 support */
Rabin Vincent62579262010-05-19 11:39:02 +0200124static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
Mattias Wallin92d50a42010-12-07 11:20:47 +0100125 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
Rabin Vincent62579262010-05-19 11:39:02 +0200126};
127
Linus Walleijd6255522012-02-20 21:42:24 +0100128/* AB9540 support */
129static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = {
130 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24,
131};
132
Linus Walleij0f6208372012-02-20 21:42:10 +0100133static const char ab8500_version_str[][7] = {
134 [AB8500_VERSION_AB8500] = "AB8500",
135 [AB8500_VERSION_AB8505] = "AB8505",
136 [AB8500_VERSION_AB9540] = "AB9540",
137 [AB8500_VERSION_AB8540] = "AB8540",
138};
139
Mattias Wallin47c16972010-09-10 17:47:56 +0200140static int ab8500_get_chip_id(struct device *dev)
141{
Mattias Wallin6bce7bf2010-12-02 15:08:32 +0100142 struct ab8500 *ab8500;
143
144 if (!dev)
145 return -EINVAL;
146 ab8500 = dev_get_drvdata(dev->parent);
147 return ab8500 ? (int)ab8500->chip_id : -EINVAL;
Mattias Wallin47c16972010-09-10 17:47:56 +0200148}
149
150static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
151 u8 reg, u8 data)
Rabin Vincent62579262010-05-19 11:39:02 +0200152{
153 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200154 /*
155 * Put the u8 bank and u8 register together into a an u16.
156 * The bank on higher 8 bits and register in lower 8 bits.
157 * */
158 u16 addr = ((u16)bank) << 8 | reg;
Rabin Vincent62579262010-05-19 11:39:02 +0200159
160 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
161
Rabin Vincent392cbd12012-03-08 14:01:46 +0100162 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200163
164 ret = ab8500->write(ab8500, addr, data);
165 if (ret < 0)
166 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
167 addr, ret);
168 mutex_unlock(&ab8500->lock);
169
170 return ret;
171}
172
173static int ab8500_set_register(struct device *dev, u8 bank,
174 u8 reg, u8 value)
175{
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200176 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200177 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
178
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200179 atomic_inc(&ab8500->transfer_ongoing);
180 ret = set_register_interruptible(ab8500, bank, reg, value);
181 atomic_dec(&ab8500->transfer_ongoing);
182 return ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200183}
184
185static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
186 u8 reg, u8 *value)
187{
188 int ret;
189 /* put the u8 bank and u8 reg together into a an u16.
190 * bank on higher 8 bits and reg in lower */
191 u16 addr = ((u16)bank) << 8 | reg;
192
Rabin Vincent392cbd12012-03-08 14:01:46 +0100193 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200194
195 ret = ab8500->read(ab8500, addr);
196 if (ret < 0)
197 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
198 addr, ret);
199 else
200 *value = ret;
201
202 mutex_unlock(&ab8500->lock);
203 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
204
205 return ret;
206}
207
208static int ab8500_get_register(struct device *dev, u8 bank,
209 u8 reg, u8 *value)
210{
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200211 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200212 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
213
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200214 atomic_inc(&ab8500->transfer_ongoing);
215 ret = get_register_interruptible(ab8500, bank, reg, value);
216 atomic_dec(&ab8500->transfer_ongoing);
217 return ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200218}
219
220static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
221 u8 reg, u8 bitmask, u8 bitvalues)
222{
223 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200224 /* put the u8 bank and u8 reg together into a an u16.
225 * bank on higher 8 bits and reg in lower */
226 u16 addr = ((u16)bank) << 8 | reg;
227
Rabin Vincent392cbd12012-03-08 14:01:46 +0100228 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200229
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100230 if (ab8500->write_masked == NULL) {
231 u8 data;
232
233 ret = ab8500->read(ab8500, addr);
234 if (ret < 0) {
235 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
236 addr, ret);
237 goto out;
238 }
239
240 data = (u8)ret;
241 data = (~bitmask & data) | (bitmask & bitvalues);
242
243 ret = ab8500->write(ab8500, addr, data);
244 if (ret < 0)
245 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
246 addr, ret);
247
248 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr,
249 data);
Mattias Wallin47c16972010-09-10 17:47:56 +0200250 goto out;
251 }
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100252 ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues);
Rabin Vincent62579262010-05-19 11:39:02 +0200253 if (ret < 0)
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100254 dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr,
255 ret);
Rabin Vincent62579262010-05-19 11:39:02 +0200256out:
257 mutex_unlock(&ab8500->lock);
258 return ret;
259}
Mattias Wallin47c16972010-09-10 17:47:56 +0200260
261static int ab8500_mask_and_set_register(struct device *dev,
262 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
263{
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200264 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200265 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
266
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200267 atomic_inc(&ab8500->transfer_ongoing);
268 ret= mask_and_set_register_interruptible(ab8500, bank, reg,
269 bitmask, bitvalues);
270 atomic_dec(&ab8500->transfer_ongoing);
271 return ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200272}
273
274static struct abx500_ops ab8500_ops = {
275 .get_chip_id = ab8500_get_chip_id,
276 .get_register = ab8500_get_register,
277 .set_register = ab8500_set_register,
278 .get_register_page = NULL,
279 .set_register_page = NULL,
280 .mask_and_set_register = ab8500_mask_and_set_register,
281 .event_registers_startup_state_get = NULL,
282 .startup_irq_enabled = NULL,
283};
Rabin Vincent62579262010-05-19 11:39:02 +0200284
Mark Brown9505a0a2010-12-11 13:16:08 +0000285static void ab8500_irq_lock(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200286{
Mark Brown9505a0a2010-12-11 13:16:08 +0000287 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Rabin Vincent62579262010-05-19 11:39:02 +0200288
289 mutex_lock(&ab8500->irq_lock);
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200290 atomic_inc(&ab8500->transfer_ongoing);
Rabin Vincent62579262010-05-19 11:39:02 +0200291}
292
Mark Brown9505a0a2010-12-11 13:16:08 +0000293static void ab8500_irq_sync_unlock(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200294{
Mark Brown9505a0a2010-12-11 13:16:08 +0000295 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Rabin Vincent62579262010-05-19 11:39:02 +0200296 int i;
297
Linus Walleij2ced4452012-02-20 21:42:17 +0100298 for (i = 0; i < ab8500->mask_size; i++) {
Rabin Vincent62579262010-05-19 11:39:02 +0200299 u8 old = ab8500->oldmask[i];
300 u8 new = ab8500->mask[i];
301 int reg;
302
303 if (new == old)
304 continue;
305
Linus Walleij0f6208372012-02-20 21:42:10 +0100306 /*
307 * Interrupt register 12 doesn't exist prior to AB8500 version
308 * 2.0
309 */
310 if (ab8500->irq_reg_offset[i] == 11 &&
311 is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100312 continue;
313
Rabin Vincent62579262010-05-19 11:39:02 +0200314 ab8500->oldmask[i] = new;
315
Linus Walleij2ced4452012-02-20 21:42:17 +0100316 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
Mattias Wallin47c16972010-09-10 17:47:56 +0200317 set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
Rabin Vincent62579262010-05-19 11:39:02 +0200318 }
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200319 atomic_dec(&ab8500->transfer_ongoing);
Rabin Vincent62579262010-05-19 11:39:02 +0200320 mutex_unlock(&ab8500->irq_lock);
321}
322
Mark Brown9505a0a2010-12-11 13:16:08 +0000323static void ab8500_irq_mask(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200324{
Mark Brown9505a0a2010-12-11 13:16:08 +0000325 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
326 int offset = data->irq - ab8500->irq_base;
Rabin Vincent62579262010-05-19 11:39:02 +0200327 int index = offset / 8;
328 int mask = 1 << (offset % 8);
329
330 ab8500->mask[index] |= mask;
331}
332
Mark Brown9505a0a2010-12-11 13:16:08 +0000333static void ab8500_irq_unmask(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200334{
Mark Brown9505a0a2010-12-11 13:16:08 +0000335 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
336 int offset = data->irq - ab8500->irq_base;
Rabin Vincent62579262010-05-19 11:39:02 +0200337 int index = offset / 8;
338 int mask = 1 << (offset % 8);
339
340 ab8500->mask[index] &= ~mask;
341}
342
343static struct irq_chip ab8500_irq_chip = {
344 .name = "ab8500",
Mark Brown9505a0a2010-12-11 13:16:08 +0000345 .irq_bus_lock = ab8500_irq_lock,
346 .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
347 .irq_mask = ab8500_irq_mask,
Virupax Sadashivpetimathe6f93062011-10-11 10:49:17 +0200348 .irq_disable = ab8500_irq_mask,
Mark Brown9505a0a2010-12-11 13:16:08 +0000349 .irq_unmask = ab8500_irq_unmask,
Rabin Vincent62579262010-05-19 11:39:02 +0200350};
351
Michel JAOUEN7ccfe9b2012-05-07 15:02:03 +0200352static int ab8500_handle_hierarchical_line(struct ab8500 *ab8500,
353 int latch_offset, u8 latch_val)
354{
355 int int_bit = __ffs(latch_val);
356 int line, i;
357
358 do {
359 int_bit = __ffs(latch_val);
360
361 for (i = 0; i < ab8500->mask_size; i++)
362 if (ab8500->irq_reg_offset[i] == latch_offset)
363 break;
364
365 if (i >= ab8500->mask_size) {
366 dev_err(ab8500->dev, "Register offset 0x%2x not declared\n",
367 latch_offset);
368 return -ENXIO;
369 }
370
371 line = (i << 3) + int_bit;
372 latch_val &= ~(1 << int_bit);
373
374 handle_nested_irq(ab8500->irq_base + line);
375 } while (latch_val);
376
377 return 0;
378}
379
380static int ab8500_handle_hierarchical_latch(struct ab8500 *ab8500,
381 int hier_offset, u8 hier_val)
382{
383 int latch_bit, status;
384 u8 latch_offset, latch_val;
385
386 do {
387 latch_bit = __ffs(hier_val);
388 latch_offset = (hier_offset << 3) + latch_bit;
389
390 /* Fix inconsistent ITFromLatch25 bit mapping... */
391 if (unlikely(latch_offset == 17))
392 latch_offset = 24;
393
394 status = get_register_interruptible(ab8500,
395 AB8500_INTERRUPT,
396 AB8500_IT_LATCH1_REG + latch_offset,
397 &latch_val);
398 if (status < 0 || latch_val == 0)
399 goto discard;
400
401 status = ab8500_handle_hierarchical_line(ab8500,
402 latch_offset, latch_val);
403 if (status < 0)
404 return status;
405discard:
406 hier_val &= ~(1 << latch_bit);
407 } while (hier_val);
408
409 return 0;
410}
411
412static irqreturn_t ab8500_hierarchical_irq(int irq, void *dev)
413{
414 struct ab8500 *ab8500 = dev;
415 u8 i;
416
417 dev_vdbg(ab8500->dev, "interrupt\n");
418
419 /* Hierarchical interrupt version */
420 for (i = 0; i < AB8500_IT_LATCHHIER_NUM; i++) {
421 int status;
422 u8 hier_val;
423
424 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
425 AB8500_IT_LATCHHIER1_REG + i, &hier_val);
426 if (status < 0 || hier_val == 0)
427 continue;
428
429 status = ab8500_handle_hierarchical_latch(ab8500, i, hier_val);
430 if (status < 0)
431 break;
432 }
433 return IRQ_HANDLED;
434}
435
Rabin Vincent62579262010-05-19 11:39:02 +0200436static irqreturn_t ab8500_irq(int irq, void *dev)
437{
438 struct ab8500 *ab8500 = dev;
439 int i;
440
441 dev_vdbg(ab8500->dev, "interrupt\n");
442
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200443 atomic_inc(&ab8500->transfer_ongoing);
444
Linus Walleij2ced4452012-02-20 21:42:17 +0100445 for (i = 0; i < ab8500->mask_size; i++) {
446 int regoffset = ab8500->irq_reg_offset[i];
Rabin Vincent62579262010-05-19 11:39:02 +0200447 int status;
Mattias Wallin47c16972010-09-10 17:47:56 +0200448 u8 value;
Rabin Vincent62579262010-05-19 11:39:02 +0200449
Linus Walleij0f6208372012-02-20 21:42:10 +0100450 /*
451 * Interrupt register 12 doesn't exist prior to AB8500 version
452 * 2.0
453 */
454 if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100455 continue;
456
Mattias Wallin47c16972010-09-10 17:47:56 +0200457 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
458 AB8500_IT_LATCH1_REG + regoffset, &value);
459 if (status < 0 || value == 0)
Rabin Vincent62579262010-05-19 11:39:02 +0200460 continue;
461
462 do {
Mattias Wallin88aec4f2010-12-02 15:06:49 +0100463 int bit = __ffs(value);
Rabin Vincent62579262010-05-19 11:39:02 +0200464 int line = i * 8 + bit;
465
466 handle_nested_irq(ab8500->irq_base + line);
Mattias Wallin47c16972010-09-10 17:47:56 +0200467 value &= ~(1 << bit);
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200468
Mattias Wallin47c16972010-09-10 17:47:56 +0200469 } while (value);
Rabin Vincent62579262010-05-19 11:39:02 +0200470 }
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200471 atomic_dec(&ab8500->transfer_ongoing);
Rabin Vincent62579262010-05-19 11:39:02 +0200472 return IRQ_HANDLED;
473}
474
475static int ab8500_irq_init(struct ab8500 *ab8500)
476{
477 int base = ab8500->irq_base;
478 int irq;
Linus Walleij2ced4452012-02-20 21:42:17 +0100479 int num_irqs;
Rabin Vincent62579262010-05-19 11:39:02 +0200480
Linus Walleijd6255522012-02-20 21:42:24 +0100481 if (is_ab9540(ab8500))
482 num_irqs = AB9540_NR_IRQS;
Bengt Jonssona9823622012-03-08 14:01:57 +0100483 else if (is_ab8505(ab8500))
484 num_irqs = AB8505_NR_IRQS;
Linus Walleijd6255522012-02-20 21:42:24 +0100485 else
486 num_irqs = AB8500_NR_IRQS;
Linus Walleij2ced4452012-02-20 21:42:17 +0100487
488 for (irq = base; irq < base + num_irqs; irq++) {
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000489 irq_set_chip_data(irq, ab8500);
490 irq_set_chip_and_handler(irq, &ab8500_irq_chip,
Rabin Vincent62579262010-05-19 11:39:02 +0200491 handle_simple_irq);
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000492 irq_set_nested_thread(irq, 1);
Rabin Vincent62579262010-05-19 11:39:02 +0200493#ifdef CONFIG_ARM
494 set_irq_flags(irq, IRQF_VALID);
495#else
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000496 irq_set_noprobe(irq);
Rabin Vincent62579262010-05-19 11:39:02 +0200497#endif
498 }
499
500 return 0;
501}
502
503static void ab8500_irq_remove(struct ab8500 *ab8500)
504{
505 int base = ab8500->irq_base;
506 int irq;
Linus Walleij2ced4452012-02-20 21:42:17 +0100507 int num_irqs;
Rabin Vincent62579262010-05-19 11:39:02 +0200508
Linus Walleijd6255522012-02-20 21:42:24 +0100509 if (is_ab9540(ab8500))
510 num_irqs = AB9540_NR_IRQS;
Bengt Jonssona9823622012-03-08 14:01:57 +0100511 else if (is_ab8505(ab8500))
512 num_irqs = AB8505_NR_IRQS;
Linus Walleijd6255522012-02-20 21:42:24 +0100513 else
514 num_irqs = AB8500_NR_IRQS;
Linus Walleij2ced4452012-02-20 21:42:17 +0100515
516 for (irq = base; irq < base + num_irqs; irq++) {
Rabin Vincent62579262010-05-19 11:39:02 +0200517#ifdef CONFIG_ARM
518 set_irq_flags(irq, 0);
519#endif
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000520 irq_set_chip_and_handler(irq, NULL, NULL);
521 irq_set_chip_data(irq, NULL);
Rabin Vincent62579262010-05-19 11:39:02 +0200522 }
523}
524
Jonas Aaberg112a80d2012-04-17 09:30:33 +0200525int ab8500_suspend(struct ab8500 *ab8500)
526{
527 if (atomic_read(&ab8500->transfer_ongoing))
528 return -EINVAL;
529 else
530 return 0;
531}
532
Linus Walleijd6255522012-02-20 21:42:24 +0100533/* AB8500 GPIO Resources */
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200534static struct resource __devinitdata ab8500_gpio_resources[] = {
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530535 {
536 .name = "GPIO_INT6",
537 .start = AB8500_INT_GPIO6R,
538 .end = AB8500_INT_GPIO41F,
539 .flags = IORESOURCE_IRQ,
540 }
541};
542
Linus Walleijd6255522012-02-20 21:42:24 +0100543/* AB9540 GPIO Resources */
544static struct resource __devinitdata ab9540_gpio_resources[] = {
545 {
546 .name = "GPIO_INT6",
547 .start = AB8500_INT_GPIO6R,
548 .end = AB8500_INT_GPIO41F,
549 .flags = IORESOURCE_IRQ,
550 },
551 {
552 .name = "GPIO_INT14",
553 .start = AB9540_INT_GPIO50R,
554 .end = AB9540_INT_GPIO54R,
555 .flags = IORESOURCE_IRQ,
556 },
557 {
558 .name = "GPIO_INT15",
559 .start = AB9540_INT_GPIO50F,
560 .end = AB9540_INT_GPIO54F,
561 .flags = IORESOURCE_IRQ,
562 }
563};
564
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200565static struct resource __devinitdata ab8500_gpadc_resources[] = {
Rabin Vincent62579262010-05-19 11:39:02 +0200566 {
567 .name = "HW_CONV_END",
568 .start = AB8500_INT_GP_HW_ADC_CONV_END,
569 .end = AB8500_INT_GP_HW_ADC_CONV_END,
570 .flags = IORESOURCE_IRQ,
571 },
572 {
573 .name = "SW_CONV_END",
574 .start = AB8500_INT_GP_SW_ADC_CONV_END,
575 .end = AB8500_INT_GP_SW_ADC_CONV_END,
576 .flags = IORESOURCE_IRQ,
577 },
578};
579
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200580static struct resource __devinitdata ab8500_rtc_resources[] = {
Rabin Vincent62579262010-05-19 11:39:02 +0200581 {
582 .name = "60S",
583 .start = AB8500_INT_RTC_60S,
584 .end = AB8500_INT_RTC_60S,
585 .flags = IORESOURCE_IRQ,
586 },
587 {
588 .name = "ALARM",
589 .start = AB8500_INT_RTC_ALARM,
590 .end = AB8500_INT_RTC_ALARM,
591 .flags = IORESOURCE_IRQ,
592 },
593};
594
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200595static struct resource __devinitdata ab8500_poweronkey_db_resources[] = {
Sundar R Iyer77686512010-09-05 12:18:47 -0700596 {
597 .name = "ONKEY_DBF",
598 .start = AB8500_INT_PON_KEY1DB_F,
599 .end = AB8500_INT_PON_KEY1DB_F,
600 .flags = IORESOURCE_IRQ,
601 },
602 {
603 .name = "ONKEY_DBR",
604 .start = AB8500_INT_PON_KEY1DB_R,
605 .end = AB8500_INT_PON_KEY1DB_R,
606 .flags = IORESOURCE_IRQ,
607 },
608};
609
Linus Walleij6af75ec2011-06-09 23:57:45 +0200610static struct resource __devinitdata ab8500_av_acc_detect_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100611 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200612 .name = "ACC_DETECT_1DB_F",
613 .start = AB8500_INT_ACC_DETECT_1DB_F,
614 .end = AB8500_INT_ACC_DETECT_1DB_F,
615 .flags = IORESOURCE_IRQ,
Mattias Walline098aded72010-12-02 15:40:31 +0100616 },
617 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200618 .name = "ACC_DETECT_1DB_R",
619 .start = AB8500_INT_ACC_DETECT_1DB_R,
620 .end = AB8500_INT_ACC_DETECT_1DB_R,
621 .flags = IORESOURCE_IRQ,
Mattias Walline098aded72010-12-02 15:40:31 +0100622 },
623 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200624 .name = "ACC_DETECT_21DB_F",
625 .start = AB8500_INT_ACC_DETECT_21DB_F,
626 .end = AB8500_INT_ACC_DETECT_21DB_F,
627 .flags = IORESOURCE_IRQ,
628 },
629 {
630 .name = "ACC_DETECT_21DB_R",
631 .start = AB8500_INT_ACC_DETECT_21DB_R,
632 .end = AB8500_INT_ACC_DETECT_21DB_R,
633 .flags = IORESOURCE_IRQ,
634 },
635 {
636 .name = "ACC_DETECT_22DB_F",
637 .start = AB8500_INT_ACC_DETECT_22DB_F,
638 .end = AB8500_INT_ACC_DETECT_22DB_F,
639 .flags = IORESOURCE_IRQ,
640 },
641 {
642 .name = "ACC_DETECT_22DB_R",
643 .start = AB8500_INT_ACC_DETECT_22DB_R,
644 .end = AB8500_INT_ACC_DETECT_22DB_R,
645 .flags = IORESOURCE_IRQ,
646 },
647};
648
649static struct resource __devinitdata ab8500_charger_resources[] = {
650 {
Mattias Walline098aded72010-12-02 15:40:31 +0100651 .name = "MAIN_CH_UNPLUG_DET",
652 .start = AB8500_INT_MAIN_CH_UNPLUG_DET,
653 .end = AB8500_INT_MAIN_CH_UNPLUG_DET,
654 .flags = IORESOURCE_IRQ,
655 },
656 {
657 .name = "MAIN_CHARGE_PLUG_DET",
658 .start = AB8500_INT_MAIN_CH_PLUG_DET,
659 .end = AB8500_INT_MAIN_CH_PLUG_DET,
660 .flags = IORESOURCE_IRQ,
661 },
662 {
Mattias Walline098aded72010-12-02 15:40:31 +0100663 .name = "VBUS_DET_R",
664 .start = AB8500_INT_VBUS_DET_R,
665 .end = AB8500_INT_VBUS_DET_R,
666 .flags = IORESOURCE_IRQ,
667 },
668 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200669 .name = "VBUS_DET_F",
670 .start = AB8500_INT_VBUS_DET_F,
671 .end = AB8500_INT_VBUS_DET_F,
Mattias Walline098aded72010-12-02 15:40:31 +0100672 .flags = IORESOURCE_IRQ,
673 },
674 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200675 .name = "USB_LINK_STATUS",
676 .start = AB8500_INT_USB_LINK_STATUS,
677 .end = AB8500_INT_USB_LINK_STATUS,
678 .flags = IORESOURCE_IRQ,
679 },
680 {
Mattias Walline098aded72010-12-02 15:40:31 +0100681 .name = "VBUS_OVV",
682 .start = AB8500_INT_VBUS_OVV,
683 .end = AB8500_INT_VBUS_OVV,
684 .flags = IORESOURCE_IRQ,
685 },
686 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200687 .name = "USB_CH_TH_PROT_R",
688 .start = AB8500_INT_USB_CH_TH_PROT_R,
689 .end = AB8500_INT_USB_CH_TH_PROT_R,
Mattias Walline098aded72010-12-02 15:40:31 +0100690 .flags = IORESOURCE_IRQ,
691 },
692 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200693 .name = "USB_CH_TH_PROT_F",
694 .start = AB8500_INT_USB_CH_TH_PROT_F,
695 .end = AB8500_INT_USB_CH_TH_PROT_F,
Mattias Walline098aded72010-12-02 15:40:31 +0100696 .flags = IORESOURCE_IRQ,
697 },
698 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200699 .name = "MAIN_EXT_CH_NOT_OK",
700 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
701 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
702 .flags = IORESOURCE_IRQ,
703 },
704 {
705 .name = "MAIN_CH_TH_PROT_R",
706 .start = AB8500_INT_MAIN_CH_TH_PROT_R,
707 .end = AB8500_INT_MAIN_CH_TH_PROT_R,
708 .flags = IORESOURCE_IRQ,
709 },
710 {
711 .name = "MAIN_CH_TH_PROT_F",
712 .start = AB8500_INT_MAIN_CH_TH_PROT_F,
713 .end = AB8500_INT_MAIN_CH_TH_PROT_F,
714 .flags = IORESOURCE_IRQ,
715 },
716 {
717 .name = "USB_CHARGER_NOT_OKR",
Bengt Jonssona9823622012-03-08 14:01:57 +0100718 .start = AB8500_INT_USB_CHARGER_NOT_OKR,
719 .end = AB8500_INT_USB_CHARGER_NOT_OKR,
Linus Walleij6af75ec2011-06-09 23:57:45 +0200720 .flags = IORESOURCE_IRQ,
721 },
722 {
723 .name = "CH_WD_EXP",
724 .start = AB8500_INT_CH_WD_EXP,
725 .end = AB8500_INT_CH_WD_EXP,
726 .flags = IORESOURCE_IRQ,
727 },
728};
729
730static struct resource __devinitdata ab8500_btemp_resources[] = {
731 {
732 .name = "BAT_CTRL_INDB",
733 .start = AB8500_INT_BAT_CTRL_INDB,
734 .end = AB8500_INT_BAT_CTRL_INDB,
Mattias Walline098aded72010-12-02 15:40:31 +0100735 .flags = IORESOURCE_IRQ,
736 },
737 {
738 .name = "BTEMP_LOW",
739 .start = AB8500_INT_BTEMP_LOW,
740 .end = AB8500_INT_BTEMP_LOW,
741 .flags = IORESOURCE_IRQ,
742 },
743 {
744 .name = "BTEMP_HIGH",
745 .start = AB8500_INT_BTEMP_HIGH,
746 .end = AB8500_INT_BTEMP_HIGH,
747 .flags = IORESOURCE_IRQ,
748 },
749 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200750 .name = "BTEMP_LOW_MEDIUM",
751 .start = AB8500_INT_BTEMP_LOW_MEDIUM,
752 .end = AB8500_INT_BTEMP_LOW_MEDIUM,
Mattias Walline098aded72010-12-02 15:40:31 +0100753 .flags = IORESOURCE_IRQ,
754 },
755 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200756 .name = "BTEMP_MEDIUM_HIGH",
757 .start = AB8500_INT_BTEMP_MEDIUM_HIGH,
758 .end = AB8500_INT_BTEMP_MEDIUM_HIGH,
Mattias Walline098aded72010-12-02 15:40:31 +0100759 .flags = IORESOURCE_IRQ,
760 },
761};
762
Linus Walleij6af75ec2011-06-09 23:57:45 +0200763static struct resource __devinitdata ab8500_fg_resources[] = {
764 {
765 .name = "NCONV_ACCU",
766 .start = AB8500_INT_CCN_CONV_ACC,
767 .end = AB8500_INT_CCN_CONV_ACC,
768 .flags = IORESOURCE_IRQ,
769 },
770 {
771 .name = "BATT_OVV",
772 .start = AB8500_INT_BATT_OVV,
773 .end = AB8500_INT_BATT_OVV,
774 .flags = IORESOURCE_IRQ,
775 },
776 {
777 .name = "LOW_BAT_F",
778 .start = AB8500_INT_LOW_BAT_F,
779 .end = AB8500_INT_LOW_BAT_F,
780 .flags = IORESOURCE_IRQ,
781 },
782 {
783 .name = "LOW_BAT_R",
784 .start = AB8500_INT_LOW_BAT_R,
785 .end = AB8500_INT_LOW_BAT_R,
786 .flags = IORESOURCE_IRQ,
787 },
788 {
789 .name = "CC_INT_CALIB",
790 .start = AB8500_INT_CC_INT_CALIB,
791 .end = AB8500_INT_CC_INT_CALIB,
792 .flags = IORESOURCE_IRQ,
793 },
Bengt Jonssona9823622012-03-08 14:01:57 +0100794 {
795 .name = "CCEOC",
796 .start = AB8500_INT_CCEOC,
797 .end = AB8500_INT_CCEOC,
798 .flags = IORESOURCE_IRQ,
799 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200800};
801
802static struct resource __devinitdata ab8500_chargalg_resources[] = {};
803
Axel Lindf720642011-11-10 09:56:18 +0800804#ifdef CONFIG_DEBUG_FS
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200805static struct resource __devinitdata ab8500_debug_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100806 {
807 .name = "IRQ_FIRST",
808 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
809 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
810 .flags = IORESOURCE_IRQ,
811 },
812 {
813 .name = "IRQ_LAST",
Bengt Jonssona9823622012-03-08 14:01:57 +0100814 .start = AB8500_INT_XTAL32K_KO,
815 .end = AB8500_INT_XTAL32K_KO,
Mattias Walline098aded72010-12-02 15:40:31 +0100816 .flags = IORESOURCE_IRQ,
817 },
818};
Axel Lindf720642011-11-10 09:56:18 +0800819#endif
Mattias Walline098aded72010-12-02 15:40:31 +0100820
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200821static struct resource __devinitdata ab8500_usb_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100822 {
823 .name = "ID_WAKEUP_R",
824 .start = AB8500_INT_ID_WAKEUP_R,
825 .end = AB8500_INT_ID_WAKEUP_R,
826 .flags = IORESOURCE_IRQ,
827 },
828 {
829 .name = "ID_WAKEUP_F",
830 .start = AB8500_INT_ID_WAKEUP_F,
831 .end = AB8500_INT_ID_WAKEUP_F,
832 .flags = IORESOURCE_IRQ,
833 },
834 {
835 .name = "VBUS_DET_F",
836 .start = AB8500_INT_VBUS_DET_F,
837 .end = AB8500_INT_VBUS_DET_F,
838 .flags = IORESOURCE_IRQ,
839 },
840 {
841 .name = "VBUS_DET_R",
842 .start = AB8500_INT_VBUS_DET_R,
843 .end = AB8500_INT_VBUS_DET_R,
844 .flags = IORESOURCE_IRQ,
845 },
Mattias Wallin92d50a42010-12-07 11:20:47 +0100846 {
847 .name = "USB_LINK_STATUS",
848 .start = AB8500_INT_USB_LINK_STATUS,
849 .end = AB8500_INT_USB_LINK_STATUS,
850 .flags = IORESOURCE_IRQ,
851 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200852 {
853 .name = "USB_ADP_PROBE_PLUG",
854 .start = AB8500_INT_ADP_PROBE_PLUG,
855 .end = AB8500_INT_ADP_PROBE_PLUG,
856 .flags = IORESOURCE_IRQ,
857 },
858 {
859 .name = "USB_ADP_PROBE_UNPLUG",
860 .start = AB8500_INT_ADP_PROBE_UNPLUG,
861 .end = AB8500_INT_ADP_PROBE_UNPLUG,
862 .flags = IORESOURCE_IRQ,
863 },
Mattias Walline098aded72010-12-02 15:40:31 +0100864};
865
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +0200866static struct resource __devinitdata ab8505_iddet_resources[] = {
867 {
868 .name = "KeyDeglitch",
869 .start = AB8505_INT_KEYDEGLITCH,
870 .end = AB8505_INT_KEYDEGLITCH,
871 .flags = IORESOURCE_IRQ,
872 },
873 {
874 .name = "KP",
875 .start = AB8505_INT_KP,
876 .end = AB8505_INT_KP,
877 .flags = IORESOURCE_IRQ,
878 },
879 {
880 .name = "IKP",
881 .start = AB8505_INT_IKP,
882 .end = AB8505_INT_IKP,
883 .flags = IORESOURCE_IRQ,
884 },
885 {
886 .name = "IKR",
887 .start = AB8505_INT_IKR,
888 .end = AB8505_INT_IKR,
889 .flags = IORESOURCE_IRQ,
890 },
891 {
892 .name = "KeyStuck",
893 .start = AB8505_INT_KEYSTUCK,
894 .end = AB8505_INT_KEYSTUCK,
895 .flags = IORESOURCE_IRQ,
896 },
897};
898
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200899static struct resource __devinitdata ab8500_temp_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100900 {
901 .name = "AB8500_TEMP_WARM",
902 .start = AB8500_INT_TEMP_WARM,
903 .end = AB8500_INT_TEMP_WARM,
904 .flags = IORESOURCE_IRQ,
905 },
906};
907
Linus Walleijd6255522012-02-20 21:42:24 +0100908static struct mfd_cell __devinitdata abx500_common_devs[] = {
Mattias Wallin5814fc32010-09-13 16:05:04 +0200909#ifdef CONFIG_DEBUG_FS
910 {
911 .name = "ab8500-debug",
Mattias Walline098aded72010-12-02 15:40:31 +0100912 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
913 .resources = ab8500_debug_resources,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200914 },
915#endif
Rabin Vincent62579262010-05-19 11:39:02 +0200916 {
Mattias Walline098aded72010-12-02 15:40:31 +0100917 .name = "ab8500-sysctrl",
918 },
919 {
920 .name = "ab8500-regulator",
921 },
922 {
Rabin Vincent62579262010-05-19 11:39:02 +0200923 .name = "ab8500-gpadc",
924 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
925 .resources = ab8500_gpadc_resources,
926 },
927 {
928 .name = "ab8500-rtc",
929 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
930 .resources = ab8500_rtc_resources,
931 },
Arun Murthyf0f05b12010-09-06 12:24:52 +0530932 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200933 .name = "ab8500-acc-det",
934 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
935 .resources = ab8500_av_acc_detect_resources,
936 },
937 {
Mattias Walline098aded72010-12-02 15:40:31 +0100938 .name = "ab8500-poweron-key",
939 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
940 .resources = ab8500_poweronkey_db_resources,
941 },
942 {
Arun Murthyf0f05b12010-09-06 12:24:52 +0530943 .name = "ab8500-pwm",
944 .id = 1,
945 },
946 {
947 .name = "ab8500-pwm",
948 .id = 2,
949 },
950 {
951 .name = "ab8500-pwm",
952 .id = 3,
953 },
Mattias Walline098aded72010-12-02 15:40:31 +0100954 { .name = "ab8500-leds", },
Sundar R Iyer77686512010-09-05 12:18:47 -0700955 {
Mattias Walline098aded72010-12-02 15:40:31 +0100956 .name = "ab8500-denc",
957 },
958 {
959 .name = "ab8500-temp",
960 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
961 .resources = ab8500_temp_resources,
Sundar R Iyer77686512010-09-05 12:18:47 -0700962 },
Rabin Vincent62579262010-05-19 11:39:02 +0200963};
964
Rickard Andersson6ef94182012-04-17 09:30:57 +0200965static struct mfd_cell __devinitdata ab8500_bm_devs[] = {
966 {
967 .name = "ab8500-charger",
968 .num_resources = ARRAY_SIZE(ab8500_charger_resources),
969 .resources = ab8500_charger_resources,
970 },
971 {
972 .name = "ab8500-btemp",
973 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
974 .resources = ab8500_btemp_resources,
975 },
976 {
977 .name = "ab8500-fg",
978 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
979 .resources = ab8500_fg_resources,
980 },
981 {
982 .name = "ab8500-chargalg",
983 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
984 .resources = ab8500_chargalg_resources,
985 },
986};
987
Linus Walleijd6255522012-02-20 21:42:24 +0100988static struct mfd_cell __devinitdata ab8500_devs[] = {
989 {
990 .name = "ab8500-gpio",
991 .num_resources = ARRAY_SIZE(ab8500_gpio_resources),
992 .resources = ab8500_gpio_resources,
993 },
994 {
995 .name = "ab8500-usb",
996 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
997 .resources = ab8500_usb_resources,
998 },
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +0200999 {
1000 .name = "ab8500-codec",
1001 },
Linus Walleijd6255522012-02-20 21:42:24 +01001002};
1003
1004static struct mfd_cell __devinitdata ab9540_devs[] = {
1005 {
1006 .name = "ab8500-gpio",
1007 .num_resources = ARRAY_SIZE(ab9540_gpio_resources),
1008 .resources = ab9540_gpio_resources,
1009 },
1010 {
1011 .name = "ab9540-usb",
1012 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
1013 .resources = ab8500_usb_resources,
1014 },
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +02001015 {
1016 .name = "ab9540-codec",
1017 },
1018};
1019
1020/* Device list common to ab9540 and ab8505 */
1021static struct mfd_cell __devinitdata ab9540_ab8505_devs[] = {
1022 {
1023 .name = "ab-iddet",
1024 .num_resources = ARRAY_SIZE(ab8505_iddet_resources),
1025 .resources = ab8505_iddet_resources,
1026 },
Linus Walleijd6255522012-02-20 21:42:24 +01001027};
1028
Mattias Wallincca69b62010-12-02 15:09:36 +01001029static ssize_t show_chip_id(struct device *dev,
1030 struct device_attribute *attr, char *buf)
1031{
1032 struct ab8500 *ab8500;
1033
1034 ab8500 = dev_get_drvdata(dev);
1035 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
1036}
1037
Mattias Walline5c238c2011-03-02 11:52:36 +01001038/*
1039 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
1040 * 0x01 Swoff bit programming
1041 * 0x02 Thermal protection activation
1042 * 0x04 Vbat lower then BattOk falling threshold
1043 * 0x08 Watchdog expired
1044 * 0x10 Non presence of 32kHz clock
1045 * 0x20 Battery level lower than power on reset threshold
1046 * 0x40 Power on key 1 pressed longer than 10 seconds
1047 * 0x80 DB8500 thermal shutdown
1048 */
1049static ssize_t show_switch_off_status(struct device *dev,
1050 struct device_attribute *attr, char *buf)
1051{
1052 int ret;
1053 u8 value;
1054 struct ab8500 *ab8500;
1055
1056 ab8500 = dev_get_drvdata(dev);
1057 ret = get_register_interruptible(ab8500, AB8500_RTC,
1058 AB8500_SWITCH_OFF_STATUS, &value);
1059 if (ret < 0)
1060 return ret;
1061 return sprintf(buf, "%#x\n", value);
1062}
1063
Andrew Lynnb4a31032011-10-11 10:49:47 +02001064/*
1065 * ab8500 has turned on due to (TURN_ON_STATUS):
1066 * 0x01 PORnVbat
1067 * 0x02 PonKey1dbF
1068 * 0x04 PonKey2dbF
1069 * 0x08 RTCAlarm
1070 * 0x10 MainChDet
1071 * 0x20 VbusDet
1072 * 0x40 UsbIDDetect
1073 * 0x80 Reserved
1074 */
1075static ssize_t show_turn_on_status(struct device *dev,
1076 struct device_attribute *attr, char *buf)
1077{
1078 int ret;
1079 u8 value;
1080 struct ab8500 *ab8500;
1081
1082 ab8500 = dev_get_drvdata(dev);
1083 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
1084 AB8500_TURN_ON_STATUS, &value);
1085 if (ret < 0)
1086 return ret;
1087 return sprintf(buf, "%#x\n", value);
1088}
1089
Linus Walleijd6255522012-02-20 21:42:24 +01001090static ssize_t show_ab9540_dbbrstn(struct device *dev,
1091 struct device_attribute *attr, char *buf)
1092{
1093 struct ab8500 *ab8500;
1094 int ret;
1095 u8 value;
1096
1097 ab8500 = dev_get_drvdata(dev);
1098
1099 ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2,
1100 AB9540_MODEM_CTRL2_REG, &value);
1101 if (ret < 0)
1102 return ret;
1103
1104 return sprintf(buf, "%d\n",
1105 (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0);
1106}
1107
1108static ssize_t store_ab9540_dbbrstn(struct device *dev,
1109 struct device_attribute *attr, const char *buf, size_t count)
1110{
1111 struct ab8500 *ab8500;
1112 int ret = count;
1113 int err;
1114 u8 bitvalues;
1115
1116 ab8500 = dev_get_drvdata(dev);
1117
1118 if (count > 0) {
1119 switch (buf[0]) {
1120 case '0':
1121 bitvalues = 0;
1122 break;
1123 case '1':
1124 bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT;
1125 break;
1126 default:
1127 goto exit;
1128 }
1129
1130 err = mask_and_set_register_interruptible(ab8500,
1131 AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG,
1132 AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues);
1133 if (err)
1134 dev_info(ab8500->dev,
1135 "Failed to set DBBRSTN %c, err %#x\n",
1136 buf[0], err);
1137 }
1138
1139exit:
1140 return ret;
1141}
1142
Mattias Wallincca69b62010-12-02 15:09:36 +01001143static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
Mattias Walline5c238c2011-03-02 11:52:36 +01001144static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
Andrew Lynnb4a31032011-10-11 10:49:47 +02001145static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
Linus Walleijd6255522012-02-20 21:42:24 +01001146static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
1147 show_ab9540_dbbrstn, store_ab9540_dbbrstn);
Mattias Wallincca69b62010-12-02 15:09:36 +01001148
1149static struct attribute *ab8500_sysfs_entries[] = {
1150 &dev_attr_chip_id.attr,
Mattias Walline5c238c2011-03-02 11:52:36 +01001151 &dev_attr_switch_off_status.attr,
Andrew Lynnb4a31032011-10-11 10:49:47 +02001152 &dev_attr_turn_on_status.attr,
Mattias Wallincca69b62010-12-02 15:09:36 +01001153 NULL,
1154};
1155
Linus Walleijd6255522012-02-20 21:42:24 +01001156static struct attribute *ab9540_sysfs_entries[] = {
1157 &dev_attr_chip_id.attr,
1158 &dev_attr_switch_off_status.attr,
1159 &dev_attr_turn_on_status.attr,
1160 &dev_attr_dbbrstn.attr,
1161 NULL,
1162};
1163
Mattias Wallincca69b62010-12-02 15:09:36 +01001164static struct attribute_group ab8500_attr_group = {
1165 .attrs = ab8500_sysfs_entries,
1166};
1167
Linus Walleijd6255522012-02-20 21:42:24 +01001168static struct attribute_group ab9540_attr_group = {
1169 .attrs = ab9540_sysfs_entries,
1170};
1171
Linus Walleij0f6208372012-02-20 21:42:10 +01001172int __devinit ab8500_init(struct ab8500 *ab8500, enum ab8500_version version)
Rabin Vincent62579262010-05-19 11:39:02 +02001173{
1174 struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev);
1175 int ret;
1176 int i;
Mattias Wallin47c16972010-09-10 17:47:56 +02001177 u8 value;
Rabin Vincent62579262010-05-19 11:39:02 +02001178
1179 if (plat)
1180 ab8500->irq_base = plat->irq_base;
1181
1182 mutex_init(&ab8500->lock);
1183 mutex_init(&ab8500->irq_lock);
Jonas Aaberg112a80d2012-04-17 09:30:33 +02001184 atomic_set(&ab8500->transfer_ongoing, 0);
Rabin Vincent62579262010-05-19 11:39:02 +02001185
Linus Walleij0f6208372012-02-20 21:42:10 +01001186 if (version != AB8500_VERSION_UNDEFINED)
1187 ab8500->version = version;
1188 else {
1189 ret = get_register_interruptible(ab8500, AB8500_MISC,
1190 AB8500_IC_NAME_REG, &value);
1191 if (ret < 0)
1192 return ret;
1193
1194 ab8500->version = value;
1195 }
1196
Mattias Wallin47c16972010-09-10 17:47:56 +02001197 ret = get_register_interruptible(ab8500, AB8500_MISC,
1198 AB8500_REV_REG, &value);
Rabin Vincent62579262010-05-19 11:39:02 +02001199 if (ret < 0)
1200 return ret;
1201
Mattias Wallin47c16972010-09-10 17:47:56 +02001202 ab8500->chip_id = value;
Rabin Vincent62579262010-05-19 11:39:02 +02001203
Linus Walleij0f6208372012-02-20 21:42:10 +01001204 dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n",
1205 ab8500_version_str[ab8500->version],
1206 ab8500->chip_id >> 4,
1207 ab8500->chip_id & 0x0F);
1208
Linus Walleijd6255522012-02-20 21:42:24 +01001209 /* Configure AB8500 or AB9540 IRQ */
Bengt Jonssona9823622012-03-08 14:01:57 +01001210 if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
Linus Walleijd6255522012-02-20 21:42:24 +01001211 ab8500->mask_size = AB9540_NUM_IRQ_REGS;
1212 ab8500->irq_reg_offset = ab9540_irq_regoffset;
1213 } else {
1214 ab8500->mask_size = AB8500_NUM_IRQ_REGS;
1215 ab8500->irq_reg_offset = ab8500_irq_regoffset;
1216 }
Linus Walleij2ced4452012-02-20 21:42:17 +01001217 ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL);
1218 if (!ab8500->mask)
1219 return -ENOMEM;
1220 ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL);
1221 if (!ab8500->oldmask) {
1222 ret = -ENOMEM;
1223 goto out_freemask;
1224 }
Mattias Walline5c238c2011-03-02 11:52:36 +01001225 /*
1226 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
1227 * 0x01 Swoff bit programming
1228 * 0x02 Thermal protection activation
1229 * 0x04 Vbat lower then BattOk falling threshold
1230 * 0x08 Watchdog expired
1231 * 0x10 Non presence of 32kHz clock
1232 * 0x20 Battery level lower than power on reset threshold
1233 * 0x40 Power on key 1 pressed longer than 10 seconds
1234 * 0x80 DB8500 thermal shutdown
1235 */
1236
1237 ret = get_register_interruptible(ab8500, AB8500_RTC,
1238 AB8500_SWITCH_OFF_STATUS, &value);
1239 if (ret < 0)
1240 return ret;
1241 dev_info(ab8500->dev, "switch off status: %#x", value);
1242
Rabin Vincent62579262010-05-19 11:39:02 +02001243 if (plat && plat->init)
1244 plat->init(ab8500);
1245
1246 /* Clear and mask all interrupts */
Linus Walleij2ced4452012-02-20 21:42:17 +01001247 for (i = 0; i < ab8500->mask_size; i++) {
Linus Walleij0f6208372012-02-20 21:42:10 +01001248 /*
1249 * Interrupt register 12 doesn't exist prior to AB8500 version
1250 * 2.0
1251 */
1252 if (ab8500->irq_reg_offset[i] == 11 &&
1253 is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +01001254 continue;
Rabin Vincent62579262010-05-19 11:39:02 +02001255
Mattias Wallin47c16972010-09-10 17:47:56 +02001256 get_register_interruptible(ab8500, AB8500_INTERRUPT,
Linus Walleij2ced4452012-02-20 21:42:17 +01001257 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
Mattias Wallin92d50a42010-12-07 11:20:47 +01001258 &value);
Mattias Wallin47c16972010-09-10 17:47:56 +02001259 set_register_interruptible(ab8500, AB8500_INTERRUPT,
Linus Walleij2ced4452012-02-20 21:42:17 +01001260 AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
Rabin Vincent62579262010-05-19 11:39:02 +02001261 }
1262
Mattias Wallin47c16972010-09-10 17:47:56 +02001263 ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
1264 if (ret)
Linus Walleij2ced4452012-02-20 21:42:17 +01001265 goto out_freeoldmask;
Mattias Wallin47c16972010-09-10 17:47:56 +02001266
Linus Walleij2ced4452012-02-20 21:42:17 +01001267 for (i = 0; i < ab8500->mask_size; i++)
Rabin Vincent62579262010-05-19 11:39:02 +02001268 ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
1269
1270 if (ab8500->irq_base) {
1271 ret = ab8500_irq_init(ab8500);
1272 if (ret)
Linus Walleij2ced4452012-02-20 21:42:17 +01001273 goto out_freeoldmask;
Rabin Vincent62579262010-05-19 11:39:02 +02001274
Michel JAOUEN7ccfe9b2012-05-07 15:02:03 +02001275 /* Activate this feature only in ab9540 */
1276 /* till tests are done on ab8500 1p2 or later*/
1277 if (is_ab9540(ab8500))
1278 ret = request_threaded_irq(ab8500->irq, NULL,
1279 ab8500_hierarchical_irq,
1280 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1281 "ab8500", ab8500);
1282 else
1283 ret = request_threaded_irq(ab8500->irq, NULL,
1284 ab8500_irq,
1285 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1286 "ab8500", ab8500);
Rabin Vincent62579262010-05-19 11:39:02 +02001287 if (ret)
1288 goto out_removeirq;
1289 }
1290
Linus Walleijd6255522012-02-20 21:42:24 +01001291 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs,
1292 ARRAY_SIZE(abx500_common_devs), NULL,
1293 ab8500->irq_base);
1294
1295 if (ret)
1296 goto out_freeirq;
1297
1298 if (is_ab9540(ab8500))
1299 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
1300 ARRAY_SIZE(ab9540_devs), NULL,
1301 ab8500->irq_base);
1302 else
1303 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +02001304 ARRAY_SIZE(ab8500_devs), NULL,
Rabin Vincent62579262010-05-19 11:39:02 +02001305 ab8500->irq_base);
Virupax Sadashivpetimath44f72e52012-04-17 09:30:14 +02001306
1307 if (is_ab9540(ab8500) || is_ab8505(ab8500))
1308 ret = mfd_add_devices(ab8500->dev, 0, ab9540_ab8505_devs,
1309 ARRAY_SIZE(ab9540_ab8505_devs), NULL,
1310 ab8500->irq_base);
1311
Rabin Vincent62579262010-05-19 11:39:02 +02001312 if (ret)
1313 goto out_freeirq;
1314
Rickard Andersson6ef94182012-04-17 09:30:57 +02001315 if (!no_bm) {
1316 /* Add battery management devices */
1317 ret = mfd_add_devices(ab8500->dev, 0, ab8500_bm_devs,
1318 ARRAY_SIZE(ab8500_bm_devs), NULL,
1319 ab8500->irq_base);
1320 if (ret)
1321 dev_err(ab8500->dev, "error adding bm devices\n");
1322 }
1323
Linus Walleijd6255522012-02-20 21:42:24 +01001324 if (is_ab9540(ab8500))
1325 ret = sysfs_create_group(&ab8500->dev->kobj,
1326 &ab9540_attr_group);
1327 else
1328 ret = sysfs_create_group(&ab8500->dev->kobj,
1329 &ab8500_attr_group);
Mattias Wallincca69b62010-12-02 15:09:36 +01001330 if (ret)
1331 dev_err(ab8500->dev, "error creating sysfs entries\n");
Linus Walleijd6255522012-02-20 21:42:24 +01001332 else
1333 return ret;
Rabin Vincent62579262010-05-19 11:39:02 +02001334
1335out_freeirq:
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001336 if (ab8500->irq_base)
Rabin Vincent62579262010-05-19 11:39:02 +02001337 free_irq(ab8500->irq, ab8500);
1338out_removeirq:
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001339 if (ab8500->irq_base)
Rabin Vincent62579262010-05-19 11:39:02 +02001340 ab8500_irq_remove(ab8500);
Linus Walleij2ced4452012-02-20 21:42:17 +01001341out_freeoldmask:
1342 kfree(ab8500->oldmask);
1343out_freemask:
1344 kfree(ab8500->mask);
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001345
Rabin Vincent62579262010-05-19 11:39:02 +02001346 return ret;
1347}
1348
1349int __devexit ab8500_exit(struct ab8500 *ab8500)
1350{
Linus Walleijd6255522012-02-20 21:42:24 +01001351 if (is_ab9540(ab8500))
1352 sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
1353 else
1354 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
Rabin Vincent62579262010-05-19 11:39:02 +02001355 mfd_remove_devices(ab8500->dev);
1356 if (ab8500->irq_base) {
1357 free_irq(ab8500->irq, ab8500);
1358 ab8500_irq_remove(ab8500);
1359 }
Linus Walleij2ced4452012-02-20 21:42:17 +01001360 kfree(ab8500->oldmask);
1361 kfree(ab8500->mask);
Rabin Vincent62579262010-05-19 11:39:02 +02001362
1363 return 0;
1364}
1365
Mattias Wallinadceed62011-03-02 11:51:11 +01001366MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
Rabin Vincent62579262010-05-19 11:39:02 +02001367MODULE_DESCRIPTION("AB8500 MFD core");
1368MODULE_LICENSE("GPL v2");