Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (tmp513) Use SI constants from units.h

MILLI and MICRO may be used in the driver to make code more robust
against possible miscalculations.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20231128180654.395692-4-andriy.shevchenko@linux.intel.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Andy Shevchenko and committed by
Guenter Roeck
f07f9d24 df989762

+10 -11
+10 -11
drivers/hwmon/tmp513.c
··· 32 32 #include <linux/regmap.h> 33 33 #include <linux/slab.h> 34 34 #include <linux/types.h> 35 + #include <linux/units.h> 35 36 36 37 // Common register definition 37 38 #define TMP51X_SHUNT_CONFIG 0x00 ··· 102 101 #define TMP51X_REMOTE_TEMP_LIMIT_2_POS 8 103 102 #define TMP513_REMOTE_TEMP_LIMIT_3_POS 7 104 103 105 - #define TMP51X_VBUS_RANGE_32V 32000000 106 - #define TMP51X_VBUS_RANGE_16V 16000000 104 + #define TMP51X_VBUS_RANGE_32V (32 * MICRO) 105 + #define TMP51X_VBUS_RANGE_16V (16 * MICRO) 107 106 108 107 // Max and Min value 109 108 #define MAX_BUS_VOLTAGE_32_LIMIT 32764 ··· 205 204 * on the pga gain setting. 1lsb = 10uV 206 205 */ 207 206 *val = sign_extend32(regval, 17 - tmp51x_get_pga_shift(data)); 208 - *val = DIV_ROUND_CLOSEST(*val * 10000, data->shunt_uohms); 207 + *val = DIV_ROUND_CLOSEST(*val * 10 * MILLI, data->shunt_uohms); 209 208 break; 210 209 case TMP51X_BUS_VOLTAGE_RESULT: 211 210 case TMP51X_BUS_VOLTAGE_H_LIMIT: ··· 221 220 case TMP51X_BUS_CURRENT_RESULT: 222 221 // Current = (ShuntVoltage * CalibrationRegister) / 4096 223 222 *val = sign_extend32(regval, 16) * data->curr_lsb_ua; 224 - *val = DIV_ROUND_CLOSEST(*val, 1000); 223 + *val = DIV_ROUND_CLOSEST(*val, MILLI); 225 224 break; 226 225 case TMP51X_LOCAL_TEMP_RESULT: 227 226 case TMP51X_REMOTE_TEMP_RESULT_1: ··· 261 260 * The user enter current value and we convert it to 262 261 * voltage. 1lsb = 10uV 263 262 */ 264 - val = DIV_ROUND_CLOSEST(val * data->shunt_uohms, 10000); 263 + val = DIV_ROUND_CLOSEST(val * data->shunt_uohms, 10 * MILLI); 265 264 max_val = U16_MAX >> tmp51x_get_pga_shift(data); 266 265 regval = clamp_val(val, -max_val, max_val); 267 266 break; ··· 551 550 if (data->shunt_uohms == 0) 552 551 return regmap_write(data->regmap, TMP51X_SHUNT_CALIBRATION, 0); 553 552 554 - max_curr_ma = DIV_ROUND_CLOSEST_ULL(vshunt_max * 1000 * 1000, 555 - data->shunt_uohms); 553 + max_curr_ma = DIV_ROUND_CLOSEST_ULL(vshunt_max * MICRO, data->shunt_uohms); 556 554 557 555 /* 558 556 * Calculate the minimal bit resolution for the current and the power. 559 557 * Those values will be used during register interpretation. 560 558 */ 561 - data->curr_lsb_ua = DIV_ROUND_CLOSEST_ULL(max_curr_ma * 1000, 32767); 559 + data->curr_lsb_ua = DIV_ROUND_CLOSEST_ULL(max_curr_ma * MILLI, 32767); 562 560 data->pwr_lsb_uw = 20 * data->curr_lsb_ua; 563 561 564 - div = DIV_ROUND_CLOSEST_ULL(data->curr_lsb_ua * data->shunt_uohms, 565 - 1000 * 1000); 562 + div = DIV_ROUND_CLOSEST_ULL(data->curr_lsb_ua * data->shunt_uohms, MICRO); 566 563 567 564 return regmap_write(data->regmap, TMP51X_SHUNT_CALIBRATION, 568 565 DIV_ROUND_CLOSEST(40960, div)); ··· 677 678 data->max_channels - 1); 678 679 679 680 // Check if shunt value is compatible with pga-gain 680 - if (data->shunt_uohms > data->pga_gain * 40 * 1000 * 1000) { 681 + if (data->shunt_uohms > data->pga_gain * 40 * MICRO) { 681 682 return dev_err_probe(dev, -EINVAL, 682 683 "shunt-resistor: %u too big for pga_gain: %u\n", 683 684 data->shunt_uohms, data->pga_gain);