iio: adc: max1363: use devm_regulator_get_enable_read_voltage()
Use devm_regulator_get_enable_read_voltage() to simplify the code. Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Nuno Sa <nuno.sa@analog.com> Link: https://patch.msgid.link/20240621-iio-regulator-refactor-round-2-v1-6-49e50cd0b99a@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
890582c2a4
commit
0817c9543c
@@ -1561,18 +1561,12 @@ static const struct of_device_id max1363_of_match[] = {
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, max1363_of_match);
|
||||
|
||||
static void max1363_reg_disable(void *reg)
|
||||
{
|
||||
regulator_disable(reg);
|
||||
}
|
||||
|
||||
static int max1363_probe(struct i2c_client *client)
|
||||
{
|
||||
const struct i2c_device_id *id = i2c_client_get_device_id(client);
|
||||
int ret;
|
||||
struct max1363_state *st;
|
||||
struct iio_dev *indio_dev;
|
||||
struct regulator *vref;
|
||||
|
||||
indio_dev = devm_iio_device_alloc(&client->dev,
|
||||
sizeof(struct max1363_state));
|
||||
@@ -1589,26 +1583,12 @@ static int max1363_probe(struct i2c_client *client)
|
||||
st->chip_info = i2c_get_match_data(client);
|
||||
st->client = client;
|
||||
|
||||
st->vref_uv = st->chip_info->int_vref_mv * 1000;
|
||||
vref = devm_regulator_get_optional(&client->dev, "vref");
|
||||
if (!IS_ERR(vref)) {
|
||||
int vref_uv;
|
||||
ret = devm_regulator_get_enable_read_voltage(&client->dev, "vref");
|
||||
if (ret < 0 && ret != -ENODEV)
|
||||
return ret;
|
||||
|
||||
ret = regulator_enable(vref);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = devm_add_action_or_reset(&client->dev, max1363_reg_disable, vref);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
st->vref = vref;
|
||||
vref_uv = regulator_get_voltage(vref);
|
||||
if (vref_uv <= 0)
|
||||
return -EINVAL;
|
||||
|
||||
st->vref_uv = vref_uv;
|
||||
}
|
||||
st->vref_uv = ret == -ENODEV ? st->chip_info->int_vref_mv * 1000 : ret;
|
||||
|
||||
if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
|
||||
st->send = i2c_master_send;
|
||||
|
||||
Reference in New Issue
Block a user