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