diff options
| -rw-r--r-- | drivers/hwmon/adt7473.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c index 3a0b63136479..b9a8ea30c99c 100644 --- a/drivers/hwmon/adt7473.c +++ b/drivers/hwmon/adt7473.c | |||
| @@ -319,35 +319,24 @@ out: | |||
| 319 | } | 319 | } |
| 320 | 320 | ||
| 321 | /* | 321 | /* |
| 322 | * On this chip, voltages are given as a count of steps between a minimum | 322 | * Conversions |
| 323 | * and maximum voltage, not a direct voltage. | ||
| 324 | */ | 323 | */ |
| 325 | static const int volt_convert_table[][2] = { | 324 | |
| 326 | {2997, 3}, | 325 | /* IN are scaled acording to built-in resistors */ |
| 327 | {4395, 4}, | 326 | static const int adt7473_scaling[] = { /* .001 Volts */ |
| 327 | 2250, 3300 | ||
| 328 | }; | 328 | }; |
| 329 | #define SCALE(val, from, to) (((val) * (to) + ((from) / 2)) / (from)) | ||
| 329 | 330 | ||
| 330 | static int decode_volt(int volt_index, u8 raw) | 331 | static int decode_volt(int volt_index, u8 raw) |
| 331 | { | 332 | { |
| 332 | int cmax = volt_convert_table[volt_index][0]; | 333 | return SCALE(raw, 192, adt7473_scaling[volt_index]); |
| 333 | int cmin = volt_convert_table[volt_index][1]; | ||
| 334 | return ((raw * (cmax - cmin)) / 255) + cmin; | ||
| 335 | } | 334 | } |
| 336 | 335 | ||
| 337 | static u8 encode_volt(int volt_index, int cooked) | 336 | static u8 encode_volt(int volt_index, int cooked) |
| 338 | { | 337 | { |
| 339 | int cmax = volt_convert_table[volt_index][0]; | 338 | int raw = SCALE(cooked, adt7473_scaling[volt_index], 192); |
| 340 | int cmin = volt_convert_table[volt_index][1]; | 339 | return SENSORS_LIMIT(raw, 0, 255); |
| 341 | u8 x; | ||
| 342 | |||
| 343 | if (cooked > cmax) | ||
| 344 | cooked = cmax; | ||
| 345 | else if (cooked < cmin) | ||
| 346 | cooked = cmin; | ||
| 347 | |||
| 348 | x = ((cooked - cmin) * 255) / (cmax - cmin); | ||
| 349 | |||
| 350 | return x; | ||
| 351 | } | 340 | } |
| 352 | 341 | ||
| 353 | static ssize_t show_volt_min(struct device *dev, | 342 | static ssize_t show_volt_min(struct device *dev, |
