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