diff --git a/TODO b/TODO index d838242e..2302dfa4 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,9 @@ Many, many things. Most notably: +* Check whether the FAN count divisors in the lm78 module are correct + (probably not!) +* Wouldn't it be better to display all natural voltages for the LM78 chip, + and do *all* conversions through a user program? * kmalloc with GFP_KERNEL can cause a context switch! Check whether this is safe everywhere it is used. * Support 10-bit addresses. At this moment, they are supported nowhere, except diff --git a/kernel/chips/lm75.c b/kernel/chips/lm75.c index c8b03e67..71d68495 100644 --- a/kernel/chips/lm75.c +++ b/kernel/chips/lm75.c @@ -37,8 +37,8 @@ #define TEMP_TO_REG(val) (((((val) + 2) / 5) << 7) & 0xff80) /* Initial values */ -#define LM75_INIT_TEMP_OS 60 -#define LM75_INIT_TEMP_HYST 50 +#define LM75_INIT_TEMP_OS 600 +#define LM75_INIT_TEMP_HYST 500 /* Each client has this additional data */ struct lm75_data { @@ -170,8 +170,10 @@ int lm75_attach_adapter(struct i2c_adapter *adapter) err = 0; /* Initialize the LM75 chip */ - lm75_write_value(new_client,LM75_REG_TEMP_OS,LM75_INIT_TEMP_OS); - lm75_write_value(new_client,LM75_REG_TEMP_HYST,LM75_INIT_TEMP_HYST); + lm75_write_value(new_client,LM75_REG_TEMP_OS, + TEMP_TO_REG(LM75_INIT_TEMP_OS)); + lm75_write_value(new_client,LM75_REG_TEMP_HYST, + TEMP_TO_REG(LM75_INIT_TEMP_HYST)); lm75_write_value(new_client,LM75_REG_CONF,0); continue; diff --git a/kernel/chips/lm78.c b/kernel/chips/lm78.c index e20db28b..2c3036ba 100644 --- a/kernel/chips/lm78.c +++ b/kernel/chips/lm78.c @@ -63,18 +63,17 @@ #define LM78_REG_CHIPID 0x49 -/* Conversions */ +/* Conversions. Rounding is only done on the TO_REG variants. */ static int lm78_in_conv[7] = {10000, 10000, 10000, 16892, 38000, -34768, -15050 }; #define IN_TO_REG(val,nr) (((((val) * 100000 / lm78_in_conv[nr]) + 8) / 16) \ & 0xff) #define IN_FROM_REG(val,nr) (((val) * 16 * lm78_in_conv[nr]) / 100000) -#define FAN_TO_REG(val) ((((val)==0)?255:((1350000+(val))/((val)*2))) & 0xff) -#define FAN_FROM_REG(val) (((val)==0)?-1:\ - ((val)==255)?0:(1350000 + (val))/((val)*2)) +#define FAN_TO_REG(val) ((val)==0?255:((1350000+(val))/((val)*2)) & 0xff) +#define FAN_FROM_REG(val) ((val)==0?-1:(val)==255?0:1350000/((val)*2)) -#define TEMP_TO_REG(val) (((val)<0?(val/10)&0xff:(val/10)) & 0xff) +#define TEMP_TO_REG(val) (((val)<0?(((val)-5)/10)&0xff:((val)+5)/10) & 0xff) #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*10) #define VID_FROM_REG(val) ((val)==0x1f?0:(val)>=0x10?510-(val)*10:\ diff --git a/src/lm75.c b/src/lm75.c index c8b03e67..71d68495 100644 --- a/src/lm75.c +++ b/src/lm75.c @@ -37,8 +37,8 @@ #define TEMP_TO_REG(val) (((((val) + 2) / 5) << 7) & 0xff80) /* Initial values */ -#define LM75_INIT_TEMP_OS 60 -#define LM75_INIT_TEMP_HYST 50 +#define LM75_INIT_TEMP_OS 600 +#define LM75_INIT_TEMP_HYST 500 /* Each client has this additional data */ struct lm75_data { @@ -170,8 +170,10 @@ int lm75_attach_adapter(struct i2c_adapter *adapter) err = 0; /* Initialize the LM75 chip */ - lm75_write_value(new_client,LM75_REG_TEMP_OS,LM75_INIT_TEMP_OS); - lm75_write_value(new_client,LM75_REG_TEMP_HYST,LM75_INIT_TEMP_HYST); + lm75_write_value(new_client,LM75_REG_TEMP_OS, + TEMP_TO_REG(LM75_INIT_TEMP_OS)); + lm75_write_value(new_client,LM75_REG_TEMP_HYST, + TEMP_TO_REG(LM75_INIT_TEMP_HYST)); lm75_write_value(new_client,LM75_REG_CONF,0); continue; diff --git a/src/lm78.c b/src/lm78.c index e20db28b..2c3036ba 100644 --- a/src/lm78.c +++ b/src/lm78.c @@ -63,18 +63,17 @@ #define LM78_REG_CHIPID 0x49 -/* Conversions */ +/* Conversions. Rounding is only done on the TO_REG variants. */ static int lm78_in_conv[7] = {10000, 10000, 10000, 16892, 38000, -34768, -15050 }; #define IN_TO_REG(val,nr) (((((val) * 100000 / lm78_in_conv[nr]) + 8) / 16) \ & 0xff) #define IN_FROM_REG(val,nr) (((val) * 16 * lm78_in_conv[nr]) / 100000) -#define FAN_TO_REG(val) ((((val)==0)?255:((1350000+(val))/((val)*2))) & 0xff) -#define FAN_FROM_REG(val) (((val)==0)?-1:\ - ((val)==255)?0:(1350000 + (val))/((val)*2)) +#define FAN_TO_REG(val) ((val)==0?255:((1350000+(val))/((val)*2)) & 0xff) +#define FAN_FROM_REG(val) ((val)==0?-1:(val)==255?0:1350000/((val)*2)) -#define TEMP_TO_REG(val) (((val)<0?(val/10)&0xff:(val/10)) & 0xff) +#define TEMP_TO_REG(val) (((val)<0?(((val)-5)/10)&0xff:((val)+5)/10) & 0xff) #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*10) #define VID_FROM_REG(val) ((val)==0x1f?0:(val)>=0x10?510-(val)*10:\