> >> + } > >> + > >> + return -EINVAL; > >> +}; > >> + > >> +static const struct iio_backend_ops sd_backend_ops = { > >> + .enable = sd_backend_enable, > >> + .disable = sd_backend_disable, > >> + .read_raw = sd_backend_read, > >> +}; > >> + > >> +static int iio_sd_backend_probe(struct platform_device *pdev) > >> +{ > >> + struct device *dev = &pdev->dev; > >> + struct regulator *vref; > >> + struct iio_sd_backend_priv *priv; > >> + int ret; > >> + > >> + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > >> + if (!priv) > >> + return -ENOMEM; > >> + > >> + vref = devm_regulator_get_optional(dev, "vref"); > > > > New devm_regulator_get_enable_read_voltage() slightly simplifies this > > and means you don't need to keep vref around. > > > >> + if (IS_ERR(vref)) { > >> + if (PTR_ERR(vref) != -ENODEV) > >> + return dev_err_probe(dev, PTR_ERR(vref), "Failed to get vref\n"); > >> + } else { > >> + ret = regulator_get_voltage(vref); > > You haven't turned it on so it's not guaranteed to give you a useful > > answer. > > > > My understanding is that regulator_get_voltage() always returns the > regulator voltage, whatever the regulator state, as documented in the > API description: > "* NOTE: If the regulator is disabled it will return the voltage value. > * This function should not be used to determine regulator state." > > So, my logic was to enable the regulator only when requested, through > enable/disable callbacks to manage power. > > Please, let me know if I missed something here. Ah ok. I had a vague and it seems incorrect recollection that you had to turn the regs on to get voltage in some cases. Ah well. Clearly not :) What you have is fine. Add a comment though just so no one replaces this code with the helper. Jonathan