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>
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/abx500/ab8500.h>
21 #include <linux/regulator/ab8500.h>
24 * Interrupt register offsets
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
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
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_IC_NAME_REG 0x82
94 #define AB8500_SWITCH_OFF_STATUS 0x00
96 #define AB8500_TURN_ON_STATUS 0x00
99 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
100 * numbers are indexed into this array with (num / 8). The interupts are
101 * defined in linux/mfd/ab8500.h
103 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
107 static const int ab8500_irq_regoffset[AB8500_NUM_IRQ_REGS] = {
108 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
111 static 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",
118 static int ab8500_get_chip_id(struct device *dev)
120 struct ab8500 *ab8500;
124 ab8500 = dev_get_drvdata(dev->parent);
125 return ab8500 ? (int)ab8500->chip_id : -EINVAL;
128 static int set_register_interruptible(struct ab8500 *ab8500, u8 bank,
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.
136 u16 addr = ((u16)bank) << 8 | reg;
138 dev_vdbg(ab8500->dev, "wr: addr %#x <= %#x\n", addr, data);
140 ret = mutex_lock_interruptible(&ab8500->lock);
144 ret = ab8500->write(ab8500, addr, data);
146 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
148 mutex_unlock(&ab8500->lock);
153 static int ab8500_set_register(struct device *dev, u8 bank,
156 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
158 return set_register_interruptible(ab8500, bank, reg, value);
161 static int get_register_interruptible(struct ab8500 *ab8500, u8 bank,
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;
169 ret = mutex_lock_interruptible(&ab8500->lock);
173 ret = ab8500->read(ab8500, addr);
175 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
180 mutex_unlock(&ab8500->lock);
181 dev_vdbg(ab8500->dev, "rd: addr %#x => data %#x\n", addr, ret);
186 static int ab8500_get_register(struct device *dev, u8 bank,
189 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
191 return get_register_interruptible(ab8500, bank, reg, value);
194 static int mask_and_set_register_interruptible(struct ab8500 *ab8500, u8 bank,
195 u8 reg, u8 bitmask, u8 bitvalues)
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;
203 ret = mutex_lock_interruptible(&ab8500->lock);
207 ret = ab8500->read(ab8500, addr);
209 dev_err(ab8500->dev, "failed to read reg %#x: %d\n",
215 data = (~bitmask & data) | (bitmask & bitvalues);
217 ret = ab8500->write(ab8500, addr, data);
219 dev_err(ab8500->dev, "failed to write reg %#x: %d\n",
222 dev_vdbg(ab8500->dev, "mask: addr %#x => data %#x\n", addr, data);
224 mutex_unlock(&ab8500->lock);
228 static int ab8500_mask_and_set_register(struct device *dev,
229 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
231 struct ab8500 *ab8500 = dev_get_drvdata(dev->parent);
233 return mask_and_set_register_interruptible(ab8500, bank, reg,
238 static 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,
249 static void ab8500_irq_lock(struct irq_data *data)
251 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
253 mutex_lock(&ab8500->irq_lock);
256 static void ab8500_irq_sync_unlock(struct irq_data *data)
258 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
261 for (i = 0; i < ab8500->mask_size; i++) {
262 u8 old = ab8500->oldmask[i];
263 u8 new = ab8500->mask[i];
270 * Interrupt register 12 doesn't exist prior to AB8500 version
273 if (ab8500->irq_reg_offset[i] == 11 &&
274 is_ab8500_1p1_or_earlier(ab8500))
277 ab8500->oldmask[i] = new;
279 reg = AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i];
280 set_register_interruptible(ab8500, AB8500_INTERRUPT, reg, new);
283 mutex_unlock(&ab8500->irq_lock);
286 static void ab8500_irq_mask(struct irq_data *data)
288 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
289 int offset = data->irq - ab8500->irq_base;
290 int index = offset / 8;
291 int mask = 1 << (offset % 8);
293 ab8500->mask[index] |= mask;
296 static void ab8500_irq_unmask(struct irq_data *data)
298 struct ab8500 *ab8500 = irq_data_get_irq_chip_data(data);
299 int offset = data->irq - ab8500->irq_base;
300 int index = offset / 8;
301 int mask = 1 << (offset % 8);
303 ab8500->mask[index] &= ~mask;
306 static struct irq_chip ab8500_irq_chip = {
308 .irq_bus_lock = ab8500_irq_lock,
309 .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
310 .irq_mask = ab8500_irq_mask,
311 .irq_disable = ab8500_irq_mask,
312 .irq_unmask = ab8500_irq_unmask,
315 static irqreturn_t ab8500_irq(int irq, void *dev)
317 struct ab8500 *ab8500 = dev;
320 dev_vdbg(ab8500->dev, "interrupt\n");
322 for (i = 0; i < ab8500->mask_size; i++) {
323 int regoffset = ab8500->irq_reg_offset[i];
328 * Interrupt register 12 doesn't exist prior to AB8500 version
331 if (regoffset == 11 && is_ab8500_1p1_or_earlier(ab8500))
334 status = get_register_interruptible(ab8500, AB8500_INTERRUPT,
335 AB8500_IT_LATCH1_REG + regoffset, &value);
336 if (status < 0 || value == 0)
340 int bit = __ffs(value);
341 int line = i * 8 + bit;
343 handle_nested_irq(ab8500->irq_base + line);
344 value &= ~(1 << bit);
351 static int ab8500_irq_init(struct ab8500 *ab8500)
353 int base = ab8500->irq_base;
357 num_irqs = AB8500_NR_IRQS;
359 for (irq = base; irq < base + num_irqs; irq++) {
360 irq_set_chip_data(irq, ab8500);
361 irq_set_chip_and_handler(irq, &ab8500_irq_chip,
363 irq_set_nested_thread(irq, 1);
365 set_irq_flags(irq, IRQF_VALID);
367 irq_set_noprobe(irq);
374 static void ab8500_irq_remove(struct ab8500 *ab8500)
376 int base = ab8500->irq_base;
380 num_irqs = AB8500_NR_IRQS;
382 for (irq = base; irq < base + num_irqs; irq++) {
384 set_irq_flags(irq, 0);
386 irq_set_chip_and_handler(irq, NULL, NULL);
387 irq_set_chip_data(irq, NULL);
391 static struct resource __devinitdata ab8500_gpio_resources[] = {
394 .start = AB8500_INT_GPIO6R,
395 .end = AB8500_INT_GPIO41F,
396 .flags = IORESOURCE_IRQ,
400 static struct resource __devinitdata ab8500_gpadc_resources[] = {
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,
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,
415 static struct resource __devinitdata ab8500_rtc_resources[] = {
418 .start = AB8500_INT_RTC_60S,
419 .end = AB8500_INT_RTC_60S,
420 .flags = IORESOURCE_IRQ,
424 .start = AB8500_INT_RTC_ALARM,
425 .end = AB8500_INT_RTC_ALARM,
426 .flags = IORESOURCE_IRQ,
430 static struct resource __devinitdata ab8500_poweronkey_db_resources[] = {
433 .start = AB8500_INT_PON_KEY1DB_F,
434 .end = AB8500_INT_PON_KEY1DB_F,
435 .flags = IORESOURCE_IRQ,
439 .start = AB8500_INT_PON_KEY1DB_R,
440 .end = AB8500_INT_PON_KEY1DB_R,
441 .flags = IORESOURCE_IRQ,
445 static struct resource __devinitdata ab8500_av_acc_detect_resources[] = {
447 .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,
453 .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,
459 .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,
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,
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,
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,
484 static struct resource __devinitdata ab8500_charger_resources[] = {
486 .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,
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,
498 .name = "VBUS_DET_R",
499 .start = AB8500_INT_VBUS_DET_R,
500 .end = AB8500_INT_VBUS_DET_R,
501 .flags = IORESOURCE_IRQ,
504 .name = "VBUS_DET_F",
505 .start = AB8500_INT_VBUS_DET_F,
506 .end = AB8500_INT_VBUS_DET_F,
507 .flags = IORESOURCE_IRQ,
510 .name = "USB_LINK_STATUS",
511 .start = AB8500_INT_USB_LINK_STATUS,
512 .end = AB8500_INT_USB_LINK_STATUS,
513 .flags = IORESOURCE_IRQ,
516 .name = "USB_CHARGE_DET_DONE",
517 .start = AB8500_INT_USB_CHG_DET_DONE,
518 .end = AB8500_INT_USB_CHG_DET_DONE,
519 .flags = IORESOURCE_IRQ,
523 .start = AB8500_INT_VBUS_OVV,
524 .end = AB8500_INT_VBUS_OVV,
525 .flags = IORESOURCE_IRQ,
528 .name = "USB_CH_TH_PROT_R",
529 .start = AB8500_INT_USB_CH_TH_PROT_R,
530 .end = AB8500_INT_USB_CH_TH_PROT_R,
531 .flags = IORESOURCE_IRQ,
534 .name = "USB_CH_TH_PROT_F",
535 .start = AB8500_INT_USB_CH_TH_PROT_F,
536 .end = AB8500_INT_USB_CH_TH_PROT_F,
537 .flags = IORESOURCE_IRQ,
540 .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,
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,
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,
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,
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,
571 .start = AB8500_INT_CH_WD_EXP,
572 .end = AB8500_INT_CH_WD_EXP,
573 .flags = IORESOURCE_IRQ,
577 static struct resource __devinitdata ab8500_btemp_resources[] = {
579 .name = "BAT_CTRL_INDB",
580 .start = AB8500_INT_BAT_CTRL_INDB,
581 .end = AB8500_INT_BAT_CTRL_INDB,
582 .flags = IORESOURCE_IRQ,
586 .start = AB8500_INT_BTEMP_LOW,
587 .end = AB8500_INT_BTEMP_LOW,
588 .flags = IORESOURCE_IRQ,
591 .name = "BTEMP_HIGH",
592 .start = AB8500_INT_BTEMP_HIGH,
593 .end = AB8500_INT_BTEMP_HIGH,
594 .flags = IORESOURCE_IRQ,
597 .name = "BTEMP_LOW_MEDIUM",
598 .start = AB8500_INT_BTEMP_LOW_MEDIUM,
599 .end = AB8500_INT_BTEMP_LOW_MEDIUM,
600 .flags = IORESOURCE_IRQ,
603 .name = "BTEMP_MEDIUM_HIGH",
604 .start = AB8500_INT_BTEMP_MEDIUM_HIGH,
605 .end = AB8500_INT_BTEMP_MEDIUM_HIGH,
606 .flags = IORESOURCE_IRQ,
610 static struct resource __devinitdata ab8500_fg_resources[] = {
612 .name = "NCONV_ACCU",
613 .start = AB8500_INT_CCN_CONV_ACC,
614 .end = AB8500_INT_CCN_CONV_ACC,
615 .flags = IORESOURCE_IRQ,
619 .start = AB8500_INT_BATT_OVV,
620 .end = AB8500_INT_BATT_OVV,
621 .flags = IORESOURCE_IRQ,
625 .start = AB8500_INT_LOW_BAT_F,
626 .end = AB8500_INT_LOW_BAT_F,
627 .flags = IORESOURCE_IRQ,
631 .start = AB8500_INT_LOW_BAT_R,
632 .end = AB8500_INT_LOW_BAT_R,
633 .flags = IORESOURCE_IRQ,
636 .name = "CC_INT_CALIB",
637 .start = AB8500_INT_CC_INT_CALIB,
638 .end = AB8500_INT_CC_INT_CALIB,
639 .flags = IORESOURCE_IRQ,
643 static struct resource __devinitdata ab8500_chargalg_resources[] = {};
645 #ifdef CONFIG_DEBUG_FS
646 static struct resource __devinitdata ab8500_debug_resources[] = {
649 .start = AB8500_INT_MAIN_EXT_CH_NOT_OK,
650 .end = AB8500_INT_MAIN_EXT_CH_NOT_OK,
651 .flags = IORESOURCE_IRQ,
655 .start = AB8500_INT_USB_CHARGER_NOT_OKF,
656 .end = AB8500_INT_USB_CHARGER_NOT_OKF,
657 .flags = IORESOURCE_IRQ,
662 static struct resource __devinitdata ab8500_usb_resources[] = {
664 .name = "ID_WAKEUP_R",
665 .start = AB8500_INT_ID_WAKEUP_R,
666 .end = AB8500_INT_ID_WAKEUP_R,
667 .flags = IORESOURCE_IRQ,
670 .name = "ID_WAKEUP_F",
671 .start = AB8500_INT_ID_WAKEUP_F,
672 .end = AB8500_INT_ID_WAKEUP_F,
673 .flags = IORESOURCE_IRQ,
676 .name = "VBUS_DET_F",
677 .start = AB8500_INT_VBUS_DET_F,
678 .end = AB8500_INT_VBUS_DET_F,
679 .flags = IORESOURCE_IRQ,
682 .name = "VBUS_DET_R",
683 .start = AB8500_INT_VBUS_DET_R,
684 .end = AB8500_INT_VBUS_DET_R,
685 .flags = IORESOURCE_IRQ,
688 .name = "USB_LINK_STATUS",
689 .start = AB8500_INT_USB_LINK_STATUS,
690 .end = AB8500_INT_USB_LINK_STATUS,
691 .flags = IORESOURCE_IRQ,
694 .name = "USB_ADP_PROBE_PLUG",
695 .start = AB8500_INT_ADP_PROBE_PLUG,
696 .end = AB8500_INT_ADP_PROBE_PLUG,
697 .flags = IORESOURCE_IRQ,
700 .name = "USB_ADP_PROBE_UNPLUG",
701 .start = AB8500_INT_ADP_PROBE_UNPLUG,
702 .end = AB8500_INT_ADP_PROBE_UNPLUG,
703 .flags = IORESOURCE_IRQ,
707 static struct resource __devinitdata ab8500_temp_resources[] = {
709 .name = "AB8500_TEMP_WARM",
710 .start = AB8500_INT_TEMP_WARM,
711 .end = AB8500_INT_TEMP_WARM,
712 .flags = IORESOURCE_IRQ,
716 static struct mfd_cell __devinitdata ab8500_devs[] = {
717 #ifdef CONFIG_DEBUG_FS
719 .name = "ab8500-debug",
720 .num_resources = ARRAY_SIZE(ab8500_debug_resources),
721 .resources = ab8500_debug_resources,
725 .name = "ab8500-sysctrl",
728 .name = "ab8500-regulator",
731 .name = "ab8500-gpio",
732 .num_resources = ARRAY_SIZE(ab8500_gpio_resources),
733 .resources = ab8500_gpio_resources,
736 .name = "ab8500-gpadc",
737 .num_resources = ARRAY_SIZE(ab8500_gpadc_resources),
738 .resources = ab8500_gpadc_resources,
741 .name = "ab8500-rtc",
742 .num_resources = ARRAY_SIZE(ab8500_rtc_resources),
743 .resources = ab8500_rtc_resources,
746 .name = "ab8500-charger",
747 .num_resources = ARRAY_SIZE(ab8500_charger_resources),
748 .resources = ab8500_charger_resources,
751 .name = "ab8500-btemp",
752 .num_resources = ARRAY_SIZE(ab8500_btemp_resources),
753 .resources = ab8500_btemp_resources,
757 .num_resources = ARRAY_SIZE(ab8500_fg_resources),
758 .resources = ab8500_fg_resources,
761 .name = "ab8500-chargalg",
762 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
763 .resources = ab8500_chargalg_resources,
766 .name = "ab8500-acc-det",
767 .num_resources = ARRAY_SIZE(ab8500_av_acc_detect_resources),
768 .resources = ab8500_av_acc_detect_resources,
771 .name = "ab8500-codec",
774 .name = "ab8500-usb",
775 .num_resources = ARRAY_SIZE(ab8500_usb_resources),
776 .resources = ab8500_usb_resources,
779 .name = "ab8500-poweron-key",
780 .num_resources = ARRAY_SIZE(ab8500_poweronkey_db_resources),
781 .resources = ab8500_poweronkey_db_resources,
784 .name = "ab8500-pwm",
788 .name = "ab8500-pwm",
792 .name = "ab8500-pwm",
795 { .name = "ab8500-leds", },
797 .name = "ab8500-denc",
800 .name = "ab8500-temp",
801 .num_resources = ARRAY_SIZE(ab8500_temp_resources),
802 .resources = ab8500_temp_resources,
806 static ssize_t show_chip_id(struct device *dev,
807 struct device_attribute *attr, char *buf)
809 struct ab8500 *ab8500;
811 ab8500 = dev_get_drvdata(dev);
812 return sprintf(buf, "%#x\n", ab8500 ? ab8500->chip_id : -EINVAL);
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
826 static ssize_t show_switch_off_status(struct device *dev,
827 struct device_attribute *attr, char *buf)
831 struct ab8500 *ab8500;
833 ab8500 = dev_get_drvdata(dev);
834 ret = get_register_interruptible(ab8500, AB8500_RTC,
835 AB8500_SWITCH_OFF_STATUS, &value);
838 return sprintf(buf, "%#x\n", value);
842 * ab8500 has turned on due to (TURN_ON_STATUS):
852 static ssize_t show_turn_on_status(struct device *dev,
853 struct device_attribute *attr, char *buf)
857 struct ab8500 *ab8500;
859 ab8500 = dev_get_drvdata(dev);
860 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
861 AB8500_TURN_ON_STATUS, &value);
864 return sprintf(buf, "%#x\n", value);
867 static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
868 static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
869 static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
871 static struct attribute *ab8500_sysfs_entries[] = {
872 &dev_attr_chip_id.attr,
873 &dev_attr_switch_off_status.attr,
874 &dev_attr_turn_on_status.attr,
878 static struct attribute_group ab8500_attr_group = {
879 .attrs = ab8500_sysfs_entries,
882 int __devinit ab8500_init(struct ab8500 *ab8500, enum ab8500_version version)
884 struct ab8500_platform_data *plat = dev_get_platdata(ab8500->dev);
890 ab8500->irq_base = plat->irq_base;
892 mutex_init(&ab8500->lock);
893 mutex_init(&ab8500->irq_lock);
895 if (version != AB8500_VERSION_UNDEFINED)
896 ab8500->version = version;
898 ret = get_register_interruptible(ab8500, AB8500_MISC,
899 AB8500_IC_NAME_REG, &value);
903 ab8500->version = value;
906 ret = get_register_interruptible(ab8500, AB8500_MISC,
907 AB8500_REV_REG, &value);
911 ab8500->chip_id = value;
913 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);
918 ab8500->mask_size = AB8500_NUM_IRQ_REGS;
919 ab8500->irq_reg_offset = ab8500_irq_regoffset;
920 ab8500->mask = kzalloc(ab8500->mask_size, GFP_KERNEL);
923 ab8500->oldmask = kzalloc(ab8500->mask_size, GFP_KERNEL);
924 if (!ab8500->oldmask) {
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
940 ret = get_register_interruptible(ab8500, AB8500_RTC,
941 AB8500_SWITCH_OFF_STATUS, &value);
944 dev_info(ab8500->dev, "switch off status: %#x", value);
946 if (plat && plat->init)
949 /* Clear and mask all interrupts */
950 for (i = 0; i < ab8500->mask_size; i++) {
952 * Interrupt register 12 doesn't exist prior to AB8500 version
955 if (ab8500->irq_reg_offset[i] == 11 &&
956 is_ab8500_1p1_or_earlier(ab8500))
959 get_register_interruptible(ab8500, AB8500_INTERRUPT,
960 AB8500_IT_LATCH1_REG + ab8500->irq_reg_offset[i],
962 set_register_interruptible(ab8500, AB8500_INTERRUPT,
963 AB8500_IT_MASK1_REG + ab8500->irq_reg_offset[i], 0xff);
966 ret = abx500_register_ops(ab8500->dev, &ab8500_ops);
968 goto out_freeoldmask;
970 for (i = 0; i < ab8500->mask_size; i++)
971 ab8500->mask[i] = ab8500->oldmask[i] = 0xff;
973 if (ab8500->irq_base) {
974 ret = ab8500_irq_init(ab8500);
976 goto out_freeoldmask;
978 ret = request_threaded_irq(ab8500->irq, NULL, ab8500_irq,
979 IRQF_ONESHOT | IRQF_NO_SUSPEND,
985 ret = mfd_add_devices(ab8500->dev, 0, ab8500_devs,
986 ARRAY_SIZE(ab8500_devs), NULL,
991 ret = sysfs_create_group(&ab8500->dev->kobj, &ab8500_attr_group);
993 dev_err(ab8500->dev, "error creating sysfs entries\n");
998 if (ab8500->irq_base)
999 free_irq(ab8500->irq, ab8500);
1001 if (ab8500->irq_base)
1002 ab8500_irq_remove(ab8500);
1004 kfree(ab8500->oldmask);
1006 kfree(ab8500->mask);
1011 int __devexit ab8500_exit(struct ab8500 *ab8500)
1013 sysfs_remove_group(&ab8500->dev->kobj, &ab8500_attr_group);
1014 mfd_remove_devices(ab8500->dev);
1015 if (ab8500->irq_base) {
1016 free_irq(ab8500->irq, ab8500);
1017 ab8500_irq_remove(ab8500);
1019 kfree(ab8500->oldmask);
1020 kfree(ab8500->mask);
1025 MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
1026 MODULE_DESCRIPTION("AB8500 MFD core");
1027 MODULE_LICENSE("GPL v2");