From: Eugene Shalygin <eugene.shalygin@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Oleksandr Natalenko <oleksandr@natalenko.name>,
Denis Pauk <pauk.denis@gmail.com>,
Eugene Shalygin <eugene.shalygin@gmail.com>,
Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] hwmon: (asus-ec-sensors) deduce sensor signess from its type
Date: Fri, 11 Feb 2022 01:36:39 +0100 [thread overview]
Message-ID: <20220211003641.73111-1-eugene.shalygin@gmail.com> (raw)
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 cofirmed by a user who showed
high enough current value for overflow.
Thus let's assume that the signess of the sensors is determined by its
type and that only temperature ones provide signed numbers.
Signed-off-by: Eugene Shalygin <eugene.shalygin@gmail.com>
---
drivers/hwmon/asus-ec-sensors.c | 38 +++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/drivers/hwmon/asus-ec-sensors.c b/drivers/hwmon/asus-ec-sensors.c
index bfac08a5dc57..a1b13fe149ac 100644
--- a/drivers/hwmon/asus-ec-sensors.c
+++ b/drivers/hwmon/asus-ec-sensors.c
@@ -266,6 +266,13 @@ static u8 register_index(u16 reg)
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 *
get_sensor_info(const struct ec_sensors_data *state, int index)
{
@@ -420,15 +427,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)
{
- switch (si->addr.components.size) {
- case 1:
- return (s8)*data;
- case 2:
- return (s16)get_unaligned_be16(data);
- case 4:
- return (s32)get_unaligned_be32(data);
- default:
- return 0;
+ if (is_sensor_data_signed(si)) {
+ switch (si->addr.components.size) {
+ case 1:
+ return (s8)*data;
+ case 2:
+ return (s16)get_unaligned_be16(data);
+ case 4:
+ return (s32)get_unaligned_be32(data);
+ 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;
+ }
}
}
--
2.35.1
next reply other threads:[~2022-02-11 0:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-11 0:36 Eugene Shalygin [this message]
2022-02-11 0:40 ` [PATCH] hwmon: (asus-ec-sensors) deduce sensor signess from its type Eugene Shalygin
2022-02-11 4:40 ` Guenter Roeck
2022-02-11 16:48 ` [PATCH v2] hwmon: (asus-ec-sensors) deduce sensor signedness " Eugene Shalygin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220211003641.73111-1-eugene.shalygin@gmail.com \
--to=eugene.shalygin@gmail.com \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=oleksandr@natalenko.name \
--cc=pauk.denis@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox