Commit 9a36aa0f authored by David Lechner's avatar David Lechner Committed by Jonathan Cameron

iio: adc: aspeed_adc: use devm_regulator_get_enable_read_voltage()

This makes use of the devm_regulator_get_enable_read_voltage() helper
function to simplify the code.

The error return is moved closer to the function call to make it easier
to follow the logic. And a few blank lines are added for readability.
Signed-off-by: default avatarDavid Lechner <dlechner@baylibre.com>
Reviewed-by: default avatarAndrew Jeffery <andrew@codeconstruct.com.au>
Link: https://patch.msgid.link/20240621-iio-regulator-refactor-round-2-v1-1-49e50cd0b99a@baylibre.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent bb78ad62
...@@ -108,7 +108,6 @@ struct adc_gain { ...@@ -108,7 +108,6 @@ struct adc_gain {
struct aspeed_adc_data { struct aspeed_adc_data {
struct device *dev; struct device *dev;
const struct aspeed_adc_model_data *model_data; const struct aspeed_adc_model_data *model_data;
struct regulator *regulator;
void __iomem *base; void __iomem *base;
spinlock_t clk_lock; spinlock_t clk_lock;
struct clk_hw *fixed_div_clk; struct clk_hw *fixed_div_clk;
...@@ -404,13 +403,6 @@ static void aspeed_adc_power_down(void *data) ...@@ -404,13 +403,6 @@ static void aspeed_adc_power_down(void *data)
priv_data->base + ASPEED_REG_ENGINE_CONTROL); priv_data->base + ASPEED_REG_ENGINE_CONTROL);
} }
static void aspeed_adc_reg_disable(void *data)
{
struct regulator *reg = data;
regulator_disable(reg);
}
static int aspeed_adc_vref_config(struct iio_dev *indio_dev) static int aspeed_adc_vref_config(struct iio_dev *indio_dev)
{ {
struct aspeed_adc_data *data = iio_priv(indio_dev); struct aspeed_adc_data *data = iio_priv(indio_dev);
...@@ -423,18 +415,14 @@ static int aspeed_adc_vref_config(struct iio_dev *indio_dev) ...@@ -423,18 +415,14 @@ static int aspeed_adc_vref_config(struct iio_dev *indio_dev)
} }
adc_engine_control_reg_val = adc_engine_control_reg_val =
readl(data->base + ASPEED_REG_ENGINE_CONTROL); readl(data->base + ASPEED_REG_ENGINE_CONTROL);
data->regulator = devm_regulator_get_optional(data->dev, "vref");
if (!IS_ERR(data->regulator)) { ret = devm_regulator_get_enable_read_voltage(data->dev, "vref");
ret = regulator_enable(data->regulator); if (ret < 0 && ret != -ENODEV)
if (ret) return ret;
return ret;
ret = devm_add_action_or_reset( if (ret != -ENODEV) {
data->dev, aspeed_adc_reg_disable, data->regulator); data->vref_mv = ret / 1000;
if (ret)
return ret;
data->vref_mv = regulator_get_voltage(data->regulator);
/* Conversion from uV to mV */
data->vref_mv /= 1000;
if ((data->vref_mv >= 1550) && (data->vref_mv <= 2700)) if ((data->vref_mv >= 1550) && (data->vref_mv <= 2700))
writel(adc_engine_control_reg_val | writel(adc_engine_control_reg_val |
FIELD_PREP( FIELD_PREP(
...@@ -453,8 +441,6 @@ static int aspeed_adc_vref_config(struct iio_dev *indio_dev) ...@@ -453,8 +441,6 @@ static int aspeed_adc_vref_config(struct iio_dev *indio_dev)
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
} else { } else {
if (PTR_ERR(data->regulator) != -ENODEV)
return PTR_ERR(data->regulator);
data->vref_mv = 2500000; data->vref_mv = 2500000;
of_property_read_u32(data->dev->of_node, of_property_read_u32(data->dev->of_node,
"aspeed,int-vref-microvolt", "aspeed,int-vref-microvolt",
......
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