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