Skip to content

Commit d742762

Browse files
committed
Merge tag 'hwmon-for-v6.13-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck: - Fix reporting of negative temperature, current, and voltage values in the tmp513 driver * tag 'hwmon-for-v6.13-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (tmp513) Fix interpretation of values of Temperature Result and Limit Registers hwmon: (tmp513) Fix Current Register value interpretation hwmon: (tmp513) Fix interpretation of values of Shunt Voltage and Limit Registers
2 parents 11167b2 + dd471e2 commit d742762

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/hwmon/tmp513.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ struct tmp51x_data {
182182
struct regmap *regmap;
183183
};
184184

185-
// Set the shift based on the gain 8=4, 4=3, 2=2, 1=1
185+
// Set the shift based on the gain: 8 -> 1, 4 -> 2, 2 -> 3, 1 -> 4
186186
static inline u8 tmp51x_get_pga_shift(struct tmp51x_data *data)
187187
{
188188
return 5 - ffs(data->pga_gain);
@@ -204,7 +204,9 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos,
204204
* 2's complement number shifted by one to four depending
205205
* on the pga gain setting. 1lsb = 10uV
206206
*/
207-
*val = sign_extend32(regval, 17 - tmp51x_get_pga_shift(data));
207+
*val = sign_extend32(regval,
208+
reg == TMP51X_SHUNT_CURRENT_RESULT ?
209+
16 - tmp51x_get_pga_shift(data) : 15);
208210
*val = DIV_ROUND_CLOSEST(*val * 10 * MILLI, data->shunt_uohms);
209211
break;
210212
case TMP51X_BUS_VOLTAGE_RESULT:
@@ -220,7 +222,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos,
220222
break;
221223
case TMP51X_BUS_CURRENT_RESULT:
222224
// Current = (ShuntVoltage * CalibrationRegister) / 4096
223-
*val = sign_extend32(regval, 16) * data->curr_lsb_ua;
225+
*val = sign_extend32(regval, 15) * (long)data->curr_lsb_ua;
224226
*val = DIV_ROUND_CLOSEST(*val, MILLI);
225227
break;
226228
case TMP51X_LOCAL_TEMP_RESULT:
@@ -232,7 +234,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos,
232234
case TMP51X_REMOTE_TEMP_LIMIT_2:
233235
case TMP513_REMOTE_TEMP_LIMIT_3:
234236
// 1lsb = 0.0625 degrees centigrade
235-
*val = sign_extend32(regval, 16) >> TMP51X_TEMP_SHIFT;
237+
*val = sign_extend32(regval, 15) >> TMP51X_TEMP_SHIFT;
236238
*val = DIV_ROUND_CLOSEST(*val * 625, 10);
237239
break;
238240
case TMP51X_N_FACTOR_AND_HYST_1:

0 commit comments

Comments
 (0)