several bmcsensors fixes:

- fix voltage scaling
	- swap voltage limits
	- use lower critical rather than upper hysteresis
	  for non-temperature sensors
	- increase libsensors support to 20 voltage, 10 fan,
	  10 temperature sensors
	Tickets 1406 and 1407.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@2017 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Mark D. Studebaker committed 2003-10-13 03:01:45 +00:00
1 parent 337ff4d2a9
commit f38dc972e0
3 files changed
+282 -123

No files matched your search

+94 -80
View File
@@ -63,23 +63,22 @@ static int bmcsensors_command(struct i2c_client *client, unsigned int cmd,
void *arg);
static void bmcsensors_update_client(struct i2c_client *client);
static int bmcsensors_find(int *address);
static void bmcsensors_reserve_sdr(void);
static void bmcsensors_all(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results);
#if 0
static void bmcsensors_alarms(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results);
static void bmcsensors_fan_div(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results);
static void bmcsensors_pwm(struct i2c_client *client, int operation,
int ctl_name, int *nrels_mag, long *results);
#endif
static void bmcsensors_get_sdr(u16 resid, u16 record, u8 offset);
static void bmcsensors_get_reading(struct i2c_client *client, int i);
static int bmcsensors_id = 0;
static struct i2c_driver bmcsensors_driver = {
.owner = THIS_MODULE,
.name = "BMC Sensors driver",
@@ -102,7 +101,7 @@ struct i2c_client bmc_client = {
0
};
static bmcsensors_initialized;
static int bmcsensors_initialized;
#define MAX_SDR_ENTRIES 50
#define SDR_LIMITS 8
@@ -123,7 +122,7 @@ struct sdrdata {
u8 k;
u8 nominal;
u8 limits[SDR_LIMITS];
int lim1, lim2;
int lim1, lim2; /* index into limits for reported upper and lower limit */
u8 lim1_write, lim2_write;
u8 string_type;
u8 id_length;
@@ -238,69 +237,71 @@ static const char * threshold_text[] = {
/* select two out of the 8 possible readable thresholds, and place indexes into the limits
array into lim1 and lim2. Set writable flags */
static void bmcsensors_select_thresholds(int i)
static void bmcsensors_select_thresholds(struct sdrdata * sd)
{
u8 capab = sdrd[i].capab;
u16 mask = sdrd[i].thresh_mask;
u8 capab = sd->capab;
u16 mask = sd->thresh_mask;
sdrd[i].lim1 = -1;
sdrd[i].lim2 = -1;
sdrd[i].lim1_write = 0;
sdrd[i].lim2_write = 0;
sd->lim1 = -1;
sd->lim2 = -1;
sd->lim1_write = 0;
sd->lim2_write = 0;
if(((capab & 0x0c) == 0x04) || /* readable thresholds ? */
((capab & 0x0c) == 0x08)) {
/* select upper threshold */
if(mask & 0x10) { /* upper crit */
sdrd[i].lim1 = 1;
sd->lim1 = 1;
if((capab & 0x0c) == 0x08 && (mask & 0x1000))
sdrd[i].lim1_write = 1;
sd->lim1_write = 1;
}
else if(mask & 0x20) { /* upper non-recov */
sdrd[i].lim1 = 0;
sd->lim1 = 0;
if((capab & 0x0c) == 0x08 && (mask & 0x2000))
sdrd[i].lim1_write = 1;
sd->lim1_write = 1;
}
else if(mask & 0x08) { /* upper non-crit */
sdrd[i].lim1 = 2;
sd->lim1 = 2;
if((capab & 0x0c) == 0x08 && (mask & 0x0800))
sdrd[i].lim1_write = 1;
sd->lim1_write = 1;
}
/* select lower threshold */
if(((capab & 0x30) == 0x10) || /* readable hysteresis ? */
((capab & 0x30) == 0x20)) /* pos hyst */
sdrd[i].lim2 = 6;
if((((capab & 0x30) == 0x10) || /* readable ? */
((capab & 0x30) == 0x20)) && /* pos hyst */
sd->stype == STYPE_TEMP)
sd->lim2 = 6;
else if(mask & 0x02) { /* lower crit */
sdrd[i].lim2 = 4;
sd->lim2 = 4;
if((capab & 0x0c) == 0x08 && (mask & 0x0200))
sdrd[i].lim2_write = 1;
sd->lim2_write = 1;
}
else if(mask & 0x04) { /* lower non-recov */
sdrd[i].lim2 = 3;
sd->lim2 = 3;
if((capab & 0x0c) == 0x08 && (mask & 0x0400))
sdrd[i].lim2_write = 1;
sd->lim2_write = 1;
}
else if(mask & 0x01) { /* lower non-crit */
sdrd[i].lim2 = 5;
sd->lim2 = 5;
if((capab & 0x0c) == 0x08 && (mask & 0x0100))
sdrd[i].lim2_write = 1;
sd->lim2_write = 1;
}
}
if(sdrd[i].lim1 >= 0)
printk(KERN_INFO "bmcsensors.o: sensor %d: using %s for upper limit\n",
i, threshold_text[sdrd[i].lim1]);
/* fixme swap lim1/lim2 if m < 0 */
if(sd->lim1 >= 0)
printk(KERN_INFO "bmcsensors.o: using %s for upper limit\n",
threshold_text[sd->lim1]);
#ifdef DEBUG
else
printk(KERN_INFO "bmcsensors.o: sensor %d: no readable upper limit\n", i);
printk(KERN_INFO "bmcsensors.o: no readable upper limit\n");
#endif
if(sdrd[i].lim2 >= 0)
printk(KERN_INFO "bmcsensors.o: sensor %d: using %s for lower limit\n",
i, threshold_text[sdrd[i].lim2]);
if(sd->lim2 >= 0)
printk(KERN_INFO "bmcsensors.o: using %s for lower limit\n",
threshold_text[sd->lim2]);
#ifdef DEBUG
else
printk(KERN_INFO "bmcsensors.o: sensor %d: no readable lower limit\n", i);
printk(KERN_INFO "bmcsensors.o: no readable lower limit\n");
#endif
}
@@ -368,7 +369,7 @@ static void bmcsensors_build_proc_table()
printk(KERN_INFO "bmcsensors.o: sensors.conf: label %s \"%s\"\n",
bmcsensors_dir_table[i].procname, id);
}
bmcsensors_select_thresholds(i);
bmcsensors_select_thresholds(sdrd + i);
if(sdrd[i].linear != 0) {
printk(KERN_INFO
"bmcsensors.o: sensor %d: nonlinear function 0x%.2x unsupported, expect bad results\n",
@@ -440,12 +441,11 @@ static int bmcsensors_rcv_reading_msg(struct ipmi_msg *msg)
static int bmcsensors_rcv_sdr_msg(struct ipmi_msg *msg, int state)
{
u16 record;
int type, length, owner, lun, number, entity, instance, init;
int stype, code;
int type;
int stype;
int id_length;
int i;
int rstate = STATE_SDR;
struct ipmi_msg txmsg;
unsigned char * data;
u8 id[SDR_MAX_UNPACKED_ID_LENGTH];
@@ -848,51 +848,55 @@ static void bmcsensors_update_client(struct i2c_client *client)
/************* /proc callback helper functions *********/
/* need better way to map from sysctl to sdrd record number */
static int find_sdrd(int sysctl)
static struct sdrdata * find_sdrd(int sysctl)
{
int i;
for(i = 0; i < sdrd_count; i++)
if(sdrd[i].sysctl == sysctl)
return i;
return -1;
return sdrd + i;
return NULL;
}
/* IPMI V1.5 Section 30 */
static const int exps[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
static int decplaces(int i)
/* Return 0 for fan, 2 for temp, 3 for voltage
We could make it variable based on the accuracy (= log10(m * 10**k2));
this would work for /proc output, however libsensors resolution
is statically set in lib/chips.c */
static int decplaces(struct sdrdata *sd)
{
u8 k2;
k2 = sdrd[i].k >> 4;
if(k2 < 8)
switch(sd->stype) {
case STYPE_TEMP:
return 2;
case STYPE_CURR:
case STYPE_VOLT:
return 3;
case STYPE_FAN:
default:
return 0;
else
return 16 - k2;
}
}
static long convert_value(u8 value, int i)
/* convert a raw value to a reading. IMPI V1.5 Section 30 */
static long conv_val(int value, struct sdrdata *sd)
{
u8 k1, k2;
long r;
/* fixme signed/unsigned */
r = value * sdrd[i].m;
k1 = sdrd[i].k & 0x0f;
k2 = sdrd[i].k >> 4;
r = value * sd->m;
k1 = sd->k & 0x0f;
k2 = sd->k >> 4;
if(k1 < 8)
r += sdrd[i].b * exps[k1];
r += sd->b * exps[k1];
else
r += sdrd[i].b / exps[16 - k1];
r += sd->b / exps[16 - k1];
r *= exps[decplaces(sd)];
if(k2 < 8)
r *= exps[k2];
/*
taken care of by nrels_mag
else
r /= exps[16 - k2];
*/
return r;
}
@@ -902,49 +906,59 @@ static long convert_value(u8 value, int i)
static void bmcsensors_all(struct i2c_client *client, int operation, int ctl_name,
int *nrels_mag, long *results)
{
int i;
struct sdrdata *sd;
/*
struct bmcsensors_data *data = client->data;
*/
if((i = find_sdrd(ctl_name)) < 0) {
if((sd = find_sdrd(ctl_name)) == NULL) {
*nrels_mag = 0;
return;
}
if (operation == SENSORS_PROC_REAL_INFO)
*nrels_mag = decplaces(i);
*nrels_mag = decplaces(sd);
else if (operation == SENSORS_PROC_REAL_READ) {
bmcsensors_update_client(client);
if(sdrd[i].stype == STYPE_FAN) { /* lower limit only */
if(sdrd[i].lim2 >= 0)
results[0] = convert_value(sdrd[i].limits[sdrd[i].lim2], i);
else
results[0] = 0;
results[1] = convert_value(sdrd[i].reading, i);
if(sd->lim2 >= 0) {
if(sd->stype == STYPE_TEMP) /* upper limit first */
results[0] =
conv_val(sd->limits[sd->lim1], sd);
else /* lower limit first */
results[0] =
conv_val(sd->limits[sd->lim2], sd);
} else
results[0] = 0;
if(sd->stype == STYPE_FAN) { /* lower limit only */
results[1] = conv_val(sd->reading, sd);
*nrels_mag = 2;
} else {
if(sdrd[i].lim1 >= 0)
results[0] = convert_value(sdrd[i].limits[sdrd[i].lim1], i);
else
results[0] = 0;
results[2] = convert_value(sdrd[i].reading, i);
if(sdrd[i].lim2 >= 0) {
results[1] = convert_value(sdrd[i].limits[sdrd[i].lim2], i);
if(sdrd[i].lim2 == 6) /* pos. threshold */
results[1] = results[0] - results[1];
if(sd->lim1 >= 0) {
if(sd->stype == STYPE_TEMP) { /* lower 2nd */
results[1] =
conv_val(sd->limits[sd->lim2], sd);
if(sd->lim2 == 6) /* pos. thresh. */
results[1] = results[0] -
results[1];
} else /* upper 2nd */
results[1] =
conv_val(sd->limits[sd->lim1], sd);
} else
results[1] = 0;
results[2] = conv_val(sd->reading, sd);
*nrels_mag = 3;
}
} else if (operation == SENSORS_PROC_REAL_WRITE) {
if (*nrels_mag >= 1) {
/* unimplemented */
}
}
}
#if 0
static void bmcsensors_alarms(struct i2c_client *client, int operation, int ctl_name,
int *nrels_mag, long *results)
{
struct bmcsensors_data *data = client->data;
#if 0
if (operation == SENSORS_PROC_REAL_INFO)
*nrels_mag = 0;
else if (operation == SENSORS_PROC_REAL_READ) {
@@ -952,8 +966,8 @@ static void bmcsensors_alarms(struct i2c_client *client, int operation, int ctl_
results[0] = data->alarms;
*nrels_mag = 1;
}
#endif
}
#endif
static int __init sm_bmcsensors_init(void)
{