diff options
| author | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2015-01-12 08:47:22 -0500 |
|---|---|---|
| committer | Guenter Roeck <linux@roeck-us.net> | 2015-01-26 00:23:59 -0500 |
| commit | b721fe2a3a92b896ba1b41e338471dfef672052a (patch) | |
| tree | d982f8763a82b764cbe2d62308f7a6a11e4c73f3 | |
| parent | 71eb7c4c7e6219a484c5185919962a99fb0ddabb (diff) | |
hwmon: (ina2xx) use DIV_ROUND_CLOSEST() to avoid rounding errors
Use DIV_ROUND_CLOSEST() when dealing with the calibration values to make the
calculations less error prone.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
| -rw-r--r-- | drivers/hwmon/ina2xx.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index ae110c5386ae..611ec4edd979 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c | |||
| @@ -186,8 +186,11 @@ static void ina226_set_update_interval(struct ina2xx_data *data) | |||
| 186 | 186 | ||
| 187 | static int ina2xx_calibrate(struct ina2xx_data *data) | 187 | static int ina2xx_calibrate(struct ina2xx_data *data) |
| 188 | { | 188 | { |
| 189 | return i2c_smbus_write_word_swapped(data->client, INA2XX_CALIBRATION, | 189 | u16 val = DIV_ROUND_CLOSEST(data->config->calibration_factor, |
| 190 | data->config->calibration_factor / data->rshunt); | 190 | data->rshunt); |
| 191 | |||
| 192 | return i2c_smbus_write_word_swapped(data->client, | ||
| 193 | INA2XX_CALIBRATION, val); | ||
| 191 | } | 194 | } |
| 192 | 195 | ||
| 193 | /* | 196 | /* |
| @@ -307,7 +310,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg) | |||
| 307 | val = (s16)data->regs[reg]; | 310 | val = (s16)data->regs[reg]; |
| 308 | break; | 311 | break; |
| 309 | case INA2XX_CALIBRATION: | 312 | case INA2XX_CALIBRATION: |
| 310 | val = data->config->calibration_factor / data->regs[reg]; | 313 | val = DIV_ROUND_CLOSEST(data->config->calibration_factor, |
| 314 | data->regs[reg]); | ||
| 311 | break; | 315 | break; |
| 312 | default: | 316 | default: |
| 313 | /* programmer goofed */ | 317 | /* programmer goofed */ |
