Commit 1ad2ff02 authored by David S. Miller's avatar David S. Miller

Merge branch 'macb-Introduce-phy-handle-DT-functionality'

Brad Mouring says:

====================
net: macb: Introduce phy-handle DT functionality

Consider the situation where a macb netdev is connected through
a phydev that sits on a mii bus other than the one provided to
this particular netdev. This situation is what this patchset aims
to accomplish through the existing phy-handle optional binding.

This optional binding (as described in the ethernet DT bindings doc)
directs the netdev to the phydev to use. This is precisely the
situation this patchset aims to solve, so it makes sense to introduce
the functionality to this driver (where the physical layout discussed
was encountered).

The devicetree snippet would look something like this:

...
   ethernet@feedf00d {
           ...
           phy-handle = <&phy0> // the first netdev is physically wired to phy0
           ...
           phy0: phy@0 {
                   ...
                   reg = <0x0> // MDIO address 0
                   ...
           }
           phy1: phy@1 {
                   ...
                   reg = <0x1> // MDIO address 1
                   ...
           }
           ...
   }

   ethernet@deadbeef {
           ...
           phy-handle = <&phy1> // tells the driver to use phy1 on the
                                // first mac's mdio bus (it's wired thusly)
           ...
   }
...

The work done to add the phy_node in the first place (dacdbb4d:
"net: macb: add fixed-link node support") will consume the
device_node (if found).

v2: Reorganization of mii probe/init functions, suggested by Andrew Lunn
v3: Moved some of the bus init code back into init (erroneously moved to probe)
    some style issues, and an unintialized variable warning addressed.
v4: Add Reviewed-by: tags
    Skip fallback code if phy-handle phandle is found
v5: Cleanup formatting issues
    Fix compile failure introduced in 1/4 "net: macb: Reorganize macb_mii
        bringup"
    Fix typo in "Documentation: macb: Document phy-handle binding"
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 2b221d20 f3b249e6
...@@ -29,6 +29,7 @@ Optional properties for PHY child node: ...@@ -29,6 +29,7 @@ Optional properties for PHY child node:
- reset-gpios : Should specify the gpio for phy reset - reset-gpios : Should specify the gpio for phy reset
- magic-packet : If present, indicates that the hardware supports waking - magic-packet : If present, indicates that the hardware supports waking
up via magic packet. up via magic packet.
- phy-handle : see ethernet.txt file in the same directory
Examples: Examples:
......
...@@ -472,8 +472,44 @@ static int macb_mii_probe(struct net_device *dev) ...@@ -472,8 +472,44 @@ static int macb_mii_probe(struct net_device *dev)
struct macb *bp = netdev_priv(dev); struct macb *bp = netdev_priv(dev);
struct macb_platform_data *pdata; struct macb_platform_data *pdata;
struct phy_device *phydev; struct phy_device *phydev;
int phy_irq; struct device_node *np;
int ret; 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 {
bp->phy_node = of_parse_phandle(np, "phy-handle", 0);
/* fallback to standard phy registration if no
* phy-handle was found nor any phy found during
* dt phy registration
*/
if (!bp->phy_node && !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) { if (bp->phy_node) {
phydev = of_phy_connect(dev, bp->phy_node, phydev = of_phy_connect(dev, bp->phy_node,
...@@ -488,7 +524,6 @@ static int macb_mii_probe(struct net_device *dev) ...@@ -488,7 +524,6 @@ static int macb_mii_probe(struct net_device *dev)
return -ENXIO; return -ENXIO;
} }
pdata = dev_get_platdata(&bp->pdev->dev);
if (pdata) { if (pdata) {
if (gpio_is_valid(pdata->phy_irq_pin)) { if (gpio_is_valid(pdata->phy_irq_pin)) {
ret = devm_gpio_request(&bp->pdev->dev, ret = devm_gpio_request(&bp->pdev->dev,
...@@ -533,7 +568,7 @@ static int macb_mii_init(struct macb *bp) ...@@ -533,7 +568,7 @@ static int macb_mii_init(struct macb *bp)
{ {
struct macb_platform_data *pdata; struct macb_platform_data *pdata;
struct device_node *np; struct device_node *np;
int err = -ENXIO, i; int err;
/* Enable management port */ /* Enable management port */
macb_writel(bp, NCR, MACB_BIT(MPE)); macb_writel(bp, NCR, MACB_BIT(MPE));
...@@ -556,43 +591,10 @@ static int macb_mii_init(struct macb *bp) ...@@ -556,43 +591,10 @@ static int macb_mii_init(struct macb *bp)
dev_set_drvdata(&bp->dev->dev, bp->mii_bus); dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
np = bp->pdev->dev.of_node; 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) if (np) {
goto err_out_unregister_bus; err = of_mdiobus_register(bp->mii_bus, np);
}
}
} else { } else {
for (i = 0; i < PHY_MAX_ADDR; i++)
bp->mii_bus->irq[i] = PHY_POLL;
if (pdata) if (pdata)
bp->mii_bus->phy_mask = pdata->phy_mask; bp->mii_bus->phy_mask = pdata->phy_mask;
...@@ -610,10 +612,10 @@ static int macb_mii_init(struct macb *bp) ...@@ -610,10 +612,10 @@ static int macb_mii_init(struct macb *bp)
err_out_unregister_bus: err_out_unregister_bus:
mdiobus_unregister(bp->mii_bus); mdiobus_unregister(bp->mii_bus);
err_out_free_mdiobus:
of_node_put(bp->phy_node);
if (np && of_phy_is_fixed_link(np)) if (np && of_phy_is_fixed_link(np))
of_phy_deregister_fixed_link(np); of_phy_deregister_fixed_link(np);
err_out_free_mdiobus:
of_node_put(bp->phy_node);
mdiobus_free(bp->mii_bus); mdiobus_free(bp->mii_bus);
err_out: err_out:
return err; return err;
......
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