mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 22:14:03 +02:00
hwmon: (cros_ec) Implement custom kelvin to celsius conversions
The ChromeOS EC APIs use integers representing degrees kelvin for temperatures. The default conversions from linux/units.h will then always convert these integer degrees celsius with a 150 millidegree offset. This is a bit confusing, as it also differs from other CrOS EC tooling. Internally the EC uses a kelvin to celsius offset of a round 273, so the current conversion is also not entirely accurate. Implement a custom conversion which preserves round values. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://lore.kernel.org/r/20260630-cros_ec-hwmon-overflow-v1-1-3d2ecd3eb0f2@weissschuh.net Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
ecc0eb5e95
commit
de0181c95b
|
|
@ -146,9 +146,17 @@ static bool cros_ec_hwmon_is_error_temp(u8 temp)
|
|||
temp == EC_TEMP_SENSOR_NOT_CALIBRATED;
|
||||
}
|
||||
|
||||
/* This differs slightly from the variant in units.h to avoid rounding inconsistencies. */
|
||||
#define CROS_EC_HWMON_ABSOLUTE_ZERO_MILLICELSIUS (-273000)
|
||||
|
||||
static long cros_ec_hwmon_kelvin_to_millicelsius(long t)
|
||||
{
|
||||
return t * MILLIDEGREE_PER_DEGREE + CROS_EC_HWMON_ABSOLUTE_ZERO_MILLICELSIUS;
|
||||
}
|
||||
|
||||
static long cros_ec_hwmon_temp_to_millicelsius(u8 temp)
|
||||
{
|
||||
return kelvin_to_millicelsius((((long)temp) + EC_TEMP_SENSOR_OFFSET));
|
||||
return cros_ec_hwmon_kelvin_to_millicelsius((((long)temp) + EC_TEMP_SENSOR_OFFSET));
|
||||
}
|
||||
|
||||
static bool cros_ec_hwmon_attr_is_temp_threshold(u32 attr)
|
||||
|
|
@ -227,7 +235,7 @@ static int cros_ec_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
|
|||
cros_ec_hwmon_attr_to_thres(attr),
|
||||
&threshold);
|
||||
if (ret == 0)
|
||||
*val = kelvin_to_millicelsius(threshold);
|
||||
*val = cros_ec_hwmon_kelvin_to_millicelsius(threshold);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user