Commit 8aba9ca6 authored by Eugene Shalygin's avatar Eugene Shalygin Committed by Guenter Roeck

hwmon: (asus-ec-sensors) deduce sensor signedness from its type

Reading DSDT code for ASUS X470-based boards (the ones served by the
asus_wmi_Sensors driver), where ASUS put hardware monitoring functions
into the WMI code, reveals that fan and current sensors data is
unsigned. For the current sensor that was confirmed by a user who showed
high enough current value for overflow.

Thus let's assume that the signedness of the sensors is determined by its
type and that only temperature ones provide signed numbers.
Signed-off-by: default avatarEugene Shalygin <eugene.shalygin@gmail.com>
Link: https://lore.kernel.org/r/20220211164855.265698-1-eugene.shalygin@gmail.comSigned-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 99cb5e9f
...@@ -266,6 +266,15 @@ static u8 register_index(u16 reg) ...@@ -266,6 +266,15 @@ static u8 register_index(u16 reg)
return reg & 0x00ff; return reg & 0x00ff;
} }
static bool is_sensor_data_signed(const struct ec_sensor_info *si)
{
/*
* guessed from WMI functions in DSDT code for boards
* of the X470 generation
*/
return si->type == hwmon_temp;
}
static const struct ec_sensor_info * static const struct ec_sensor_info *
get_sensor_info(const struct ec_sensors_data *state, int index) get_sensor_info(const struct ec_sensors_data *state, int index)
{ {
...@@ -420,15 +429,28 @@ static int asus_ec_block_read(const struct device *dev, ...@@ -420,15 +429,28 @@ static int asus_ec_block_read(const struct device *dev,
static inline s32 get_sensor_value(const struct ec_sensor_info *si, u8 *data) static inline s32 get_sensor_value(const struct ec_sensor_info *si, u8 *data)
{ {
switch (si->addr.components.size) { if (is_sensor_data_signed(si)) {
case 1: switch (si->addr.components.size) {
return (s8)*data; case 1:
case 2: return (s8)*data;
return (s16)get_unaligned_be16(data); case 2:
case 4: return (s16)get_unaligned_be16(data);
return (s32)get_unaligned_be32(data); case 4:
default: return (s32)get_unaligned_be32(data);
return 0; default:
return 0;
}
} else {
switch (si->addr.components.size) {
case 1:
return *data;
case 2:
return get_unaligned_be16(data);
case 4:
return get_unaligned_be32(data);
default:
return 0;
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment