Skip to contentSkip to conversation

hwmon: ntc: use iio_read_channel_processed if possible

PATCH Superseded Chris Lesiak 2 participants 2 messages May 27, 2015 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: ntc: use iio_read_channel_processed if possible

The function ntc_adc_iio_read assumes both a 12 bit ADC and that pullup_uv is the same as the ADC reference voltage. If either assumption is false, then the result is incorrect.

For iio channels supporting either IIO_CHAN_INFO_PROCESSED or IIO_CHAN_INFO_SCALE, a new function, ntc_adc_iio_read_processed, will be used. That function gets microvolts directly with a call to iio_read_channel_processed.

---
 drivers/hwmon/ntc_thermistor.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/hwmon/ntc_thermistor.c +20 -1
index 6880011..311df86 100644
@@ -206,6 +206,20 @@ static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
 	return (int)result;
 }
 
+static int ntc_adc_iio_read_processed(struct ntc_thermistor_platform_data *pdata)
+{
+	struct iio_channel *channel = pdata->chan;
+	int val, ret;
+
+	ret = iio_read_channel_processed(channel, &val);
+	if (ret < 0) {
+		pr_err("read channel() error: %d\n", ret);
+		return ret;
+	}
+
+	return val;
+}
+
 static const struct of_device_id ntc_match[] = {
 	{ .compatible = "murata,ncp15wb473",
 		.data = &ntc_thermistor_id[0] },
@@ -275,7 +289,12 @@ ntc_thermistor_parse_dt(struct platform_device *pdev)
 		pdata->connect = NTC_CONNECTED_GROUND;
 
 	pdata->chan = chan;
-	pdata->read_uv = ntc_adc_iio_read;
+
+	if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED)
+		|| iio_channel_has_info(chan->channel, IIO_CHAN_INFO_SCALE))
+		pdata->read_uv = ntc_adc_iio_read_processed;
+	else
+		pdata->read_uv = ntc_adc_iio_read;
 
 	return pdata;
 }
Signature · 7 lines
1.9.3


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
maintainer
#1 lore raw
Quoted 10 lines · Chris Lesiak

The function ntc_adc_iio_read assumes both a 12 bit ADC and that pullup_uv is the same as the ADC reference voltage. If either assumption is false, then the result is incorrect.

For iio channels supporting either IIO_CHAN_INFO_PROCESSED or IIO_CHAN_INFO_SCALE, a new function, ntc_adc_iio_read_processed, will be used. That function gets microvolts directly with a call to iio_read_channel_processed.

Hi Chris,

Couple of comments below.

When sending a new version of a patch, please provide versions and change logs as suggested in Documentation/SubmittingPatches. Otherwise you are making it difficult for us to track patch version and changes made.

Thanks,
Guenter

drivers/hwmon/ntc_thermistor.c static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata) · line 209

Quoted 13 lines
---
 drivers/hwmon/ntc_thermistor.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/hwmon/ntc_thermistor.c +1 -0
index 6880011..311df86 100644
@@ -206,6 +206,20 @@ static int ntc_adc_iio_read(struct ntc_thermistor_platform_data *pdata)
 	return (int)result;
 }
 
+static int ntc_adc_iio_read_processed(struct ntc_thermistor_platform_data *pdata)

checkpatch warning (line too long). You could rename the function to ntc_adc_iio_read() and the current ntc_adc_iio_read() to ntc_adc_iio_read_raw() as possible solution, or move 'static int' to a separate line.

Quoted 17 lines
drivers/hwmon/ntc_thermistor.c +13 -0
+{
+	struct iio_channel *channel = pdata->chan;
+	int val, ret;
+
+	ret = iio_read_channel_processed(channel, &val);
+	if (ret < 0) {
+		pr_err("read channel() error: %d\n", ret);
+		return ret;
+	}
+
+	return val;
+}
+
 static const struct of_device_id ntc_match[] = {
 	{ .compatible = "murata,ncp15wb473",
 		.data = &ntc_thermistor_id[0] },

drivers/hwmon/ntc_thermistor.c ntc_thermistor_parse_dt(struct platform_device *pdev) · line 294

Quoted 7 lines
drivers/hwmon/ntc_thermistor.c +3 -1
@@ -275,7 +289,12 @@ ntc_thermistor_parse_dt(struct platform_device *pdev)
 		pdata->connect = NTC_CONNECTED_GROUND;
 
 	pdata->chan = chan;
-	pdata->read_uv = ntc_adc_iio_read;
+
+	if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED)
+		|| iio_channel_has_info(chan->channel, IIO_CHAN_INFO_SCALE))

checkpatch check message (from --strict) - please address as recommended.

	if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED) ||
	    iio_channel_has_info(chan->channel, IIO_CHAN_INFO_SCALE))
Quoted 14 lines
drivers/hwmon/ntc_thermistor.c +3 -0
+		pdata->read_uv = ntc_adc_iio_read_processed;
+	else
+		pdata->read_uv = ntc_adc_iio_read;
 
 	return pdata;
 }
Signature · 7 lines
1.9.3


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors