Commit f411b5cca48f0eee9443b85e7b75a46356bd2327

Authored by Roger Quadros
Committed by Joe Hershberger
1 parent e607ec993b

board: am335x: Always set eth/eth1addr environment variable

Ethernet ports might be used in the kernel even if CPSW driver
is disabled at u-boot. So always set ethaddr and eth1addr
environment variable from efuse.

Retain usbnet_devaddr as it is required for SPL USB eth boot.

Signed-off-by: Roger Quadros <rogerq@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

Showing 1 changed file with 46 additions and 26 deletions Side-by-side Diff

board/ti/am335x/board.c
... ... @@ -50,10 +50,7 @@
50 50 #define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
51 51 #define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
52 52  
53   -#if defined(CONFIG_SPL_BUILD) || \
54   - (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_DM_ETH))
55 53 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
56   -#endif
57 54  
58 55 #define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
59 56 #define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
... ... @@ -639,6 +636,11 @@
639 636 #ifdef CONFIG_BOARD_LATE_INIT
640 637 int board_late_init(void)
641 638 {
  639 +#if !defined(CONFIG_SPL_BUILD)
  640 + uint8_t mac_addr[6];
  641 + uint32_t mac_hi, mac_lo;
  642 +#endif
  643 +
642 644 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
643 645 int rc;
644 646 char *name = NULL;
... ... @@ -652,6 +654,39 @@
652 654 set_board_info_env(name);
653 655 #endif
654 656  
  657 +#if !defined(CONFIG_SPL_BUILD)
  658 + /* try reading mac address from efuse */
  659 + mac_lo = readl(&cdev->macid0l);
  660 + mac_hi = readl(&cdev->macid0h);
  661 + mac_addr[0] = mac_hi & 0xFF;
  662 + mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  663 + mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  664 + mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  665 + mac_addr[4] = mac_lo & 0xFF;
  666 + mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  667 +
  668 + if (!getenv("ethaddr")) {
  669 + printf("<ethaddr> not set. Validating first E-fuse MAC\n");
  670 +
  671 + if (is_valid_ethaddr(mac_addr))
  672 + eth_setenv_enetaddr("ethaddr", mac_addr);
  673 + }
  674 +
  675 + mac_lo = readl(&cdev->macid1l);
  676 + mac_hi = readl(&cdev->macid1h);
  677 + mac_addr[0] = mac_hi & 0xFF;
  678 + mac_addr[1] = (mac_hi & 0xFF00) >> 8;
  679 + mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
  680 + mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
  681 + mac_addr[4] = mac_lo & 0xFF;
  682 + mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  683 +
  684 + if (!getenv("eth1addr")) {
  685 + if (is_valid_ethaddr(mac_addr))
  686 + eth_setenv_enetaddr("eth1addr", mac_addr);
  687 + }
  688 +#endif
  689 +
655 690 return 0;
656 691 }
657 692 #endif
658 693  
659 694  
... ... @@ -720,11 +755,15 @@
720 755 int board_eth_init(bd_t *bis)
721 756 {
722 757 int rv, n = 0;
  758 +#if defined(CONFIG_USB_ETHER) && \
  759 + (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
723 760 uint8_t mac_addr[6];
724 761 uint32_t mac_hi, mac_lo;
725   - __maybe_unused struct ti_am_eeprom *header;
726 762  
727   - /* try reading mac address from efuse */
  763 + /*
  764 + * use efuse mac address for USB ethernet as we know that
  765 + * both CPSW and USB ethernet will never be active at the same time
  766 + */
728 767 mac_lo = readl(&cdev->macid0l);
729 768 mac_hi = readl(&cdev->macid0h);
730 769 mac_addr[0] = mac_hi & 0xFF;
731 770  
732 771  
733 772  
734 773  
... ... @@ -733,32 +772,13 @@
733 772 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
734 773 mac_addr[4] = mac_lo & 0xFF;
735 774 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
  775 +#endif
736 776  
  777 +
737 778 #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
738 779 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
739   - if (!getenv("ethaddr")) {
740   - printf("<ethaddr> not set. Validating first E-fuse MAC\n");
741 780  
742   - if (is_valid_ethaddr(mac_addr))
743   - eth_setenv_enetaddr("ethaddr", mac_addr);
744   - }
745   -
746 781 #ifdef CONFIG_DRIVER_TI_CPSW
747   -
748   - mac_lo = readl(&cdev->macid1l);
749   - mac_hi = readl(&cdev->macid1h);
750   - mac_addr[0] = mac_hi & 0xFF;
751   - mac_addr[1] = (mac_hi & 0xFF00) >> 8;
752   - mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
753   - mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
754   - mac_addr[4] = mac_lo & 0xFF;
755   - mac_addr[5] = (mac_lo & 0xFF00) >> 8;
756   -
757   - if (!getenv("eth1addr")) {
758   - if (is_valid_ethaddr(mac_addr))
759   - eth_setenv_enetaddr("eth1addr", mac_addr);
760   - }
761   -
762 782 if (read_eeprom() < 0)
763 783 puts("Could not get board ID.\n");
764 784