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 <Jonathan.Cameron@huawei.com> Signed-off-by: David Lechner <dlechner@baylibre.com> Acked-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20240429-regulator-get-enable-get-votlage-v2-3-b1f11ab766c1@baylibre.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
cffb8d74bd
commit
d72fd5228c
@ -26,7 +26,6 @@ struct da9052_hwmon {
|
|||||||
struct mutex hwmon_lock;
|
struct mutex hwmon_lock;
|
||||||
bool tsi_as_adc;
|
bool tsi_as_adc;
|
||||||
int tsiref_mv;
|
int tsiref_mv;
|
||||||
struct regulator *tsiref;
|
|
||||||
struct completion tsidone;
|
struct completion tsidone;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -397,7 +396,7 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
|
|||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
struct da9052_hwmon *hwmon;
|
struct da9052_hwmon *hwmon;
|
||||||
struct device *hwmon_dev;
|
struct device *hwmon_dev;
|
||||||
int err;
|
int err, tsiref_uv;
|
||||||
|
|
||||||
hwmon = devm_kzalloc(dev, sizeof(struct da9052_hwmon), GFP_KERNEL);
|
hwmon = devm_kzalloc(dev, sizeof(struct da9052_hwmon), GFP_KERNEL);
|
||||||
if (!hwmon)
|
if (!hwmon)
|
||||||
@ -414,32 +413,20 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
|
|||||||
device_property_read_bool(pdev->dev.parent, "dlg,tsi-as-adc");
|
device_property_read_bool(pdev->dev.parent, "dlg,tsi-as-adc");
|
||||||
|
|
||||||
if (hwmon->tsi_as_adc) {
|
if (hwmon->tsi_as_adc) {
|
||||||
hwmon->tsiref = devm_regulator_get(pdev->dev.parent, "tsiref");
|
tsiref_uv = devm_regulator_get_enable_read_voltage(dev->parent,
|
||||||
if (IS_ERR(hwmon->tsiref)) {
|
"tsiref");
|
||||||
err = PTR_ERR(hwmon->tsiref);
|
if (tsiref_uv < 0)
|
||||||
dev_err(&pdev->dev, "failed to get tsiref: %d", err);
|
return dev_err_probe(dev, tsiref_uv,
|
||||||
return err;
|
"failed to get tsiref voltage\n");
|
||||||
}
|
|
||||||
|
|
||||||
err = regulator_enable(hwmon->tsiref);
|
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
hwmon->tsiref_mv = regulator_get_voltage(hwmon->tsiref);
|
|
||||||
if (hwmon->tsiref_mv < 0) {
|
|
||||||
err = hwmon->tsiref_mv;
|
|
||||||
goto exit_regulator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* convert from microvolt (DT) to millivolt (hwmon) */
|
/* convert from microvolt (DT) to millivolt (hwmon) */
|
||||||
hwmon->tsiref_mv /= 1000;
|
hwmon->tsiref_mv = tsiref_uv / 1000;
|
||||||
|
|
||||||
/* TSIREF limits from datasheet */
|
/* TSIREF limits from datasheet */
|
||||||
if (hwmon->tsiref_mv < 1800 || hwmon->tsiref_mv > 2600) {
|
if (hwmon->tsiref_mv < 1800 || hwmon->tsiref_mv > 2600) {
|
||||||
dev_err(hwmon->da9052->dev, "invalid TSIREF voltage: %d",
|
dev_err(hwmon->da9052->dev, "invalid TSIREF voltage: %d",
|
||||||
hwmon->tsiref_mv);
|
hwmon->tsiref_mv);
|
||||||
err = -ENXIO;
|
return -ENXIO;
|
||||||
goto exit_regulator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* disable touchscreen features */
|
/* disable touchscreen features */
|
||||||
@ -456,7 +443,7 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
|
|||||||
if (err) {
|
if (err) {
|
||||||
dev_err(&pdev->dev, "Failed to register TSIRDY IRQ: %d",
|
dev_err(&pdev->dev, "Failed to register TSIRDY IRQ: %d",
|
||||||
err);
|
err);
|
||||||
goto exit_regulator;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,9 +459,6 @@ static int da9052_hwmon_probe(struct platform_device *pdev)
|
|||||||
exit_irq:
|
exit_irq:
|
||||||
if (hwmon->tsi_as_adc)
|
if (hwmon->tsi_as_adc)
|
||||||
da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon);
|
da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon);
|
||||||
exit_regulator:
|
|
||||||
if (hwmon->tsiref)
|
|
||||||
regulator_disable(hwmon->tsiref);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -483,10 +467,8 @@ static void da9052_hwmon_remove(struct platform_device *pdev)
|
|||||||
{
|
{
|
||||||
struct da9052_hwmon *hwmon = platform_get_drvdata(pdev);
|
struct da9052_hwmon *hwmon = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
if (hwmon->tsi_as_adc) {
|
if (hwmon->tsi_as_adc)
|
||||||
da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon);
|
da9052_free_irq(hwmon->da9052, DA9052_IRQ_TSIREADY, hwmon);
|
||||||
regulator_disable(hwmon->tsiref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct platform_driver da9052_hwmon_driver = {
|
static struct platform_driver da9052_hwmon_driver = {
|
||||||
|
Loading…
Reference in New Issue
Block a user