Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: David Lechner <dlechner@baylibre.com>
Reviewed-by: Andrew Jeffery <andrew@codeconstruct.com.au>
Link: https://patch.msgid.link/20240621-iio-regulator-refactor-round-2-v1-1-49e50cd0b99a@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

David Lechner and committed by
Jonathan Cameron
9a36aa0f bb78ad62

+8 -22
+8 -22
drivers/iio/adc/aspeed_adc.c
··· 108 108 struct aspeed_adc_data { 109 109 struct device *dev; 110 110 const struct aspeed_adc_model_data *model_data; 111 - struct regulator *regulator; 112 111 void __iomem *base; 113 112 spinlock_t clk_lock; 114 113 struct clk_hw *fixed_div_clk; ··· 403 404 priv_data->base + ASPEED_REG_ENGINE_CONTROL); 404 405 } 405 406 406 - static void aspeed_adc_reg_disable(void *data) 407 - { 408 - struct regulator *reg = data; 409 - 410 - regulator_disable(reg); 411 - } 412 - 413 407 static int aspeed_adc_vref_config(struct iio_dev *indio_dev) 414 408 { 415 409 struct aspeed_adc_data *data = iio_priv(indio_dev); ··· 415 423 } 416 424 adc_engine_control_reg_val = 417 425 readl(data->base + ASPEED_REG_ENGINE_CONTROL); 418 - data->regulator = devm_regulator_get_optional(data->dev, "vref"); 419 - if (!IS_ERR(data->regulator)) { 420 - ret = regulator_enable(data->regulator); 421 - if (ret) 422 - return ret; 423 - ret = devm_add_action_or_reset( 424 - data->dev, aspeed_adc_reg_disable, data->regulator); 425 - if (ret) 426 - return ret; 427 - data->vref_mv = regulator_get_voltage(data->regulator); 428 - /* Conversion from uV to mV */ 429 - data->vref_mv /= 1000; 426 + 427 + ret = devm_regulator_get_enable_read_voltage(data->dev, "vref"); 428 + if (ret < 0 && ret != -ENODEV) 429 + return ret; 430 + 431 + if (ret != -ENODEV) { 432 + data->vref_mv = ret / 1000; 433 + 430 434 if ((data->vref_mv >= 1550) && (data->vref_mv <= 2700)) 431 435 writel(adc_engine_control_reg_val | 432 436 FIELD_PREP( ··· 441 453 return -EOPNOTSUPP; 442 454 } 443 455 } else { 444 - if (PTR_ERR(data->regulator) != -ENODEV) 445 - return PTR_ERR(data->regulator); 446 456 data->vref_mv = 2500000; 447 457 of_property_read_u32(data->dev->of_node, 448 458 "aspeed,int-vref-microvolt",