Skip to content

Commit c172708

Browse files
committed
regulator: core: Use a struct to pass in regulator runtime configuration
Rather than adding new arguments to regulator_register() every time we want to add a new bit of dynamic information at runtime change the function to take these via a struct. By doing this we avoid needing to do further changes like the recent addition of device tree support which required each regulator driver to be updated to take an additional parameter. The regulator_desc which should (mostly) be static data is still passed separately as most drivers are able to configure this statically at build time. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent 1474e4d commit c172708

45 files changed

Lines changed: 331 additions & 120 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎drivers/regulator/88pm8607.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
365365
struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
366366
struct pm8607_regulator_info *info = NULL;
367367
struct regulator_init_data *pdata = pdev->dev.platform_data;
368+
struct regulator_config config = { };
368369
struct resource *res;
369370
int i;
370371

@@ -390,9 +391,12 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev)
390391
if ((i == PM8607_ID_BUCK3) && info->chip->buck3_double)
391392
info->slope_double = 1;
392393

394+
config.dev = &pdev->dev;
395+
config.init_data = pdata;
396+
config.driver_data = info;
397+
393398
/* replace driver_data with info */
394-
info->regulator = regulator_register(&info->desc, &pdev->dev,
395-
pdata, info, NULL);
399+
info->regulator = regulator_register(&info->desc, &config);
396400
if (IS_ERR(info->regulator)) {
397401
dev_err(&pdev->dev, "failed to register regulator %s\n",
398402
info->desc.name);

‎drivers/regulator/aat2870-regulator.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ static struct aat2870_regulator *aat2870_get_regulator(int id)
178178
static int aat2870_regulator_probe(struct platform_device *pdev)
179179
{
180180
struct aat2870_regulator *ri;
181+
struct regulator_config config = { 0 };
181182
struct regulator_dev *rdev;
182183

183184
ri = aat2870_get_regulator(pdev->id);
@@ -187,8 +188,11 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
187188
}
188189
ri->aat2870 = dev_get_drvdata(pdev->dev.parent);
189190

190-
rdev = regulator_register(&ri->desc, &pdev->dev,
191-
pdev->dev.platform_data, ri, NULL);
191+
config.dev = &pdev->dev;
192+
config.driver_data = ri;
193+
config.init_data = pdev->dev.platform_data;
194+
195+
rdev = regulator_register(&ri->desc, &config);
192196
if (IS_ERR(rdev)) {
193197
dev_err(&pdev->dev, "Failed to register regulator %s\n",
194198
ri->desc.name);

‎drivers/regulator/ab3100.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
574574
static int __devinit ab3100_regulators_probe(struct platform_device *pdev)
575575
{
576576
struct ab3100_platform_data *plfdata = pdev->dev.platform_data;
577+
struct regulator_config config = { };
577578
int err = 0;
578579
u8 data;
579580
int i;
@@ -619,15 +620,15 @@ static int __devinit ab3100_regulators_probe(struct platform_device *pdev)
619620
reg->dev = &pdev->dev;
620621
reg->plfdata = plfdata;
621622

623+
config.dev = &pdev->dev;
624+
config.driver_data = reg;
625+
config.init_data = &plfdata->reg_constraints[i];
626+
622627
/*
623628
* Register the regulator, pass around
624629
* the ab3100_regulator struct
625630
*/
626-
rdev = regulator_register(&ab3100_regulator_desc[i],
627-
&pdev->dev,
628-
&plfdata->reg_constraints[i],
629-
reg, NULL);
630-
631+
rdev = regulator_register(&ab3100_regulator_desc[i], &config);
631632
if (IS_ERR(rdev)) {
632633
err = PTR_ERR(rdev);
633634
dev_err(&pdev->dev,

‎drivers/regulator/ab8500.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
712712
{
713713
struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
714714
struct ab8500_platform_data *pdata;
715+
struct regulator_config config = { };
715716
int i, err;
716717

717718
if (!ab8500) {
@@ -779,6 +780,10 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
779780
info = &ab8500_regulator_info[i];
780781
info->dev = &pdev->dev;
781782

783+
config->dev = &pdev->dev;
784+
config->init_data = &pdata->regulator[i];
785+
config->driver_data = info;
786+
782787
/* fix for hardware before ab8500v2.0 */
783788
if (abx500_get_chip_id(info->dev) < 0x20) {
784789
if (info->desc.id == AB8500_LDO_AUX3) {
@@ -792,8 +797,7 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
792797
}
793798

794799
/* register regulator with framework */
795-
info->regulator = regulator_register(&info->desc, &pdev->dev,
796-
&pdata->regulator[i], info, NULL);
800+
info->regulator = regulator_register(&info->desc, &config);
797801
if (IS_ERR(info->regulator)) {
798802
err = PTR_ERR(info->regulator);
799803
dev_err(&pdev->dev, "failed to register regulator %s\n",

‎drivers/regulator/ad5398.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static int __devinit ad5398_probe(struct i2c_client *client,
212212
const struct i2c_device_id *id)
213213
{
214214
struct regulator_init_data *init_data = client->dev.platform_data;
215+
struct regulator_config config = { };
215216
struct ad5398_chip_info *chip;
216217
const struct ad5398_current_data_format *df =
217218
(struct ad5398_current_data_format *)id->driver_data;
@@ -224,6 +225,10 @@ static int __devinit ad5398_probe(struct i2c_client *client,
224225
if (!chip)
225226
return -ENOMEM;
226227

228+
config.dev = &client->dev;
229+
config.init_data = init_data;
230+
config.driver_data = chip;
231+
227232
chip->client = client;
228233

229234
chip->min_uA = df->min_uA;
@@ -232,8 +237,7 @@ static int __devinit ad5398_probe(struct i2c_client *client,
232237
chip->current_offset = df->current_offset;
233238
chip->current_mask = (chip->current_level - 1) << chip->current_offset;
234239

235-
chip->rdev = regulator_register(&ad5398_reg, &client->dev,
236-
init_data, chip, NULL);
240+
chip->rdev = regulator_register(&ad5398_reg, &config);
237241
if (IS_ERR(chip->rdev)) {
238242
ret = PTR_ERR(chip->rdev);
239243
dev_err(&client->dev, "failed to register %s %s\n",

‎drivers/regulator/core.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,27 +2820,24 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
28202820
/**
28212821
* regulator_register - register regulator
28222822
* @regulator_desc: regulator to register
2823-
* @dev: struct device for the regulator
2824-
* @init_data: platform provided init data, passed through by driver
2825-
* @driver_data: private regulator data
2826-
* @of_node: OpenFirmware node to parse for device tree bindings (may be
2827-
* NULL).
2823+
* @config: runtime configuration for regulator
28282824
*
28292825
* Called by regulator drivers to register a regulator.
28302826
* Returns 0 on success.
28312827
*/
28322828
struct regulator_dev *
28332829
regulator_register(const struct regulator_desc *regulator_desc,
2834-
struct device *dev, const struct regulator_init_data *init_data,
2835-
void *driver_data, struct device_node *of_node)
2830+
const struct regulator_config *config)
28362831
{
28372832
const struct regulation_constraints *constraints = NULL;
2833+
const struct regulator_init_data *init_data;
28382834
static atomic_t regulator_no = ATOMIC_INIT(0);
28392835
struct regulator_dev *rdev;
2836+
struct device *dev = config->dev;
28402837
int ret, i;
28412838
const char *supply = NULL;
28422839

2843-
if (regulator_desc == NULL)
2840+
if (regulator_desc == NULL || config == NULL)
28442841
return ERR_PTR(-EINVAL);
28452842

28462843
if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
@@ -2866,14 +2863,16 @@ regulator_register(const struct regulator_desc *regulator_desc,
28662863
return ERR_PTR(-EINVAL);
28672864
}
28682865

2866+
init_data = config->init_data;
2867+
28692868
rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
28702869
if (rdev == NULL)
28712870
return ERR_PTR(-ENOMEM);
28722871

28732872
mutex_lock(&regulator_list_mutex);
28742873

28752874
mutex_init(&rdev->mutex);
2876-
rdev->reg_data = driver_data;
2875+
rdev->reg_data = config->driver_data;
28772876
rdev->owner = regulator_desc->owner;
28782877
rdev->desc = regulator_desc;
28792878
INIT_LIST_HEAD(&rdev->consumer_list);
@@ -2890,7 +2889,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
28902889

28912890
/* register with sysfs */
28922891
rdev->dev.class = &regulator_class;
2893-
rdev->dev.of_node = of_node;
2892+
rdev->dev.of_node = config->of_node;
28942893
rdev->dev.parent = dev;
28952894
dev_set_name(&rdev->dev, "regulator.%d",
28962895
atomic_inc_return(&regulator_no) - 1);

‎drivers/regulator/da903x.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev)
517517
{
518518
struct da903x_regulator_info *ri = NULL;
519519
struct regulator_dev *rdev;
520+
struct regulator_config config = { };
520521

521522
ri = find_regulator_info(pdev->id);
522523
if (ri == NULL) {
@@ -536,8 +537,11 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev)
536537
if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15)
537538
ri->desc.ops = &da9030_regulator_ldo1_15_ops;
538539

539-
rdev = regulator_register(&ri->desc, &pdev->dev,
540-
pdev->dev.platform_data, ri, NULL);
540+
config.dev = &pdev->dev;
541+
conifg.init_data = pdev->dev.platform_data;
542+
config.driver_data = ri;
543+
544+
rdev = regulator_register(&ri->desc, &config);
541545
if (IS_ERR(rdev)) {
542546
dev_err(&pdev->dev, "failed to register regulator %s\n",
543547
ri->desc.name);

‎drivers/regulator/da9052-regulator.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ static inline struct da9052_regulator_info *find_regulator_info(u8 chip_id,
403403

404404
static int __devinit da9052_regulator_probe(struct platform_device *pdev)
405405
{
406+
struct regulator_config config = { };
406407
struct da9052_regulator *regulator;
407408
struct da9052 *da9052;
408409
struct da9052_pdata *pdata;
@@ -422,10 +423,13 @@ static int __devinit da9052_regulator_probe(struct platform_device *pdev)
422423
dev_err(&pdev->dev, "invalid regulator ID specified\n");
423424
return -EINVAL;
424425
}
426+
427+
config.dev = &pdev->dev;
428+
config.init_data = pdata->regulators[pdev->id];
429+
config.driver_data = regulator;
430+
425431
regulator->rdev = regulator_register(&regulator->info->reg_desc,
426-
&pdev->dev,
427-
pdata->regulators[pdev->id],
428-
regulator, NULL);
432+
&config);
429433
if (IS_ERR(regulator->rdev)) {
430434
dev_err(&pdev->dev, "failed to register regulator %s\n",
431435
regulator->info->reg_desc.name);

‎drivers/regulator/db8500-prcmu.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev)
414414
{
415415
struct regulator_init_data *db8500_init_data =
416416
dev_get_platdata(&pdev->dev);
417+
struct regulator_config config = { };
417418
int i, err;
418419

419420
/* register all regulators */
@@ -425,9 +426,12 @@ static int __devinit db8500_regulator_probe(struct platform_device *pdev)
425426
info = &dbx500_regulator_info[i];
426427
info->dev = &pdev->dev;
427428

429+
config.dev = &pdev->dev;
430+
config.init_data = init_data;
431+
config.driver_data = info;
432+
428433
/* register with the regulator framework */
429-
info->rdev = regulator_register(&info->desc, &pdev->dev,
430-
init_data, info, NULL);
434+
info->rdev = regulator_register(&info->desc, &config);
431435
if (IS_ERR(info->rdev)) {
432436
err = PTR_ERR(info->rdev);
433437
dev_err(&pdev->dev, "failed to register %s: err %i\n",

‎drivers/regulator/dummy.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ static struct regulator_desc dummy_desc = {
3939

4040
static int __devinit dummy_regulator_probe(struct platform_device *pdev)
4141
{
42+
struct regulator_config config = { };
4243
int ret;
4344

44-
dummy_regulator_rdev = regulator_register(&dummy_desc, NULL,
45-
&dummy_initdata, NULL, NULL);
45+
config.init_data = &dummy_initdata;
46+
47+
dummy_regulator_rdev = regulator_register(&dummy_desc, &config);
4648
if (IS_ERR(dummy_regulator_rdev)) {
4749
ret = PTR_ERR(dummy_regulator_rdev);
4850
pr_err("Failed to register regulator: %d\n", ret);

0 commit comments

Comments
 (0)