Skip to contentSkip to conversation

AUXADC: Mediatek auxadc driver

PATCH Superseded Hui Liu 2 participants 3 messages Aug 31, 2021 – Sep 5, 2021

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Hui Liu

author
#0 lore raw

v2 cover AUXADC: Mediatek auxadc driver

This series includes one patch:
1.update case IIO_CHAN_INFO_PROCESSED: convert raw data to voltage.

Changes in patch v2:
1)abandon support case IIO_CHAN_INFO_RAW.

Changes in patch v1:
1)fix typo covert to convert in patch 2/2 description.

Hui Liu (1):
iio: mtk-auxadc: update case IIO_CHAN_INFO_PROCESSED

 drivers/iio/adc/mt6577_auxadc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

--
2.18.0

author
#1 lore raw

PATCH v2 1/1 iio: mtk-auxadc: update case IIO_CHAN_INFO_PROCESSED

Convert raw data to processed data, the processed data is input voltage.

---
 drivers/iio/adc/mt6577_auxadc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/adc/mt6577_auxadc.c +8 -0
index 79c1dd68b909..d4fccd52ef08 100644
@@ -82,6 +82,10 @@ static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
 	MT6577_AUXADC_CHANNEL(15),
 };
 
+/* For Voltage calculation */
+#define VOLTAGE_FULL_RANGE  1500	/* VA voltage */
+#define AUXADC_PRECISE      4096	/* 12 bits */
+
 static int mt_auxadc_get_cali_data(int rawdata, bool enable_cali)
 {
 	return rawdata;
@@ -191,6 +195,10 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev,
 		}
 		if (adc_dev->dev_comp->sample_data_cali)
 			*val = mt_auxadc_get_cali_data(*val, true);
+
+		/* Convert adc raw data to voltage: 0 - 1500 mV */
+		*val = *val * VOLTAGE_FULL_RANGE / AUXADC_PRECISE;
+
 		return IIO_VAL_INT;
 
 	default:
Signature · 1 line
2.18.0
maintainer
#2 lore raw

Re: [PATCH v2 1/1] iio: mtk-auxadc: update case IIO_CHAN_INFO_PROCESSED

Quoted 3 lines · On Tue, 31 Aug 2021 13:42:07 +0800 Hui Liu <[email protected]> wrote:

Convert raw data to processed data, the processed data is input voltage.

Looks very much to be a fix. Please track down appropriate patch and let me know what the Fixes: tag should be. If you reply to this thread I'll add it plus a not saying it is an ABI change, but a necessary one as the driver was previously buggy.

Whilst we are here, what is the cali_data() function actually there for? Seems to only set *val = *val which is rather pointless.

Thanks,

Jonathan

Quoted 30 lines
---
 drivers/iio/adc/mt6577_auxadc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/iio/adc/mt6577_auxadc.c +8 -0
index 79c1dd68b909..d4fccd52ef08 100644
@@ -82,6 +82,10 @@ static const struct iio_chan_spec mt6577_auxadc_iio_channels[] = {
 	MT6577_AUXADC_CHANNEL(15),
 };
 
+/* For Voltage calculation */
+#define VOLTAGE_FULL_RANGE  1500	/* VA voltage */
+#define AUXADC_PRECISE      4096	/* 12 bits */
+
 static int mt_auxadc_get_cali_data(int rawdata, bool enable_cali)
 {
 	return rawdata;
@@ -191,6 +195,10 @@ static int mt6577_auxadc_read_raw(struct iio_dev *indio_dev,
 		}
 		if (adc_dev->dev_comp->sample_data_cali)
 			*val = mt_auxadc_get_cali_data(*val, true);
+
+		/* Convert adc raw data to voltage: 0 - 1500 mV */
+		*val = *val * VOLTAGE_FULL_RANGE / AUXADC_PRECISE;
+
 		return IIO_VAL_INT;
 
 	default: