From: Guenter Roeck <linux@roeck-us.net>
To: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 6/6] hwmon: (lm95234) Use multi-byte regmap operations
Date: Wed, 17 Jul 2024 20:39:35 -0700 [thread overview]
Message-ID: <20240718033935.205185-7-linux@roeck-us.net> (raw)
In-Reply-To: <20240718033935.205185-1-linux@roeck-us.net>
Use multi-byte regmap operations to simplify the code
and to reduce dependency on locking.
No functional change.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/lm95234.c | 45 +++++++++++++++++------------------------
1 file changed, 18 insertions(+), 27 deletions(-)
diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
index f0df1134f811..c3c68c196479 100644
--- a/drivers/hwmon/lm95234.c
+++ b/drivers/hwmon/lm95234.c
@@ -60,54 +60,45 @@ struct lm95234_data {
static int lm95234_read_temp(struct regmap *regmap, int index, long *t)
{
+ unsigned int regs[2];
int temp = 0, ret;
- u32 val;
+ u8 regvals[2];
if (index) {
- ret = regmap_read(regmap, LM95234_REG_UTEMPH(index - 1), &val);
+ regs[0] = LM95234_REG_UTEMPH(index - 1);
+ regs[1] = LM95234_REG_UTEMPL(index - 1);
+ ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret)
return ret;
- temp = val << 8;
- ret = regmap_read(regmap, LM95234_REG_UTEMPL(index - 1), &val);
- if (ret)
- return ret;
- temp |= val;
+ temp = (regvals[0] << 8) | regvals[1];
}
/*
* Read signed temperature if unsigned temperature is 0,
* or if this is the local sensor.
*/
if (!temp) {
- ret = regmap_read(regmap, LM95234_REG_TEMPH(index), &val);
+ regs[0] = LM95234_REG_TEMPH(index);
+ regs[1] = LM95234_REG_TEMPL(index);
+ ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret)
return ret;
- temp = val << 8;
- ret = regmap_read(regmap, LM95234_REG_TEMPL(index), &val);
- if (ret)
- return ret;
- temp = sign_extend32(temp | val, 15);
+ temp = (regvals[0] << 8) | regvals[1];
+ temp = sign_extend32(temp, 15);
}
*t = DIV_ROUND_CLOSEST(temp * 125, 32);
return 0;
}
-static int lm95234_hyst_get(struct lm95234_data *data, int reg, long *val)
+static int lm95234_hyst_get(struct regmap *regmap, int reg, long *val)
{
- u32 thyst, tcrit;
+ unsigned int regs[2] = {reg, LM95234_REG_TCRIT_HYST};
+ u8 regvals[2];
int ret;
- mutex_lock(&data->update_lock);
- ret = regmap_read(data->regmap, reg, &tcrit);
- if (ret)
- goto unlock;
- ret = regmap_read(data->regmap, LM95234_REG_TCRIT_HYST, &thyst);
-unlock:
- mutex_unlock(&data->update_lock);
+ ret = regmap_multi_reg_read(regmap, regs, regvals, 2);
if (ret)
return ret;
-
- /* Result can be negative, so be careful with unsigned operands */
- *val = ((int)tcrit - (int)thyst) * 1000;
+ *val = (regvals[0] - regvals[1]) * 1000;
return 0;
}
@@ -209,7 +200,7 @@ static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va
*val = !!(regval & BIT(channel));
break;
case hwmon_temp_crit_hyst:
- return lm95234_hyst_get(data, LM95234_REG_TCRIT1(channel), val);
+ return lm95234_hyst_get(regmap, LM95234_REG_TCRIT1(channel), val);
case hwmon_temp_type:
ret = regmap_read(regmap, LM95234_REG_REM_MODEL, ®val);
if (ret)
@@ -236,7 +227,7 @@ static int lm95234_temp_read(struct device *dev, u32 attr, int channel, long *va
*val = regval * 1000;
break;
case hwmon_temp_max_hyst:
- return lm95234_hyst_get(data, lm95234_crit_reg(channel), val);
+ return lm95234_hyst_get(regmap, lm95234_crit_reg(channel), val);
case hwmon_temp_crit:
ret = regmap_read(regmap, LM95234_REG_TCRIT1(channel), ®val);
if (ret)
--
2.39.2
next prev parent reply other threads:[~2024-07-18 3:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-18 3:39 [PATCH 0/6] hwmon: (lm9534) Various improvements Guenter Roeck
2024-07-18 3:39 ` [PATCH 1/6] hwmon: (lm95234) Reorder include files to be in alphabetic order Guenter Roeck
2024-07-18 16:39 ` Tzung-Bi Shih
2024-07-18 3:39 ` [PATCH 2/6] hwmon: (lm95234) Use find_closest to find matching update interval Guenter Roeck
2024-07-18 16:39 ` Tzung-Bi Shih
2024-07-18 17:48 ` Guenter Roeck
2024-07-18 17:53 ` Guenter Roeck
2024-07-19 0:52 ` Tzung-Bi Shih
2024-07-18 3:39 ` [PATCH 3/6] hwmon: (lm95234) Convert to use regmap Guenter Roeck
2024-07-18 16:40 ` Tzung-Bi Shih
2024-07-18 3:39 ` [PATCH 4/6] hwmon: (lm95234) Convert to with_info hwmon API Guenter Roeck
2024-07-18 16:40 ` Tzung-Bi Shih
2024-07-18 17:47 ` Guenter Roeck
2024-07-19 0:52 ` Tzung-Bi Shih
2024-07-19 1:55 ` Guenter Roeck
2024-07-18 3:39 ` [PATCH 5/6] hwmon: (lm95234) Add support for tempX_enable attribute Guenter Roeck
2024-07-18 16:40 ` Tzung-Bi Shih
2024-07-18 3:39 ` Guenter Roeck [this message]
2024-07-18 16:40 ` [PATCH 6/6] hwmon: (lm95234) Use multi-byte regmap operations Tzung-Bi Shih
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=20240718033935.205185-7-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-hwmon@vger.kernel.org \
/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