* [PATCHv2] hwmon: adm9240: handle temperature readings below 0
@ 2016-10-04 21:40 Chris Packham
2016-10-04 22:16 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Chris Packham @ 2016-10-04 21:40 UTC (permalink / raw)
To: jdelvare, linux, linux-hwmon, linux-kernel; +Cc: Michael.Wang, Chris Packham
Unlike the temperature thresholds the temperature data is a 9-bit signed
value. This allows and additional 0.5 degrees of precision on the
reading but makes handling negative values slightly harder. In order to
have sign-extension applied correctly the 9-bit value is stored in the
upper bits of a signed 16-bit value. When presenting this in sysfs the
value is shifted and scaled appropriately.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- Simplify as per feedback from Guenter.
- Re-word commit message.
drivers/hwmon/adm9240.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 98114ce..8d8ede8 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -197,7 +197,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
data->temp = ((i2c_smbus_read_byte_data(client,
ADM9240_REG_TEMP) << 8) |
i2c_smbus_read_byte_data(client,
- ADM9240_REG_TEMP_CONF)) / 128;
+ ADM9240_REG_TEMP_CONF));
for (i = 0; i < 2; i++) { /* read fans */
data->fan[i] = i2c_smbus_read_byte_data(client,
@@ -263,7 +263,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *dummy,
char *buf)
{
struct adm9240_data *data = adm9240_update_device(dev);
- return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */
+ return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */
}
static ssize_t show_max(struct device *dev, struct device_attribute *devattr,
--
2.10.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCHv2] hwmon: adm9240: handle temperature readings below 0
2016-10-04 21:40 [PATCHv2] hwmon: adm9240: handle temperature readings below 0 Chris Packham
@ 2016-10-04 22:16 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2016-10-04 22:16 UTC (permalink / raw)
To: Chris Packham; +Cc: jdelvare, linux-hwmon, linux-kernel, Michael.Wang
On Wed, Oct 05, 2016 at 10:40:54AM +1300, Chris Packham wrote:
> Unlike the temperature thresholds the temperature data is a 9-bit signed
> value. This allows and additional 0.5 degrees of precision on the
> reading but makes handling negative values slightly harder. In order to
> have sign-extension applied correctly the 9-bit value is stored in the
> upper bits of a signed 16-bit value. When presenting this in sysfs the
> value is shifted and scaled appropriately.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Applied (after removing the extra () in the data->temp assignment).
Thanks,
Guenter
> ---
> Changes in v2:
> - Simplify as per feedback from Guenter.
> - Re-word commit message.
>
> drivers/hwmon/adm9240.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
> index 98114ce..8d8ede8 100644
> --- a/drivers/hwmon/adm9240.c
> +++ b/drivers/hwmon/adm9240.c
> @@ -197,7 +197,7 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
> data->temp = ((i2c_smbus_read_byte_data(client,
> ADM9240_REG_TEMP) << 8) |
> i2c_smbus_read_byte_data(client,
> - ADM9240_REG_TEMP_CONF)) / 128;
> + ADM9240_REG_TEMP_CONF));
>
> for (i = 0; i < 2; i++) { /* read fans */
> data->fan[i] = i2c_smbus_read_byte_data(client,
> @@ -263,7 +263,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *dummy,
> char *buf)
> {
> struct adm9240_data *data = adm9240_update_device(dev);
> - return sprintf(buf, "%d\n", data->temp * 500); /* 9-bit value */
> + return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */
> }
>
> static ssize_t show_max(struct device *dev, struct device_attribute *devattr,
> --
> 2.10.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-04 22:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-04 21:40 [PATCHv2] hwmon: adm9240: handle temperature readings below 0 Chris Packham
2016-10-04 22:16 ` 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).