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: dac: ad3552r: use devm_regulator_get_enable_read_voltage()

Use devm_regulator_get_enable_read_voltage() to simplify the code.
Error message is slightly changed since there is only one error return
now.

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-10-49e50cd0b99a@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

David Lechner and committed by
Jonathan Cameron
3341d692 a4a9fc32

+4 -24
+4 -24
drivers/iio/dac/ad3552r.c
··· 857 857 return 0; 858 858 } 859 859 860 - static void ad3552r_reg_disable(void *reg) 861 - { 862 - regulator_disable(reg); 863 - } 864 - 865 860 static int ad3552r_configure_device(struct ad3552r_desc *dac) 866 861 { 867 862 struct device *dev = &dac->spi->dev; 868 - struct regulator *vref; 869 863 int err, cnt = 0, voltage, delta = 100000; 870 864 u32 vals[2], val, ch; 871 865 ··· 868 874 return dev_err_probe(dev, PTR_ERR(dac->gpio_ldac), 869 875 "Error getting gpio ldac"); 870 876 871 - vref = devm_regulator_get_optional(dev, "vref"); 872 - if (IS_ERR(vref)) { 873 - if (PTR_ERR(vref) != -ENODEV) 874 - return dev_err_probe(dev, PTR_ERR(vref), 875 - "Error getting vref"); 877 + voltage = devm_regulator_get_enable_read_voltage(dev, "vref"); 878 + if (voltage < 0 && voltage != -ENODEV) 879 + return dev_err_probe(dev, voltage, "Error getting vref voltage\n"); 876 880 881 + if (voltage == -ENODEV) { 877 882 if (device_property_read_bool(dev, "adi,vref-out-en")) 878 883 val = AD3552R_INTERNAL_VREF_PIN_2P5V; 879 884 else 880 885 val = AD3552R_INTERNAL_VREF_PIN_FLOATING; 881 886 } else { 882 - err = regulator_enable(vref); 883 - if (err) { 884 - dev_err(dev, "Failed to enable external vref supply\n"); 885 - return err; 886 - } 887 - 888 - err = devm_add_action_or_reset(dev, ad3552r_reg_disable, vref); 889 - if (err) { 890 - regulator_disable(vref); 891 - return err; 892 - } 893 - 894 - voltage = regulator_get_voltage(vref); 895 887 if (voltage > 2500000 + delta || voltage < 2500000 - delta) { 896 888 dev_warn(dev, "vref-supply must be 2.5V"); 897 889 return -EINVAL;