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 AB9540_IT_SOURCE13_REG 0x0C
36 #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
46 #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
56 #define AB8500_IT_LATCH12_REG 0x2B
57 #define AB9540_IT_LATCH13_REG 0x2C
58 #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
69 #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
94 #define AB8500_REV_REG 0x80
95 #define AB8500_IC_NAME_REG 0x82
96 #define AB8500_SWITCH_OFF_STATUS 0x00
98 #define AB8500_TURN_ON_STATUS 0x00
100 #define AB9540_MODEM_CTRL2_REG 0x23
101 #define AB9540_MODEM_CTRL2_SWDBBRSTN_BIT BIT(2)
104 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
105 * numbers are indexed into this array with (num / 8). The interupts are
106 * defined in linux/mfd/ab8500.h
108 * This is one off from the register names, i.e. AB8500_IT_MASK1_REG is at
112 static const int ab8500_irq_regoffset
[AB8500_NUM_IRQ_REGS
] = {
113 0, 1, 2, 3, 4, 6, 7, 8, 9, 11, 18, 19, 20, 21,
117 static 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,
121 static 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",
128 static int ab8500_get_chip_id(struct device
*dev
)
130 struct ab8500
*ab8500
;
134 ab8500
= dev_get_drvdata(dev
->parent
);
135 return ab8500
? (int)ab8500
->chip_id
: -EINVAL
;
138 static int set_register_interruptible(struct ab8500
*ab8500
, u8 bank
,
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.
146 u16 addr
= ((u16
)bank
) << 8 | reg
;
148 dev_vdbg(ab8500
->dev
, "wr: addr %#x <= %#x\n", addr
, data
);
150 mutex_lock(&ab8500
->lock
);
152 ret
= ab8500
->write(ab8500
, addr
, data
);
154 dev_err(ab8500
->dev
, "failed to write reg %#x: %d\n",
156 mutex_unlock(&ab8500
->lock
);
161 static int ab8500_set_register(struct device
*dev
, u8 bank
,
164 struct ab8500
*ab8500
= dev_get_drvdata(dev
->parent
);
166 return set_register_interruptible(ab8500
, bank
, reg
, value
);
169 static int get_register_interruptible(struct ab8500
*ab8500
, u8 bank
,
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
;
177 mutex_lock(&ab8500
->lock
);
179 ret
= ab8500
->read(ab8500
, addr
);
181 dev_err(ab8500
->dev
, "failed to read reg %#x: %d\n",
186 mutex_unlock(&ab8500
->lock
);
187 dev_vdbg(ab8500
->dev
, "rd: addr %#x => data %#x\n", addr
, ret
);
192 static int ab8500_get_register(struct device
*dev
, u8 bank
,
195 struct ab8500
*ab8500
= dev_get_drvdata(dev
->parent
);
197 return get_register_interruptible(ab8500
, bank
, reg
, value
);
200 static int mask_and_set_register_interruptible(struct ab8500
*ab8500
, u8 bank
,
201 u8 reg
, u8 bitmask
, u8 bitvalues
)
204 /* 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
;
208 mutex_lock(&ab8500
->lock
);
210 if (ab8500
->write_masked
== NULL
) {
213 ret
= ab8500
->read(ab8500
, addr
);
215 dev_err(ab8500
->dev
, "failed to read reg %#x: %d\n",
221 data
= (~bitmask
& data
) | (bitmask
& bitvalues
);
223 ret
= ab8500
->write(ab8500
, addr
, data
);
225 dev_err(ab8500
->dev
, "failed to write reg %#x: %d\n",
228 dev_vdbg(ab8500
->dev
, "mask: addr %#x => data %#x\n", addr
,
232 ret
= ab8500
->write_masked(ab8500
, addr
, bitmask
, bitvalues
);
234 dev_err(ab8500
->dev
, "failed to modify reg %#x: %d\n", addr
,
237 mutex_unlock(&ab8500
->lock
);
241 static int ab8500_mask_and_set_register(struct device
*dev
,
242 u8 bank
, u8 reg
, u8 bitmask
, u8 bitvalues
)
244 struct ab8500
*ab8500
= dev_get_drvdata(dev
->parent
);
246 return mask_and_set_register_interruptible(ab8500
, bank
, reg
,
251 static 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
,
262 static void ab8500_irq_lock(struct irq_data
*data
)
264 struct ab8500
*ab8500
= irq_data_get_irq_chip_data(data
);
266 mutex_lock(&ab8500
->irq_lock
);
269 static void ab8500_irq_sync_unlock(struct irq_data
*data
)
271 struct ab8500
*ab8500
= irq_data_get_irq_chip_data(data
);
274 for (i
= 0; i
< ab8500
->mask_size
; i
++) {
275 u8 old
= ab8500
->oldmask
[i
];
276 u8
new = ab8500
->mask
[i
];
283 * Interrupt register 12 doesn't exist prior to AB8500 version
286 if (ab8500
->irq_reg_offset
[i
] == 11 &&
287 is_ab8500_1p1_or_earlier(ab8500
))
290 ab8500
->oldmask
[i
] = new;
292 reg
= AB8500_IT_MASK1_REG
+ ab8500
->irq_reg_offset
[i
];
293 set_register_interruptible(ab8500
, AB8500_INTERRUPT
, reg
, new);
296 mutex_unlock(&ab8500
->irq_lock
);
299 static void ab8500_irq_mask(struct irq_data
*data
)
301 struct ab8500
*ab8500
= irq_data_get_irq_chip_data(data
);
302 int offset
= data
->irq
- ab8500
->irq_base
;
303 int index
= offset
/ 8;
304 int mask
= 1 << (offset
% 8);
306 ab8500
->mask
[index
] |= mask
;
309 static void ab8500_irq_unmask(struct irq_data
*data
)
311 struct ab8500
*ab8500
= irq_data_get_irq_chip_data(data
);
312 int offset
= data
->irq
- ab8500
->irq_base
;
313 int index
= offset
/ 8;
314 int mask
= 1 << (offset
% 8);
316 ab8500
->mask
[index
] &= ~mask
;
319 static struct irq_chip ab8500_irq_chip
= {
321 .irq_bus_lock
= ab8500_irq_lock
,
322 .irq_bus_sync_unlock
= ab8500_irq_sync_unlock
,
323 .irq_mask
= ab8500_irq_mask
,
324 .irq_disable
= ab8500_irq_mask
,
325 .irq_unmask
= ab8500_irq_unmask
,
328 static irqreturn_t
ab8500_irq(int irq
, void *dev
)
330 struct ab8500
*ab8500
= dev
;
333 dev_vdbg(ab8500
->dev
, "interrupt\n");
335 for (i
= 0; i
< ab8500
->mask_size
; i
++) {
336 int regoffset
= ab8500
->irq_reg_offset
[i
];
341 * Interrupt register 12 doesn't exist prior to AB8500 version
344 if (regoffset
== 11 && is_ab8500_1p1_or_earlier(ab8500
))
347 status
= get_register_interruptible(ab8500
, AB8500_INTERRUPT
,
348 AB8500_IT_LATCH1_REG
+ regoffset
, &value
);
349 if (status
< 0 || value
== 0)
353 int bit
= __ffs(value
);
354 int line
= i
* 8 + bit
;
356 handle_nested_irq(ab8500
->irq_base
+ line
);
357 value
&= ~(1 << bit
);
364 static int ab8500_irq_init(struct ab8500
*ab8500
)
366 int base
= ab8500
->irq_base
;
370 if (is_ab9540(ab8500
))
371 num_irqs
= AB9540_NR_IRQS
;
372 else if (is_ab8505(ab8500
))
373 num_irqs
= AB8505_NR_IRQS
;
375 num_irqs
= AB8500_NR_IRQS
;
377 for (irq
= base
; irq
< base
+ num_irqs
; irq
++) {
378 irq_set_chip_data(irq
, ab8500
);
379 irq_set_chip_and_handler(irq
, &ab8500_irq_chip
,
381 irq_set_nested_thread(irq
, 1);
383 set_irq_flags(irq
, IRQF_VALID
);
385 irq_set_noprobe(irq
);
392 static void ab8500_irq_remove(struct ab8500
*ab8500
)
394 int base
= ab8500
->irq_base
;
398 if (is_ab9540(ab8500
))
399 num_irqs
= AB9540_NR_IRQS
;
400 else if (is_ab8505(ab8500
))
401 num_irqs
= AB8505_NR_IRQS
;
403 num_irqs
= AB8500_NR_IRQS
;
405 for (irq
= base
; irq
< base
+ num_irqs
; irq
++) {
407 set_irq_flags(irq
, 0);
409 irq_set_chip_and_handler(irq
, NULL
, NULL
);
410 irq_set_chip_data(irq
, NULL
);
414 /* AB8500 GPIO Resources */
415 static struct resource __devinitdata ab8500_gpio_resources
[] = {
418 .start
= AB8500_INT_GPIO6R
,
419 .end
= AB8500_INT_GPIO41F
,
420 .flags
= IORESOURCE_IRQ
,
424 /* AB9540 GPIO Resources */
425 static struct resource __devinitdata ab9540_gpio_resources
[] = {
428 .start
= AB8500_INT_GPIO6R
,
429 .end
= AB8500_INT_GPIO41F
,
430 .flags
= IORESOURCE_IRQ
,
433 .name
= "GPIO_INT14",
434 .start
= AB9540_INT_GPIO50R
,
435 .end
= AB9540_INT_GPIO54R
,
436 .flags
= IORESOURCE_IRQ
,
439 .name
= "GPIO_INT15",
440 .start
= AB9540_INT_GPIO50F
,
441 .end
= AB9540_INT_GPIO54F
,
442 .flags
= IORESOURCE_IRQ
,
446 static struct resource __devinitdata ab8500_gpadc_resources
[] = {
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
,
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
,
461 static struct resource __devinitdata ab8500_rtc_resources
[] = {
464 .start
= AB8500_INT_RTC_60S
,
465 .end
= AB8500_INT_RTC_60S
,
466 .flags
= IORESOURCE_IRQ
,
470 .start
= AB8500_INT_RTC_ALARM
,
471 .end
= AB8500_INT_RTC_ALARM
,
472 .flags
= IORESOURCE_IRQ
,
476 static struct resource __devinitdata ab8500_poweronkey_db_resources
[] = {
479 .start
= AB8500_INT_PON_KEY1DB_F
,
480 .end
= AB8500_INT_PON_KEY1DB_F
,
481 .flags
= IORESOURCE_IRQ
,
485 .start
= AB8500_INT_PON_KEY1DB_R
,
486 .end
= AB8500_INT_PON_KEY1DB_R
,
487 .flags
= IORESOURCE_IRQ
,
491 static struct resource __devinitdata ab8500_av_acc_detect_resources
[] = {
493 .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
,
499 .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
,
505 .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
,
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
,
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
,
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
,
530 static struct resource __devinitdata ab8500_charger_resources
[] = {
532 .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
,
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
,
544 .name
= "VBUS_DET_R",
545 .start
= AB8500_INT_VBUS_DET_R
,
546 .end
= AB8500_INT_VBUS_DET_R
,
547 .flags
= IORESOURCE_IRQ
,
550 .name
= "VBUS_DET_F",
551 .start
= AB8500_INT_VBUS_DET_F
,
552 .end
= AB8500_INT_VBUS_DET_F
,
553 .flags
= IORESOURCE_IRQ
,
556 .name
= "USB_LINK_STATUS",
557 .start
= AB8500_INT_USB_LINK_STATUS
,
558 .end
= AB8500_INT_USB_LINK_STATUS
,
559 .flags
= IORESOURCE_IRQ
,
563 .start
= AB8500_INT_VBUS_OVV
,
564 .end
= AB8500_INT_VBUS_OVV
,
565 .flags
= IORESOURCE_IRQ
,
568 .name
= "USB_CH_TH_PROT_R",
569 .start
= AB8500_INT_USB_CH_TH_PROT_R
,
570 .end
= AB8500_INT_USB_CH_TH_PROT_R
,
571 .flags
= IORESOURCE_IRQ
,
574 .name
= "USB_CH_TH_PROT_F",
575 .start
= AB8500_INT_USB_CH_TH_PROT_F
,
576 .end
= AB8500_INT_USB_CH_TH_PROT_F
,
577 .flags
= IORESOURCE_IRQ
,
580 .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
,
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
,
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
,
598 .name
= "USB_CHARGER_NOT_OKR",
599 .start
= AB8500_INT_USB_CHARGER_NOT_OKR
,
600 .end
= AB8500_INT_USB_CHARGER_NOT_OKR
,
601 .flags
= IORESOURCE_IRQ
,
605 .start
= AB8500_INT_CH_WD_EXP
,
606 .end
= AB8500_INT_CH_WD_EXP
,
607 .flags
= IORESOURCE_IRQ
,
611 static struct resource __devinitdata ab8500_btemp_resources
[] = {
613 .name
= "BAT_CTRL_INDB",
614 .start
= AB8500_INT_BAT_CTRL_INDB
,
615 .end
= AB8500_INT_BAT_CTRL_INDB
,
616 .flags
= IORESOURCE_IRQ
,
620 .start
= AB8500_INT_BTEMP_LOW
,
621 .end
= AB8500_INT_BTEMP_LOW
,
622 .flags
= IORESOURCE_IRQ
,
625 .name
= "BTEMP_HIGH",
626 .start
= AB8500_INT_BTEMP_HIGH
,
627 .end
= AB8500_INT_BTEMP_HIGH
,
628 .flags
= IORESOURCE_IRQ
,
631 .name
= "BTEMP_LOW_MEDIUM",
632 .start
= AB8500_INT_BTEMP_LOW_MEDIUM
,
633 .end
= AB8500_INT_BTEMP_LOW_MEDIUM
,
634 .flags
= IORESOURCE_IRQ
,
637 .name
= "BTEMP_MEDIUM_HIGH",
638 .start
= AB8500_INT_BTEMP_MEDIUM_HIGH
,
639 .end
= AB8500_INT_BTEMP_MEDIUM_HIGH
,
640 .flags
= IORESOURCE_IRQ
,
644 static struct resource __devinitdata ab8500_fg_resources
[] = {
646 .name
= "NCONV_ACCU",
647 .start
= AB8500_INT_CCN_CONV_ACC
,
648 .end
= AB8500_INT_CCN_CONV_ACC
,
649 .flags
= IORESOURCE_IRQ
,
653 .start
= AB8500_INT_BATT_OVV
,
654 .end
= AB8500_INT_BATT_OVV
,
655 .flags
= IORESOURCE_IRQ
,
659 .start
= AB8500_INT_LOW_BAT_F
,
660 .end
= AB8500_INT_LOW_BAT_F
,
661 .flags
= IORESOURCE_IRQ
,
665 .start
= AB8500_INT_LOW_BAT_R
,
666 .end
= AB8500_INT_LOW_BAT_R
,
667 .flags
= IORESOURCE_IRQ
,
670 .name
= "CC_INT_CALIB",
671 .start
= AB8500_INT_CC_INT_CALIB
,
672 .end
= AB8500_INT_CC_INT_CALIB
,
673 .flags
= IORESOURCE_IRQ
,
677 .start
= AB8500_INT_CCEOC
,
678 .end
= AB8500_INT_CCEOC
,
679 .flags
= IORESOURCE_IRQ
,
683 static struct resource __devinitdata ab8500_chargalg_resources
[] = {};
685 #ifdef CONFIG_DEBUG_FS
686 static struct resource __devinitdata ab8500_debug_resources
[] = {
689 .start
= AB8500_INT_MAIN_EXT_CH_NOT_OK
,
690 .end
= AB8500_INT_MAIN_EXT_CH_NOT_OK
,
691 .flags
= IORESOURCE_IRQ
,
695 .start
= AB8500_INT_XTAL32K_KO
,
696 .end
= AB8500_INT_XTAL32K_KO
,
697 .flags
= IORESOURCE_IRQ
,
702 static struct resource __devinitdata ab8500_usb_resources
[] = {
704 .name
= "ID_WAKEUP_R",
705 .start
= AB8500_INT_ID_WAKEUP_R
,
706 .end
= AB8500_INT_ID_WAKEUP_R
,
707 .flags
= IORESOURCE_IRQ
,
710 .name
= "ID_WAKEUP_F",
711 .start
= AB8500_INT_ID_WAKEUP_F
,
712 .end
= AB8500_INT_ID_WAKEUP_F
,
713 .flags
= IORESOURCE_IRQ
,
716 .name
= "VBUS_DET_F",
717 .start
= AB8500_INT_VBUS_DET_F
,
718 .end
= AB8500_INT_VBUS_DET_F
,
719 .flags
= IORESOURCE_IRQ
,
722 .name
= "VBUS_DET_R",
723 .start
= AB8500_INT_VBUS_DET_R
,
724 .end
= AB8500_INT_VBUS_DET_R
,
725 .flags
= IORESOURCE_IRQ
,
728 .name
= "USB_LINK_STATUS",
729 .start
= AB8500_INT_USB_LINK_STATUS
,
730 .end
= AB8500_INT_USB_LINK_STATUS
,
731 .flags
= IORESOURCE_IRQ
,
734 .name
= "USB_ADP_PROBE_PLUG",
735 .start
= AB8500_INT_ADP_PROBE_PLUG
,
736 .end
= AB8500_INT_ADP_PROBE_PLUG
,
737 .flags
= IORESOURCE_IRQ
,
740 .name
= "USB_ADP_PROBE_UNPLUG",
741 .start
= AB8500_INT_ADP_PROBE_UNPLUG
,
742 .end
= AB8500_INT_ADP_PROBE_UNPLUG
,
743 .flags
= IORESOURCE_IRQ
,
747 static struct resource __devinitdata ab8500_temp_resources
[] = {
749 .name
= "AB8500_TEMP_WARM",
750 .start
= AB8500_INT_TEMP_WARM
,
751 .end
= AB8500_INT_TEMP_WARM
,
752 .flags
= IORESOURCE_IRQ
,
756 static struct mfd_cell __devinitdata abx500_common_devs
[] = {
757 #ifdef CONFIG_DEBUG_FS
759 .name
= "ab8500-debug",
760 .num_resources
= ARRAY_SIZE(ab8500_debug_resources
),
761 .resources
= ab8500_debug_resources
,
765 .name
= "ab8500-sysctrl",
768 .name
= "ab8500-regulator",
771 .name
= "ab8500-gpadc",
772 .num_resources
= ARRAY_SIZE(ab8500_gpadc_resources
),
773 .resources
= ab8500_gpadc_resources
,
776 .name
= "ab8500-rtc",
777 .num_resources
= ARRAY_SIZE(ab8500_rtc_resources
),
778 .resources
= ab8500_rtc_resources
,
781 .name
= "ab8500-charger",
782 .num_resources
= ARRAY_SIZE(ab8500_charger_resources
),
783 .resources
= ab8500_charger_resources
,
786 .name
= "ab8500-btemp",
787 .num_resources
= ARRAY_SIZE(ab8500_btemp_resources
),
788 .resources
= ab8500_btemp_resources
,
792 .num_resources
= ARRAY_SIZE(ab8500_fg_resources
),
793 .resources
= ab8500_fg_resources
,
796 .name
= "ab8500-chargalg",
797 .num_resources
= ARRAY_SIZE(ab8500_chargalg_resources
),
798 .resources
= ab8500_chargalg_resources
,
801 .name
= "ab8500-acc-det",
802 .num_resources
= ARRAY_SIZE(ab8500_av_acc_detect_resources
),
803 .resources
= ab8500_av_acc_detect_resources
,
806 .name
= "ab8500-codec",
810 .name
= "ab8500-poweron-key",
811 .num_resources
= ARRAY_SIZE(ab8500_poweronkey_db_resources
),
812 .resources
= ab8500_poweronkey_db_resources
,
815 .name
= "ab8500-pwm",
819 .name
= "ab8500-pwm",
823 .name
= "ab8500-pwm",
826 { .name
= "ab8500-leds", },
828 .name
= "ab8500-denc",
831 .name
= "ab8500-temp",
832 .num_resources
= ARRAY_SIZE(ab8500_temp_resources
),
833 .resources
= ab8500_temp_resources
,
837 static struct mfd_cell __devinitdata ab8500_devs
[] = {
839 .name
= "ab8500-gpio",
840 .num_resources
= ARRAY_SIZE(ab8500_gpio_resources
),
841 .resources
= ab8500_gpio_resources
,
844 .name
= "ab8500-usb",
845 .num_resources
= ARRAY_SIZE(ab8500_usb_resources
),
846 .resources
= ab8500_usb_resources
,
850 static struct mfd_cell __devinitdata ab9540_devs
[] = {
852 .name
= "ab8500-gpio",
853 .num_resources
= ARRAY_SIZE(ab9540_gpio_resources
),
854 .resources
= ab9540_gpio_resources
,
857 .name
= "ab9540-usb",
858 .num_resources
= ARRAY_SIZE(ab8500_usb_resources
),
859 .resources
= ab8500_usb_resources
,
863 static ssize_t
show_chip_id(struct device
*dev
,
864 struct device_attribute
*attr
, char *buf
)
866 struct ab8500
*ab8500
;
868 ab8500
= dev_get_drvdata(dev
);
869 return sprintf(buf
, "%#x\n", ab8500
? ab8500
->chip_id
: -EINVAL
);
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
883 static ssize_t
show_switch_off_status(struct device
*dev
,
884 struct device_attribute
*attr
, char *buf
)
888 struct ab8500
*ab8500
;
890 ab8500
= dev_get_drvdata(dev
);
891 ret
= get_register_interruptible(ab8500
, AB8500_RTC
,
892 AB8500_SWITCH_OFF_STATUS
, &value
);
895 return sprintf(buf
, "%#x\n", value
);
899 * ab8500 has turned on due to (TURN_ON_STATUS):
909 static ssize_t
show_turn_on_status(struct device
*dev
,
910 struct device_attribute
*attr
, char *buf
)
914 struct ab8500
*ab8500
;
916 ab8500
= dev_get_drvdata(dev
);
917 ret
= get_register_interruptible(ab8500
, AB8500_SYS_CTRL1_BLOCK
,
918 AB8500_TURN_ON_STATUS
, &value
);
921 return sprintf(buf
, "%#x\n", value
);
924 static ssize_t
show_ab9540_dbbrstn(struct device
*dev
,
925 struct device_attribute
*attr
, char *buf
)
927 struct ab8500
*ab8500
;
931 ab8500
= dev_get_drvdata(dev
);
933 ret
= get_register_interruptible(ab8500
, AB8500_REGU_CTRL2
,
934 AB9540_MODEM_CTRL2_REG
, &value
);
938 return sprintf(buf
, "%d\n",
939 (value
& AB9540_MODEM_CTRL2_SWDBBRSTN_BIT
) ? 1 : 0);
942 static ssize_t
store_ab9540_dbbrstn(struct device
*dev
,
943 struct device_attribute
*attr
, const char *buf
, size_t count
)
945 struct ab8500
*ab8500
;
950 ab8500
= dev_get_drvdata(dev
);
958 bitvalues
= AB9540_MODEM_CTRL2_SWDBBRSTN_BIT
;
964 err
= mask_and_set_register_interruptible(ab8500
,
965 AB8500_REGU_CTRL2
, AB9540_MODEM_CTRL2_REG
,
966 AB9540_MODEM_CTRL2_SWDBBRSTN_BIT
, bitvalues
);
968 dev_info(ab8500
->dev
,
969 "Failed to set DBBRSTN %c, err %#x\n",
977 static DEVICE_ATTR(chip_id
, S_IRUGO
, show_chip_id
, NULL
);
978 static DEVICE_ATTR(switch_off_status
, S_IRUGO
, show_switch_off_status
, NULL
);
979 static DEVICE_ATTR(turn_on_status
, S_IRUGO
, show_turn_on_status
, NULL
);
980 static DEVICE_ATTR(dbbrstn
, S_IRUGO
| S_IWUSR
,
981 show_ab9540_dbbrstn
, store_ab9540_dbbrstn
);
983 static struct attribute
*ab8500_sysfs_entries
[] = {
984 &dev_attr_chip_id
.attr
,
985 &dev_attr_switch_off_status
.attr
,
986 &dev_attr_turn_on_status
.attr
,
990 static 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
,
998 static struct attribute_group ab8500_attr_group
= {
999 .attrs
= ab8500_sysfs_entries
,
1002 static struct attribute_group ab9540_attr_group
= {
1003 .attrs
= ab9540_sysfs_entries
,
1006 int __devinit
ab8500_init(struct ab8500
*ab8500
, enum ab8500_version version
)
1008 struct ab8500_platform_data
*plat
= dev_get_platdata(ab8500
->dev
);
1014 ab8500
->irq_base
= plat
->irq_base
;
1016 mutex_init(&ab8500
->lock
);
1017 mutex_init(&ab8500
->irq_lock
);
1019 if (version
!= AB8500_VERSION_UNDEFINED
)
1020 ab8500
->version
= version
;
1022 ret
= get_register_interruptible(ab8500
, AB8500_MISC
,
1023 AB8500_IC_NAME_REG
, &value
);
1027 ab8500
->version
= value
;
1030 ret
= get_register_interruptible(ab8500
, AB8500_MISC
,
1031 AB8500_REV_REG
, &value
);
1035 ab8500
->chip_id
= value
;
1037 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);
1042 /* Configure AB8500 or AB9540 IRQ */
1043 if (is_ab9540(ab8500
) || is_ab8505(ab8500
)) {
1044 ab8500
->mask_size
= AB9540_NUM_IRQ_REGS
;
1045 ab8500
->irq_reg_offset
= ab9540_irq_regoffset
;
1047 ab8500
->mask_size
= AB8500_NUM_IRQ_REGS
;
1048 ab8500
->irq_reg_offset
= ab8500_irq_regoffset
;
1050 ab8500
->mask
= kzalloc(ab8500
->mask_size
, GFP_KERNEL
);
1053 ab8500
->oldmask
= kzalloc(ab8500
->mask_size
, GFP_KERNEL
);
1054 if (!ab8500
->oldmask
) {
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
1070 ret
= get_register_interruptible(ab8500
, AB8500_RTC
,
1071 AB8500_SWITCH_OFF_STATUS
, &value
);
1074 dev_info(ab8500
->dev
, "switch off status: %#x", value
);
1076 if (plat
&& plat
->init
)
1079 /* Clear and mask all interrupts */
1080 for (i
= 0; i
< ab8500
->mask_size
; i
++) {
1082 * Interrupt register 12 doesn't exist prior to AB8500 version
1085 if (ab8500
->irq_reg_offset
[i
] == 11 &&
1086 is_ab8500_1p1_or_earlier(ab8500
))
1089 get_register_interruptible(ab8500
, AB8500_INTERRUPT
,
1090 AB8500_IT_LATCH1_REG
+ ab8500
->irq_reg_offset
[i
],
1092 set_register_interruptible(ab8500
, AB8500_INTERRUPT
,
1093 AB8500_IT_MASK1_REG
+ ab8500
->irq_reg_offset
[i
], 0xff);
1096 ret
= abx500_register_ops(ab8500
->dev
, &ab8500_ops
);
1098 goto out_freeoldmask
;
1100 for (i
= 0; i
< ab8500
->mask_size
; i
++)
1101 ab8500
->mask
[i
] = ab8500
->oldmask
[i
] = 0xff;
1103 if (ab8500
->irq_base
) {
1104 ret
= ab8500_irq_init(ab8500
);
1106 goto out_freeoldmask
;
1108 ret
= request_threaded_irq(ab8500
->irq
, NULL
, ab8500_irq
,
1109 IRQF_ONESHOT
| IRQF_NO_SUSPEND
,
1115 ret
= mfd_add_devices(ab8500
->dev
, 0, abx500_common_devs
,
1116 ARRAY_SIZE(abx500_common_devs
), NULL
,
1122 if (is_ab9540(ab8500
))
1123 ret
= mfd_add_devices(ab8500
->dev
, 0, ab9540_devs
,
1124 ARRAY_SIZE(ab9540_devs
), NULL
,
1127 ret
= mfd_add_devices(ab8500
->dev
, 0, ab8500_devs
,
1128 ARRAY_SIZE(ab9540_devs
), NULL
,
1133 if (is_ab9540(ab8500
))
1134 ret
= sysfs_create_group(&ab8500
->dev
->kobj
,
1135 &ab9540_attr_group
);
1137 ret
= sysfs_create_group(&ab8500
->dev
->kobj
,
1138 &ab8500_attr_group
);
1140 dev_err(ab8500
->dev
, "error creating sysfs entries\n");
1145 if (ab8500
->irq_base
)
1146 free_irq(ab8500
->irq
, ab8500
);
1148 if (ab8500
->irq_base
)
1149 ab8500_irq_remove(ab8500
);
1151 kfree(ab8500
->oldmask
);
1153 kfree(ab8500
->mask
);
1158 int __devexit
ab8500_exit(struct ab8500
*ab8500
)
1160 if (is_ab9540(ab8500
))
1161 sysfs_remove_group(&ab8500
->dev
->kobj
, &ab9540_attr_group
);
1163 sysfs_remove_group(&ab8500
->dev
->kobj
, &ab8500_attr_group
);
1164 mfd_remove_devices(ab8500
->dev
);
1165 if (ab8500
->irq_base
) {
1166 free_irq(ab8500
->irq
, ab8500
);
1167 ab8500_irq_remove(ab8500
);
1169 kfree(ab8500
->oldmask
);
1170 kfree(ab8500
->mask
);
1175 MODULE_AUTHOR("Mattias Wallin, Srinidhi Kasagar, Rabin Vincent");
1176 MODULE_DESCRIPTION("AB8500 MFD core");
1177 MODULE_LICENSE("GPL v2");