This simplifies the code, removing the need to handle active low
flags, etc.

Signed-off-by: Andrew Lunn <and...@lunn.ch>
---
 drivers/net/phy/mdio-gpio.c             | 73 ++++++-------------------
 include/linux/platform_data/mdio-gpio.h | 10 +---
 2 files changed, 20 insertions(+), 63 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");
diff --git a/include/linux/platform_data/mdio-gpio.h 
b/include/linux/platform_data/mdio-gpio.h
index af3be0c4ff9b..bd91fa98a3aa 100644
--- a/include/linux/platform_data/mdio-gpio.h
+++ b/include/linux/platform_data/mdio-gpio.h
@@ -15,13 +15,9 @@
 
 struct mdio_gpio_platform_data {
        /* GPIO numbers for bus pins */
-       unsigned int mdc;
-       unsigned int mdio;
-       unsigned int mdo;
-
-       bool mdc_active_low;
-       bool mdio_active_low;
-       bool mdo_active_low;
+       struct gpio_desc *mdc;
+       struct gpio_desc *mdio;
+       struct gpio_desc *mdo;
 };
 
 #endif /* __LINUX_MDIO_GPIO_H */
-- 
2.17.0

Reply via email to