aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2012-07-16 03:18:10 -0400
committerGuenter Roeck <linux@roeck-us.net>2012-07-22 00:48:45 -0400
commitb6e5122f09272cb30c2e1fc1d80a40bfa6e87757 (patch)
treee166c109e4d9da60aa1f6590c302042fff716729
parent41bf870e6db130c6e467c70b6da96398066b8be7 (diff)
hwmon: (applesmc) Allow negative temperature values
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> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/applesmc.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index f41585ecbe2b..75f87f125dac 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -80,6 +80,8 @@
80#define FANS_MANUAL "FS! " /* r-w ui16 */ 80#define FANS_MANUAL "FS! " /* r-w ui16 */
81#define FAN_ID_FMT "F%dID" /* r-o char[16] */ 81#define FAN_ID_FMT "F%dID" /* r-o char[16] */
82 82
83#define TEMP_SENSOR_TYPE "sp78"
84
83/* List of keys used to read/write fan speeds */ 85/* List of keys used to read/write fan speeds */
84static const char *const fan_speed_fmt[] = { 86static const char *const fan_speed_fmt[] = {
85 "F%dAc", /* actual speed */ 87 "F%dAc", /* actual speed */
@@ -720,27 +722,22 @@ static ssize_t applesmc_show_temperature(struct device *dev,
720 int index = smcreg.temp_begin + to_index(devattr); 722 int index = smcreg.temp_begin + to_index(devattr);
721 const struct applesmc_entry *entry; 723 const struct applesmc_entry *entry;
722 int ret; 724 int ret;
723 u8 buffer[2]; 725 s16 value;
724 unsigned int temp; 726 int temp;
725 727
726 entry = applesmc_get_entry_by_index(index); 728 entry = applesmc_get_entry_by_index(index);
727 if (IS_ERR(entry)) 729 if (IS_ERR(entry))
728 return PTR_ERR(entry); 730 return PTR_ERR(entry);
729 if (entry->len > 2) 731 if (strcmp(entry->type, TEMP_SENSOR_TYPE))
730 return -EINVAL; 732 return -EINVAL;
731 733
732 ret = applesmc_read_entry(entry, buffer, entry->len); 734 ret = applesmc_read_s16(entry->key, &value);
733 if (ret) 735 if (ret)
734 return ret; 736 return ret;
735 737
736 if (entry->len == 2) { 738 temp = 250 * (value >> 6);
737 temp = buffer[0] * 1000;
738 temp += (buffer[1] >> 6) * 250;
739 } else {
740 temp = buffer[0] * 4000;
741 }
742 739
743 return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", temp); 740 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", temp);
744} 741}
745 742
746static ssize_t applesmc_show_fan_speed(struct device *dev, 743static ssize_t applesmc_show_fan_speed(struct device *dev,