aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Lozano <walter@vanguardiasur.com.ar>2014-10-03 14:09:00 -0400
committerDavid S. Miller <davem@davemloft.net>2014-10-05 21:39:40 -0400
commit004fa11861f89c54c8839119a99e87b6164dcc2c (patch)
tree5b390e3d36f7882381988e78c6f2b937f66f293e
parenta4b4a2b7f98a45c71a906b1126cabea6446a9905 (diff)
Altera TSE: Move PHY get addr and MDIO create
Move PHY get addr and MDIO create to a new function to improve readability and make it easier to avoid its usage. This will be useful for example in the case where there is no PHY chip. Signed-off-by: Walter Lozano <walter@vanguardiasur.com.ar> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/altera/altera_tse_main.c57
1 files changed, 36 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..95a30a30f7ff 100644
--- a/drivers/net/ethernet/altera/altera_tse_main.c
+++ b/drivers/net/ethernet/altera/altera_tse_main.c
@@ -728,6 +728,40 @@ 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 /* try to get PHY address from device tree, use PHY autodetection if
740 * no valid address is given
741 */
742
743 if (of_property_read_u32(priv->device->of_node, "phy-addr",
744 &priv->phy_addr)) {
745 priv->phy_addr = POLL_PHY;
746 }
747
748 if (!((priv->phy_addr == POLL_PHY) ||
749 ((priv->phy_addr >= 0) && (priv->phy_addr < PHY_MAX_ADDR)))) {
750 netdev_err(dev, "invalid phy-addr specified %d\n",
751 priv->phy_addr);
752 return -ENODEV;
753 }
754
755 /* Create/attach to MDIO bus */
756 ret = altera_tse_mdio_create(dev,
757 atomic_add_return(1, &instance_count));
758
759 if (ret)
760 return -ENODEV;
761
762 return 0;
763}
764
731/* Initialize driver's PHY state, and attach to the PHY 765/* Initialize driver's PHY state, and attach to the PHY
732 */ 766 */
733static int init_phy(struct net_device *dev) 767static int init_phy(struct net_device *dev)
@@ -1231,7 +1265,6 @@ static int altera_tse_probe(struct platform_device *pdev)
1231 struct resource *dma_res; 1265 struct resource *dma_res;
1232 struct altera_tse_private *priv; 1266 struct altera_tse_private *priv;
1233 const unsigned char *macaddr; 1267 const unsigned char *macaddr;
1234 struct device_node *np = pdev->dev.of_node;
1235 void __iomem *descmap; 1268 void __iomem *descmap;
1236 const struct of_device_id *of_id = NULL; 1269 const struct of_device_id *of_id = NULL;
1237 1270
@@ -1408,26 +1441,8 @@ static int altera_tse_probe(struct platform_device *pdev)
1408 else 1441 else
1409 eth_hw_addr_random(ndev); 1442 eth_hw_addr_random(ndev);
1410 1443
1411 priv->phy_iface = of_get_phy_mode(np); 1444 /* get phy addr and create mdio */
1412 1445 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 1446
1432 if (ret) 1447 if (ret)
1433 goto err_free_netdev; 1448 goto err_free_netdev;