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