Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Marek Behun <marek.behun@nic.cz> |
| 4 | * Copyright (C) 2016 Tomas Hlavacek <tomas.hlavacek@nic.cz> |
| 5 | * |
| 6 | * Derived from the code for |
| 7 | * Marvell/db-88f6820-gp by Stefan Roese <sr@denx.de> |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 11 | #include <environment.h> |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 12 | #include <i2c.h> |
| 13 | #include <miiphy.h> |
| 14 | #include <netdev.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/cpu.h> |
| 17 | #include <asm/arch/soc.h> |
| 18 | #include <dm/uclass.h> |
| 19 | #include <fdt_support.h> |
| 20 | #include <time.h> |
| 21 | |
| 22 | #ifdef CONFIG_ATSHA204A |
| 23 | # include <atsha204a-i2c.h> |
| 24 | #endif |
| 25 | |
| 26 | #ifdef CONFIG_WDT_ORION |
| 27 | # include <wdt.h> |
| 28 | #endif |
| 29 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 30 | #include "../drivers/ddr/marvell/a38x/ddr3_init.h" |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 31 | #include <../serdes/a38x/high_speed_env_spec.h> |
| 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Pierre Bourdon | 9a1386f | 2019-04-11 01:00:23 +0200 | [diff] [blame] | 35 | #define OMNIA_I2C_EEPROM_DM_NAME "i2c@11000->i2cmux@70->i2c@0" |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 36 | #define OMNIA_I2C_EEPROM 0x54 |
| 37 | #define OMNIA_I2C_EEPROM_CONFIG_ADDR 0x0 |
| 38 | #define OMNIA_I2C_EEPROM_ADDRLEN 2 |
| 39 | #define OMNIA_I2C_EEPROM_MAGIC 0x0341a034 |
| 40 | |
Pierre Bourdon | 9a1386f | 2019-04-11 01:00:23 +0200 | [diff] [blame] | 41 | #define OMNIA_I2C_MCU_DM_NAME "i2c@11000->i2cmux@70->i2c@0" |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 42 | #define OMNIA_I2C_MCU_ADDR_STATUS 0x1 |
| 43 | #define OMNIA_I2C_MCU_SATA 0x20 |
| 44 | #define OMNIA_I2C_MCU_CARDDET 0x10 |
| 45 | #define OMNIA_I2C_MCU 0x2a |
| 46 | #define OMNIA_I2C_MCU_WDT_ADDR 0x0b |
| 47 | |
| 48 | #define OMNIA_ATSHA204_OTP_VERSION 0 |
| 49 | #define OMNIA_ATSHA204_OTP_SERIAL 1 |
| 50 | #define OMNIA_ATSHA204_OTP_MAC0 3 |
| 51 | #define OMNIA_ATSHA204_OTP_MAC1 4 |
| 52 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 53 | /* |
| 54 | * Those values and defines are taken from the Marvell U-Boot version |
| 55 | * "u-boot-2013.01-2014_T3.0" |
| 56 | */ |
| 57 | #define OMNIA_GPP_OUT_ENA_LOW \ |
| 58 | (~(BIT(1) | BIT(4) | BIT(6) | BIT(7) | BIT(8) | BIT(9) | \ |
| 59 | BIT(10) | BIT(11) | BIT(19) | BIT(22) | BIT(23) | BIT(25) | \ |
| 60 | BIT(26) | BIT(27) | BIT(29) | BIT(30) | BIT(31))) |
| 61 | #define OMNIA_GPP_OUT_ENA_MID \ |
| 62 | (~(BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(15) | \ |
| 63 | BIT(16) | BIT(17) | BIT(18))) |
| 64 | |
| 65 | #define OMNIA_GPP_OUT_VAL_LOW 0x0 |
| 66 | #define OMNIA_GPP_OUT_VAL_MID 0x0 |
| 67 | #define OMNIA_GPP_POL_LOW 0x0 |
| 68 | #define OMNIA_GPP_POL_MID 0x0 |
| 69 | |
| 70 | static struct serdes_map board_serdes_map_pex[] = { |
| 71 | {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 72 | {USB3_HOST0, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 73 | {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 74 | {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 75 | {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 76 | {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0} |
| 77 | }; |
| 78 | |
| 79 | static struct serdes_map board_serdes_map_sata[] = { |
| 80 | {SATA0, SERDES_SPEED_6_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 81 | {USB3_HOST0, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 82 | {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 83 | {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 84 | {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 85 | {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0} |
| 86 | }; |
| 87 | |
| 88 | static bool omnia_detect_sata(void) |
| 89 | { |
| 90 | struct udevice *bus, *dev; |
Marek Behún | d0b374d | 2017-08-04 15:28:25 +0200 | [diff] [blame] | 91 | int ret, retry = 3; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 92 | u16 mode; |
| 93 | |
| 94 | puts("SERDES0 card detect: "); |
| 95 | |
| 96 | if (uclass_get_device_by_name(UCLASS_I2C, OMNIA_I2C_MCU_DM_NAME, &bus)) { |
| 97 | puts("Cannot find MCU bus!\n"); |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | ret = i2c_get_chip(bus, OMNIA_I2C_MCU, 1, &dev); |
| 102 | if (ret) { |
| 103 | puts("Cannot get MCU chip!\n"); |
| 104 | return false; |
| 105 | } |
| 106 | |
Marek Behún | d0b374d | 2017-08-04 15:28:25 +0200 | [diff] [blame] | 107 | for (; retry > 0; --retry) { |
| 108 | ret = dm_i2c_read(dev, OMNIA_I2C_MCU_ADDR_STATUS, (uchar *) &mode, 2); |
| 109 | if (!ret) |
| 110 | break; |
| 111 | } |
| 112 | |
| 113 | if (!retry) { |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 114 | puts("I2C read failed! Default PEX\n"); |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | if (!(mode & OMNIA_I2C_MCU_CARDDET)) { |
| 119 | puts("NONE\n"); |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | if (mode & OMNIA_I2C_MCU_SATA) { |
| 124 | puts("SATA\n"); |
| 125 | return true; |
| 126 | } else { |
| 127 | puts("PEX\n"); |
| 128 | return false; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count) |
| 133 | { |
| 134 | if (omnia_detect_sata()) { |
| 135 | *serdes_map_array = board_serdes_map_sata; |
| 136 | *count = ARRAY_SIZE(board_serdes_map_sata); |
| 137 | } else { |
| 138 | *serdes_map_array = board_serdes_map_pex; |
| 139 | *count = ARRAY_SIZE(board_serdes_map_pex); |
| 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | struct omnia_eeprom { |
| 146 | u32 magic; |
| 147 | u32 ramsize; |
| 148 | char region[4]; |
| 149 | u32 crc; |
| 150 | }; |
| 151 | |
| 152 | static bool omnia_read_eeprom(struct omnia_eeprom *oep) |
| 153 | { |
| 154 | struct udevice *bus, *dev; |
| 155 | int ret, crc, retry = 3; |
| 156 | |
| 157 | if (uclass_get_device_by_name(UCLASS_I2C, OMNIA_I2C_EEPROM_DM_NAME, &bus)) { |
| 158 | puts("Cannot find EEPROM bus\n"); |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | ret = i2c_get_chip(bus, OMNIA_I2C_EEPROM, OMNIA_I2C_EEPROM_ADDRLEN, &dev); |
| 163 | if (ret) { |
| 164 | puts("Cannot get EEPROM chip\n"); |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | for (; retry > 0; --retry) { |
| 169 | ret = dm_i2c_read(dev, OMNIA_I2C_EEPROM_CONFIG_ADDR, (uchar *) oep, sizeof(struct omnia_eeprom)); |
| 170 | if (ret) |
| 171 | continue; |
| 172 | |
| 173 | if (oep->magic != OMNIA_I2C_EEPROM_MAGIC) { |
| 174 | puts("I2C EEPROM missing magic number!\n"); |
| 175 | continue; |
| 176 | } |
| 177 | |
| 178 | crc = crc32(0, (unsigned char *) oep, |
| 179 | sizeof(struct omnia_eeprom) - 4); |
| 180 | if (crc == oep->crc) { |
| 181 | break; |
| 182 | } else { |
| 183 | printf("CRC of EEPROM memory config failed! " |
| 184 | "calc=0x%04x saved=0x%04x\n", crc, oep->crc); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | if (!retry) { |
| 189 | puts("I2C EEPROM read failed!\n"); |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | return true; |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Define the DDR layout / topology here in the board file. This will |
| 198 | * be used by the DDR3 init code in the SPL U-Boot version to configure |
| 199 | * the DDR3 controller. |
| 200 | */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 201 | static struct mv_ddr_topology_map board_topology_map_1g = { |
| 202 | DEBUG_LEVEL_ERROR, |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 203 | 0x1, /* active interfaces */ |
| 204 | /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */ |
| 205 | { { { {0x1, 0, 0, 0}, |
| 206 | {0x1, 0, 0, 0}, |
| 207 | {0x1, 0, 0, 0}, |
| 208 | {0x1, 0, 0, 0}, |
| 209 | {0x1, 0, 0, 0} }, |
| 210 | SPEED_BIN_DDR_1600K, /* speed_bin */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 211 | MV_DDR_DEV_WIDTH_16BIT, /* memory_width */ |
| 212 | MV_DDR_DIE_CAP_4GBIT, /* mem_size */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 213 | MV_DDR_FREQ_800, /* frequency */ |
Chris Packham | dd092bd | 2017-11-29 10:38:34 +1300 | [diff] [blame] | 214 | 0, 0, /* cas_wl cas_l */ |
Chris Packham | 3a09e13 | 2018-05-10 13:28:30 +1200 | [diff] [blame] | 215 | MV_DDR_TEMP_NORMAL, /* temperature */ |
| 216 | MV_DDR_TIM_2T} }, /* timing */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 217 | BUS_MASK_32BIT, /* Busses mask */ |
| 218 | MV_DDR_CFG_DEFAULT, /* ddr configuration data source */ |
| 219 | { {0} }, /* raw spd data */ |
| 220 | {0} /* timing parameters */ |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 223 | static struct mv_ddr_topology_map board_topology_map_2g = { |
| 224 | DEBUG_LEVEL_ERROR, |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 225 | 0x1, /* active interfaces */ |
| 226 | /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */ |
| 227 | { { { {0x1, 0, 0, 0}, |
| 228 | {0x1, 0, 0, 0}, |
| 229 | {0x1, 0, 0, 0}, |
| 230 | {0x1, 0, 0, 0}, |
| 231 | {0x1, 0, 0, 0} }, |
| 232 | SPEED_BIN_DDR_1600K, /* speed_bin */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 233 | MV_DDR_DEV_WIDTH_16BIT, /* memory_width */ |
| 234 | MV_DDR_DIE_CAP_8GBIT, /* mem_size */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 235 | MV_DDR_FREQ_800, /* frequency */ |
Chris Packham | dd092bd | 2017-11-29 10:38:34 +1300 | [diff] [blame] | 236 | 0, 0, /* cas_wl cas_l */ |
Chris Packham | 3a09e13 | 2018-05-10 13:28:30 +1200 | [diff] [blame] | 237 | MV_DDR_TEMP_NORMAL, /* temperature */ |
| 238 | MV_DDR_TIM_2T} }, /* timing */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 239 | BUS_MASK_32BIT, /* Busses mask */ |
| 240 | MV_DDR_CFG_DEFAULT, /* ddr configuration data source */ |
| 241 | { {0} }, /* raw spd data */ |
| 242 | {0} /* timing parameters */ |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 243 | }; |
| 244 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 245 | struct mv_ddr_topology_map *mv_ddr_topology_map_get(void) |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 246 | { |
| 247 | static int mem = 0; |
| 248 | struct omnia_eeprom oep; |
| 249 | |
| 250 | /* Get the board config from EEPROM */ |
| 251 | if (mem == 0) { |
| 252 | if(!omnia_read_eeprom(&oep)) |
| 253 | goto out; |
| 254 | |
| 255 | printf("Memory config in EEPROM: 0x%02x\n", oep.ramsize); |
| 256 | |
| 257 | if (oep.ramsize == 0x2) |
| 258 | mem = 2; |
| 259 | else |
| 260 | mem = 1; |
| 261 | } |
| 262 | |
| 263 | out: |
| 264 | /* Hardcoded fallback */ |
| 265 | if (mem == 0) { |
| 266 | puts("WARNING: Memory config from EEPROM read failed.\n"); |
| 267 | puts("Falling back to default 1GiB map.\n"); |
| 268 | mem = 1; |
| 269 | } |
| 270 | |
| 271 | /* Return the board topology as defined in the board code */ |
| 272 | if (mem == 1) |
| 273 | return &board_topology_map_1g; |
| 274 | if (mem == 2) |
| 275 | return &board_topology_map_2g; |
| 276 | |
| 277 | return &board_topology_map_1g; |
| 278 | } |
| 279 | |
| 280 | #ifndef CONFIG_SPL_BUILD |
| 281 | static int set_regdomain(void) |
| 282 | { |
| 283 | struct omnia_eeprom oep; |
| 284 | char rd[3] = {' ', ' ', 0}; |
| 285 | |
| 286 | if (omnia_read_eeprom(&oep)) |
| 287 | memcpy(rd, &oep.region, 2); |
| 288 | else |
| 289 | puts("EEPROM regdomain read failed.\n"); |
| 290 | |
| 291 | printf("Regdomain set to %s\n", rd); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 292 | return env_set("regdomain", rd); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 293 | } |
| 294 | #endif |
| 295 | |
| 296 | int board_early_init_f(void) |
| 297 | { |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 298 | /* Configure MPP */ |
| 299 | writel(0x11111111, MVEBU_MPP_BASE + 0x00); |
| 300 | writel(0x11111111, MVEBU_MPP_BASE + 0x04); |
| 301 | writel(0x11244011, MVEBU_MPP_BASE + 0x08); |
| 302 | writel(0x22222111, MVEBU_MPP_BASE + 0x0c); |
| 303 | writel(0x22200002, MVEBU_MPP_BASE + 0x10); |
| 304 | writel(0x30042022, MVEBU_MPP_BASE + 0x14); |
| 305 | writel(0x55550555, MVEBU_MPP_BASE + 0x18); |
| 306 | writel(0x00005550, MVEBU_MPP_BASE + 0x1c); |
| 307 | |
| 308 | /* Set GPP Out value */ |
| 309 | writel(OMNIA_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00); |
| 310 | writel(OMNIA_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00); |
| 311 | |
| 312 | /* Set GPP Polarity */ |
| 313 | writel(OMNIA_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c); |
| 314 | writel(OMNIA_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c); |
| 315 | |
| 316 | /* Set GPP Out Enable */ |
| 317 | writel(OMNIA_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04); |
| 318 | writel(OMNIA_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04); |
| 319 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | #ifndef CONFIG_SPL_BUILD |
| 324 | static bool disable_mcu_watchdog(void) |
| 325 | { |
| 326 | struct udevice *bus, *dev; |
| 327 | int ret, retry = 3; |
| 328 | uchar buf[1] = {0x0}; |
| 329 | |
| 330 | if (uclass_get_device_by_name(UCLASS_I2C, OMNIA_I2C_MCU_DM_NAME, &bus)) { |
| 331 | puts("Cannot find MCU bus! Can not disable MCU WDT.\n"); |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | ret = i2c_get_chip(bus, OMNIA_I2C_MCU, 1, &dev); |
| 336 | if (ret) { |
| 337 | puts("Cannot get MCU chip! Can not disable MCU WDT.\n"); |
| 338 | return false; |
| 339 | } |
| 340 | |
| 341 | for (; retry > 0; --retry) |
| 342 | if (!dm_i2c_write(dev, OMNIA_I2C_MCU_WDT_ADDR, (uchar *) buf, 1)) |
| 343 | break; |
| 344 | |
| 345 | if (retry <= 0) { |
| 346 | puts("I2C MCU watchdog failed to disable!\n"); |
| 347 | return false; |
| 348 | } |
| 349 | |
| 350 | return true; |
| 351 | } |
| 352 | #endif |
| 353 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 354 | int board_init(void) |
| 355 | { |
| 356 | /* adress of boot parameters */ |
| 357 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
| 358 | |
| 359 | #ifndef CONFIG_SPL_BUILD |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 360 | if (disable_mcu_watchdog()) |
| 361 | puts("Disabled MCU startup watchdog.\n"); |
| 362 | |
| 363 | set_regdomain(); |
| 364 | #endif |
| 365 | |
| 366 | return 0; |
| 367 | } |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 368 | |
| 369 | int board_late_init(void) |
| 370 | { |
| 371 | #ifndef CONFIG_SPL_BUILD |
| 372 | set_regdomain(); |
| 373 | #endif |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | #ifdef CONFIG_ATSHA204A |
| 379 | static struct udevice *get_atsha204a_dev(void) |
| 380 | { |
| 381 | static struct udevice *dev = NULL; |
| 382 | |
| 383 | if (dev != NULL) |
| 384 | return dev; |
| 385 | |
| 386 | if (uclass_get_device_by_name(UCLASS_MISC, "atsha204a@64", &dev)) { |
| 387 | puts("Cannot find ATSHA204A on I2C bus!\n"); |
| 388 | dev = NULL; |
| 389 | } |
| 390 | |
| 391 | return dev; |
| 392 | } |
| 393 | #endif |
| 394 | |
| 395 | int checkboard(void) |
| 396 | { |
| 397 | u32 version_num, serial_num; |
| 398 | int err = 1; |
| 399 | |
| 400 | #ifdef CONFIG_ATSHA204A |
| 401 | struct udevice *dev = get_atsha204a_dev(); |
| 402 | |
| 403 | if (dev) { |
| 404 | err = atsha204a_wakeup(dev); |
| 405 | if (err) |
| 406 | goto out; |
| 407 | |
| 408 | err = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, |
| 409 | OMNIA_ATSHA204_OTP_VERSION, |
| 410 | (u8 *) &version_num); |
| 411 | if (err) |
| 412 | goto out; |
| 413 | |
| 414 | err = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, |
| 415 | OMNIA_ATSHA204_OTP_SERIAL, |
| 416 | (u8 *) &serial_num); |
| 417 | if (err) |
| 418 | goto out; |
| 419 | |
| 420 | atsha204a_sleep(dev); |
| 421 | } |
| 422 | |
| 423 | out: |
| 424 | #endif |
| 425 | |
| 426 | if (err) |
| 427 | printf("Board: Turris Omnia (ver N/A). SN: N/A\n"); |
| 428 | else |
| 429 | printf("Board: Turris Omnia SNL %08X%08X\n", |
| 430 | be32_to_cpu(version_num), be32_to_cpu(serial_num)); |
| 431 | |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | static void increment_mac(u8 *mac) |
| 436 | { |
| 437 | int i; |
| 438 | |
| 439 | for (i = 5; i >= 3; i--) { |
| 440 | mac[i] += 1; |
| 441 | if (mac[i]) |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | int misc_init_r(void) |
| 447 | { |
| 448 | #ifdef CONFIG_ATSHA204A |
| 449 | int err; |
| 450 | struct udevice *dev = get_atsha204a_dev(); |
| 451 | u8 mac0[4], mac1[4], mac[6]; |
| 452 | |
| 453 | if (!dev) |
| 454 | goto out; |
| 455 | |
| 456 | err = atsha204a_wakeup(dev); |
| 457 | if (err) |
| 458 | goto out; |
| 459 | |
| 460 | err = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, |
| 461 | OMNIA_ATSHA204_OTP_MAC0, mac0); |
| 462 | if (err) |
| 463 | goto out; |
| 464 | |
| 465 | err = atsha204a_read(dev, ATSHA204A_ZONE_OTP, false, |
| 466 | OMNIA_ATSHA204_OTP_MAC1, mac1); |
| 467 | if (err) |
| 468 | goto out; |
| 469 | |
| 470 | atsha204a_sleep(dev); |
| 471 | |
| 472 | mac[0] = mac0[1]; |
| 473 | mac[1] = mac0[2]; |
| 474 | mac[2] = mac0[3]; |
| 475 | mac[3] = mac1[1]; |
| 476 | mac[4] = mac1[2]; |
| 477 | mac[5] = mac1[3]; |
| 478 | |
| 479 | if (is_valid_ethaddr(mac)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 480 | eth_env_set_enetaddr("ethaddr", mac); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 481 | |
| 482 | increment_mac(mac); |
| 483 | |
| 484 | if (is_valid_ethaddr(mac)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 485 | eth_env_set_enetaddr("eth1addr", mac); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 486 | |
| 487 | increment_mac(mac); |
| 488 | |
| 489 | if (is_valid_ethaddr(mac)) |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 490 | eth_env_set_enetaddr("eth2addr", mac); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 491 | |
| 492 | out: |
| 493 | #endif |
| 494 | |
| 495 | return 0; |
| 496 | } |
| 497 | |