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: (max1619) Improve chip detection code
Date: Sat, 27 Jul 2024 07:38:20 -0700 [thread overview]
Message-ID: <20240727143820.1358225-7-linux@roeck-us.net> (raw)
In-Reply-To: <20240727143820.1358225-1-linux@roeck-us.net>
Bail out immediately if reading any of the registers used for chip
detection fails, or if it returns an unexpected value. Drop all log
messages from detection code.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/hwmon/max1619.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 40f0726e9f22..9cbca17f27a5 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -260,31 +260,27 @@ static int max1619_detect(struct i2c_client *client,
struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;
- u8 reg_config, reg_convrate, reg_status, man_id, chip_id;
+ int regval;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV;
- /* detection */
- reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_CONFIG);
- reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_CONVRATE);
- reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_STATUS);
- if ((reg_config & 0x03) != 0x00
- || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) {
- dev_dbg(&adapter->dev, "MAX1619 detection failed at 0x%02x\n",
- client->addr);
+ regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CONFIG);
+ if (regval < 0 || (regval & 0x03))
+ return -ENODEV;
+ regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CONVRATE);
+ if (regval < 0 || regval > 0x07)
+ return -ENODEV;
+ regval = i2c_smbus_read_byte_data(client, MAX1619_REG_STATUS);
+ if (regval < 0 || (regval & 0x61))
return -ENODEV;
- }
- /* identification */
- man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_MAN_ID);
- chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_CHIP_ID);
- if (man_id != 0x4D || chip_id != 0x04) {
- dev_info(&adapter->dev,
- "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n",
- man_id, chip_id);
+ regval = i2c_smbus_read_byte_data(client, MAX1619_REG_MAN_ID);
+ if (regval != 0x4d)
+ return -ENODEV;
+ regval = i2c_smbus_read_byte_data(client, MAX1619_REG_CHIP_ID);
+ if (regval != 0x04)
return -ENODEV;
- }
strscpy(info->type, "max1619", I2C_NAME_SIZE);
--
2.39.2
next prev parent reply other threads:[~2024-07-27 14:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-27 14:38 [PATCH 1/6] hwmon: (max1619) Modernize driver Guenter Roeck
2024-07-27 14:38 ` [PATCH 1/6] hwmon: (max1619) Clamp temperature range when writing limits Guenter Roeck
2024-07-28 4:25 ` Tzung-Bi Shih
2024-07-27 14:38 ` [PATCH 2/6] hwmon: (max1619) Reorder include files to alphabetic order Guenter Roeck
2024-07-28 4:25 ` Tzung-Bi Shih
2024-07-27 14:38 ` [PATCH 3/6] hwmon: (max1619) Convert to use regmap Guenter Roeck
2024-07-28 4:26 ` Tzung-Bi Shih
2024-07-28 5:22 ` Guenter Roeck
2024-07-28 12:17 ` Tzung-Bi Shih
2024-07-27 14:38 ` [PATCH 4/6] hwmon: (max1619) Convert to with_info API Guenter Roeck
2024-07-28 4:26 ` Tzung-Bi Shih
2024-07-27 14:38 ` [PATCH 5/6] hwmon: (max1619) Add support for update_interval attribute Guenter Roeck
2024-07-28 4:26 ` Tzung-Bi Shih
2024-07-27 14:38 ` Guenter Roeck [this message]
2024-07-28 4:26 ` [PATCH 6/6] hwmon: (max1619) Improve chip detection code 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=20240727143820.1358225-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