All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlo Caione <carlo@caione.org>
To: jdelvare@suse.com, linux@roeck-us.net,
	linux-hwmon@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org, linux@endlessm.com,
	punit.agrawal@arm.com, sudeep.holla@arm.com
Cc: Carlo Caione <carlo@endlessm.com>
Subject: [PATCH] hwmon: (scpi) Add slope and offset to SCP sensor readings
Date: Wed,  1 Mar 2017 14:20:28 +0100	[thread overview]
Message-ID: <20170301132028.25309-1-carlo@caione.org> (raw)

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

WARNING: multiple messages have this Message-ID (diff)
From: carlo@caione.org (Carlo Caione)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] hwmon: (scpi) Add slope and offset to SCP sensor readings
Date: Wed,  1 Mar 2017 14:20:28 +0100	[thread overview]
Message-ID: <20170301132028.25309-1-carlo@caione.org> (raw)

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

WARNING: multiple messages have this Message-ID (diff)
From: carlo@caione.org (Carlo Caione)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH] hwmon: (scpi) Add slope and offset to SCP sensor readings
Date: Wed,  1 Mar 2017 14:20:28 +0100	[thread overview]
Message-ID: <20170301132028.25309-1-carlo@caione.org> (raw)

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

             reply	other threads:[~2017-03-01 13:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-01 13:20 Carlo Caione [this message]
2017-03-01 13:20 ` [PATCH] hwmon: (scpi) Add slope and offset to SCP sensor readings Carlo Caione
2017-03-01 13:20 ` Carlo Caione
2017-03-01 15:01 ` Guenter Roeck
2017-03-01 15:01   ` Guenter Roeck
2017-03-01 15:01   ` Guenter Roeck
2017-03-01 16:16   ` Carlo Caione
2017-03-01 16:16     ` Carlo Caione
2017-03-01 16:16     ` Carlo Caione
2017-03-01 16:57     ` Punit Agrawal
2017-03-01 16:57       ` Punit Agrawal
2017-03-01 16:57       ` Punit Agrawal
2017-03-01 17:09       ` Carlo Caione
2017-03-01 17:09         ` Carlo Caione
2017-03-01 17:09         ` Carlo Caione
2017-03-01 17:56       ` Guenter Roeck
2017-03-01 17:56         ` Guenter Roeck
2017-03-01 17:56         ` Guenter Roeck
2017-03-01 18:45         ` Carlo Caione
2017-03-01 18:45           ` Carlo Caione
2017-03-01 18:45           ` Carlo Caione
2017-03-01 20:04           ` Guenter Roeck
2017-03-01 20:04             ` Guenter Roeck
2017-03-01 20:04             ` Guenter Roeck
2017-03-01 17:46     ` Guenter Roeck
2017-03-01 17:46       ` Guenter Roeck
2017-03-01 17:46       ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170301132028.25309-1-carlo@caione.org \
    --to=carlo@caione.org \
    --cc=carlo@endlessm.com \
    --cc=jdelvare@suse.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@endlessm.com \
    --cc=linux@roeck-us.net \
    --cc=punit.agrawal@arm.com \
    --cc=sudeep.holla@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.