Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Library to support early TI EVM EEPROM handling |
| 4 | * |
| 5 | * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * Lokesh Vutla |
| 7 | * Steve Kipisz |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | eba6b8d | 2019-11-14 12:57:50 -0700 | [diff] [blame] | 11 | #include <eeprom.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <net.h> |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 14 | #include <asm/arch/hardware.h> |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 15 | #include <asm/omap_common.h> |
Cooper Jr., Franklin | f2598de | 2017-04-20 10:25:44 -0500 | [diff] [blame] | 16 | #include <dm/uclass.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 17 | #include <env.h> |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 18 | #include <i2c.h> |
Caleb Robey | 0dfcc93 | 2020-01-02 08:17:25 -0600 | [diff] [blame] | 19 | #include <mmc.h> |
| 20 | #include <errno.h> |
| 21 | #include <malloc.h> |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 22 | |
| 23 | #include "board_detect.h" |
| 24 | |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 25 | #if !CONFIG_IS_ENABLED(DM_I2C) |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 26 | /** |
| 27 | * ti_i2c_eeprom_init - Initialize an i2c bus and probe for a device |
| 28 | * @i2c_bus: i2c bus number to initialize |
| 29 | * @dev_addr: Device address to probe for |
| 30 | * |
| 31 | * Return: 0 on success or corresponding error on failure. |
| 32 | */ |
| 33 | static int __maybe_unused ti_i2c_eeprom_init(int i2c_bus, int dev_addr) |
| 34 | { |
| 35 | int rc; |
| 36 | |
| 37 | if (i2c_bus >= 0) { |
| 38 | rc = i2c_set_bus_num(i2c_bus); |
| 39 | if (rc) |
| 40 | return rc; |
| 41 | } |
| 42 | |
| 43 | return i2c_probe(dev_addr); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * ti_i2c_eeprom_read - Read data from an EEPROM |
| 48 | * @dev_addr: The device address of the EEPROM |
| 49 | * @offset: Offset to start reading in the EEPROM |
| 50 | * @ep: Pointer to a buffer to read into |
| 51 | * @epsize: Size of buffer |
| 52 | * |
| 53 | * Return: 0 on success or corresponding result of i2c_read |
| 54 | */ |
| 55 | static int __maybe_unused ti_i2c_eeprom_read(int dev_addr, int offset, |
| 56 | uchar *ep, int epsize) |
| 57 | { |
Jean-Jacques Hiblot | 52a5151 | 2018-12-07 14:50:49 +0100 | [diff] [blame] | 58 | return i2c_read(dev_addr, offset, 2, ep, epsize); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 59 | } |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 60 | #endif |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * ti_eeprom_string_cleanup() - Handle eeprom programming errors |
| 64 | * @s: eeprom string (should be NULL terminated) |
| 65 | * |
| 66 | * Some Board manufacturers do not add a NULL termination at the |
| 67 | * end of string, instead some binary information is kludged in, hence |
| 68 | * convert the string to just printable characters of ASCII chart. |
| 69 | */ |
| 70 | static void __maybe_unused ti_eeprom_string_cleanup(char *s) |
| 71 | { |
| 72 | int i, l; |
| 73 | |
| 74 | l = strlen(s); |
| 75 | for (i = 0; i < l; i++, s++) |
| 76 | if (*s < ' ' || *s > '~') { |
| 77 | *s = 0; |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | __weak void gpi2c_init(void) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr, |
| 87 | u32 header, u32 size, uint8_t *ep) |
| 88 | { |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 89 | int rc; |
| 90 | |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 91 | #if CONFIG_IS_ENABLED(DM_I2C) |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 92 | struct udevice *dev; |
| 93 | struct udevice *bus; |
| 94 | |
| 95 | rc = uclass_get_device_by_seq(UCLASS_I2C, bus_addr, &bus); |
| 96 | if (rc) |
| 97 | return rc; |
Andreas Dannenberg | 4803492 | 2020-01-07 13:15:53 +0530 | [diff] [blame] | 98 | rc = dm_i2c_probe(bus, dev_addr, 0, &dev); |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 99 | if (rc) |
| 100 | return rc; |
| 101 | |
| 102 | /* |
| 103 | * Read the header first then only read the other contents. |
| 104 | */ |
Nishanth Menon | 9177b30 | 2022-06-17 13:26:12 -0500 | [diff] [blame] | 105 | rc = i2c_set_chip_offset_len(dev, 1); |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 106 | if (rc) |
| 107 | return rc; |
| 108 | |
Nishanth Menon | 570c3bb | 2022-06-17 13:26:11 -0500 | [diff] [blame] | 109 | /* |
| 110 | * Skip checking result here since this could be a valid i2c read fail |
Nishanth Menon | 9177b30 | 2022-06-17 13:26:12 -0500 | [diff] [blame] | 111 | * on some boards that use 2 byte addressing. |
| 112 | * We must allow for fall through to check the data if 2 byte |
Nishanth Menon | 570c3bb | 2022-06-17 13:26:11 -0500 | [diff] [blame] | 113 | * addressing works |
| 114 | */ |
Matwey V. Kornilov | b90ca70 | 2022-08-23 19:05:34 +0300 | [diff] [blame] | 115 | (void)dm_i2c_read(dev, 0, ep, size); |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 116 | |
| 117 | /* Corrupted data??? */ |
Matwey V. Kornilov | b90ca70 | 2022-08-23 19:05:34 +0300 | [diff] [blame] | 118 | if (*((u32 *)ep) != header) { |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 119 | /* |
| 120 | * read the eeprom header using i2c again, but use only a |
Nishanth Menon | 9177b30 | 2022-06-17 13:26:12 -0500 | [diff] [blame] | 121 | * 2 byte address (some newer boards need this..) |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 122 | */ |
Nishanth Menon | 9177b30 | 2022-06-17 13:26:12 -0500 | [diff] [blame] | 123 | rc = i2c_set_chip_offset_len(dev, 2); |
Michal Simek | 888f10d | 2020-08-27 15:43:48 +0200 | [diff] [blame] | 124 | if (rc) |
| 125 | return rc; |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 126 | |
Matwey V. Kornilov | b90ca70 | 2022-08-23 19:05:34 +0300 | [diff] [blame] | 127 | rc = dm_i2c_read(dev, 0, ep, size); |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 128 | if (rc) |
| 129 | return rc; |
| 130 | } |
Matwey V. Kornilov | b90ca70 | 2022-08-23 19:05:34 +0300 | [diff] [blame] | 131 | if (*((u32 *)ep) != header) |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 132 | return -1; |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 133 | #else |
| 134 | u32 byte; |
| 135 | |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 136 | gpi2c_init(); |
| 137 | rc = ti_i2c_eeprom_init(bus_addr, dev_addr); |
| 138 | if (rc) |
| 139 | return rc; |
| 140 | |
| 141 | /* |
| 142 | * Read the header first then only read the other contents. |
| 143 | */ |
Nishanth Menon | 9177b30 | 2022-06-17 13:26:12 -0500 | [diff] [blame] | 144 | byte = 1; |
Cooper Jr., Franklin | 5b89c97 | 2017-04-20 10:25:45 -0500 | [diff] [blame] | 145 | |
Nishanth Menon | 570c3bb | 2022-06-17 13:26:11 -0500 | [diff] [blame] | 146 | /* |
| 147 | * Skip checking result here since this could be a valid i2c read fail |
Nishanth Menon | 9177b30 | 2022-06-17 13:26:12 -0500 | [diff] [blame] | 148 | * on some boards that use 2 byte addressing. |
| 149 | * We must allow for fall through to check the data if 2 byte |
Nishanth Menon | 570c3bb | 2022-06-17 13:26:11 -0500 | [diff] [blame] | 150 | * addressing works |
| 151 | */ |
Matwey V. Kornilov | b90ca70 | 2022-08-23 19:05:34 +0300 | [diff] [blame] | 152 | (void)i2c_read(dev_addr, 0x0, byte, ep, size); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 153 | |
| 154 | /* Corrupted data??? */ |
Matwey V. Kornilov | b90ca70 | 2022-08-23 19:05:34 +0300 | [diff] [blame] | 155 | if (*((u32 *)ep) != header) { |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 156 | /* |
| 157 | * read the eeprom header using i2c again, but use only a |
Nishanth Menon | 9177b30 | 2022-06-17 13:26:12 -0500 | [diff] [blame] | 158 | * 2 byte address (some newer boards need this..) |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 159 | */ |
Nishanth Menon | 9177b30 | 2022-06-17 13:26:12 -0500 | [diff] [blame] | 160 | byte = 2; |
Matwey V. Kornilov | b90ca70 | 2022-08-23 19:05:34 +0300 | [diff] [blame] | 161 | rc = i2c_read(dev_addr, 0x0, byte, ep, size); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 162 | if (rc) |
| 163 | return rc; |
| 164 | } |
Matwey V. Kornilov | b90ca70 | 2022-08-23 19:05:34 +0300 | [diff] [blame] | 165 | if (*((u32 *)ep) != header) |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 166 | return -1; |
Andreas Dannenberg | e315a66 | 2018-12-07 14:50:47 +0100 | [diff] [blame] | 167 | #endif |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
Caleb Robey | 0dfcc93 | 2020-01-02 08:17:25 -0600 | [diff] [blame] | 171 | int __maybe_unused ti_emmc_boardid_get(void) |
| 172 | { |
| 173 | int rc; |
| 174 | struct udevice *dev; |
| 175 | struct mmc *mmc; |
| 176 | struct ti_common_eeprom *ep; |
| 177 | struct ti_am_eeprom brdid; |
| 178 | struct blk_desc *bdesc; |
| 179 | uchar *buffer; |
| 180 | |
| 181 | ep = TI_EEPROM_DATA; |
| 182 | if (ep->header == TI_EEPROM_HEADER_MAGIC) |
| 183 | return 0; /* EEPROM has already been read */ |
| 184 | |
| 185 | /* Initialize with a known bad marker for emmc fails.. */ |
| 186 | ep->header = TI_DEAD_EEPROM_MAGIC; |
| 187 | ep->name[0] = 0x0; |
| 188 | ep->version[0] = 0x0; |
| 189 | ep->serial[0] = 0x0; |
| 190 | ep->config[0] = 0x0; |
| 191 | |
| 192 | /* uclass object initialization */ |
| 193 | rc = mmc_initialize(NULL); |
| 194 | if (rc) |
| 195 | return rc; |
| 196 | |
| 197 | /* Set device to /dev/mmcblk1 */ |
| 198 | rc = uclass_get_device(UCLASS_MMC, 1, &dev); |
| 199 | if (rc) |
| 200 | return rc; |
| 201 | |
| 202 | /* Grab the mmc device */ |
| 203 | mmc = mmc_get_mmc_dev(dev); |
| 204 | if (!mmc) |
| 205 | return -ENODEV; |
| 206 | |
| 207 | /* mmc hardware initialization routine */ |
| 208 | mmc_init(mmc); |
| 209 | |
| 210 | /* Set partition to /dev/mmcblk1boot1 */ |
| 211 | rc = mmc_switch_part(mmc, 2); |
| 212 | if (rc) |
| 213 | return rc; |
| 214 | |
| 215 | buffer = malloc(mmc->read_bl_len); |
| 216 | if (!buffer) |
| 217 | return -ENOMEM; |
| 218 | |
| 219 | bdesc = mmc_get_blk_desc(mmc); |
| 220 | |
| 221 | /* blk_dread returns the number of blocks read*/ |
| 222 | if (blk_dread(bdesc, 0L, 1, buffer) != 1) { |
| 223 | rc = -EIO; |
| 224 | goto cleanup; |
| 225 | } |
| 226 | |
| 227 | memcpy(&brdid, buffer, sizeof(brdid)); |
| 228 | |
| 229 | /* Write out the ep struct values */ |
| 230 | ep->header = brdid.header; |
| 231 | strlcpy(ep->name, brdid.name, TI_EEPROM_HDR_NAME_LEN + 1); |
| 232 | ti_eeprom_string_cleanup(ep->name); |
| 233 | strlcpy(ep->version, brdid.version, TI_EEPROM_HDR_REV_LEN + 1); |
| 234 | ti_eeprom_string_cleanup(ep->version); |
| 235 | strlcpy(ep->serial, brdid.serial, TI_EEPROM_HDR_SERIAL_LEN + 1); |
| 236 | ti_eeprom_string_cleanup(ep->serial); |
| 237 | |
| 238 | cleanup: |
| 239 | free(buffer); |
| 240 | |
| 241 | return rc; |
| 242 | } |
| 243 | |
Nishanth Menon | 27856ff | 2017-06-16 17:25:04 -0500 | [diff] [blame] | 244 | int __maybe_unused ti_i2c_eeprom_am_set(const char *name, const char *rev) |
| 245 | { |
| 246 | struct ti_common_eeprom *ep; |
| 247 | |
| 248 | if (!name || !rev) |
| 249 | return -1; |
| 250 | |
| 251 | ep = TI_EEPROM_DATA; |
| 252 | if (ep->header == TI_EEPROM_HEADER_MAGIC) |
| 253 | goto already_set; |
| 254 | |
| 255 | /* Set to 0 all fields */ |
| 256 | memset(ep, 0, sizeof(*ep)); |
| 257 | strncpy(ep->name, name, TI_EEPROM_HDR_NAME_LEN); |
| 258 | strncpy(ep->version, rev, TI_EEPROM_HDR_REV_LEN); |
| 259 | /* Some dummy serial number to identify the platform */ |
| 260 | strncpy(ep->serial, "0000", TI_EEPROM_HDR_SERIAL_LEN); |
| 261 | /* Mark it with a valid header */ |
| 262 | ep->header = TI_EEPROM_HEADER_MAGIC; |
| 263 | |
| 264 | already_set: |
| 265 | return 0; |
| 266 | } |
| 267 | |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 268 | int __maybe_unused ti_i2c_eeprom_am_get(int bus_addr, int dev_addr) |
| 269 | { |
| 270 | int rc; |
| 271 | struct ti_am_eeprom am_ep; |
| 272 | struct ti_common_eeprom *ep; |
| 273 | |
| 274 | ep = TI_EEPROM_DATA; |
Jean-Jacques Hiblot | a096a76 | 2016-12-01 10:37:03 +0100 | [diff] [blame] | 275 | #ifndef CONFIG_SPL_BUILD |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 276 | if (ep->header == TI_EEPROM_HEADER_MAGIC) |
Jean-Jacques Hiblot | a096a76 | 2016-12-01 10:37:03 +0100 | [diff] [blame] | 277 | return 0; /* EEPROM has already been read */ |
| 278 | #endif |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 279 | |
| 280 | /* Initialize with a known bad marker for i2c fails.. */ |
| 281 | ep->header = TI_DEAD_EEPROM_MAGIC; |
| 282 | ep->name[0] = 0x0; |
| 283 | ep->version[0] = 0x0; |
| 284 | ep->serial[0] = 0x0; |
Nishanth Menon | e2b0a52 | 2016-10-11 12:39:04 -0500 | [diff] [blame] | 285 | ep->config[0] = 0x0; |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 286 | |
| 287 | rc = ti_i2c_eeprom_get(bus_addr, dev_addr, TI_EEPROM_HEADER_MAGIC, |
| 288 | sizeof(am_ep), (uint8_t *)&am_ep); |
| 289 | if (rc) |
| 290 | return rc; |
| 291 | |
| 292 | ep->header = am_ep.header; |
| 293 | strlcpy(ep->name, am_ep.name, TI_EEPROM_HDR_NAME_LEN + 1); |
| 294 | ti_eeprom_string_cleanup(ep->name); |
| 295 | |
| 296 | /* BeagleBone Green '1' eeprom, board_rev: 0x1a 0x00 0x00 0x00 */ |
| 297 | if (am_ep.version[0] == 0x1a && am_ep.version[1] == 0x00 && |
| 298 | am_ep.version[2] == 0x00 && am_ep.version[3] == 0x00) |
| 299 | strlcpy(ep->version, "BBG1", TI_EEPROM_HDR_REV_LEN + 1); |
| 300 | else |
| 301 | strlcpy(ep->version, am_ep.version, TI_EEPROM_HDR_REV_LEN + 1); |
| 302 | ti_eeprom_string_cleanup(ep->version); |
| 303 | strlcpy(ep->serial, am_ep.serial, TI_EEPROM_HDR_SERIAL_LEN + 1); |
| 304 | ti_eeprom_string_cleanup(ep->serial); |
| 305 | strlcpy(ep->config, am_ep.config, TI_EEPROM_HDR_CONFIG_LEN + 1); |
| 306 | ti_eeprom_string_cleanup(ep->config); |
| 307 | |
| 308 | memcpy(ep->mac_addr, am_ep.mac_addr, |
| 309 | TI_EEPROM_HDR_NO_OF_MAC_ADDR * TI_EEPROM_HDR_ETH_ALEN); |
| 310 | |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
Lokesh Vutla | 7c08a78 | 2016-03-08 09:18:04 +0530 | [diff] [blame] | 314 | int __maybe_unused ti_i2c_eeprom_dra7_get(int bus_addr, int dev_addr) |
| 315 | { |
| 316 | int rc, offset = 0; |
| 317 | struct dra7_eeprom dra7_ep; |
| 318 | struct ti_common_eeprom *ep; |
| 319 | |
| 320 | ep = TI_EEPROM_DATA; |
Jean-Jacques Hiblot | a096a76 | 2016-12-01 10:37:03 +0100 | [diff] [blame] | 321 | #ifndef CONFIG_SPL_BUILD |
Lokesh Vutla | 7c08a78 | 2016-03-08 09:18:04 +0530 | [diff] [blame] | 322 | if (ep->header == DRA7_EEPROM_HEADER_MAGIC) |
Jean-Jacques Hiblot | a096a76 | 2016-12-01 10:37:03 +0100 | [diff] [blame] | 323 | return 0; /* EEPROM has already been read */ |
| 324 | #endif |
Lokesh Vutla | 7c08a78 | 2016-03-08 09:18:04 +0530 | [diff] [blame] | 325 | |
| 326 | /* Initialize with a known bad marker for i2c fails.. */ |
Nishanth Menon | 21e54c0 | 2016-10-11 12:39:03 -0500 | [diff] [blame] | 327 | ep->header = TI_DEAD_EEPROM_MAGIC; |
Lokesh Vutla | 7c08a78 | 2016-03-08 09:18:04 +0530 | [diff] [blame] | 328 | ep->name[0] = 0x0; |
| 329 | ep->version[0] = 0x0; |
| 330 | ep->serial[0] = 0x0; |
Nishanth Menon | e2b0a52 | 2016-10-11 12:39:04 -0500 | [diff] [blame] | 331 | ep->config[0] = 0x0; |
Lokesh Vutla | 7c08a78 | 2016-03-08 09:18:04 +0530 | [diff] [blame] | 332 | ep->emif1_size = 0; |
| 333 | ep->emif2_size = 0; |
| 334 | |
| 335 | rc = ti_i2c_eeprom_get(bus_addr, dev_addr, DRA7_EEPROM_HEADER_MAGIC, |
| 336 | sizeof(dra7_ep), (uint8_t *)&dra7_ep); |
| 337 | if (rc) |
| 338 | return rc; |
| 339 | |
| 340 | ep->header = dra7_ep.header; |
| 341 | strlcpy(ep->name, dra7_ep.name, TI_EEPROM_HDR_NAME_LEN + 1); |
| 342 | ti_eeprom_string_cleanup(ep->name); |
| 343 | |
| 344 | offset = dra7_ep.version_major - 1; |
| 345 | |
| 346 | /* Rev F is skipped */ |
| 347 | if (offset >= 5) |
| 348 | offset = offset + 1; |
| 349 | snprintf(ep->version, TI_EEPROM_HDR_REV_LEN + 1, "%c.%d", |
| 350 | 'A' + offset, dra7_ep.version_minor); |
| 351 | ti_eeprom_string_cleanup(ep->version); |
| 352 | ep->emif1_size = (u64)dra7_ep.emif1_size; |
| 353 | ep->emif2_size = (u64)dra7_ep.emif2_size; |
| 354 | strlcpy(ep->config, dra7_ep.config, TI_EEPROM_HDR_CONFIG_LEN + 1); |
| 355 | ti_eeprom_string_cleanup(ep->config); |
| 356 | |
Lokesh Vutla | 7c08a78 | 2016-03-08 09:18:04 +0530 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 360 | static int ti_i2c_eeprom_am6_parse_record(struct ti_am6_eeprom_record *record, |
| 361 | struct ti_am6_eeprom *ep, |
| 362 | char **mac_addr, |
| 363 | u8 mac_addr_max_cnt, |
| 364 | u8 *mac_addr_cnt) |
| 365 | { |
| 366 | switch (record->header.id) { |
| 367 | case TI_AM6_EEPROM_RECORD_BOARD_INFO: |
| 368 | if (record->header.len != sizeof(record->data.board_info)) |
| 369 | return -EINVAL; |
| 370 | |
| 371 | if (!ep) |
| 372 | break; |
| 373 | |
| 374 | /* Populate (and clean, if needed) the board name */ |
| 375 | strlcpy(ep->name, record->data.board_info.name, |
| 376 | sizeof(ep->name)); |
| 377 | ti_eeprom_string_cleanup(ep->name); |
| 378 | |
| 379 | /* Populate selected other fields from the board info record */ |
| 380 | strlcpy(ep->version, record->data.board_info.version, |
| 381 | sizeof(ep->version)); |
| 382 | strlcpy(ep->software_revision, |
| 383 | record->data.board_info.software_revision, |
| 384 | sizeof(ep->software_revision)); |
| 385 | strlcpy(ep->serial, record->data.board_info.serial, |
| 386 | sizeof(ep->serial)); |
| 387 | break; |
| 388 | case TI_AM6_EEPROM_RECORD_MAC_INFO: |
| 389 | if (record->header.len != sizeof(record->data.mac_info)) |
| 390 | return -EINVAL; |
| 391 | |
| 392 | if (!mac_addr || !mac_addr_max_cnt) |
| 393 | break; |
| 394 | |
| 395 | *mac_addr_cnt = ((record->data.mac_info.mac_control & |
| 396 | TI_AM6_EEPROM_MAC_ADDR_COUNT_MASK) >> |
| 397 | TI_AM6_EEPROM_MAC_ADDR_COUNT_SHIFT) + 1; |
| 398 | |
| 399 | /* |
| 400 | * The EEPROM can (but may not) hold a very large amount |
| 401 | * of MAC addresses, by far exceeding what we want/can store |
| 402 | * in the common memory array, so only grab what we can fit. |
| 403 | * Note that a value of 0 means 1 MAC address, and so on. |
| 404 | */ |
| 405 | *mac_addr_cnt = min(*mac_addr_cnt, mac_addr_max_cnt); |
| 406 | |
| 407 | memcpy(mac_addr, record->data.mac_info.mac_addr, |
| 408 | *mac_addr_cnt * TI_EEPROM_HDR_ETH_ALEN); |
| 409 | break; |
| 410 | case 0x00: |
| 411 | /* Illegal value... Fall through... */ |
| 412 | case 0xFF: |
| 413 | /* Illegal value... Something went horribly wrong... */ |
| 414 | return -EINVAL; |
| 415 | default: |
| 416 | pr_warn("%s: Ignoring record id %u\n", __func__, |
| 417 | record->header.id); |
| 418 | } |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | int __maybe_unused ti_i2c_eeprom_am6_get(int bus_addr, int dev_addr, |
| 424 | struct ti_am6_eeprom *ep, |
| 425 | char **mac_addr, |
| 426 | u8 mac_addr_max_cnt, |
| 427 | u8 *mac_addr_cnt) |
| 428 | { |
| 429 | struct udevice *dev; |
| 430 | struct udevice *bus; |
| 431 | unsigned int eeprom_addr; |
| 432 | struct ti_am6_eeprom_record_board_id board_id; |
| 433 | struct ti_am6_eeprom_record record; |
| 434 | int rc; |
Nishanth Menon | 77c94ea | 2022-06-17 13:26:10 -0500 | [diff] [blame] | 435 | int consecutive_bad_records = 0; |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 436 | |
| 437 | /* Initialize with a known bad marker for i2c fails.. */ |
| 438 | memset(ep, 0, sizeof(*ep)); |
| 439 | ep->header = TI_DEAD_EEPROM_MAGIC; |
| 440 | |
| 441 | /* Read the board ID record which is always the first EEPROM record */ |
| 442 | rc = ti_i2c_eeprom_get(bus_addr, dev_addr, TI_EEPROM_HEADER_MAGIC, |
| 443 | sizeof(board_id), (uint8_t *)&board_id); |
| 444 | if (rc) |
| 445 | return rc; |
| 446 | |
Nishanth Menon | 892d5c0 | 2022-09-21 08:38:42 -0500 | [diff] [blame] | 447 | /* |
| 448 | * Handle case of bad 2 byte eeproms that responds to 1 byte addressing |
| 449 | * but gets stuck in const addressing when read requests are performed |
| 450 | * on offsets. We re-read the board ID to ensure we have sane data back |
| 451 | */ |
| 452 | rc = ti_i2c_eeprom_get(bus_addr, dev_addr, TI_EEPROM_HEADER_MAGIC, |
| 453 | sizeof(board_id), (uint8_t *)&board_id); |
| 454 | if (rc) |
| 455 | return rc; |
| 456 | |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 457 | if (board_id.header.id != TI_AM6_EEPROM_RECORD_BOARD_ID) { |
| 458 | pr_err("%s: Invalid board ID record!\n", __func__); |
| 459 | return -EINVAL; |
| 460 | } |
| 461 | |
| 462 | /* Establish DM handle to board config EEPROM */ |
| 463 | rc = uclass_get_device_by_seq(UCLASS_I2C, bus_addr, &bus); |
| 464 | if (rc) |
| 465 | return rc; |
| 466 | rc = i2c_get_chip(bus, dev_addr, 1, &dev); |
| 467 | if (rc) |
| 468 | return rc; |
| 469 | |
| 470 | ep->header = TI_EEPROM_HEADER_MAGIC; |
| 471 | |
| 472 | /* Ready to parse TLV structure. Initialize variables... */ |
| 473 | *mac_addr_cnt = 0; |
| 474 | |
| 475 | /* |
| 476 | * After the all-encompassing board ID record all other records follow |
| 477 | * a TLV-type scheme. Point to the first such record and then start |
| 478 | * parsing those one by one. |
| 479 | */ |
| 480 | eeprom_addr = sizeof(board_id); |
| 481 | |
Nishanth Menon | 77c94ea | 2022-06-17 13:26:10 -0500 | [diff] [blame] | 482 | while (consecutive_bad_records < 10) { |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 483 | rc = dm_i2c_read(dev, eeprom_addr, (uint8_t *)&record.header, |
| 484 | sizeof(record.header)); |
| 485 | if (rc) |
| 486 | return rc; |
| 487 | |
| 488 | /* |
| 489 | * Check for end of list marker. If we reached it don't go |
| 490 | * any further and stop parsing right here. |
| 491 | */ |
| 492 | if (record.header.id == TI_AM6_EEPROM_RECORD_END_LIST) |
| 493 | break; |
| 494 | |
| 495 | eeprom_addr += sizeof(record.header); |
| 496 | |
| 497 | debug("%s: dev_addr=0x%02x header.id=%u header.len=%u\n", |
| 498 | __func__, dev_addr, record.header.id, |
| 499 | record.header.len); |
| 500 | |
| 501 | /* Read record into memory if it fits */ |
| 502 | if (record.header.len <= sizeof(record.data)) { |
| 503 | rc = dm_i2c_read(dev, eeprom_addr, |
| 504 | (uint8_t *)&record.data, |
| 505 | record.header.len); |
| 506 | if (rc) |
| 507 | return rc; |
| 508 | |
| 509 | /* Process record */ |
| 510 | rc = ti_i2c_eeprom_am6_parse_record(&record, ep, |
| 511 | mac_addr, |
| 512 | mac_addr_max_cnt, |
| 513 | mac_addr_cnt); |
| 514 | if (rc) { |
| 515 | pr_err("%s: EEPROM parsing error!\n", __func__); |
| 516 | return rc; |
| 517 | } |
Nishanth Menon | 77c94ea | 2022-06-17 13:26:10 -0500 | [diff] [blame] | 518 | consecutive_bad_records = 0; |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 519 | } else { |
| 520 | /* |
| 521 | * We may get here in case of larger records which |
| 522 | * are not yet understood. |
| 523 | */ |
| 524 | pr_err("%s: Ignoring record id %u\n", __func__, |
| 525 | record.header.id); |
Nishanth Menon | 77c94ea | 2022-06-17 13:26:10 -0500 | [diff] [blame] | 526 | consecutive_bad_records++; |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | eeprom_addr += record.header.len; |
| 530 | } |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | int __maybe_unused ti_i2c_eeprom_am6_get_base(int bus_addr, int dev_addr) |
| 536 | { |
| 537 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 538 | int ret; |
| 539 | |
| 540 | /* |
| 541 | * Always execute EEPROM read by not allowing to bypass it during the |
| 542 | * first invocation of SPL which happens on the R5 core. |
| 543 | */ |
| 544 | #if !(defined(CONFIG_SPL_BUILD) && defined(CONFIG_CPU_V7R)) |
| 545 | if (ep->header == TI_EEPROM_HEADER_MAGIC) { |
| 546 | debug("%s: EEPROM has already been read\n", __func__); |
| 547 | return 0; |
| 548 | } |
| 549 | #endif |
| 550 | |
| 551 | ret = ti_i2c_eeprom_am6_get(bus_addr, dev_addr, ep, |
| 552 | (char **)ep->mac_addr, |
| 553 | AM6_EEPROM_HDR_NO_OF_MAC_ADDR, |
| 554 | &ep->mac_addr_cnt); |
| 555 | return ret; |
| 556 | } |
| 557 | |
Andreas Dannenberg | d036a21 | 2020-01-07 13:15:54 +0530 | [diff] [blame] | 558 | bool __maybe_unused board_ti_k3_is(char *name_tag) |
| 559 | { |
| 560 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 561 | |
| 562 | if (ep->header == TI_DEAD_EEPROM_MAGIC) |
| 563 | return false; |
| 564 | return !strncmp(ep->name, name_tag, AM6_EEPROM_HDR_NAME_LEN); |
| 565 | } |
| 566 | |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 567 | bool __maybe_unused board_ti_is(char *name_tag) |
| 568 | { |
| 569 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 570 | |
| 571 | if (ep->header == TI_DEAD_EEPROM_MAGIC) |
| 572 | return false; |
| 573 | return !strncmp(ep->name, name_tag, TI_EEPROM_HDR_NAME_LEN); |
| 574 | } |
| 575 | |
| 576 | bool __maybe_unused board_ti_rev_is(char *rev_tag, int cmp_len) |
| 577 | { |
| 578 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 579 | int l; |
| 580 | |
| 581 | if (ep->header == TI_DEAD_EEPROM_MAGIC) |
| 582 | return false; |
| 583 | |
| 584 | l = cmp_len > TI_EEPROM_HDR_REV_LEN ? TI_EEPROM_HDR_REV_LEN : cmp_len; |
| 585 | return !strncmp(ep->version, rev_tag, l); |
| 586 | } |
| 587 | |
| 588 | char * __maybe_unused board_ti_get_rev(void) |
| 589 | { |
| 590 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 591 | |
Nishanth Menon | 23afc8a | 2016-10-11 12:39:05 -0500 | [diff] [blame] | 592 | /* if ep->header == TI_DEAD_EEPROM_MAGIC, this is empty already */ |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 593 | return ep->version; |
| 594 | } |
| 595 | |
| 596 | char * __maybe_unused board_ti_get_config(void) |
| 597 | { |
| 598 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 599 | |
Nishanth Menon | 23afc8a | 2016-10-11 12:39:05 -0500 | [diff] [blame] | 600 | /* if ep->header == TI_DEAD_EEPROM_MAGIC, this is empty already */ |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 601 | return ep->config; |
| 602 | } |
| 603 | |
| 604 | char * __maybe_unused board_ti_get_name(void) |
| 605 | { |
| 606 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 607 | |
Nishanth Menon | 23afc8a | 2016-10-11 12:39:05 -0500 | [diff] [blame] | 608 | /* if ep->header == TI_DEAD_EEPROM_MAGIC, this is empty already */ |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 609 | return ep->name; |
| 610 | } |
| 611 | |
| 612 | void __maybe_unused |
| 613 | board_ti_get_eth_mac_addr(int index, |
| 614 | u8 mac_addr[TI_EEPROM_HDR_ETH_ALEN]) |
| 615 | { |
| 616 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 617 | |
| 618 | if (ep->header == TI_DEAD_EEPROM_MAGIC) |
| 619 | goto fail; |
| 620 | |
| 621 | if (index < 0 || index >= TI_EEPROM_HDR_NO_OF_MAC_ADDR) |
| 622 | goto fail; |
| 623 | |
| 624 | memcpy(mac_addr, ep->mac_addr[index], TI_EEPROM_HDR_ETH_ALEN); |
| 625 | return; |
| 626 | |
| 627 | fail: |
| 628 | memset(mac_addr, 0, TI_EEPROM_HDR_ETH_ALEN); |
| 629 | } |
| 630 | |
Andreas Dannenberg | 5a64711 | 2019-06-04 18:08:25 -0500 | [diff] [blame] | 631 | void __maybe_unused |
| 632 | board_ti_am6_get_eth_mac_addr(int index, |
| 633 | u8 mac_addr[TI_EEPROM_HDR_ETH_ALEN]) |
| 634 | { |
| 635 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 636 | |
| 637 | if (ep->header == TI_DEAD_EEPROM_MAGIC) |
| 638 | goto fail; |
| 639 | |
| 640 | if (index < 0 || index >= ep->mac_addr_cnt) |
| 641 | goto fail; |
| 642 | |
| 643 | memcpy(mac_addr, ep->mac_addr[index], TI_EEPROM_HDR_ETH_ALEN); |
| 644 | return; |
| 645 | |
| 646 | fail: |
| 647 | memset(mac_addr, 0, TI_EEPROM_HDR_ETH_ALEN); |
| 648 | } |
| 649 | |
Lokesh Vutla | 7c08a78 | 2016-03-08 09:18:04 +0530 | [diff] [blame] | 650 | u64 __maybe_unused board_ti_get_emif1_size(void) |
| 651 | { |
| 652 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 653 | |
| 654 | if (ep->header != DRA7_EEPROM_HEADER_MAGIC) |
| 655 | return 0; |
| 656 | |
| 657 | return ep->emif1_size; |
| 658 | } |
| 659 | |
| 660 | u64 __maybe_unused board_ti_get_emif2_size(void) |
| 661 | { |
| 662 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 663 | |
| 664 | if (ep->header != DRA7_EEPROM_HEADER_MAGIC) |
| 665 | return 0; |
| 666 | |
| 667 | return ep->emif2_size; |
| 668 | } |
| 669 | |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 670 | void __maybe_unused set_board_info_env(char *name) |
| 671 | { |
| 672 | char *unknown = "unknown"; |
| 673 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 674 | |
| 675 | if (name) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 676 | env_set("board_name", name); |
Tom Rini | d1449cb | 2020-06-04 15:45:08 -0400 | [diff] [blame] | 677 | else if (strlen(ep->name) != 0) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 678 | env_set("board_name", ep->name); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 679 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 680 | env_set("board_name", unknown); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 681 | |
Tom Rini | d1449cb | 2020-06-04 15:45:08 -0400 | [diff] [blame] | 682 | if (strlen(ep->version) != 0) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 683 | env_set("board_rev", ep->version); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 684 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 685 | env_set("board_rev", unknown); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 686 | |
Tom Rini | d1449cb | 2020-06-04 15:45:08 -0400 | [diff] [blame] | 687 | if (strlen(ep->serial) != 0) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 688 | env_set("board_serial", ep->serial); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 689 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 690 | env_set("board_serial", unknown); |
Lokesh Vutla | 35f7a97 | 2016-02-24 12:30:54 -0600 | [diff] [blame] | 691 | } |
Roger Quadros | 44c7d9a | 2017-03-14 15:04:19 +0200 | [diff] [blame] | 692 | |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 693 | void __maybe_unused set_board_info_env_am6(char *name) |
| 694 | { |
| 695 | char *unknown = "unknown"; |
| 696 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 697 | |
| 698 | if (name) |
| 699 | env_set("board_name", name); |
Tom Rini | d1449cb | 2020-06-04 15:45:08 -0400 | [diff] [blame] | 700 | else if (strlen(ep->name) != 0) |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 701 | env_set("board_name", ep->name); |
| 702 | else |
| 703 | env_set("board_name", unknown); |
| 704 | |
Tom Rini | d1449cb | 2020-06-04 15:45:08 -0400 | [diff] [blame] | 705 | if (strlen(ep->version) != 0) |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 706 | env_set("board_rev", ep->version); |
| 707 | else |
| 708 | env_set("board_rev", unknown); |
| 709 | |
Tom Rini | d1449cb | 2020-06-04 15:45:08 -0400 | [diff] [blame] | 710 | if (strlen(ep->software_revision) != 0) |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 711 | env_set("board_software_revision", ep->software_revision); |
| 712 | else |
| 713 | env_set("board_software_revision", unknown); |
| 714 | |
Tom Rini | d1449cb | 2020-06-04 15:45:08 -0400 | [diff] [blame] | 715 | if (strlen(ep->serial) != 0) |
Andreas Dannenberg | f998a82 | 2019-06-04 18:08:24 -0500 | [diff] [blame] | 716 | env_set("board_serial", ep->serial); |
| 717 | else |
| 718 | env_set("board_serial", unknown); |
| 719 | } |
| 720 | |
Roger Quadros | 44c7d9a | 2017-03-14 15:04:19 +0200 | [diff] [blame] | 721 | static u64 mac_to_u64(u8 mac[6]) |
| 722 | { |
| 723 | int i; |
| 724 | u64 addr = 0; |
| 725 | |
| 726 | for (i = 0; i < 6; i++) { |
| 727 | addr <<= 8; |
| 728 | addr |= mac[i]; |
| 729 | } |
| 730 | |
| 731 | return addr; |
| 732 | } |
| 733 | |
| 734 | static void u64_to_mac(u64 addr, u8 mac[6]) |
| 735 | { |
| 736 | mac[5] = addr; |
| 737 | mac[4] = addr >> 8; |
| 738 | mac[3] = addr >> 16; |
| 739 | mac[2] = addr >> 24; |
| 740 | mac[1] = addr >> 32; |
| 741 | mac[0] = addr >> 40; |
| 742 | } |
| 743 | |
| 744 | void board_ti_set_ethaddr(int index) |
| 745 | { |
| 746 | uint8_t mac_addr[6]; |
| 747 | int i; |
| 748 | u64 mac1, mac2; |
| 749 | u8 mac_addr1[6], mac_addr2[6]; |
| 750 | int num_macs; |
| 751 | /* |
| 752 | * Export any Ethernet MAC addresses from EEPROM. |
| 753 | * The 2 MAC addresses in EEPROM define the address range. |
| 754 | */ |
| 755 | board_ti_get_eth_mac_addr(0, mac_addr1); |
| 756 | board_ti_get_eth_mac_addr(1, mac_addr2); |
| 757 | |
| 758 | if (is_valid_ethaddr(mac_addr1) && is_valid_ethaddr(mac_addr2)) { |
| 759 | mac1 = mac_to_u64(mac_addr1); |
| 760 | mac2 = mac_to_u64(mac_addr2); |
| 761 | |
| 762 | /* must contain an address range */ |
| 763 | num_macs = mac2 - mac1 + 1; |
| 764 | if (num_macs <= 0) |
| 765 | return; |
| 766 | |
| 767 | if (num_macs > 50) { |
| 768 | printf("%s: Too many MAC addresses: %d. Limiting to 50\n", |
| 769 | __func__, num_macs); |
| 770 | num_macs = 50; |
| 771 | } |
| 772 | |
| 773 | for (i = 0; i < num_macs; i++) { |
| 774 | u64_to_mac(mac1 + i, mac_addr); |
| 775 | if (is_valid_ethaddr(mac_addr)) { |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 776 | eth_env_set_enetaddr_by_index("eth", i + index, |
| 777 | mac_addr); |
Roger Quadros | 44c7d9a | 2017-03-14 15:04:19 +0200 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | } |
| 781 | } |
Cooper Jr., Franklin | e1328c7 | 2017-06-16 17:25:08 -0500 | [diff] [blame] | 782 | |
Andreas Dannenberg | 5a64711 | 2019-06-04 18:08:25 -0500 | [diff] [blame] | 783 | void board_ti_am6_set_ethaddr(int index, int count) |
| 784 | { |
| 785 | u8 mac_addr[6]; |
| 786 | int i; |
| 787 | |
| 788 | for (i = 0; i < count; i++) { |
| 789 | board_ti_am6_get_eth_mac_addr(i, mac_addr); |
| 790 | if (is_valid_ethaddr(mac_addr)) |
| 791 | eth_env_set_enetaddr_by_index("eth", i + index, |
| 792 | mac_addr); |
| 793 | } |
| 794 | } |
| 795 | |
Cooper Jr., Franklin | e1328c7 | 2017-06-16 17:25:08 -0500 | [diff] [blame] | 796 | bool __maybe_unused board_ti_was_eeprom_read(void) |
| 797 | { |
| 798 | struct ti_common_eeprom *ep = TI_EEPROM_DATA; |
| 799 | |
| 800 | if (ep->header == TI_EEPROM_HEADER_MAGIC) |
| 801 | return true; |
| 802 | else |
| 803 | return false; |
| 804 | } |