diff options
author | Andrew Lunn <andrew@lunn.ch> | 2018-04-19 01:02:55 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-04-19 15:59:11 -0400 |
commit | c82fc4814a93f36c9b536b5af8dd617e4ee1380f (patch) | |
tree | 6fa54592de0f543199f95f63f0a0a81e74f7be10 /drivers/net/phy/mdio-gpio.c | |
parent | 68abb4f25d7eaf4d5f40108aa748621ddab68209 (diff) | |
download | linux-stable-c82fc4814a93f36c9b536b5af8dd617e4ee1380f.tar.gz linux-stable-c82fc4814a93f36c9b536b5af8dd617e4ee1380f.tar.bz2 linux-stable-c82fc4814a93f36c9b536b5af8dd617e4ee1380f.zip |
net: phy: mdio-gpio: Swap to using gpio descriptors
This simplifies the code, removing the need to handle active low
flags, etc.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/mdio-gpio.c')
-rw-r--r-- | drivers/net/phy/mdio-gpio.c | 73 |
1 files changed, 17 insertions, 56 deletions
diff --git a/drivers/net/phy/mdio-gpio.c b/drivers/net/phy/mdio-gpio.c index 0f8c748c8edd..b999f32374e2 100644 --- a/drivers/net/phy/mdio-gpio.c +++ b/drivers/net/phy/mdio-gpio.c @@ -35,35 +35,25 @@ struct mdio_gpio_info { struct gpio_desc *mdc, *mdio, *mdo; }; -static void *mdio_gpio_of_get_data(struct platform_device *pdev) +static void *mdio_gpio_of_get_data(struct device *dev) { - struct device_node *np = pdev->dev.of_node; struct mdio_gpio_platform_data *pdata; - enum of_gpio_flags flags; - int ret; - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return NULL; - ret = of_get_gpio_flags(np, 0, &flags); - if (ret < 0) - return NULL; - - pdata->mdc = ret; - pdata->mdc_active_low = flags & OF_GPIO_ACTIVE_LOW; + pdata->mdc = devm_gpiod_get_index(dev, NULL, 0, GPIOD_OUT_LOW); + if (IS_ERR(pdata->mdc)) + return ERR_CAST(pdata->mdc); - ret = of_get_gpio_flags(np, 1, &flags); - if (ret < 0) - return NULL; - pdata->mdio = ret; - pdata->mdio_active_low = flags & OF_GPIO_ACTIVE_LOW; + pdata->mdio = devm_gpiod_get_index(dev, NULL, 1, GPIOD_IN); + if (IS_ERR(pdata->mdio)) + return ERR_CAST(pdata->mdio); - ret = of_get_gpio_flags(np, 2, &flags); - if (ret > 0) { - pdata->mdo = ret; - pdata->mdo_active_low = flags & OF_GPIO_ACTIVE_LOW; - } + pdata->mdo = devm_gpiod_get_index_optional(dev, NULL, 2, GPIOD_OUT_LOW); + if (IS_ERR(pdata->mdo)) + return ERR_CAST(pdata->mdo); return pdata; } @@ -130,34 +120,19 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev, { struct mii_bus *new_bus; struct mdio_gpio_info *bitbang; - int mdc, mdio, mdo; - unsigned long mdc_flags = GPIOF_OUT_INIT_LOW; - unsigned long mdio_flags = GPIOF_DIR_IN; - unsigned long mdo_flags = GPIOF_OUT_INIT_HIGH; bitbang = devm_kzalloc(dev, sizeof(*bitbang), GFP_KERNEL); if (!bitbang) - goto out; + return NULL; bitbang->ctrl.ops = &mdio_gpio_ops; - mdc = pdata->mdc; - bitbang->mdc = gpio_to_desc(mdc); - if (pdata->mdc_active_low) - mdc_flags = GPIOF_OUT_INIT_HIGH | GPIOF_ACTIVE_LOW; - mdio = pdata->mdio; - bitbang->mdio = gpio_to_desc(mdio); - if (pdata->mdio_active_low) - mdio_flags |= GPIOF_ACTIVE_LOW; - mdo = pdata->mdo; - if (mdo) { - bitbang->mdo = gpio_to_desc(mdo); - if (pdata->mdo_active_low) - mdo_flags = GPIOF_OUT_INIT_LOW | GPIOF_ACTIVE_LOW; - } + bitbang->mdc = pdata->mdc; + bitbang->mdio = pdata->mdio; + bitbang->mdo = pdata->mdo; new_bus = alloc_mdio_bitbang(&bitbang->ctrl); if (!new_bus) - goto out; + return NULL; new_bus->name = "GPIO Bitbanged MDIO"; new_bus->parent = dev; @@ -167,23 +142,9 @@ static struct mii_bus *mdio_gpio_bus_init(struct device *dev, else strncpy(new_bus->id, "gpio", MII_BUS_ID_SIZE); - if (devm_gpio_request_one(dev, mdc, mdc_flags, "mdc")) - goto out_free_bus; - - if (devm_gpio_request_one(dev, mdio, mdio_flags, "mdio")) - goto out_free_bus; - - if (mdo && devm_gpio_request_one(dev, mdo, mdo_flags, "mdo")) - goto out_free_bus; - dev_set_drvdata(dev, new_bus); return new_bus; - -out_free_bus: - free_mdio_bitbang(new_bus); -out: - return NULL; } static void mdio_gpio_bus_deinit(struct device *dev) @@ -208,7 +169,7 @@ static int mdio_gpio_probe(struct platform_device *pdev) int ret, bus_id; if (pdev->dev.of_node) { - pdata = mdio_gpio_of_get_data(pdev); + pdata = mdio_gpio_of_get_data(&pdev->dev); bus_id = of_alias_get_id(pdev->dev.of_node, "mdio-gpio"); if (bus_id < 0) { dev_warn(&pdev->dev, "failed to get alias id\n"); |