2 * Base driver for Marvell 88PM8607
4 * Copyright (C) 2009 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/i2c.h>
15 #include <linux/irq.h>
16 #include <linux/interrupt.h>
17 #include <linux/platform_device.h>
18 #include <linux/mfd/core.h>
19 #include <linux/mfd/88pm860x.h>
20 #include <linux/regulator/machine.h>
22 #define INT_STATUS_NUM 3
24 static struct resource bk_resources
[] __devinitdata
= {
25 {PM8606_BACKLIGHT1
, PM8606_BACKLIGHT1
, "backlight-0", IORESOURCE_IO
,},
26 {PM8606_BACKLIGHT2
, PM8606_BACKLIGHT2
, "backlight-1", IORESOURCE_IO
,},
27 {PM8606_BACKLIGHT3
, PM8606_BACKLIGHT3
, "backlight-2", IORESOURCE_IO
,},
30 static struct resource led_resources
[] __devinitdata
= {
31 {PM8606_LED1_RED
, PM8606_LED1_RED
, "led0-red", IORESOURCE_IO
,},
32 {PM8606_LED1_GREEN
, PM8606_LED1_GREEN
, "led0-green", IORESOURCE_IO
,},
33 {PM8606_LED1_BLUE
, PM8606_LED1_BLUE
, "led0-blue", IORESOURCE_IO
,},
34 {PM8606_LED2_RED
, PM8606_LED2_RED
, "led1-red", IORESOURCE_IO
,},
35 {PM8606_LED2_GREEN
, PM8606_LED2_GREEN
, "led1-green", IORESOURCE_IO
,},
36 {PM8606_LED2_BLUE
, PM8606_LED2_BLUE
, "led1-blue", IORESOURCE_IO
,},
39 static struct resource regulator_resources
[] __devinitdata
= {
40 {PM8607_ID_BUCK1
, PM8607_ID_BUCK1
, "buck-1", IORESOURCE_IO
,},
41 {PM8607_ID_BUCK2
, PM8607_ID_BUCK2
, "buck-2", IORESOURCE_IO
,},
42 {PM8607_ID_BUCK3
, PM8607_ID_BUCK3
, "buck-3", IORESOURCE_IO
,},
43 {PM8607_ID_LDO1
, PM8607_ID_LDO1
, "ldo-01", IORESOURCE_IO
,},
44 {PM8607_ID_LDO2
, PM8607_ID_LDO2
, "ldo-02", IORESOURCE_IO
,},
45 {PM8607_ID_LDO3
, PM8607_ID_LDO3
, "ldo-03", IORESOURCE_IO
,},
46 {PM8607_ID_LDO4
, PM8607_ID_LDO4
, "ldo-04", IORESOURCE_IO
,},
47 {PM8607_ID_LDO5
, PM8607_ID_LDO5
, "ldo-05", IORESOURCE_IO
,},
48 {PM8607_ID_LDO6
, PM8607_ID_LDO6
, "ldo-06", IORESOURCE_IO
,},
49 {PM8607_ID_LDO7
, PM8607_ID_LDO7
, "ldo-07", IORESOURCE_IO
,},
50 {PM8607_ID_LDO8
, PM8607_ID_LDO8
, "ldo-08", IORESOURCE_IO
,},
51 {PM8607_ID_LDO9
, PM8607_ID_LDO9
, "ldo-09", IORESOURCE_IO
,},
52 {PM8607_ID_LDO10
, PM8607_ID_LDO10
, "ldo-10", IORESOURCE_IO
,},
53 {PM8607_ID_LDO11
, PM8607_ID_LDO11
, "ldo-11", IORESOURCE_IO
,},
54 {PM8607_ID_LDO12
, PM8607_ID_LDO12
, "ldo-12", IORESOURCE_IO
,},
55 {PM8607_ID_LDO13
, PM8607_ID_LDO13
, "ldo-13", IORESOURCE_IO
,},
56 {PM8607_ID_LDO14
, PM8607_ID_LDO14
, "ldo-14", IORESOURCE_IO
,},
57 {PM8607_ID_LDO15
, PM8607_ID_LDO15
, "ldo-15", IORESOURCE_IO
,},
60 static struct resource touch_resources
[] __devinitdata
= {
61 {PM8607_IRQ_PEN
, PM8607_IRQ_PEN
, "touch", IORESOURCE_IRQ
,},
64 static struct resource onkey_resources
[] __devinitdata
= {
65 {PM8607_IRQ_ONKEY
, PM8607_IRQ_ONKEY
, "onkey", IORESOURCE_IRQ
,},
68 static struct resource codec_resources
[] __devinitdata
= {
69 /* Headset microphone insertion or removal */
70 {PM8607_IRQ_MICIN
, PM8607_IRQ_MICIN
, "micin", IORESOURCE_IRQ
,},
71 /* Hook-switch press or release */
72 {PM8607_IRQ_HOOK
, PM8607_IRQ_HOOK
, "hook", IORESOURCE_IRQ
,},
73 /* Headset insertion or removal */
74 {PM8607_IRQ_HEADSET
, PM8607_IRQ_HEADSET
, "headset", IORESOURCE_IRQ
,},
76 {PM8607_IRQ_AUDIO_SHORT
, PM8607_IRQ_AUDIO_SHORT
, "audio-short", IORESOURCE_IRQ
,},
79 static struct resource battery_resources
[] __devinitdata
= {
80 {PM8607_IRQ_CC
, PM8607_IRQ_CC
, "columb counter", IORESOURCE_IRQ
,},
81 {PM8607_IRQ_BAT
, PM8607_IRQ_BAT
, "battery", IORESOURCE_IRQ
,},
84 static struct resource charger_resources
[] __devinitdata
= {
85 {PM8607_IRQ_CHG
, PM8607_IRQ_CHG
, "charger detect", IORESOURCE_IRQ
,},
86 {PM8607_IRQ_CHG_DONE
, PM8607_IRQ_CHG_DONE
, "charging done", IORESOURCE_IRQ
,},
87 {PM8607_IRQ_CHG_FAULT
, PM8607_IRQ_CHG_FAULT
, "charging timeout", IORESOURCE_IRQ
,},
88 {PM8607_IRQ_GPADC1
, PM8607_IRQ_GPADC1
, "battery temperature", IORESOURCE_IRQ
,},
89 {PM8607_IRQ_VBAT
, PM8607_IRQ_VBAT
, "battery voltage", IORESOURCE_IRQ
,},
90 {PM8607_IRQ_VCHG
, PM8607_IRQ_VCHG
, "vchg voltage", IORESOURCE_IRQ
,},
93 static struct resource rtc_resources
[] __devinitdata
= {
94 {PM8607_IRQ_RTC
, PM8607_IRQ_RTC
, "rtc", IORESOURCE_IRQ
,},
97 static struct mfd_cell bk_devs
[] = {
98 {"88pm860x-backlight", 0,},
99 {"88pm860x-backlight", 1,},
100 {"88pm860x-backlight", 2,},
103 static struct mfd_cell led_devs
[] = {
104 {"88pm860x-led", 0,},
105 {"88pm860x-led", 1,},
106 {"88pm860x-led", 2,},
107 {"88pm860x-led", 3,},
108 {"88pm860x-led", 4,},
109 {"88pm860x-led", 5,},
112 static struct mfd_cell regulator_devs
[] = {
113 {"88pm860x-regulator", 0,},
114 {"88pm860x-regulator", 1,},
115 {"88pm860x-regulator", 2,},
116 {"88pm860x-regulator", 3,},
117 {"88pm860x-regulator", 4,},
118 {"88pm860x-regulator", 5,},
119 {"88pm860x-regulator", 6,},
120 {"88pm860x-regulator", 7,},
121 {"88pm860x-regulator", 8,},
122 {"88pm860x-regulator", 9,},
123 {"88pm860x-regulator", 10,},
124 {"88pm860x-regulator", 11,},
125 {"88pm860x-regulator", 12,},
126 {"88pm860x-regulator", 13,},
127 {"88pm860x-regulator", 14,},
128 {"88pm860x-regulator", 15,},
129 {"88pm860x-regulator", 16,},
130 {"88pm860x-regulator", 17,},
133 static struct mfd_cell touch_devs
[] = {
134 {"88pm860x-touch", -1,},
137 static struct mfd_cell onkey_devs
[] = {
138 {"88pm860x-onkey", -1,},
141 static struct mfd_cell codec_devs
[] = {
142 {"88pm860x-codec", -1,},
145 static struct mfd_cell power_devs
[] = {
146 {"88pm860x-battery", -1,},
147 {"88pm860x-charger", -1,},
150 static struct mfd_cell rtc_devs
[] = {
151 {"88pm860x-rtc", -1,},
155 struct pm860x_irq_data
{
158 int enable
; /* enable or not */
159 int offs
; /* bit offset in mask register */
162 static struct pm860x_irq_data pm860x_irqs
[] = {
163 [PM8607_IRQ_ONKEY
] = {
164 .reg
= PM8607_INT_STATUS1
,
165 .mask_reg
= PM8607_INT_MASK_1
,
168 [PM8607_IRQ_EXTON
] = {
169 .reg
= PM8607_INT_STATUS1
,
170 .mask_reg
= PM8607_INT_MASK_1
,
174 .reg
= PM8607_INT_STATUS1
,
175 .mask_reg
= PM8607_INT_MASK_1
,
179 .reg
= PM8607_INT_STATUS1
,
180 .mask_reg
= PM8607_INT_MASK_1
,
184 .reg
= PM8607_INT_STATUS1
,
185 .mask_reg
= PM8607_INT_MASK_1
,
189 .reg
= PM8607_INT_STATUS1
,
190 .mask_reg
= PM8607_INT_MASK_1
,
193 [PM8607_IRQ_VBAT
] = {
194 .reg
= PM8607_INT_STATUS2
,
195 .mask_reg
= PM8607_INT_MASK_2
,
198 [PM8607_IRQ_VCHG
] = {
199 .reg
= PM8607_INT_STATUS2
,
200 .mask_reg
= PM8607_INT_MASK_2
,
203 [PM8607_IRQ_VSYS
] = {
204 .reg
= PM8607_INT_STATUS2
,
205 .mask_reg
= PM8607_INT_MASK_2
,
208 [PM8607_IRQ_TINT
] = {
209 .reg
= PM8607_INT_STATUS2
,
210 .mask_reg
= PM8607_INT_MASK_2
,
213 [PM8607_IRQ_GPADC0
] = {
214 .reg
= PM8607_INT_STATUS2
,
215 .mask_reg
= PM8607_INT_MASK_2
,
218 [PM8607_IRQ_GPADC1
] = {
219 .reg
= PM8607_INT_STATUS2
,
220 .mask_reg
= PM8607_INT_MASK_2
,
223 [PM8607_IRQ_GPADC2
] = {
224 .reg
= PM8607_INT_STATUS2
,
225 .mask_reg
= PM8607_INT_MASK_2
,
228 [PM8607_IRQ_GPADC3
] = {
229 .reg
= PM8607_INT_STATUS2
,
230 .mask_reg
= PM8607_INT_MASK_2
,
233 [PM8607_IRQ_AUDIO_SHORT
] = {
234 .reg
= PM8607_INT_STATUS3
,
235 .mask_reg
= PM8607_INT_MASK_3
,
239 .reg
= PM8607_INT_STATUS3
,
240 .mask_reg
= PM8607_INT_MASK_3
,
243 [PM8607_IRQ_HEADSET
] = {
244 .reg
= PM8607_INT_STATUS3
,
245 .mask_reg
= PM8607_INT_MASK_3
,
248 [PM8607_IRQ_HOOK
] = {
249 .reg
= PM8607_INT_STATUS3
,
250 .mask_reg
= PM8607_INT_MASK_3
,
253 [PM8607_IRQ_MICIN
] = {
254 .reg
= PM8607_INT_STATUS3
,
255 .mask_reg
= PM8607_INT_MASK_3
,
258 [PM8607_IRQ_CHG_FAIL
] = {
259 .reg
= PM8607_INT_STATUS3
,
260 .mask_reg
= PM8607_INT_MASK_3
,
263 [PM8607_IRQ_CHG_DONE
] = {
264 .reg
= PM8607_INT_STATUS3
,
265 .mask_reg
= PM8607_INT_MASK_3
,
268 [PM8607_IRQ_CHG_FAULT
] = {
269 .reg
= PM8607_INT_STATUS3
,
270 .mask_reg
= PM8607_INT_MASK_3
,
275 static irqreturn_t
pm860x_irq(int irq
, void *data
)
277 struct pm860x_chip
*chip
= data
;
278 struct pm860x_irq_data
*irq_data
;
279 struct i2c_client
*i2c
;
280 int read_reg
= -1, value
= 0;
283 i2c
= (chip
->id
== CHIP_PM8607
) ? chip
->client
: chip
->companion
;
284 for (i
= 0; i
< ARRAY_SIZE(pm860x_irqs
); i
++) {
285 irq_data
= &pm860x_irqs
[i
];
286 if (read_reg
!= irq_data
->reg
) {
287 read_reg
= irq_data
->reg
;
288 value
= pm860x_reg_read(i2c
, irq_data
->reg
);
290 if (value
& irq_data
->enable
)
291 handle_nested_irq(chip
->irq_base
+ i
);
296 static void pm860x_irq_lock(struct irq_data
*data
)
298 struct pm860x_chip
*chip
= irq_data_get_irq_chip_data(data
);
300 mutex_lock(&chip
->irq_lock
);
303 static void pm860x_irq_sync_unlock(struct irq_data
*data
)
305 struct pm860x_chip
*chip
= irq_data_get_irq_chip_data(data
);
306 struct pm860x_irq_data
*irq_data
;
307 struct i2c_client
*i2c
;
308 static unsigned char cached
[3] = {0x0, 0x0, 0x0};
309 unsigned char mask
[3];
312 i2c
= (chip
->id
== CHIP_PM8607
) ? chip
->client
: chip
->companion
;
313 /* Load cached value. In initial, all IRQs are masked */
314 for (i
= 0; i
< 3; i
++)
316 for (i
= 0; i
< ARRAY_SIZE(pm860x_irqs
); i
++) {
317 irq_data
= &pm860x_irqs
[i
];
318 switch (irq_data
->mask_reg
) {
319 case PM8607_INT_MASK_1
:
320 mask
[0] &= ~irq_data
->offs
;
321 mask
[0] |= irq_data
->enable
;
323 case PM8607_INT_MASK_2
:
324 mask
[1] &= ~irq_data
->offs
;
325 mask
[1] |= irq_data
->enable
;
327 case PM8607_INT_MASK_3
:
328 mask
[2] &= ~irq_data
->offs
;
329 mask
[2] |= irq_data
->enable
;
332 dev_err(chip
->dev
, "wrong IRQ\n");
336 /* update mask into registers */
337 for (i
= 0; i
< 3; i
++) {
338 if (mask
[i
] != cached
[i
]) {
340 pm860x_reg_write(i2c
, PM8607_INT_MASK_1
+ i
, mask
[i
]);
344 mutex_unlock(&chip
->irq_lock
);
347 static void pm860x_irq_enable(struct irq_data
*data
)
349 struct pm860x_chip
*chip
= irq_data_get_irq_chip_data(data
);
350 pm860x_irqs
[data
->irq
- chip
->irq_base
].enable
351 = pm860x_irqs
[data
->irq
- chip
->irq_base
].offs
;
354 static void pm860x_irq_disable(struct irq_data
*data
)
356 struct pm860x_chip
*chip
= irq_data_get_irq_chip_data(data
);
357 pm860x_irqs
[data
->irq
- chip
->irq_base
].enable
= 0;
360 static struct irq_chip pm860x_irq_chip
= {
362 .irq_bus_lock
= pm860x_irq_lock
,
363 .irq_bus_sync_unlock
= pm860x_irq_sync_unlock
,
364 .irq_enable
= pm860x_irq_enable
,
365 .irq_disable
= pm860x_irq_disable
,
368 static int __devinit
device_gpadc_init(struct pm860x_chip
*chip
,
369 struct pm860x_platform_data
*pdata
)
371 struct i2c_client
*i2c
= (chip
->id
== CHIP_PM8607
) ? chip
->client \
376 /* initialize GPADC without activating it */
378 if (!pdata
|| !pdata
->touch
)
381 /* set GPADC MISC1 register */
383 data
|= (pdata
->touch
->gpadc_prebias
<< 1) & PM8607_GPADC_PREBIAS_MASK
;
384 data
|= (pdata
->touch
->slot_cycle
<< 3) & PM8607_GPADC_SLOT_CYCLE_MASK
;
385 data
|= (pdata
->touch
->off_scale
<< 5) & PM8607_GPADC_OFF_SCALE_MASK
;
386 data
|= (pdata
->touch
->sw_cal
<< 7) & PM8607_GPADC_SW_CAL_MASK
;
388 ret
= pm860x_reg_write(i2c
, PM8607_GPADC_MISC1
, data
);
392 /* set tsi prebias time */
393 if (pdata
->touch
->tsi_prebias
) {
394 data
= pdata
->touch
->tsi_prebias
;
395 ret
= pm860x_reg_write(i2c
, PM8607_TSI_PREBIAS
, data
);
399 /* set prebias & prechg time of pen detect */
401 data
|= pdata
->touch
->pen_prebias
& PM8607_PD_PREBIAS_MASK
;
402 data
|= (pdata
->touch
->pen_prechg
<< 5) & PM8607_PD_PRECHG_MASK
;
404 ret
= pm860x_reg_write(i2c
, PM8607_PD_PREBIAS
, data
);
409 ret
= pm860x_set_bits(i2c
, PM8607_GPADC_MISC1
,
410 PM8607_GPADC_EN
, PM8607_GPADC_EN
);
415 static int __devinit
device_irq_init(struct pm860x_chip
*chip
,
416 struct pm860x_platform_data
*pdata
)
418 struct i2c_client
*i2c
= (chip
->id
== CHIP_PM8607
) ? chip
->client \
420 unsigned char status_buf
[INT_STATUS_NUM
];
421 unsigned long flags
= IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
;
422 int i
, data
, mask
, ret
= -EINVAL
;
425 if (!pdata
|| !pdata
->irq_base
) {
426 dev_warn(chip
->dev
, "No interrupt support on IRQ base\n");
430 mask
= PM8607_B0_MISC1_INV_INT
| PM8607_B0_MISC1_INT_CLEAR
431 | PM8607_B0_MISC1_INT_MASK
;
434 if (pdata
&& pdata
->irq_mode
) {
436 * irq_mode defines the way of clearing interrupt. If it's 1,
437 * clear IRQ by write. Otherwise, clear it by read.
438 * This control bit is valid from 88PM8607 B0 steping.
440 data
|= PM8607_B0_MISC1_INT_CLEAR
;
443 ret
= pm860x_set_bits(i2c
, PM8607_B0_MISC1
, mask
, data
);
448 memset(status_buf
, 0, INT_STATUS_NUM
);
449 ret
= pm860x_bulk_write(i2c
, PM8607_INT_MASK_1
,
450 INT_STATUS_NUM
, status_buf
);
454 if (chip
->irq_mode
) {
455 /* clear interrupt status by write */
456 memset(status_buf
, 0xFF, INT_STATUS_NUM
);
457 ret
= pm860x_bulk_write(i2c
, PM8607_INT_STATUS1
,
458 INT_STATUS_NUM
, status_buf
);
460 /* clear interrupt status by read */
461 ret
= pm860x_bulk_read(i2c
, PM8607_INT_STATUS1
,
462 INT_STATUS_NUM
, status_buf
);
467 mutex_init(&chip
->irq_lock
);
468 chip
->irq_base
= pdata
->irq_base
;
469 chip
->core_irq
= i2c
->irq
;
473 /* register IRQ by genirq */
474 for (i
= 0; i
< ARRAY_SIZE(pm860x_irqs
); i
++) {
475 __irq
= i
+ chip
->irq_base
;
476 irq_set_chip_data(__irq
, chip
);
477 irq_set_chip_and_handler(__irq
, &pm860x_irq_chip
,
479 irq_set_nested_thread(__irq
, 1);
481 set_irq_flags(__irq
, IRQF_VALID
);
483 irq_set_noprobe(__irq
);
487 ret
= request_threaded_irq(chip
->core_irq
, NULL
, pm860x_irq
, flags
,
490 dev_err(chip
->dev
, "Failed to request IRQ: %d\n", ret
);
500 static void device_irq_exit(struct pm860x_chip
*chip
)
503 free_irq(chip
->core_irq
, chip
);
506 static void __devinit
device_bk_init(struct pm860x_chip
*chip
,
507 struct pm860x_platform_data
*pdata
)
512 if ((pdata
== NULL
) || (pdata
->backlight
== NULL
))
515 if (pdata
->num_backlights
> ARRAY_SIZE(bk_devs
))
516 pdata
->num_backlights
= ARRAY_SIZE(bk_devs
);
518 for (i
= 0; i
< pdata
->num_backlights
; i
++) {
519 bk_devs
[i
].platform_data
= &pdata
->backlight
[i
];
520 bk_devs
[i
].pdata_size
= sizeof(struct pm860x_backlight_pdata
);
522 for (j
= 0; j
< ARRAY_SIZE(bk_devs
); j
++) {
523 id
= bk_resources
[j
].start
;
524 if (pdata
->backlight
[i
].flags
!= id
)
527 bk_devs
[i
].num_resources
= 1;
528 bk_devs
[i
].resources
= &bk_resources
[j
];
529 ret
= mfd_add_devices(chip
->dev
, 0,
531 &bk_resources
[j
], 0);
533 dev_err(chip
->dev
, "Failed to add "
534 "backlight subdev\n");
541 static void __devinit
device_led_init(struct pm860x_chip
*chip
,
542 struct pm860x_platform_data
*pdata
)
547 if ((pdata
== NULL
) || (pdata
->led
== NULL
))
550 if (pdata
->num_leds
> ARRAY_SIZE(led_devs
))
551 pdata
->num_leds
= ARRAY_SIZE(led_devs
);
553 for (i
= 0; i
< pdata
->num_leds
; i
++) {
554 led_devs
[i
].platform_data
= &pdata
->led
[i
];
555 led_devs
[i
].pdata_size
= sizeof(struct pm860x_led_pdata
);
557 for (j
= 0; j
< ARRAY_SIZE(led_devs
); j
++) {
558 id
= led_resources
[j
].start
;
559 if (pdata
->led
[i
].flags
!= id
)
562 led_devs
[i
].num_resources
= 1;
563 led_devs
[i
].resources
= &led_resources
[j
],
564 ret
= mfd_add_devices(chip
->dev
, 0,
566 &led_resources
[j
], 0);
568 dev_err(chip
->dev
, "Failed to add "
576 static void __devinit
device_regulator_init(struct pm860x_chip
*chip
,
577 struct pm860x_platform_data
*pdata
)
579 struct regulator_init_data
*initdata
;
583 if ((pdata
== NULL
) || (pdata
->regulator
== NULL
))
586 if (pdata
->num_regulators
> ARRAY_SIZE(regulator_devs
))
587 pdata
->num_regulators
= ARRAY_SIZE(regulator_devs
);
589 for (i
= 0, seq
= -1; i
< pdata
->num_regulators
; i
++) {
590 initdata
= &pdata
->regulator
[i
];
591 seq
= *(unsigned int *)initdata
->driver_data
;
592 if ((seq
< 0) || (seq
> PM8607_ID_RG_MAX
)) {
593 dev_err(chip
->dev
, "Wrong ID(%d) on regulator(%s)\n",
594 seq
, initdata
->constraints
.name
);
597 regulator_devs
[i
].platform_data
= &pdata
->regulator
[i
];
598 regulator_devs
[i
].pdata_size
= sizeof(struct regulator_init_data
);
599 regulator_devs
[i
].num_resources
= 1;
600 regulator_devs
[i
].resources
= ®ulator_resources
[seq
];
602 ret
= mfd_add_devices(chip
->dev
, 0, ®ulator_devs
[i
], 1,
603 ®ulator_resources
[seq
], 0);
605 dev_err(chip
->dev
, "Failed to add regulator subdev\n");
613 static void __devinit
device_rtc_init(struct pm860x_chip
*chip
,
614 struct pm860x_platform_data
*pdata
)
621 rtc_devs
[0].platform_data
= pdata
->rtc
;
622 rtc_devs
[0].pdata_size
= sizeof(struct pm860x_rtc_pdata
);
623 rtc_devs
[0].num_resources
= ARRAY_SIZE(rtc_resources
);
624 rtc_devs
[0].resources
= &rtc_resources
[0];
625 ret
= mfd_add_devices(chip
->dev
, 0, &rtc_devs
[0],
626 ARRAY_SIZE(rtc_devs
), &rtc_resources
[0],
629 dev_err(chip
->dev
, "Failed to add rtc subdev\n");
632 static void __devinit
device_touch_init(struct pm860x_chip
*chip
,
633 struct pm860x_platform_data
*pdata
)
640 touch_devs
[0].platform_data
= pdata
->touch
;
641 touch_devs
[0].pdata_size
= sizeof(struct pm860x_touch_pdata
);
642 touch_devs
[0].num_resources
= ARRAY_SIZE(touch_resources
);
643 touch_devs
[0].resources
= &touch_resources
[0];
644 ret
= mfd_add_devices(chip
->dev
, 0, &touch_devs
[0],
645 ARRAY_SIZE(touch_devs
), &touch_resources
[0],
648 dev_err(chip
->dev
, "Failed to add touch subdev\n");
651 static void __devinit
device_power_init(struct pm860x_chip
*chip
,
652 struct pm860x_platform_data
*pdata
)
659 power_devs
[0].platform_data
= pdata
->power
;
660 power_devs
[0].pdata_size
= sizeof(struct pm860x_power_pdata
);
661 power_devs
[0].num_resources
= ARRAY_SIZE(battery_resources
);
662 power_devs
[0].resources
= &battery_resources
[0],
663 ret
= mfd_add_devices(chip
->dev
, 0, &power_devs
[0], 1,
664 &battery_resources
[0], chip
->irq_base
);
666 dev_err(chip
->dev
, "Failed to add battery subdev\n");
668 power_devs
[1].platform_data
= pdata
->power
;
669 power_devs
[1].pdata_size
= sizeof(struct pm860x_power_pdata
);
670 power_devs
[1].num_resources
= ARRAY_SIZE(charger_resources
);
671 power_devs
[1].resources
= &charger_resources
[0],
672 ret
= mfd_add_devices(chip
->dev
, 0, &power_devs
[1], 1,
673 &charger_resources
[0], chip
->irq_base
);
675 dev_err(chip
->dev
, "Failed to add charger subdev\n");
678 static void __devinit
device_onkey_init(struct pm860x_chip
*chip
,
679 struct pm860x_platform_data
*pdata
)
683 onkey_devs
[0].num_resources
= ARRAY_SIZE(onkey_resources
);
684 onkey_devs
[0].resources
= &onkey_resources
[0],
685 ret
= mfd_add_devices(chip
->dev
, 0, &onkey_devs
[0],
686 ARRAY_SIZE(onkey_devs
), &onkey_resources
[0],
689 dev_err(chip
->dev
, "Failed to add onkey subdev\n");
692 static void __devinit
device_codec_init(struct pm860x_chip
*chip
,
693 struct pm860x_platform_data
*pdata
)
697 codec_devs
[0].num_resources
= ARRAY_SIZE(codec_resources
);
698 codec_devs
[0].resources
= &codec_resources
[0],
699 ret
= mfd_add_devices(chip
->dev
, 0, &codec_devs
[0],
700 ARRAY_SIZE(codec_devs
), &codec_resources
[0], 0);
702 dev_err(chip
->dev
, "Failed to add codec subdev\n");
705 static void __devinit
device_8607_init(struct pm860x_chip
*chip
,
706 struct i2c_client
*i2c
,
707 struct pm860x_platform_data
*pdata
)
711 ret
= pm860x_reg_read(i2c
, PM8607_CHIP_ID
);
713 dev_err(chip
->dev
, "Failed to read CHIP ID: %d\n", ret
);
716 switch (ret
& PM8607_VERSION_MASK
) {
719 dev_info(chip
->dev
, "Marvell 88PM8607 (ID: %02x) detected\n",
723 dev_err(chip
->dev
, "Failed to detect Marvell 88PM8607. "
724 "Chip ID: %02x\n", ret
);
728 ret
= pm860x_reg_read(i2c
, PM8607_BUCK3
);
730 dev_err(chip
->dev
, "Failed to read BUCK3 register: %d\n", ret
);
733 if (ret
& PM8607_BUCK3_DOUBLE
)
734 chip
->buck3_double
= 1;
736 ret
= pm860x_reg_read(i2c
, PM8607_B0_MISC1
);
738 dev_err(chip
->dev
, "Failed to read MISC1 register: %d\n", ret
);
742 if (pdata
&& (pdata
->i2c_port
== PI2C_PORT
))
743 data
= PM8607_B0_MISC1_PI2C
;
746 ret
= pm860x_set_bits(i2c
, PM8607_B0_MISC1
, PM8607_B0_MISC1_PI2C
, data
);
748 dev_err(chip
->dev
, "Failed to access MISC1:%d\n", ret
);
752 ret
= device_gpadc_init(chip
, pdata
);
756 ret
= device_irq_init(chip
, pdata
);
760 device_regulator_init(chip
, pdata
);
761 device_rtc_init(chip
, pdata
);
762 device_onkey_init(chip
, pdata
);
763 device_touch_init(chip
, pdata
);
764 device_power_init(chip
, pdata
);
765 device_codec_init(chip
, pdata
);
770 int __devinit
pm860x_device_init(struct pm860x_chip
*chip
,
771 struct pm860x_platform_data
*pdata
)
777 device_bk_init(chip
, pdata
);
778 device_led_init(chip
, pdata
);
781 device_8607_init(chip
, chip
->client
, pdata
);
785 if (chip
->companion
) {
788 device_bk_init(chip
, pdata
);
789 device_led_init(chip
, pdata
);
792 device_8607_init(chip
, chip
->companion
, pdata
);
800 void __devexit
pm860x_device_exit(struct pm860x_chip
*chip
)
802 device_irq_exit(chip
);
803 mfd_remove_devices(chip
->dev
);
806 MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x");
807 MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
808 MODULE_LICENSE("GPL");