@@ -472,8 +472,42 @@ 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+ /* fallback to standard phy registration if no phy were
492+ * found during dt phy registration
493+ */
494+ if (!phy_find_first (bp -> mii_bus )) {
495+ for (i = 0 ; i < PHY_MAX_ADDR ; i ++ ) {
496+ struct phy_device * phydev ;
497+
498+ phydev = mdiobus_scan (bp -> mii_bus , i );
499+ if (IS_ERR (phydev ) &&
500+ PTR_ERR (phydev ) != - ENODEV ) {
501+ ret = PTR_ERR (phydev );
502+ break ;
503+ }
504+ }
505+
506+ if (ret )
507+ return - ENODEV ;
508+ }
509+ }
510+ }
477511
478512 if (bp -> phy_node ) {
479513 phydev = of_phy_connect (dev , bp -> phy_node ,
@@ -488,7 +522,6 @@ static int macb_mii_probe(struct net_device *dev)
488522 return - ENXIO ;
489523 }
490524
491- pdata = dev_get_platdata (& bp -> pdev -> dev );
492525 if (pdata ) {
493526 if (gpio_is_valid (pdata -> phy_irq_pin )) {
494527 ret = devm_gpio_request (& bp -> pdev -> dev ,
@@ -533,7 +566,7 @@ static int macb_mii_init(struct macb *bp)
533566{
534567 struct macb_platform_data * pdata ;
535568 struct device_node * np ;
536- int err = - ENXIO , i ;
569+ int err , i ;
537570
538571 /* Enable management port */
539572 macb_writel (bp , NCR , MACB_BIT (MPE ));
@@ -556,39 +589,9 @@ static int macb_mii_init(struct macb *bp)
556589 dev_set_drvdata (& bp -> dev -> dev , bp -> mii_bus );
557590
558591 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 ;
579592
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- }
587-
588- if (err )
589- goto err_out_unregister_bus ;
590- }
591- }
593+ if (np ) {
594+ err = of_mdiobus_register (bp -> mii_bus , np );
592595 } else {
593596 for (i = 0 ; i < PHY_MAX_ADDR ; i ++ )
594597 bp -> mii_bus -> irq [i ] = PHY_POLL ;
@@ -610,10 +613,10 @@ static int macb_mii_init(struct macb *bp)
610613
611614err_out_unregister_bus :
612615 mdiobus_unregister (bp -> mii_bus );
613- err_out_free_mdiobus :
614- of_node_put (bp -> phy_node );
615616 if (np && of_phy_is_fixed_link (np ))
616617 of_phy_deregister_fixed_link (np );
618+ err_out_free_mdiobus :
619+ of_node_put (bp -> phy_node );
617620 mdiobus_free (bp -> mii_bus );
618621err_out :
619622 return err ;
0 commit comments