upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / drivers / i2c / chips / lm90.c
index c3dd521..0d2bf23 100644 (file)
@@ -76,9 +76,7 @@
  */
 
 static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END };
-static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
 static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
-static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END };
 
 /*
  * Insmod parameters
@@ -127,19 +125,24 @@ 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). Note that TEMP2_TO_REG does not round values, but
- * stick to the nearest lower value instead. Fixing it is just
- * not worth it.
+ * 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) * 1000)
-#define TEMP1_TO_REG(val)      ((val < 0 ? val+0x100*1000 : val) / 1000)
-#define TEMP2_FROM_REG(val)    (((val & 0x8000 ? val-0x10000 : val) >> 5) * 125)
-#define TEMP2_TO_REG(val)      ((((val / 125) << 5) + (val < 0 ? 0x10000 : 0)) & 0xFFE0)
-#define HYST_FROM_REG(val)     (val * 1000)
-#define HYST_TO_REG(val)       (val <= 0 ? 0 : val >= 31000 ? 31 : val / 1000)
+#define TEMP1_FROM_REG(val)    ((val) * 1000)
+#define TEMP1_TO_REG(val)      ((val) <= -128000 ? -128 : \
+                                (val) >= 127000 ? 127 : \
+                                (val) < 0 ? ((val) - 500) / 1000 : \
+                                ((val) + 500) / 1000)
+#define TEMP2_FROM_REG(val)    ((val) / 32 * 125)
+#define TEMP2_TO_REG(val)      ((val) <= -128000 ? 0x8000 : \
+                                (val) >= 127875 ? 0x7FE0 : \
+                                (val) < 0 ? ((val) - 62) / 125 * 32 : \
+                                ((val) + 62) / 125 * 32)
+#define HYST_TO_REG(val)       ((val) <= 0 ? 0 : (val) >= 30500 ? 31 : \
+                                ((val) + 500) / 1000)
 
 /*
  * Functions declaration
@@ -176,18 +179,18 @@ struct lm90_data {
        unsigned long last_updated; /* in jiffies */
 
        /* registers values */
-       u8 temp_input1, temp_low1, temp_high1; /* local */
-       u16 temp_input2, temp_low2, temp_high2; /* remote, combined */
-       u8 temp_crit1, temp_crit2;
+       s8 temp_input1, temp_low1, temp_high1; /* local */
+       s16 temp_input2, temp_low2, temp_high2; /* remote, combined */
+       s8 temp_crit1, temp_crit2;
        u8 temp_hyst;
-       u16 alarms; /* bitvector, combined */
+       u8 alarms; /* bitvector */
 };
 
 /*
  * Internal variables
  */
 
-static int lm90_id = 0;
+static int lm90_id;
 
 /*
  * Sysfs stuff
@@ -214,7 +217,8 @@ static ssize_t set_##value(struct device *dev, const char *buf, \
 { \
        struct i2c_client *client = to_i2c_client(dev); \
        struct lm90_data *data = i2c_get_clientdata(client); \
-       data->value = TEMP1_TO_REG(simple_strtol(buf, NULL, 10)); \
+       long val = simple_strtol(buf, NULL, 10); \
+       data->value = TEMP1_TO_REG(val); \
        i2c_smbus_write_byte_data(client, reg, data->value); \
        return count; \
 }
@@ -224,7 +228,8 @@ static ssize_t set_##value(struct device *dev, const char *buf, \
 { \
        struct i2c_client *client = to_i2c_client(dev); \
        struct lm90_data *data = i2c_get_clientdata(client); \
-       data->value = TEMP2_TO_REG(simple_strtol(buf, NULL, 10)); \
+       long val = simple_strtol(buf, NULL, 10); \
+       data->value = TEMP2_TO_REG(val); \
        i2c_smbus_write_byte_data(client, regh, data->value >> 8); \
        i2c_smbus_write_byte_data(client, regl, data->value & 0xff); \
        return count; \
@@ -241,7 +246,7 @@ static ssize_t show_##value(struct device *dev, char *buf) \
 { \
        struct lm90_data *data = lm90_update_device(dev); \
        return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->basereg) \
-                      - HYST_FROM_REG(data->temp_hyst)); \
+                      - TEMP1_FROM_REG(data->temp_hyst)); \
 }
 show_temp_hyst(temp_hyst1, temp_crit1);
 show_temp_hyst(temp_hyst2, temp_crit2);