[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220525135758.2944744-27-linux@roeck-us.net>
Date: Wed, 25 May 2022 06:57:44 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: linux-hwmon@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Jean Delvare <jdelvare@...e.com>,
Slawomir Stepien <sst@...zta.fm>,
Guenter Roeck <linux@...ck-us.net>
Subject: [PATCH 26/40] hwmon: (lm90) Let lm90_read16() handle 8-bit read operations
Simplify the code a bit by handling single-register read operations
in lm90_read16(). All we need to do is to skip the low-byte read
operation if the register address is 0.
Signed-off-by: Guenter Roeck <linux@...ck-us.net>
---
drivers/hwmon/lm90.c | 47 ++++++++++++++++----------------------------
1 file changed, 17 insertions(+), 30 deletions(-)
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 78eda648d960..20208f127508 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -673,6 +673,10 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl,
oldh = lm90_read_reg(client, regh);
if (oldh < 0)
return oldh;
+
+ if (!regl)
+ return oldh << 8;
+
l = lm90_read_reg(client, regl);
if (l < 0)
return l;
@@ -804,29 +808,19 @@ static int lm90_update_limits(struct device *dev)
data->temp_hyst = val;
}
- val = lm90_read_reg(client, LM90_REG_REMOTE_LOWH);
+ val = lm90_read16(client, LM90_REG_REMOTE_LOWH,
+ (data->flags & LM90_HAVE_REM_LIMIT_EXT) ? LM90_REG_REMOTE_LOWL : 0,
+ false);
if (val < 0)
return val;
- data->temp[REMOTE_LOW] = val << 8;
+ data->temp[REMOTE_LOW] = val;
- if (data->flags & LM90_HAVE_REM_LIMIT_EXT) {
- val = lm90_read_reg(client, LM90_REG_REMOTE_LOWL);
- if (val < 0)
- return val;
- data->temp[REMOTE_LOW] |= val;
- }
-
- val = lm90_read_reg(client, LM90_REG_REMOTE_HIGHH);
+ val = lm90_read16(client, LM90_REG_REMOTE_HIGHH,
+ (data->flags & LM90_HAVE_REM_LIMIT_EXT) ? LM90_REG_REMOTE_HIGHL : 0,
+ false);
if (val < 0)
return val;
- data->temp[REMOTE_HIGH] = val << 8;
-
- if (data->flags & LM90_HAVE_REM_LIMIT_EXT) {
- val = lm90_read_reg(client, LM90_REG_REMOTE_HIGHL);
- if (val < 0)
- return val;
- data->temp[REMOTE_HIGH] |= val;
- }
+ data->temp[REMOTE_HIGH] = val;
if (data->flags & LM90_HAVE_OFFSET) {
val = lm90_read16(client, LM90_REG_REMOTE_OFFSH,
@@ -1063,18 +1057,11 @@ static int lm90_update_device(struct device *dev)
return val;
data->temp[LOCAL_HIGH] = val << 8;
- if (data->reg_local_ext) {
- val = lm90_read16(client, LM90_REG_LOCAL_TEMP,
- data->reg_local_ext, true);
- if (val < 0)
- return val;
- data->temp[LOCAL_TEMP] = val;
- } else {
- val = lm90_read_reg(client, LM90_REG_LOCAL_TEMP);
- if (val < 0)
- return val;
- data->temp[LOCAL_TEMP] = val << 8;
- }
+ val = lm90_read16(client, LM90_REG_LOCAL_TEMP,
+ data->reg_local_ext, true);
+ if (val < 0)
+ return val;
+ data->temp[LOCAL_TEMP] = val;
val = lm90_read16(client, LM90_REG_REMOTE_TEMPH,
LM90_REG_REMOTE_TEMPL, true);
if (val < 0)
--
2.35.1
Powered by blists - more mailing lists