Commit 3bc427006ac8d0661169ed771b3cac7e86f960e8

Authored by Simon Glass
1 parent 7b9cf84031

dm: net: Use existing Ethernet init for driver model

At present even with driver model is used there is still much manual init
of related devices: PHY, environment and board init. Until these requirements
are dealt with in another way we need to keep them around.

Break out the init portion of the legacy eth_initialize() into a separate
function and call it from both the legacy and driver model eth_initialize()
functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

Showing 1 changed file with 42 additions and 37 deletions Side-by-side Diff

... ... @@ -82,6 +82,45 @@
82 82  
83 83 static void eth_current_changed(void);
84 84  
  85 +/*
  86 + * CPU and board-specific Ethernet initializations. Aliased function
  87 + * signals caller to move on
  88 + */
  89 +static int __def_eth_init(bd_t *bis)
  90 +{
  91 + return -1;
  92 +}
  93 +int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
  94 +int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
  95 +
  96 +static void eth_common_init(void)
  97 +{
  98 + bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
  99 +#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
  100 + miiphy_init();
  101 +#endif
  102 +
  103 +#ifdef CONFIG_PHYLIB
  104 + phy_init();
  105 +#endif
  106 +
  107 + eth_env_init();
  108 +
  109 + /*
  110 + * If board-specific initialization exists, call it.
  111 + * If not, call a CPU-specific one
  112 + */
  113 + if (board_eth_init != __def_eth_init) {
  114 + if (board_eth_init(gd->bd) < 0)
  115 + printf("Board Net Initialization Failed\n");
  116 + } else if (cpu_eth_init != __def_eth_init) {
  117 + if (cpu_eth_init(gd->bd) < 0)
  118 + printf("CPU Net Initialization Failed\n");
  119 + } else {
  120 + printf("Net Initialization Skipped\n");
  121 + }
  122 +}
  123 +
85 124 #ifdef CONFIG_DM_ETH
86 125 /**
87 126 * struct eth_device_priv - private structure for each Ethernet device
... ... @@ -392,8 +431,7 @@
392 431 int num_devices = 0;
393 432 struct udevice *dev;
394 433  
395   - bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
396   - eth_env_init();
  434 + eth_common_init();
397 435  
398 436 /*
399 437 * Devices need to write the hwaddr even if not started so that Linux
... ... @@ -520,16 +558,6 @@
520 558 #endif
521 559  
522 560 #ifndef CONFIG_DM_ETH
523   -/*
524   - * CPU and board-specific Ethernet initializations. Aliased function
525   - * signals caller to move on
526   - */
527   -static int __def_eth_init(bd_t *bis)
528   -{
529   - return -1;
530   -}
531   -int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
532   -int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
533 561  
534 562 #ifdef CONFIG_API
535 563 static struct {
536 564  
... ... @@ -706,33 +734,10 @@
706 734 int eth_initialize(void)
707 735 {
708 736 int num_devices = 0;
  737 +
709 738 eth_devices = NULL;
710 739 eth_current = NULL;
711   -
712   - bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
713   -#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
714   - miiphy_init();
715   -#endif
716   -
717   -#ifdef CONFIG_PHYLIB
718   - phy_init();
719   -#endif
720   -
721   - eth_env_init();
722   -
723   - /*
724   - * If board-specific initialization exists, call it.
725   - * If not, call a CPU-specific one
726   - */
727   - if (board_eth_init != __def_eth_init) {
728   - if (board_eth_init(gd->bd) < 0)
729   - printf("Board Net Initialization Failed\n");
730   - } else if (cpu_eth_init != __def_eth_init) {
731   - if (cpu_eth_init(gd->bd) < 0)
732   - printf("CPU Net Initialization Failed\n");
733   - } else {
734   - printf("Net Initialization Skipped\n");
735   - }
  740 + eth_common_init();
736 741  
737 742 if (!eth_devices) {
738 743 puts("No ethernet found.\n");