Commit 482acbd6 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'net-sfp-cleanup-i2c-dt-acpi-fwnode-includes'

Russell King says:

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

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

Link: https://lore.kernel.org/r/Y8fH+Vqx6huYQFDU@shell.armlinux.org.ukSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 3ef4a8c8 f8f24a52
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <linux/acpi.h>
#include <linux/ctype.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
...@@ -144,7 +142,7 @@ static const char *sm_state_to_str(unsigned short sm_state) ...@@ -144,7 +142,7 @@ static const char *sm_state_to_str(unsigned short sm_state)
return sm_state_strings[sm_state]; return sm_state_strings[sm_state];
} }
static const char *gpio_of_names[] = { static const char *gpio_names[] = {
"mod-def0", "mod-def0",
"los", "los",
"tx-fault", "tx-fault",
...@@ -2563,7 +2561,7 @@ static void sfp_check_state(struct sfp *sfp) ...@@ -2563,7 +2561,7 @@ static void sfp_check_state(struct sfp *sfp)
for (i = 0; i < GPIO_MAX; i++) for (i = 0; i < GPIO_MAX; i++)
if (changed & BIT(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))); !!(sfp->state & BIT(i)), !!(state & BIT(i)));
state |= sfp->state & (SFP_F_TX_DISABLE | SFP_F_RATE_SELECT); state |= sfp->state & (SFP_F_TX_DISABLE | SFP_F_RATE_SELECT);
...@@ -2644,10 +2642,8 @@ static void sfp_cleanup(void *data) ...@@ -2644,10 +2642,8 @@ static void sfp_cleanup(void *data)
static int sfp_i2c_get(struct sfp *sfp) static int sfp_i2c_get(struct sfp *sfp)
{ {
struct acpi_handle *acpi_handle;
struct fwnode_handle *h; struct fwnode_handle *h;
struct i2c_adapter *i2c; struct i2c_adapter *i2c;
struct device_node *np;
int err; int err;
h = fwnode_find_reference(dev_fwnode(sfp->dev), "i2c-bus", 0); h = fwnode_find_reference(dev_fwnode(sfp->dev), "i2c-bus", 0);
...@@ -2656,16 +2652,7 @@ static int sfp_i2c_get(struct sfp *sfp) ...@@ -2656,16 +2652,7 @@ static int sfp_i2c_get(struct sfp *sfp)
return -ENODEV; return -ENODEV;
} }
if (is_acpi_device_node(h)) { i2c = i2c_get_adapter_by_fwnode(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;
}
if (!i2c) { if (!i2c) {
err = -EPROBE_DEFER; err = -EPROBE_DEFER;
goto put; goto put;
...@@ -2696,19 +2683,11 @@ static int sfp_probe(struct platform_device *pdev) ...@@ -2696,19 +2683,11 @@ static int sfp_probe(struct platform_device *pdev)
if (err < 0) if (err < 0)
return err; return err;
sff = sfp->type = &sfp_data; sff = device_get_match_data(sfp->dev);
if (!sff)
if (pdev->dev.of_node) { sff = &sfp_data;
const struct of_device_id *id;
id = of_match_node(sfp_of_match, pdev->dev.of_node); sfp->type = sff;
if (WARN_ON(!id))
return -EINVAL;
sff = sfp->type = id->data;
} else if (!has_acpi_companion(&pdev->dev)) {
return -EINVAL;
}
err = sfp_i2c_get(sfp); err = sfp_i2c_get(sfp);
if (err) if (err)
...@@ -2717,7 +2696,7 @@ static int sfp_probe(struct platform_device *pdev) ...@@ -2717,7 +2696,7 @@ static int sfp_probe(struct platform_device *pdev)
for (i = 0; i < GPIO_MAX; i++) for (i = 0; i < GPIO_MAX; i++)
if (sff->gpios & BIT(i)) { if (sff->gpios & BIT(i)) {
sfp->gpio[i] = devm_gpiod_get_optional(sfp->dev, 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])) if (IS_ERR(sfp->gpio[i]))
return PTR_ERR(sfp->gpio[i]); return PTR_ERR(sfp->gpio[i]);
} }
...@@ -2772,7 +2751,7 @@ static int sfp_probe(struct platform_device *pdev) ...@@ -2772,7 +2751,7 @@ static int sfp_probe(struct platform_device *pdev)
sfp_irq_name = devm_kasprintf(sfp->dev, GFP_KERNEL, sfp_irq_name = devm_kasprintf(sfp->dev, GFP_KERNEL,
"%s-%s", dev_name(sfp->dev), "%s-%s", dev_name(sfp->dev),
gpio_of_names[i]); gpio_names[i]);
if (!sfp_irq_name) if (!sfp_irq_name)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment