diff options
author | Marek Szyprowski | 2021-02-18 11:33:16 +0100 |
---|---|---|
committer | Neil Armstrong | 2021-02-18 11:37:26 +0100 |
commit | 97ab802aa36f1ee74196525af0e844656ae3dc63 (patch) | |
tree | c1d71eafd8f31076932ce22881039a2c7472c193 | |
parent | c0165c85c3b149a86740fd649b54d5e988fab457 (diff) |
adc: meson-saradc: add support for getting reference voltage value
Add support for getting the 'vref-supply' regulator and register it as
ADC's reference voltage regulator, so clients can translate sampled ADC
values to the voltage.
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
-rw-r--r-- | drivers/adc/meson-saradc.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c index 21db55831d8..1a45a3a2655 100644 --- a/drivers/adc/meson-saradc.c +++ b/drivers/adc/meson-saradc.c @@ -18,6 +18,7 @@ #include <linux/delay.h> #include <linux/math64.h> #include <linux/bitfield.h> +#include <power/regulator.h> #define MESON_SAR_ADC_REG0 0x00 #define MESON_SAR_ADC_REG0_PANEL_DETECT BIT(31) @@ -656,7 +657,10 @@ static int meson_saradc_stop(struct udevice *dev) static int meson_saradc_probe(struct udevice *dev) { + struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev); struct meson_saradc_priv *priv = dev_get_priv(dev); + struct udevice *vref; + int vref_uv; int ret; ret = regmap_init_mem(dev_ofnode(dev), &priv->regmap); @@ -675,6 +679,23 @@ static int meson_saradc_probe(struct udevice *dev) priv->active_channel = -1; + ret = device_get_supply_regulator(dev, "vref-supply", &vref); + if (ret) { + printf("can't get vref-supply: %d\n", ret); + return ret; + } + + vref_uv = regulator_get_value(vref); + if (vref_uv < 0) { + printf("can't get vref-supply value: %d\n", vref_uv); + return vref_uv; + } + + /* VDD supplied by common vref pin */ + uc_pdata->vdd_supply = vref; + uc_pdata->vdd_microvolts = vref_uv; + uc_pdata->vss_microvolts = 0; + return 0; } |