@@ -472,8 +472,42 @@ static int macb_mii_probe(struct net_device *dev)
472
472
struct macb * bp = netdev_priv (dev );
473
473
struct macb_platform_data * pdata ;
474
474
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
+ }
477
511
478
512
if (bp -> phy_node ) {
479
513
phydev = of_phy_connect (dev , bp -> phy_node ,
@@ -488,7 +522,6 @@ static int macb_mii_probe(struct net_device *dev)
488
522
return - ENXIO ;
489
523
}
490
524
491
- pdata = dev_get_platdata (& bp -> pdev -> dev );
492
525
if (pdata ) {
493
526
if (gpio_is_valid (pdata -> phy_irq_pin )) {
494
527
ret = devm_gpio_request (& bp -> pdev -> dev ,
@@ -533,7 +566,7 @@ static int macb_mii_init(struct macb *bp)
533
566
{
534
567
struct macb_platform_data * pdata ;
535
568
struct device_node * np ;
536
- int err = - ENXIO , i ;
569
+ int err , i ;
537
570
538
571
/* Enable management port */
539
572
macb_writel (bp , NCR , MACB_BIT (MPE ));
@@ -556,39 +589,9 @@ static int macb_mii_init(struct macb *bp)
556
589
dev_set_drvdata (& bp -> dev -> dev , bp -> mii_bus );
557
590
558
591
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 ;
579
592
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 );
592
595
} else {
593
596
for (i = 0 ; i < PHY_MAX_ADDR ; i ++ )
594
597
bp -> mii_bus -> irq [i ] = PHY_POLL ;
@@ -610,10 +613,10 @@ static int macb_mii_init(struct macb *bp)
610
613
611
614
err_out_unregister_bus :
612
615
mdiobus_unregister (bp -> mii_bus );
613
- err_out_free_mdiobus :
614
- of_node_put (bp -> phy_node );
615
616
if (np && of_phy_is_fixed_link (np ))
616
617
of_phy_deregister_fixed_link (np );
618
+ err_out_free_mdiobus :
619
+ of_node_put (bp -> phy_node );
617
620
mdiobus_free (bp -> mii_bus );
618
621
err_out :
619
622
return err ;
0 commit comments