diff options
author | Dmitry Lifshitz <lifshitz@compulab.co.il> | 2014-04-27 13:18:46 +0300 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-05-23 19:40:39 -0400 |
commit | a9375f3328135d651d7500df3e4c43432e5db133 (patch) | |
tree | fd9cf808d41d9ce69ce6fd086f6239be40e31a58 | |
parent | 076446f106d0732f79456485be275ad2109306f4 (diff) | |
download | u-boot-imx-a9375f3328135d651d7500df3e4c43432e5db133.zip u-boot-imx-a9375f3328135d651d7500df3e4c43432e5db133.tar.gz u-boot-imx-a9375f3328135d651d7500df3e4c43432e5db133.tar.bz2 |
cm-t54: add EEPROM support and MAC address handling
cm-t54 Eth MAC address is stored in onboard EEPROM.
Add EEPROM support and setup stored Eth MAC address.
If EEPROM does not contain a valid MAC, then generate it from the
processor ID code (reference code is taken from OMAP5 uEvm board file).
Modify Device Tree blob MAC address field with retrieved data.
Signed-off-by: Dmitry Lifshitz <lifshitz@compulab.co.il>
Acked-by: Igor Grinberg <grinberg@compulab.co.il>
-rw-r--r-- | board/compulab/cm_t54/cm_t54.c | 63 | ||||
-rw-r--r-- | include/configs/cm_t54.h | 9 |
2 files changed, 72 insertions, 0 deletions
diff --git a/board/compulab/cm_t54/cm_t54.c b/board/compulab/cm_t54/cm_t54.c index e0df47e..6b18b93 100644 --- a/board/compulab/cm_t54/cm_t54.c +++ b/board/compulab/cm_t54/cm_t54.c @@ -9,6 +9,7 @@ */ #include <common.h> +#include <fdt_support.h> #include <usb.h> #include <mmc.h> #include <palmas.h> @@ -20,6 +21,8 @@ #include <asm/arch/ehci.h> #include <asm/ehci-omap.h> +#include "../common/eeprom.h" + #define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000) #define DIE_ID_REG_OFFSET 0x200 @@ -99,6 +102,66 @@ int board_mmc_init(bd_t *bis) } #endif +#ifdef CONFIG_USB_HOST_ETHER + +void ft_board_setup(void *blob, bd_t *bd) +{ + uint8_t enetaddr[6]; + + /* MAC addr */ + if (eth_getenv_enetaddr("usbethaddr", enetaddr)) { + fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address", + enetaddr, 6, 1); + } +} + +static void generate_mac_addr(uint8_t *enetaddr) +{ + int reg; + + reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET; + + /* + * create a fake MAC address from the processor ID code. + * first byte is 0x02 to signify locally administered. + */ + enetaddr[0] = 0x02; + enetaddr[1] = readl(reg + 0x10) & 0xff; + enetaddr[2] = readl(reg + 0xC) & 0xff; + enetaddr[3] = readl(reg + 0x8) & 0xff; + enetaddr[4] = readl(reg) & 0xff; + enetaddr[5] = (readl(reg) >> 8) & 0xff; +} + +/* + * Routine: handle_mac_address + * Description: prepare MAC address for on-board Ethernet. + */ +static int handle_mac_address(void) +{ + uint8_t enetaddr[6]; + int ret; + + ret = eth_getenv_enetaddr("usbethaddr", enetaddr); + if (ret) + return 0; + + ret = cl_eeprom_read_mac_addr(enetaddr); + if (!ret || !is_valid_ether_addr(enetaddr)) + generate_mac_addr(enetaddr); + + if (!is_valid_ether_addr(enetaddr)) + return -1; + + return eth_setenv_enetaddr("usbethaddr", enetaddr); +} + +int board_eth_init(bd_t *bis) +{ + return handle_mac_address(); +} +#endif + #ifdef CONFIG_USB_EHCI static struct omap_usbhs_board_data usbhs_bdata = { .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED, diff --git a/include/configs/cm_t54.h b/include/configs/cm_t54.h index 4dcac40..5e805c4 100644 --- a/include/configs/cm_t54.h +++ b/include/configs/cm_t54.h @@ -19,6 +19,15 @@ #undef CONFIG_MISC_INIT_R #undef CONFIG_SPL_OS_BOOT +/* Device Tree defines */ +#define CONFIG_OF_LIBFDT +#define CONFIG_OF_BOARD_SETUP + +/* EEPROM related defines */ +#define CONFIG_SYS_I2C_OMAP34XX +#define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 +#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1 + /* Enable SD/MMC CD and WP GPIOs */ #define OMAP_HSMMC_USE_GPIO |