summaryrefslogtreecommitdiff
path: root/drivers/adc
diff options
context:
space:
mode:
authorFabrice Gasnier <fabrice.gasnier@st.com>2018-11-12 14:03:58 +0100
committerTom Rini <trini@konsulko.com>2018-11-20 12:35:25 -0500
commit63f004e7aae17a6b6048c88ce7e39d64e58c08c1 (patch)
treed24d457dd1dfedb302da045a978782508556dcc1 /drivers/adc
parentd73d81fd85e4a030ade42c4b2d13466d45090aa3 (diff)
downloadu-boot-63f004e7aae17a6b6048c88ce7e39d64e58c08c1.tar.gz
u-boot-63f004e7aae17a6b6048c88ce7e39d64e58c08c1.tar.bz2
u-boot-63f004e7aae17a6b6048c88ce7e39d64e58c08c1.zip
dm: adc: add uclass's mask and conversion helpers
Add two functions to ADC uclass's: - adc_raw_to_uV() to ease ADC raw value conversion to microvolts - adc_channel_mask() to get channels on consumer side Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/adc')
-rw-r--r--drivers/adc/adc-uclass.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/adc/adc-uclass.c b/drivers/adc/adc-uclass.c
index 738c1eabdc..0a492eba54 100644
--- a/drivers/adc/adc-uclass.c
+++ b/drivers/adc/adc-uclass.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <errno.h>
+#include <div64.h>
#include <dm.h>
#include <dm/lists.h>
#include <dm/device-internal.h>
@@ -77,6 +78,18 @@ int adc_data_mask(struct udevice *dev, unsigned int *data_mask)
return 0;
}
+int adc_channel_mask(struct udevice *dev, unsigned int *channel_mask)
+{
+ struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);
+
+ if (!uc_pdata)
+ return -ENOSYS;
+
+ *channel_mask = uc_pdata->channel_mask;
+
+ return 0;
+}
+
int adc_stop(struct udevice *dev)
{
const struct adc_ops *ops = dev_get_driver_ops(dev);
@@ -329,6 +342,30 @@ int adc_vss_value(struct udevice *dev, int *uV)
return 0;
}
+int adc_raw_to_uV(struct udevice *dev, unsigned int raw, int *uV)
+{
+ unsigned int data_mask;
+ int ret, val, vref;
+ u64 raw64 = raw;
+
+ ret = adc_vdd_value(dev, &vref);
+ if (ret)
+ return ret;
+
+ if (!adc_vss_value(dev, &val))
+ vref -= val;
+
+ ret = adc_data_mask(dev, &data_mask);
+ if (ret)
+ return ret;
+
+ raw64 *= vref;
+ do_div(raw64, data_mask);
+ *uV = raw64;
+
+ return 0;
+}
+
static int adc_vdd_platdata_set(struct udevice *dev)
{
struct adc_uclass_platdata *uc_pdata = dev_get_uclass_platdata(dev);