Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
[linux-2.6/next.git] / drivers / mfd / ab8500-core.c
blob67d01c9382844f9e1b6c793181e82cd2865e58c4
1 /*
2 * Copyright (C) ST-Ericsson SA 2010
4 * License Terms: GNU General Public License v2
5 * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
6 * Author: Rabin Vincent <rabin.vincent@stericsson.com>
7 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
8 */
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>
19 #include <linux/mfd/abx500.h>
20 #include <linux/mfd/ab8500.h>
21 #include <linux/regulator/ab8500.h>
24 * Interrupt register offsets
25 * Bank : 0x0E
27 #define AB8500_IT_SOURCE1_REG 0x00
28 #define AB8500_IT_SOURCE2_REG 0x01
29 #define AB8500_IT_SOURCE3_REG 0x02
30 #define AB8500_IT_SOURCE4_REG 0x03
31 #define AB8500_IT_SOURCE5_REG 0x04
32 #define AB8500_IT_SOURCE6_REG 0x05
33 #define AB8500_IT_SOURCE7_REG 0x06
34 #define AB8500_IT_SOURCE8_REG 0x07
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
43 * latch registers
45 #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
55 #define AB8500_IT_LATCH12_REG 0x2B
56 #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
64 * mask registers
67 #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
92 #define AB8500_REV_REG 0x80
93 #define AB8500_SWITCH_OFF_STATUS 0x00
96 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
97 * numbers are indexed into this array with (num / 8).
99 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
100 * offset 0.
102 static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
103 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
106 static int ab8500_get_chip_id(struct device *dev)
108 struct ab8500 *ab8500;
110 if (!dev)
111 return -EINVAL;
112 ab8500 = dev_get_drvdata(dev->parent);
113 return ab8500 ? (int)ab8500->chip_id : -EINVAL;
116 static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
117 u8 reg, u8 data)
119 int ret;
121 * Put the u8 bank and u8 register together into a an u16.
122 * The bank on higher 8 bits and register in lower 8 bits.
123 * */
124 u16 addr = ((u16)bank) << 8 | reg;
126 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
128 ret = mutex_lock_interruptible(&ab8500->lock);
129 if (ret)
130 return ret;
132 ret = ab8500->write(ab8500, addr, data);
133 if (ret < 0)
134 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
135 addr, ret);
136 mutex_unlock(&ab8500->lock);
138 return ret;
141 static int ab8500_set_register(struct device *dev, u8 bank,
142 u8 reg, u8 value)
144 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
146 return set_register_interruptible(ab8500, bank, reg, value);
149 static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
150 u8 reg, u8 *value)
152 int ret;
153 /* put the u8 bank and u8 reg together into a an u16.
154 * bank on higher 8 bits and reg in lower */
155 u16 addr = ((u16)bank) << 8 | reg;
157 ret = mutex_lock_interruptible(&ab8500->lock);
158 if (ret)
159 return ret;
161 ret = ab8500->read(ab8500, addr);
162 if (ret < 0)
163 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
164 addr, ret);
165 else
166 *value = ret;
168 mutex_unlock(&ab8500->lock);
169 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
171 return ret;
174 static int ab8500_get_register(struct device *dev, u8 bank,
175 u8 reg, u8 *value)
177 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
179 return get_register_interruptible(ab8500, bank, reg, value);
182 static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
183 u8 reg, u8 bitmask, u8 bitvalues)
185 int ret;
186 u8 data;
187 /* put the u8 bank and u8 reg together into a an u16.
188 * bank on higher 8 bits and reg in lower */
189 u16 addr = ((u16)bank) << 8 | reg;
191 ret = mutex_lock_interruptible(&ab8500->lock);
192 if (ret)
193 return ret;
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 goto out;
202 data = (u8)ret;
203 data = (~bitmask & data) | (bitmask & bitvalues);
205 ret = ab8500->write(ab8500, addr, data);
206 if (ret < 0)
207 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
208 addr, ret);
210 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, data);
211 out:
212 mutex_unlock(&ab8500->lock);
213 return ret;
216 static int ab8500_mask_and_set_register(struct device *dev,
217 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
219 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
221 return mask_and_set_register_interruptible(ab8500, bank, reg,
222 bitmask, bitvalues);
226 static struct abx500_ops ab8500_ops = {
227 .get_chip_id = ab8500_get_chip_id,
228 .get_register = ab8500_get_register,
229 .set_register = ab8500_set_register,
230 .get_register_page = NULL,
231 .set_register_page = NULL,
232 .mask_and_set_register = ab8500_mask_and_set_register,
233 .event_registers_startup_state_get = NULL,
234 .startup_irq_enabled = NULL,
237 static void ab8500_irq_lock(struct irq_data *data)
239 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
241 mutex_lock(&ab8500->irq_lock);
244 static void ab8500_irq_sync_unlock(struct irq_data *data)
246 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
247 int i;
249 for (i = 0; i < AB8500_NUM_IRQ_REGS; i++) {
250 u8 old = ab8500->oldmask[i];
251 u8 new = ab8500->mask[i];
252 int reg;
254 if (new == old)
255 continue;
257 /* Interrupt register 12 does'nt exist prior to version 0x20 */
258 if (ab8500_irq_regoffset[i] == 11 && ab8500->chip_id < 0x20)
259 continue;
261 ab8500->oldmask[i] = new;
263 reg = AB8500_IT_MASK1_REG + ab8500_irq_regoffset[i];
264 set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
267 mutex_unlock(&ab8500->irq_lock);
270 static void ab8500_irq_mask(struct irq_data *data)
272 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
273 int offset = data->irq - ab8500->irq_base;
274 int index = offset / 8;
275 int mask = 1 << (offset % 8);
277 ab8500->mask[index] |= mask;
280 static void ab8500_irq_unmask(struct irq_data *data)
282 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
283 int offset = data->irq - ab8500->irq_base;
284 int index = offset / 8;
285 int mask = 1 << (offset % 8);
287 ab8500->mask[index] &= ~mask;
290 static struct irq_chip ab8500_irq_chip = {
291 .name = "ab8500",
292 .irq_bus_lock = ab8500_irq_lock,
293 .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
294 .irq_mask = ab8500_irq_mask,
295 .irq_unmask = ab8500_irq_unmask,
298 static irqreturn_t ab8500_irq(int irq, void *dev)
300 struct ab8500 *ab8500 = dev;
301 int i;
303 dev_vdbg(ab8500->dev, "interrupt\n");
305 for (i = 0; i < AB8500_NUM_IRQ_REGS; i++) {
306 int regoffset = ab8500_irq_regoffset[i];
307 int status;
308 u8 value;
310 /* Interrupt register 12 does'nt exist prior to version 0x20 */
311 if (regoffset == 11 && ab8500->chip_id < 0x20)
312 continue;
314 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
315 AB8500_IT_LATCH1_REG + regoffset, &value);
316 if (status < 0 || value == 0)
317 continue;
319 do {
320 int bit = __ffs(value);
321 int line = i * 8 + bit;
323 handle_nested_irq(ab8500->irq_base + line);
324 value &= ~(1 << bit);
325 } while (value);
328 return IRQ_HANDLED;
331 static int ab8500_irq_init(struct ab8500 *ab8500)
333 int base = ab8500->irq_base;
334 int irq;
336 for (irq = base; irq < base + AB8500_NR_IRQS; irq++) {
337 irq_set_chip_data(irq, ab8500);
338 irq_set_chip_and_handler(irq, &ab8500_irq_chip,
339 handle_simple_irq);
340 irq_set_nested_thread(irq, 1);
341 #ifdef CONFIG_ARM
342 set_irq_flags(irq, IRQF_VALID);
343 #else
344 irq_set_noprobe(irq);
345 #endif
348 return 0;
351 static void ab8500_irq_remove(struct ab8500 *ab8500)
353 int base = ab8500->irq_base;
354 int irq;
356 for (irq = base; irq < base + AB8500_NR_IRQS; irq++) {
357 #ifdef CONFIG_ARM
358 set_irq_flags(irq, 0);
359 #endif
360 irq_set_chip_and_handler(irq, NULL, NULL);
361 irq_set_chip_data(irq, NULL);
365 static struct resource ab8500_gpio_resources[] = {
367 .name = "GPIO_INT6",
368 .start = AB8500_INT_GPIO6R,
369 .end = AB8500_INT_GPIO41F,
370 .flags = IORESOURCE_IRQ,
374 static struct resource ab8500_gpadc_resources[] = {
376 .name = "HW_CONV_END",
377 .start = AB8500_INT_GP_HW_ADC_CONV_END,
378 .end = AB8500_INT_GP_HW_ADC_CONV_END,
379 .flags = IORESOURCE_IRQ,
382 .name = "SW_CONV_END",
383 .start = AB8500_INT_GP_SW_ADC_CONV_END,
384 .end = AB8500_INT_GP_SW_ADC_CONV_END,
385 .flags = IORESOURCE_IRQ,
389 static struct resource ab8500_rtc_resources[] = {
391 .name = "60S",
392 .start = AB8500_INT_RTC_60S,
393 .end = AB8500_INT_RTC_60S,
394 .flags = IORESOURCE_IRQ,
397 .name = "ALARM",
398 .start = AB8500_INT_RTC_ALARM,
399 .end = AB8500_INT_RTC_ALARM,
400 .flags = IORESOURCE_IRQ,
404 static struct resource ab8500_poweronkey_db_resources[] = {
406 .name = "ONKEY_DBF",
407 .start = AB8500_INT_PON_KEY1DB_F,
408 .end = AB8500_INT_PON_KEY1DB_F,
409 .flags = IORESOURCE_IRQ,
412 .name = "ONKEY_DBR",
413 .start = AB8500_INT_PON_KEY1DB_R,
414 .end = AB8500_INT_PON_KEY1DB_R,
415 .flags = IORESOURCE_IRQ,
419 static struct resource ab8500_bm_resources[] = {
421 .name = "MAIN_EXT_CH_NOT_OK",
422 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
423 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
424 .flags = IORESOURCE_IRQ,
427 .name = "BATT_OVV",
428 .start = AB8500_INT_BATT_OVV,
429 .end = AB8500_INT_BATT_OVV,
430 .flags = IORESOURCE_IRQ,
433 .name = "MAIN_CH_UNPLUG_DET",
434 .start = AB8500_INT_MAIN_CH_UNPLUG_DET,
435 .end = AB8500_INT_MAIN_CH_UNPLUG_DET,
436 .flags = IORESOURCE_IRQ,
439 .name = "MAIN_CHARGE_PLUG_DET",
440 .start = AB8500_INT_MAIN_CH_PLUG_DET,
441 .end = AB8500_INT_MAIN_CH_PLUG_DET,
442 .flags = IORESOURCE_IRQ,
445 .name = "VBUS_DET_F",
446 .start = AB8500_INT_VBUS_DET_F,
447 .end = AB8500_INT_VBUS_DET_F,
448 .flags = IORESOURCE_IRQ,
451 .name = "VBUS_DET_R",
452 .start = AB8500_INT_VBUS_DET_R,
453 .end = AB8500_INT_VBUS_DET_R,
454 .flags = IORESOURCE_IRQ,
457 .name = "BAT_CTRL_INDB",
458 .start = AB8500_INT_BAT_CTRL_INDB,
459 .end = AB8500_INT_BAT_CTRL_INDB,
460 .flags = IORESOURCE_IRQ,
463 .name = "CH_WD_EXP",
464 .start = AB8500_INT_CH_WD_EXP,
465 .end = AB8500_INT_CH_WD_EXP,
466 .flags = IORESOURCE_IRQ,
469 .name = "VBUS_OVV",
470 .start = AB8500_INT_VBUS_OVV,
471 .end = AB8500_INT_VBUS_OVV,
472 .flags = IORESOURCE_IRQ,
475 .name = "NCONV_ACCU",
476 .start = AB8500_INT_CCN_CONV_ACC,
477 .end = AB8500_INT_CCN_CONV_ACC,
478 .flags = IORESOURCE_IRQ,
481 .name = "LOW_BAT_F",
482 .start = AB8500_INT_LOW_BAT_F,
483 .end = AB8500_INT_LOW_BAT_F,
484 .flags = IORESOURCE_IRQ,
487 .name = "LOW_BAT_R",
488 .start = AB8500_INT_LOW_BAT_R,
489 .end = AB8500_INT_LOW_BAT_R,
490 .flags = IORESOURCE_IRQ,
493 .name = "BTEMP_LOW",
494 .start = AB8500_INT_BTEMP_LOW,
495 .end = AB8500_INT_BTEMP_LOW,
496 .flags = IORESOURCE_IRQ,
499 .name = "BTEMP_HIGH",
500 .start = AB8500_INT_BTEMP_HIGH,
501 .end = AB8500_INT_BTEMP_HIGH,
502 .flags = IORESOURCE_IRQ,
505 .name = "USB_CHARGER_NOT_OKR",
506 .start = AB8500_INT_USB_CHARGER_NOT_OK,
507 .end = AB8500_INT_USB_CHARGER_NOT_OK,
508 .flags = IORESOURCE_IRQ,
511 .name = "USB_CHARGE_DET_DONE",
512 .start = AB8500_INT_USB_CHG_DET_DONE,
513 .end = AB8500_INT_USB_CHG_DET_DONE,
514 .flags = IORESOURCE_IRQ,
517 .name = "USB_CH_TH_PROT_R",
518 .start = AB8500_INT_USB_CH_TH_PROT_R,
519 .end = AB8500_INT_USB_CH_TH_PROT_R,
520 .flags = IORESOURCE_IRQ,
523 .name = "MAIN_CH_TH_PROT_R",
524 .start = AB8500_INT_MAIN_CH_TH_PROT_R,
525 .end = AB8500_INT_MAIN_CH_TH_PROT_R,
526 .flags = IORESOURCE_IRQ,
529 .name = "USB_CHARGER_NOT_OKF",
530 .start = AB8500_INT_USB_CHARGER_NOT_OKF,
531 .end = AB8500_INT_USB_CHARGER_NOT_OKF,
532 .flags = IORESOURCE_IRQ,
536 static struct resource ab8500_debug_resources[] = {
538 .name = "IRQ_FIRST",
539 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
540 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
541 .flags = IORESOURCE_IRQ,
544 .name = "IRQ_LAST",
545 .start = AB8500_INT_USB_CHARGER_NOT_OKF,
546 .end = AB8500_INT_USB_CHARGER_NOT_OKF,
547 .flags = IORESOURCE_IRQ,
551 static struct resource ab8500_usb_resources[] = {
553 .name = "ID_WAKEUP_R",
554 .start = AB8500_INT_ID_WAKEUP_R,
555 .end = AB8500_INT_ID_WAKEUP_R,
556 .flags = IORESOURCE_IRQ,
559 .name = "ID_WAKEUP_F",
560 .start = AB8500_INT_ID_WAKEUP_F,
561 .end = AB8500_INT_ID_WAKEUP_F,
562 .flags = IORESOURCE_IRQ,
565 .name = "VBUS_DET_F",
566 .start = AB8500_INT_VBUS_DET_F,
567 .end = AB8500_INT_VBUS_DET_F,
568 .flags = IORESOURCE_IRQ,
571 .name = "VBUS_DET_R",
572 .start = AB8500_INT_VBUS_DET_R,
573 .end = AB8500_INT_VBUS_DET_R,
574 .flags = IORESOURCE_IRQ,
577 .name = "USB_LINK_STATUS",
578 .start = AB8500_INT_USB_LINK_STATUS,
579 .end = AB8500_INT_USB_LINK_STATUS,
580 .flags = IORESOURCE_IRQ,
584 static struct resource ab8500_temp_resources[] = {
586 .name = "AB8500_TEMP_WARM",
587 .start = AB8500_INT_TEMP_WARM,
588 .end = AB8500_INT_TEMP_WARM,
589 .flags = IORESOURCE_IRQ,
593 static struct mfd_cell ab8500_devs[] = {
594 #ifdef CONFIG_DEBUG_FS
596 .name = "ab8500-debug",
597 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
598 .resources = ab8500_debug_resources,
600 #endif
602 .name = "ab8500-sysctrl",
605 .name = "ab8500-regulator",
608 .name = "ab8500-gpio",
609 .num_resources = ARRAY_SIZE(ab8500_gpio_resources),
610 .resources = ab8500_gpio_resources,
613 .name = "ab8500-gpadc",
614 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
615 .resources = ab8500_gpadc_resources,
618 .name = "ab8500-rtc",
619 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
620 .resources = ab8500_rtc_resources,
623 .name = "ab8500-bm",
624 .num_resources = ARRAY_SIZE(ab8500_bm_resources),
625 .resources = ab8500_bm_resources,
627 { .name = "ab8500-codec", },
629 .name = "ab8500-usb",
630 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
631 .resources = ab8500_usb_resources,
634 .name = "ab8500-poweron-key",
635 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
636 .resources = ab8500_poweronkey_db_resources,
639 .name = "ab8500-pwm",
640 .id = 1,
643 .name = "ab8500-pwm",
644 .id = 2,
647 .name = "ab8500-pwm",
648 .id = 3,
650 { .name = "ab8500-leds", },
652 .name = "ab8500-denc",
655 .name = "ab8500-temp",
656 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
657 .resources = ab8500_temp_resources,
661 static ssize_t show_chip_id(struct device *dev,
662 struct device_attribute *attr, char *buf)
664 struct ab8500 *ab8500;
666 ab8500 = dev_get_drvdata(dev);
667 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
671 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
672 * 0x01 Swoff bit programming
673 * 0x02 Thermal protection activation
674 * 0x04 Vbat lower then BattOk falling threshold
675 * 0x08 Watchdog expired
676 * 0x10 Non presence of 32kHz clock
677 * 0x20 Battery level lower than power on reset threshold
678 * 0x40 Power on key 1 pressed longer than 10 seconds
679 * 0x80 DB8500 thermal shutdown
681 static ssize_t show_switch_off_status(struct device *dev,
682 struct device_attribute *attr, char *buf)
684 int ret;
685 u8 value;
686 struct ab8500 *ab8500;
688 ab8500 = dev_get_drvdata(dev);
689 ret = get_register_interruptible(ab8500, AB8500_RTC,
690 AB8500_SWITCH_OFF_STATUS, &value);
691 if (ret < 0)
692 return ret;
693 return sprintf(buf, "%#x\n", value);
696 static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
697 static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
699 static struct attribute *ab8500_sysfs_entries[] = {
700 &dev_attr_chip_id.attr,
701 &dev_attr_switch_off_status.attr,
702 NULL,
705 static struct attribute_group ab8500_attr_group = {
706 .attrs = ab8500_sysfs_entries,
709 int __devinit ab8500_init(struct ab8500 *ab8500)
711 struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev);
712 int ret;
713 int i;
714 u8 value;
716 if (plat)
717 ab8500->irq_base = plat->irq_base;
719 mutex_init(&ab8500->lock);
720 mutex_init(&ab8500->irq_lock);
722 ret = get_register_interruptible(ab8500, AB8500_MISC,
723 AB8500_REV_REG, &value);
724 if (ret < 0)
725 return ret;
728 * 0x0 - Early Drop
729 * 0x10 - Cut 1.0
730 * 0x11 - Cut 1.1
731 * 0x20 - Cut 2.0
732 * 0x30 - Cut 3.0
734 if (value == 0x0 || value == 0x10 || value == 0x11 || value == 0x20 ||
735 value == 0x30) {
736 dev_info(ab8500->dev, "detected chip, revision: %#x\n", value);
737 } else {
738 dev_err(ab8500->dev, "unknown chip, revision: %#x\n", value);
739 return -EINVAL;
741 ab8500->chip_id = value;
744 * ab8500 has switched off due to (SWITCH_OFF_STATUS):
745 * 0x01 Swoff bit programming
746 * 0x02 Thermal protection activation
747 * 0x04 Vbat lower then BattOk falling threshold
748 * 0x08 Watchdog expired
749 * 0x10 Non presence of 32kHz clock
750 * 0x20 Battery level lower than power on reset threshold
751 * 0x40 Power on key 1 pressed longer than 10 seconds
752 * 0x80 DB8500 thermal shutdown
755 ret = get_register_interruptible(ab8500, AB8500_RTC,
756 AB8500_SWITCH_OFF_STATUS, &value);
757 if (ret < 0)
758 return ret;
759 dev_info(ab8500->dev, "switch off status: %#x", value);
761 if (plat && plat->init)
762 plat->init(ab8500);
764 /* Clear and mask all interrupts */
765 for (i = 0; i < AB8500_NUM_IRQ_REGS; i++) {
766 /* Interrupt register 12 does'nt exist prior to version 0x20 */
767 if (ab8500_irq_regoffset[i] == 11 && ab8500->chip_id < 0x20)
768 continue;
770 get_register_interruptible(ab8500, AB8500_INTERRUPT,
771 AB8500_IT_LATCH1_REG + ab8500_irq_regoffset[i],
772 &value);
773 set_register_interruptible(ab8500, AB8500_INTERRUPT,
774 AB8500_IT_MASK1_REG + ab8500_irq_regoffset[i], 0xff);
777 ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
778 if (ret)
779 return ret;
781 for (i = 0; i < AB8500_NUM_IRQ_REGS; i++)
782 ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
784 if (ab8500->irq_base) {
785 ret = ab8500_irq_init(ab8500);
786 if (ret)
787 return ret;
789 ret = request_threaded_irq(ab8500->irq, NULL, ab8500_irq,
790 IRQF_ONESHOT | IRQF_NO_SUSPEND,
791 "ab8500", ab8500);
792 if (ret)
793 goto out_removeirq;
796 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
797 ARRAY_SIZE(ab8500_devs), NULL,
798 ab8500->irq_base);
799 if (ret)
800 goto out_freeirq;
802 ret = sysfs_create_group(&ab8500->dev->kobj, &ab8500_attr_group);
803 if (ret)
804 dev_err(ab8500->dev, "error creating sysfs entries\n");
806 return ret;
808 out_freeirq:
809 if (ab8500->irq_base) {
810 free_irq(ab8500->irq, ab8500);
811 out_removeirq:
812 ab8500_irq_remove(ab8500);
814 return ret;
817 int __devexit ab8500_exit(struct ab8500 *ab8500)
819 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
820 mfd_remove_devices(ab8500->dev);
821 if (ab8500->irq_base) {
822 free_irq(ab8500->irq, ab8500);
823 ab8500_irq_remove(ab8500);
826 return 0;
829 MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
830 MODULE_DESCRIPTION("AB8500 MFD core");
831 MODULE_LICENSE("GPL v2");