From: Guenter Roeck <linux@roeck-us.net>
To: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 1/6] hwmon: (lm92) Improve auto-detection accuracy
Date: Thu, 1 Aug 2024 07:49:13 -0700 [thread overview]
Message-ID: <20240801144918.6156-2-linux@roeck-us.net> (raw)
In-Reply-To: <20240801144918.6156-1-linux@roeck-us.net>
Checking three configuration register bits and the manufacturer ID
register to auto-detect LM92 is a bit vague. Repeat twice on replicated
register addresses to improve detection accuracy. Check the manufacturer
ID first and bail out immediately without reading the other register if
there is a mismatch to reduce the number of i2c transfers needed in that
case. Also explicitly test for an error from reading the configuration
register to avoid potential situations where the returned error masked
against 0xe0 is 0.
While at it, drop "lm92: Found National Semiconductor LM92 chip" detection
noise.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/lm92.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 46579a3e1715..e2d8c8afcbfa 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -272,20 +272,28 @@ static int lm92_detect(struct i2c_client *new_client,
struct i2c_board_info *info)
{
struct i2c_adapter *adapter = new_client->adapter;
- u8 config;
- u16 man_id;
+ u8 config_addr = LM92_REG_CONFIG;
+ u8 man_id_addr = LM92_REG_MAN_ID;
+ int i, regval;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
| I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV;
- config = i2c_smbus_read_byte_data(new_client, LM92_REG_CONFIG);
- man_id = i2c_smbus_read_word_data(new_client, LM92_REG_MAN_ID);
-
- if ((config & 0xe0) == 0x00 && man_id == 0x0180)
- pr_info("lm92: Found National Semiconductor LM92 chip\n");
- else
- return -ENODEV;
+ /*
+ * Register values repeat with multiples of 8.
+ * Read twice to improve detection accuracy.
+ */
+ for (i = 0; i < 2; i++) {
+ regval = i2c_smbus_read_word_data(new_client, man_id_addr);
+ if (regval != 0x0180)
+ return -ENODEV;
+ regval = i2c_smbus_read_byte_data(new_client, config_addr);
+ if (regval < 0 || (regval & 0xe0))
+ return -ENODEV;
+ config_addr += 8;
+ man_id_addr += 8;
+ }
strscpy(info->type, "lm92", I2C_NAME_SIZE);
--
2.39.2
next prev parent reply other threads:[~2024-08-01 14:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-01 14:49 [PATCH 0/6] hwmon: (lm92) Cleanup and conversion to with_info API Guenter Roeck
2024-08-01 14:49 ` Guenter Roeck [this message]
2024-08-02 5:11 ` [PATCH 1/6] hwmon: (lm92) Improve auto-detection accuracy Tzung-Bi Shih
2024-08-01 14:49 ` [PATCH 2/6] hwmon: (lm92) Reorder include files to alphabetic order Guenter Roeck
2024-08-02 5:12 ` Tzung-Bi Shih
2024-08-01 14:49 ` [PATCH 3/6] hwmon: (lm92) Replace chip IDs with limit register resolution Guenter Roeck
2024-08-02 5:12 ` Tzung-Bi Shih
2024-08-01 14:49 ` [PATCH 4/6] hwmon: (lm92) Convert to use regmap Guenter Roeck
2024-08-02 5:12 ` Tzung-Bi Shih
2024-08-01 14:49 ` [PATCH 5/6] hwmon: (lm92) Convert to with_info hwmon API Guenter Roeck
2024-08-02 5:12 ` Tzung-Bi Shih
2024-08-01 14:49 ` [PATCH 6/6] hwmon: (lm92) Update documentation Guenter Roeck
2024-08-02 5:12 ` Tzung-Bi Shih
2024-08-02 14:11 ` Guenter Roeck
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=20240801144918.6156-2-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