aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHaojian Zhuang <haojian.zhuang@marvell.com>2009-12-15 16:04:36 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2010-03-07 16:17:04 -0500
commita16122bcacf050e7f83015183053cf799713cc37 (patch)
treeecbeff86882200fc32d787388cd7aa902bf61505 /drivers
parent5c42e8c4a9c86ea26ed4ecb732a842dea0dfb6b6 (diff)
mfd: Append subdev into 88pm860x driver
Append backlight, led & touch subdevs into 88pm860x driver. Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mfd/88pm860x-core.c217
1 files changed, 205 insertions, 12 deletions
diff --git a/drivers/mfd/88pm860x-core.c b/drivers/mfd/88pm860x-core.c
index 9185f0d945f4..16f0dca707a7 100644
--- a/drivers/mfd/88pm860x-core.c
+++ b/drivers/mfd/88pm860x-core.c
@@ -17,6 +17,100 @@
17#include <linux/mfd/core.h> 17#include <linux/mfd/core.h>
18#include <linux/mfd/88pm860x.h> 18#include <linux/mfd/88pm860x.h>
19 19
20char pm860x_backlight_name[][MFD_NAME_SIZE] = {
21 "backlight-0",
22 "backlight-1",
23 "backlight-2",
24};
25EXPORT_SYMBOL(pm860x_backlight_name);
26
27char pm860x_led_name[][MFD_NAME_SIZE] = {
28 "led0-red",
29 "led0-green",
30 "led0-blue",
31 "led1-red",
32 "led1-green",
33 "led1-blue",
34};
35EXPORT_SYMBOL(pm860x_led_name);
36
37#define PM8606_BACKLIGHT_RESOURCE(_i, _x) \
38{ \
39 .name = pm860x_backlight_name[_i], \
40 .start = PM8606_##_x, \
41 .end = PM8606_##_x, \
42 .flags = IORESOURCE_IO, \
43}
44
45static struct resource backlight_resources[] = {
46 PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT1, WLED1A),
47 PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT2, WLED2A),
48 PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT3, WLED3A),
49};
50
51#define PM8606_BACKLIGHT_DEVS(_i) \
52{ \
53 .name = "88pm860x-backlight", \
54 .num_resources = 1, \
55 .resources = &backlight_resources[_i], \
56 .id = _i, \
57}
58
59static struct mfd_cell backlight_devs[] = {
60 PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT1),
61 PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT2),
62 PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT3),
63};
64
65#define PM8606_LED_RESOURCE(_i, _x) \
66{ \
67 .name = pm860x_led_name[_i], \
68 .start = PM8606_##_x, \
69 .end = PM8606_##_x, \
70 .flags = IORESOURCE_IO, \
71}
72
73static struct resource led_resources[] = {
74 PM8606_LED_RESOURCE(PM8606_LED1_RED, RGB2B),
75 PM8606_LED_RESOURCE(PM8606_LED1_GREEN, RGB2C),
76 PM8606_LED_RESOURCE(PM8606_LED1_BLUE, RGB2D),
77 PM8606_LED_RESOURCE(PM8606_LED2_RED, RGB1B),
78 PM8606_LED_RESOURCE(PM8606_LED2_GREEN, RGB1C),
79 PM8606_LED_RESOURCE(PM8606_LED2_BLUE, RGB1D),
80};
81
82#define PM8606_LED_DEVS(_i) \
83{ \
84 .name = "88pm860x-led", \
85 .num_resources = 1, \
86 .resources = &led_resources[_i], \
87 .id = _i, \
88}
89
90static struct mfd_cell led_devs[] = {
91 PM8606_LED_DEVS(PM8606_LED1_RED),
92 PM8606_LED_DEVS(PM8606_LED1_GREEN),
93 PM8606_LED_DEVS(PM8606_LED1_BLUE),
94 PM8606_LED_DEVS(PM8606_LED2_RED),
95 PM8606_LED_DEVS(PM8606_LED2_GREEN),
96 PM8606_LED_DEVS(PM8606_LED2_BLUE),
97};
98
99static struct resource touch_resources[] = {
100 {
101 .start = PM8607_IRQ_PEN,
102 .end = PM8607_IRQ_PEN,
103 .flags = IORESOURCE_IRQ,
104 },
105};
106
107static struct mfd_cell touch_devs[] = {
108 {
109 .name = "88pm860x-touch",
110 .num_resources = 1,
111 .resources = &touch_resources[0],
112 },
113};
20 114
21#define PM8607_REG_RESOURCE(_start, _end) \ 115#define PM8607_REG_RESOURCE(_start, _end) \
22{ \ 116{ \
@@ -25,7 +119,7 @@
25 .flags = IORESOURCE_IO, \ 119 .flags = IORESOURCE_IO, \
26} 120}
27 121
28static struct resource pm8607_regulator_resources[] = { 122static struct resource regulator_resources[] = {
29 PM8607_REG_RESOURCE(BUCK1, BUCK1), 123 PM8607_REG_RESOURCE(BUCK1, BUCK1),
30 PM8607_REG_RESOURCE(BUCK2, BUCK2), 124 PM8607_REG_RESOURCE(BUCK2, BUCK2),
31 PM8607_REG_RESOURCE(BUCK3, BUCK3), 125 PM8607_REG_RESOURCE(BUCK3, BUCK3),
@@ -47,10 +141,11 @@ static struct resource pm8607_regulator_resources[] = {
47{ \ 141{ \
48 .name = "88pm8607-" #_name, \ 142 .name = "88pm8607-" #_name, \
49 .num_resources = 1, \ 143 .num_resources = 1, \
50 .resources = &pm8607_regulator_resources[PM8607_ID_##_id], \ 144 .resources = &regulator_resources[PM8607_ID_##_id], \
145 .id = PM8607_ID_##_id, \
51} 146}
52 147
53static struct mfd_cell pm8607_devs[] = { 148static struct mfd_cell regulator_devs[] = {
54 PM8607_REG_DEVS(buck1, BUCK1), 149 PM8607_REG_DEVS(buck1, BUCK1),
55 PM8607_REG_DEVS(buck2, BUCK2), 150 PM8607_REG_DEVS(buck2, BUCK2),
56 PM8607_REG_DEVS(buck3, BUCK3), 151 PM8607_REG_DEVS(buck3, BUCK3),
@@ -192,6 +287,61 @@ int pm860x_free_irq(struct pm860x_chip *chip, int irq)
192} 287}
193EXPORT_SYMBOL(pm860x_free_irq); 288EXPORT_SYMBOL(pm860x_free_irq);
194 289
290static int __devinit device_gpadc_init(struct pm860x_chip *chip,
291 struct pm860x_platform_data *pdata)
292{
293 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
294 : chip->companion;
295 int use_gpadc = 0, data, ret;
296
297 /* initialize GPADC without activating it */
298
299 if (pdata && pdata->touch) {
300 /* set GPADC MISC1 register */
301 data = 0;
302 data |= (pdata->touch->gpadc_prebias << 1)
303 & PM8607_GPADC_PREBIAS_MASK;
304 data |= (pdata->touch->slot_cycle << 3)
305 & PM8607_GPADC_SLOT_CYCLE_MASK;
306 data |= (pdata->touch->off_scale << 5)
307 & PM8607_GPADC_OFF_SCALE_MASK;
308 data |= (pdata->touch->sw_cal << 7)
309 & PM8607_GPADC_SW_CAL_MASK;
310 if (data) {
311 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
312 if (ret < 0)
313 goto out;
314 }
315 /* set tsi prebias time */
316 if (pdata->touch->tsi_prebias) {
317 data = pdata->touch->tsi_prebias;
318 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
319 if (ret < 0)
320 goto out;
321 }
322 /* set prebias & prechg time of pen detect */
323 data = 0;
324 data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
325 data |= (pdata->touch->pen_prechg << 5)
326 & PM8607_PD_PRECHG_MASK;
327 if (data) {
328 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
329 if (ret < 0)
330 goto out;
331 }
332
333 use_gpadc = 1;
334 }
335
336 /* turn on GPADC */
337 if (use_gpadc) {
338 ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
339 PM8607_GPADC_EN, PM8607_GPADC_EN);
340 }
341out:
342 return ret;
343}
344
195static int __devinit device_irq_init(struct pm860x_chip *chip, 345static int __devinit device_irq_init(struct pm860x_chip *chip,
196 struct pm860x_platform_data *pdata) 346 struct pm860x_platform_data *pdata)
197{ 347{
@@ -264,14 +414,40 @@ static void __devinit device_8606_init(struct pm860x_chip *chip,
264 struct i2c_client *i2c, 414 struct i2c_client *i2c,
265 struct pm860x_platform_data *pdata) 415 struct pm860x_platform_data *pdata)
266{ 416{
417 int ret;
418
419 if (pdata && pdata->backlight) {
420 ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
421 ARRAY_SIZE(backlight_devs),
422 &backlight_resources[0], 0);
423 if (ret < 0) {
424 dev_err(chip->dev, "Failed to add backlight "
425 "subdev\n");
426 goto out_dev;
427 }
428 }
429
430 if (pdata && pdata->led) {
431 ret = mfd_add_devices(chip->dev, 0, &led_devs[0],
432 ARRAY_SIZE(led_devs),
433 &led_resources[0], 0);
434 if (ret < 0) {
435 dev_err(chip->dev, "Failed to add led "
436 "subdev\n");
437 goto out_dev;
438 }
439 }
440 return;
441out_dev:
442 mfd_remove_devices(chip->dev);
443 device_irq_exit(chip);
267} 444}
268 445
269static void __devinit device_8607_init(struct pm860x_chip *chip, 446static void __devinit device_8607_init(struct pm860x_chip *chip,
270 struct i2c_client *i2c, 447 struct i2c_client *i2c,
271 struct pm860x_platform_data *pdata) 448 struct pm860x_platform_data *pdata)
272{ 449{
273 int i, count, data; 450 int data, ret;
274 int ret;
275 451
276 ret = pm860x_reg_read(i2c, PM8607_CHIP_ID); 452 ret = pm860x_reg_read(i2c, PM8607_CHIP_ID);
277 if (ret < 0) { 453 if (ret < 0) {
@@ -311,19 +487,36 @@ static void __devinit device_8607_init(struct pm860x_chip *chip,
311 goto out; 487 goto out;
312 } 488 }
313 489
490 ret = device_gpadc_init(chip, pdata);
491 if (ret < 0)
492 goto out;
493
314 ret = device_irq_init(chip, pdata); 494 ret = device_irq_init(chip, pdata);
315 if (ret < 0) 495 if (ret < 0)
316 goto out; 496 goto out;
317 497
318 count = ARRAY_SIZE(pm8607_devs); 498 ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
319 for (i = 0; i < count; i++) { 499 ARRAY_SIZE(regulator_devs),
320 ret = mfd_add_devices(chip->dev, i, &pm8607_devs[i], 500 &regulator_resources[0], 0);
321 1, NULL, 0); 501 if (ret < 0) {
322 if (ret != 0) { 502 dev_err(chip->dev, "Failed to add regulator subdev\n");
323 dev_err(chip->dev, "Failed to add subdevs\n"); 503 goto out_dev;
324 goto out; 504 }
505
506 if (pdata && pdata->touch) {
507 ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
508 ARRAY_SIZE(touch_devs),
509 &touch_resources[0], 0);
510 if (ret < 0) {
511 dev_err(chip->dev, "Failed to add touch "
512 "subdev\n");
513 goto out_dev;
325 } 514 }
326 } 515 }
516 return;
517out_dev:
518 mfd_remove_devices(chip->dev);
519 device_irq_exit(chip);
327out: 520out:
328 return; 521 return;
329} 522}