From a8379104e0ca5848fb118255e15945586a489ec6 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Mon, 11 Oct 2004 20:36:45 +0000 Subject: [PATCH] Use signed types for temperatures. Check limits on register writes. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2724 7894878c-1315-0410-8ee3-d5d059ff63e0 --- kernel/chips/lm83.c | 12 +++++------- kernel/chips/lm90.c | 30 ++++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/kernel/chips/lm83.c b/kernel/chips/lm83.c index 7bad81ee..9905fa23 100644 --- a/kernel/chips/lm83.c +++ b/kernel/chips/lm83.c @@ -80,14 +80,12 @@ SENSORS_INSMOD_1(lm83); /* * Conversions and various macros - * The LM83 uses signed 8-bit values. + * The LM83 uses signed 8-bit values with LSB = 1 degree Celcius. */ -#define TEMP_FROM_REG(val) ((val) > 127 ? (val) - 0x100 : (val)) -#define TEMP_TO_REG(val) ((val) <= -50 ? -50 + 0x100 : \ - (val) >= 127 ? 127 : \ - (val) >= 0 ? (val) : \ - (val) + 0x100) +#define TEMP_FROM_REG(val) (val) +#define TEMP_TO_REG(val) ((val) <= -50 ? -50 : \ + (val) >= 127 ? 127 : (val)) static const u8 LM83_REG_R_TEMP[] = { LM83_REG_R_LOCAL_TEMP, @@ -153,7 +151,7 @@ struct lm83_data unsigned long last_updated; /* in jiffies */ /* registers values */ - u8 temp[4], temp_high[4], tcrit; + s8 temp[4], temp_high[4], tcrit; u16 alarms; /* bitvector, combined */ }; diff --git a/kernel/chips/lm90.c b/kernel/chips/lm90.c index cb079f91..e4176dbd 100644 --- a/kernel/chips/lm90.c +++ b/kernel/chips/lm90.c @@ -131,19 +131,21 @@ SENSORS_INSMOD_5(lm90, adm1032, lm99, lm86, max6657); /* * Conversions and various macros - * The LM90 uses signed 8-bit values for the local temperatures, - * and signed 11-bit values for the remote temperatures (except - * T_CRIT). The 11-bit conversion formulas may not round negative - * numbers perfectly, but who cares? + * For local temperatures and limits, critical limits and the hysteresis + * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celcius. + * For remote temperatures and limits, it uses signed 11-bit values with + * LSB = 0.125 degree Celcius, left-justified in 16-bit registers. */ -#define TEMP1_FROM_REG(val) (val & 0x80 ? val-0x100 : val) -#define TEMP1_TO_REG(val) (val < 0 ? val+0x100 : val) -#define TEMP2_FROM_REG(val) (((val & 0x8000 ? val-0x10000 : val) \ - * 10 + 128) >> 8) -#define TEMP2_TO_REG(val) (((val << 8) / 10 + (val < 0 ? \ - 0x10000 : 0)) & 0xFFE0) -#define HYST_TO_REG(val) (val < 0 ? 0 : val > 31 ? 31 : val) +#define TEMP1_FROM_REG(val) (val) +#define TEMP1_TO_REG(val) ((val) <= -128 ? -128 : \ + (val) >= 127 ? 127 : (val)) +#define TEMP2_FROM_REG(val) ((val) / 32 * 125 / 100) +#define TEMP2_TO_REG(val) ((val) <= -1280 ? 0x8000 : \ + (val) >= 1270 ? 0x7FE0 : \ + ((val) * 100 / 125 * 32)) +#define HYST_TO_REG(val) ((val) <= 0 ? 0 : \ + (val) >= 31 ? 31 : (val)) /* * Functions declaration @@ -196,9 +198,9 @@ struct lm90_data unsigned long last_updated; /* in jiffies */ /* registers values */ - u8 local_temp, local_high, local_low; - u16 remote_temp, remote_high, remote_low; /* combined */ - u8 local_crit, remote_crit; + s8 local_temp, local_high, local_low; + s16 remote_temp, remote_high, remote_low; /* combined */ + s8 local_crit, remote_crit; u8 hyst; /* linked to two sysctl files (hyst1 RW, hyst2 RO) */ u8 alarms; /* bitvector */ };