Commit a9375f3328135d651d7500df3e4c43432e5db133
Committed by
Tom Rini
1 parent
076446f106
Exists in
v2017.01-smarct4x
and in
40 other branches
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>
Showing 2 changed files with 72 additions and 0 deletions Side-by-side Diff
board/compulab/cm_t54/cm_t54.c
... | ... | @@ -9,6 +9,7 @@ |
9 | 9 | */ |
10 | 10 | |
11 | 11 | #include <common.h> |
12 | +#include <fdt_support.h> | |
12 | 13 | #include <usb.h> |
13 | 14 | #include <mmc.h> |
14 | 15 | #include <palmas.h> |
... | ... | @@ -20,6 +21,8 @@ |
20 | 21 | #include <asm/arch/ehci.h> |
21 | 22 | #include <asm/ehci-omap.h> |
22 | 23 | |
24 | +#include "../common/eeprom.h" | |
25 | + | |
23 | 26 | #define DIE_ID_REG_BASE (OMAP54XX_L4_CORE_BASE + 0x2000) |
24 | 27 | #define DIE_ID_REG_OFFSET 0x200 |
25 | 28 | |
... | ... | @@ -96,6 +99,66 @@ |
96 | 99 | return -1; |
97 | 100 | |
98 | 101 | return 0; |
102 | +} | |
103 | +#endif | |
104 | + | |
105 | +#ifdef CONFIG_USB_HOST_ETHER | |
106 | + | |
107 | +void ft_board_setup(void *blob, bd_t *bd) | |
108 | +{ | |
109 | + uint8_t enetaddr[6]; | |
110 | + | |
111 | + /* MAC addr */ | |
112 | + if (eth_getenv_enetaddr("usbethaddr", enetaddr)) { | |
113 | + fdt_find_and_setprop(blob, "/smsc95xx@0", "mac-address", | |
114 | + enetaddr, 6, 1); | |
115 | + } | |
116 | +} | |
117 | + | |
118 | +static void generate_mac_addr(uint8_t *enetaddr) | |
119 | +{ | |
120 | + int reg; | |
121 | + | |
122 | + reg = DIE_ID_REG_BASE + DIE_ID_REG_OFFSET; | |
123 | + | |
124 | + /* | |
125 | + * create a fake MAC address from the processor ID code. | |
126 | + * first byte is 0x02 to signify locally administered. | |
127 | + */ | |
128 | + enetaddr[0] = 0x02; | |
129 | + enetaddr[1] = readl(reg + 0x10) & 0xff; | |
130 | + enetaddr[2] = readl(reg + 0xC) & 0xff; | |
131 | + enetaddr[3] = readl(reg + 0x8) & 0xff; | |
132 | + enetaddr[4] = readl(reg) & 0xff; | |
133 | + enetaddr[5] = (readl(reg) >> 8) & 0xff; | |
134 | +} | |
135 | + | |
136 | +/* | |
137 | + * Routine: handle_mac_address | |
138 | + * Description: prepare MAC address for on-board Ethernet. | |
139 | + */ | |
140 | +static int handle_mac_address(void) | |
141 | +{ | |
142 | + uint8_t enetaddr[6]; | |
143 | + int ret; | |
144 | + | |
145 | + ret = eth_getenv_enetaddr("usbethaddr", enetaddr); | |
146 | + if (ret) | |
147 | + return 0; | |
148 | + | |
149 | + ret = cl_eeprom_read_mac_addr(enetaddr); | |
150 | + if (!ret || !is_valid_ether_addr(enetaddr)) | |
151 | + generate_mac_addr(enetaddr); | |
152 | + | |
153 | + if (!is_valid_ether_addr(enetaddr)) | |
154 | + return -1; | |
155 | + | |
156 | + return eth_setenv_enetaddr("usbethaddr", enetaddr); | |
157 | +} | |
158 | + | |
159 | +int board_eth_init(bd_t *bis) | |
160 | +{ | |
161 | + return handle_mac_address(); | |
99 | 162 | } |
100 | 163 | #endif |
101 | 164 |
include/configs/cm_t54.h
... | ... | @@ -19,6 +19,15 @@ |
19 | 19 | #undef CONFIG_MISC_INIT_R |
20 | 20 | #undef CONFIG_SPL_OS_BOOT |
21 | 21 | |
22 | +/* Device Tree defines */ | |
23 | +#define CONFIG_OF_LIBFDT | |
24 | +#define CONFIG_OF_BOARD_SETUP | |
25 | + | |
26 | +/* EEPROM related defines */ | |
27 | +#define CONFIG_SYS_I2C_OMAP34XX | |
28 | +#define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 | |
29 | +#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 1 | |
30 | + | |
22 | 31 | /* Enable SD/MMC CD and WP GPIOs */ |
23 | 32 | #define OMAP_HSMMC_USE_GPIO |
24 | 33 |