Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2018 Marek Behun <marek.behun@nic.cz> |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Marek Behún | 455ef5b | 2020-04-08 19:25:22 +0200 | [diff] [blame] | 7 | #include <asm/arch/cpu.h> |
Marek Behún | 1055ce1 | 2020-04-08 12:02:07 +0200 | [diff] [blame] | 8 | #include <asm/arch/soc.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 11 | #include <asm/io.h> |
Marek Behún | 28e935f | 2020-04-08 12:02:08 +0200 | [diff] [blame] | 12 | #include <asm/gpio.h> |
Marek Behún | 859ada5 | 2021-06-07 16:34:47 +0200 | [diff] [blame] | 13 | #include <button.h> |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 14 | #include <clk.h> |
Marek Behún | 28e935f | 2020-04-08 12:02:08 +0200 | [diff] [blame] | 15 | #include <dm.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 16 | #include <env.h> |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 17 | #include <fdt_support.h> |
Marek Behún | 28e935f | 2020-04-08 12:02:08 +0200 | [diff] [blame] | 18 | #include <init.h> |
Marek Behún | 859ada5 | 2021-06-07 16:34:47 +0200 | [diff] [blame] | 19 | #include <led.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Marek Behún | 28e935f | 2020-04-08 12:02:08 +0200 | [diff] [blame] | 21 | #include <linux/libfdt.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <miiphy.h> |
| 24 | #include <mvebu/comphy.h> |
| 25 | #include <spi.h> |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 26 | |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 27 | #include "mox_sp.h" |
| 28 | |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 29 | #define MAX_MOX_MODULES 10 |
| 30 | |
| 31 | #define MOX_MODULE_SFP 0x1 |
| 32 | #define MOX_MODULE_PCI 0x2 |
| 33 | #define MOX_MODULE_TOPAZ 0x3 |
| 34 | #define MOX_MODULE_PERIDOT 0x4 |
| 35 | #define MOX_MODULE_USB3 0x5 |
| 36 | #define MOX_MODULE_PASSPCI 0x6 |
| 37 | |
Marek Behún | 1055ce1 | 2020-04-08 12:02:07 +0200 | [diff] [blame] | 38 | #define ARMADA_37XX_NB_GPIO_SEL (MVEBU_REGISTER(0x13830)) |
| 39 | #define ARMADA_37XX_SPI_CTRL (MVEBU_REGISTER(0x10600)) |
| 40 | #define ARMADA_37XX_SPI_CFG (MVEBU_REGISTER(0x10604)) |
| 41 | #define ARMADA_37XX_SPI_DOUT (MVEBU_REGISTER(0x10608)) |
| 42 | #define ARMADA_37XX_SPI_DIN (MVEBU_REGISTER(0x1060c)) |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 43 | |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 44 | #define ETH1_PATH "/soc/internal-regs@d0000000/ethernet@40000" |
| 45 | #define MDIO_PATH "/soc/internal-regs@d0000000/mdio@32004" |
| 46 | #define SFP_GPIO_PATH "/soc/internal-regs@d0000000/spi@10600/moxtet@1/gpio@0" |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 47 | #define PCIE_PATH "/soc/pcie@d0070000" |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 48 | #define SFP_PATH "/sfp" |
Marek Behún | 859ada5 | 2021-06-07 16:34:47 +0200 | [diff] [blame] | 49 | #define LED_PATH "/leds/led" |
| 50 | #define BUTTON_PATH "/gpio-keys/reset" |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 51 | |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 52 | DECLARE_GLOBAL_DATA_PTR; |
| 53 | |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 54 | #if defined(CONFIG_OF_BOARD_FIXUP) |
| 55 | int board_fix_fdt(void *blob) |
| 56 | { |
| 57 | u8 topology[MAX_MOX_MODULES]; |
| 58 | int i, size, node; |
| 59 | bool enable; |
| 60 | |
| 61 | /* |
| 62 | * SPI driver is not loaded in driver model yet, but we have to find out |
| 63 | * if pcie should be enabled in U-Boot's device tree. Therefore we have |
| 64 | * to read SPI by reading/writing SPI registers directly |
| 65 | */ |
| 66 | |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 67 | writel(0x10df, ARMADA_37XX_SPI_CFG); |
Marek Behún | a4e697f | 2020-04-08 12:02:03 +0200 | [diff] [blame] | 68 | /* put pin from GPIO to SPI mode */ |
| 69 | clrbits_le32(ARMADA_37XX_NB_GPIO_SEL, BIT(12)); |
| 70 | /* enable SPI CS1 */ |
| 71 | setbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17)); |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 72 | |
| 73 | while (!(readl(ARMADA_37XX_SPI_CTRL) & 0x2)) |
| 74 | udelay(1); |
| 75 | |
| 76 | for (i = 0; i < MAX_MOX_MODULES; ++i) { |
| 77 | writel(0x0, ARMADA_37XX_SPI_DOUT); |
| 78 | |
| 79 | while (!(readl(ARMADA_37XX_SPI_CTRL) & 0x2)) |
| 80 | udelay(1); |
| 81 | |
| 82 | topology[i] = readl(ARMADA_37XX_SPI_DIN) & 0xff; |
| 83 | if (topology[i] == 0xff) |
| 84 | break; |
| 85 | |
| 86 | topology[i] &= 0xf; |
| 87 | } |
| 88 | |
| 89 | size = i; |
| 90 | |
Marek Behún | a4e697f | 2020-04-08 12:02:03 +0200 | [diff] [blame] | 91 | /* disable SPI CS1 */ |
| 92 | clrbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17)); |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 93 | |
| 94 | if (size > 1 && (topology[1] == MOX_MODULE_PCI || |
| 95 | topology[1] == MOX_MODULE_USB3 || |
| 96 | topology[1] == MOX_MODULE_PASSPCI)) |
| 97 | enable = true; |
| 98 | else |
| 99 | enable = false; |
| 100 | |
| 101 | node = fdt_path_offset(blob, PCIE_PATH); |
| 102 | |
| 103 | if (node < 0) { |
| 104 | printf("Cannot find PCIe node in U-Boot's device tree!\n"); |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | if (fdt_setprop_string(blob, node, "status", |
| 109 | enable ? "okay" : "disabled") < 0) { |
| 110 | printf("Cannot %s PCIe in U-Boot's device tree!\n", |
| 111 | enable ? "enable" : "disable"); |
| 112 | return 0; |
| 113 | } |
| 114 | |
Marek Behún | 455ef5b | 2020-04-08 19:25:22 +0200 | [diff] [blame] | 115 | if (a3700_fdt_fix_pcie_regions(blob) < 0) { |
| 116 | printf("Cannot fix PCIe regions in U-Boot's device tree!\n"); |
| 117 | return 0; |
| 118 | } |
| 119 | |
Marek Behún | 9602a8c | 2018-08-21 12:22:09 +0200 | [diff] [blame] | 120 | return 0; |
| 121 | } |
| 122 | #endif |
| 123 | |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 124 | int board_init(void) |
| 125 | { |
| 126 | /* address of boot parameters */ |
| 127 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
| 128 | |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 129 | return 0; |
| 130 | } |
| 131 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 132 | static int mox_do_spi(u8 *in, u8 *out, size_t size) |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 133 | { |
| 134 | struct spi_slave *slave; |
| 135 | struct udevice *dev; |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 136 | int ret; |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 137 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 138 | ret = spi_get_bus_and_cs(0, 1, 1000000, SPI_CPHA | SPI_CPOL, |
| 139 | "spi_generic_drv", "moxtet@1", &dev, |
| 140 | &slave); |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 141 | if (ret) |
| 142 | goto fail; |
| 143 | |
| 144 | ret = spi_claim_bus(slave); |
| 145 | if (ret) |
| 146 | goto fail_free; |
| 147 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 148 | ret = spi_xfer(slave, size * 8, out, in, SPI_XFER_ONCE); |
| 149 | |
| 150 | spi_release_bus(slave); |
| 151 | fail_free: |
| 152 | spi_free_slave(slave); |
| 153 | fail: |
| 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | static int mox_get_topology(const u8 **ptopology, int *psize, int *pis_sd) |
| 158 | { |
| 159 | static int is_sd; |
| 160 | static u8 topology[MAX_MOX_MODULES - 1]; |
| 161 | static int size; |
| 162 | u8 din[MAX_MOX_MODULES], dout[MAX_MOX_MODULES]; |
| 163 | int ret, i; |
| 164 | |
| 165 | if (size) { |
| 166 | if (ptopology) |
| 167 | *ptopology = topology; |
| 168 | if (psize) |
| 169 | *psize = size; |
| 170 | if (pis_sd) |
| 171 | *pis_sd = is_sd; |
| 172 | return 0; |
| 173 | } |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 174 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 175 | memset(din, 0, MAX_MOX_MODULES); |
| 176 | memset(dout, 0, MAX_MOX_MODULES); |
| 177 | |
| 178 | ret = mox_do_spi(din, dout, MAX_MOX_MODULES); |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 179 | if (ret) |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 180 | return ret; |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 181 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 182 | if (din[0] == 0x10) |
| 183 | is_sd = 1; |
| 184 | else if (din[0] == 0x00) |
| 185 | is_sd = 0; |
| 186 | else |
| 187 | return -ENODEV; |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 188 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 189 | for (i = 1; i < MAX_MOX_MODULES && din[i] != 0xff; ++i) |
| 190 | topology[i - 1] = din[i] & 0xf; |
| 191 | size = i - 1; |
| 192 | |
| 193 | if (ptopology) |
| 194 | *ptopology = topology; |
| 195 | if (psize) |
| 196 | *psize = size; |
| 197 | if (pis_sd) |
| 198 | *pis_sd = is_sd; |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
Marek Behún | a261d13 | 2018-12-17 16:10:02 +0100 | [diff] [blame] | 203 | int comphy_update_map(struct comphy_map *serdes_map, int count) |
| 204 | { |
| 205 | int ret, i, size, sfpindex = -1, swindex = -1; |
| 206 | const u8 *topology; |
| 207 | |
| 208 | ret = mox_get_topology(&topology, &size, NULL); |
| 209 | if (ret) |
| 210 | return ret; |
| 211 | |
| 212 | for (i = 0; i < size; ++i) { |
| 213 | if (topology[i] == MOX_MODULE_SFP && sfpindex == -1) |
| 214 | sfpindex = i; |
| 215 | else if ((topology[i] == MOX_MODULE_TOPAZ || |
| 216 | topology[i] == MOX_MODULE_PERIDOT) && |
| 217 | swindex == -1) |
| 218 | swindex = i; |
| 219 | } |
| 220 | |
| 221 | if (sfpindex >= 0 && swindex >= 0) { |
| 222 | if (sfpindex < swindex) |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 223 | serdes_map[0].speed = COMPHY_SPEED_1_25G; |
Marek Behún | a261d13 | 2018-12-17 16:10:02 +0100 | [diff] [blame] | 224 | else |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 225 | serdes_map[0].speed = COMPHY_SPEED_3_125G; |
Marek Behún | a261d13 | 2018-12-17 16:10:02 +0100 | [diff] [blame] | 226 | } else if (sfpindex >= 0) { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 227 | serdes_map[0].speed = COMPHY_SPEED_1_25G; |
Marek Behún | a261d13 | 2018-12-17 16:10:02 +0100 | [diff] [blame] | 228 | } else if (swindex >= 0) { |
Igal Liberman | ffd5d2f | 2017-04-26 15:40:00 +0300 | [diff] [blame] | 229 | serdes_map[0].speed = COMPHY_SPEED_3_125G; |
Marek Behún | a261d13 | 2018-12-17 16:10:02 +0100 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 235 | #define SW_SMI_CMD_R(d, r) (0x9800 | (((d) & 0x1f) << 5) | ((r) & 0x1f)) |
| 236 | #define SW_SMI_CMD_W(d, r) (0x9400 | (((d) & 0x1f) << 5) | ((r) & 0x1f)) |
| 237 | |
| 238 | static int sw_multi_read(struct mii_dev *bus, int sw, int dev, int reg) |
| 239 | { |
| 240 | bus->write(bus, sw, 0, 0, SW_SMI_CMD_R(dev, reg)); |
| 241 | mdelay(5); |
| 242 | return bus->read(bus, sw, 0, 1); |
| 243 | } |
| 244 | |
| 245 | static void sw_multi_write(struct mii_dev *bus, int sw, int dev, int reg, |
| 246 | u16 val) |
| 247 | { |
| 248 | bus->write(bus, sw, 0, 1, val); |
| 249 | bus->write(bus, sw, 0, 0, SW_SMI_CMD_W(dev, reg)); |
| 250 | mdelay(5); |
| 251 | } |
| 252 | |
| 253 | static int sw_scratch_read(struct mii_dev *bus, int sw, int reg) |
| 254 | { |
| 255 | sw_multi_write(bus, sw, 0x1c, 0x1a, (reg & 0x7f) << 8); |
| 256 | return sw_multi_read(bus, sw, 0x1c, 0x1a) & 0xff; |
| 257 | } |
| 258 | |
| 259 | static void sw_led_write(struct mii_dev *bus, int sw, int port, int reg, |
| 260 | u16 val) |
| 261 | { |
| 262 | sw_multi_write(bus, sw, port, 0x16, 0x8000 | ((reg & 7) << 12) |
| 263 | | (val & 0x7ff)); |
| 264 | } |
| 265 | |
| 266 | static void sw_blink_leds(struct mii_dev *bus, int peridot, int topaz) |
| 267 | { |
| 268 | int i, p; |
| 269 | struct { |
| 270 | int port; |
| 271 | u16 val; |
| 272 | int wait; |
| 273 | } regs[] = { |
| 274 | { 2, 0xef, 1 }, { 2, 0xfe, 1 }, { 2, 0x33, 0 }, |
| 275 | { 4, 0xef, 1 }, { 4, 0xfe, 1 }, { 4, 0x33, 0 }, |
| 276 | { 3, 0xfe, 1 }, { 3, 0xef, 1 }, { 3, 0x33, 0 }, |
| 277 | { 1, 0xfe, 1 }, { 1, 0xef, 1 }, { 1, 0x33, 0 } |
| 278 | }; |
| 279 | |
| 280 | for (i = 0; i < 12; ++i) { |
| 281 | for (p = 0; p < peridot; ++p) { |
| 282 | sw_led_write(bus, 0x10 + p, regs[i].port, 0, |
| 283 | regs[i].val); |
| 284 | sw_led_write(bus, 0x10 + p, regs[i].port + 4, 0, |
| 285 | regs[i].val); |
| 286 | } |
| 287 | if (topaz) { |
| 288 | sw_led_write(bus, 0x2, 0x10 + regs[i].port, 0, |
| 289 | regs[i].val); |
| 290 | } |
| 291 | |
| 292 | if (regs[i].wait) |
| 293 | mdelay(75); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | static void check_switch_address(struct mii_dev *bus, int addr) |
| 298 | { |
| 299 | if (sw_scratch_read(bus, addr, 0x70) >> 3 != addr) |
| 300 | printf("Check of switch MDIO address failed for 0x%02x\n", |
| 301 | addr); |
| 302 | } |
| 303 | |
| 304 | static int sfp, pci, topaz, peridot, usb, passpci; |
| 305 | static int sfp_pos, peridot_pos[3]; |
| 306 | static int module_count; |
| 307 | |
| 308 | static int configure_peridots(struct gpio_desc *reset_gpio) |
| 309 | { |
| 310 | int i, ret; |
| 311 | u8 dout[MAX_MOX_MODULES]; |
| 312 | |
| 313 | memset(dout, 0, MAX_MOX_MODULES); |
| 314 | |
| 315 | /* set addresses of Peridot modules */ |
| 316 | for (i = 0; i < peridot; ++i) |
| 317 | dout[module_count - peridot_pos[i]] = (~i) & 3; |
| 318 | |
| 319 | /* |
| 320 | * if there is a SFP module connected to the last Peridot module, set |
| 321 | * the P10_SMODE to 1 for the Peridot module |
| 322 | */ |
| 323 | if (sfp) |
| 324 | dout[module_count - peridot_pos[i - 1]] |= 1 << 3; |
| 325 | |
| 326 | dm_gpio_set_value(reset_gpio, 1); |
| 327 | mdelay(10); |
| 328 | |
| 329 | ret = mox_do_spi(NULL, dout, module_count + 1); |
| 330 | |
| 331 | mdelay(10); |
| 332 | dm_gpio_set_value(reset_gpio, 0); |
| 333 | |
| 334 | mdelay(50); |
| 335 | |
| 336 | return ret; |
| 337 | } |
| 338 | |
| 339 | static int get_reset_gpio(struct gpio_desc *reset_gpio) |
| 340 | { |
| 341 | int node; |
| 342 | |
| 343 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "cznic,moxtet"); |
| 344 | if (node < 0) { |
| 345 | printf("Cannot find Moxtet bus device node!\n"); |
| 346 | return -1; |
| 347 | } |
| 348 | |
| 349 | gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpios", 0, |
| 350 | reset_gpio, GPIOD_IS_OUT); |
| 351 | |
| 352 | if (!dm_gpio_is_valid(reset_gpio)) { |
| 353 | printf("Cannot find reset GPIO for Moxtet bus!\n"); |
| 354 | return -1; |
| 355 | } |
| 356 | |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | int misc_init_r(void) |
| 361 | { |
| 362 | int ret; |
| 363 | u8 mac1[6], mac2[6]; |
| 364 | |
| 365 | ret = mbox_sp_get_board_info(NULL, mac1, mac2, NULL, NULL); |
| 366 | if (ret < 0) { |
| 367 | printf("Cannot read data from OTP!\n"); |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | if (is_valid_ethaddr(mac1) && !env_get("ethaddr")) |
| 372 | eth_env_set_enetaddr("ethaddr", mac1); |
| 373 | |
| 374 | if (is_valid_ethaddr(mac2) && !env_get("eth1addr")) |
| 375 | eth_env_set_enetaddr("eth1addr", mac2); |
| 376 | |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 377 | return 0; |
| 378 | } |
| 379 | |
Marek Behún | d1a3079 | 2021-06-07 16:34:48 +0200 | [diff] [blame^] | 380 | static void mox_phy_modify(struct phy_device *phydev, int page, int reg, |
| 381 | u16 mask, u16 set) |
| 382 | { |
| 383 | int val; |
| 384 | |
| 385 | val = phydev->drv->readext(phydev, MDIO_DEVAD_NONE, page, reg); |
| 386 | val &= ~mask; |
| 387 | val |= set; |
| 388 | phydev->drv->writeext(phydev, MDIO_DEVAD_NONE, page, reg, val); |
| 389 | } |
| 390 | |
| 391 | static void mox_phy_leds_start_blinking(void) |
| 392 | { |
| 393 | struct phy_device *phydev; |
| 394 | struct mii_dev *bus; |
| 395 | |
| 396 | bus = miiphy_get_dev_by_name("neta@30000"); |
| 397 | if (!bus) { |
| 398 | printf("Cannot get MDIO bus device!\n"); |
| 399 | return; |
| 400 | } |
| 401 | |
| 402 | phydev = phy_find_by_mask(bus, BIT(1), PHY_INTERFACE_MODE_RGMII); |
| 403 | if (!phydev) { |
| 404 | printf("Cannot get ethernet PHY!\n"); |
| 405 | return; |
| 406 | } |
| 407 | |
| 408 | mox_phy_modify(phydev, 3, 0x12, 0x700, 0x400); |
| 409 | mox_phy_modify(phydev, 3, 0x10, 0xff, 0xbb); |
| 410 | } |
| 411 | |
Marek Behún | 859ada5 | 2021-06-07 16:34:47 +0200 | [diff] [blame] | 412 | static bool read_reset_button(void) |
| 413 | { |
| 414 | struct udevice *button, *led; |
| 415 | int i; |
| 416 | |
| 417 | if (device_get_global_by_ofnode(ofnode_path(BUTTON_PATH), &button)) { |
| 418 | printf("Cannot find reset button!\n"); |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | if (device_get_global_by_ofnode(ofnode_path(LED_PATH), &led)) { |
| 423 | printf("Cannot find status LED!\n"); |
| 424 | return false; |
| 425 | } |
| 426 | |
| 427 | led_set_state(led, LEDST_ON); |
| 428 | |
| 429 | for (i = 0; i < 21; ++i) { |
| 430 | if (button_get_state(button) != BUTTON_ON) |
| 431 | return false; |
| 432 | if (i < 20) |
| 433 | mdelay(50); |
| 434 | } |
| 435 | |
| 436 | led_set_state(led, LEDST_OFF); |
| 437 | |
| 438 | return true; |
| 439 | } |
| 440 | |
| 441 | static void handle_reset_button(void) |
| 442 | { |
| 443 | if (read_reset_button()) { |
| 444 | const char * const vars[3] = { |
| 445 | "bootcmd", |
| 446 | "bootcmd_rescue", |
| 447 | "distro_bootcmd", |
| 448 | }; |
| 449 | |
| 450 | /* |
| 451 | * Set the above envs to their default values, in case the user |
| 452 | * managed to break them. |
| 453 | */ |
| 454 | env_set_default_vars(3, (char * const *)vars, 0); |
| 455 | |
| 456 | /* Ensure bootcmd_rescue is used by distroboot */ |
| 457 | env_set("boot_targets", "rescue"); |
| 458 | |
Marek Behún | d1a3079 | 2021-06-07 16:34:48 +0200 | [diff] [blame^] | 459 | /* start blinking PHY LEDs */ |
| 460 | mox_phy_leds_start_blinking(); |
| 461 | |
Marek Behún | 859ada5 | 2021-06-07 16:34:47 +0200 | [diff] [blame] | 462 | printf("RESET button was pressed, overwriting boot_targets!\n"); |
| 463 | } else { |
| 464 | /* |
| 465 | * In case the user somehow managed to save environment with |
| 466 | * boot_targets=rescue, reset boot_targets to default value. |
| 467 | * This could happen in subsequent commands if bootcmd_rescue |
| 468 | * failed. |
| 469 | */ |
| 470 | if (!strcmp(env_get("boot_targets"), "rescue")) { |
| 471 | const char * const vars[1] = { |
| 472 | "boot_targets", |
| 473 | }; |
| 474 | |
| 475 | env_set_default_vars(1, (char * const *)vars, 0); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 480 | static void mox_print_info(void) |
| 481 | { |
| 482 | int ret, board_version, ram_size; |
| 483 | u64 serial_number; |
| 484 | const char *pub_key; |
| 485 | |
| 486 | ret = mbox_sp_get_board_info(&serial_number, NULL, NULL, &board_version, |
| 487 | &ram_size); |
| 488 | if (ret < 0) |
| 489 | return; |
| 490 | |
| 491 | printf("Turris Mox:\n"); |
| 492 | printf(" Board version: %i\n", board_version); |
| 493 | printf(" RAM size: %i MiB\n", ram_size); |
| 494 | printf(" Serial Number: %016llX\n", serial_number); |
| 495 | |
| 496 | pub_key = mox_sp_get_ecdsa_public_key(); |
| 497 | if (pub_key) |
| 498 | printf(" ECDSA Public Key: %s\n", pub_key); |
| 499 | else |
| 500 | printf("Cannot read ECDSA Public Key\n"); |
| 501 | } |
| 502 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 503 | int last_stage_init(void) |
| 504 | { |
| 505 | int ret, i; |
| 506 | const u8 *topology; |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 507 | int is_sd; |
| 508 | struct mii_dev *bus; |
| 509 | struct gpio_desc reset_gpio = {}; |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 510 | |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 511 | mox_print_info(); |
| 512 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 513 | ret = mox_get_topology(&topology, &module_count, &is_sd); |
| 514 | if (ret) { |
| 515 | printf("Cannot read module topology!\n"); |
| 516 | return 0; |
| 517 | } |
| 518 | |
Marek Behún | 35572c9 | 2018-12-17 16:10:08 +0100 | [diff] [blame] | 519 | printf(" SD/eMMC version: %s\n", is_sd ? "SD" : "eMMC"); |
| 520 | |
| 521 | if (module_count) |
| 522 | printf("Module Topology:\n"); |
| 523 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 524 | for (i = 0; i < module_count; ++i) { |
| 525 | switch (topology[i]) { |
| 526 | case MOX_MODULE_SFP: |
| 527 | printf("% 4i: SFP Module\n", i + 1); |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 528 | break; |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 529 | case MOX_MODULE_PCI: |
| 530 | printf("% 4i: Mini-PCIe Module\n", i + 1); |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 531 | break; |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 532 | case MOX_MODULE_TOPAZ: |
| 533 | printf("% 4i: Topaz Switch Module (4-port)\n", i + 1); |
| 534 | break; |
| 535 | case MOX_MODULE_PERIDOT: |
| 536 | printf("% 4i: Peridot Switch Module (8-port)\n", i + 1); |
| 537 | break; |
| 538 | case MOX_MODULE_USB3: |
| 539 | printf("% 4i: USB 3.0 Module (4 ports)\n", i + 1); |
| 540 | break; |
| 541 | case MOX_MODULE_PASSPCI: |
| 542 | printf("% 4i: Passthrough Mini-PCIe Module\n", i + 1); |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 543 | break; |
| 544 | default: |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 545 | printf("% 4i: unknown (ID %i)\n", i + 1, topology[i]); |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 546 | } |
| 547 | } |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 548 | |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 549 | /* now check if modules are connected in supported mode */ |
| 550 | |
| 551 | for (i = 0; i < module_count; ++i) { |
| 552 | switch (topology[i]) { |
| 553 | case MOX_MODULE_SFP: |
| 554 | if (sfp) { |
| 555 | printf("Error: Only one SFP module is supported!\n"); |
| 556 | } else if (topaz) { |
| 557 | printf("Error: SFP module cannot be connected after Topaz Switch module!\n"); |
| 558 | } else { |
| 559 | sfp_pos = i; |
| 560 | ++sfp; |
| 561 | } |
| 562 | break; |
| 563 | case MOX_MODULE_PCI: |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 564 | if (pci) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 565 | printf("Error: Only one Mini-PCIe module is supported!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 566 | else if (usb) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 567 | printf("Error: Mini-PCIe module cannot come after USB 3.0 module!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 568 | else if (i && (i != 1 || !passpci)) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 569 | printf("Error: Mini-PCIe module should be the first connected module or come right after Passthrough Mini-PCIe module!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 570 | else |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 571 | ++pci; |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 572 | break; |
| 573 | case MOX_MODULE_TOPAZ: |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 574 | if (topaz) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 575 | printf("Error: Only one Topaz module is supported!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 576 | else if (peridot >= 3) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 577 | printf("Error: At most two Peridot modules can come before Topaz module!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 578 | else |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 579 | ++topaz; |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 580 | break; |
| 581 | case MOX_MODULE_PERIDOT: |
| 582 | if (sfp || topaz) { |
| 583 | printf("Error: Peridot module must come before SFP or Topaz module!\n"); |
| 584 | } else if (peridot >= 3) { |
| 585 | printf("Error: At most three Peridot modules are supported!\n"); |
| 586 | } else { |
| 587 | peridot_pos[peridot] = i; |
| 588 | ++peridot; |
| 589 | } |
| 590 | break; |
| 591 | case MOX_MODULE_USB3: |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 592 | if (pci) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 593 | printf("Error: USB 3.0 module cannot come after Mini-PCIe module!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 594 | else if (usb) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 595 | printf("Error: Only one USB 3.0 module is supported!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 596 | else if (i && (i != 1 || !passpci)) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 597 | printf("Error: USB 3.0 module should be the first connected module or come right after Passthrough Mini-PCIe module!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 598 | else |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 599 | ++usb; |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 600 | break; |
| 601 | case MOX_MODULE_PASSPCI: |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 602 | if (passpci) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 603 | printf("Error: Only one Passthrough Mini-PCIe module is supported!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 604 | else if (i != 0) |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 605 | printf("Error: Passthrough Mini-PCIe module should be the first connected module!\n"); |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 606 | else |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 607 | ++passpci; |
Marek Behún | 35b3513 | 2018-12-17 16:10:03 +0100 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
| 611 | /* now configure modules */ |
| 612 | |
| 613 | if (get_reset_gpio(&reset_gpio) < 0) |
| 614 | return 0; |
| 615 | |
| 616 | if (peridot > 0) { |
| 617 | if (configure_peridots(&reset_gpio) < 0) { |
| 618 | printf("Cannot configure Peridot modules!\n"); |
| 619 | peridot = 0; |
| 620 | } |
| 621 | } else { |
| 622 | dm_gpio_set_value(&reset_gpio, 1); |
| 623 | mdelay(50); |
| 624 | dm_gpio_set_value(&reset_gpio, 0); |
| 625 | mdelay(50); |
| 626 | } |
| 627 | |
| 628 | if (peridot || topaz) { |
| 629 | /* |
| 630 | * now check if the addresses are set by reading Scratch & Misc |
| 631 | * register 0x70 of Peridot (and potentially Topaz) modules |
| 632 | */ |
| 633 | |
| 634 | bus = miiphy_get_dev_by_name("neta@30000"); |
| 635 | if (!bus) { |
| 636 | printf("Cannot get MDIO bus device!\n"); |
| 637 | } else { |
| 638 | for (i = 0; i < peridot; ++i) |
| 639 | check_switch_address(bus, 0x10 + i); |
| 640 | |
| 641 | if (topaz) |
| 642 | check_switch_address(bus, 0x2); |
| 643 | |
| 644 | sw_blink_leds(bus, peridot, topaz); |
| 645 | } |
| 646 | } |
| 647 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 648 | printf("\n"); |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 649 | |
Marek Behún | 859ada5 | 2021-06-07 16:34:47 +0200 | [diff] [blame] | 650 | handle_reset_button(); |
| 651 | |
Marek Behún | f68ed8b | 2018-12-17 16:10:01 +0100 | [diff] [blame] | 652 | return 0; |
Marek Behún | f835bed | 2018-04-24 17:21:31 +0200 | [diff] [blame] | 653 | } |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 654 | |
| 655 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 656 | |
| 657 | static int vnode_by_path(void *blob, const char *fmt, va_list ap) |
| 658 | { |
| 659 | char path[128]; |
| 660 | |
| 661 | vsnprintf(path, 128, fmt, ap); |
| 662 | return fdt_path_offset(blob, path); |
| 663 | } |
| 664 | |
| 665 | static int node_by_path(void *blob, const char *fmt, ...) |
| 666 | { |
| 667 | va_list ap; |
| 668 | int res; |
| 669 | |
| 670 | va_start(ap, fmt); |
| 671 | res = vnode_by_path(blob, fmt, ap); |
| 672 | va_end(ap); |
| 673 | |
| 674 | return res; |
| 675 | } |
| 676 | |
| 677 | static int phandle_by_path(void *blob, const char *fmt, ...) |
| 678 | { |
| 679 | va_list ap; |
| 680 | int node, phandle, res; |
| 681 | |
| 682 | va_start(ap, fmt); |
| 683 | node = vnode_by_path(blob, fmt, ap); |
| 684 | va_end(ap); |
| 685 | |
| 686 | if (node < 0) |
| 687 | return node; |
| 688 | |
| 689 | phandle = fdt_get_phandle(blob, node); |
| 690 | if (phandle > 0) |
| 691 | return phandle; |
| 692 | |
| 693 | phandle = fdt_get_max_phandle(blob); |
| 694 | if (phandle < 0) |
| 695 | return phandle; |
| 696 | |
| 697 | phandle += 1; |
| 698 | |
| 699 | res = fdt_setprop_u32(blob, node, "linux,phandle", phandle); |
| 700 | if (res < 0) |
| 701 | return res; |
| 702 | |
| 703 | res = fdt_setprop_u32(blob, node, "phandle", phandle); |
| 704 | if (res < 0) |
| 705 | return res; |
| 706 | |
| 707 | return phandle; |
| 708 | } |
| 709 | |
| 710 | static int enable_by_path(void *blob, const char *fmt, ...) |
| 711 | { |
| 712 | va_list ap; |
| 713 | int node; |
| 714 | |
| 715 | va_start(ap, fmt); |
| 716 | node = vnode_by_path(blob, fmt, ap); |
| 717 | va_end(ap); |
| 718 | |
| 719 | if (node < 0) |
| 720 | return node; |
| 721 | |
| 722 | return fdt_setprop_string(blob, node, "status", "okay"); |
| 723 | } |
| 724 | |
| 725 | static bool is_topaz(int id) |
| 726 | { |
| 727 | return topaz && id == peridot + topaz - 1; |
| 728 | } |
| 729 | |
| 730 | static int switch_addr(int id) |
| 731 | { |
| 732 | return is_topaz(id) ? 0x2 : 0x10 + id; |
| 733 | } |
| 734 | |
| 735 | static int setup_switch(void *blob, int id) |
| 736 | { |
| 737 | int res, addr, i, node, phandle; |
| 738 | |
| 739 | addr = switch_addr(id); |
| 740 | |
| 741 | /* first enable the switch by setting status = "okay" */ |
| 742 | res = enable_by_path(blob, MDIO_PATH "/switch%i@%x", id, addr); |
| 743 | if (res < 0) |
| 744 | return res; |
| 745 | |
| 746 | /* |
| 747 | * now if there are more switches or a SFP module coming after, |
| 748 | * enable corresponding ports |
| 749 | */ |
| 750 | if (id < peridot + topaz - 1) { |
| 751 | res = enable_by_path(blob, |
| 752 | MDIO_PATH "/switch%i@%x/ports/port@a", |
| 753 | id, addr); |
| 754 | } else if (id == peridot - 1 && !topaz && sfp) { |
| 755 | res = enable_by_path(blob, |
| 756 | MDIO_PATH "/switch%i@%x/ports/port-sfp@a", |
| 757 | id, addr); |
| 758 | } else { |
| 759 | res = 0; |
| 760 | } |
| 761 | if (res < 0) |
| 762 | return res; |
| 763 | |
| 764 | if (id >= peridot + topaz - 1) |
| 765 | return 0; |
| 766 | |
| 767 | /* finally change link property if needed */ |
| 768 | node = node_by_path(blob, MDIO_PATH "/switch%i@%x/ports/port@a", id, |
| 769 | addr); |
| 770 | if (node < 0) |
| 771 | return node; |
| 772 | |
| 773 | for (i = id + 1; i < peridot + topaz; ++i) { |
| 774 | phandle = phandle_by_path(blob, |
| 775 | MDIO_PATH "/switch%i@%x/ports/port@%x", |
| 776 | i, switch_addr(i), |
| 777 | is_topaz(i) ? 5 : 9); |
| 778 | if (phandle < 0) |
| 779 | return phandle; |
| 780 | |
| 781 | if (i == id + 1) |
| 782 | res = fdt_setprop_u32(blob, node, "link", phandle); |
| 783 | else |
| 784 | res = fdt_appendprop_u32(blob, node, "link", phandle); |
| 785 | if (res < 0) |
| 786 | return res; |
| 787 | } |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | static int remove_disabled_nodes(void *blob) |
| 793 | { |
| 794 | while (1) { |
| 795 | int res, offset; |
| 796 | |
| 797 | offset = fdt_node_offset_by_prop_value(blob, -1, "status", |
| 798 | "disabled", 9); |
| 799 | if (offset < 0) |
| 800 | break; |
| 801 | |
| 802 | res = fdt_del_node(blob, offset); |
| 803 | if (res < 0) |
| 804 | return res; |
| 805 | } |
| 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 810 | int ft_board_setup(void *blob, struct bd_info *bd) |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 811 | { |
| 812 | int node, phandle, res; |
| 813 | |
| 814 | /* |
| 815 | * If MOX B (PCI), MOX F (USB) or MOX G (Passthrough PCI) modules are |
| 816 | * connected, enable the PCIe node. |
| 817 | */ |
| 818 | if (pci || usb || passpci) { |
| 819 | node = fdt_path_offset(blob, PCIE_PATH); |
| 820 | if (node < 0) |
| 821 | return node; |
| 822 | |
| 823 | res = fdt_setprop_string(blob, node, "status", "okay"); |
| 824 | if (res < 0) |
| 825 | return res; |
Marek Behún | 455ef5b | 2020-04-08 19:25:22 +0200 | [diff] [blame] | 826 | |
| 827 | /* Fix PCIe regions for devices with 4 GB RAM */ |
| 828 | res = a3700_fdt_fix_pcie_regions(blob); |
| 829 | if (res < 0) |
| 830 | return res; |
Marek Behún | 4529fce | 2020-04-08 12:02:05 +0200 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* |
| 834 | * If MOX C (Topaz switch) and/or MOX E (Peridot switch) are connected, |
| 835 | * enable the eth1 node and setup the switches. |
| 836 | */ |
| 837 | if (peridot || topaz) { |
| 838 | int i; |
| 839 | |
| 840 | res = enable_by_path(blob, ETH1_PATH); |
| 841 | if (res < 0) |
| 842 | return res; |
| 843 | |
| 844 | for (i = 0; i < peridot + topaz; ++i) { |
| 845 | res = setup_switch(blob, i); |
| 846 | if (res < 0) |
| 847 | return res; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | * If MOX D (SFP cage module) is connected, enable the SFP node and eth1 |
| 853 | * node. If there is no Peridot switch between MOX A and MOX D, add link |
| 854 | * to the SFP node to eth1 node. |
| 855 | * Also enable and configure SFP GPIO controller node. |
| 856 | */ |
| 857 | if (sfp) { |
| 858 | res = enable_by_path(blob, SFP_PATH); |
| 859 | if (res < 0) |
| 860 | return res; |
| 861 | |
| 862 | res = enable_by_path(blob, ETH1_PATH); |
| 863 | if (res < 0) |
| 864 | return res; |
| 865 | |
| 866 | if (!peridot) { |
| 867 | phandle = phandle_by_path(blob, SFP_PATH); |
| 868 | if (phandle < 0) |
| 869 | return res; |
| 870 | |
| 871 | node = node_by_path(blob, ETH1_PATH); |
| 872 | if (node < 0) |
| 873 | return node; |
| 874 | |
| 875 | res = fdt_setprop_u32(blob, node, "sfp", phandle); |
| 876 | if (res < 0) |
| 877 | return res; |
| 878 | |
| 879 | res = fdt_setprop_string(blob, node, "phy-mode", |
| 880 | "sgmii"); |
| 881 | if (res < 0) |
| 882 | return res; |
| 883 | } |
| 884 | |
| 885 | res = enable_by_path(blob, SFP_GPIO_PATH); |
| 886 | if (res < 0) |
| 887 | return res; |
| 888 | |
| 889 | if (sfp_pos) { |
| 890 | char newname[16]; |
| 891 | |
| 892 | /* moxtet-sfp is on non-zero position, change default */ |
| 893 | node = node_by_path(blob, SFP_GPIO_PATH); |
| 894 | if (node < 0) |
| 895 | return node; |
| 896 | |
| 897 | res = fdt_setprop_u32(blob, node, "reg", sfp_pos); |
| 898 | if (res < 0) |
| 899 | return res; |
| 900 | |
| 901 | sprintf(newname, "gpio@%x", sfp_pos); |
| 902 | |
| 903 | res = fdt_set_name(blob, node, newname); |
| 904 | if (res < 0) |
| 905 | return res; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | fdt_fixup_ethernet(blob); |
| 910 | |
| 911 | /* Finally remove disabled nodes, as per Rob Herring's request. */ |
| 912 | remove_disabled_nodes(blob); |
| 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | #endif |