linux-amlogic.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: (scpi) Add slope and offset to SCP sensor readings
@ 2017-03-01 13:20 Carlo Caione
  2017-03-01 15:01 ` Guenter Roeck
  0 siblings, 1 reply; 9+ messages in thread
From: Carlo Caione @ 2017-03-01 13:20 UTC (permalink / raw)
  To: linus-amlogic

From: Carlo Caione <carlo@endlessm.com>

The temperature provided by the SCP sensors not always is expressed in
millicelsius, whereas this is required by the thermal framework. This is
for example the case for the Amlogic devices, where the SCP sensor
readings are expressed in degree (and not milli degree) Celsius.

To convert the sensor readings, the thermal framework provides the
"coefficients" property, used by the thermal sensor device to adjust
their reading. This adjustment in currently not considered by the SCPI
hwmon driver. Fix this introducing slope and offset for the SCP sensor
readings.

Signed-off-by: Carlo Caione <carlo@endlessm.com>
---
 drivers/hwmon/scpi-hwmon.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/hwmon/scpi-hwmon.c b/drivers/hwmon/scpi-hwmon.c
index 094f948f99ff..cdc05c60ba67 100644
--- a/drivers/hwmon/scpi-hwmon.c
+++ b/drivers/hwmon/scpi-hwmon.c
@@ -33,6 +33,7 @@ struct sensor_data {
 struct scpi_thermal_zone {
 	int sensor_id;
 	struct scpi_sensors *scpi_sensors;
+	struct thermal_zone_device *z;
 };
 
 struct scpi_sensors {
@@ -51,13 +52,17 @@ static int scpi_read_temp(void *dev, int *temp)
 	struct scpi_ops *scpi_ops = scpi_sensors->scpi_ops;
 	struct sensor_data *sensor = &scpi_sensors->data[zone->sensor_id];
 	u64 value;
+	int slope, offset;
 	int ret;
 
 	ret = scpi_ops->sensor_get_value(sensor->info.sensor_id, &value);
 	if (ret)
 		return ret;
 
-	*temp = value;
+	slope = thermal_zone_get_slope(zone->z);
+	offset = thermal_zone_get_offset(zone->z);
+
+	*temp = value * slope + offset;
 	return 0;
 }
 
@@ -216,7 +221,6 @@ static int scpi_hwmon_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&scpi_sensors->thermal_zones);
 	for (i = 0; i < nr_sensors; i++) {
 		struct sensor_data *sensor = &scpi_sensors->data[i];
-		struct thermal_zone_device *z;
 		struct scpi_thermal_zone *zone;
 
 		if (sensor->info.class != TEMPERATURE)
@@ -228,17 +232,17 @@ static int scpi_hwmon_probe(struct platform_device *pdev)
 
 		zone->sensor_id = i;
 		zone->scpi_sensors = scpi_sensors;
-		z = devm_thermal_zone_of_sensor_register(dev,
-							 sensor->info.sensor_id,
-							 zone,
-							 &scpi_sensor_ops);
+		zone->z = devm_thermal_zone_of_sensor_register(dev,
+							       sensor->info.sensor_id,
+							       zone,
+							       &scpi_sensor_ops);
 		/*
 		 * The call to thermal_zone_of_sensor_register returns
 		 * an error for sensors that are not associated with
 		 * any thermal zones or if the thermal subsystem is
 		 * not configured.
 		 */
-		if (IS_ERR(z)) {
+		if (IS_ERR(zone->z)) {
 			devm_kfree(dev, zone);
 			continue;
 		}
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-03-01 20:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-01 13:20 [PATCH] hwmon: (scpi) Add slope and offset to SCP sensor readings Carlo Caione
2017-03-01 15:01 ` Guenter Roeck
2017-03-01 16:16   ` Carlo Caione
2017-03-01 16:57     ` Punit Agrawal
2017-03-01 17:09       ` Carlo Caione
2017-03-01 17:56       ` Guenter Roeck
2017-03-01 18:45         ` Carlo Caione
2017-03-01 20:04           ` Guenter Roeck
2017-03-01 17:46     ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).