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