Commit d7427629 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'hwmon-for-v6.13-rc4' of...

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
parents 11167b29 dd471e25
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ struct tmp51x_data {
	struct regmap *regmap;
};

// Set the shift based on the gain 8=4, 4=3, 2=2, 1=1
// Set the shift based on the gain: 8 -> 1, 4 -> 2, 2 -> 3, 1 -> 4
static inline u8 tmp51x_get_pga_shift(struct tmp51x_data *data)
{
	return 5 - ffs(data->pga_gain);
@@ -204,7 +204,9 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos,
		 * 2's complement number shifted by one to four depending
		 * on the pga gain setting. 1lsb = 10uV
		 */
		*val = sign_extend32(regval, 17 - tmp51x_get_pga_shift(data));
		*val = sign_extend32(regval,
				     reg == TMP51X_SHUNT_CURRENT_RESULT ?
				     16 - tmp51x_get_pga_shift(data) : 15);
		*val = DIV_ROUND_CLOSEST(*val * 10 * MILLI, data->shunt_uohms);
		break;
	case TMP51X_BUS_VOLTAGE_RESULT:
@@ -220,7 +222,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos,
		break;
	case TMP51X_BUS_CURRENT_RESULT:
		// Current = (ShuntVoltage * CalibrationRegister) / 4096
		*val = sign_extend32(regval, 16) * data->curr_lsb_ua;
		*val = sign_extend32(regval, 15) * (long)data->curr_lsb_ua;
		*val = DIV_ROUND_CLOSEST(*val, MILLI);
		break;
	case TMP51X_LOCAL_TEMP_RESULT:
@@ -232,7 +234,7 @@ static int tmp51x_get_value(struct tmp51x_data *data, u8 reg, u8 pos,
	case TMP51X_REMOTE_TEMP_LIMIT_2:
	case TMP513_REMOTE_TEMP_LIMIT_3:
		// 1lsb = 0.0625 degrees centigrade
		*val = sign_extend32(regval, 16) >> TMP51X_TEMP_SHIFT;
		*val = sign_extend32(regval, 15) >> TMP51X_TEMP_SHIFT;
		*val = DIV_ROUND_CLOSEST(*val * 625, 10);
		break;
	case TMP51X_N_FACTOR_AND_HYST_1: