blob: 1f08704f7ae8ecab27c3247d4009f0c71de91b83 [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
Mattias Wallin47c16972010-09-10 17:47:56 +020094#define AB8500_REV_REG 0x80
Linus Walleij0f6208372012-02-20 21:42:10 +010095#define AB8500_IC_NAME_REG 0x82
Mattias Walline5c238c2011-03-02 11:52:36 +010096#define AB8500_SWITCH_OFF_STATUS 0x00
Rabin Vincent62579262010-05-19 11:39:02 +020097
Andrew Lynnb4a31032011-10-11 10:49:47 +020098#define AB8500_TURN_ON_STATUS 0x00
99
Linus Walleijd6255522012-02-20 21:42:24 +0100100#define AB9540_MODEM_CTRL2_REG 0x23
101#define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT BIT(2)
102
Rabin Vincent62579262010-05-19 11:39:02 +0200103/*
104 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
Linus Walleij2ced4452012-02-20 21:42:17 +0100105 * numbers are indexed into this array with (num / 8). The interupts are
106 * defined in linux/mfd/ab8500.h
Rabin Vincent62579262010-05-19 11:39:02 +0200107 *
108 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
109 * offset 0.
110 */
Linus Walleij2ced4452012-02-20 21:42:17 +0100111/* AB8500 support */
Rabin Vincent62579262010-05-19 11:39:02 +0200112static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
Mattias Wallin92d50a42010-12-07 11:20:47 +0100113 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
Rabin Vincent62579262010-05-19 11:39:02 +0200114};
115
Linus Walleijd6255522012-02-20 21:42:24 +0100116/* AB9540 support */
117static const int ab9540_irq_regoffset[AB9540_NUM_IRQ_REGS] = {
118 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21, 12, 13, 24,
119};
120
Linus Walleij0f6208372012-02-20 21:42:10 +0100121static const char ab8500_version_str[][7] = {
122 [AB8500_VERSION_AB8500] = "AB8500",
123 [AB8500_VERSION_AB8505] = "AB8505",
124 [AB8500_VERSION_AB9540] = "AB9540",
125 [AB8500_VERSION_AB8540] = "AB8540",
126};
127
Mattias Wallin47c16972010-09-10 17:47:56 +0200128static int ab8500_get_chip_id(struct device *dev)
129{
Mattias Wallin6bce7bf2010-12-02 15:08:32 +0100130 struct ab8500 *ab8500;
131
132 if (!dev)
133 return -EINVAL;
134 ab8500 = dev_get_drvdata(dev->parent);
135 return ab8500 ? (int)ab8500->chip_id : -EINVAL;
Mattias Wallin47c16972010-09-10 17:47:56 +0200136}
137
138static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
139 u8 reg, u8 data)
Rabin Vincent62579262010-05-19 11:39:02 +0200140{
141 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200142 /*
143 * Put the u8 bank and u8 register together into a an u16.
144 * The bank on higher 8 bits and register in lower 8 bits.
145 * */
146 u16 addr = ((u16)bank) << 8 | reg;
Rabin Vincent62579262010-05-19 11:39:02 +0200147
148 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
149
Rabin Vincent392cbd12012-03-08 14:01:46 +0100150 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200151
152 ret = ab8500->write(ab8500, addr, data);
153 if (ret < 0)
154 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
155 addr, ret);
156 mutex_unlock(&ab8500->lock);
157
158 return ret;
159}
160
161static int ab8500_set_register(struct device *dev, u8 bank,
162 u8 reg, u8 value)
163{
164 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
165
166 return set_register_interruptible(ab8500, bank, reg, value);
167}
168
169static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
170 u8 reg, u8 *value)
171{
172 int ret;
173 /* put the u8 bank and u8 reg together into a an u16.
174 * bank on higher 8 bits and reg in lower */
175 u16 addr = ((u16)bank) << 8 | reg;
176
Rabin Vincent392cbd12012-03-08 14:01:46 +0100177 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200178
179 ret = ab8500->read(ab8500, addr);
180 if (ret < 0)
181 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
182 addr, ret);
183 else
184 *value = ret;
185
186 mutex_unlock(&ab8500->lock);
187 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
188
189 return ret;
190}
191
192static int ab8500_get_register(struct device *dev, u8 bank,
193 u8 reg, u8 *value)
194{
195 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
196
197 return get_register_interruptible(ab8500, bank, reg, value);
198}
199
200static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
201 u8 reg, u8 bitmask, u8 bitvalues)
202{
203 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200204 /* put the u8 bank and u8 reg together into a an u16.
205 * bank on higher 8 bits and reg in lower */
206 u16 addr = ((u16)bank) << 8 | reg;
207
Rabin Vincent392cbd12012-03-08 14:01:46 +0100208 mutex_lock(&ab8500->lock);
Mattias Wallin47c16972010-09-10 17:47:56 +0200209
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100210 if (ab8500->write_masked == NULL) {
211 u8 data;
212
213 ret = ab8500->read(ab8500, addr);
214 if (ret < 0) {
215 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
216 addr, ret);
217 goto out;
218 }
219
220 data = (u8)ret;
221 data = (~bitmask & data) | (bitmask & bitvalues);
222
223 ret = ab8500->write(ab8500, addr, data);
224 if (ret < 0)
225 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
226 addr, ret);
227
228 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr,
229 data);
Mattias Wallin47c16972010-09-10 17:47:56 +0200230 goto out;
231 }
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100232 ret = ab8500->write_masked(ab8500, addr, bitmask, bitvalues);
Rabin Vincent62579262010-05-19 11:39:02 +0200233 if (ret < 0)
Mattias Nilssonbc628fd2012-03-08 14:02:20 +0100234 dev_err(ab8500->dev, "failed to modify reg %#x: %d\n", addr,
235 ret);
Rabin Vincent62579262010-05-19 11:39:02 +0200236out:
237 mutex_unlock(&ab8500->lock);
238 return ret;
239}
Mattias Wallin47c16972010-09-10 17:47:56 +0200240
241static int ab8500_mask_and_set_register(struct device *dev,
242 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
243{
244 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
245
246 return mask_and_set_register_interruptible(ab8500, bank, reg,
247 bitmask, bitvalues);
248
249}
250
251static struct abx500_ops ab8500_ops = {
252 .get_chip_id = ab8500_get_chip_id,
253 .get_register = ab8500_get_register,
254 .set_register = ab8500_set_register,
255 .get_register_page = NULL,
256 .set_register_page = NULL,
257 .mask_and_set_register = ab8500_mask_and_set_register,
258 .event_registers_startup_state_get = NULL,
259 .startup_irq_enabled = NULL,
260};
Rabin Vincent62579262010-05-19 11:39:02 +0200261
Mark Brown9505a0a2010-12-11 13:16:08 +0000262static void ab8500_irq_lock(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200263{
Mark Brown9505a0a2010-12-11 13:16:08 +0000264 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Rabin Vincent62579262010-05-19 11:39:02 +0200265
266 mutex_lock(&ab8500->irq_lock);
267}
268
Mark Brown9505a0a2010-12-11 13:16:08 +0000269static void ab8500_irq_sync_unlock(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200270{
Mark Brown9505a0a2010-12-11 13:16:08 +0000271 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Rabin Vincent62579262010-05-19 11:39:02 +0200272 int i;
273
Linus Walleij2ced4452012-02-20 21:42:17 +0100274 for (i = 0; i < ab8500->mask_size; i++) {
Rabin Vincent62579262010-05-19 11:39:02 +0200275 u8 old = ab8500->oldmask[i];
276 u8 new = ab8500->mask[i];
277 int reg;
278
279 if (new == old)
280 continue;
281
Linus Walleij0f6208372012-02-20 21:42:10 +0100282 /*
283 * Interrupt register 12 doesn't exist prior to AB8500 version
284 * 2.0
285 */
286 if (ab8500->irq_reg_offset[i] == 11 &&
287 is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100288 continue;
289
Rabin Vincent62579262010-05-19 11:39:02 +0200290 ab8500->oldmask[i] = new;
291
Linus Walleij2ced4452012-02-20 21:42:17 +0100292 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
Mattias Wallin47c16972010-09-10 17:47:56 +0200293 set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
Rabin Vincent62579262010-05-19 11:39:02 +0200294 }
295
296 mutex_unlock(&ab8500->irq_lock);
297}
298
Mark Brown9505a0a2010-12-11 13:16:08 +0000299static void ab8500_irq_mask(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200300{
Mark Brown9505a0a2010-12-11 13:16:08 +0000301 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
302 int offset = data->irq - ab8500->irq_base;
Rabin Vincent62579262010-05-19 11:39:02 +0200303 int index = offset / 8;
304 int mask = 1 << (offset % 8);
305
306 ab8500->mask[index] |= mask;
307}
308
Mark Brown9505a0a2010-12-11 13:16:08 +0000309static void ab8500_irq_unmask(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200310{
Mark Brown9505a0a2010-12-11 13:16:08 +0000311 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
312 int offset = data->irq - ab8500->irq_base;
Rabin Vincent62579262010-05-19 11:39:02 +0200313 int index = offset / 8;
314 int mask = 1 << (offset % 8);
315
316 ab8500->mask[index] &= ~mask;
317}
318
319static struct irq_chip ab8500_irq_chip = {
320 .name = "ab8500",
Mark Brown9505a0a2010-12-11 13:16:08 +0000321 .irq_bus_lock = ab8500_irq_lock,
322 .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
323 .irq_mask = ab8500_irq_mask,
Virupax Sadashivpetimathe6f93062011-10-11 10:49:17 +0200324 .irq_disable = ab8500_irq_mask,
Mark Brown9505a0a2010-12-11 13:16:08 +0000325 .irq_unmask = ab8500_irq_unmask,
Rabin Vincent62579262010-05-19 11:39:02 +0200326};
327
328static irqreturn_t ab8500_irq(int irq, void *dev)
329{
330 struct ab8500 *ab8500 = dev;
331 int i;
332
333 dev_vdbg(ab8500->dev, "interrupt\n");
334
Linus Walleij2ced4452012-02-20 21:42:17 +0100335 for (i = 0; i < ab8500->mask_size; i++) {
336 int regoffset = ab8500->irq_reg_offset[i];
Rabin Vincent62579262010-05-19 11:39:02 +0200337 int status;
Mattias Wallin47c16972010-09-10 17:47:56 +0200338 u8 value;
Rabin Vincent62579262010-05-19 11:39:02 +0200339
Linus Walleij0f6208372012-02-20 21:42:10 +0100340 /*
341 * Interrupt register 12 doesn't exist prior to AB8500 version
342 * 2.0
343 */
344 if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100345 continue;
346
Mattias Wallin47c16972010-09-10 17:47:56 +0200347 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
348 AB8500_IT_LATCH1_REG + regoffset, &value);
349 if (status < 0 || value == 0)
Rabin Vincent62579262010-05-19 11:39:02 +0200350 continue;
351
352 do {
Mattias Wallin88aec4f2010-12-02 15:06:49 +0100353 int bit = __ffs(value);
Rabin Vincent62579262010-05-19 11:39:02 +0200354 int line = i * 8 + bit;
355
356 handle_nested_irq(ab8500->irq_base + line);
Mattias Wallin47c16972010-09-10 17:47:56 +0200357 value &= ~(1 << bit);
358 } while (value);
Rabin Vincent62579262010-05-19 11:39:02 +0200359 }
360
361 return IRQ_HANDLED;
362}
363
364static int ab8500_irq_init(struct ab8500 *ab8500)
365{
366 int base = ab8500->irq_base;
367 int irq;
Linus Walleij2ced4452012-02-20 21:42:17 +0100368 int num_irqs;
Rabin Vincent62579262010-05-19 11:39:02 +0200369
Linus Walleijd6255522012-02-20 21:42:24 +0100370 if (is_ab9540(ab8500))
371 num_irqs = AB9540_NR_IRQS;
Bengt Jonssona9823622012-03-08 14:01:57 +0100372 else if (is_ab8505(ab8500))
373 num_irqs = AB8505_NR_IRQS;
Linus Walleijd6255522012-02-20 21:42:24 +0100374 else
375 num_irqs = AB8500_NR_IRQS;
Linus Walleij2ced4452012-02-20 21:42:17 +0100376
377 for (irq = base; irq < base + num_irqs; irq++) {
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000378 irq_set_chip_data(irq, ab8500);
379 irq_set_chip_and_handler(irq, &ab8500_irq_chip,
Rabin Vincent62579262010-05-19 11:39:02 +0200380 handle_simple_irq);
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000381 irq_set_nested_thread(irq, 1);
Rabin Vincent62579262010-05-19 11:39:02 +0200382#ifdef CONFIG_ARM
383 set_irq_flags(irq, IRQF_VALID);
384#else
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000385 irq_set_noprobe(irq);
Rabin Vincent62579262010-05-19 11:39:02 +0200386#endif
387 }
388
389 return 0;
390}
391
392static void ab8500_irq_remove(struct ab8500 *ab8500)
393{
394 int base = ab8500->irq_base;
395 int irq;
Linus Walleij2ced4452012-02-20 21:42:17 +0100396 int num_irqs;
Rabin Vincent62579262010-05-19 11:39:02 +0200397
Linus Walleijd6255522012-02-20 21:42:24 +0100398 if (is_ab9540(ab8500))
399 num_irqs = AB9540_NR_IRQS;
Bengt Jonssona9823622012-03-08 14:01:57 +0100400 else if (is_ab8505(ab8500))
401 num_irqs = AB8505_NR_IRQS;
Linus Walleijd6255522012-02-20 21:42:24 +0100402 else
403 num_irqs = AB8500_NR_IRQS;
Linus Walleij2ced4452012-02-20 21:42:17 +0100404
405 for (irq = base; irq < base + num_irqs; irq++) {
Rabin Vincent62579262010-05-19 11:39:02 +0200406#ifdef CONFIG_ARM
407 set_irq_flags(irq, 0);
408#endif
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000409 irq_set_chip_and_handler(irq, NULL, NULL);
410 irq_set_chip_data(irq, NULL);
Rabin Vincent62579262010-05-19 11:39:02 +0200411 }
412}
413
Linus Walleijd6255522012-02-20 21:42:24 +0100414/* AB8500 GPIO Resources */
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200415static struct resource __devinitdata ab8500_gpio_resources[] = {
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530416 {
417 .name = "GPIO_INT6",
418 .start = AB8500_INT_GPIO6R,
419 .end = AB8500_INT_GPIO41F,
420 .flags = IORESOURCE_IRQ,
421 }
422};
423
Linus Walleijd6255522012-02-20 21:42:24 +0100424/* AB9540 GPIO Resources */
425static struct resource __devinitdata ab9540_gpio_resources[] = {
426 {
427 .name = "GPIO_INT6",
428 .start = AB8500_INT_GPIO6R,
429 .end = AB8500_INT_GPIO41F,
430 .flags = IORESOURCE_IRQ,
431 },
432 {
433 .name = "GPIO_INT14",
434 .start = AB9540_INT_GPIO50R,
435 .end = AB9540_INT_GPIO54R,
436 .flags = IORESOURCE_IRQ,
437 },
438 {
439 .name = "GPIO_INT15",
440 .start = AB9540_INT_GPIO50F,
441 .end = AB9540_INT_GPIO54F,
442 .flags = IORESOURCE_IRQ,
443 }
444};
445
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200446static struct resource __devinitdata ab8500_gpadc_resources[] = {
Rabin Vincent62579262010-05-19 11:39:02 +0200447 {
448 .name = "HW_CONV_END",
449 .start = AB8500_INT_GP_HW_ADC_CONV_END,
450 .end = AB8500_INT_GP_HW_ADC_CONV_END,
451 .flags = IORESOURCE_IRQ,
452 },
453 {
454 .name = "SW_CONV_END",
455 .start = AB8500_INT_GP_SW_ADC_CONV_END,
456 .end = AB8500_INT_GP_SW_ADC_CONV_END,
457 .flags = IORESOURCE_IRQ,
458 },
459};
460
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200461static struct resource __devinitdata ab8500_rtc_resources[] = {
Rabin Vincent62579262010-05-19 11:39:02 +0200462 {
463 .name = "60S",
464 .start = AB8500_INT_RTC_60S,
465 .end = AB8500_INT_RTC_60S,
466 .flags = IORESOURCE_IRQ,
467 },
468 {
469 .name = "ALARM",
470 .start = AB8500_INT_RTC_ALARM,
471 .end = AB8500_INT_RTC_ALARM,
472 .flags = IORESOURCE_IRQ,
473 },
474};
475
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200476static struct resource __devinitdata ab8500_poweronkey_db_resources[] = {
Sundar R Iyer77686512010-09-05 12:18:47 -0700477 {
478 .name = "ONKEY_DBF",
479 .start = AB8500_INT_PON_KEY1DB_F,
480 .end = AB8500_INT_PON_KEY1DB_F,
481 .flags = IORESOURCE_IRQ,
482 },
483 {
484 .name = "ONKEY_DBR",
485 .start = AB8500_INT_PON_KEY1DB_R,
486 .end = AB8500_INT_PON_KEY1DB_R,
487 .flags = IORESOURCE_IRQ,
488 },
489};
490
Linus Walleij6af75ec2011-06-09 23:57:45 +0200491static struct resource __devinitdata ab8500_av_acc_detect_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100492 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200493 .name = "ACC_DETECT_1DB_F",
494 .start = AB8500_INT_ACC_DETECT_1DB_F,
495 .end = AB8500_INT_ACC_DETECT_1DB_F,
496 .flags = IORESOURCE_IRQ,
Mattias Walline098aded72010-12-02 15:40:31 +0100497 },
498 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200499 .name = "ACC_DETECT_1DB_R",
500 .start = AB8500_INT_ACC_DETECT_1DB_R,
501 .end = AB8500_INT_ACC_DETECT_1DB_R,
502 .flags = IORESOURCE_IRQ,
Mattias Walline098aded72010-12-02 15:40:31 +0100503 },
504 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200505 .name = "ACC_DETECT_21DB_F",
506 .start = AB8500_INT_ACC_DETECT_21DB_F,
507 .end = AB8500_INT_ACC_DETECT_21DB_F,
508 .flags = IORESOURCE_IRQ,
509 },
510 {
511 .name = "ACC_DETECT_21DB_R",
512 .start = AB8500_INT_ACC_DETECT_21DB_R,
513 .end = AB8500_INT_ACC_DETECT_21DB_R,
514 .flags = IORESOURCE_IRQ,
515 },
516 {
517 .name = "ACC_DETECT_22DB_F",
518 .start = AB8500_INT_ACC_DETECT_22DB_F,
519 .end = AB8500_INT_ACC_DETECT_22DB_F,
520 .flags = IORESOURCE_IRQ,
521 },
522 {
523 .name = "ACC_DETECT_22DB_R",
524 .start = AB8500_INT_ACC_DETECT_22DB_R,
525 .end = AB8500_INT_ACC_DETECT_22DB_R,
526 .flags = IORESOURCE_IRQ,
527 },
528};
529
530static struct resource __devinitdata ab8500_charger_resources[] = {
531 {
Mattias Walline098aded72010-12-02 15:40:31 +0100532 .name = "MAIN_CH_UNPLUG_DET",
533 .start = AB8500_INT_MAIN_CH_UNPLUG_DET,
534 .end = AB8500_INT_MAIN_CH_UNPLUG_DET,
535 .flags = IORESOURCE_IRQ,
536 },
537 {
538 .name = "MAIN_CHARGE_PLUG_DET",
539 .start = AB8500_INT_MAIN_CH_PLUG_DET,
540 .end = AB8500_INT_MAIN_CH_PLUG_DET,
541 .flags = IORESOURCE_IRQ,
542 },
543 {
Mattias Walline098aded72010-12-02 15:40:31 +0100544 .name = "VBUS_DET_R",
545 .start = AB8500_INT_VBUS_DET_R,
546 .end = AB8500_INT_VBUS_DET_R,
547 .flags = IORESOURCE_IRQ,
548 },
549 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200550 .name = "VBUS_DET_F",
551 .start = AB8500_INT_VBUS_DET_F,
552 .end = AB8500_INT_VBUS_DET_F,
Mattias Walline098aded72010-12-02 15:40:31 +0100553 .flags = IORESOURCE_IRQ,
554 },
555 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200556 .name = "USB_LINK_STATUS",
557 .start = AB8500_INT_USB_LINK_STATUS,
558 .end = AB8500_INT_USB_LINK_STATUS,
559 .flags = IORESOURCE_IRQ,
560 },
561 {
Mattias Walline098aded72010-12-02 15:40:31 +0100562 .name = "VBUS_OVV",
563 .start = AB8500_INT_VBUS_OVV,
564 .end = AB8500_INT_VBUS_OVV,
565 .flags = IORESOURCE_IRQ,
566 },
567 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200568 .name = "USB_CH_TH_PROT_R",
569 .start = AB8500_INT_USB_CH_TH_PROT_R,
570 .end = AB8500_INT_USB_CH_TH_PROT_R,
Mattias Walline098aded72010-12-02 15:40:31 +0100571 .flags = IORESOURCE_IRQ,
572 },
573 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200574 .name = "USB_CH_TH_PROT_F",
575 .start = AB8500_INT_USB_CH_TH_PROT_F,
576 .end = AB8500_INT_USB_CH_TH_PROT_F,
Mattias Walline098aded72010-12-02 15:40:31 +0100577 .flags = IORESOURCE_IRQ,
578 },
579 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200580 .name = "MAIN_EXT_CH_NOT_OK",
581 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
582 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
583 .flags = IORESOURCE_IRQ,
584 },
585 {
586 .name = "MAIN_CH_TH_PROT_R",
587 .start = AB8500_INT_MAIN_CH_TH_PROT_R,
588 .end = AB8500_INT_MAIN_CH_TH_PROT_R,
589 .flags = IORESOURCE_IRQ,
590 },
591 {
592 .name = "MAIN_CH_TH_PROT_F",
593 .start = AB8500_INT_MAIN_CH_TH_PROT_F,
594 .end = AB8500_INT_MAIN_CH_TH_PROT_F,
595 .flags = IORESOURCE_IRQ,
596 },
597 {
598 .name = "USB_CHARGER_NOT_OKR",
Bengt Jonssona9823622012-03-08 14:01:57 +0100599 .start = AB8500_INT_USB_CHARGER_NOT_OKR,
600 .end = AB8500_INT_USB_CHARGER_NOT_OKR,
Linus Walleij6af75ec2011-06-09 23:57:45 +0200601 .flags = IORESOURCE_IRQ,
602 },
603 {
604 .name = "CH_WD_EXP",
605 .start = AB8500_INT_CH_WD_EXP,
606 .end = AB8500_INT_CH_WD_EXP,
607 .flags = IORESOURCE_IRQ,
608 },
609};
610
611static struct resource __devinitdata ab8500_btemp_resources[] = {
612 {
613 .name = "BAT_CTRL_INDB",
614 .start = AB8500_INT_BAT_CTRL_INDB,
615 .end = AB8500_INT_BAT_CTRL_INDB,
Mattias Walline098aded72010-12-02 15:40:31 +0100616 .flags = IORESOURCE_IRQ,
617 },
618 {
619 .name = "BTEMP_LOW",
620 .start = AB8500_INT_BTEMP_LOW,
621 .end = AB8500_INT_BTEMP_LOW,
622 .flags = IORESOURCE_IRQ,
623 },
624 {
625 .name = "BTEMP_HIGH",
626 .start = AB8500_INT_BTEMP_HIGH,
627 .end = AB8500_INT_BTEMP_HIGH,
628 .flags = IORESOURCE_IRQ,
629 },
630 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200631 .name = "BTEMP_LOW_MEDIUM",
632 .start = AB8500_INT_BTEMP_LOW_MEDIUM,
633 .end = AB8500_INT_BTEMP_LOW_MEDIUM,
Mattias Walline098aded72010-12-02 15:40:31 +0100634 .flags = IORESOURCE_IRQ,
635 },
636 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200637 .name = "BTEMP_MEDIUM_HIGH",
638 .start = AB8500_INT_BTEMP_MEDIUM_HIGH,
639 .end = AB8500_INT_BTEMP_MEDIUM_HIGH,
Mattias Walline098aded72010-12-02 15:40:31 +0100640 .flags = IORESOURCE_IRQ,
641 },
642};
643
Linus Walleij6af75ec2011-06-09 23:57:45 +0200644static struct resource __devinitdata ab8500_fg_resources[] = {
645 {
646 .name = "NCONV_ACCU",
647 .start = AB8500_INT_CCN_CONV_ACC,
648 .end = AB8500_INT_CCN_CONV_ACC,
649 .flags = IORESOURCE_IRQ,
650 },
651 {
652 .name = "BATT_OVV",
653 .start = AB8500_INT_BATT_OVV,
654 .end = AB8500_INT_BATT_OVV,
655 .flags = IORESOURCE_IRQ,
656 },
657 {
658 .name = "LOW_BAT_F",
659 .start = AB8500_INT_LOW_BAT_F,
660 .end = AB8500_INT_LOW_BAT_F,
661 .flags = IORESOURCE_IRQ,
662 },
663 {
664 .name = "LOW_BAT_R",
665 .start = AB8500_INT_LOW_BAT_R,
666 .end = AB8500_INT_LOW_BAT_R,
667 .flags = IORESOURCE_IRQ,
668 },
669 {
670 .name = "CC_INT_CALIB",
671 .start = AB8500_INT_CC_INT_CALIB,
672 .end = AB8500_INT_CC_INT_CALIB,
673 .flags = IORESOURCE_IRQ,
674 },
Bengt Jonssona9823622012-03-08 14:01:57 +0100675 {
676 .name = "CCEOC",
677 .start = AB8500_INT_CCEOC,
678 .end = AB8500_INT_CCEOC,
679 .flags = IORESOURCE_IRQ,
680 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200681};
682
683static struct resource __devinitdata ab8500_chargalg_resources[] = {};
684
Axel Lindf720642011-11-10 09:56:18 +0800685#ifdef CONFIG_DEBUG_FS
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200686static struct resource __devinitdata ab8500_debug_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100687 {
688 .name = "IRQ_FIRST",
689 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
690 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
691 .flags = IORESOURCE_IRQ,
692 },
693 {
694 .name = "IRQ_LAST",
Bengt Jonssona9823622012-03-08 14:01:57 +0100695 .start = AB8500_INT_XTAL32K_KO,
696 .end = AB8500_INT_XTAL32K_KO,
Mattias Walline098aded72010-12-02 15:40:31 +0100697 .flags = IORESOURCE_IRQ,
698 },
699};
Axel Lindf720642011-11-10 09:56:18 +0800700#endif
Mattias Walline098aded72010-12-02 15:40:31 +0100701
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200702static struct resource __devinitdata ab8500_usb_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100703 {
704 .name = "ID_WAKEUP_R",
705 .start = AB8500_INT_ID_WAKEUP_R,
706 .end = AB8500_INT_ID_WAKEUP_R,
707 .flags = IORESOURCE_IRQ,
708 },
709 {
710 .name = "ID_WAKEUP_F",
711 .start = AB8500_INT_ID_WAKEUP_F,
712 .end = AB8500_INT_ID_WAKEUP_F,
713 .flags = IORESOURCE_IRQ,
714 },
715 {
716 .name = "VBUS_DET_F",
717 .start = AB8500_INT_VBUS_DET_F,
718 .end = AB8500_INT_VBUS_DET_F,
719 .flags = IORESOURCE_IRQ,
720 },
721 {
722 .name = "VBUS_DET_R",
723 .start = AB8500_INT_VBUS_DET_R,
724 .end = AB8500_INT_VBUS_DET_R,
725 .flags = IORESOURCE_IRQ,
726 },
Mattias Wallin92d50a42010-12-07 11:20:47 +0100727 {
728 .name = "USB_LINK_STATUS",
729 .start = AB8500_INT_USB_LINK_STATUS,
730 .end = AB8500_INT_USB_LINK_STATUS,
731 .flags = IORESOURCE_IRQ,
732 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200733 {
734 .name = "USB_ADP_PROBE_PLUG",
735 .start = AB8500_INT_ADP_PROBE_PLUG,
736 .end = AB8500_INT_ADP_PROBE_PLUG,
737 .flags = IORESOURCE_IRQ,
738 },
739 {
740 .name = "USB_ADP_PROBE_UNPLUG",
741 .start = AB8500_INT_ADP_PROBE_UNPLUG,
742 .end = AB8500_INT_ADP_PROBE_UNPLUG,
743 .flags = IORESOURCE_IRQ,
744 },
Mattias Walline098aded72010-12-02 15:40:31 +0100745};
746
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200747static struct resource __devinitdata ab8500_temp_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100748 {
749 .name = "AB8500_TEMP_WARM",
750 .start = AB8500_INT_TEMP_WARM,
751 .end = AB8500_INT_TEMP_WARM,
752 .flags = IORESOURCE_IRQ,
753 },
754};
755
Linus Walleijd6255522012-02-20 21:42:24 +0100756static struct mfd_cell __devinitdata abx500_common_devs[] = {
Mattias Wallin5814fc32010-09-13 16:05:04 +0200757#ifdef CONFIG_DEBUG_FS
758 {
759 .name = "ab8500-debug",
Mattias Walline098aded72010-12-02 15:40:31 +0100760 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
761 .resources = ab8500_debug_resources,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200762 },
763#endif
Rabin Vincent62579262010-05-19 11:39:02 +0200764 {
Mattias Walline098aded72010-12-02 15:40:31 +0100765 .name = "ab8500-sysctrl",
766 },
767 {
768 .name = "ab8500-regulator",
769 },
770 {
Rabin Vincent62579262010-05-19 11:39:02 +0200771 .name = "ab8500-gpadc",
772 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
773 .resources = ab8500_gpadc_resources,
774 },
775 {
776 .name = "ab8500-rtc",
777 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
778 .resources = ab8500_rtc_resources,
779 },
Arun Murthyf0f05b12010-09-06 12:24:52 +0530780 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200781 .name = "ab8500-charger",
782 .num_resources = ARRAY_SIZE(ab8500_charger_resources),
783 .resources = ab8500_charger_resources,
Mattias Walline098aded72010-12-02 15:40:31 +0100784 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200785 {
786 .name = "ab8500-btemp",
787 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
788 .resources = ab8500_btemp_resources,
789 },
790 {
791 .name = "ab8500-fg",
792 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
793 .resources = ab8500_fg_resources,
794 },
795 {
796 .name = "ab8500-chargalg",
797 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
798 .resources = ab8500_chargalg_resources,
799 },
800 {
801 .name = "ab8500-acc-det",
802 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
803 .resources = ab8500_av_acc_detect_resources,
804 },
805 {
806 .name = "ab8500-codec",
807 },
Linus Walleijd6255522012-02-20 21:42:24 +0100808
Mattias Walline098aded72010-12-02 15:40:31 +0100809 {
810 .name = "ab8500-poweron-key",
811 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
812 .resources = ab8500_poweronkey_db_resources,
813 },
814 {
Arun Murthyf0f05b12010-09-06 12:24:52 +0530815 .name = "ab8500-pwm",
816 .id = 1,
817 },
818 {
819 .name = "ab8500-pwm",
820 .id = 2,
821 },
822 {
823 .name = "ab8500-pwm",
824 .id = 3,
825 },
Mattias Walline098aded72010-12-02 15:40:31 +0100826 { .name = "ab8500-leds", },
Sundar R Iyer77686512010-09-05 12:18:47 -0700827 {
Mattias Walline098aded72010-12-02 15:40:31 +0100828 .name = "ab8500-denc",
829 },
830 {
831 .name = "ab8500-temp",
832 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
833 .resources = ab8500_temp_resources,
Sundar R Iyer77686512010-09-05 12:18:47 -0700834 },
Rabin Vincent62579262010-05-19 11:39:02 +0200835};
836
Linus Walleijd6255522012-02-20 21:42:24 +0100837static struct mfd_cell __devinitdata ab8500_devs[] = {
838 {
839 .name = "ab8500-gpio",
840 .num_resources = ARRAY_SIZE(ab8500_gpio_resources),
841 .resources = ab8500_gpio_resources,
842 },
843 {
844 .name = "ab8500-usb",
845 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
846 .resources = ab8500_usb_resources,
847 },
848};
849
850static struct mfd_cell __devinitdata ab9540_devs[] = {
851 {
852 .name = "ab8500-gpio",
853 .num_resources = ARRAY_SIZE(ab9540_gpio_resources),
854 .resources = ab9540_gpio_resources,
855 },
856 {
857 .name = "ab9540-usb",
858 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
859 .resources = ab8500_usb_resources,
860 },
861};
862
Mattias Wallincca69b62010-12-02 15:09:36 +0100863static ssize_t show_chip_id(struct device *dev,
864 struct device_attribute *attr, char *buf)
865{
866 struct ab8500 *ab8500;
867
868 ab8500 = dev_get_drvdata(dev);
869 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
870}
871
Mattias Walline5c238c2011-03-02 11:52:36 +0100872/*
873 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
874 * 0x01 Swoff bit programming
875 * 0x02 Thermal protection activation
876 * 0x04 Vbat lower then BattOk falling threshold
877 * 0x08 Watchdog expired
878 * 0x10 Non presence of 32kHz clock
879 * 0x20 Battery level lower than power on reset threshold
880 * 0x40 Power on key 1 pressed longer than 10 seconds
881 * 0x80 DB8500 thermal shutdown
882 */
883static ssize_t show_switch_off_status(struct device *dev,
884 struct device_attribute *attr, char *buf)
885{
886 int ret;
887 u8 value;
888 struct ab8500 *ab8500;
889
890 ab8500 = dev_get_drvdata(dev);
891 ret = get_register_interruptible(ab8500, AB8500_RTC,
892 AB8500_SWITCH_OFF_STATUS, &value);
893 if (ret < 0)
894 return ret;
895 return sprintf(buf, "%#x\n", value);
896}
897
Andrew Lynnb4a31032011-10-11 10:49:47 +0200898/*
899 * ab8500 has turned on due to (TURN_ON_STATUS):
900 * 0x01 PORnVbat
901 * 0x02 PonKey1dbF
902 * 0x04 PonKey2dbF
903 * 0x08 RTCAlarm
904 * 0x10 MainChDet
905 * 0x20 VbusDet
906 * 0x40 UsbIDDetect
907 * 0x80 Reserved
908 */
909static ssize_t show_turn_on_status(struct device *dev,
910 struct device_attribute *attr, char *buf)
911{
912 int ret;
913 u8 value;
914 struct ab8500 *ab8500;
915
916 ab8500 = dev_get_drvdata(dev);
917 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
918 AB8500_TURN_ON_STATUS, &value);
919 if (ret < 0)
920 return ret;
921 return sprintf(buf, "%#x\n", value);
922}
923
Linus Walleijd6255522012-02-20 21:42:24 +0100924static ssize_t show_ab9540_dbbrstn(struct device *dev,
925 struct device_attribute *attr, char *buf)
926{
927 struct ab8500 *ab8500;
928 int ret;
929 u8 value;
930
931 ab8500 = dev_get_drvdata(dev);
932
933 ret = get_register_interruptible(ab8500, AB8500_REGU_CTRL2,
934 AB9540_MODEM_CTRL2_REG, &value);
935 if (ret < 0)
936 return ret;
937
938 return sprintf(buf, "%d\n",
939 (value & AB9540_MODEM_CTRL2_SWDBBRSTN_BIT) ? 1 : 0);
940}
941
942static ssize_t store_ab9540_dbbrstn(struct device *dev,
943 struct device_attribute *attr, const char *buf, size_t count)
944{
945 struct ab8500 *ab8500;
946 int ret = count;
947 int err;
948 u8 bitvalues;
949
950 ab8500 = dev_get_drvdata(dev);
951
952 if (count > 0) {
953 switch (buf[0]) {
954 case '0':
955 bitvalues = 0;
956 break;
957 case '1':
958 bitvalues = AB9540_MODEM_CTRL2_SWDBBRSTN_BIT;
959 break;
960 default:
961 goto exit;
962 }
963
964 err = mask_and_set_register_interruptible(ab8500,
965 AB8500_REGU_CTRL2, AB9540_MODEM_CTRL2_REG,
966 AB9540_MODEM_CTRL2_SWDBBRSTN_BIT, bitvalues);
967 if (err)
968 dev_info(ab8500->dev,
969 "Failed to set DBBRSTN %c, err %#x\n",
970 buf[0], err);
971 }
972
973exit:
974 return ret;
975}
976
Mattias Wallincca69b62010-12-02 15:09:36 +0100977static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
Mattias Walline5c238c2011-03-02 11:52:36 +0100978static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
Andrew Lynnb4a31032011-10-11 10:49:47 +0200979static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
Linus Walleijd6255522012-02-20 21:42:24 +0100980static DEVICE_ATTR(dbbrstn, S_IRUGO | S_IWUSR,
981 show_ab9540_dbbrstn, store_ab9540_dbbrstn);
Mattias Wallincca69b62010-12-02 15:09:36 +0100982
983static struct attribute *ab8500_sysfs_entries[] = {
984 &dev_attr_chip_id.attr,
Mattias Walline5c238c2011-03-02 11:52:36 +0100985 &dev_attr_switch_off_status.attr,
Andrew Lynnb4a31032011-10-11 10:49:47 +0200986 &dev_attr_turn_on_status.attr,
Mattias Wallincca69b62010-12-02 15:09:36 +0100987 NULL,
988};
989
Linus Walleijd6255522012-02-20 21:42:24 +0100990static struct attribute *ab9540_sysfs_entries[] = {
991 &dev_attr_chip_id.attr,
992 &dev_attr_switch_off_status.attr,
993 &dev_attr_turn_on_status.attr,
994 &dev_attr_dbbrstn.attr,
995 NULL,
996};
997
Mattias Wallincca69b62010-12-02 15:09:36 +0100998static struct attribute_group ab8500_attr_group = {
999 .attrs = ab8500_sysfs_entries,
1000};
1001
Linus Walleijd6255522012-02-20 21:42:24 +01001002static struct attribute_group ab9540_attr_group = {
1003 .attrs = ab9540_sysfs_entries,
1004};
1005
Linus Walleij0f6208372012-02-20 21:42:10 +01001006int __devinit ab8500_init(struct ab8500 *ab8500, enum ab8500_version version)
Rabin Vincent62579262010-05-19 11:39:02 +02001007{
1008 struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev);
1009 int ret;
1010 int i;
Mattias Wallin47c16972010-09-10 17:47:56 +02001011 u8 value;
Rabin Vincent62579262010-05-19 11:39:02 +02001012
1013 if (plat)
1014 ab8500->irq_base = plat->irq_base;
1015
1016 mutex_init(&ab8500->lock);
1017 mutex_init(&ab8500->irq_lock);
1018
Linus Walleij0f6208372012-02-20 21:42:10 +01001019 if (version != AB8500_VERSION_UNDEFINED)
1020 ab8500->version = version;
1021 else {
1022 ret = get_register_interruptible(ab8500, AB8500_MISC,
1023 AB8500_IC_NAME_REG, &value);
1024 if (ret < 0)
1025 return ret;
1026
1027 ab8500->version = value;
1028 }
1029
Mattias Wallin47c16972010-09-10 17:47:56 +02001030 ret = get_register_interruptible(ab8500, AB8500_MISC,
1031 AB8500_REV_REG, &value);
Rabin Vincent62579262010-05-19 11:39:02 +02001032 if (ret < 0)
1033 return ret;
1034
Mattias Wallin47c16972010-09-10 17:47:56 +02001035 ab8500->chip_id = value;
Rabin Vincent62579262010-05-19 11:39:02 +02001036
Linus Walleij0f6208372012-02-20 21:42:10 +01001037 dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n",
1038 ab8500_version_str[ab8500->version],
1039 ab8500->chip_id >> 4,
1040 ab8500->chip_id & 0x0F);
1041
Linus Walleijd6255522012-02-20 21:42:24 +01001042 /* Configure AB8500 or AB9540 IRQ */
Bengt Jonssona9823622012-03-08 14:01:57 +01001043 if (is_ab9540(ab8500) || is_ab8505(ab8500)) {
Linus Walleijd6255522012-02-20 21:42:24 +01001044 ab8500->mask_size = AB9540_NUM_IRQ_REGS;
1045 ab8500->irq_reg_offset = ab9540_irq_regoffset;
1046 } else {
1047 ab8500->mask_size = AB8500_NUM_IRQ_REGS;
1048 ab8500->irq_reg_offset = ab8500_irq_regoffset;
1049 }
Linus Walleij2ced4452012-02-20 21:42:17 +01001050 ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL);
1051 if (!ab8500->mask)
1052 return -ENOMEM;
1053 ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL);
1054 if (!ab8500->oldmask) {
1055 ret = -ENOMEM;
1056 goto out_freemask;
1057 }
Mattias Walline5c238c2011-03-02 11:52:36 +01001058 /*
1059 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
1060 * 0x01 Swoff bit programming
1061 * 0x02 Thermal protection activation
1062 * 0x04 Vbat lower then BattOk falling threshold
1063 * 0x08 Watchdog expired
1064 * 0x10 Non presence of 32kHz clock
1065 * 0x20 Battery level lower than power on reset threshold
1066 * 0x40 Power on key 1 pressed longer than 10 seconds
1067 * 0x80 DB8500 thermal shutdown
1068 */
1069
1070 ret = get_register_interruptible(ab8500, AB8500_RTC,
1071 AB8500_SWITCH_OFF_STATUS, &value);
1072 if (ret < 0)
1073 return ret;
1074 dev_info(ab8500->dev, "switch off status: %#x", value);
1075
Rabin Vincent62579262010-05-19 11:39:02 +02001076 if (plat && plat->init)
1077 plat->init(ab8500);
1078
1079 /* Clear and mask all interrupts */
Linus Walleij2ced4452012-02-20 21:42:17 +01001080 for (i = 0; i < ab8500->mask_size; i++) {
Linus Walleij0f6208372012-02-20 21:42:10 +01001081 /*
1082 * Interrupt register 12 doesn't exist prior to AB8500 version
1083 * 2.0
1084 */
1085 if (ab8500->irq_reg_offset[i] == 11 &&
1086 is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +01001087 continue;
Rabin Vincent62579262010-05-19 11:39:02 +02001088
Mattias Wallin47c16972010-09-10 17:47:56 +02001089 get_register_interruptible(ab8500, AB8500_INTERRUPT,
Linus Walleij2ced4452012-02-20 21:42:17 +01001090 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
Mattias Wallin92d50a42010-12-07 11:20:47 +01001091 &value);
Mattias Wallin47c16972010-09-10 17:47:56 +02001092 set_register_interruptible(ab8500, AB8500_INTERRUPT,
Linus Walleij2ced4452012-02-20 21:42:17 +01001093 AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
Rabin Vincent62579262010-05-19 11:39:02 +02001094 }
1095
Mattias Wallin47c16972010-09-10 17:47:56 +02001096 ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
1097 if (ret)
Linus Walleij2ced4452012-02-20 21:42:17 +01001098 goto out_freeoldmask;
Mattias Wallin47c16972010-09-10 17:47:56 +02001099
Linus Walleij2ced4452012-02-20 21:42:17 +01001100 for (i = 0; i < ab8500->mask_size; i++)
Rabin Vincent62579262010-05-19 11:39:02 +02001101 ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
1102
1103 if (ab8500->irq_base) {
1104 ret = ab8500_irq_init(ab8500);
1105 if (ret)
Linus Walleij2ced4452012-02-20 21:42:17 +01001106 goto out_freeoldmask;
Rabin Vincent62579262010-05-19 11:39:02 +02001107
1108 ret = request_threaded_irq(ab8500->irq, NULL, ab8500_irq,
Mattias Wallin4f079982010-12-02 15:10:27 +01001109 IRQF_ONESHOT | IRQF_NO_SUSPEND,
1110 "ab8500", ab8500);
Rabin Vincent62579262010-05-19 11:39:02 +02001111 if (ret)
1112 goto out_removeirq;
1113 }
1114
Linus Walleijd6255522012-02-20 21:42:24 +01001115 ret = mfd_add_devices(ab8500->dev, 0, abx500_common_devs,
1116 ARRAY_SIZE(abx500_common_devs), NULL,
1117 ab8500->irq_base);
1118
1119 if (ret)
1120 goto out_freeirq;
1121
1122 if (is_ab9540(ab8500))
1123 ret = mfd_add_devices(ab8500->dev, 0, ab9540_devs,
1124 ARRAY_SIZE(ab9540_devs), NULL,
1125 ab8500->irq_base);
1126 else
1127 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
1128 ARRAY_SIZE(ab9540_devs), NULL,
Rabin Vincent62579262010-05-19 11:39:02 +02001129 ab8500->irq_base);
1130 if (ret)
1131 goto out_freeirq;
1132
Linus Walleijd6255522012-02-20 21:42:24 +01001133 if (is_ab9540(ab8500))
1134 ret = sysfs_create_group(&ab8500->dev->kobj,
1135 &ab9540_attr_group);
1136 else
1137 ret = sysfs_create_group(&ab8500->dev->kobj,
1138 &ab8500_attr_group);
Mattias Wallincca69b62010-12-02 15:09:36 +01001139 if (ret)
1140 dev_err(ab8500->dev, "error creating sysfs entries\n");
Linus Walleijd6255522012-02-20 21:42:24 +01001141 else
1142 return ret;
Rabin Vincent62579262010-05-19 11:39:02 +02001143
1144out_freeirq:
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001145 if (ab8500->irq_base)
Rabin Vincent62579262010-05-19 11:39:02 +02001146 free_irq(ab8500->irq, ab8500);
1147out_removeirq:
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001148 if (ab8500->irq_base)
Rabin Vincent62579262010-05-19 11:39:02 +02001149 ab8500_irq_remove(ab8500);
Linus Walleij2ced4452012-02-20 21:42:17 +01001150out_freeoldmask:
1151 kfree(ab8500->oldmask);
1152out_freemask:
1153 kfree(ab8500->mask);
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001154
Rabin Vincent62579262010-05-19 11:39:02 +02001155 return ret;
1156}
1157
1158int __devexit ab8500_exit(struct ab8500 *ab8500)
1159{
Linus Walleijd6255522012-02-20 21:42:24 +01001160 if (is_ab9540(ab8500))
1161 sysfs_remove_group(&ab8500->dev->kobj, &ab9540_attr_group);
1162 else
1163 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
Rabin Vincent62579262010-05-19 11:39:02 +02001164 mfd_remove_devices(ab8500->dev);
1165 if (ab8500->irq_base) {
1166 free_irq(ab8500->irq, ab8500);
1167 ab8500_irq_remove(ab8500);
1168 }
Linus Walleij2ced4452012-02-20 21:42:17 +01001169 kfree(ab8500->oldmask);
1170 kfree(ab8500->mask);
Rabin Vincent62579262010-05-19 11:39:02 +02001171
1172 return 0;
1173}
1174
Mattias Wallinadceed62011-03-02 11:51:11 +01001175MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
Rabin Vincent62579262010-05-19 11:39:02 +02001176MODULE_DESCRIPTION("AB8500 MFD core");
1177MODULE_LICENSE("GPL v2");