blob: 73907ad1e3d3917755bdd57d470f2a90f672744f [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
35#define AB8500_IT_SOURCE19_REG 0x12
36#define AB8500_IT_SOURCE20_REG 0x13
37#define AB8500_IT_SOURCE21_REG 0x14
38#define AB8500_IT_SOURCE22_REG 0x15
39#define AB8500_IT_SOURCE23_REG 0x16
40#define AB8500_IT_SOURCE24_REG 0x17
Rabin Vincent62579262010-05-19 11:39:02 +020041
42/*
43 * latch registers
44 */
Mattias Wallin47c16972010-09-10 17:47:56 +020045#define AB8500_IT_LATCH1_REG 0x20
46#define AB8500_IT_LATCH2_REG 0x21
47#define AB8500_IT_LATCH3_REG 0x22
48#define AB8500_IT_LATCH4_REG 0x23
49#define AB8500_IT_LATCH5_REG 0x24
50#define AB8500_IT_LATCH6_REG 0x25
51#define AB8500_IT_LATCH7_REG 0x26
52#define AB8500_IT_LATCH8_REG 0x27
53#define AB8500_IT_LATCH9_REG 0x28
54#define AB8500_IT_LATCH10_REG 0x29
Mattias Wallin92d50a42010-12-07 11:20:47 +010055#define AB8500_IT_LATCH12_REG 0x2B
Mattias Wallin47c16972010-09-10 17:47:56 +020056#define AB8500_IT_LATCH19_REG 0x32
57#define AB8500_IT_LATCH20_REG 0x33
58#define AB8500_IT_LATCH21_REG 0x34
59#define AB8500_IT_LATCH22_REG 0x35
60#define AB8500_IT_LATCH23_REG 0x36
61#define AB8500_IT_LATCH24_REG 0x37
Rabin Vincent62579262010-05-19 11:39:02 +020062
63/*
64 * mask registers
65 */
66
Mattias Wallin47c16972010-09-10 17:47:56 +020067#define AB8500_IT_MASK1_REG 0x40
68#define AB8500_IT_MASK2_REG 0x41
69#define AB8500_IT_MASK3_REG 0x42
70#define AB8500_IT_MASK4_REG 0x43
71#define AB8500_IT_MASK5_REG 0x44
72#define AB8500_IT_MASK6_REG 0x45
73#define AB8500_IT_MASK7_REG 0x46
74#define AB8500_IT_MASK8_REG 0x47
75#define AB8500_IT_MASK9_REG 0x48
76#define AB8500_IT_MASK10_REG 0x49
77#define AB8500_IT_MASK11_REG 0x4A
78#define AB8500_IT_MASK12_REG 0x4B
79#define AB8500_IT_MASK13_REG 0x4C
80#define AB8500_IT_MASK14_REG 0x4D
81#define AB8500_IT_MASK15_REG 0x4E
82#define AB8500_IT_MASK16_REG 0x4F
83#define AB8500_IT_MASK17_REG 0x50
84#define AB8500_IT_MASK18_REG 0x51
85#define AB8500_IT_MASK19_REG 0x52
86#define AB8500_IT_MASK20_REG 0x53
87#define AB8500_IT_MASK21_REG 0x54
88#define AB8500_IT_MASK22_REG 0x55
89#define AB8500_IT_MASK23_REG 0x56
90#define AB8500_IT_MASK24_REG 0x57
Rabin Vincent62579262010-05-19 11:39:02 +020091
Mattias Wallin47c16972010-09-10 17:47:56 +020092#define AB8500_REV_REG 0x80
Linus Walleij0f6208372012-02-20 21:42:10 +010093#define AB8500_IC_NAME_REG 0x82
Mattias Walline5c238c2011-03-02 11:52:36 +010094#define AB8500_SWITCH_OFF_STATUS 0x00
Rabin Vincent62579262010-05-19 11:39:02 +020095
Andrew Lynnb4a31032011-10-11 10:49:47 +020096#define AB8500_TURN_ON_STATUS 0x00
97
Rabin Vincent62579262010-05-19 11:39:02 +020098/*
99 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
Linus Walleij2ced4452012-02-20 21:42:17 +0100100 * numbers are indexed into this array with (num / 8). The interupts are
101 * defined in linux/mfd/ab8500.h
Rabin Vincent62579262010-05-19 11:39:02 +0200102 *
103 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
104 * offset 0.
105 */
Linus Walleij2ced4452012-02-20 21:42:17 +0100106/* AB8500 support */
Rabin Vincent62579262010-05-19 11:39:02 +0200107static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
Mattias Wallin92d50a42010-12-07 11:20:47 +0100108 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
Rabin Vincent62579262010-05-19 11:39:02 +0200109};
110
Linus Walleij0f6208372012-02-20 21:42:10 +0100111static const char ab8500_version_str[][7] = {
112 [AB8500_VERSION_AB8500] = "AB8500",
113 [AB8500_VERSION_AB8505] = "AB8505",
114 [AB8500_VERSION_AB9540] = "AB9540",
115 [AB8500_VERSION_AB8540] = "AB8540",
116};
117
Mattias Wallin47c16972010-09-10 17:47:56 +0200118static int ab8500_get_chip_id(struct device *dev)
119{
Mattias Wallin6bce7bf2010-12-02 15:08:32 +0100120 struct ab8500 *ab8500;
121
122 if (!dev)
123 return -EINVAL;
124 ab8500 = dev_get_drvdata(dev->parent);
125 return ab8500 ? (int)ab8500->chip_id : -EINVAL;
Mattias Wallin47c16972010-09-10 17:47:56 +0200126}
127
128static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
129 u8 reg, u8 data)
Rabin Vincent62579262010-05-19 11:39:02 +0200130{
131 int ret;
Mattias Wallin47c16972010-09-10 17:47:56 +0200132 /*
133 * Put the u8 bank and u8 register together into a an u16.
134 * The bank on higher 8 bits and register in lower 8 bits.
135 * */
136 u16 addr = ((u16)bank) << 8 | reg;
Rabin Vincent62579262010-05-19 11:39:02 +0200137
138 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
139
Mattias Wallin47c16972010-09-10 17:47:56 +0200140 ret = mutex_lock_interruptible(&ab8500->lock);
141 if (ret)
142 return ret;
143
144 ret = ab8500->write(ab8500, addr, data);
145 if (ret < 0)
146 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
147 addr, ret);
148 mutex_unlock(&ab8500->lock);
149
150 return ret;
151}
152
153static int ab8500_set_register(struct device *dev, u8 bank,
154 u8 reg, u8 value)
155{
156 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
157
158 return set_register_interruptible(ab8500, bank, reg, value);
159}
160
161static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
162 u8 reg, u8 *value)
163{
164 int ret;
165 /* put the u8 bank and u8 reg together into a an u16.
166 * bank on higher 8 bits and reg in lower */
167 u16 addr = ((u16)bank) << 8 | reg;
168
169 ret = mutex_lock_interruptible(&ab8500->lock);
170 if (ret)
171 return ret;
172
173 ret = ab8500->read(ab8500, addr);
174 if (ret < 0)
175 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
176 addr, ret);
177 else
178 *value = ret;
179
180 mutex_unlock(&ab8500->lock);
181 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
182
183 return ret;
184}
185
186static int ab8500_get_register(struct device *dev, u8 bank,
187 u8 reg, u8 *value)
188{
189 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
190
191 return get_register_interruptible(ab8500, bank, reg, value);
192}
193
194static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
195 u8 reg, u8 bitmask, u8 bitvalues)
196{
197 int ret;
198 u8 data;
199 /* put the u8 bank and u8 reg together into a an u16.
200 * bank on higher 8 bits and reg in lower */
201 u16 addr = ((u16)bank) << 8 | reg;
202
203 ret = mutex_lock_interruptible(&ab8500->lock);
204 if (ret)
205 return ret;
206
207 ret = ab8500->read(ab8500, addr);
208 if (ret < 0) {
209 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
210 addr, ret);
211 goto out;
212 }
213
214 data = (u8)ret;
215 data = (~bitmask & data) | (bitmask & bitvalues);
216
Rabin Vincent62579262010-05-19 11:39:02 +0200217 ret = ab8500->write(ab8500, addr, data);
218 if (ret < 0)
219 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
220 addr, ret);
221
Mattias Wallin47c16972010-09-10 17:47:56 +0200222 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, data);
Rabin Vincent62579262010-05-19 11:39:02 +0200223out:
224 mutex_unlock(&ab8500->lock);
225 return ret;
226}
Mattias Wallin47c16972010-09-10 17:47:56 +0200227
228static int ab8500_mask_and_set_register(struct device *dev,
229 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
230{
231 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
232
233 return mask_and_set_register_interruptible(ab8500, bank, reg,
234 bitmask, bitvalues);
235
236}
237
238static struct abx500_ops ab8500_ops = {
239 .get_chip_id = ab8500_get_chip_id,
240 .get_register = ab8500_get_register,
241 .set_register = ab8500_set_register,
242 .get_register_page = NULL,
243 .set_register_page = NULL,
244 .mask_and_set_register = ab8500_mask_and_set_register,
245 .event_registers_startup_state_get = NULL,
246 .startup_irq_enabled = NULL,
247};
Rabin Vincent62579262010-05-19 11:39:02 +0200248
Mark Brown9505a0a2010-12-11 13:16:08 +0000249static void ab8500_irq_lock(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200250{
Mark Brown9505a0a2010-12-11 13:16:08 +0000251 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Rabin Vincent62579262010-05-19 11:39:02 +0200252
253 mutex_lock(&ab8500->irq_lock);
254}
255
Mark Brown9505a0a2010-12-11 13:16:08 +0000256static void ab8500_irq_sync_unlock(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200257{
Mark Brown9505a0a2010-12-11 13:16:08 +0000258 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
Rabin Vincent62579262010-05-19 11:39:02 +0200259 int i;
260
Linus Walleij2ced4452012-02-20 21:42:17 +0100261 for (i = 0; i < ab8500->mask_size; i++) {
Rabin Vincent62579262010-05-19 11:39:02 +0200262 u8 old = ab8500->oldmask[i];
263 u8 new = ab8500->mask[i];
264 int reg;
265
266 if (new == old)
267 continue;
268
Linus Walleij0f6208372012-02-20 21:42:10 +0100269 /*
270 * Interrupt register 12 doesn't exist prior to AB8500 version
271 * 2.0
272 */
273 if (ab8500->irq_reg_offset[i] == 11 &&
274 is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100275 continue;
276
Rabin Vincent62579262010-05-19 11:39:02 +0200277 ab8500->oldmask[i] = new;
278
Linus Walleij2ced4452012-02-20 21:42:17 +0100279 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
Mattias Wallin47c16972010-09-10 17:47:56 +0200280 set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
Rabin Vincent62579262010-05-19 11:39:02 +0200281 }
282
283 mutex_unlock(&ab8500->irq_lock);
284}
285
Mark Brown9505a0a2010-12-11 13:16:08 +0000286static void ab8500_irq_mask(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200287{
Mark Brown9505a0a2010-12-11 13:16:08 +0000288 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
289 int offset = data->irq - ab8500->irq_base;
Rabin Vincent62579262010-05-19 11:39:02 +0200290 int index = offset / 8;
291 int mask = 1 << (offset % 8);
292
293 ab8500->mask[index] |= mask;
294}
295
Mark Brown9505a0a2010-12-11 13:16:08 +0000296static void ab8500_irq_unmask(struct irq_data *data)
Rabin Vincent62579262010-05-19 11:39:02 +0200297{
Mark Brown9505a0a2010-12-11 13:16:08 +0000298 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
299 int offset = data->irq - ab8500->irq_base;
Rabin Vincent62579262010-05-19 11:39:02 +0200300 int index = offset / 8;
301 int mask = 1 << (offset % 8);
302
303 ab8500->mask[index] &= ~mask;
304}
305
306static struct irq_chip ab8500_irq_chip = {
307 .name = "ab8500",
Mark Brown9505a0a2010-12-11 13:16:08 +0000308 .irq_bus_lock = ab8500_irq_lock,
309 .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
310 .irq_mask = ab8500_irq_mask,
Virupax Sadashivpetimathe6f93062011-10-11 10:49:17 +0200311 .irq_disable = ab8500_irq_mask,
Mark Brown9505a0a2010-12-11 13:16:08 +0000312 .irq_unmask = ab8500_irq_unmask,
Rabin Vincent62579262010-05-19 11:39:02 +0200313};
314
315static irqreturn_t ab8500_irq(int irq, void *dev)
316{
317 struct ab8500 *ab8500 = dev;
318 int i;
319
320 dev_vdbg(ab8500->dev, "interrupt\n");
321
Linus Walleij2ced4452012-02-20 21:42:17 +0100322 for (i = 0; i < ab8500->mask_size; i++) {
323 int regoffset = ab8500->irq_reg_offset[i];
Rabin Vincent62579262010-05-19 11:39:02 +0200324 int status;
Mattias Wallin47c16972010-09-10 17:47:56 +0200325 u8 value;
Rabin Vincent62579262010-05-19 11:39:02 +0200326
Linus Walleij0f6208372012-02-20 21:42:10 +0100327 /*
328 * Interrupt register 12 doesn't exist prior to AB8500 version
329 * 2.0
330 */
331 if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100332 continue;
333
Mattias Wallin47c16972010-09-10 17:47:56 +0200334 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
335 AB8500_IT_LATCH1_REG + regoffset, &value);
336 if (status < 0 || value == 0)
Rabin Vincent62579262010-05-19 11:39:02 +0200337 continue;
338
339 do {
Mattias Wallin88aec4f2010-12-02 15:06:49 +0100340 int bit = __ffs(value);
Rabin Vincent62579262010-05-19 11:39:02 +0200341 int line = i * 8 + bit;
342
343 handle_nested_irq(ab8500->irq_base + line);
Mattias Wallin47c16972010-09-10 17:47:56 +0200344 value &= ~(1 << bit);
345 } while (value);
Rabin Vincent62579262010-05-19 11:39:02 +0200346 }
347
348 return IRQ_HANDLED;
349}
350
351static int ab8500_irq_init(struct ab8500 *ab8500)
352{
353 int base = ab8500->irq_base;
354 int irq;
Linus Walleij2ced4452012-02-20 21:42:17 +0100355 int num_irqs;
Rabin Vincent62579262010-05-19 11:39:02 +0200356
Linus Walleij2ced4452012-02-20 21:42:17 +0100357 num_irqs = AB8500_NR_IRQS;
358
359 for (irq = base; irq < base + num_irqs; irq++) {
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000360 irq_set_chip_data(irq, ab8500);
361 irq_set_chip_and_handler(irq, &ab8500_irq_chip,
Rabin Vincent62579262010-05-19 11:39:02 +0200362 handle_simple_irq);
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000363 irq_set_nested_thread(irq, 1);
Rabin Vincent62579262010-05-19 11:39:02 +0200364#ifdef CONFIG_ARM
365 set_irq_flags(irq, IRQF_VALID);
366#else
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000367 irq_set_noprobe(irq);
Rabin Vincent62579262010-05-19 11:39:02 +0200368#endif
369 }
370
371 return 0;
372}
373
374static void ab8500_irq_remove(struct ab8500 *ab8500)
375{
376 int base = ab8500->irq_base;
377 int irq;
Linus Walleij2ced4452012-02-20 21:42:17 +0100378 int num_irqs;
Rabin Vincent62579262010-05-19 11:39:02 +0200379
Linus Walleij2ced4452012-02-20 21:42:17 +0100380 num_irqs = AB8500_NR_IRQS;
381
382 for (irq = base; irq < base + num_irqs; irq++) {
Rabin Vincent62579262010-05-19 11:39:02 +0200383#ifdef CONFIG_ARM
384 set_irq_flags(irq, 0);
385#endif
Thomas Gleixnerd5bb1222011-03-25 11:12:32 +0000386 irq_set_chip_and_handler(irq, NULL, NULL);
387 irq_set_chip_data(irq, NULL);
Rabin Vincent62579262010-05-19 11:39:02 +0200388 }
389}
390
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200391static struct resource __devinitdata ab8500_gpio_resources[] = {
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530392 {
393 .name = "GPIO_INT6",
394 .start = AB8500_INT_GPIO6R,
395 .end = AB8500_INT_GPIO41F,
396 .flags = IORESOURCE_IRQ,
397 }
398};
399
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200400static struct resource __devinitdata ab8500_gpadc_resources[] = {
Rabin Vincent62579262010-05-19 11:39:02 +0200401 {
402 .name = "HW_CONV_END",
403 .start = AB8500_INT_GP_HW_ADC_CONV_END,
404 .end = AB8500_INT_GP_HW_ADC_CONV_END,
405 .flags = IORESOURCE_IRQ,
406 },
407 {
408 .name = "SW_CONV_END",
409 .start = AB8500_INT_GP_SW_ADC_CONV_END,
410 .end = AB8500_INT_GP_SW_ADC_CONV_END,
411 .flags = IORESOURCE_IRQ,
412 },
413};
414
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200415static struct resource __devinitdata ab8500_rtc_resources[] = {
Rabin Vincent62579262010-05-19 11:39:02 +0200416 {
417 .name = "60S",
418 .start = AB8500_INT_RTC_60S,
419 .end = AB8500_INT_RTC_60S,
420 .flags = IORESOURCE_IRQ,
421 },
422 {
423 .name = "ALARM",
424 .start = AB8500_INT_RTC_ALARM,
425 .end = AB8500_INT_RTC_ALARM,
426 .flags = IORESOURCE_IRQ,
427 },
428};
429
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200430static struct resource __devinitdata ab8500_poweronkey_db_resources[] = {
Sundar R Iyer77686512010-09-05 12:18:47 -0700431 {
432 .name = "ONKEY_DBF",
433 .start = AB8500_INT_PON_KEY1DB_F,
434 .end = AB8500_INT_PON_KEY1DB_F,
435 .flags = IORESOURCE_IRQ,
436 },
437 {
438 .name = "ONKEY_DBR",
439 .start = AB8500_INT_PON_KEY1DB_R,
440 .end = AB8500_INT_PON_KEY1DB_R,
441 .flags = IORESOURCE_IRQ,
442 },
443};
444
Linus Walleij6af75ec2011-06-09 23:57:45 +0200445static struct resource __devinitdata ab8500_av_acc_detect_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100446 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200447 .name = "ACC_DETECT_1DB_F",
448 .start = AB8500_INT_ACC_DETECT_1DB_F,
449 .end = AB8500_INT_ACC_DETECT_1DB_F,
450 .flags = IORESOURCE_IRQ,
Mattias Walline098aded72010-12-02 15:40:31 +0100451 },
452 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200453 .name = "ACC_DETECT_1DB_R",
454 .start = AB8500_INT_ACC_DETECT_1DB_R,
455 .end = AB8500_INT_ACC_DETECT_1DB_R,
456 .flags = IORESOURCE_IRQ,
Mattias Walline098aded72010-12-02 15:40:31 +0100457 },
458 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200459 .name = "ACC_DETECT_21DB_F",
460 .start = AB8500_INT_ACC_DETECT_21DB_F,
461 .end = AB8500_INT_ACC_DETECT_21DB_F,
462 .flags = IORESOURCE_IRQ,
463 },
464 {
465 .name = "ACC_DETECT_21DB_R",
466 .start = AB8500_INT_ACC_DETECT_21DB_R,
467 .end = AB8500_INT_ACC_DETECT_21DB_R,
468 .flags = IORESOURCE_IRQ,
469 },
470 {
471 .name = "ACC_DETECT_22DB_F",
472 .start = AB8500_INT_ACC_DETECT_22DB_F,
473 .end = AB8500_INT_ACC_DETECT_22DB_F,
474 .flags = IORESOURCE_IRQ,
475 },
476 {
477 .name = "ACC_DETECT_22DB_R",
478 .start = AB8500_INT_ACC_DETECT_22DB_R,
479 .end = AB8500_INT_ACC_DETECT_22DB_R,
480 .flags = IORESOURCE_IRQ,
481 },
482};
483
484static struct resource __devinitdata ab8500_charger_resources[] = {
485 {
Mattias Walline098aded72010-12-02 15:40:31 +0100486 .name = "MAIN_CH_UNPLUG_DET",
487 .start = AB8500_INT_MAIN_CH_UNPLUG_DET,
488 .end = AB8500_INT_MAIN_CH_UNPLUG_DET,
489 .flags = IORESOURCE_IRQ,
490 },
491 {
492 .name = "MAIN_CHARGE_PLUG_DET",
493 .start = AB8500_INT_MAIN_CH_PLUG_DET,
494 .end = AB8500_INT_MAIN_CH_PLUG_DET,
495 .flags = IORESOURCE_IRQ,
496 },
497 {
Mattias Walline098aded72010-12-02 15:40:31 +0100498 .name = "VBUS_DET_R",
499 .start = AB8500_INT_VBUS_DET_R,
500 .end = AB8500_INT_VBUS_DET_R,
501 .flags = IORESOURCE_IRQ,
502 },
503 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200504 .name = "VBUS_DET_F",
505 .start = AB8500_INT_VBUS_DET_F,
506 .end = AB8500_INT_VBUS_DET_F,
Mattias Walline098aded72010-12-02 15:40:31 +0100507 .flags = IORESOURCE_IRQ,
508 },
509 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200510 .name = "USB_LINK_STATUS",
511 .start = AB8500_INT_USB_LINK_STATUS,
512 .end = AB8500_INT_USB_LINK_STATUS,
513 .flags = IORESOURCE_IRQ,
514 },
515 {
516 .name = "USB_CHARGE_DET_DONE",
517 .start = AB8500_INT_USB_CHG_DET_DONE,
518 .end = AB8500_INT_USB_CHG_DET_DONE,
Mattias Walline098aded72010-12-02 15:40:31 +0100519 .flags = IORESOURCE_IRQ,
520 },
521 {
522 .name = "VBUS_OVV",
523 .start = AB8500_INT_VBUS_OVV,
524 .end = AB8500_INT_VBUS_OVV,
525 .flags = IORESOURCE_IRQ,
526 },
527 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200528 .name = "USB_CH_TH_PROT_R",
529 .start = AB8500_INT_USB_CH_TH_PROT_R,
530 .end = AB8500_INT_USB_CH_TH_PROT_R,
Mattias Walline098aded72010-12-02 15:40:31 +0100531 .flags = IORESOURCE_IRQ,
532 },
533 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200534 .name = "USB_CH_TH_PROT_F",
535 .start = AB8500_INT_USB_CH_TH_PROT_F,
536 .end = AB8500_INT_USB_CH_TH_PROT_F,
Mattias Walline098aded72010-12-02 15:40:31 +0100537 .flags = IORESOURCE_IRQ,
538 },
539 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200540 .name = "MAIN_EXT_CH_NOT_OK",
541 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
542 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
543 .flags = IORESOURCE_IRQ,
544 },
545 {
546 .name = "MAIN_CH_TH_PROT_R",
547 .start = AB8500_INT_MAIN_CH_TH_PROT_R,
548 .end = AB8500_INT_MAIN_CH_TH_PROT_R,
549 .flags = IORESOURCE_IRQ,
550 },
551 {
552 .name = "MAIN_CH_TH_PROT_F",
553 .start = AB8500_INT_MAIN_CH_TH_PROT_F,
554 .end = AB8500_INT_MAIN_CH_TH_PROT_F,
555 .flags = IORESOURCE_IRQ,
556 },
557 {
558 .name = "USB_CHARGER_NOT_OKR",
559 .start = AB8500_INT_USB_CHARGER_NOT_OK,
560 .end = AB8500_INT_USB_CHARGER_NOT_OK,
561 .flags = IORESOURCE_IRQ,
562 },
563 {
564 .name = "USB_CHARGER_NOT_OKF",
565 .start = AB8500_INT_USB_CHARGER_NOT_OKF,
566 .end = AB8500_INT_USB_CHARGER_NOT_OKF,
567 .flags = IORESOURCE_IRQ,
568 },
569 {
570 .name = "CH_WD_EXP",
571 .start = AB8500_INT_CH_WD_EXP,
572 .end = AB8500_INT_CH_WD_EXP,
573 .flags = IORESOURCE_IRQ,
574 },
575};
576
577static struct resource __devinitdata ab8500_btemp_resources[] = {
578 {
579 .name = "BAT_CTRL_INDB",
580 .start = AB8500_INT_BAT_CTRL_INDB,
581 .end = AB8500_INT_BAT_CTRL_INDB,
Mattias Walline098aded72010-12-02 15:40:31 +0100582 .flags = IORESOURCE_IRQ,
583 },
584 {
585 .name = "BTEMP_LOW",
586 .start = AB8500_INT_BTEMP_LOW,
587 .end = AB8500_INT_BTEMP_LOW,
588 .flags = IORESOURCE_IRQ,
589 },
590 {
591 .name = "BTEMP_HIGH",
592 .start = AB8500_INT_BTEMP_HIGH,
593 .end = AB8500_INT_BTEMP_HIGH,
594 .flags = IORESOURCE_IRQ,
595 },
596 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200597 .name = "BTEMP_LOW_MEDIUM",
598 .start = AB8500_INT_BTEMP_LOW_MEDIUM,
599 .end = AB8500_INT_BTEMP_LOW_MEDIUM,
Mattias Walline098aded72010-12-02 15:40:31 +0100600 .flags = IORESOURCE_IRQ,
601 },
602 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200603 .name = "BTEMP_MEDIUM_HIGH",
604 .start = AB8500_INT_BTEMP_MEDIUM_HIGH,
605 .end = AB8500_INT_BTEMP_MEDIUM_HIGH,
Mattias Walline098aded72010-12-02 15:40:31 +0100606 .flags = IORESOURCE_IRQ,
607 },
608};
609
Linus Walleij6af75ec2011-06-09 23:57:45 +0200610static struct resource __devinitdata ab8500_fg_resources[] = {
611 {
612 .name = "NCONV_ACCU",
613 .start = AB8500_INT_CCN_CONV_ACC,
614 .end = AB8500_INT_CCN_CONV_ACC,
615 .flags = IORESOURCE_IRQ,
616 },
617 {
618 .name = "BATT_OVV",
619 .start = AB8500_INT_BATT_OVV,
620 .end = AB8500_INT_BATT_OVV,
621 .flags = IORESOURCE_IRQ,
622 },
623 {
624 .name = "LOW_BAT_F",
625 .start = AB8500_INT_LOW_BAT_F,
626 .end = AB8500_INT_LOW_BAT_F,
627 .flags = IORESOURCE_IRQ,
628 },
629 {
630 .name = "LOW_BAT_R",
631 .start = AB8500_INT_LOW_BAT_R,
632 .end = AB8500_INT_LOW_BAT_R,
633 .flags = IORESOURCE_IRQ,
634 },
635 {
636 .name = "CC_INT_CALIB",
637 .start = AB8500_INT_CC_INT_CALIB,
638 .end = AB8500_INT_CC_INT_CALIB,
639 .flags = IORESOURCE_IRQ,
640 },
641};
642
643static struct resource __devinitdata ab8500_chargalg_resources[] = {};
644
Axel Lindf720642011-11-10 09:56:18 +0800645#ifdef CONFIG_DEBUG_FS
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200646static struct resource __devinitdata ab8500_debug_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100647 {
648 .name = "IRQ_FIRST",
649 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
650 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
651 .flags = IORESOURCE_IRQ,
652 },
653 {
654 .name = "IRQ_LAST",
655 .start = AB8500_INT_USB_CHARGER_NOT_OKF,
656 .end = AB8500_INT_USB_CHARGER_NOT_OKF,
657 .flags = IORESOURCE_IRQ,
658 },
659};
Axel Lindf720642011-11-10 09:56:18 +0800660#endif
Mattias Walline098aded72010-12-02 15:40:31 +0100661
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200662static struct resource __devinitdata ab8500_usb_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100663 {
664 .name = "ID_WAKEUP_R",
665 .start = AB8500_INT_ID_WAKEUP_R,
666 .end = AB8500_INT_ID_WAKEUP_R,
667 .flags = IORESOURCE_IRQ,
668 },
669 {
670 .name = "ID_WAKEUP_F",
671 .start = AB8500_INT_ID_WAKEUP_F,
672 .end = AB8500_INT_ID_WAKEUP_F,
673 .flags = IORESOURCE_IRQ,
674 },
675 {
676 .name = "VBUS_DET_F",
677 .start = AB8500_INT_VBUS_DET_F,
678 .end = AB8500_INT_VBUS_DET_F,
679 .flags = IORESOURCE_IRQ,
680 },
681 {
682 .name = "VBUS_DET_R",
683 .start = AB8500_INT_VBUS_DET_R,
684 .end = AB8500_INT_VBUS_DET_R,
685 .flags = IORESOURCE_IRQ,
686 },
Mattias Wallin92d50a42010-12-07 11:20:47 +0100687 {
688 .name = "USB_LINK_STATUS",
689 .start = AB8500_INT_USB_LINK_STATUS,
690 .end = AB8500_INT_USB_LINK_STATUS,
691 .flags = IORESOURCE_IRQ,
692 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200693 {
694 .name = "USB_ADP_PROBE_PLUG",
695 .start = AB8500_INT_ADP_PROBE_PLUG,
696 .end = AB8500_INT_ADP_PROBE_PLUG,
697 .flags = IORESOURCE_IRQ,
698 },
699 {
700 .name = "USB_ADP_PROBE_UNPLUG",
701 .start = AB8500_INT_ADP_PROBE_UNPLUG,
702 .end = AB8500_INT_ADP_PROBE_UNPLUG,
703 .flags = IORESOURCE_IRQ,
704 },
Mattias Walline098aded72010-12-02 15:40:31 +0100705};
706
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200707static struct resource __devinitdata ab8500_temp_resources[] = {
Mattias Walline098aded72010-12-02 15:40:31 +0100708 {
709 .name = "AB8500_TEMP_WARM",
710 .start = AB8500_INT_TEMP_WARM,
711 .end = AB8500_INT_TEMP_WARM,
712 .flags = IORESOURCE_IRQ,
713 },
714};
715
Robert Rosengren5cef8df2011-06-09 23:57:33 +0200716static struct mfd_cell __devinitdata ab8500_devs[] = {
Mattias Wallin5814fc32010-09-13 16:05:04 +0200717#ifdef CONFIG_DEBUG_FS
718 {
719 .name = "ab8500-debug",
Mattias Walline098aded72010-12-02 15:40:31 +0100720 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
721 .resources = ab8500_debug_resources,
Mattias Wallin5814fc32010-09-13 16:05:04 +0200722 },
723#endif
Rabin Vincent62579262010-05-19 11:39:02 +0200724 {
Mattias Walline098aded72010-12-02 15:40:31 +0100725 .name = "ab8500-sysctrl",
726 },
727 {
728 .name = "ab8500-regulator",
729 },
730 {
Bibek Basu0cb3fcd2011-02-09 11:02:35 +0530731 .name = "ab8500-gpio",
732 .num_resources = ARRAY_SIZE(ab8500_gpio_resources),
733 .resources = ab8500_gpio_resources,
734 },
735 {
Rabin Vincent62579262010-05-19 11:39:02 +0200736 .name = "ab8500-gpadc",
737 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
738 .resources = ab8500_gpadc_resources,
739 },
740 {
741 .name = "ab8500-rtc",
742 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
743 .resources = ab8500_rtc_resources,
744 },
Arun Murthyf0f05b12010-09-06 12:24:52 +0530745 {
Linus Walleij6af75ec2011-06-09 23:57:45 +0200746 .name = "ab8500-charger",
747 .num_resources = ARRAY_SIZE(ab8500_charger_resources),
748 .resources = ab8500_charger_resources,
Mattias Walline098aded72010-12-02 15:40:31 +0100749 },
Linus Walleij6af75ec2011-06-09 23:57:45 +0200750 {
751 .name = "ab8500-btemp",
752 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
753 .resources = ab8500_btemp_resources,
754 },
755 {
756 .name = "ab8500-fg",
757 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
758 .resources = ab8500_fg_resources,
759 },
760 {
761 .name = "ab8500-chargalg",
762 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
763 .resources = ab8500_chargalg_resources,
764 },
765 {
766 .name = "ab8500-acc-det",
767 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
768 .resources = ab8500_av_acc_detect_resources,
769 },
770 {
771 .name = "ab8500-codec",
772 },
Mattias Walline098aded72010-12-02 15:40:31 +0100773 {
774 .name = "ab8500-usb",
775 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
776 .resources = ab8500_usb_resources,
777 },
778 {
779 .name = "ab8500-poweron-key",
780 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
781 .resources = ab8500_poweronkey_db_resources,
782 },
783 {
Arun Murthyf0f05b12010-09-06 12:24:52 +0530784 .name = "ab8500-pwm",
785 .id = 1,
786 },
787 {
788 .name = "ab8500-pwm",
789 .id = 2,
790 },
791 {
792 .name = "ab8500-pwm",
793 .id = 3,
794 },
Mattias Walline098aded72010-12-02 15:40:31 +0100795 { .name = "ab8500-leds", },
Sundar R Iyer77686512010-09-05 12:18:47 -0700796 {
Mattias Walline098aded72010-12-02 15:40:31 +0100797 .name = "ab8500-denc",
798 },
799 {
800 .name = "ab8500-temp",
801 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
802 .resources = ab8500_temp_resources,
Sundar R Iyer77686512010-09-05 12:18:47 -0700803 },
Rabin Vincent62579262010-05-19 11:39:02 +0200804};
805
Mattias Wallincca69b62010-12-02 15:09:36 +0100806static ssize_t show_chip_id(struct device *dev,
807 struct device_attribute *attr, char *buf)
808{
809 struct ab8500 *ab8500;
810
811 ab8500 = dev_get_drvdata(dev);
812 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
813}
814
Mattias Walline5c238c2011-03-02 11:52:36 +0100815/*
816 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
817 * 0x01 Swoff bit programming
818 * 0x02 Thermal protection activation
819 * 0x04 Vbat lower then BattOk falling threshold
820 * 0x08 Watchdog expired
821 * 0x10 Non presence of 32kHz clock
822 * 0x20 Battery level lower than power on reset threshold
823 * 0x40 Power on key 1 pressed longer than 10 seconds
824 * 0x80 DB8500 thermal shutdown
825 */
826static ssize_t show_switch_off_status(struct device *dev,
827 struct device_attribute *attr, char *buf)
828{
829 int ret;
830 u8 value;
831 struct ab8500 *ab8500;
832
833 ab8500 = dev_get_drvdata(dev);
834 ret = get_register_interruptible(ab8500, AB8500_RTC,
835 AB8500_SWITCH_OFF_STATUS, &value);
836 if (ret < 0)
837 return ret;
838 return sprintf(buf, "%#x\n", value);
839}
840
Andrew Lynnb4a31032011-10-11 10:49:47 +0200841/*
842 * ab8500 has turned on due to (TURN_ON_STATUS):
843 * 0x01 PORnVbat
844 * 0x02 PonKey1dbF
845 * 0x04 PonKey2dbF
846 * 0x08 RTCAlarm
847 * 0x10 MainChDet
848 * 0x20 VbusDet
849 * 0x40 UsbIDDetect
850 * 0x80 Reserved
851 */
852static ssize_t show_turn_on_status(struct device *dev,
853 struct device_attribute *attr, char *buf)
854{
855 int ret;
856 u8 value;
857 struct ab8500 *ab8500;
858
859 ab8500 = dev_get_drvdata(dev);
860 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
861 AB8500_TURN_ON_STATUS, &value);
862 if (ret < 0)
863 return ret;
864 return sprintf(buf, "%#x\n", value);
865}
866
Mattias Wallincca69b62010-12-02 15:09:36 +0100867static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
Mattias Walline5c238c2011-03-02 11:52:36 +0100868static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
Andrew Lynnb4a31032011-10-11 10:49:47 +0200869static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
Mattias Wallincca69b62010-12-02 15:09:36 +0100870
871static struct attribute *ab8500_sysfs_entries[] = {
872 &dev_attr_chip_id.attr,
Mattias Walline5c238c2011-03-02 11:52:36 +0100873 &dev_attr_switch_off_status.attr,
Andrew Lynnb4a31032011-10-11 10:49:47 +0200874 &dev_attr_turn_on_status.attr,
Mattias Wallincca69b62010-12-02 15:09:36 +0100875 NULL,
876};
877
878static struct attribute_group ab8500_attr_group = {
879 .attrs = ab8500_sysfs_entries,
880};
881
Linus Walleij0f6208372012-02-20 21:42:10 +0100882int __devinit ab8500_init(struct ab8500 *ab8500, enum ab8500_version version)
Rabin Vincent62579262010-05-19 11:39:02 +0200883{
884 struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev);
885 int ret;
886 int i;
Mattias Wallin47c16972010-09-10 17:47:56 +0200887 u8 value;
Rabin Vincent62579262010-05-19 11:39:02 +0200888
889 if (plat)
890 ab8500->irq_base = plat->irq_base;
891
892 mutex_init(&ab8500->lock);
893 mutex_init(&ab8500->irq_lock);
894
Linus Walleij0f6208372012-02-20 21:42:10 +0100895 if (version != AB8500_VERSION_UNDEFINED)
896 ab8500->version = version;
897 else {
898 ret = get_register_interruptible(ab8500, AB8500_MISC,
899 AB8500_IC_NAME_REG, &value);
900 if (ret < 0)
901 return ret;
902
903 ab8500->version = value;
904 }
905
Mattias Wallin47c16972010-09-10 17:47:56 +0200906 ret = get_register_interruptible(ab8500, AB8500_MISC,
907 AB8500_REV_REG, &value);
Rabin Vincent62579262010-05-19 11:39:02 +0200908 if (ret < 0)
909 return ret;
910
Mattias Wallin47c16972010-09-10 17:47:56 +0200911 ab8500->chip_id = value;
Rabin Vincent62579262010-05-19 11:39:02 +0200912
Linus Walleij0f6208372012-02-20 21:42:10 +0100913 dev_info(ab8500->dev, "detected chip, %s rev. %1x.%1x\n",
914 ab8500_version_str[ab8500->version],
915 ab8500->chip_id >> 4,
916 ab8500->chip_id & 0x0F);
917
Linus Walleij2ced4452012-02-20 21:42:17 +0100918 ab8500->mask_size = AB8500_NUM_IRQ_REGS;
919 ab8500->irq_reg_offset = ab8500_irq_regoffset;
920 ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL);
921 if (!ab8500->mask)
922 return -ENOMEM;
923 ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL);
924 if (!ab8500->oldmask) {
925 ret = -ENOMEM;
926 goto out_freemask;
927 }
Mattias Walline5c238c2011-03-02 11:52:36 +0100928 /*
929 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
930 * 0x01 Swoff bit programming
931 * 0x02 Thermal protection activation
932 * 0x04 Vbat lower then BattOk falling threshold
933 * 0x08 Watchdog expired
934 * 0x10 Non presence of 32kHz clock
935 * 0x20 Battery level lower than power on reset threshold
936 * 0x40 Power on key 1 pressed longer than 10 seconds
937 * 0x80 DB8500 thermal shutdown
938 */
939
940 ret = get_register_interruptible(ab8500, AB8500_RTC,
941 AB8500_SWITCH_OFF_STATUS, &value);
942 if (ret < 0)
943 return ret;
944 dev_info(ab8500->dev, "switch off status: %#x", value);
945
Rabin Vincent62579262010-05-19 11:39:02 +0200946 if (plat && plat->init)
947 plat->init(ab8500);
948
949 /* Clear and mask all interrupts */
Linus Walleij2ced4452012-02-20 21:42:17 +0100950 for (i = 0; i < ab8500->mask_size; i++) {
Linus Walleij0f6208372012-02-20 21:42:10 +0100951 /*
952 * Interrupt register 12 doesn't exist prior to AB8500 version
953 * 2.0
954 */
955 if (ab8500->irq_reg_offset[i] == 11 &&
956 is_ab8500_1p1_or_earlier(ab8500))
Mattias Wallin92d50a42010-12-07 11:20:47 +0100957 continue;
Rabin Vincent62579262010-05-19 11:39:02 +0200958
Mattias Wallin47c16972010-09-10 17:47:56 +0200959 get_register_interruptible(ab8500, AB8500_INTERRUPT,
Linus Walleij2ced4452012-02-20 21:42:17 +0100960 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
Mattias Wallin92d50a42010-12-07 11:20:47 +0100961 &value);
Mattias Wallin47c16972010-09-10 17:47:56 +0200962 set_register_interruptible(ab8500, AB8500_INTERRUPT,
Linus Walleij2ced4452012-02-20 21:42:17 +0100963 AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
Rabin Vincent62579262010-05-19 11:39:02 +0200964 }
965
Mattias Wallin47c16972010-09-10 17:47:56 +0200966 ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
967 if (ret)
Linus Walleij2ced4452012-02-20 21:42:17 +0100968 goto out_freeoldmask;
Mattias Wallin47c16972010-09-10 17:47:56 +0200969
Linus Walleij2ced4452012-02-20 21:42:17 +0100970 for (i = 0; i < ab8500->mask_size; i++)
Rabin Vincent62579262010-05-19 11:39:02 +0200971 ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
972
973 if (ab8500->irq_base) {
974 ret = ab8500_irq_init(ab8500);
975 if (ret)
Linus Walleij2ced4452012-02-20 21:42:17 +0100976 goto out_freeoldmask;
Rabin Vincent62579262010-05-19 11:39:02 +0200977
978 ret = request_threaded_irq(ab8500->irq, NULL, ab8500_irq,
Mattias Wallin4f079982010-12-02 15:10:27 +0100979 IRQF_ONESHOT | IRQF_NO_SUSPEND,
980 "ab8500", ab8500);
Rabin Vincent62579262010-05-19 11:39:02 +0200981 if (ret)
982 goto out_removeirq;
983 }
984
Sundar R Iyer549931f2010-07-13 11:51:28 +0530985 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
Rabin Vincent62579262010-05-19 11:39:02 +0200986 ARRAY_SIZE(ab8500_devs), NULL,
987 ab8500->irq_base);
988 if (ret)
989 goto out_freeirq;
990
Mattias Wallincca69b62010-12-02 15:09:36 +0100991 ret = sysfs_create_group(&ab8500->dev->kobj, &ab8500_attr_group);
992 if (ret)
993 dev_err(ab8500->dev, "error creating sysfs entries\n");
994
Rabin Vincent62579262010-05-19 11:39:02 +0200995 return ret;
996
997out_freeirq:
Linus Walleij6d95b7f2012-02-20 21:42:03 +0100998 if (ab8500->irq_base)
Rabin Vincent62579262010-05-19 11:39:02 +0200999 free_irq(ab8500->irq, ab8500);
1000out_removeirq:
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001001 if (ab8500->irq_base)
Rabin Vincent62579262010-05-19 11:39:02 +02001002 ab8500_irq_remove(ab8500);
Linus Walleij2ced4452012-02-20 21:42:17 +01001003out_freeoldmask:
1004 kfree(ab8500->oldmask);
1005out_freemask:
1006 kfree(ab8500->mask);
Linus Walleij6d95b7f2012-02-20 21:42:03 +01001007
Rabin Vincent62579262010-05-19 11:39:02 +02001008 return ret;
1009}
1010
1011int __devexit ab8500_exit(struct ab8500 *ab8500)
1012{
Mattias Wallincca69b62010-12-02 15:09:36 +01001013 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
Rabin Vincent62579262010-05-19 11:39:02 +02001014 mfd_remove_devices(ab8500->dev);
1015 if (ab8500->irq_base) {
1016 free_irq(ab8500->irq, ab8500);
1017 ab8500_irq_remove(ab8500);
1018 }
Linus Walleij2ced4452012-02-20 21:42:17 +01001019 kfree(ab8500->oldmask);
1020 kfree(ab8500->mask);
Rabin Vincent62579262010-05-19 11:39:02 +02001021
1022 return 0;
1023}
1024
Mattias Wallinadceed62011-03-02 11:51:11 +01001025MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
Rabin Vincent62579262010-05-19 11:39:02 +02001026MODULE_DESCRIPTION("AB8500 MFD core");
1027MODULE_LICENSE("GPL v2");