mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Henrik Rydberg" <rydberg@euromail.se>
To: Guenter Roeck <guenter.roeck@ericsson.com>
Cc: Jean Delvare <khali@linux-fr.org>,
	lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org,
	Henrik Rydberg <rydberg@euromail.se>
Subject: [PATCH 1/2] hwmon: (applesmc) Allow negative temperature values
Date: Mon, 16 Jul 2012 09:18:10 +0200	[thread overview]
Message-ID: <1342423091-330-1-git-send-email-rydberg@euromail.se> (raw)

There are many userland reports of sensors with unreasonably small and
large temperatures. There seem to be several reasons for this:

Firstly, the major sensor type (sp78) is actually a signed number.
This explains why some sensors show very small or large values - they
are in fact all small, but of different sign.

Secondly, the other sensor type (1-hex) is not properly understood; it
may be that it is not a temperature after all.

Thirdly, some sensors are differential in nature, showing changes over
time rather than absolute numbers.  This explains why those values are
small and of varying sign.

This patch interprets the sp78 type as signed short, but keeps the
original scaling. For other types, -EINVAL is returned, since the
nature of those sensors is unknown.

Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
---
 drivers/hwmon/applesmc.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index f41585e..75f87f1 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -80,6 +80,8 @@
 #define FANS_MANUAL		"FS! " /* r-w ui16 */
 #define FAN_ID_FMT		"F%dID" /* r-o char[16] */
 
+#define TEMP_SENSOR_TYPE	"sp78"
+
 /* List of keys used to read/write fan speeds */
 static const char *const fan_speed_fmt[] = {
 	"F%dAc",		/* actual speed */
@@ -720,27 +722,22 @@ static ssize_t applesmc_show_temperature(struct device *dev,
 	int index = smcreg.temp_begin + to_index(devattr);
 	const struct applesmc_entry *entry;
 	int ret;
-	u8 buffer[2];
-	unsigned int temp;
+	s16 value;
+	int temp;
 
 	entry = applesmc_get_entry_by_index(index);
 	if (IS_ERR(entry))
 		return PTR_ERR(entry);
-	if (entry->len > 2)
+	if (strcmp(entry->type, TEMP_SENSOR_TYPE))
 		return -EINVAL;
 
-	ret = applesmc_read_entry(entry, buffer, entry->len);
+	ret = applesmc_read_s16(entry->key, &value);
 	if (ret)
 		return ret;
 
-	if (entry->len == 2) {
-		temp = buffer[0] * 1000;
-		temp += (buffer[1] >> 6) * 250;
-	} else {
-		temp = buffer[0] * 4000;
-	}
+	temp = 250 * (value >> 6);
 
-	return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", temp);
+	return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", temp);
 }
 
 static ssize_t applesmc_show_fan_speed(struct device *dev,
-- 
1.7.11.2


             reply	other threads:[~2012-07-16  7:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-16  7:18 Henrik Rydberg [this message]
2012-07-16  7:18 ` [PATCH 2/2] hwmon: (applesmc) Ignore some temperature registers Henrik Rydberg
2012-07-17  1:11   ` [lm-sensors] " Guenter Roeck
2012-07-17  1:10 ` [lm-sensors] [PATCH 1/2] hwmon: (applesmc) Allow negative temperature values 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=1342423091-330-1-git-send-email-rydberg@euromail.se \
    --to=rydberg@euromail.se \
    --cc=guenter.roeck@ericsson.com \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®