Skip to contentSkip to conversation

adc: rockchip-saradc: add support for getting reference voltage value

PATCH Superseded Peter Cai 2 participants 2 messages Feb 2, 2022 – Feb 3, 2022 Arm Rockchip

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peter Cai

author
#0 lore raw

PATCH 1/1 adc: rockchip-saradc: add support for getting reference voltage value

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.

Cc Simon Glass <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Kever Yang <[email protected]>
---
 drivers/adc/rockchip-saradc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/adc/rockchip-saradc.c +21 -0
index e464d33f2267..67c11d896e8d 100644
@@ -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 clk clk;
+	struct udevice *vref;
+	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;
 }
 
Signature · 1 line
2.35.0
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 10 lines · Peter Cai

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.

Cc Simon Glass <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Kever Yang <[email protected]>

One code style nit below, but:

The results from this look good on RK3288.

Quoted 17 lines
---
 drivers/adc/rockchip-saradc.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/adc/rockchip-saradc.c +1 -0
index e464d33f2267..67c11d896e8d 100644
@@ -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)

drivers/adc/rockchip-saradc.c int rockchip_saradc_stop(struct udevice *dev) · line 107

Quoted 7 lines
drivers/adc/rockchip-saradc.c +2 -0
@@ -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 clk clk;
+	struct udevice *vref;

Should vref be above clk to keep the reverse Christmas tree order of decreasing line length?

Quoted 31 lines
drivers/adc/rockchip-saradc.c +18 -0
+	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;
 }
 
Signature · 1 line
2.35.0