Skip to content

Commit dacdbb4

Browse files
mgrzeschikdavem330
authored andcommitted
net: macb: add fixed-link node support
In case the MACB is directly connected to a non-mdio PHY/device, it should be possible to provide a fixed link configuration in the DT. Signed-off-by: Michael Grzeschik <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 24a72b7 commit dacdbb4

File tree

2 files changed

+60
-39
lines changed

2 files changed

+60
-39
lines changed

drivers/net/ethernet/cadence/macb.c

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -425,32 +425,40 @@ static int macb_mii_probe(struct net_device *dev)
425425
int phy_irq;
426426
int ret;
427427

428-
phydev = phy_find_first(bp->mii_bus);
429-
if (!phydev) {
430-
netdev_err(dev, "no PHY found\n");
431-
return -ENXIO;
432-
}
428+
if (bp->phy_node) {
429+
phydev = of_phy_connect(dev, bp->phy_node,
430+
&macb_handle_link_change, 0,
431+
bp->phy_interface);
432+
if (!phydev)
433+
return -ENODEV;
434+
} else {
435+
phydev = phy_find_first(bp->mii_bus);
436+
if (!phydev) {
437+
netdev_err(dev, "no PHY found\n");
438+
return -ENXIO;
439+
}
433440

434-
pdata = dev_get_platdata(&bp->pdev->dev);
435-
if (pdata) {
436-
if (gpio_is_valid(pdata->phy_irq_pin)) {
437-
ret = devm_gpio_request(&bp->pdev->dev,
438-
pdata->phy_irq_pin, "phy int");
439-
if (!ret) {
440-
phy_irq = gpio_to_irq(pdata->phy_irq_pin);
441-
phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
441+
pdata = dev_get_platdata(&bp->pdev->dev);
442+
if (pdata) {
443+
if (gpio_is_valid(pdata->phy_irq_pin)) {
444+
ret = devm_gpio_request(&bp->pdev->dev,
445+
pdata->phy_irq_pin, "phy int");
446+
if (!ret) {
447+
phy_irq = gpio_to_irq(pdata->phy_irq_pin);
448+
phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
449+
}
450+
} else {
451+
phydev->irq = PHY_POLL;
442452
}
443-
} else {
444-
phydev->irq = PHY_POLL;
445453
}
446-
}
447454

448-
/* attach the mac to the phy */
449-
ret = phy_connect_direct(dev, phydev, &macb_handle_link_change,
450-
bp->phy_interface);
451-
if (ret) {
452-
netdev_err(dev, "Could not attach to PHY\n");
453-
return ret;
455+
/* attach the mac to the phy */
456+
ret = phy_connect_direct(dev, phydev, &macb_handle_link_change,
457+
bp->phy_interface);
458+
if (ret) {
459+
netdev_err(dev, "Could not attach to PHY\n");
460+
return ret;
461+
}
454462
}
455463

456464
/* mask with MAC supported features */
@@ -499,26 +507,37 @@ static int macb_mii_init(struct macb *bp)
499507

500508
np = bp->pdev->dev.of_node;
501509
if (np) {
502-
/* try dt phy registration */
503-
err = of_mdiobus_register(bp->mii_bus, np);
510+
if (of_phy_is_fixed_link(np)) {
511+
if (of_phy_register_fixed_link(np) < 0) {
512+
dev_err(&bp->pdev->dev,
513+
"broken fixed-link specification\n");
514+
goto err_out_unregister_bus;
515+
}
516+
bp->phy_node = of_node_get(np);
504517

505-
/* fallback to standard phy registration if no phy were
506-
* found during dt phy registration
507-
*/
508-
if (!err && !phy_find_first(bp->mii_bus)) {
509-
for (i = 0; i < PHY_MAX_ADDR; i++) {
510-
struct phy_device *phydev;
511-
512-
phydev = mdiobus_scan(bp->mii_bus, i);
513-
if (IS_ERR(phydev) &&
514-
PTR_ERR(phydev) != -ENODEV) {
515-
err = PTR_ERR(phydev);
516-
break;
518+
err = mdiobus_register(bp->mii_bus);
519+
} else {
520+
/* try dt phy registration */
521+
err = of_mdiobus_register(bp->mii_bus, np);
522+
523+
/* fallback to standard phy registration if no phy were
524+
* found during dt phy registration
525+
*/
526+
if (!err && !phy_find_first(bp->mii_bus)) {
527+
for (i = 0; i < PHY_MAX_ADDR; i++) {
528+
struct phy_device *phydev;
529+
530+
phydev = mdiobus_scan(bp->mii_bus, i);
531+
if (IS_ERR(phydev) &&
532+
PTR_ERR(phydev) != -ENODEV) {
533+
err = PTR_ERR(phydev);
534+
break;
535+
}
517536
}
518-
}
519537

520-
if (err)
521-
goto err_out_unregister_bus;
538+
if (err)
539+
goto err_out_unregister_bus;
540+
}
522541
}
523542
} else {
524543
for (i = 0; i < PHY_MAX_ADDR; i++)
@@ -3438,6 +3457,7 @@ static int macb_remove(struct platform_device *pdev)
34383457
clk_disable_unprepare(bp->hclk);
34393458
clk_disable_unprepare(bp->pclk);
34403459
clk_disable_unprepare(bp->rx_clk);
3460+
of_node_put(bp->phy_node);
34413461
free_netdev(dev);
34423462
}
34433463

drivers/net/ethernet/cadence/macb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ struct macb {
930930
struct macb_or_gem_ops macbgem_ops;
931931

932932
struct mii_bus *mii_bus;
933+
struct device_node *phy_node;
933934
int link;
934935
int speed;
935936
int duplex;

0 commit comments

Comments
 (0)