hwmon: (asus-ec-sensors) detect unconnected physical sensors
Subsystems (2)
Eugene Shalygin
maintainerPATCH 1/1 hwmon: (asus-ec-sensors) detect unconnected physical sensors
When there is no temperature sensor connected, reading EC register returns one of the special values (-62, -60, -40). Test for them and return -ENODATA to hwmon.
--- drivers/hwmon/asus-ec-sensors.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/hwmon/asus-ec-sensors.c +25 -2
@@ -67,6 +67,13 @@ static char *mutex_path_override;/* Moniker for the ACPI global lock (':' is not allowed in ASL identifiers) */ #define ACPI_GLOBAL_LOCK_PSEUDO_PATH ":GLOBAL_LOCK" +/* +* The values for temperature sensor readings without physical sensors connected. +* The value varies across generations and is seemingly defined by the EC chip +* used in the given board. +*/ +static s32 temperature_blank_values[] = {-62 ,-60 ,-40 }; + typedef union { u32 value; struct {
@@ -1291,6 +1298,17 @@ static int get_cached_value_or_update(const struct device *dev,return 0 ; } +static bool is_blank_temperature_value (s32 value) +{ +size_t i; + +for (i =0 ; i <ARRAY_SIZE (temperature_blank_values); ++i) { +if (value == temperature_blank_values[i]) +return true; + } +return false; +} +/* * Now follow the functions that implement the hwmon interface */
@@ -1298,6 +1316,7 @@ static int get_cached_value_or_update(const struct device *dev,static int asus_ec_hwmon_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) { +const struct ec_sensor_info *sensor_info;int ret;s32 value =0 ;
@@ -1310,8 +1329,12 @@ static int asus_ec_hwmon_read(struct device *dev, enum hwmon_sensor_types type, ret =get_cached_value_or_update (dev, sidx, state, &value);if (!ret) { - *val =scale_sensor_value (value, -get_sensor_info (state, sidx)->type); + sensor_info =get_sensor_info (state, sidx); +if (sensor_info->type == hwmon_temp && +is_blank_temperature_value (value)) { +return -ENODATA ; + } + *val =scale_sensor_value (value, sensor_info->type); }return ret;
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The static array `temperature_blank_values` is missing the `const` qualifier. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The static array temperature_blank_values is missing the const qualifier. --
--- Patch [1]: [PATCH] hwmon: (asus-ec-sensors) detect unconnected physical sensors --- commit 674d66473a7b251333e25248978dffdc28c7dbcd
Author: Eugene Shalygin <[email protected]>
hwmon: (asus-ec-sensors) detect unconnected physical sensors
This commit adds detection for unconnected physical temperature sensors by checking for specific blank values (-62, -60, -40) returned by the EC register. If a sensor is unconnected, it now returns -ENODATA to hwmon.
Quoted 5 lines
drivers/hwmon/asus-ec-sensors.c +0
-0
drivers/hwmon/asus-ec-sensors.c static char *mutex_path_override; · line 75
Quoted 9 lines
drivers/hwmon/asus-ec-sensors.c +6
-0@@ -67,6 +67,13 @@ static char *mutex_path_override;/* Moniker for the ACPI global lock (':' is not allowed in ASL identifiers) */ #define ACPI_GLOBAL_LOCK_PSEUDO_PATH ":GLOBAL_LOCK" +/* +* The values for temperature sensor readings without physical sensors connected. +* The value varies across generations and is seemingly defined by the EC chip +* used in the given board. +*/ +static s32 temperature_blank_values[] = {-62 ,-60 ,-40 };
[Severity: Low]
This isn't a bug, but should this array be declared with the const qualifier? Without it, the array will be placed in the writable data section rather than the read-only memory section.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1