From ff31a0c496b8eb6728fdfb8091df50653523aa19 Mon Sep 17 00:00:00 2001 From: "Russell King (Oracle)" Date: Wed, 18 Jan 2023 10:20:58 +0000 Subject: [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. Reviewed-by: Mika Westerberg Signed-off-by: Russell King (Oracle) Signed-off-by: Jakub Kicinski --- 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; From b71dda81123f4158d4c9d079123c5b460af7a526 Mon Sep 17 00:00:00 2001 From: "Russell King (Oracle)" Date: Wed, 18 Jan 2023 10:21:03 +0000 Subject: [PATCH 2/5] net: sfp: use device_get_match_data() 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) Signed-off-by: Jakub Kicinski --- 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) From f35cb547865ca32084b108d79c44ddb71117b42d Mon Sep 17 00:00:00 2001 From: "Russell King (Oracle)" Date: Wed, 18 Jan 2023 10:21:08 +0000 Subject: [PATCH 3/5] net: sfp: rename gpio_of_names[] There's nothing DT specific about the gpio_of_names array, let's drop the _of infix. Signed-off-by: Russell King (Oracle) Signed-off-by: Jakub Kicinski --- 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; From 1154261ef0fb5df1ce819cb84e94e4fe0def3838 Mon Sep 17 00:00:00 2001 From: "Russell King (Oracle)" Date: Wed, 18 Jan 2023 10:21:13 +0000 Subject: [PATCH 4/5] net: sfp: remove acpi.h include 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) Signed-off-by: Jakub Kicinski --- 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 #include #include #include From f8f24a524114be2bcb4efbebcb37ab04c5b46c94 Mon Sep 17 00:00:00 2001 From: "Russell King (Oracle)" Date: Wed, 18 Jan 2023 10:21:18 +0000 Subject: [PATCH 5/5] net: sfp: remove unused ctype.h include 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) Signed-off-by: Jakub Kicinski --- 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 #include #include #include