dm: adc: uclass: get reference regulator once
device_get_supply_regulator() only needs to be called once. But each time there's call to adc_vxx_value() for instance, it calls adc_vxx_platdata_update() -> device_get_supply_regulator(). So, move device_get_supply_regulator() to pre_probe() routine. This also allows vdd_supply/vss_supply to be provided directly from uc_pdata, e.g dt-binding variant like stm32-adc provide its own 'vref-supply'. Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
1fe243a1e4
commit
a4a87f7b74
@ -264,10 +264,8 @@ static int adc_vdd_platdata_update(struct udevice *dev)
|
|||||||
* will bind before its supply regulator device, then the below 'get'
|
* will bind before its supply regulator device, then the below 'get'
|
||||||
* will return an error.
|
* will return an error.
|
||||||
*/
|
*/
|
||||||
ret = device_get_supply_regulator(dev, "vdd-supply",
|
if (!uc_pdata->vdd_supply)
|
||||||
&uc_pdata->vdd_supply);
|
return 0;
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
ret = regulator_get_value(uc_pdata->vdd_supply);
|
ret = regulator_get_value(uc_pdata->vdd_supply);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -283,10 +281,8 @@ static int adc_vss_platdata_update(struct udevice *dev)
|
|||||||
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
|
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = device_get_supply_regulator(dev, "vss-supply",
|
if (!uc_pdata->vss_supply)
|
||||||
&uc_pdata->vss_supply);
|
return 0;
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
ret = regulator_get_value(uc_pdata->vss_supply);
|
ret = regulator_get_value(uc_pdata->vss_supply);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -302,14 +298,11 @@ int adc_vdd_value(struct udevice *dev, int *uV)
|
|||||||
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
|
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
|
||||||
int ret, value_sign = uc_pdata->vdd_polarity_negative ? -1 : 1;
|
int ret, value_sign = uc_pdata->vdd_polarity_negative ? -1 : 1;
|
||||||
|
|
||||||
if (!uc_pdata->vdd_supply)
|
|
||||||
goto nodev;
|
|
||||||
|
|
||||||
/* Update the regulator Value. */
|
/* Update the regulator Value. */
|
||||||
ret = adc_vdd_platdata_update(dev);
|
ret = adc_vdd_platdata_update(dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
nodev:
|
|
||||||
if (uc_pdata->vdd_microvolts == -ENODATA)
|
if (uc_pdata->vdd_microvolts == -ENODATA)
|
||||||
return -ENODATA;
|
return -ENODATA;
|
||||||
|
|
||||||
@ -323,14 +316,11 @@ int adc_vss_value(struct udevice *dev, int *uV)
|
|||||||
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
|
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
|
||||||
int ret, value_sign = uc_pdata->vss_polarity_negative ? -1 : 1;
|
int ret, value_sign = uc_pdata->vss_polarity_negative ? -1 : 1;
|
||||||
|
|
||||||
if (!uc_pdata->vss_supply)
|
|
||||||
goto nodev;
|
|
||||||
|
|
||||||
/* Update the regulator Value. */
|
/* Update the regulator Value. */
|
||||||
ret = adc_vss_platdata_update(dev);
|
ret = adc_vss_platdata_update(dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
nodev:
|
|
||||||
if (uc_pdata->vss_microvolts == -ENODATA)
|
if (uc_pdata->vss_microvolts == -ENODATA)
|
||||||
return -ENODATA;
|
return -ENODATA;
|
||||||
|
|
||||||
@ -348,7 +338,12 @@ static int adc_vdd_platdata_set(struct udevice *dev)
|
|||||||
prop = "vdd-polarity-negative";
|
prop = "vdd-polarity-negative";
|
||||||
uc_pdata->vdd_polarity_negative = dev_read_bool(dev, prop);
|
uc_pdata->vdd_polarity_negative = dev_read_bool(dev, prop);
|
||||||
|
|
||||||
ret = adc_vdd_platdata_update(dev);
|
/* Optionally get regulators */
|
||||||
|
ret = device_get_supply_regulator(dev, "vdd-supply",
|
||||||
|
&uc_pdata->vdd_supply);
|
||||||
|
if (!ret)
|
||||||
|
return adc_vdd_platdata_update(dev);
|
||||||
|
|
||||||
if (ret != -ENOENT)
|
if (ret != -ENOENT)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -368,7 +363,11 @@ static int adc_vss_platdata_set(struct udevice *dev)
|
|||||||
prop = "vss-polarity-negative";
|
prop = "vss-polarity-negative";
|
||||||
uc_pdata->vss_polarity_negative = dev_read_bool(dev, prop);
|
uc_pdata->vss_polarity_negative = dev_read_bool(dev, prop);
|
||||||
|
|
||||||
ret = adc_vss_platdata_update(dev);
|
ret = device_get_supply_regulator(dev, "vss-supply",
|
||||||
|
&uc_pdata->vss_supply);
|
||||||
|
if (!ret)
|
||||||
|
return adc_vss_platdata_update(dev);
|
||||||
|
|
||||||
if (ret != -ENOENT)
|
if (ret != -ENOENT)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user