public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Davis <afd@ti.com>
To: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Juerg Haefliger <juergh@proton.me>,
	Riku Voipio <riku.voipio@iki.fi>
Cc: <linux-hwmon@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Andrew Davis <afd@ti.com>
Subject: [PATCH 05/31] hwmon: (adt7475) Remove use of i2c_match_id()
Date: Wed, 3 Apr 2024 15:36:07 -0500	[thread overview]
Message-ID: <20240403203633.914389-6-afd@ti.com> (raw)
In-Reply-To: <20240403203633.914389-1-afd@ti.com>

The function i2c_match_id() is used to fetch the matching ID from
the i2c_device_id table. This is often used to then retrieve the
matching driver_data. This can be done in one step with the helper
i2c_get_match_data().

This helper has a couple other benefits:
 * It doesn't need the i2c_device_id passed in so we do not need
   to have that forward declared, allowing us to remove those or
   move the i2c_device_id table down to its more natural spot
   with the other module info.
 * It also checks for device match data, which allows for OF and
   ACPI based probing. That means we do not have to manually check
   those first and can remove those checks.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/hwmon/adt7475.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 4224ffb304832..5f78e66330187 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -1676,7 +1676,6 @@ static int adt7475_probe(struct i2c_client *client)
 	struct device *hwmon_dev;
 	int i, ret = 0, revision, group_num = 0;
 	u8 config3;
-	const struct i2c_device_id *id = i2c_match_id(adt7475_id, client);
 
 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (data == NULL)
@@ -1686,10 +1685,7 @@ static int adt7475_probe(struct i2c_client *client)
 	data->client = client;
 	i2c_set_clientdata(client, data);
 
-	if (client->dev.of_node)
-		chip = (uintptr_t)of_device_get_match_data(&client->dev);
-	else
-		chip = id->driver_data;
+	chip = (uintptr_t)i2c_get_match_data(client);
 
 	/* Initialize device-specific values */
 	switch (chip) {
@@ -1717,7 +1713,7 @@ static int adt7475_probe(struct i2c_client *client)
 	if (!(config3 & CONFIG3_SMBALERT))
 		data->has_pwm2 = 1;
 	/* Meaning of this bit is inverted for the ADT7473-1 */
-	if (id->driver_data == adt7473 && revision >= 1)
+	if (chip == adt7473 && revision >= 1)
 		data->has_pwm2 = !data->has_pwm2;
 
 	data->config4 = adt7475_read(REG_CONFIG4);
@@ -1730,12 +1726,12 @@ static int adt7475_probe(struct i2c_client *client)
 	 * because 2 different pins (TACH4 and +2.5 Vin) can be used for
 	 * this function
 	 */
-	if (id->driver_data == adt7490) {
+	if (chip == adt7490) {
 		if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
 		    !(config3 & CONFIG3_THERM))
 			data->has_fan4 = 1;
 	}
-	if (id->driver_data == adt7476 || id->driver_data == adt7490) {
+	if (chip == adt7476 || chip == adt7490) {
 		if (!(config3 & CONFIG3_THERM) ||
 		    (data->config4 & CONFIG4_PINFUNC) == 0x1)
 			data->has_voltage |= (1 << 0);		/* in0 */
@@ -1745,7 +1741,7 @@ static int adt7475_probe(struct i2c_client *client)
 	 * On the ADT7476, the +12V input pin may instead be used as VID5,
 	 * and VID pins may alternatively be used as GPIO
 	 */
-	if (id->driver_data == adt7476) {
+	if (chip == adt7476) {
 		u8 vid = adt7475_read(REG_VID);
 		if (!(vid & VID_VIDSEL))
 			data->has_voltage |= (1 << 4);		/* in4 */
@@ -1829,7 +1825,7 @@ static int adt7475_probe(struct i2c_client *client)
 	}
 
 	dev_info(&client->dev, "%s device, revision %d\n",
-		 names[id->driver_data], revision);
+		 names[chip], revision);
 	if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2)
 		dev_info(&client->dev, "Optional features:%s%s%s%s%s\n",
 			 (data->has_voltage & (1 << 0)) ? " in0" : "",
-- 
2.39.2


  parent reply	other threads:[~2024-04-03 20:36 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 20:36 [PATCH 00/31] Remove use of i2c_match_id in HWMON Andrew Davis
2024-04-03 20:36 ` [PATCH 01/31] hwmon: (ad7418) Remove use of i2c_match_id() Andrew Davis
2024-04-03 20:36 ` [PATCH 02/31] hwmon: (adm1021) " Andrew Davis
2024-04-03 20:36 ` [PATCH 03/31] hwmon: (adm1031) " Andrew Davis
2024-04-03 20:36 ` [PATCH 04/31] hwmon: (ads7828) " Andrew Davis
2024-04-03 20:36 ` Andrew Davis [this message]
2024-04-03 20:36 ` [PATCH 06/31] hwmon: (aht10) " Andrew Davis
2024-04-03 20:36 ` [PATCH 07/31] hwmon: (dme1737) " Andrew Davis
2024-04-03 20:36 ` [PATCH 08/31] hwmon: (ds1621) " Andrew Davis
2024-04-03 20:36 ` [PATCH 09/31] hwmon: (f75375s) " Andrew Davis
2024-04-03 20:36 ` [PATCH 10/31] hwmon: (fschmd) " Andrew Davis
2024-04-03 20:36 ` [PATCH 11/31] hwmon: (ina2xx) " Andrew Davis
2024-04-03 20:36 ` [PATCH 12/31] hwmon: (lm63) " Andrew Davis
2024-04-03 20:36 ` [PATCH 13/31] hwmon: (lm75) " Andrew Davis
2024-04-03 20:36 ` [PATCH 14/31] hwmon: (lm78) " Andrew Davis
2024-04-03 20:36 ` [PATCH 15/31] hwmon: (lm83) " Andrew Davis
2024-04-03 20:36 ` [PATCH 16/31] hwmon: (lm85) " Andrew Davis
2024-04-03 20:36 ` [PATCH 17/31] hwmon: (lm90) " Andrew Davis
2024-04-03 20:36 ` [PATCH 18/31] hwmon: (lm95234) " Andrew Davis
2024-04-03 20:36 ` [PATCH 19/31] hwmon: (max16065) " Andrew Davis
2024-04-03 20:36 ` [PATCH 20/31] hwmon: (max1668) " Andrew Davis
2024-04-03 20:36 ` [PATCH 21/31] hwmon: (max6697) " Andrew Davis
2024-04-03 20:36 ` [PATCH 22/31] hwmon: (mcp3021) " Andrew Davis
2024-04-03 20:36 ` [PATCH 23/31] hwmon: (powr1220) " Andrew Davis
2024-04-03 20:36 ` [PATCH 24/31] hwmon: (sht3x) " Andrew Davis
2024-04-03 20:36 ` [PATCH 25/31] hwmon: (shtc1) " Andrew Davis
2024-04-03 20:36 ` [PATCH 26/31] hwmon: (thmc50) " Andrew Davis
2024-04-03 20:36 ` [PATCH 27/31] hwmon: (tmp401) " Andrew Davis
2024-04-03 20:36 ` [PATCH 28/31] hwmon: (tmp421) " Andrew Davis
2024-04-03 20:36 ` [PATCH 29/31] hwmon: (tmp464) " Andrew Davis
2024-04-03 20:36 ` [PATCH 30/31] hwmon: (w83781d) " Andrew Davis
2024-04-03 20:36 ` [PATCH 31/31] hwmon: (w83795): " Andrew Davis
2024-04-03 21:30 ` [PATCH 00/31] Remove use of i2c_match_id in HWMON Guenter Roeck
2024-04-03 22:06   ` Andrew Davis
2024-04-08 11:49     ` Guenter Roeck
2024-04-16 14:16       ` Guenter Roeck
2024-04-16 17:08         ` Andrew Davis
2024-04-18 13:42           ` Guenter Roeck
2024-06-06 17:17             ` 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=20240403203633.914389-6-afd@ti.com \
    --to=afd@ti.com \
    --cc=jdelvare@suse.com \
    --cc=juergh@proton.me \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=riku.voipio@iki.fi \
    /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