[ERD][RAMEN9610-13615] hwmon: ntc_thermistor: Add condition of iio convert
authorHyeonseong Gil <hs.gil@samsung.com>
Wed, 5 Sep 2018 04:34:48 +0000 (13:34 +0900)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:23:21 +0000 (20:23 +0300)
From mainline, ntc_thermistor uses iio_convert_raw_to_processed()
for microvolt conversion.
But, if adc driver does not support scaling, the API just pass raw
values as processed. Then, the driver misunderstands the values as microvolt.
So, we added iio_convert_support property from device-tree.
In our BSP, not supprot iio_convert, microvolt will be convert
by using pullup_uv.

Change-Id: Idcc2fe11835d7c0ca69c4b06e40129bafb756df4
Signed-off-by: Hyeonseong Gil <hs.gil@samsung.com>
drivers/hwmon/ntc_thermistor.c
include/linux/platform_data/ntc_thermistor.h

index df7449508b205a358f847a80dfbb5d01368e7ad3..cd2fb640804646648be2b2f364866da976069dc6 100644 (file)
@@ -270,8 +270,13 @@ static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
                return ret;
        }
 
-       ret = iio_convert_raw_to_processed(channel, raw, &uv, 1000);
-       if (ret < 0) {
+       if (pdata->iio_convert_support) {
+               ret = iio_convert_raw_to_processed(channel, raw, &uv, 1000);
+               if (ret < 0) {
+                       /* Assume 12 bit ADC with vref at pullup_uv */
+                       uv = (pdata->pullup_uv * (s64)raw) >> 12;
+               }
+       } else {
                /* Assume 12 bit ADC with vref at pullup_uv */
                uv = (pdata->pullup_uv * (s64)raw) >> 12;
        }
@@ -351,6 +356,11 @@ ntc_thermistor_parse_dt(struct device *dev)
        else /* status change should be possible if not always on. */
                pdata->connect = NTC_CONNECTED_GROUND;
 
+       if (of_find_property(np, "iio-convert-support", NULL))
+               pdata->iio_convert_support = true;
+       else
+               pdata->iio_convert_support = false;
+
        pdata->chan = chan;
        pdata->read_uv = ntc_adc_iio_read;
 
index 698d0d59db761b3cae1d75d5b88a67603dc2c187..962d582a480346c970e59d6bf1821d2ecf83e489 100644 (file)
@@ -55,6 +55,7 @@ struct ntc_thermistor_platform_data {
        unsigned int pulldown_ohm;
        enum { NTC_CONNECTED_POSITIVE, NTC_CONNECTED_GROUND } connect;
        struct iio_channel *chan;
+       bool iio_convert_support;
 
        int (*read_ohm)(void);
 };