1 // SPDX-License-Identifier: GPL-2.0+
4 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
14 #include <linux/bitops.h>
15 #include <linux/delay.h>
16 #include <linux/libfdt.h>
17 #include <fdt_support.h>
20 #include <fsl_esdhc.h>
22 #include <asm/fsl_serdes.h>
23 #include <asm/fsl_mpc83xx_serdes.h>
27 #include <gdsys_fpga.h>
29 #include "../common/adv7611.h"
30 #include "../common/ch7301.h"
31 #include "../common/dp501.h"
32 #include "../common/ioep-fpga.h"
33 #include "../common/mclink.h"
34 #include "../common/osd.h"
35 #include "../common/phy.h"
36 #include "../common/fanctrl.h"
43 #define MAX_MUX_CHANNELS 2
47 MCFPGA_INIT_N = 1 << 1,
48 MCFPGA_PROGRAM_N = 1 << 2,
49 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
50 MCFPGA_RESET_N = 1 << 4,
58 uint mclink_fpgacount;
59 struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
64 } strider_fans[] = CONFIG_STRIDER_FANS;
66 int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
75 res = mclink_send(fpga - 1, regoff, data);
77 printf("mclink_send reg %02lx data %04x returned %d\n",
87 int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
96 if (fpga > mclink_fpgacount)
98 res = mclink_receive(fpga - 1, regoff, data);
100 printf("mclink_receive reg %02lx returned %d\n",
111 char *s = env_get("serial#");
112 bool hw_type_cat = pca9698_get_value(0x20, 18);
116 printf("Strider %s", hw_type_cat ? "CAT" : "Fiber");
128 int last_stage_init(void)
133 uchar mclink_controllers_dvi[] = { 0x3c, 0x3d, 0x3e };
134 #ifdef CONFIG_STRIDER_CPU
135 uchar mclink_controllers_dp[] = { 0x24, 0x25, 0x26 };
137 bool hw_type_cat = pca9698_get_value(0x20, 18);
138 #ifdef CONFIG_STRIDER_CON_DP
139 bool is_dh = pca9698_get_value(0x20, 25);
141 bool ch0_sgmii2_present;
143 /* Turn on Analog Devices ADV7611 */
144 pca9698_direction_output(0x20, 8, 0);
146 /* Turn on Parade DP501 */
147 pca9698_direction_output(0x20, 10, 1);
148 pca9698_direction_output(0x20, 11, 1);
150 ch0_sgmii2_present = !pca9698_get_value(0x20, 37);
152 /* wait for FPGA done, then reset FPGA */
153 for (k = 0; k < ARRAY_SIZE(mclink_controllers_dvi); ++k) {
155 uchar *mclink_controllers = mclink_controllers_dvi;
157 #ifdef CONFIG_STRIDER_CPU
158 if (i2c_probe(mclink_controllers[k])) {
159 mclink_controllers = mclink_controllers_dp;
160 if (i2c_probe(mclink_controllers[k]))
164 if (i2c_probe(mclink_controllers[k]))
167 while (!(pca953x_get_val(mclink_controllers[k])
171 printf("no done for mclink_controller %d\n", k);
176 pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
177 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
179 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
185 struct mii_dev *mdiodev = mdio_alloc();
189 strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
190 mdiodev->read = bb_miiphy_read;
191 mdiodev->write = bb_miiphy_write;
193 retval = mdio_register(mdiodev);
196 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
197 if ((mux_ch == 1) && !ch0_sgmii2_present)
200 setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
204 /* give slave-PLLs and Parade DP501 some time to be up and running */
207 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
208 slaves = mclink_probe();
209 mclink_fpgacount = 0;
211 ioep_fpga_print_info(0);
213 if (!adv7611_probe(0))
214 printf(" Advantiv ADV7611 HDMI Receiver\n");
216 #ifdef CONFIG_STRIDER_CON
217 if (ioep_fpga_has_osd(0))
221 #ifdef CONFIG_STRIDER_CON_DP
222 if (ioep_fpga_has_osd(0)) {
229 #ifdef CONFIG_STRIDER_CPU
230 ch7301_probe(0, false);
231 dp501_probe(0, false);
237 mclink_fpgacount = slaves;
239 #ifdef CONFIG_STRIDER_CPU
240 /* get ADV7611 out of reset, power up DP501, give some time to wakeup */
241 for (k = 1; k <= slaves; ++k)
242 FPGA_SET_REG(k, extended_control, 0x10); /* enable video */
247 for (k = 1; k <= slaves; ++k) {
248 ioep_fpga_print_info(k);
249 #ifdef CONFIG_STRIDER_CON
250 if (ioep_fpga_has_osd(k))
253 #ifdef CONFIG_STRIDER_CON_DP
254 if (ioep_fpga_has_osd(k)) {
260 #ifdef CONFIG_STRIDER_CPU
261 if (!adv7611_probe(k))
262 printf(" Advantiv ADV7611 HDMI Receiver\n");
263 ch7301_probe(k, false);
264 dp501_probe(k, false);
268 struct mii_dev *mdiodev = mdio_alloc();
272 strncpy(mdiodev->name, bb_miiphy_buses[k].name,
274 mdiodev->read = bb_miiphy_read;
275 mdiodev->write = bb_miiphy_write;
277 retval = mdio_register(mdiodev);
280 setup_88e1514(bb_miiphy_buses[k].name, 0);
284 for (k = 0; k < ARRAY_SIZE(strider_fans); ++k) {
285 i2c_set_bus_num(strider_fans[k].bus);
286 init_fan_controller(strider_fans[k].addr);
293 * provide access to fpga gpios (for I2C bitbang)
294 * (these may look all too simple but make iocon.h much more readable)
296 void fpga_gpio_set(uint bus, int pin)
298 FPGA_SET_REG(bus, gpio.set, pin);
301 void fpga_gpio_clear(uint bus, int pin)
303 FPGA_SET_REG(bus, gpio.clear, pin);
306 int fpga_gpio_get(uint bus, int pin)
310 FPGA_GET_REG(bus, gpio.read, &val);
315 #ifdef CONFIG_STRIDER_CON_DP
316 void fpga_control_set(uint bus, int pin)
320 FPGA_GET_REG(bus, control, &val);
321 FPGA_SET_REG(bus, control, val | pin);
324 void fpga_control_clear(uint bus, int pin)
328 FPGA_GET_REG(bus, control, &val);
329 FPGA_SET_REG(bus, control, val & ~pin);
333 void mpc8308_init(void)
335 pca9698_direction_output(0x20, 26, 1);
338 void mpc8308_set_fpga_reset(uint state)
340 pca9698_set_value(0x20, 26, state ? 0 : 1);
343 void mpc8308_setup_hw(void)
345 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
348 * set "startup-finished"-gpios
350 setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12));
351 setbits_gpio0_out(BIT(31 - 12));
354 int mpc8308_get_fpga_done(uint fpga)
356 return pca9698_get_value(0x20, 20);
359 #ifdef CONFIG_FSL_ESDHC
360 int board_mmc_init(bd_t *bd)
362 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
363 sysconf83xx_t *sysconf = &immr->sysconf;
365 /* Enable cache snooping in eSDHC system configuration register */
366 out_be32(&sysconf->sdhccr, 0x02000000);
368 return fsl_esdhc_mmc_init(bd);
372 static struct pci_region pcie_regions_0[] = {
374 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
375 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
376 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
377 .flags = PCI_REGION_MEM,
380 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
381 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
382 .size = CONFIG_SYS_PCIE1_IO_SIZE,
383 .flags = PCI_REGION_IO,
387 void pci_init_board(void)
389 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
390 sysconf83xx_t *sysconf = &immr->sysconf;
391 law83xx_t *pcie_law = sysconf->pcielaw;
392 struct pci_region *pcie_reg[] = { pcie_regions_0 };
394 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
395 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
397 /* Deassert the resets in the control register */
398 out_be32(&sysconf->pecr1, 0xE0008000);
401 /* Configure PCI Express Local Access Windows */
402 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
403 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
405 mpc83xx_pcie_init(1, pcie_reg);
408 ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
410 info->portwidth = FLASH_CFI_16BIT;
411 info->chipwidth = FLASH_CFI_BY16;
412 info->interface = FLASH_CFI_X16;
416 #if defined(CONFIG_OF_BOARD_SETUP)
417 int ft_board_setup(void *blob, bd_t *bd)
419 ft_cpu_setup(blob, bd);
420 fsl_fdt_fixup_dr_usb(blob, bd);
421 fdt_fixup_esdhc(blob, bd);
428 * FPGA MII bitbang implementation
441 static int mii_dummy_init(struct bb_miiphy_bus *bus)
446 static int mii_mdio_active(struct bb_miiphy_bus *bus)
448 struct fpga_mii *fpga_mii = bus->priv;
451 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
453 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
458 static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
460 struct fpga_mii *fpga_mii = bus->priv;
462 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
467 static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
469 struct fpga_mii *fpga_mii = bus->priv;
472 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
474 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
481 static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
484 struct fpga_mii *fpga_mii = bus->priv;
486 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
488 *v = ((gpio & GPIO_MDIO) != 0);
493 static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
495 struct fpga_mii *fpga_mii = bus->priv;
498 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
500 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
505 static int mii_delay(struct bb_miiphy_bus *bus)
512 struct bb_miiphy_bus bb_miiphy_buses[] = {
515 .init = mii_dummy_init,
516 .mdio_active = mii_mdio_active,
517 .mdio_tristate = mii_mdio_tristate,
518 .set_mdio = mii_set_mdio,
519 .get_mdio = mii_get_mdio,
520 .set_mdc = mii_set_mdc,
522 .priv = &fpga_mii[0],
526 .init = mii_dummy_init,
527 .mdio_active = mii_mdio_active,
528 .mdio_tristate = mii_mdio_tristate,
529 .set_mdio = mii_set_mdio,
530 .get_mdio = mii_get_mdio,
531 .set_mdc = mii_set_mdc,
533 .priv = &fpga_mii[1],
537 .init = mii_dummy_init,
538 .mdio_active = mii_mdio_active,
539 .mdio_tristate = mii_mdio_tristate,
540 .set_mdio = mii_set_mdio,
541 .get_mdio = mii_get_mdio,
542 .set_mdc = mii_set_mdc,
544 .priv = &fpga_mii[2],
548 .init = mii_dummy_init,
549 .mdio_active = mii_mdio_active,
550 .mdio_tristate = mii_mdio_tristate,
551 .set_mdio = mii_set_mdio,
552 .get_mdio = mii_get_mdio,
553 .set_mdc = mii_set_mdc,
555 .priv = &fpga_mii[3],
559 int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);