diff options
author | Jean Delvare <khali@linux-fr.org> | 2007-07-05 14:38:32 -0400 |
---|---|---|
committer | Mark M. Hoffman <mhoffman@lightlink.com> | 2007-10-09 22:56:30 -0400 |
commit | 5a4d3ef317c845893fe3f9d3517cb0a99375da53 (patch) | |
tree | 3e1b29b3ef889d160f8cc29e5d534bd5f7a79464 /drivers/hwmon | |
parent | bf76e9d3c42fae879feabe26a10bf8ebf27ab328 (diff) |
hwmon: (lm85) Clean up the handling of additional resolution bits
The way the lm85 driver currently handles the additional resolution
bits some chips have for the voltage and temperature measurements is
quite complex. This is my attempt to make it simpler.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Juerg Haefliger <juergh at gmail.com>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/lm85.c | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 3b70815ab982..0c61fa36c83c 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -139,10 +139,10 @@ static int lm85_scaling[] = { /* .001 Volts */ | |||
139 | #define INS_TO_REG(n,val) \ | 139 | #define INS_TO_REG(n,val) \ |
140 | SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255) | 140 | SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255) |
141 | 141 | ||
142 | #define INSEXT_FROM_REG(n,val,ext,scale) \ | 142 | #define INSEXT_FROM_REG(n,val,ext) \ |
143 | SCALE((val)*(scale) + (ext),192*(scale),lm85_scaling[n]) | 143 | SCALE(((val) << 4) + (ext), 192 << 4, lm85_scaling[n]) |
144 | 144 | ||
145 | #define INS_FROM_REG(n,val) INSEXT_FROM_REG(n,val,0,1) | 145 | #define INS_FROM_REG(n,val) SCALE((val), 192, lm85_scaling[n]) |
146 | 146 | ||
147 | /* FAN speed is measured using 90kHz clock */ | 147 | /* FAN speed is measured using 90kHz clock */ |
148 | #define FAN_TO_REG(val) (SENSORS_LIMIT( (val)<=0?0: 5400000/(val),0,65534)) | 148 | #define FAN_TO_REG(val) (SENSORS_LIMIT( (val)<=0?0: 5400000/(val),0,65534)) |
@@ -151,10 +151,9 @@ static int lm85_scaling[] = { /* .001 Volts */ | |||
151 | /* Temperature is reported in .001 degC increments */ | 151 | /* Temperature is reported in .001 degC increments */ |
152 | #define TEMP_TO_REG(val) \ | 152 | #define TEMP_TO_REG(val) \ |
153 | SENSORS_LIMIT(SCALE(val,1000,1),-127,127) | 153 | SENSORS_LIMIT(SCALE(val,1000,1),-127,127) |
154 | #define TEMPEXT_FROM_REG(val,ext,scale) \ | 154 | #define TEMPEXT_FROM_REG(val,ext) \ |
155 | SCALE((val)*scale + (ext),scale,1000) | 155 | SCALE(((val) << 4) + (ext), 16, 1000) |
156 | #define TEMP_FROM_REG(val) \ | 156 | #define TEMP_FROM_REG(val) ((val) * 1000) |
157 | TEMPEXT_FROM_REG(val,0,1) | ||
158 | 157 | ||
159 | #define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255)) | 158 | #define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255)) |
160 | #define PWM_FROM_REG(val) (val) | 159 | #define PWM_FROM_REG(val) (val) |
@@ -334,7 +333,6 @@ struct lm85_data { | |||
334 | u8 tach_mode; /* Register encoding, combined */ | 333 | u8 tach_mode; /* Register encoding, combined */ |
335 | u8 temp_ext[3]; /* Decoded values */ | 334 | u8 temp_ext[3]; /* Decoded values */ |
336 | u8 in_ext[8]; /* Decoded values */ | 335 | u8 in_ext[8]; /* Decoded values */ |
337 | u8 adc_scale; /* ADC Extended bits scaling factor */ | ||
338 | u8 fan_ppr; /* Register value */ | 336 | u8 fan_ppr; /* Register value */ |
339 | u8 smooth[3]; /* Register encoding */ | 337 | u8 smooth[3]; /* Register encoding */ |
340 | u8 vid; /* Register value */ | 338 | u8 vid; /* Register value */ |
@@ -541,8 +539,7 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr, | |||
541 | struct lm85_data *data = lm85_update_device(dev); | 539 | struct lm85_data *data = lm85_update_device(dev); |
542 | return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr, | 540 | return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr, |
543 | data->in[nr], | 541 | data->in[nr], |
544 | data->in_ext[nr], | 542 | data->in_ext[nr])); |
545 | data->adc_scale) ); | ||
546 | } | 543 | } |
547 | 544 | ||
548 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, | 545 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
@@ -616,8 +613,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | |||
616 | int nr = to_sensor_dev_attr(attr)->index; | 613 | int nr = to_sensor_dev_attr(attr)->index; |
617 | struct lm85_data *data = lm85_update_device(dev); | 614 | struct lm85_data *data = lm85_update_device(dev); |
618 | return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr], | 615 | return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr], |
619 | data->temp_ext[nr], | 616 | data->temp_ext[nr])); |
620 | data->adc_scale) ); | ||
621 | } | 617 | } |
622 | 618 | ||
623 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, | 619 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
@@ -1394,6 +1390,8 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1394 | 1390 | ||
1395 | /* Have to read extended bits first to "freeze" the | 1391 | /* Have to read extended bits first to "freeze" the |
1396 | * more significant bits that are read later. | 1392 | * more significant bits that are read later. |
1393 | * There are 2 additional resolution bits per channel and we | ||
1394 | * have room for 4, so we shift them to the left. | ||
1397 | */ | 1395 | */ |
1398 | if ( (data->type == adm1027) || (data->type == adt7463) ) { | 1396 | if ( (data->type == adm1027) || (data->type == adt7463) ) { |
1399 | int ext1 = lm85_read_value(client, | 1397 | int ext1 = lm85_read_value(client, |
@@ -1403,18 +1401,12 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1403 | int val = (ext1 << 8) + ext2; | 1401 | int val = (ext1 << 8) + ext2; |
1404 | 1402 | ||
1405 | for(i = 0; i <= 4; i++) | 1403 | for(i = 0; i <= 4; i++) |
1406 | data->in_ext[i] = (val>>(i * 2))&0x03; | 1404 | data->in_ext[i] = ((val>>(i * 2))&0x03) << 2; |
1407 | 1405 | ||
1408 | for(i = 0; i <= 2; i++) | 1406 | for(i = 0; i <= 2; i++) |
1409 | data->temp_ext[i] = (val>>((i + 5) * 2))&0x03; | 1407 | data->temp_ext[i] = (val>>((i + 4) * 2))&0x0c; |
1410 | } | 1408 | } |
1411 | 1409 | ||
1412 | /* adc_scale is 2^(number of LSBs). There are 4 extra bits in | ||
1413 | the emc6d102 and 2 in the adt7463 and adm1027. In all | ||
1414 | other chips ext is always 0 and the value of scale is | ||
1415 | irrelevant. So it is left in 4*/ | ||
1416 | data->adc_scale = (data->type == emc6d102 ) ? 16 : 4; | ||
1417 | |||
1418 | data->vid = lm85_read_value(client, LM85_REG_VID); | 1410 | data->vid = lm85_read_value(client, LM85_REG_VID); |
1419 | 1411 | ||
1420 | for (i = 0; i <= 3; ++i) { | 1412 | for (i = 0; i <= 3; ++i) { |