mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-31 06:15:15 +00:00
fixed off-by-factor-of-2 of FAN_FROM_REG in w83781d.
Improved bounds checking for FAN_TO_REG in all files. For lm78-compatible drivers, minimum speed is 2657 RPM when the divisor is 2. Attempts to set lower than that now are set to 0. Before was set to a random number. Thanks Jeff Dairiki. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@330 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
@@ -116,8 +116,19 @@
|
||||
#define IN_TO_REG(val,nr) ((val) & 0xff)
|
||||
#define IN_FROM_REG(val,nr) (val)
|
||||
|
||||
#define FAN_TO_REG(val,div) ((val)==0?255:\
|
||||
((1350000+(val)*(div)/2)/((val)*(div))) & 0xff)
|
||||
static inline unsigned char
|
||||
FAN_TO_REG (unsigned rpm, unsigned divisor)
|
||||
{
|
||||
unsigned val;
|
||||
|
||||
if (rpm == 0)
|
||||
return 255;
|
||||
|
||||
val = (1350000 + rpm * divisor / 2) / (rpm * divisor);
|
||||
if (val > 255)
|
||||
val = 255;
|
||||
return val;
|
||||
}
|
||||
#define FAN_FROM_REG(val,div) ((val)==0?-1:\
|
||||
(val)==255?0:1350000/((div)*(val)))
|
||||
|
||||
|
@@ -63,8 +63,19 @@
|
||||
#define TEMP_TO_REG(val) (((((val)<0?(val)-5:(val)+5) / 10) + 119) & 0xff)
|
||||
#define TEMP_FROM_REG(val) (((val) - 119) * 10)
|
||||
|
||||
#define FAN_TO_REG(val,div) \
|
||||
(( (val)==0 ? 255 : ((960000+(val)*(div))/(2*(val)*(div))) ) & 0xff)
|
||||
static inline unsigned char
|
||||
FAN_TO_REG (unsigned rpm, unsigned divisor)
|
||||
{
|
||||
unsigned val;
|
||||
|
||||
if (rpm == 0)
|
||||
return 255;
|
||||
|
||||
val = (960000 + rpm * divisor) / (2 * rpm * divisor);
|
||||
if (val > 255)
|
||||
val = 255;
|
||||
return val;
|
||||
}
|
||||
#define FAN_FROM_REG(val,div) \
|
||||
( (val)==0 ? 0 : (val)==255 ? 0 : (960000/(2*(val)*(div))) )
|
||||
|
||||
|
@@ -76,8 +76,19 @@ SENSORS_INSMOD_3(lm78,lm78j,lm79);
|
||||
#define IN_TO_REG(val) (((val) * 10 + 8)/16)
|
||||
#define IN_FROM_REG(val) (((val) * 16) / 10)
|
||||
|
||||
#define FAN_TO_REG(val,div) ((val)==0?255:((1350000+(val)*(div)/2)/\
|
||||
((val)*(div))) & 0xff)
|
||||
static inline unsigned char
|
||||
FAN_TO_REG (unsigned rpm, unsigned divisor)
|
||||
{
|
||||
unsigned val;
|
||||
|
||||
if (rpm == 0)
|
||||
return 255;
|
||||
|
||||
val = (1350000 + rpm * divisor / 2) / (rpm * divisor);
|
||||
if (val > 255)
|
||||
val = 255;
|
||||
return val;
|
||||
}
|
||||
#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
|
||||
|
||||
#define TEMP_TO_REG(val) (((val)<0?(((val)-5)/10)&0xff:((val)+5)/10) & 0xff)
|
||||
|
@@ -65,8 +65,19 @@
|
||||
#define IN_TO_REG(val,nr) ((val) & 0xff)
|
||||
#define IN_FROM_REG(val,nr) (val)
|
||||
|
||||
#define FAN_TO_REG(val,div) ((val)==0?255:\
|
||||
((1350000+(val)*(div)/2)/((val)*(div))) & 0xff)
|
||||
static inline unsigned char
|
||||
FAN_TO_REG (unsigned rpm, unsigned divisor)
|
||||
{
|
||||
unsigned val;
|
||||
|
||||
if (rpm == 0)
|
||||
return 255;
|
||||
|
||||
val = (1350000 + rpm * divisor / 2) / (rpm * divisor);
|
||||
if (val > 255)
|
||||
val = 255;
|
||||
return val;
|
||||
}
|
||||
#define FAN_FROM_REG(val,div) ((val)==0?-1:\
|
||||
(val)==255?0:1350000/((div)*(val)))
|
||||
|
||||
|
@@ -85,7 +85,19 @@ static const char *version = "1.00 25/2/99 Fons Rademakers";
|
||||
/* 19531 / val * 60 == 1171860 / val */
|
||||
#define FAN_FROM_REG(val) ((val)==0xfe ? -1 : (val)==0xff ? 0 : \
|
||||
(1171860 / (val)))
|
||||
#define FAN_TO_REG(val) (1171860 / (val))
|
||||
static inline unsigned char
|
||||
FAN_TO_REG (unsigned rpm)
|
||||
{
|
||||
unsigned val;
|
||||
|
||||
if (rpm == 0)
|
||||
return 255;
|
||||
|
||||
val = 1171860 / rpm;
|
||||
if (val > 255)
|
||||
val = 255;
|
||||
return val;
|
||||
}
|
||||
|
||||
#define TEMP_FROM_REG(val) ((val) * 5)
|
||||
#define TEMP_TO_REG(val) ((val) / 5)
|
||||
|
@@ -79,8 +79,19 @@
|
||||
#define IN_TO_REG(val) (((val) * 10 + 8)/16)
|
||||
#define IN_FROM_REG(val) (((val) * 16) / 10)
|
||||
|
||||
#define FAN_TO_REG(val,div) ((val)==0?255:((1350000+(val)*(div)/2)/\
|
||||
((val)*(div))) & 0xff)
|
||||
static inline unsigned char
|
||||
FAN_TO_REG (unsigned rpm, unsigned divisor)
|
||||
{
|
||||
unsigned val;
|
||||
|
||||
if (rpm == 0)
|
||||
return 255;
|
||||
|
||||
val = (1350000 + rpm * divisor / 2) / (rpm * divisor);
|
||||
if (val > 255)
|
||||
val = 255;
|
||||
return val;
|
||||
}
|
||||
#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
|
||||
|
||||
#define TEMP_TO_REG(val) (((val)<0?(((val)-5)/10)&0xff:((val)+5)/10) & 0xff)
|
||||
|
@@ -114,9 +114,20 @@ const u8 regpwm[] = {W83781D_REG_PWM1, W83781D_REG_PWM2, W83781D_REG_PWM3, W8378
|
||||
#define IN_TO_REG(val,nr) (((val) * 10 + 8)/16)
|
||||
#define IN_FROM_REG(val,nr) (((val) * 16) / 10)
|
||||
|
||||
#define FAN_TO_REG(val,div) ((val)==0?255:((1350000+(val)*(div)/2)/\
|
||||
((val)*(div))) & 0xff)
|
||||
#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*2*(div)))
|
||||
static inline unsigned char
|
||||
FAN_TO_REG (unsigned rpm, unsigned divisor)
|
||||
{
|
||||
unsigned val;
|
||||
|
||||
if (rpm == 0)
|
||||
return 255;
|
||||
|
||||
val = (1350000 + rpm * divisor / 2) / (rpm * divisor);
|
||||
if (val > 255)
|
||||
val = 255;
|
||||
return val;
|
||||
}
|
||||
#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
|
||||
|
||||
#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)
|
||||
|
Reference in New Issue
Block a user