Skip to content

Commit 1ad2ff0

Browse files
committed
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 (dacdbb4: "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: David S. Miller <[email protected]>
2 parents 2b221d2 + f3b249e commit 1ad2ff0

File tree

2 files changed

+44
-41
lines changed

2 files changed

+44
-41
lines changed

Documentation/devicetree/bindings/net/macb.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Optional properties for PHY child node:
2929
- reset-gpios : Should specify the gpio for phy reset
3030
- magic-packet : If present, indicates that the hardware supports waking
3131
up via magic packet.
32+
- phy-handle : see ethernet.txt file in the same directory
3233

3334
Examples:
3435

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,44 @@ static int macb_mii_probe(struct net_device *dev)
472472
struct macb *bp = netdev_priv(dev);
473473
struct macb_platform_data *pdata;
474474
struct phy_device *phydev;
475-
int phy_irq;
476-
int ret;
475+
struct device_node *np;
476+
int phy_irq, ret, i;
477+
478+
pdata = dev_get_platdata(&bp->pdev->dev);
479+
np = bp->pdev->dev.of_node;
480+
ret = 0;
481+
482+
if (np) {
483+
if (of_phy_is_fixed_link(np)) {
484+
if (of_phy_register_fixed_link(np) < 0) {
485+
dev_err(&bp->pdev->dev,
486+
"broken fixed-link specification\n");
487+
return -ENODEV;
488+
}
489+
bp->phy_node = of_node_get(np);
490+
} else {
491+
bp->phy_node = of_parse_phandle(np, "phy-handle", 0);
492+
/* fallback to standard phy registration if no
493+
* phy-handle was found nor any phy found during
494+
* dt phy registration
495+
*/
496+
if (!bp->phy_node && !phy_find_first(bp->mii_bus)) {
497+
for (i = 0; i < PHY_MAX_ADDR; i++) {
498+
struct phy_device *phydev;
499+
500+
phydev = mdiobus_scan(bp->mii_bus, i);
501+
if (IS_ERR(phydev) &&
502+
PTR_ERR(phydev) != -ENODEV) {
503+
ret = PTR_ERR(phydev);
504+
break;
505+
}
506+
}
507+
508+
if (ret)
509+
return -ENODEV;
510+
}
511+
}
512+
}
477513

478514
if (bp->phy_node) {
479515
phydev = of_phy_connect(dev, bp->phy_node,
@@ -488,7 +524,6 @@ static int macb_mii_probe(struct net_device *dev)
488524
return -ENXIO;
489525
}
490526

491-
pdata = dev_get_platdata(&bp->pdev->dev);
492527
if (pdata) {
493528
if (gpio_is_valid(pdata->phy_irq_pin)) {
494529
ret = devm_gpio_request(&bp->pdev->dev,
@@ -533,7 +568,7 @@ static int macb_mii_init(struct macb *bp)
533568
{
534569
struct macb_platform_data *pdata;
535570
struct device_node *np;
536-
int err = -ENXIO, i;
571+
int err;
537572

538573
/* Enable management port */
539574
macb_writel(bp, NCR, MACB_BIT(MPE));
@@ -556,43 +591,10 @@ static int macb_mii_init(struct macb *bp)
556591
dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
557592

558593
np = bp->pdev->dev.of_node;
559-
if (np) {
560-
if (of_phy_is_fixed_link(np)) {
561-
if (of_phy_register_fixed_link(np) < 0) {
562-
dev_err(&bp->pdev->dev,
563-
"broken fixed-link specification\n");
564-
goto err_out_unregister_bus;
565-
}
566-
bp->phy_node = of_node_get(np);
567-
568-
err = mdiobus_register(bp->mii_bus);
569-
} else {
570-
/* try dt phy registration */
571-
err = of_mdiobus_register(bp->mii_bus, np);
572-
573-
/* fallback to standard phy registration if no phy were
574-
* found during dt phy registration
575-
*/
576-
if (!err && !phy_find_first(bp->mii_bus)) {
577-
for (i = 0; i < PHY_MAX_ADDR; i++) {
578-
struct phy_device *phydev;
579-
580-
phydev = mdiobus_scan(bp->mii_bus, i);
581-
if (IS_ERR(phydev) &&
582-
PTR_ERR(phydev) != -ENODEV) {
583-
err = PTR_ERR(phydev);
584-
break;
585-
}
586-
}
587594

588-
if (err)
589-
goto err_out_unregister_bus;
590-
}
591-
}
595+
if (np) {
596+
err = of_mdiobus_register(bp->mii_bus, np);
592597
} else {
593-
for (i = 0; i < PHY_MAX_ADDR; i++)
594-
bp->mii_bus->irq[i] = PHY_POLL;
595-
596598
if (pdata)
597599
bp->mii_bus->phy_mask = pdata->phy_mask;
598600

@@ -610,10 +612,10 @@ static int macb_mii_init(struct macb *bp)
610612

611613
err_out_unregister_bus:
612614
mdiobus_unregister(bp->mii_bus);
613-
err_out_free_mdiobus:
614-
of_node_put(bp->phy_node);
615615
if (np && of_phy_is_fixed_link(np))
616616
of_phy_deregister_fixed_link(np);
617+
err_out_free_mdiobus:
618+
of_node_put(bp->phy_node);
617619
mdiobus_free(bp->mii_bus);
618620
err_out:
619621
return err;

0 commit comments

Comments
 (0)