Skip to contentSkip to conversation

net: sfp: cleanup i2c / dt / acpi / fwnode / includes

PATCH Applied Russell King (Oracle) 3 participants 7 messages Jan 18, 2023 – Jan 20, 2023

Subsystems (4)
lore
Share & tools
lore

Russell King (Oracle)

author maintainer
#0 lore raw

cover net: sfp: cleanup i2c / dt / acpi / fwnode / includes

Hi,

This series cleans up the DT/fwnode/ACPI code in the SFP cage driver:

1. Use the newly introduced i2c_get_adapter_by_fwnode(), which removes the need to know about ACPI handles to find the I2C device.

2. Use device_get_match_data() to get the match data, rather than having to look up the matching DT device_id to get at the data.

3. Rename gpio_of_names, as this is not DT specific.

4. Remove acpi.h include which is no longer necessary.

5. Remove ctype.h include which, as far as I can tell, was never necessary.

 drivers/net/phy/sfp.c | 39 +++++++++------------------------------
 1 file changed, 9 insertions(+), 30 deletions(-)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
#1 lore raw

PATCH 1/5 net: sfp: use i2c_get_adapter_by_fwnode()

Use the newly introduced i2c_get_adapter_by_fwnode() API, so that we can retrieve the I2C adapter in a firmware independent manner once we have the fwnode handle for the adapter.

---
 drivers/net/phy/sfp.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/net/phy/sfp.c +1 -12
index 83b99d95b278..aa2f7ebbdebc 100644
@@ -2644,10 +2644,8 @@ static void sfp_cleanup(void *data)
 
 static int sfp_i2c_get(struct sfp *sfp)
 {
-	struct acpi_handle *acpi_handle;
 	struct fwnode_handle *h;
 	struct i2c_adapter *i2c;
-	struct device_node *np;
 	int err;
 
 	h = fwnode_find_reference(dev_fwnode(sfp->dev), "i2c-bus", 0);
@@ -2656,16 +2654,7 @@ static int sfp_i2c_get(struct sfp *sfp)
 		return -ENODEV;
 	}
 
-	if (is_acpi_device_node(h)) {
-		acpi_handle = ACPI_HANDLE_FWNODE(h);
-		i2c = i2c_acpi_find_adapter_by_handle(acpi_handle);
-	} else if ((np = to_of_node(h)) != NULL) {
-		i2c = of_find_i2c_adapter_by_node(np);
-	} else {
-		err = -EINVAL;
-		goto put;
-	}
-
+	i2c = i2c_get_adapter_by_fwnode(h);
 	if (!i2c) {
 		err = -EPROBE_DEFER;
 		goto put;
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/5 net: sfp: use device_get_match_data()

In reply to Russell King (Oracle)

Rather than using of_match_node() to get the matching of_device_id to then retrieve the match data, use device_get_match_data() instead to avoid firmware specific functions, and free the driver from having firmware specific code.

---
 drivers/net/phy/sfp.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/net/phy/sfp.c +4 -12
index aa2f7ebbdebc..402dcdd59acb 100644
@@ -2685,19 +2685,11 @@ static int sfp_probe(struct platform_device *pdev)
 	if (err < 0)
 		return err;
 
-	sff = sfp->type = &sfp_data;
+	sff = device_get_match_data(sfp->dev);
+	if (!sff)
+		sff = &sfp_data;
 
-	if (pdev->dev.of_node) {
-		const struct of_device_id *id;
-
-		id = of_match_node(sfp_of_match, pdev->dev.of_node);
-		if (WARN_ON(!id))
-			return -EINVAL;
-
-		sff = sfp->type = id->data;
-	} else if (!has_acpi_companion(&pdev->dev)) {
-		return -EINVAL;
-	}
+	sfp->type = sff;
 
 	err = sfp_i2c_get(sfp);
 	if (err)
Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/5 net: sfp: rename gpio_of_names[]

In reply to Russell King (Oracle)

There's nothing DT specific about the gpio_of_names array, let's drop the _of infix.

---
 drivers/net/phy/sfp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/phy/sfp.c +4 -4
index 402dcdd59acb..64dfc5f1ea7b 100644
@@ -144,7 +144,7 @@ static const char *sm_state_to_str(unsigned short sm_state)
 	return sm_state_strings[sm_state];
 }
 
-static const char *gpio_of_names[] = {
+static const char *gpio_names[] = {
 	"mod-def0",
 	"los",
 	"tx-fault",
@@ -2563,7 +2563,7 @@ static void sfp_check_state(struct sfp *sfp)
 
 	for (i = 0; i < GPIO_MAX; i++)
 		if (changed & BIT(i))
-			dev_dbg(sfp->dev, "%s %u -> %u\n", gpio_of_names[i],
+			dev_dbg(sfp->dev, "%s %u -> %u\n", gpio_names[i],
 				!!(sfp->state & BIT(i)), !!(state & BIT(i)));
 
 	state |= sfp->state & (SFP_F_TX_DISABLE | SFP_F_RATE_SELECT);
@@ -2698,7 +2698,7 @@ static int sfp_probe(struct platform_device *pdev)
 	for (i = 0; i < GPIO_MAX; i++)
 		if (sff->gpios & BIT(i)) {
 			sfp->gpio[i] = devm_gpiod_get_optional(sfp->dev,
-					   gpio_of_names[i], gpio_flags[i]);
+					   gpio_names[i], gpio_flags[i]);
 			if (IS_ERR(sfp->gpio[i]))
 				return PTR_ERR(sfp->gpio[i]);
 		}
@@ -2753,7 +2753,7 @@ static int sfp_probe(struct platform_device *pdev)
 
 		sfp_irq_name = devm_kasprintf(sfp->dev, GFP_KERNEL,
 					      "%s-%s", dev_name(sfp->dev),
-					      gpio_of_names[i]);
+					      gpio_names[i]);
 
 		if (!sfp_irq_name)
 			return -ENOMEM;
Signature · 1 line
2.30.2
#4 lore raw

PATCH 4/5 net: sfp: remove acpi.h include

In reply to Russell King (Oracle)

Nothing in the sfp code now references anything from the ACPI header, everything is done via fwnode APIs, so get rid of this header.

---
 drivers/net/phy/sfp.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/phy/sfp.c +0 -1
index 64dfc5f1ea7b..99cd2b538126 100644
@@ -1,5 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/acpi.h>
 #include <linux/ctype.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
Signature · 1 line
2.30.2
#5 lore raw

PATCH 5/5 net: sfp: remove unused ctype.h include

In reply to Russell King (Oracle)

An include of linux/ctype.h was added in commit 1323061a018a ("net: phy: sfp: Add HWMON support for module sensors") but nothing was used from this header file. Remove this unnecessary include.

---
 drivers/net/phy/sfp.c | 1 -
 1 file changed, 1 deletion(-)
drivers/net/phy/sfp.c +0 -1
index 99cd2b538126..c02cad6478a8 100644
@@ -1,5 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#include <linux/ctype.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
Signature · 1 line
2.30.2
#6 lore raw
In reply to Russell King (Oracle)
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 18 Jan 2023 10:20:41 +0000 you wrote:

Hi,

This series cleans up the DT/fwnode/ACPI code in the SFP cage driver:

1. Use the newly introduced i2c_get_adapter_by_fwnode(), which removes the need to know about ACPI handles to find the I2C device.

[...]

Here is the summary with links:
- [net-next,1/5] net: sfp: use i2c_get_adapter_by_fwnode()

    https://git.kernel.org/netdev/net-next/c/ff31a0c496b8
  - [net-next,2/5] net: sfp: use device_get_match_data()
    https://git.kernel.org/netdev/net-next/c/b71dda81123f
  - [net-next,3/5] net: sfp: rename gpio_of_names[]
    https://git.kernel.org/netdev/net-next/c/f35cb547865c
  - [net-next,4/5] net: sfp: remove acpi.h include
    https://git.kernel.org/netdev/net-next/c/1154261ef0fb
  - [net-next,5/5] net: sfp: remove unused ctype.h include
    https://git.kernel.org/netdev/net-next/c/f8f24a524114

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html