Skip to content

Commit 7f62cb8

Browse files
nsolanki22broonie
authored andcommitted
regulator: max597x: Align for simple_mfd_i2c driver
Use regmap provided by simple_mfd_i2c driver and remove unused variable. Identify device variant by checking compatible property in DT. Signed-off-by: Naresh Solanki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 9d1c731 commit 7f62cb8

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

drivers/regulator/max597x-regulator.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,54 +425,72 @@ static int max597x_setup_irq(struct device *dev,
425425

426426
static int max597x_regulator_probe(struct platform_device *pdev)
427427
{
428-
429-
430-
struct max597x_data *max597x = dev_get_drvdata(pdev->dev.parent);
428+
struct max597x_data *max597x;
429+
struct regmap *regmap = dev_get_regmap(pdev->dev.parent, NULL);
431430
struct max597x_regulator *data;
432-
431+
struct i2c_client *i2c = to_i2c_client(pdev->dev.parent);
433432
struct regulator_config config = { };
434433
struct regulator_dev *rdev;
435434
struct regulator_dev *rdevs[MAX5970_NUM_SWITCHES];
436-
int num_switches = max597x->num_switches;
435+
int num_switches;
437436
int ret, i;
438437

438+
if (!regmap)
439+
return -EPROBE_DEFER;
440+
441+
max597x = devm_kzalloc(&i2c->dev, sizeof(struct max597x_data), GFP_KERNEL);
442+
if (!max597x)
443+
return -ENOMEM;
444+
445+
i2c_set_clientdata(i2c, max597x);
446+
447+
if (of_device_is_compatible(i2c->dev.of_node, "maxim,max5978"))
448+
max597x->num_switches = MAX597x_TYPE_MAX5978;
449+
else if (of_device_is_compatible(i2c->dev.of_node, "maxim,max5970"))
450+
max597x->num_switches = MAX597x_TYPE_MAX5970;
451+
else
452+
return -ENODEV;
453+
454+
i2c_set_clientdata(i2c, max597x);
455+
num_switches = max597x->num_switches;
456+
439457
for (i = 0; i < num_switches; i++) {
440458
data =
441-
devm_kzalloc(max597x->dev, sizeof(struct max597x_regulator),
459+
devm_kzalloc(&i2c->dev, sizeof(struct max597x_regulator),
442460
GFP_KERNEL);
443461
if (!data)
444462
return -ENOMEM;
445463

446464
data->num_switches = num_switches;
447-
data->regmap = max597x->regmap;
465+
data->regmap = regmap;
448466

449-
ret = max597x_adc_range(data->regmap, i, &max597x->irng[i], &max597x->mon_rng[i]);
467+
ret = max597x_adc_range(regmap, i, &max597x->irng[i], &max597x->mon_rng[i]);
450468
if (ret < 0)
451469
return ret;
452470

453471
data->irng = max597x->irng[i];
454472
data->mon_rng = max597x->mon_rng[i];
455473

456-
config.dev = max597x->dev;
474+
config.dev = &i2c->dev;
457475
config.driver_data = (void *)data;
458476
config.regmap = data->regmap;
459-
rdev = devm_regulator_register(max597x->dev,
477+
rdev = devm_regulator_register(&i2c->dev,
460478
&regulators[i], &config);
461479
if (IS_ERR(rdev)) {
462-
dev_err(max597x->dev, "failed to register regulator %s\n",
480+
dev_err(&i2c->dev, "failed to register regulator %s\n",
463481
regulators[i].name);
464482
return PTR_ERR(rdev);
465483
}
466484
rdevs[i] = rdev;
467485
max597x->shunt_micro_ohms[i] = data->shunt_micro_ohms;
468486
}
469487

470-
if (max597x->irq) {
488+
if (i2c->irq) {
471489
ret =
472-
max597x_setup_irq(max597x->dev, max597x->irq, rdevs, num_switches,
490+
max597x_setup_irq(&i2c->dev, i2c->irq, rdevs, num_switches,
473491
data);
474492
if (ret) {
475-
dev_err(max597x->dev, "IRQ setup failed");
493+
dev_err(&i2c->dev, "IRQ setup failed");
476494
return ret;
477495
}
478496
}

0 commit comments

Comments
 (0)