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 <m.grzeschik@pengutronix.de> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
24a72b77f3
commit
dacdbb4dfc
2 changed files with 64 additions and 43 deletions
|
@ -425,32 +425,40 @@ static int macb_mii_probe(struct net_device *dev)
|
||||||
int phy_irq;
|
int phy_irq;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
phydev = phy_find_first(bp->mii_bus);
|
if (bp->phy_node) {
|
||||||
if (!phydev) {
|
phydev = of_phy_connect(dev, bp->phy_node,
|
||||||
netdev_err(dev, "no PHY found\n");
|
&macb_handle_link_change, 0,
|
||||||
return -ENXIO;
|
bp->phy_interface);
|
||||||
}
|
if (!phydev)
|
||||||
|
return -ENODEV;
|
||||||
pdata = dev_get_platdata(&bp->pdev->dev);
|
} else {
|
||||||
if (pdata) {
|
phydev = phy_find_first(bp->mii_bus);
|
||||||
if (gpio_is_valid(pdata->phy_irq_pin)) {
|
if (!phydev) {
|
||||||
ret = devm_gpio_request(&bp->pdev->dev,
|
netdev_err(dev, "no PHY found\n");
|
||||||
pdata->phy_irq_pin, "phy int");
|
return -ENXIO;
|
||||||
if (!ret) {
|
|
||||||
phy_irq = gpio_to_irq(pdata->phy_irq_pin);
|
|
||||||
phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
phydev->irq = PHY_POLL;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* attach the mac to the phy */
|
pdata = dev_get_platdata(&bp->pdev->dev);
|
||||||
ret = phy_connect_direct(dev, phydev, &macb_handle_link_change,
|
if (pdata) {
|
||||||
bp->phy_interface);
|
if (gpio_is_valid(pdata->phy_irq_pin)) {
|
||||||
if (ret) {
|
ret = devm_gpio_request(&bp->pdev->dev,
|
||||||
netdev_err(dev, "Could not attach to PHY\n");
|
pdata->phy_irq_pin, "phy int");
|
||||||
return ret;
|
if (!ret) {
|
||||||
|
phy_irq = gpio_to_irq(pdata->phy_irq_pin);
|
||||||
|
phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
phydev->irq = PHY_POLL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* attach the mac to the phy */
|
||||||
|
ret = phy_connect_direct(dev, phydev, &macb_handle_link_change,
|
||||||
|
bp->phy_interface);
|
||||||
|
if (ret) {
|
||||||
|
netdev_err(dev, "Could not attach to PHY\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mask with MAC supported features */
|
/* mask with MAC supported features */
|
||||||
|
@ -499,26 +507,37 @@ static int macb_mii_init(struct macb *bp)
|
||||||
|
|
||||||
np = bp->pdev->dev.of_node;
|
np = bp->pdev->dev.of_node;
|
||||||
if (np) {
|
if (np) {
|
||||||
/* try dt phy registration */
|
if (of_phy_is_fixed_link(np)) {
|
||||||
err = of_mdiobus_register(bp->mii_bus, np);
|
if (of_phy_register_fixed_link(np) < 0) {
|
||||||
|
dev_err(&bp->pdev->dev,
|
||||||
/* fallback to standard phy registration if no phy were
|
"broken fixed-link specification\n");
|
||||||
* 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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < PHY_MAX_ADDR; i++)
|
for (i = 0; i < PHY_MAX_ADDR; i++)
|
||||||
|
@ -3438,6 +3457,7 @@ static int macb_remove(struct platform_device *pdev)
|
||||||
clk_disable_unprepare(bp->hclk);
|
clk_disable_unprepare(bp->hclk);
|
||||||
clk_disable_unprepare(bp->pclk);
|
clk_disable_unprepare(bp->pclk);
|
||||||
clk_disable_unprepare(bp->rx_clk);
|
clk_disable_unprepare(bp->rx_clk);
|
||||||
|
of_node_put(bp->phy_node);
|
||||||
free_netdev(dev);
|
free_netdev(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -930,6 +930,7 @@ struct macb {
|
||||||
struct macb_or_gem_ops macbgem_ops;
|
struct macb_or_gem_ops macbgem_ops;
|
||||||
|
|
||||||
struct mii_bus *mii_bus;
|
struct mii_bus *mii_bus;
|
||||||
|
struct device_node *phy_node;
|
||||||
int link;
|
int link;
|
||||||
int speed;
|
int speed;
|
||||||
int duplex;
|
int duplex;
|
||||||
|
|
Loading…
Add table
Reference in a new issue