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