Commit 22aad0011e4728a29bf3775b6f5e2f9677abd8c0

Authored by Haojian Zhuang
Committed by Samuel Ortiz
1 parent 3154c34469

mfd: Adopt mfd_data in 88pm860x regulator

Copy 88pm860x platform data into different mfd_data structure for
regulator driver. So move the identification of device node from
regulator driver to mfd driver.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

Showing 3 changed files with 132 additions and 86 deletions Side-by-side Diff

drivers/mfd/88pm860x-core.c
... ... @@ -17,6 +17,7 @@
17 17 #include <linux/platform_device.h>
18 18 #include <linux/mfd/core.h>
19 19 #include <linux/mfd/88pm860x.h>
  20 +#include <linux/regulator/machine.h>
20 21  
21 22 #define INT_STATUS_NUM 3
22 23  
... ... @@ -35,6 +36,27 @@
35 36 {PM8606_LED2_BLUE, PM8606_LED2_BLUE, "led1-blue", IORESOURCE_IO,},
36 37 };
37 38  
  39 +static struct resource regulator_resources[] __initdata = {
  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,},
  58 +};
  59 +
38 60 static struct mfd_cell bk_devs[] __initdata = {
39 61 {"88pm860x-backlight", 0,},
40 62 {"88pm860x-backlight", 1,},
41 63  
... ... @@ -50,8 +72,30 @@
50 72 {"88pm860x-led", 5,},
51 73 };
52 74  
  75 +static struct mfd_cell regulator_devs[] __initdata = {
  76 + {"88pm860x-regulator", 0,},
  77 + {"88pm860x-regulator", 1,},
  78 + {"88pm860x-regulator", 2,},
  79 + {"88pm860x-regulator", 3,},
  80 + {"88pm860x-regulator", 4,},
  81 + {"88pm860x-regulator", 5,},
  82 + {"88pm860x-regulator", 6,},
  83 + {"88pm860x-regulator", 7,},
  84 + {"88pm860x-regulator", 8,},
  85 + {"88pm860x-regulator", 9,},
  86 + {"88pm860x-regulator", 10,},
  87 + {"88pm860x-regulator", 11,},
  88 + {"88pm860x-regulator", 12,},
  89 + {"88pm860x-regulator", 13,},
  90 + {"88pm860x-regulator", 14,},
  91 + {"88pm860x-regulator", 15,},
  92 + {"88pm860x-regulator", 16,},
  93 + {"88pm860x-regulator", 17,},
  94 +};
  95 +
53 96 static struct pm860x_backlight_pdata bk_pdata[ARRAY_SIZE(bk_devs)];
54 97 static struct pm860x_led_pdata led_pdata[ARRAY_SIZE(led_devs)];
  98 +static struct regulator_init_data regulator_pdata[ARRAY_SIZE(regulator_devs)];
55 99  
56 100 static struct resource touch_resources[] = {
57 101 {
... ... @@ -69,13 +113,6 @@
69 113 },
70 114 };
71 115  
72   -#define PM8607_REG_RESOURCE(_start, _end) \
73   -{ \
74   - .start = PM8607_##_start, \
75   - .end = PM8607_##_end, \
76   - .flags = IORESOURCE_IO, \
77   -}
78   -
79 116 static struct resource power_supply_resources[] = {
80 117 {
81 118 .name = "88pm860x-power",
... ... @@ -149,52 +186,6 @@
149 186 },
150 187 };
151 188  
152   -static struct resource regulator_resources[] = {
153   - PM8607_REG_RESOURCE(BUCK1, BUCK1),
154   - PM8607_REG_RESOURCE(BUCK2, BUCK2),
155   - PM8607_REG_RESOURCE(BUCK3, BUCK3),
156   - PM8607_REG_RESOURCE(LDO1, LDO1),
157   - PM8607_REG_RESOURCE(LDO2, LDO2),
158   - PM8607_REG_RESOURCE(LDO3, LDO3),
159   - PM8607_REG_RESOURCE(LDO4, LDO4),
160   - PM8607_REG_RESOURCE(LDO5, LDO5),
161   - PM8607_REG_RESOURCE(LDO6, LDO6),
162   - PM8607_REG_RESOURCE(LDO7, LDO7),
163   - PM8607_REG_RESOURCE(LDO8, LDO8),
164   - PM8607_REG_RESOURCE(LDO9, LDO9),
165   - PM8607_REG_RESOURCE(LDO10, LDO10),
166   - PM8607_REG_RESOURCE(LDO12, LDO12),
167   - PM8607_REG_RESOURCE(VIBRATOR_SET, VIBRATOR_SET),
168   - PM8607_REG_RESOURCE(LDO14, LDO14),
169   -};
170   -
171   -#define PM8607_REG_DEVS(_id) \
172   -{ \
173   - .name = "88pm860x-regulator", \
174   - .num_resources = 1, \
175   - .resources = &regulator_resources[PM8607_ID_##_id], \
176   - .id = PM8607_ID_##_id, \
177   -}
178   -
179   -static struct mfd_cell regulator_devs[] = {
180   - PM8607_REG_DEVS(BUCK1),
181   - PM8607_REG_DEVS(BUCK2),
182   - PM8607_REG_DEVS(BUCK3),
183   - PM8607_REG_DEVS(LDO1),
184   - PM8607_REG_DEVS(LDO2),
185   - PM8607_REG_DEVS(LDO3),
186   - PM8607_REG_DEVS(LDO4),
187   - PM8607_REG_DEVS(LDO5),
188   - PM8607_REG_DEVS(LDO6),
189   - PM8607_REG_DEVS(LDO7),
190   - PM8607_REG_DEVS(LDO8),
191   - PM8607_REG_DEVS(LDO9),
192   - PM8607_REG_DEVS(LDO10),
193   - PM8607_REG_DEVS(LDO12),
194   - PM8607_REG_DEVS(LDO13),
195   - PM8607_REG_DEVS(LDO14),
196   -};
197   -
198 189 struct pm860x_irq_data {
199 190 int reg;
200 191 int mask_reg;
... ... @@ -623,6 +614,64 @@
623 614 }
624 615 }
625 616  
  617 +static void __devinit device_regulator_init(struct pm860x_chip *chip,
  618 + struct i2c_client *i2c,
  619 + struct pm860x_platform_data *pdata)
  620 +{
  621 + struct regulator_init_data *initdata;
  622 + int ret;
  623 + int i, j;
  624 +
  625 + if ((pdata == NULL) || (pdata->regulator == NULL))
  626 + return;
  627 +
  628 + if (pdata->num_regulators > ARRAY_SIZE(regulator_devs))
  629 + pdata->num_regulators = ARRAY_SIZE(regulator_devs);
  630 +
  631 + for (i = 0, j = -1; i < pdata->num_regulators; i++) {
  632 + initdata = &pdata->regulator[i];
  633 + if (strstr(initdata->constraints.name, "BUCK")) {
  634 + sscanf(initdata->constraints.name, "BUCK%d", &j);
  635 + /* BUCK1 ~ BUCK3 */
  636 + if ((j < 1) || (j > 3)) {
  637 + dev_err(chip->dev, "Failed to add constraint "
  638 + "(%s)\n", initdata->constraints.name);
  639 + goto out;
  640 + }
  641 + j = (j - 1) + PM8607_ID_BUCK1;
  642 + }
  643 + if (strstr(initdata->constraints.name, "LDO")) {
  644 + sscanf(initdata->constraints.name, "LDO%d", &j);
  645 + /* LDO1 ~ LDO15 */
  646 + if ((j < 1) || (j > 15)) {
  647 + dev_err(chip->dev, "Failed to add constraint "
  648 + "(%s)\n", initdata->constraints.name);
  649 + goto out;
  650 + }
  651 + j = (j - 1) + PM8607_ID_LDO1;
  652 + }
  653 + if (j == -1) {
  654 + dev_err(chip->dev, "Failed to add constraint (%s)\n",
  655 + initdata->constraints.name);
  656 + goto out;
  657 + }
  658 + memcpy(&regulator_pdata[i], &pdata->regulator[i],
  659 + sizeof(struct regulator_init_data));
  660 + regulator_devs[i].mfd_data = &regulator_pdata[i];
  661 + regulator_devs[i].num_resources = 1;
  662 + regulator_devs[i].resources = &regulator_resources[j];
  663 +
  664 + ret = mfd_add_devices(chip->dev, 0, &regulator_devs[i], 1,
  665 + &regulator_resources[j], 0);
  666 + if (ret < 0) {
  667 + dev_err(chip->dev, "Failed to add regulator subdev\n");
  668 + goto out;
  669 + }
  670 + }
  671 +out:
  672 + return;
  673 +}
  674 +
626 675 static void __devinit device_8607_init(struct pm860x_chip *chip,
627 676 struct i2c_client *i2c,
628 677 struct pm860x_platform_data *pdata)
... ... @@ -678,14 +727,6 @@
678 727 if (ret < 0)
679 728 goto out;
680 729  
681   - ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
682   - ARRAY_SIZE(regulator_devs),
683   - &regulator_resources[0], 0);
684   - if (ret < 0) {
685   - dev_err(chip->dev, "Failed to add regulator subdev\n");
686   - goto out_dev;
687   - }
688   -
689 730 if (pdata && pdata->touch) {
690 731 ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
691 732 ARRAY_SIZE(touch_devs),
... ... @@ -723,6 +764,8 @@
723 764 dev_err(chip->dev, "Failed to add codec subdev\n");
724 765 goto out_dev;
725 766 }
  767 +
  768 + device_regulator_init(chip, i2c, pdata);
726 769 return;
727 770 out_dev:
728 771 mfd_remove_devices(chip->dev);
drivers/regulator/88pm8607.c
... ... @@ -15,6 +15,7 @@
15 15 #include <linux/platform_device.h>
16 16 #include <linux/regulator/driver.h>
17 17 #include <linux/regulator/machine.h>
  18 +#include <linux/mfd/core.h>
18 19 #include <linux/mfd/88pm860x.h>
19 20  
20 21 struct pm8607_regulator_info {
21 22  
22 23  
23 24  
24 25  
25 26  
26 27  
27 28  
... ... @@ -394,46 +395,47 @@
394 395 PM8607_LDO(14, LDO14, 0, 4, SUPPLIES_EN12, 6),
395 396 };
396 397  
397   -static inline struct pm8607_regulator_info *find_regulator_info(int id)
  398 +static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
398 399 {
399   - struct pm8607_regulator_info *info;
  400 + struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
  401 + struct pm8607_regulator_info *info = NULL;
  402 + struct regulator_init_data *pdata;
  403 + struct mfd_cell *cell;
400 404 int i;
401 405  
  406 + cell = pdev->dev.platform_data;
  407 + if (cell == NULL)
  408 + return -ENODEV;
  409 + pdata = cell->mfd_data;
  410 + if (pdata == NULL)
  411 + return -EINVAL;
  412 +
402 413 for (i = 0; i < ARRAY_SIZE(pm8607_regulator_info); i++) {
403 414 info = &pm8607_regulator_info[i];
404   - if (info->desc.id == id)
405   - return info;
  415 + if (!strcmp(info->desc.name, pdata->constraints.name))
  416 + break;
406 417 }
407   - return NULL;
408   -}
409   -
410   -static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
411   -{
412   - struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
413   - struct pm860x_platform_data *pdata = chip->dev->platform_data;
414   - struct pm8607_regulator_info *info = NULL;
415   -
416   - info = find_regulator_info(pdev->id);
417   - if (info == NULL) {
418   - dev_err(&pdev->dev, "invalid regulator ID specified\n");
  418 + if (i > ARRAY_SIZE(pm8607_regulator_info)) {
  419 + dev_err(&pdev->dev, "Failed to find regulator %s\n",
  420 + pdata->constraints.name);
419 421 return -EINVAL;
420 422 }
421 423  
422 424 info->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
423 425 info->chip = chip;
424 426  
  427 + /* check DVC ramp slope double */
  428 + if (!strcmp(info->desc.name, "BUCK3"))
  429 + if (info->chip->buck3_double)
  430 + info->slope_double = 1;
  431 +
425 432 info->regulator = regulator_register(&info->desc, &pdev->dev,
426   - pdata->regulator[pdev->id], info);
  433 + pdata, info);
427 434 if (IS_ERR(info->regulator)) {
428 435 dev_err(&pdev->dev, "failed to register regulator %s\n",
429 436 info->desc.name);
430 437 return PTR_ERR(info->regulator);
431 438 }
432   -
433   - /* check DVC ramp slope double */
434   - if (info->desc.id == PM8607_ID_BUCK3)
435   - if (info->chip->buck3_double)
436   - info->slope_double = 1;
437 439  
438 440 platform_set_drvdata(pdev, info);
439 441 return 0;
include/linux/mfd/88pm860x.h
... ... @@ -131,9 +131,11 @@
131 131 PM8607_ID_LDO8,
132 132 PM8607_ID_LDO9,
133 133 PM8607_ID_LDO10,
  134 + PM8607_ID_LDO11,
134 135 PM8607_ID_LDO12,
135 136 PM8607_ID_LDO13,
136 137 PM8607_ID_LDO14,
  138 + PM8607_ID_LDO15,
137 139  
138 140 PM8607_ID_RG_MAX,
139 141 };
... ... @@ -310,8 +312,6 @@
310 312  
311 313 };
312 314  
313   -#define PM8607_MAX_REGULATOR PM8607_ID_RG_MAX /* 3 Bucks, 13 LDOs */
314   -
315 315 enum {
316 316 GI2C_PORT = 0,
317 317 PI2C_PORT,
... ... @@ -351,6 +351,7 @@
351 351 struct pm860x_led_pdata *led;
352 352 struct pm860x_touch_pdata *touch;
353 353 struct pm860x_power_pdata *power;
  354 + struct regulator_init_data *regulator;
354 355  
355 356 unsigned short companion_addr; /* I2C address of companion chip */
356 357 int i2c_port; /* Controlled by GI2C or PI2C */
... ... @@ -358,7 +359,7 @@
358 359 int irq_base; /* IRQ base number of 88pm860x */
359 360 int num_leds;
360 361 int num_backlights;
361   - struct regulator_init_data *regulator[PM8607_MAX_REGULATOR];
  362 + int num_regulators;
362 363 };
363 364  
364 365 extern int pm860x_reg_read(struct i2c_client *, int);