From: Brad Mouring <brad.mouring@ni.com> To: Nicolas Ferre <nicolas.ferre@microchip.com>, Rob Herring <robh+dt@kernel.org>, "David S . Miller" <davem@davemloft.net>, Michael Grzeschik <m.grzeschik@pengutronix.de>, Andrew Lunn <andrew@lunn.ch> Cc: Mark Rutland <mark.rutland@arm.com>, <netdev@vger.kernel.org>, Julia Cartwright <julia@ni.com>, <devicetree@vger.kernel.org>, Brad Mouring <brad.mouring@ni.com> Subject: [PATCH v5 net-next 1/4] net: macb: Reorganize macb_mii bringup Date: Tue, 13 Mar 2018 16:32:13 -0500 [thread overview] Message-ID: <20180313213216.109153-2-brad.mouring@ni.com> (raw) In-Reply-To: <20180313213216.109153-1-brad.mouring@ni.com> The macb mii setup (mii_probe() and mii_init()) previously was somewhat interspersed, likely a result of organic growth and hacking. This change moves mii bus registration into mii_init and probing the bus for devices into mii_probe. Signed-off-by: Brad Mouring <brad.mouring@ni.com> Suggested-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> --- drivers/net/ethernet/cadence/macb_main.c | 79 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index e84afcf1ecb5..4b514c705e57 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -472,8 +472,42 @@ static int macb_mii_probe(struct net_device *dev) struct macb *bp = netdev_priv(dev); struct macb_platform_data *pdata; struct phy_device *phydev; - int phy_irq; - int ret; + struct device_node *np; + int phy_irq, ret, i; + + pdata = dev_get_platdata(&bp->pdev->dev); + np = bp->pdev->dev.of_node; + ret = 0; + + if (np) { + if (of_phy_is_fixed_link(np)) { + if (of_phy_register_fixed_link(np) < 0) { + dev_err(&bp->pdev->dev, + "broken fixed-link specification\n"); + return -ENODEV; + } + bp->phy_node = of_node_get(np); + } else { + /* fallback to standard phy registration if no phy were + * found during dt phy registration + */ + if (!phy_find_first(bp->mii_bus)) { + for (i = 0; i < PHY_MAX_ADDR; i++) { + struct phy_device *phydev; + + phydev = mdiobus_scan(bp->mii_bus, i); + if (IS_ERR(phydev) && + PTR_ERR(phydev) != -ENODEV) { + ret = PTR_ERR(phydev); + break; + } + } + + if (ret) + return -ENODEV; + } + } + } if (bp->phy_node) { phydev = of_phy_connect(dev, bp->phy_node, @@ -488,7 +522,6 @@ static int macb_mii_probe(struct net_device *dev) return -ENXIO; } - pdata = dev_get_platdata(&bp->pdev->dev); if (pdata) { if (gpio_is_valid(pdata->phy_irq_pin)) { ret = devm_gpio_request(&bp->pdev->dev, @@ -533,7 +566,7 @@ static int macb_mii_init(struct macb *bp) { struct macb_platform_data *pdata; struct device_node *np; - int err = -ENXIO, i; + int err, i; /* Enable management port */ macb_writel(bp, NCR, MACB_BIT(MPE)); @@ -556,39 +589,9 @@ static int macb_mii_init(struct macb *bp) dev_set_drvdata(&bp->dev->dev, bp->mii_bus); np = bp->pdev->dev.of_node; - if (np) { - if (of_phy_is_fixed_link(np)) { - if (of_phy_register_fixed_link(np) < 0) { - dev_err(&bp->pdev->dev, - "broken fixed-link specification\n"); - goto err_out_unregister_bus; - } - bp->phy_node = of_node_get(np); - - err = mdiobus_register(bp->mii_bus); - } else { - /* try dt phy registration */ - err = of_mdiobus_register(bp->mii_bus, np); - - /* fallback to standard phy registration if no phy were - * found during dt phy registration - */ - if (!err && !phy_find_first(bp->mii_bus)) { - for (i = 0; i < PHY_MAX_ADDR; i++) { - struct phy_device *phydev; - phydev = mdiobus_scan(bp->mii_bus, i); - if (IS_ERR(phydev) && - PTR_ERR(phydev) != -ENODEV) { - err = PTR_ERR(phydev); - break; - } - } - - if (err) - goto err_out_unregister_bus; - } - } + if (np) { + err = of_mdiobus_register(bp->mii_bus, np); } else { for (i = 0; i < PHY_MAX_ADDR; i++) bp->mii_bus->irq[i] = PHY_POLL; @@ -610,10 +613,10 @@ static int macb_mii_init(struct macb *bp) err_out_unregister_bus: mdiobus_unregister(bp->mii_bus); -err_out_free_mdiobus: - of_node_put(bp->phy_node); if (np && of_phy_is_fixed_link(np)) of_phy_deregister_fixed_link(np); +err_out_free_mdiobus: + of_node_put(bp->phy_node); mdiobus_free(bp->mii_bus); err_out: return err; -- 2.16.2
WARNING: multiple messages have this Message-ID (diff)
From: Brad Mouring <brad.mouring@ni.com> To: Nicolas Ferre <nicolas.ferre@microchip.com>, Rob Herring <robh+dt@kernel.org>, "David S . Miller" <davem@davemloft.net>, Michael Grzeschik <m.grzeschik@pengutronix.de>, Andrew Lunn <andrew@lunn.ch> Cc: Mark Rutland <mark.rutland@arm.com>, netdev@vger.kernel.org, Julia Cartwright <julia@ni.com>, devicetree@vger.kernel.org, Brad Mouring <brad.mouring@ni.com> Subject: [PATCH v5 net-next 1/4] net: macb: Reorganize macb_mii bringup Date: Tue, 13 Mar 2018 16:32:13 -0500 [thread overview] Message-ID: <20180313213216.109153-2-brad.mouring@ni.com> (raw) In-Reply-To: <20180313213216.109153-1-brad.mouring@ni.com> The macb mii setup (mii_probe() and mii_init()) previously was somewhat interspersed, likely a result of organic growth and hacking. This change moves mii bus registration into mii_init and probing the bus for devices into mii_probe. Signed-off-by: Brad Mouring <brad.mouring@ni.com> Suggested-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> --- drivers/net/ethernet/cadence/macb_main.c | 79 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c index e84afcf1ecb5..4b514c705e57 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -472,8 +472,42 @@ static int macb_mii_probe(struct net_device *dev) struct macb *bp = netdev_priv(dev); struct macb_platform_data *pdata; struct phy_device *phydev; - int phy_irq; - int ret; + struct device_node *np; + int phy_irq, ret, i; + + pdata = dev_get_platdata(&bp->pdev->dev); + np = bp->pdev->dev.of_node; + ret = 0; + + if (np) { + if (of_phy_is_fixed_link(np)) { + if (of_phy_register_fixed_link(np) < 0) { + dev_err(&bp->pdev->dev, + "broken fixed-link specification\n"); + return -ENODEV; + } + bp->phy_node = of_node_get(np); + } else { + /* fallback to standard phy registration if no phy were + * found during dt phy registration + */ + if (!phy_find_first(bp->mii_bus)) { + for (i = 0; i < PHY_MAX_ADDR; i++) { + struct phy_device *phydev; + + phydev = mdiobus_scan(bp->mii_bus, i); + if (IS_ERR(phydev) && + PTR_ERR(phydev) != -ENODEV) { + ret = PTR_ERR(phydev); + break; + } + } + + if (ret) + return -ENODEV; + } + } + } if (bp->phy_node) { phydev = of_phy_connect(dev, bp->phy_node, @@ -488,7 +522,6 @@ static int macb_mii_probe(struct net_device *dev) return -ENXIO; } - pdata = dev_get_platdata(&bp->pdev->dev); if (pdata) { if (gpio_is_valid(pdata->phy_irq_pin)) { ret = devm_gpio_request(&bp->pdev->dev, @@ -533,7 +566,7 @@ static int macb_mii_init(struct macb *bp) { struct macb_platform_data *pdata; struct device_node *np; - int err = -ENXIO, i; + int err, i; /* Enable management port */ macb_writel(bp, NCR, MACB_BIT(MPE)); @@ -556,39 +589,9 @@ static int macb_mii_init(struct macb *bp) dev_set_drvdata(&bp->dev->dev, bp->mii_bus); np = bp->pdev->dev.of_node; - if (np) { - if (of_phy_is_fixed_link(np)) { - if (of_phy_register_fixed_link(np) < 0) { - dev_err(&bp->pdev->dev, - "broken fixed-link specification\n"); - goto err_out_unregister_bus; - } - bp->phy_node = of_node_get(np); - - err = mdiobus_register(bp->mii_bus); - } else { - /* try dt phy registration */ - err = of_mdiobus_register(bp->mii_bus, np); - - /* fallback to standard phy registration if no phy were - * found during dt phy registration - */ - if (!err && !phy_find_first(bp->mii_bus)) { - for (i = 0; i < PHY_MAX_ADDR; i++) { - struct phy_device *phydev; - phydev = mdiobus_scan(bp->mii_bus, i); - if (IS_ERR(phydev) && - PTR_ERR(phydev) != -ENODEV) { - err = PTR_ERR(phydev); - break; - } - } - - if (err) - goto err_out_unregister_bus; - } - } + if (np) { + err = of_mdiobus_register(bp->mii_bus, np); } else { for (i = 0; i < PHY_MAX_ADDR; i++) bp->mii_bus->irq[i] = PHY_POLL; @@ -610,10 +613,10 @@ static int macb_mii_init(struct macb *bp) err_out_unregister_bus: mdiobus_unregister(bp->mii_bus); -err_out_free_mdiobus: - of_node_put(bp->phy_node); if (np && of_phy_is_fixed_link(np)) of_phy_deregister_fixed_link(np); +err_out_free_mdiobus: + of_node_put(bp->phy_node); mdiobus_free(bp->mii_bus); err_out: return err; -- 2.16.2
next prev parent reply other threads:[~2018-03-13 21:32 UTC|newest] Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-03-07 22:42 [PATCH 1/2] net: macb: Add phy-handle DT support Brad Mouring 2018-03-07 22:42 ` Brad Mouring 2018-03-07 22:42 ` [PATCH 2/2] Documentation: macb: Document phy-handle optional binding Brad Mouring 2018-03-07 22:42 ` Brad Mouring 2018-03-08 17:32 ` [1/2] net: macb: Add phy-handle DT support Andrew Lunn 2018-03-08 22:00 ` Brad Mouring 2018-03-08 22:00 ` Brad Mouring 2018-03-09 22:12 ` [PATCH v2 net-next 1/3] net: macb: Reorganize macb_mii bringup Brad Mouring 2018-03-09 22:12 ` Brad Mouring 2018-03-09 22:12 ` [PATCH v2 net-next 2/3] net: macb: Add phy-handle DT support Brad Mouring 2018-03-09 22:12 ` Brad Mouring 2018-03-09 22:12 ` [PATCH v2 net-next 3/3] Documentation: macb: Document phy-handle optional binding Brad Mouring 2018-03-09 22:12 ` Brad Mouring 2018-03-10 16:18 ` Andrew Lunn 2018-03-10 16:17 ` [PATCH v2 net-next 1/3] net: macb: Reorganize macb_mii bringup Andrew Lunn 2018-03-10 22:19 ` Brad Mouring 2018-03-10 22:19 ` Brad Mouring 2018-03-12 17:09 ` [PATCH v3 net-next 0/4] macb: Introduce phy-handle DT functionality Brad Mouring 2018-03-12 17:09 ` [PATCH v3 net-next 1/4] net: macb: Reorganize macb_mii bringup Brad Mouring 2018-03-12 17:09 ` Brad Mouring 2018-03-12 17:17 ` Florian Fainelli 2018-03-13 4:25 ` kbuild test robot 2018-03-13 4:25 ` kbuild test robot 2018-03-12 17:09 ` [PATCH v3 net-next 2/4] net: macb: Remove redundant poll irq assignment Brad Mouring 2018-03-12 17:09 ` Brad Mouring 2018-03-12 17:17 ` Florian Fainelli 2018-03-12 17:10 ` [PATCH v3 net-next 3/4] net: macb: Add phy-handle DT support Brad Mouring 2018-03-12 17:10 ` Brad Mouring 2018-03-12 17:59 ` Andrew Lunn 2018-03-12 21:34 ` [PATCH v4 net-next 0/4] Brad Mouring 2018-03-12 21:34 ` [PATCH v4 net-next 1/4] net: macb: Reorganize macb_mii bringup Brad Mouring 2018-03-12 21:34 ` Brad Mouring 2018-03-12 21:34 ` [PATCH v4 net-next 2/4] net: macb: Remove redundant poll irq assignment Brad Mouring 2018-03-12 21:34 ` Brad Mouring 2018-03-12 21:34 ` [PATCH v4 net-next 3/4] net: macb: Add phy-handle DT support Brad Mouring 2018-03-12 21:34 ` Brad Mouring 2018-03-12 21:57 ` Andrew Lunn 2018-03-12 22:30 ` Florian Fainelli 2018-03-13 13:49 ` Brad Mouring 2018-03-13 13:49 ` Brad Mouring 2018-03-13 21:32 ` [PATCH v5 net-next 0/4] net: macb: Introduce phy-handle DT functionality Brad Mouring 2018-03-13 21:32 ` Brad Mouring 2018-03-13 21:32 ` Brad Mouring [this message] 2018-03-13 21:32 ` [PATCH v5 net-next 1/4] net: macb: Reorganize macb_mii bringup Brad Mouring 2018-03-13 21:32 ` [PATCH v5 net-next 2/4] net: macb: Remove redundant poll irq assignment Brad Mouring 2018-03-13 21:32 ` Brad Mouring 2018-03-13 21:32 ` [PATCH v5 net-next 3/4] net: macb: Add phy-handle DT support Brad Mouring 2018-03-13 21:32 ` Brad Mouring 2018-03-13 21:32 ` [PATCH v5 net-next 4/4] Documentation: macb: Document phy-handle binding Brad Mouring 2018-03-13 21:32 ` Brad Mouring 2018-03-16 15:15 ` [PATCH v5 net-next 0/4] net: macb: Introduce phy-handle DT functionality David Miller 2018-03-12 21:34 ` [PATCH v4 net-next 4/4] Documentation: macb: Document phy-handle binding Brad Mouring 2018-03-12 21:34 ` Brad Mouring 2018-03-12 17:10 ` [PATCH v3 " Brad Mouring 2018-03-12 17:10 ` Brad Mouring 2018-03-12 17:18 ` Florian Fainelli 2018-03-11 7:02 ` [PATCH v2 net-next 1/3] net: macb: Reorganize macb_mii bringup kbuild test robot 2018-03-11 7:02 ` kbuild test robot
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180313213216.109153-2-brad.mouring@ni.com \ --to=brad.mouring@ni.com \ --cc=andrew@lunn.ch \ --cc=davem@davemloft.net \ --cc=devicetree@vger.kernel.org \ --cc=julia@ni.com \ --cc=m.grzeschik@pengutronix.de \ --cc=mark.rutland@arm.com \ --cc=netdev@vger.kernel.org \ --cc=nicolas.ferre@microchip.com \ --cc=robh+dt@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.