]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
adc: rockchip-saradc: add support for getting reference voltage value
authorPeter Cai <peter@typeblog.net>
Fri, 4 Feb 2022 20:16:06 +0000 (15:16 -0500)
committerKever Yang <kever.yang@rock-chips.com>
Mon, 18 Apr 2022 03:25:12 +0000 (11:25 +0800)
Mirroring commit 97ab802aa36f ("adc: meson-saradc: add support for
getting reference voltage value") for meson-saradc, this adds support
for getting the "vref-supply" regulator and register it as the ADC's
reference voltage regulator, so clients can translate sampled ADC values
to voltage.

Signed-off-by: Peter Cai <peter@typeblog.net>
Reviewed-by: John Keeping <john@metanate.com>
Tested-by: John Keeping <john@metanate.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Philipp Tomsich <philipp.tomsich@vrull.eu>
Cc: Kever Yang <kever.yang@rock-chips.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>
drivers/adc/rockchip-saradc.c

index e0cbab6aa067b2c791b347b98d01c1fe99e1c7eb..760f8fe628047d4eac6ff330510f51c6ec981eb1 100644 (file)
@@ -13,6 +13,7 @@
 #include <asm/io.h>
 #include <linux/bitops.h>
 #include <linux/err.h>
+#include <power/regulator.h>
 
 #define SARADC_CTRL_CHN_MASK           GENMASK(2, 0)
 #define SARADC_CTRL_POWER_CTRL         BIT(3)
@@ -100,8 +101,11 @@ int rockchip_saradc_stop(struct udevice *dev)
 
 int rockchip_saradc_probe(struct udevice *dev)
 {
+       struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev);
        struct rockchip_saradc_priv *priv = dev_get_priv(dev);
+       struct udevice *vref;
        struct clk clk;
+       int vref_uv;
        int ret;
 
        ret = clk_get_by_index(dev, 0, &clk);
@@ -114,6 +118,23 @@ int rockchip_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;
 }