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