netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes
@ 2023-01-18 10:20 Russell King (Oracle)
  2023-01-18 10:20 ` [PATCH net-next 1/5] net: sfp: use i2c_get_adapter_by_fwnode() Russell King (Oracle)
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2023-01-18 10:20 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev, Paolo Abeni

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(-)

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next 1/5] net: sfp: use i2c_get_adapter_by_fwnode()
  2023-01-18 10:20 [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes Russell King (Oracle)
@ 2023-01-18 10:20 ` Russell King (Oracle)
  2023-01-18 10:21 ` [PATCH net-next 2/5] net: sfp: use device_get_match_data() Russell King (Oracle)
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2023-01-18 10:20 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev, Paolo Abeni

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.

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/sfp.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 83b99d95b278..aa2f7ebbdebc 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -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;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 2/5] net: sfp: use device_get_match_data()
  2023-01-18 10:20 [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes Russell King (Oracle)
  2023-01-18 10:20 ` [PATCH net-next 1/5] net: sfp: use i2c_get_adapter_by_fwnode() Russell King (Oracle)
@ 2023-01-18 10:21 ` Russell King (Oracle)
  2023-01-18 10:21 ` [PATCH net-next 3/5] net: sfp: rename gpio_of_names[] Russell King (Oracle)
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2023-01-18 10:21 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev, Paolo Abeni

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.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/sfp.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index aa2f7ebbdebc..402dcdd59acb 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -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)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 3/5] net: sfp: rename gpio_of_names[]
  2023-01-18 10:20 [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes Russell King (Oracle)
  2023-01-18 10:20 ` [PATCH net-next 1/5] net: sfp: use i2c_get_adapter_by_fwnode() Russell King (Oracle)
  2023-01-18 10:21 ` [PATCH net-next 2/5] net: sfp: use device_get_match_data() Russell King (Oracle)
@ 2023-01-18 10:21 ` Russell King (Oracle)
  2023-01-18 10:21 ` [PATCH net-next 4/5] net: sfp: remove acpi.h include Russell King (Oracle)
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2023-01-18 10:21 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev, Paolo Abeni

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

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/sfp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 402dcdd59acb..64dfc5f1ea7b 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -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;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 4/5] net: sfp: remove acpi.h include
  2023-01-18 10:20 [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes Russell King (Oracle)
                   ` (2 preceding siblings ...)
  2023-01-18 10:21 ` [PATCH net-next 3/5] net: sfp: rename gpio_of_names[] Russell King (Oracle)
@ 2023-01-18 10:21 ` Russell King (Oracle)
  2023-01-18 10:21 ` [PATCH net-next 5/5] net: sfp: remove unused ctype.h include Russell King (Oracle)
  2023-01-20  3:00 ` [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2023-01-18 10:21 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev, Paolo Abeni

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

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/sfp.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 64dfc5f1ea7b..99cd2b538126 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -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>
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next 5/5] net: sfp: remove unused ctype.h include
  2023-01-18 10:20 [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes Russell King (Oracle)
                   ` (3 preceding siblings ...)
  2023-01-18 10:21 ` [PATCH net-next 4/5] net: sfp: remove acpi.h include Russell King (Oracle)
@ 2023-01-18 10:21 ` Russell King (Oracle)
  2023-01-20  3:00 ` [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: Russell King (Oracle) @ 2023-01-18 10:21 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev, Paolo Abeni

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.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/sfp.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
index 99cd2b538126..c02cad6478a8 100644
--- a/drivers/net/phy/sfp.c
+++ b/drivers/net/phy/sfp.c
@@ -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>
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes
  2023-01-18 10:20 [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes Russell King (Oracle)
                   ` (4 preceding siblings ...)
  2023-01-18 10:21 ` [PATCH net-next 5/5] net: sfp: remove unused ctype.h include Russell King (Oracle)
@ 2023-01-20  3:00 ` patchwork-bot+netdevbpf
  5 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-20  3:00 UTC (permalink / raw)
  To: Russell King; +Cc: andrew, hkallweit1, davem, edumazet, kuba, netdev, pabeni

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-20  3:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-18 10:20 [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes Russell King (Oracle)
2023-01-18 10:20 ` [PATCH net-next 1/5] net: sfp: use i2c_get_adapter_by_fwnode() Russell King (Oracle)
2023-01-18 10:21 ` [PATCH net-next 2/5] net: sfp: use device_get_match_data() Russell King (Oracle)
2023-01-18 10:21 ` [PATCH net-next 3/5] net: sfp: rename gpio_of_names[] Russell King (Oracle)
2023-01-18 10:21 ` [PATCH net-next 4/5] net: sfp: remove acpi.h include Russell King (Oracle)
2023-01-18 10:21 ` [PATCH net-next 5/5] net: sfp: remove unused ctype.h include Russell King (Oracle)
2023-01-20  3:00 ` [PATCH net-next 0/5] net: sfp: cleanup i2c / dt / acpi / fwnode / includes patchwork-bot+netdevbpf

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).