Skip to content

Commit d72fd52

Browse files
dlechbroonie
authored andcommitted
hwmon: (da9052) Use devm_regulator_get_enable_read_voltage()
We can reduce boilerplate code by using devm_regulator_get_enable_read_voltage(). Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: David Lechner <[email protected]> Acked-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/20240429-regulator-get-enable-get-votlage-v2-3-b1f11ab766c1@baylibre.com Signed-off-by: Mark Brown <[email protected]>
1 parent cffb8d7 commit d72fd52

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

drivers/hwmon/da9052-hwmon.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct da9052_hwmon {
2626
struct mutex hwmon_lock;
2727
bool tsi_as_adc;
2828
int tsiref_mv;
29-
struct regulator *tsiref;
3029
struct completion tsidone;
3130
};
3231

@@ -397,7 +396,7 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
397396
struct device *dev = &pdev->dev;
398397
struct da9052_hwmon *hwmon;
399398
struct device *hwmon_dev;
400-
int err;
399+
int err, tsiref_uv;
401400

402401
hwmon = devm_kzalloc(dev, sizeof(struct da9052_hwmon), GFP_KERNEL);
403402
if (!hwmon)
@@ -414,32 +413,20 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
414413
device_property_read_bool(pdev->dev.parent, "dlg,tsi-as-adc");
415414

416415
if (hwmon->tsi_as_adc) {
417-
hwmon->tsiref = devm_regulator_get(pdev->dev.parent, "tsiref");
418-
if (IS_ERR(hwmon->tsiref)) {
419-
err = PTR_ERR(hwmon->tsiref);
420-
dev_err(&pdev->dev, "failed to get tsiref: %d", err);
421-
return err;
422-
}
423-
424-
err = regulator_enable(hwmon->tsiref);
425-
if (err)
426-
return err;
427-
428-
hwmon->tsiref_mv = regulator_get_voltage(hwmon->tsiref);
429-
if (hwmon->tsiref_mv < 0) {
430-
err = hwmon->tsiref_mv;
431-
goto exit_regulator;
432-
}
416+
tsiref_uv = devm_regulator_get_enable_read_voltage(dev->parent,
417+
"tsiref");
418+
if (tsiref_uv < 0)
419+
return dev_err_probe(dev, tsiref_uv,
420+
"failed to get tsiref voltage\n");
433421

434422
/* convert from microvolt (DT) to millivolt (hwmon) */
435-
hwmon->tsiref_mv /= 1000;
423+
hwmon->tsiref_mv = tsiref_uv / 1000;
436424

437425
/* TSIREF limits from datasheet */
438426
if (hwmon->tsiref_mv < 1800 || hwmon->tsiref_mv > 2600) {
439427
dev_err(hwmon->da9052->dev, "invalid TSIREF voltage: %d",
440428
hwmon->tsiref_mv);
441-
err = -ENXIO;
442-
goto exit_regulator;
429+
return -ENXIO;
443430
}
444431

445432
/* disable touchscreen features */
@@ -456,7 +443,7 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
456443
if (err) {
457444
dev_err(&pdev->dev, "Failed to register TSIRDY IRQ: %d",
458445
err);
459-
goto exit_regulator;
446+
return err;
460447
}
461448
}
462449

@@ -472,9 +459,6 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
472459
exit_irq:
473460
if (hwmon->tsi_as_adc)
474461
da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon);
475-
exit_regulator:
476-
if (hwmon->tsiref)
477-
regulator_disable(hwmon->tsiref);
478462

479463
return err;
480464
}
@@ -483,10 +467,8 @@ static void da9052_hwmon_remove(struct platform_device *pdev)
483467
{
484468
struct da9052_hwmon *hwmon = platform_get_drvdata(pdev);
485469

486-
if (hwmon->tsi_as_adc) {
470+
if (hwmon->tsi_as_adc)
487471
da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon);
488-
regulator_disable(hwmon->tsiref);
489-
}
490472
}
491473

492474
static struct platform_driver da9052_hwmon_driver = {

0 commit comments

Comments
 (0)