From: Chris Packham <chris.packham@alliedtelesis.co.nz>
To: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Chris Packham <chris.packham@alliedtelesis.co.nz>
Subject: [PATCH v3 3/3] hwmon: (adt7475) Use enum chips when loading attenuator settings
Date: Wed, 23 Mar 2022 16:40:56 +1300 [thread overview]
Message-ID: <20220323034056.260455-4-chris.packham@alliedtelesis.co.nz> (raw)
In-Reply-To: <20220323034056.260455-1-chris.packham@alliedtelesis.co.nz>
Make use of enum chips and use a switch statement in load_attenuators()
so that the compiler can tell us if we've failed to cater for a
supported chip.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Notes:
Changes in v3:
- Reword commit message
- Use switch instead of if/else
Changes in v2:
- New
drivers/hwmon/adt7475.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 6de501de41b2..ac480e6e4818 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -1569,12 +1569,12 @@ static int set_property_bit(const struct i2c_client *client, char *property,
return ret;
}
-static int load_attenuators(const struct i2c_client *client, int chip,
+static int load_attenuators(const struct i2c_client *client, enum chips chip,
struct adt7475_data *data)
{
- int ret;
-
- if (chip == adt7476 || chip == adt7490) {
+ switch (chip) {
+ case adt7476:
+ case adt7490:
set_property_bit(client, "adi,bypass-attenuator-in0",
&data->config4, 4);
set_property_bit(client, "adi,bypass-attenuator-in1",
@@ -1584,18 +1584,15 @@ static int load_attenuators(const struct i2c_client *client, int chip,
set_property_bit(client, "adi,bypass-attenuator-in4",
&data->config4, 7);
- ret = i2c_smbus_write_byte_data(client, REG_CONFIG4,
- data->config4);
- if (ret < 0)
- return ret;
- } else if (chip == adt7473 || chip == adt7475) {
+ return i2c_smbus_write_byte_data(client, REG_CONFIG4,
+ data->config4);
+ case adt7473:
+ case adt7475:
set_property_bit(client, "adi,bypass-attenuator-in1",
&data->config2, 5);
- ret = i2c_smbus_write_byte_data(client, REG_CONFIG2,
- data->config2);
- if (ret < 0)
- return ret;
+ return i2c_smbus_write_byte_data(client, REG_CONFIG2,
+ data->config2);
}
return 0;
--
2.35.1
next prev parent reply other threads:[~2022-03-23 3:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-23 3:40 [PATCH v3 0/3] hwmon: (adt7475) pin configuration Chris Packham
2022-03-23 3:40 ` [PATCH v3 1/3] dt-bindings: hwmon: Document adt7475 pin-function properties Chris Packham
2022-04-24 16:52 ` Guenter Roeck
2022-05-02 4:35 ` Guenter Roeck
2022-03-23 3:40 ` [PATCH v3 2/3] hwmon: (adt7475) Add support for pin configuration Chris Packham
2022-04-24 16:53 ` Guenter Roeck
2022-05-02 4:36 ` Guenter Roeck
2022-03-23 3:40 ` Chris Packham [this message]
2022-04-24 16:54 ` [PATCH v3 3/3] hwmon: (adt7475) Use enum chips when loading attenuator settings Guenter Roeck
2022-05-02 4:37 ` 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=20220323034056.260455-4-chris.packham@alliedtelesis.co.nz \
--to=chris.packham@alliedtelesis.co.nz \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).