aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/net/ethernet/altera/altera_tse_main.c65
1 files changed, 44 insertions, 21 deletions
diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
index fc2d5556b715..4efc4355d345 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -728,6 +728,44 @@ static struct phy_device *connect_local_phy(struct net_device *dev)
728 return phydev; 728 return phydev;
729} 729}
730 730
731static int altera_tse_phy_get_addr_mdio_create(struct net_device *dev)
732{
733 struct altera_tse_private *priv = netdev_priv(dev);
734 struct device_node *np = priv->device->of_node;
735 int ret = 0;
736
737 priv->phy_iface = of_get_phy_mode(np);
738
739 /* Avoid get phy addr and create mdio if no phy is present */
740 if (!priv->phy_iface)
741 return 0;
742
743 /* try to get PHY address from device tree, use PHY autodetection if
744 * no valid address is given
745 */
746
747 if (of_property_read_u32(priv->device->of_node, "phy-addr",
748 &priv->phy_addr)) {
749 priv->phy_addr = POLL_PHY;
750 }
751
752 if (!((priv->phy_addr == POLL_PHY) ||
753 ((priv->phy_addr >= 0) && (priv->phy_addr < PHY_MAX_ADDR)))) {
754 netdev_err(dev, "invalid phy-addr specified %d\n",
755 priv->phy_addr);
756 return -ENODEV;
757 }
758
759 /* Create/attach to MDIO bus */
760 ret = altera_tse_mdio_create(dev,
761 atomic_add_return(1, &instance_count));
762
763 if (ret)
764 return -ENODEV;
765
766 return 0;
767}
768
731/* Initialize driver's PHY state, and attach to the PHY 769/* Initialize driver's PHY state, and attach to the PHY
732 */ 770 */
733static int init_phy(struct net_device *dev) 771static int init_phy(struct net_device *dev)
@@ -736,6 +774,10 @@ static int init_phy(struct net_device *dev)
736 struct phy_device *phydev; 774 struct phy_device *phydev;
737 struct device_node *phynode; 775 struct device_node *phynode;
738 776
777 /* Avoid init phy in case of no phy present */
778 if (!priv->phy_iface)
779 return 0;
780
739 priv->oldlink = 0; 781 priv->oldlink = 0;
740 priv->oldspeed = 0; 782 priv->oldspeed = 0;
741 priv->oldduplex = -1; 783 priv->oldduplex = -1;
@@ -1231,7 +1273,6 @@ static int altera_tse_probe(struct platform_device *pdev)
1231 struct resource *dma_res; 1273 struct resource *dma_res;
1232 struct altera_tse_private *priv; 1274 struct altera_tse_private *priv;
1233 const unsigned char *macaddr; 1275 const unsigned char *macaddr;
1234 struct device_node *np = pdev->dev.of_node;
1235 void __iomem *descmap; 1276 void __iomem *descmap;
1236 const struct of_device_id *of_id = NULL; 1277 const struct of_device_id *of_id = NULL;
1237 1278
@@ -1408,26 +1449,8 @@ static int altera_tse_probe(struct platform_device *pdev)
1408 else 1449 else
1409 eth_hw_addr_random(ndev); 1450 eth_hw_addr_random(ndev);
1410 1451
1411 priv->phy_iface = of_get_phy_mode(np); 1452 /* get phy addr and create mdio */
1412 1453 ret = altera_tse_phy_get_addr_mdio_create(ndev);
1413 /* try to get PHY address from device tree, use PHY autodetection if
1414 * no valid address is given
1415 */
1416 if (of_property_read_u32(pdev->dev.of_node, "phy-addr",
1417 &priv->phy_addr)) {
1418 priv->phy_addr = POLL_PHY;
1419 }
1420
1421 if (!((priv->phy_addr == POLL_PHY) ||
1422 ((priv->phy_addr >= 0) && (priv->phy_addr < PHY_MAX_ADDR)))) {
1423 dev_err(&pdev->dev, "invalid phy-addr specified %d\n",
1424 priv->phy_addr);
1425 goto err_free_netdev;
1426 }
1427
1428 /* Create/attach to MDIO bus */
1429 ret = altera_tse_mdio_create(ndev,
1430 atomic_add_return(1, &instance_count));
1431 1454
1432 if (ret) 1455 if (ret)
1433 goto err_free_netdev; 1456 goto err_free_netdev;