Commit 122ef59a authored by Jonathan Cameron's avatar Jonathan Cameron

iio: pressure: ms5611: Use devm_regulator_get_enable()

This driver only turns the power on at probe and off at remove.
The new devm_regulator_get_enable() replaces this boilerplate code.
Some additional refactoring to drop now unnecessary unwinding after
this change.
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Tomasz Duszynski <tduszyns@gmail.com>
Reviewed-by: default avatarMatti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/20221016163409.320197-14-jic23@kernel.org
parent 4da9438d
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
#include <linux/iio/iio.h> #include <linux/iio/iio.h>
#include <linux/mutex.h> #include <linux/mutex.h>
struct regulator;
#define MS5611_RESET 0x1e #define MS5611_RESET 0x1e
#define MS5611_READ_ADC 0x00 #define MS5611_READ_ADC 0x00
#define MS5611_READ_PROM_WORD 0xA0 #define MS5611_READ_PROM_WORD 0xA0
...@@ -52,7 +50,6 @@ struct ms5611_state { ...@@ -52,7 +50,6 @@ struct ms5611_state {
int (*compensate_temp_and_pressure)(struct ms5611_state *st, s32 *temp, int (*compensate_temp_and_pressure)(struct ms5611_state *st, s32 *temp,
s32 *pressure); s32 *pressure);
struct regulator *vdd;
}; };
int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
......
...@@ -380,40 +380,21 @@ static const struct iio_info ms5611_info = { ...@@ -380,40 +380,21 @@ static const struct iio_info ms5611_info = {
static int ms5611_init(struct iio_dev *indio_dev) static int ms5611_init(struct iio_dev *indio_dev)
{ {
int ret; int ret;
struct ms5611_state *st = iio_priv(indio_dev);
/* Enable attached regulator if any. */ /* Enable attached regulator if any. */
st->vdd = devm_regulator_get(indio_dev->dev.parent, "vdd"); ret = devm_regulator_get_enable(indio_dev->dev.parent, "vdd");
if (IS_ERR(st->vdd)) if (ret)
return PTR_ERR(st->vdd);
ret = regulator_enable(st->vdd);
if (ret) {
dev_err(indio_dev->dev.parent,
"failed to enable Vdd supply: %d\n", ret);
return ret; return ret;
}
ret = ms5611_reset(indio_dev); ret = ms5611_reset(indio_dev);
if (ret < 0) if (ret < 0)
goto err_regulator_disable; return ret;
ret = ms5611_read_prom(indio_dev); ret = ms5611_read_prom(indio_dev);
if (ret < 0) if (ret < 0)
goto err_regulator_disable; return ret;
return 0; return 0;
err_regulator_disable:
regulator_disable(st->vdd);
return ret;
}
static void ms5611_fini(const struct iio_dev *indio_dev)
{
const struct ms5611_state *st = iio_priv(indio_dev);
regulator_disable(st->vdd);
} }
int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
...@@ -457,7 +438,7 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, ...@@ -457,7 +438,7 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
ms5611_trigger_handler, NULL); ms5611_trigger_handler, NULL);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "iio triggered buffer setup failed\n"); dev_err(dev, "iio triggered buffer setup failed\n");
goto err_fini; return ret;
} }
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
...@@ -470,8 +451,6 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, ...@@ -470,8 +451,6 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
err_buffer_cleanup: err_buffer_cleanup:
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
err_fini:
ms5611_fini(indio_dev);
return ret; return ret;
} }
EXPORT_SYMBOL_NS(ms5611_probe, IIO_MS5611); EXPORT_SYMBOL_NS(ms5611_probe, IIO_MS5611);
...@@ -480,7 +459,6 @@ void ms5611_remove(struct iio_dev *indio_dev) ...@@ -480,7 +459,6 @@ void ms5611_remove(struct iio_dev *indio_dev)
{ {
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
ms5611_fini(indio_dev);
} }
EXPORT_SYMBOL_NS(ms5611_remove, IIO_MS5611); EXPORT_SYMBOL_NS(ms5611_remove, IIO_MS5611);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment