Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Stefan Roese <sr@denx.de> |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 7 | #include <dm.h> |
Pali Rohár | f100063 | 2020-12-21 11:09:10 +0100 | [diff] [blame] | 8 | #include <dm/device-internal.h> |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 9 | #include <env.h> |
Pali Rohár | e892899 | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 10 | #include <env_internal.h> |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 11 | #include <event.h> |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 12 | #include <i2c.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 13 | #include <init.h> |
Pali Rohár | 71388ee | 2020-11-25 19:20:10 +0100 | [diff] [blame] | 14 | #include <mmc.h> |
Marek Behún | 56a776e | 2022-04-27 12:41:48 +0200 | [diff] [blame] | 15 | #include <miiphy.h> |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 16 | #include <phy.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 17 | #include <asm/global_data.h> |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 18 | #include <asm/io.h> |
| 19 | #include <asm/arch/cpu.h> |
| 20 | #include <asm/arch/soc.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 21 | #include <linux/delay.h> |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
| 25 | /* IO expander I2C device */ |
| 26 | #define I2C_IO_EXP_ADDR 0x22 |
| 27 | #define I2C_IO_CFG_REG_0 0x6 |
| 28 | #define I2C_IO_DATA_OUT_REG_0 0x2 |
| 29 | #define I2C_IO_REG_0_SATA_OFF 2 |
| 30 | #define I2C_IO_REG_0_USB_H_OFF 1 |
| 31 | |
Konstantin Porotchkin | b65ffc4 | 2017-02-16 13:52:32 +0200 | [diff] [blame] | 32 | /* The pin control values are the same for DB and Espressobin */ |
Konstantin Porotchkin | cfa88a3 | 2017-02-16 13:52:26 +0200 | [diff] [blame] | 33 | #define PINCTRL_NB_REG_VALUE 0x000173fa |
| 34 | #define PINCTRL_SB_REG_VALUE 0x00007a23 |
| 35 | |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 36 | /* Ethernet switch registers */ |
| 37 | /* SMI addresses for multi-chip mode */ |
| 38 | #define MVEBU_PORT_CTRL_SMI_ADDR(p) (16 + (p)) |
| 39 | #define MVEBU_SW_G2_SMI_ADDR (28) |
| 40 | |
| 41 | /* Multi-chip mode */ |
| 42 | #define MVEBU_SW_SMI_DATA_REG (1) |
| 43 | #define MVEBU_SW_SMI_CMD_REG (0) |
| 44 | #define SW_SMI_CMD_REG_ADDR_OFF 0 |
| 45 | #define SW_SMI_CMD_DEV_ADDR_OFF 5 |
| 46 | #define SW_SMI_CMD_SMI_OP_OFF 10 |
| 47 | #define SW_SMI_CMD_SMI_MODE_OFF 12 |
| 48 | #define SW_SMI_CMD_SMI_BUSY_OFF 15 |
| 49 | |
| 50 | /* Single-chip mode */ |
| 51 | /* Switch Port Registers */ |
| 52 | #define MVEBU_SW_LINK_CTRL_REG (1) |
| 53 | #define MVEBU_SW_PORT_CTRL_REG (4) |
Pali Rohár | 7325a81 | 2020-08-17 16:36:38 +0200 | [diff] [blame] | 54 | #define MVEBU_SW_PORT_BASE_VLAN (6) |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 55 | |
| 56 | /* Global 2 Registers */ |
| 57 | #define MVEBU_G2_SMI_PHY_CMD_REG (24) |
| 58 | #define MVEBU_G2_SMI_PHY_DATA_REG (25) |
| 59 | |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 60 | /* |
| 61 | * Memory Controller Registers |
| 62 | * |
| 63 | * Assembled based on public information: |
Pali Rohár | 5f85224 | 2022-01-21 12:01:15 +0100 | [diff] [blame] | 64 | * https://gitlab.nic.cz/turris/mox-boot-builder/-/blob/v2020.11.26/wtmi/main.c#L332-336 |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 65 | * https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell/blob/mv_ddr-armada-18.12/drivers/mv_ddr_mc6.h#L309-L332 |
| 66 | * |
| 67 | * And checked against the written register values for the various topologies: |
Pali Rohár | 5f85224 | 2022-01-21 12:01:15 +0100 | [diff] [blame] | 68 | * https://github.com/MarvellEmbeddedProcessors/mv-ddr-marvell/blob/master/a3700/mv_ddr_tim.h |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 69 | */ |
| 70 | #define A3700_CH0_MC_CTRL2_REG MVEBU_REGISTER(0x002c4) |
| 71 | #define A3700_MC_CTRL2_SDRAM_TYPE_MASK 0xf |
| 72 | #define A3700_MC_CTRL2_SDRAM_TYPE_OFFS 4 |
| 73 | #define A3700_MC_CTRL2_SDRAM_TYPE_DDR3 2 |
| 74 | #define A3700_MC_CTRL2_SDRAM_TYPE_DDR4 3 |
| 75 | |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 76 | int board_early_init_f(void) |
| 77 | { |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | int board_init(void) |
| 82 | { |
| 83 | /* adress of boot parameters */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 84 | gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100; |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 85 | |
| 86 | return 0; |
| 87 | } |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 88 | |
| 89 | #ifdef CONFIG_BOARD_LATE_INIT |
| 90 | int board_late_init(void) |
| 91 | { |
Marek Behún | 73d2534 | 2021-10-22 15:47:24 +0200 | [diff] [blame] | 92 | char *ptr = &default_environment[0]; |
Pali Rohár | f100063 | 2020-12-21 11:09:10 +0100 | [diff] [blame] | 93 | struct udevice *dev; |
Pali Rohár | 71388ee | 2020-11-25 19:20:10 +0100 | [diff] [blame] | 94 | struct mmc *mmc_dev; |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 95 | bool ddr4, emmc; |
Pali Rohár | 88d349a | 2020-12-23 12:21:30 +0100 | [diff] [blame] | 96 | const char *mac; |
| 97 | char eth[10]; |
| 98 | int i; |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 99 | |
Andre Heider | 3d33c1d | 2020-10-02 07:51:12 +0200 | [diff] [blame] | 100 | if (!of_machine_is_compatible("globalscale,espressobin")) |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 101 | return 0; |
| 102 | |
Derek LaHousse | 0bf72a9 | 2022-12-12 07:34:17 +0100 | [diff] [blame] | 103 | /* |
| 104 | * Find free space for new variables in default_environment[] array. |
| 105 | * Free space is after the last variable, each variable is termined |
| 106 | * by nul byte and after the last variable is additional nul byte. |
| 107 | * Move ptr to the position where new variable can be filled. |
| 108 | */ |
| 109 | while (*ptr != '\0') { |
| 110 | do { ptr++; } while (*ptr != '\0'); |
| 111 | ptr++; |
| 112 | } |
Pali Rohár | e892899 | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 113 | |
Pali Rohár | 88d349a | 2020-12-23 12:21:30 +0100 | [diff] [blame] | 114 | /* |
| 115 | * Ensure that 'env default -a' does not erase permanent MAC addresses |
| 116 | * stored in env variables: $ethaddr, $eth1addr, $eth2addr and $eth3addr |
| 117 | */ |
| 118 | |
| 119 | mac = env_get("ethaddr"); |
| 120 | if (mac && strlen(mac) <= 17) |
| 121 | ptr += sprintf(ptr, "ethaddr=%s", mac) + 1; |
| 122 | |
| 123 | for (i = 1; i <= 3; i++) { |
| 124 | sprintf(eth, "eth%daddr", i); |
| 125 | mac = env_get(eth); |
| 126 | if (mac && strlen(mac) <= 17) |
| 127 | ptr += sprintf(ptr, "%s=%s", eth, mac) + 1; |
| 128 | } |
| 129 | |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 130 | /* If the memory controller has been configured for DDR4, we're running on v7 */ |
| 131 | ddr4 = ((readl(A3700_CH0_MC_CTRL2_REG) >> A3700_MC_CTRL2_SDRAM_TYPE_OFFS) |
| 132 | & A3700_MC_CTRL2_SDRAM_TYPE_MASK) == A3700_MC_CTRL2_SDRAM_TYPE_DDR4; |
| 133 | |
Pali Rohár | 71388ee | 2020-11-25 19:20:10 +0100 | [diff] [blame] | 134 | /* eMMC is mmc dev num 1 */ |
| 135 | mmc_dev = find_mmc_device(1); |
Pali Rohár | 7c63962 | 2021-07-14 16:37:29 +0200 | [diff] [blame] | 136 | emmc = (mmc_dev && mmc_get_op_cond(mmc_dev, true) == 0); |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 137 | |
Pali Rohár | f100063 | 2020-12-21 11:09:10 +0100 | [diff] [blame] | 138 | /* if eMMC is not present then remove it from DM */ |
| 139 | if (!emmc && mmc_dev) { |
| 140 | dev = mmc_dev->dev; |
| 141 | device_remove(dev, DM_REMOVE_NORMAL); |
| 142 | device_unbind(dev); |
Pali Rohár | f71edd4 | 2022-08-27 14:00:51 +0200 | [diff] [blame] | 143 | if (of_live_active()) |
| 144 | ofnode_set_enabled(dev_ofnode(dev), false); |
Pali Rohár | f100063 | 2020-12-21 11:09:10 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Pali Rohár | e892899 | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 147 | /* Ensure that 'env default -a' set correct value to $fdtfile */ |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 148 | if (ddr4 && emmc) |
Pali Rohár | e892899 | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 149 | strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-v7-emmc.dtb"); |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 150 | else if (ddr4) |
Pali Rohár | e892899 | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 151 | strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-v7.dtb"); |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 152 | else if (emmc) |
Pali Rohár | e892899 | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 153 | strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin-emmc.dtb"); |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 154 | else |
Pali Rohár | e892899 | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 155 | strcpy(ptr, "fdtfile=marvell/armada-3720-espressobin.dtb"); |
Derek LaHousse | 0bf72a9 | 2022-12-12 07:34:17 +0100 | [diff] [blame] | 156 | ptr += strlen(ptr) + 1; |
| 157 | |
| 158 | /* |
| 159 | * After the last variable (which is nul term string) append another nul |
| 160 | * byte which terminates the list. So everything after ptr is ignored. |
| 161 | */ |
| 162 | *ptr = '\0'; |
Pali Rohár | e892899 | 2020-12-23 12:21:29 +0100 | [diff] [blame] | 163 | |
Andre Heider | ac81fa0 | 2020-09-11 06:35:10 +0200 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | #endif |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 167 | |
| 168 | /* Board specific AHCI / SATA enable code */ |
| 169 | int board_ahci_enable(void) |
| 170 | { |
| 171 | struct udevice *dev; |
| 172 | int ret; |
| 173 | u8 buf[8]; |
| 174 | |
Konstantin Porotchkin | b65ffc4 | 2017-02-16 13:52:32 +0200 | [diff] [blame] | 175 | /* Only DB requres this configuration */ |
| 176 | if (!of_machine_is_compatible("marvell,armada-3720-db")) |
| 177 | return 0; |
| 178 | |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 179 | /* Configure IO exander PCA9555: 7bit address 0x22 */ |
| 180 | ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev); |
| 181 | if (ret) { |
| 182 | printf("Cannot find PCA9555: %d\n", ret); |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1); |
| 187 | if (ret) { |
| 188 | printf("Failed to read IO expander value via I2C\n"); |
| 189 | return -EIO; |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * Enable SATA power via IO expander connected via I2C by setting |
| 194 | * the corresponding bit to output mode to enable power for SATA |
| 195 | */ |
| 196 | buf[0] &= ~(1 << I2C_IO_REG_0_SATA_OFF); |
| 197 | ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1); |
| 198 | if (ret) { |
| 199 | printf("Failed to set IO expander via I2C\n"); |
| 200 | return -EIO; |
| 201 | } |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | /* Board specific xHCI enable code */ |
Jon Nettleton | a81f47c | 2017-11-06 10:33:19 +0200 | [diff] [blame] | 207 | int board_xhci_enable(fdt_addr_t base) |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 208 | { |
| 209 | struct udevice *dev; |
| 210 | int ret; |
| 211 | u8 buf[8]; |
| 212 | |
Konstantin Porotchkin | b65ffc4 | 2017-02-16 13:52:32 +0200 | [diff] [blame] | 213 | /* Only DB requres this configuration */ |
| 214 | if (!of_machine_is_compatible("marvell,armada-3720-db")) |
| 215 | return 0; |
| 216 | |
Stefan Roese | 6edf27e | 2016-05-17 15:04:16 +0200 | [diff] [blame] | 217 | /* Configure IO exander PCA9555: 7bit address 0x22 */ |
| 218 | ret = i2c_get_chip_for_busnum(0, I2C_IO_EXP_ADDR, 1, &dev); |
| 219 | if (ret) { |
| 220 | printf("Cannot find PCA9555: %d\n", ret); |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | printf("Enable USB VBUS\n"); |
| 225 | |
| 226 | /* |
| 227 | * Read configuration (direction) and set VBUS pin as output |
| 228 | * (reset pin = output) |
| 229 | */ |
| 230 | ret = dm_i2c_read(dev, I2C_IO_CFG_REG_0, buf, 1); |
| 231 | if (ret) { |
| 232 | printf("Failed to read IO expander value via I2C\n"); |
| 233 | return -EIO; |
| 234 | } |
| 235 | buf[0] &= ~(1 << I2C_IO_REG_0_USB_H_OFF); |
| 236 | ret = dm_i2c_write(dev, I2C_IO_CFG_REG_0, buf, 1); |
| 237 | if (ret) { |
| 238 | printf("Failed to set IO expander via I2C\n"); |
| 239 | return -EIO; |
| 240 | } |
| 241 | |
| 242 | /* Read VBUS output value and disable it */ |
| 243 | ret = dm_i2c_read(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 244 | if (ret) { |
| 245 | printf("Failed to read IO expander value via I2C\n"); |
| 246 | return -EIO; |
| 247 | } |
| 248 | buf[0] &= ~(1 << I2C_IO_REG_0_USB_H_OFF); |
| 249 | ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 250 | if (ret) { |
| 251 | printf("Failed to set IO expander via I2C\n"); |
| 252 | return -EIO; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Required delay for configuration to settle - must wait for |
| 257 | * power on port is disabled in case VBUS signal was high, |
| 258 | * required 3 seconds delay to let VBUS signal fully settle down |
| 259 | */ |
| 260 | mdelay(3000); |
| 261 | |
| 262 | /* Enable VBUS power: Set output value of VBUS pin as enabled */ |
| 263 | buf[0] |= (1 << I2C_IO_REG_0_USB_H_OFF); |
| 264 | ret = dm_i2c_write(dev, I2C_IO_DATA_OUT_REG_0, buf, 1); |
| 265 | if (ret) { |
| 266 | printf("Failed to set IO expander via I2C\n"); |
| 267 | return -EIO; |
| 268 | } |
| 269 | |
| 270 | mdelay(500); /* required delay to let output value settle */ |
| 271 | |
| 272 | return 0; |
| 273 | } |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 274 | |
Marek Behún | 56a776e | 2022-04-27 12:41:48 +0200 | [diff] [blame] | 275 | #ifdef CONFIG_LAST_STAGE_INIT |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 276 | /* Helper function for accessing switch devices in multi-chip connection mode */ |
Marek Behún | 56a776e | 2022-04-27 12:41:48 +0200 | [diff] [blame] | 277 | static int mii_multi_chip_mode_write(struct udevice *bus, int dev_smi_addr, |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 278 | int smi_addr, int reg, u16 value) |
| 279 | { |
| 280 | u16 smi_cmd = 0; |
| 281 | |
Marek Behún | 56a776e | 2022-04-27 12:41:48 +0200 | [diff] [blame] | 282 | if (dm_mdio_write(bus, dev_smi_addr, MDIO_DEVAD_NONE, |
| 283 | MVEBU_SW_SMI_DATA_REG, value) != 0) { |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 284 | printf("Error writing to the PHY addr=%02x reg=%02x\n", |
| 285 | smi_addr, reg); |
| 286 | return -EFAULT; |
| 287 | } |
| 288 | |
| 289 | smi_cmd = (1 << SW_SMI_CMD_SMI_BUSY_OFF) | |
| 290 | (1 << SW_SMI_CMD_SMI_MODE_OFF) | |
| 291 | (1 << SW_SMI_CMD_SMI_OP_OFF) | |
| 292 | (smi_addr << SW_SMI_CMD_DEV_ADDR_OFF) | |
| 293 | (reg << SW_SMI_CMD_REG_ADDR_OFF); |
Marek Behún | 56a776e | 2022-04-27 12:41:48 +0200 | [diff] [blame] | 294 | if (dm_mdio_write(bus, dev_smi_addr, MDIO_DEVAD_NONE, |
| 295 | MVEBU_SW_SMI_CMD_REG, smi_cmd) != 0) { |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 296 | printf("Error writing to the PHY addr=%02x reg=%02x\n", |
| 297 | smi_addr, reg); |
| 298 | return -EFAULT; |
| 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | /* Bring-up board-specific network stuff */ |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 305 | static int last_stage_init(void) |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 306 | { |
Marek Behún | 56a776e | 2022-04-27 12:41:48 +0200 | [diff] [blame] | 307 | struct udevice *bus; |
| 308 | ofnode node; |
| 309 | |
Simon Glass | aadec12 | 2023-09-20 07:29:51 -0600 | [diff] [blame^] | 310 | if (!CONFIG_IS_ENABLED(DM_MDIO) || |
| 311 | !of_machine_is_compatible("globalscale,espressobin")) |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 312 | return 0; |
| 313 | |
Marek Behún | 56a776e | 2022-04-27 12:41:48 +0200 | [diff] [blame] | 314 | node = ofnode_by_compatible(ofnode_null(), "marvell,orion-mdio"); |
| 315 | if (!ofnode_valid(node) || |
| 316 | uclass_get_device_by_ofnode(UCLASS_MDIO, node, &bus) || |
| 317 | device_probe(bus)) { |
| 318 | printf("Cannot find MDIO bus\n"); |
| 319 | return 0; |
| 320 | } |
| 321 | |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 322 | /* |
| 323 | * FIXME: remove this code once Topaz driver gets available |
| 324 | * A3720 Community Board Only |
| 325 | * Configure Topaz switch (88E6341) |
Pali Rohár | 7325a81 | 2020-08-17 16:36:38 +0200 | [diff] [blame] | 326 | * Restrict output to ports 1,2,3 only from port 0 (CPU) |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 327 | * Set port 0,1,2,3 to forwarding Mode (through Switch Port registers) |
| 328 | */ |
Pali Rohár | 7325a81 | 2020-08-17 16:36:38 +0200 | [diff] [blame] | 329 | mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(1), |
| 330 | MVEBU_SW_PORT_BASE_VLAN, BIT(0)); |
| 331 | mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(2), |
| 332 | MVEBU_SW_PORT_BASE_VLAN, BIT(0)); |
| 333 | mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(3), |
| 334 | MVEBU_SW_PORT_BASE_VLAN, BIT(0)); |
| 335 | |
Konstantin Porotchkin | f4d32b4 | 2017-02-16 13:52:29 +0200 | [diff] [blame] | 336 | mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(0), |
| 337 | MVEBU_SW_PORT_CTRL_REG, 0x7f); |
| 338 | mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(1), |
| 339 | MVEBU_SW_PORT_CTRL_REG, 0x7f); |
| 340 | mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(2), |
| 341 | MVEBU_SW_PORT_CTRL_REG, 0x7f); |
| 342 | mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(3), |
| 343 | MVEBU_SW_PORT_CTRL_REG, 0x7f); |
| 344 | |
| 345 | /* RGMII Delay on Port 0 (CPU port), force link to 1000Mbps */ |
| 346 | mii_multi_chip_mode_write(bus, 1, MVEBU_PORT_CTRL_SMI_ADDR(0), |
| 347 | MVEBU_SW_LINK_CTRL_REG, 0xe002); |
| 348 | |
| 349 | /* Power up PHY 1, 2, 3 (through Global 2 registers) */ |
| 350 | mii_multi_chip_mode_write(bus, 1, MVEBU_SW_G2_SMI_ADDR, |
| 351 | MVEBU_G2_SMI_PHY_DATA_REG, 0x1140); |
| 352 | mii_multi_chip_mode_write(bus, 1, MVEBU_SW_G2_SMI_ADDR, |
| 353 | MVEBU_G2_SMI_PHY_CMD_REG, 0x9620); |
| 354 | mii_multi_chip_mode_write(bus, 1, MVEBU_SW_G2_SMI_ADDR, |
| 355 | MVEBU_G2_SMI_PHY_CMD_REG, 0x9640); |
| 356 | mii_multi_chip_mode_write(bus, 1, MVEBU_SW_G2_SMI_ADDR, |
| 357 | MVEBU_G2_SMI_PHY_CMD_REG, 0x9660); |
| 358 | |
| 359 | return 0; |
| 360 | } |
Simon Glass | 1cedca1 | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 361 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); |
| 362 | |
Marek Behún | 56a776e | 2022-04-27 12:41:48 +0200 | [diff] [blame] | 363 | #endif |
Pali Rohár | cb00c18 | 2020-08-19 16:24:17 +0200 | [diff] [blame] | 364 | |
Rogier Stam | e0e10d4 | 2022-02-09 00:27:00 +0100 | [diff] [blame] | 365 | #ifdef CONFIG_OF_BOARD_SETUP |
Pali Rohár | cb00c18 | 2020-08-19 16:24:17 +0200 | [diff] [blame] | 366 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 367 | { |
Rogier Stam | e0e10d4 | 2022-02-09 00:27:00 +0100 | [diff] [blame] | 368 | #ifdef CONFIG_ENV_IS_IN_SPI_FLASH |
Pali Rohár | cb00c18 | 2020-08-19 16:24:17 +0200 | [diff] [blame] | 369 | int ret; |
| 370 | int spi_off; |
| 371 | int parts_off; |
| 372 | int part_off; |
| 373 | |
| 374 | /* Fill SPI MTD partitions for Linux kernel on Espressobin */ |
Andre Heider | 3d33c1d | 2020-10-02 07:51:12 +0200 | [diff] [blame] | 375 | if (!of_machine_is_compatible("globalscale,espressobin")) |
Pali Rohár | cb00c18 | 2020-08-19 16:24:17 +0200 | [diff] [blame] | 376 | return 0; |
| 377 | |
| 378 | spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor"); |
| 379 | if (spi_off < 0) |
| 380 | return 0; |
| 381 | |
| 382 | /* Do not touch partitions if they are already defined */ |
| 383 | if (fdt_subnode_offset(blob, spi_off, "partitions") >= 0) |
| 384 | return 0; |
| 385 | |
| 386 | parts_off = fdt_add_subnode(blob, spi_off, "partitions"); |
| 387 | if (parts_off < 0) { |
| 388 | printf("Can't add partitions node: %s\n", fdt_strerror(parts_off)); |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | ret = fdt_setprop_string(blob, parts_off, "compatible", "fixed-partitions"); |
| 393 | if (ret < 0) { |
| 394 | printf("Can't set compatible property: %s\n", fdt_strerror(ret)); |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | ret = fdt_setprop_u32(blob, parts_off, "#address-cells", 1); |
| 399 | if (ret < 0) { |
| 400 | printf("Can't set #address-cells property: %s\n", fdt_strerror(ret)); |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | ret = fdt_setprop_u32(blob, parts_off, "#size-cells", 1); |
| 405 | if (ret < 0) { |
| 406 | printf("Can't set #size-cells property: %s\n", fdt_strerror(ret)); |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | /* Add u-boot-env partition */ |
| 411 | |
| 412 | part_off = fdt_add_subnode(blob, parts_off, "partition@u-boot-env"); |
| 413 | if (part_off < 0) { |
| 414 | printf("Can't add partition@u-boot-env node: %s\n", fdt_strerror(part_off)); |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | ret = fdt_setprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET); |
| 419 | if (ret < 0) { |
| 420 | printf("Can't set partition@u-boot-env reg property: %s\n", fdt_strerror(ret)); |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | ret = fdt_appendprop_u32(blob, part_off, "reg", CONFIG_ENV_SIZE); |
| 425 | if (ret < 0) { |
| 426 | printf("Can't set partition@u-boot-env reg property: %s\n", fdt_strerror(ret)); |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | ret = fdt_setprop_string(blob, part_off, "label", "u-boot-env"); |
| 431 | if (ret < 0) { |
| 432 | printf("Can't set partition@u-boot-env label property: %s\n", fdt_strerror(ret)); |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | /* Add firmware partition */ |
| 437 | |
| 438 | part_off = fdt_add_subnode(blob, parts_off, "partition@firmware"); |
| 439 | if (part_off < 0) { |
| 440 | printf("Can't add partition@firmware node: %s\n", fdt_strerror(part_off)); |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | ret = fdt_setprop_u32(blob, part_off, "reg", 0); |
| 445 | if (ret < 0) { |
| 446 | printf("Can't set partition@firmware reg property: %s\n", fdt_strerror(ret)); |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | ret = fdt_appendprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET); |
| 451 | if (ret < 0) { |
| 452 | printf("Can't set partition@firmware reg property: %s\n", fdt_strerror(ret)); |
| 453 | return 0; |
| 454 | } |
| 455 | |
| 456 | ret = fdt_setprop_string(blob, part_off, "label", "firmware"); |
| 457 | if (ret < 0) { |
| 458 | printf("Can't set partition@firmware label property: %s\n", fdt_strerror(ret)); |
| 459 | return 0; |
| 460 | } |
| 461 | |
Rogier Stam | e0e10d4 | 2022-02-09 00:27:00 +0100 | [diff] [blame] | 462 | #endif |
Pali Rohár | cb00c18 | 2020-08-19 16:24:17 +0200 | [diff] [blame] | 463 | return 0; |
| 464 | } |
| 465 | #endif |