[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220525135758.2944744-28-linux@roeck-us.net>
Date: Wed, 25 May 2022 06:57:45 -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 27/40] hwmon: (lm90) Introduce 16-bit register write function
Introduce 16-bit register write function to simplify the code in
some places.
Signed-off-by: Guenter Roeck <linux@...ck-us.net>
---
drivers/hwmon/lm90.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 20208f127508..46837f0bf62e 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -665,6 +665,21 @@ static int lm90_write_reg(struct i2c_client *client, u8 reg, u8 val)
return i2c_smbus_write_byte_data(client, lm90_write_reg_addr(reg), val);
}
+/*
+ * Write into 16-bit LM90 register.
+ * Convert register addresses to write address if needed, then execute the
+ * operation.
+ */
+static int lm90_write16(struct i2c_client *client, u8 regh, u8 regl, u16 val)
+{
+ int ret;
+
+ ret = lm90_write_reg(client, regh, val >> 8);
+ if (ret < 0 || !regl)
+ return ret;
+ return lm90_write_reg(client, regl, val & 0xff);
+}
+
static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl,
bool is_volatile)
{
@@ -1240,12 +1255,8 @@ static int lm90_set_temp(struct lm90_data *data, int index, int channel, long va
if (channel > 1)
lm90_select_remote_channel(data, true);
- err = lm90_write_reg(client, regh, data->temp[index] >> 8);
- if (err < 0)
- goto deselect;
- if (regl)
- err = lm90_write_reg(client, regl, data->temp[index] & 0xff);
-deselect:
+ err = lm90_write16(client, regh, regl, data->temp[index]);
+
if (channel > 1)
lm90_select_remote_channel(data, false);
@@ -1405,14 +1416,8 @@ static int lm90_temp_write(struct device *dev, u32 attr, int channel, long val)
val = lm90_temp_to_reg(0, val,
lm90_temp_get_resolution(data, REMOTE_OFFSET));
data->temp[REMOTE_OFFSET] = val;
- err = i2c_smbus_write_byte_data(data->client,
- LM90_REG_REMOTE_OFFSH,
- val >> 8);
- if (err)
- break;
- err = i2c_smbus_write_byte_data(data->client,
- LM90_REG_REMOTE_OFFSL,
- val & 0xff);
+ err = lm90_write16(data->client, LM90_REG_REMOTE_OFFSH,
+ LM90_REG_REMOTE_OFFSL, val);
break;
default:
err = -EOPNOTSUPP;
--
2.35.1
Powered by blists - more mailing lists