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 | /* |
Marek Behún | d63726e | 2022-06-01 17:17:06 +0200 | [diff] [blame] | 3 | * Copyright (C) 2017 Marek Behún <kabel@kernel.org> |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 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> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 15 | #include <miiphy.h> |
Marek Behún | 91ef59c | 2021-07-15 19:21:02 +0200 | [diff] [blame] | 16 | #include <mtd.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 18 | #include <asm/io.h> |
| 19 | #include <asm/arch/cpu.h> |
| 20 | #include <asm/arch/soc.h> |
| 21 | #include <dm/uclass.h> |
| 22 | #include <fdt_support.h> |
| 23 | #include <time.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 24 | #include <linux/bitops.h> |
Simon Glass | 48b6c6b | 2019-11-14 12:57:16 -0700 | [diff] [blame] | 25 | #include <u-boot/crc.h> |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 26 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 27 | #include "../drivers/ddr/marvell/a38x/ddr3_init.h" |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 28 | #include <../serdes/a38x/high_speed_env_spec.h> |
Pali Rohár | 0387f7f | 2022-04-08 16:30:12 +0200 | [diff] [blame] | 29 | #include "../turris_atsha_otp.h" |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Marek Behún | 91ef59c | 2021-07-15 19:21:02 +0200 | [diff] [blame] | 33 | #define OMNIA_SPI_NOR_PATH "/soc/spi@10600/spi-nor@0" |
| 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 | |
Pali Rohár | 30e398d | 2022-04-29 13:53:25 +0200 | [diff] [blame] | 44 | #define A385_SYS_RSTOUT_MASK MVEBU_REGISTER(0x18260) |
| 45 | #define A385_SYS_RSTOUT_MASK_WD BIT(10) |
Pali Rohár | 7fcda0c | 2021-11-09 17:14:02 +0100 | [diff] [blame] | 46 | |
| 47 | #define A385_WDT_GLOBAL_CTRL MVEBU_REGISTER(0x20300) |
| 48 | #define A385_WDT_GLOBAL_RATIO_MASK GENMASK(18, 16) |
| 49 | #define A385_WDT_GLOBAL_RATIO_SHIFT 16 |
| 50 | #define A385_WDT_GLOBAL_25MHZ BIT(10) |
| 51 | #define A385_WDT_GLOBAL_ENABLE BIT(8) |
| 52 | |
| 53 | #define A385_WDT_GLOBAL_STATUS MVEBU_REGISTER(0x20304) |
| 54 | #define A385_WDT_GLOBAL_EXPIRED BIT(31) |
| 55 | |
| 56 | #define A385_WDT_DURATION MVEBU_REGISTER(0x20334) |
| 57 | |
| 58 | #define A385_WD_RSTOUT_UNMASK MVEBU_REGISTER(0x20704) |
| 59 | #define A385_WD_RSTOUT_UNMASK_GLOBAL BIT(8) |
| 60 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 61 | enum mcu_commands { |
| 62 | CMD_GET_STATUS_WORD = 0x01, |
| 63 | CMD_GET_RESET = 0x09, |
| 64 | CMD_WATCHDOG_STATE = 0x0b, |
Pali Rohár | 4798ba9 | 2022-07-29 13:29:06 +0200 | [diff] [blame^] | 65 | |
| 66 | /* available if STS_FEATURES_SUPPORTED bit set in status word */ |
| 67 | CMD_GET_FEATURES = 0x10, |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | enum status_word_bits { |
Pali Rohár | 4798ba9 | 2022-07-29 13:29:06 +0200 | [diff] [blame^] | 71 | STS_MCU_TYPE_MASK = GENMASK(1, 0), |
| 72 | STS_MCU_TYPE_STM32 = 0, |
| 73 | STS_MCU_TYPE_GD32 = 1, |
| 74 | STS_MCU_TYPE_MKL = 2, |
| 75 | STS_MCU_TYPE_UNKN = 3, |
| 76 | STS_FEATURES_SUPPORTED = BIT(2), |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 77 | CARD_DET_STSBIT = 0x0010, |
| 78 | MSATA_IND_STSBIT = 0x0020, |
| 79 | }; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 80 | |
Pali Rohár | 4798ba9 | 2022-07-29 13:29:06 +0200 | [diff] [blame^] | 81 | /* CMD_GET_FEATURES */ |
| 82 | enum features_e { |
| 83 | FEAT_PERIPH_MCU = BIT(0), |
| 84 | }; |
| 85 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 86 | /* |
| 87 | * Those values and defines are taken from the Marvell U-Boot version |
| 88 | * "u-boot-2013.01-2014_T3.0" |
| 89 | */ |
| 90 | #define OMNIA_GPP_OUT_ENA_LOW \ |
| 91 | (~(BIT(1) | BIT(4) | BIT(6) | BIT(7) | BIT(8) | BIT(9) | \ |
| 92 | BIT(10) | BIT(11) | BIT(19) | BIT(22) | BIT(23) | BIT(25) | \ |
| 93 | BIT(26) | BIT(27) | BIT(29) | BIT(30) | BIT(31))) |
| 94 | #define OMNIA_GPP_OUT_ENA_MID \ |
| 95 | (~(BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(15) | \ |
| 96 | BIT(16) | BIT(17) | BIT(18))) |
| 97 | |
| 98 | #define OMNIA_GPP_OUT_VAL_LOW 0x0 |
| 99 | #define OMNIA_GPP_OUT_VAL_MID 0x0 |
| 100 | #define OMNIA_GPP_POL_LOW 0x0 |
| 101 | #define OMNIA_GPP_POL_MID 0x0 |
| 102 | |
Pali Rohár | 3c4dd981 | 2022-03-02 12:47:54 +0100 | [diff] [blame] | 103 | static struct serdes_map board_serdes_map[] = { |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 104 | {PEX0, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 105 | {USB3_HOST0, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 106 | {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 107 | {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0}, |
| 108 | {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}, |
| 109 | {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0} |
| 110 | }; |
| 111 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 112 | static struct udevice *omnia_get_i2c_chip(const char *name, uint addr, |
| 113 | uint offset_len) |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 114 | { |
| 115 | struct udevice *bus, *dev; |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 116 | int ret; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 117 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 118 | ret = uclass_get_device_by_name(UCLASS_I2C, OMNIA_I2C_BUS_NAME, &bus); |
| 119 | if (ret) { |
| 120 | printf("Cannot get I2C bus %s: uclass_get_device_by_name failed: %i\n", |
| 121 | OMNIA_I2C_BUS_NAME, ret); |
| 122 | return NULL; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 125 | ret = i2c_get_chip(bus, addr, offset_len, &dev); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 126 | if (ret) { |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 127 | printf("Cannot get %s I2C chip: i2c_get_chip failed: %i\n", |
| 128 | name, ret); |
| 129 | return NULL; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 130 | } |
| 131 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 132 | return dev; |
| 133 | } |
Marek Behún | d0b374d | 2017-08-04 15:28:25 +0200 | [diff] [blame] | 134 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 135 | static int omnia_mcu_read(u8 cmd, void *buf, int len) |
| 136 | { |
| 137 | struct udevice *chip; |
| 138 | |
| 139 | chip = omnia_get_i2c_chip("MCU", OMNIA_I2C_MCU_CHIP_ADDR, |
| 140 | OMNIA_I2C_MCU_CHIP_LEN); |
| 141 | if (!chip) |
| 142 | return -ENODEV; |
| 143 | |
| 144 | return dm_i2c_read(chip, cmd, buf, len); |
| 145 | } |
| 146 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 147 | static int omnia_mcu_write(u8 cmd, const void *buf, int len) |
| 148 | { |
| 149 | struct udevice *chip; |
| 150 | |
| 151 | chip = omnia_get_i2c_chip("MCU", OMNIA_I2C_MCU_CHIP_ADDR, |
| 152 | OMNIA_I2C_MCU_CHIP_LEN); |
| 153 | if (!chip) |
| 154 | return -ENODEV; |
| 155 | |
| 156 | return dm_i2c_write(chip, cmd, buf, len); |
| 157 | } |
| 158 | |
Pali Rohár | 7fcda0c | 2021-11-09 17:14:02 +0100 | [diff] [blame] | 159 | static void enable_a385_watchdog(unsigned int timeout_minutes) |
| 160 | { |
| 161 | struct sar_freq_modes sar_freq; |
| 162 | u32 watchdog_freq; |
| 163 | |
| 164 | printf("Enabling A385 watchdog with %u minutes timeout...\n", |
| 165 | timeout_minutes); |
| 166 | |
| 167 | /* |
| 168 | * Use NBCLK clock (a.k.a. L2 clock) as watchdog input clock with |
| 169 | * its maximal ratio 7 instead of default fixed 25 MHz clock. |
| 170 | * It allows to set watchdog duration up to the 22 minutes. |
| 171 | */ |
| 172 | clrsetbits_32(A385_WDT_GLOBAL_CTRL, |
| 173 | A385_WDT_GLOBAL_25MHZ | A385_WDT_GLOBAL_RATIO_MASK, |
| 174 | 7 << A385_WDT_GLOBAL_RATIO_SHIFT); |
| 175 | |
| 176 | /* |
| 177 | * Calculate watchdog clock frequency. It is defined by formula: |
| 178 | * freq = NBCLK / 2 / (2 ^ ratio) |
| 179 | * We set ratio to the maximal possible value 7. |
| 180 | */ |
| 181 | get_sar_freq(&sar_freq); |
| 182 | watchdog_freq = sar_freq.nb_clk * 1000000 / 2 / (1 << 7); |
| 183 | |
| 184 | /* Set watchdog duration */ |
| 185 | writel(timeout_minutes * 60 * watchdog_freq, A385_WDT_DURATION); |
| 186 | |
| 187 | /* Clear the watchdog expiration bit */ |
| 188 | clrbits_32(A385_WDT_GLOBAL_STATUS, A385_WDT_GLOBAL_EXPIRED); |
| 189 | |
| 190 | /* Enable watchdog timer */ |
| 191 | setbits_32(A385_WDT_GLOBAL_CTRL, A385_WDT_GLOBAL_ENABLE); |
| 192 | |
| 193 | /* Enable reset on watchdog */ |
| 194 | setbits_32(A385_WD_RSTOUT_UNMASK, A385_WD_RSTOUT_UNMASK_GLOBAL); |
| 195 | |
| 196 | /* Unmask reset for watchdog */ |
Pali Rohár | 30e398d | 2022-04-29 13:53:25 +0200 | [diff] [blame] | 197 | clrbits_32(A385_SYS_RSTOUT_MASK, A385_SYS_RSTOUT_MASK_WD); |
Pali Rohár | 7fcda0c | 2021-11-09 17:14:02 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 200 | static bool disable_mcu_watchdog(void) |
| 201 | { |
| 202 | int ret; |
| 203 | |
| 204 | puts("Disabling MCU watchdog... "); |
| 205 | |
| 206 | ret = omnia_mcu_write(CMD_WATCHDOG_STATE, "\x00", 1); |
| 207 | if (ret) { |
| 208 | printf("omnia_mcu_write failed: %i\n", ret); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 209 | return false; |
| 210 | } |
| 211 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 212 | puts("disabled\n"); |
| 213 | |
| 214 | return true; |
| 215 | } |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 216 | |
Pali Rohár | f8f305b | 2022-03-02 12:47:55 +0100 | [diff] [blame] | 217 | static bool omnia_detect_sata(const char *msata_slot) |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 218 | { |
| 219 | int ret; |
| 220 | u16 stsword; |
| 221 | |
| 222 | puts("MiniPCIe/mSATA card detection... "); |
| 223 | |
Pali Rohár | f8f305b | 2022-03-02 12:47:55 +0100 | [diff] [blame] | 224 | if (msata_slot) { |
| 225 | if (strcmp(msata_slot, "pcie") == 0) { |
| 226 | puts("forced to MiniPCIe via env\n"); |
| 227 | return false; |
| 228 | } else if (strcmp(msata_slot, "sata") == 0) { |
| 229 | puts("forced to mSATA via env\n"); |
| 230 | return true; |
| 231 | } else if (strcmp(msata_slot, "auto") != 0) { |
| 232 | printf("unsupported env value '%s', fallback to... ", msata_slot); |
| 233 | } |
| 234 | } |
| 235 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 236 | ret = omnia_mcu_read(CMD_GET_STATUS_WORD, &stsword, sizeof(stsword)); |
| 237 | if (ret) { |
| 238 | printf("omnia_mcu_read failed: %i, defaulting to MiniPCIe card\n", |
| 239 | ret); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 240 | return false; |
| 241 | } |
| 242 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 243 | if (!(stsword & CARD_DET_STSBIT)) { |
| 244 | puts("none\n"); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 245 | return false; |
| 246 | } |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 247 | |
| 248 | if (stsword & MSATA_IND_STSBIT) |
| 249 | puts("mSATA\n"); |
| 250 | else |
| 251 | puts("MiniPCIe\n"); |
| 252 | |
| 253 | return stsword & MSATA_IND_STSBIT ? true : false; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Pali Rohár | 93a89c5 | 2022-03-02 12:47:58 +0100 | [diff] [blame] | 256 | static bool omnia_detect_wwan_usb3(const char *wwan_slot) |
| 257 | { |
| 258 | puts("WWAN slot configuration... "); |
| 259 | |
| 260 | if (wwan_slot && strcmp(wwan_slot, "usb3") == 0) { |
| 261 | puts("USB3.0\n"); |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | if (wwan_slot && strcmp(wwan_slot, "pcie") != 0) |
| 266 | printf("unsupported env value '%s', fallback to... ", wwan_slot); |
| 267 | |
| 268 | puts("PCIe+USB2.0\n"); |
| 269 | return false; |
| 270 | } |
| 271 | |
Pali Rohár | c13401b | 2022-03-02 12:47:52 +0100 | [diff] [blame] | 272 | void *env_sf_get_env_addr(void) |
| 273 | { |
| 274 | /* SPI Flash is mapped to address 0xD4000000 only in SPL */ |
| 275 | #ifdef CONFIG_SPL_BUILD |
| 276 | return (void *)0xD4000000 + CONFIG_ENV_OFFSET; |
| 277 | #else |
| 278 | return NULL; |
| 279 | #endif |
| 280 | } |
| 281 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 282 | int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count) |
| 283 | { |
Pali Rohár | f8f305b | 2022-03-02 12:47:55 +0100 | [diff] [blame] | 284 | #ifdef CONFIG_SPL_ENV_SUPPORT |
| 285 | /* Do not use env_load() as malloc() pool is too small at this stage */ |
| 286 | bool has_env = (env_init() == 0); |
| 287 | #endif |
| 288 | const char *env_value = NULL; |
| 289 | |
| 290 | #ifdef CONFIG_SPL_ENV_SUPPORT |
| 291 | /* beware that env_get() returns static allocated memory */ |
| 292 | env_value = has_env ? env_get("omnia_msata_slot") : NULL; |
| 293 | #endif |
| 294 | |
| 295 | if (omnia_detect_sata(env_value)) { |
Pali Rohár | 3c4dd981 | 2022-03-02 12:47:54 +0100 | [diff] [blame] | 296 | /* Change SerDes for first mPCIe port (mSATA) from PCIe to SATA */ |
| 297 | board_serdes_map[0].serdes_type = SATA0; |
| 298 | board_serdes_map[0].serdes_speed = SERDES_SPEED_6_GBPS; |
| 299 | board_serdes_map[0].serdes_mode = SERDES_DEFAULT_MODE; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Pali Rohár | 93a89c5 | 2022-03-02 12:47:58 +0100 | [diff] [blame] | 302 | #ifdef CONFIG_SPL_ENV_SUPPORT |
| 303 | /* beware that env_get() returns static allocated memory */ |
| 304 | env_value = has_env ? env_get("omnia_wwan_slot") : NULL; |
| 305 | #endif |
| 306 | |
| 307 | if (omnia_detect_wwan_usb3(env_value)) { |
| 308 | /* Disable SerDes for USB 3.0 pins on the front USB-A port */ |
| 309 | board_serdes_map[1].serdes_type = DEFAULT_SERDES; |
| 310 | /* Change SerDes for third mPCIe port (WWAN) from PCIe to USB 3.0 */ |
| 311 | board_serdes_map[4].serdes_type = USB3_HOST0; |
| 312 | board_serdes_map[4].serdes_speed = SERDES_SPEED_5_GBPS; |
| 313 | board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE; |
| 314 | } |
| 315 | |
Pali Rohár | 3c4dd981 | 2022-03-02 12:47:54 +0100 | [diff] [blame] | 316 | *serdes_map_array = board_serdes_map; |
| 317 | *count = ARRAY_SIZE(board_serdes_map); |
| 318 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | struct omnia_eeprom { |
| 323 | u32 magic; |
| 324 | u32 ramsize; |
| 325 | char region[4]; |
| 326 | u32 crc; |
| 327 | }; |
| 328 | |
| 329 | static bool omnia_read_eeprom(struct omnia_eeprom *oep) |
| 330 | { |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 331 | struct udevice *chip; |
| 332 | u32 crc; |
| 333 | int ret; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 334 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 335 | chip = omnia_get_i2c_chip("EEPROM", OMNIA_I2C_EEPROM_CHIP_ADDR, |
| 336 | OMNIA_I2C_EEPROM_CHIP_LEN); |
| 337 | |
| 338 | if (!chip) |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 339 | return false; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 340 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 341 | ret = dm_i2c_read(chip, 0, (void *)oep, sizeof(*oep)); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 342 | if (ret) { |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 343 | printf("dm_i2c_read failed: %i, cannot read EEPROM\n", ret); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 344 | return false; |
| 345 | } |
| 346 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 347 | if (oep->magic != OMNIA_I2C_EEPROM_MAGIC) { |
| 348 | printf("bad EEPROM magic number (%08x, should be %08x)\n", |
| 349 | oep->magic, OMNIA_I2C_EEPROM_MAGIC); |
| 350 | return false; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Marek Behún | ba53b6b | 2019-05-02 16:53:30 +0200 | [diff] [blame] | 353 | crc = crc32(0, (void *)oep, sizeof(*oep) - 4); |
| 354 | if (crc != oep->crc) { |
| 355 | printf("bad EEPROM CRC (stored %08x, computed %08x)\n", |
| 356 | oep->crc, crc); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 357 | return false; |
| 358 | } |
| 359 | |
| 360 | return true; |
| 361 | } |
| 362 | |
Marek Behún | 77652c7 | 2019-05-02 16:53:33 +0200 | [diff] [blame] | 363 | static int omnia_get_ram_size_gb(void) |
| 364 | { |
| 365 | static int ram_size; |
| 366 | struct omnia_eeprom oep; |
| 367 | |
| 368 | if (!ram_size) { |
| 369 | /* Get the board config from EEPROM */ |
| 370 | if (omnia_read_eeprom(&oep)) { |
| 371 | debug("Memory config in EEPROM: 0x%02x\n", oep.ramsize); |
| 372 | |
| 373 | if (oep.ramsize == 0x2) |
| 374 | ram_size = 2; |
| 375 | else |
| 376 | ram_size = 1; |
| 377 | } else { |
| 378 | /* Hardcoded fallback */ |
| 379 | puts("Memory config from EEPROM read failed!\n"); |
| 380 | puts("Falling back to default 1 GiB!\n"); |
| 381 | ram_size = 1; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | return ram_size; |
| 386 | } |
| 387 | |
Pali Rohár | 4798ba9 | 2022-07-29 13:29:06 +0200 | [diff] [blame^] | 388 | static const char * const omnia_get_mcu_type(void) |
| 389 | { |
| 390 | static const char * const mcu_types[] = { |
| 391 | [STS_MCU_TYPE_STM32] = "STM32", |
| 392 | [STS_MCU_TYPE_GD32] = "GD32", |
| 393 | [STS_MCU_TYPE_MKL] = "MKL", |
| 394 | [STS_MCU_TYPE_UNKN] = "unknown", |
| 395 | }; |
| 396 | static const char * const mcu_types_with_perip_resets[] = { |
| 397 | [STS_MCU_TYPE_STM32] = "STM32 (with peripheral resets)", |
| 398 | [STS_MCU_TYPE_GD32] = "GD32 (with peripheral resets)", |
| 399 | [STS_MCU_TYPE_MKL] = "MKL (with peripheral resets)", |
| 400 | [STS_MCU_TYPE_UNKN] = "unknown (with peripheral resets)", |
| 401 | }; |
| 402 | u16 stsword, features; |
| 403 | int ret; |
| 404 | |
| 405 | ret = omnia_mcu_read(CMD_GET_STATUS_WORD, &stsword, sizeof(stsword)); |
| 406 | if (ret) |
| 407 | return "unknown"; |
| 408 | |
| 409 | if (stsword & STS_FEATURES_SUPPORTED) { |
| 410 | ret = omnia_mcu_read(CMD_GET_FEATURES, &features, sizeof(features)); |
| 411 | if (ret == 0 && (features & FEAT_PERIPH_MCU)) |
| 412 | return mcu_types_with_perip_resets[stsword & STS_MCU_TYPE_MASK]; |
| 413 | } |
| 414 | |
| 415 | return mcu_types[stsword & STS_MCU_TYPE_MASK]; |
| 416 | } |
| 417 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 418 | /* |
| 419 | * Define the DDR layout / topology here in the board file. This will |
| 420 | * be used by the DDR3 init code in the SPL U-Boot version to configure |
| 421 | * the DDR3 controller. |
| 422 | */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 423 | static struct mv_ddr_topology_map board_topology_map_1g = { |
| 424 | DEBUG_LEVEL_ERROR, |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 425 | 0x1, /* active interfaces */ |
| 426 | /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */ |
| 427 | { { { {0x1, 0, 0, 0}, |
| 428 | {0x1, 0, 0, 0}, |
| 429 | {0x1, 0, 0, 0}, |
| 430 | {0x1, 0, 0, 0}, |
| 431 | {0x1, 0, 0, 0} }, |
| 432 | SPEED_BIN_DDR_1600K, /* speed_bin */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 433 | MV_DDR_DEV_WIDTH_16BIT, /* memory_width */ |
| 434 | MV_DDR_DIE_CAP_4GBIT, /* mem_size */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 435 | MV_DDR_FREQ_800, /* frequency */ |
Chris Packham | dd092bd | 2017-11-29 10:38:34 +1300 | [diff] [blame] | 436 | 0, 0, /* cas_wl cas_l */ |
Chris Packham | 3a09e13 | 2018-05-10 13:28:30 +1200 | [diff] [blame] | 437 | MV_DDR_TEMP_NORMAL, /* temperature */ |
| 438 | MV_DDR_TIM_2T} }, /* timing */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 439 | BUS_MASK_32BIT, /* Busses mask */ |
| 440 | MV_DDR_CFG_DEFAULT, /* ddr configuration data source */ |
Moti Buskila | 498475e | 2021-02-19 17:11:19 +0100 | [diff] [blame] | 441 | NOT_COMBINED, /* ddr twin-die combined */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 442 | { {0} }, /* raw spd data */ |
| 443 | {0} /* timing parameters */ |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 444 | }; |
| 445 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 446 | static struct mv_ddr_topology_map board_topology_map_2g = { |
| 447 | DEBUG_LEVEL_ERROR, |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 448 | 0x1, /* active interfaces */ |
| 449 | /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */ |
| 450 | { { { {0x1, 0, 0, 0}, |
| 451 | {0x1, 0, 0, 0}, |
| 452 | {0x1, 0, 0, 0}, |
| 453 | {0x1, 0, 0, 0}, |
| 454 | {0x1, 0, 0, 0} }, |
| 455 | SPEED_BIN_DDR_1600K, /* speed_bin */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 456 | MV_DDR_DEV_WIDTH_16BIT, /* memory_width */ |
| 457 | MV_DDR_DIE_CAP_8GBIT, /* mem_size */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 458 | MV_DDR_FREQ_800, /* frequency */ |
Chris Packham | dd092bd | 2017-11-29 10:38:34 +1300 | [diff] [blame] | 459 | 0, 0, /* cas_wl cas_l */ |
Chris Packham | 3a09e13 | 2018-05-10 13:28:30 +1200 | [diff] [blame] | 460 | MV_DDR_TEMP_NORMAL, /* temperature */ |
| 461 | MV_DDR_TIM_2T} }, /* timing */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 462 | BUS_MASK_32BIT, /* Busses mask */ |
| 463 | MV_DDR_CFG_DEFAULT, /* ddr configuration data source */ |
Moti Buskila | 498475e | 2021-02-19 17:11:19 +0100 | [diff] [blame] | 464 | NOT_COMBINED, /* ddr twin-die combined */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 465 | { {0} }, /* raw spd data */ |
| 466 | {0} /* timing parameters */ |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 467 | }; |
| 468 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 469 | struct mv_ddr_topology_map *mv_ddr_topology_map_get(void) |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 470 | { |
Marek Behún | 77652c7 | 2019-05-02 16:53:33 +0200 | [diff] [blame] | 471 | if (omnia_get_ram_size_gb() == 2) |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 472 | return &board_topology_map_2g; |
Marek Behún | 77652c7 | 2019-05-02 16:53:33 +0200 | [diff] [blame] | 473 | else |
| 474 | return &board_topology_map_1g; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 475 | } |
| 476 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 477 | static int set_regdomain(void) |
| 478 | { |
| 479 | struct omnia_eeprom oep; |
| 480 | char rd[3] = {' ', ' ', 0}; |
| 481 | |
| 482 | if (omnia_read_eeprom(&oep)) |
| 483 | memcpy(rd, &oep.region, 2); |
| 484 | else |
| 485 | puts("EEPROM regdomain read failed.\n"); |
| 486 | |
| 487 | printf("Regdomain set to %s\n", rd); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 488 | return env_set("regdomain", rd); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 489 | } |
Marek Behún | 0f2e66a | 2019-05-02 16:53:37 +0200 | [diff] [blame] | 490 | |
Marek Behún | 0f2e66a | 2019-05-02 16:53:37 +0200 | [diff] [blame] | 491 | static void handle_reset_button(void) |
| 492 | { |
Pali Rohár | 905c3bf | 2021-06-14 16:45:58 +0200 | [diff] [blame] | 493 | const char * const vars[1] = { "bootcmd_rescue", }; |
Marek Behún | 0f2e66a | 2019-05-02 16:53:37 +0200 | [diff] [blame] | 494 | int ret; |
| 495 | u8 reset_status; |
| 496 | |
Pali Rohár | 905c3bf | 2021-06-14 16:45:58 +0200 | [diff] [blame] | 497 | /* |
| 498 | * Ensure that bootcmd_rescue has always stock value, so that running |
| 499 | * run bootcmd_rescue |
| 500 | * always works correctly. |
| 501 | */ |
| 502 | env_set_default_vars(1, (char * const *)vars, 0); |
| 503 | |
Marek Behún | 0f2e66a | 2019-05-02 16:53:37 +0200 | [diff] [blame] | 504 | ret = omnia_mcu_read(CMD_GET_RESET, &reset_status, 1); |
| 505 | if (ret) { |
| 506 | printf("omnia_mcu_read failed: %i, reset status unknown!\n", |
| 507 | ret); |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | env_set_ulong("omnia_reset", reset_status); |
| 512 | |
| 513 | if (reset_status) { |
Pali Rohár | 905c3bf | 2021-06-14 16:45:58 +0200 | [diff] [blame] | 514 | const char * const vars[2] = { |
Marek Behún | 09f8de2 | 2021-05-28 10:00:49 +0200 | [diff] [blame] | 515 | "bootcmd", |
Marek Behún | 09f8de2 | 2021-05-28 10:00:49 +0200 | [diff] [blame] | 516 | "distro_bootcmd", |
| 517 | }; |
| 518 | |
| 519 | /* |
| 520 | * Set the above envs to their default values, in case the user |
| 521 | * managed to break them. |
| 522 | */ |
Pali Rohár | 905c3bf | 2021-06-14 16:45:58 +0200 | [diff] [blame] | 523 | env_set_default_vars(2, (char * const *)vars, 0); |
Marek Behún | 09f8de2 | 2021-05-28 10:00:49 +0200 | [diff] [blame] | 524 | |
| 525 | /* Ensure bootcmd_rescue is used by distroboot */ |
| 526 | env_set("boot_targets", "rescue"); |
| 527 | |
Pali Rohár | 4f9e6fb | 2022-04-06 11:39:32 +0200 | [diff] [blame] | 528 | printf("RESET button was pressed, overwriting boot_targets!\n"); |
Marek Behún | 09f8de2 | 2021-05-28 10:00:49 +0200 | [diff] [blame] | 529 | } else { |
| 530 | /* |
| 531 | * In case the user somehow managed to save environment with |
| 532 | * boot_targets=rescue, reset boot_targets to default value. |
| 533 | * This could happen in subsequent commands if bootcmd_rescue |
| 534 | * failed. |
| 535 | */ |
| 536 | if (!strcmp(env_get("boot_targets"), "rescue")) { |
| 537 | const char * const vars[1] = { |
| 538 | "boot_targets", |
| 539 | }; |
| 540 | |
| 541 | env_set_default_vars(1, (char * const *)vars, 0); |
| 542 | } |
Marek Behún | 0f2e66a | 2019-05-02 16:53:37 +0200 | [diff] [blame] | 543 | } |
| 544 | } |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 545 | |
| 546 | int board_early_init_f(void) |
| 547 | { |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 548 | /* Configure MPP */ |
| 549 | writel(0x11111111, MVEBU_MPP_BASE + 0x00); |
| 550 | writel(0x11111111, MVEBU_MPP_BASE + 0x04); |
| 551 | writel(0x11244011, MVEBU_MPP_BASE + 0x08); |
| 552 | writel(0x22222111, MVEBU_MPP_BASE + 0x0c); |
| 553 | writel(0x22200002, MVEBU_MPP_BASE + 0x10); |
| 554 | writel(0x30042022, MVEBU_MPP_BASE + 0x14); |
| 555 | writel(0x55550555, MVEBU_MPP_BASE + 0x18); |
| 556 | writel(0x00005550, MVEBU_MPP_BASE + 0x1c); |
| 557 | |
| 558 | /* Set GPP Out value */ |
| 559 | writel(OMNIA_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00); |
| 560 | writel(OMNIA_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00); |
| 561 | |
| 562 | /* Set GPP Polarity */ |
| 563 | writel(OMNIA_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c); |
| 564 | writel(OMNIA_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c); |
| 565 | |
| 566 | /* Set GPP Out Enable */ |
| 567 | writel(OMNIA_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04); |
| 568 | writel(OMNIA_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04); |
| 569 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
Marek Behún | f355616 | 2021-08-16 15:19:39 +0200 | [diff] [blame] | 573 | void spl_board_init(void) |
| 574 | { |
| 575 | /* |
| 576 | * If booting from UART, disable MCU watchdog in SPL, since uploading |
Pali Rohár | 7fcda0c | 2021-11-09 17:14:02 +0100 | [diff] [blame] | 577 | * U-Boot proper can take too much time and trigger it. Instead enable |
| 578 | * A385 watchdog with very high timeout (10 minutes) to prevent hangup. |
Marek Behún | f355616 | 2021-08-16 15:19:39 +0200 | [diff] [blame] | 579 | */ |
Pali Rohár | 7fcda0c | 2021-11-09 17:14:02 +0100 | [diff] [blame] | 580 | if (get_boot_device() == BOOT_DEVICE_UART) { |
| 581 | enable_a385_watchdog(10); |
Marek Behún | f355616 | 2021-08-16 15:19:39 +0200 | [diff] [blame] | 582 | disable_mcu_watchdog(); |
Pali Rohár | 7fcda0c | 2021-11-09 17:14:02 +0100 | [diff] [blame] | 583 | } |
Marek Behún | f355616 | 2021-08-16 15:19:39 +0200 | [diff] [blame] | 584 | } |
| 585 | |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 586 | #if IS_ENABLED(CONFIG_OF_BOARD_FIXUP) || IS_ENABLED(CONFIG_OF_BOARD_SETUP) |
| 587 | |
Pali Rohár | 7cd4173 | 2022-03-02 12:47:56 +0100 | [diff] [blame] | 588 | static void disable_sata_node(void *blob) |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 589 | { |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 590 | int node; |
| 591 | |
Pali Rohár | 7cd4173 | 2022-03-02 12:47:56 +0100 | [diff] [blame] | 592 | fdt_for_each_node_by_compatible(node, blob, -1, "marvell,armada-380-ahci") { |
| 593 | if (!fdtdec_get_is_enabled(blob, node)) |
| 594 | continue; |
| 595 | |
| 596 | if (fdt_status_disabled(blob, node) < 0) |
| 597 | printf("Cannot disable SATA DT node!\n"); |
| 598 | else |
| 599 | debug("Disabled SATA DT node\n"); |
| 600 | |
Pali Rohár | e910526 | 2022-03-02 12:47:57 +0100 | [diff] [blame] | 601 | return; |
Pali Rohár | 7cd4173 | 2022-03-02 12:47:56 +0100 | [diff] [blame] | 602 | } |
Pali Rohár | e910526 | 2022-03-02 12:47:57 +0100 | [diff] [blame] | 603 | |
| 604 | printf("Cannot find SATA DT node!\n"); |
Pali Rohár | 7cd4173 | 2022-03-02 12:47:56 +0100 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static void disable_pcie_node(void *blob, int port) |
| 608 | { |
| 609 | int node; |
| 610 | |
| 611 | fdt_for_each_node_by_compatible(node, blob, -1, "marvell,armada-370-pcie") { |
| 612 | int port_node; |
| 613 | |
| 614 | if (!fdtdec_get_is_enabled(blob, node)) |
| 615 | continue; |
| 616 | |
| 617 | fdt_for_each_subnode (port_node, blob, node) { |
| 618 | if (!fdtdec_get_is_enabled(blob, port_node)) |
| 619 | continue; |
| 620 | |
| 621 | if (fdtdec_get_int(blob, port_node, "marvell,pcie-port", -1) != port) |
| 622 | continue; |
| 623 | |
| 624 | if (fdt_status_disabled(blob, port_node) < 0) |
| 625 | printf("Cannot disable PCIe port %d DT node!\n", port); |
| 626 | else |
| 627 | debug("Disabled PCIe port %d DT node\n", port); |
| 628 | |
| 629 | return; |
| 630 | } |
| 631 | } |
Pali Rohár | e910526 | 2022-03-02 12:47:57 +0100 | [diff] [blame] | 632 | |
| 633 | printf("Cannot find PCIe port %d DT node!\n", port); |
Pali Rohár | 7cd4173 | 2022-03-02 12:47:56 +0100 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static void fixup_msata_port_nodes(void *blob) |
| 637 | { |
| 638 | bool mode_sata; |
| 639 | |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 640 | /* |
| 641 | * Determine if SerDes 0 is configured to SATA mode. |
| 642 | * We do this instead of calling omnia_detect_sata() to avoid another |
| 643 | * call to the MCU. By this time the common PHYs are initialized (it is |
| 644 | * done in SPL), so we can read this common PHY register. |
| 645 | */ |
| 646 | mode_sata = (readl(MVEBU_REGISTER(0x183fc)) & GENMASK(3, 0)) == 2; |
| 647 | |
| 648 | /* |
| 649 | * We're either adding status = "disabled" property, or changing |
| 650 | * status = "okay" to status = "disabled". In both cases we'll need more |
| 651 | * space. Increase the size a little. |
| 652 | */ |
| 653 | if (fdt_increase_size(blob, 32) < 0) { |
| 654 | printf("Cannot increase FDT size!\n"); |
| 655 | return; |
| 656 | } |
| 657 | |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 658 | if (!mode_sata) { |
Pali Rohár | 7cd4173 | 2022-03-02 12:47:56 +0100 | [diff] [blame] | 659 | /* If mSATA card is not present, disable SATA DT node */ |
| 660 | disable_sata_node(blob); |
| 661 | } else { |
| 662 | /* Otherwise disable PCIe port 0 DT node (MiniPCIe / mSATA port) */ |
| 663 | disable_pcie_node(blob, 0); |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 664 | } |
Pali Rohár | 93a89c5 | 2022-03-02 12:47:58 +0100 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | static void fixup_wwan_port_nodes(void *blob) |
| 668 | { |
| 669 | bool mode_usb3; |
| 670 | |
| 671 | /* Determine if SerDes 4 is configured to USB3 mode */ |
| 672 | mode_usb3 = ((readl(MVEBU_REGISTER(0x183fc)) & GENMASK(19, 16)) >> 16) == 4; |
| 673 | |
| 674 | /* If SerDes 4 is not configured to USB3 mode then nothing is needed to fixup */ |
| 675 | if (!mode_usb3) |
| 676 | return; |
| 677 | |
| 678 | /* |
| 679 | * We're either adding status = "disabled" property, or changing |
| 680 | * status = "okay" to status = "disabled". In both cases we'll need more |
| 681 | * space. Increase the size a little. |
| 682 | */ |
| 683 | if (fdt_increase_size(blob, 32) < 0) { |
| 684 | printf("Cannot increase FDT size!\n"); |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | /* Disable PCIe port 2 DT node (WWAN) */ |
| 689 | disable_pcie_node(blob, 2); |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | #endif |
| 693 | |
| 694 | #if IS_ENABLED(CONFIG_OF_BOARD_FIXUP) |
| 695 | int board_fix_fdt(void *blob) |
| 696 | { |
Pali Rohár | 7cd4173 | 2022-03-02 12:47:56 +0100 | [diff] [blame] | 697 | fixup_msata_port_nodes(blob); |
Pali Rohár | 93a89c5 | 2022-03-02 12:47:58 +0100 | [diff] [blame] | 698 | fixup_wwan_port_nodes(blob); |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 699 | |
| 700 | return 0; |
| 701 | } |
| 702 | #endif |
| 703 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 704 | int board_init(void) |
| 705 | { |
Marek Behún | 4dfc57e | 2019-05-02 16:53:31 +0200 | [diff] [blame] | 706 | /* address of boot parameters */ |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 707 | gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100; |
| 708 | |
Marek Behún | 88dc024 | 2021-08-16 15:19:40 +0200 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | int board_late_init(void) |
| 713 | { |
Marek Behún | f355616 | 2021-08-16 15:19:39 +0200 | [diff] [blame] | 714 | /* |
| 715 | * If not booting from UART, MCU watchdog was not disabled in SPL, |
| 716 | * disable it now. |
| 717 | */ |
| 718 | if (get_boot_device() != BOOT_DEVICE_UART) |
| 719 | disable_mcu_watchdog(); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 720 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 721 | set_regdomain(); |
Marek Behún | 0f2e66a | 2019-05-02 16:53:37 +0200 | [diff] [blame] | 722 | handle_reset_button(); |
Marek Behún | db1e5c6 | 2019-05-24 14:57:53 +0200 | [diff] [blame] | 723 | pci_init(); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 724 | |
| 725 | return 0; |
| 726 | } |
| 727 | |
Marek Behún | ab9447f | 2021-10-09 19:33:44 +0200 | [diff] [blame] | 728 | int show_board_info(void) |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 729 | { |
| 730 | u32 version_num, serial_num; |
Pali Rohár | 0387f7f | 2022-04-08 16:30:12 +0200 | [diff] [blame] | 731 | int err; |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 732 | |
Pali Rohár | 0387f7f | 2022-04-08 16:30:12 +0200 | [diff] [blame] | 733 | err = turris_atsha_otp_get_serial_number(&version_num, &serial_num); |
Marek Behún | ab9447f | 2021-10-09 19:33:44 +0200 | [diff] [blame] | 734 | printf("Model: Turris Omnia\n"); |
Pali Rohár | 4798ba9 | 2022-07-29 13:29:06 +0200 | [diff] [blame^] | 735 | printf(" MCU type: %s\n", omnia_get_mcu_type()); |
Marek Behún | c4ba72a | 2019-05-02 16:53:34 +0200 | [diff] [blame] | 736 | 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] | 737 | if (err) |
Marek Behún | c4ba72a | 2019-05-02 16:53:34 +0200 | [diff] [blame] | 738 | printf(" Serial Number: unknown\n"); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 739 | else |
Marek Behún | c4ba72a | 2019-05-02 16:53:34 +0200 | [diff] [blame] | 740 | printf(" Serial Number: %08X%08X\n", be32_to_cpu(version_num), |
| 741 | be32_to_cpu(serial_num)); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 746 | int misc_init_r(void) |
| 747 | { |
Pali Rohár | 60f37e8 | 2022-04-08 16:30:14 +0200 | [diff] [blame] | 748 | turris_atsha_otp_init_mac_addresses(1); |
Marek Behún | 09e16b8 | 2017-06-09 19:28:45 +0200 | [diff] [blame] | 749 | return 0; |
| 750 | } |
| 751 | |
Marek Behún | 91ef59c | 2021-07-15 19:21:02 +0200 | [diff] [blame] | 752 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 753 | /* |
| 754 | * I plan to generalize this function and move it to common/fdt_support.c. |
| 755 | * This will require some more work on multiple boards, though, so for now leave |
| 756 | * it here. |
| 757 | */ |
| 758 | static bool fixup_mtd_partitions(void *blob, int offset, struct mtd_info *mtd) |
| 759 | { |
| 760 | struct mtd_info *slave; |
| 761 | int parts; |
| 762 | |
| 763 | parts = fdt_subnode_offset(blob, offset, "partitions"); |
| 764 | if (parts < 0) |
| 765 | return false; |
| 766 | |
| 767 | if (fdt_del_node(blob, parts) < 0) |
| 768 | return false; |
| 769 | |
| 770 | parts = fdt_add_subnode(blob, offset, "partitions"); |
| 771 | if (parts < 0) |
| 772 | return false; |
| 773 | |
| 774 | if (fdt_setprop_u32(blob, parts, "#address-cells", 1) < 0) |
| 775 | return false; |
| 776 | |
| 777 | if (fdt_setprop_u32(blob, parts, "#size-cells", 1) < 0) |
| 778 | return false; |
| 779 | |
| 780 | if (fdt_setprop_string(blob, parts, "compatible", |
| 781 | "fixed-partitions") < 0) |
| 782 | return false; |
| 783 | |
| 784 | mtd_probe_devices(); |
| 785 | |
Pali Rohár | d8210ef | 2021-10-21 17:55:48 +0200 | [diff] [blame] | 786 | list_for_each_entry_reverse(slave, &mtd->partitions, node) { |
Marek Behún | 91ef59c | 2021-07-15 19:21:02 +0200 | [diff] [blame] | 787 | char name[32]; |
| 788 | int part; |
| 789 | |
| 790 | snprintf(name, sizeof(name), "partition@%llx", slave->offset); |
| 791 | part = fdt_add_subnode(blob, parts, name); |
| 792 | if (part < 0) |
| 793 | return false; |
| 794 | |
| 795 | if (fdt_setprop_u32(blob, part, "reg", slave->offset) < 0) |
| 796 | return false; |
| 797 | |
| 798 | if (fdt_appendprop_u32(blob, part, "reg", slave->size) < 0) |
| 799 | return false; |
| 800 | |
| 801 | if (fdt_setprop_string(blob, part, "label", slave->name) < 0) |
| 802 | return false; |
| 803 | |
| 804 | if (!(slave->flags & MTD_WRITEABLE)) |
| 805 | if (fdt_setprop_empty(blob, part, "read-only") < 0) |
| 806 | return false; |
| 807 | |
| 808 | if (slave->flags & MTD_POWERUP_LOCK) |
| 809 | if (fdt_setprop_empty(blob, part, "lock") < 0) |
| 810 | return false; |
| 811 | } |
| 812 | |
| 813 | return true; |
| 814 | } |
| 815 | |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 816 | static void fixup_spi_nor_partitions(void *blob) |
Marek Behún | 91ef59c | 2021-07-15 19:21:02 +0200 | [diff] [blame] | 817 | { |
| 818 | struct mtd_info *mtd; |
| 819 | int node; |
| 820 | |
| 821 | mtd = get_mtd_device_nm(OMNIA_SPI_NOR_PATH); |
| 822 | if (IS_ERR_OR_NULL(mtd)) |
| 823 | goto fail; |
| 824 | |
| 825 | node = fdt_path_offset(blob, OMNIA_SPI_NOR_PATH); |
| 826 | if (node < 0) |
| 827 | goto fail; |
| 828 | |
| 829 | if (!fixup_mtd_partitions(blob, node, mtd)) |
| 830 | goto fail; |
| 831 | |
Marek Behún | 36feac9 | 2021-09-25 02:49:18 +0200 | [diff] [blame] | 832 | put_mtd_device(mtd); |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 833 | return; |
Marek Behún | 91ef59c | 2021-07-15 19:21:02 +0200 | [diff] [blame] | 834 | |
| 835 | fail: |
| 836 | printf("Failed fixing SPI NOR partitions!\n"); |
Marek Behún | 36feac9 | 2021-09-25 02:49:18 +0200 | [diff] [blame] | 837 | if (!IS_ERR_OR_NULL(mtd)) |
| 838 | put_mtd_device(mtd); |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 842 | { |
| 843 | fixup_spi_nor_partitions(blob); |
Pali Rohár | 7cd4173 | 2022-03-02 12:47:56 +0100 | [diff] [blame] | 844 | fixup_msata_port_nodes(blob); |
Pali Rohár | 93a89c5 | 2022-03-02 12:47:58 +0100 | [diff] [blame] | 845 | fixup_wwan_port_nodes(blob); |
Pali Rohár | cbda3e2 | 2022-01-10 11:47:18 +0100 | [diff] [blame] | 846 | |
Marek Behún | 91ef59c | 2021-07-15 19:21:02 +0200 | [diff] [blame] | 847 | return 0; |
| 848 | } |
| 849 | #endif |