1 // SPDX-License-Identifier: GPL-2.0+
4 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
13 #include <linux/libfdt.h>
14 #include <fdt_support.h>
17 #include <fsl_esdhc.h>
19 #include <asm/fsl_serdes.h>
20 #include <asm/fsl_mpc83xx_serdes.h>
24 #include <gdsys_fpga.h>
26 #include "../common/adv7611.h"
27 #include "../common/ch7301.h"
28 #include "../common/dp501.h"
29 #include "../common/ioep-fpga.h"
30 #include "../common/mclink.h"
31 #include "../common/osd.h"
32 #include "../common/phy.h"
33 #include "../common/fanctrl.h"
40 #define MAX_MUX_CHANNELS 2
44 MCFPGA_INIT_N = 1 << 1,
45 MCFPGA_PROGRAM_N = 1 << 2,
46 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
47 MCFPGA_RESET_N = 1 << 4,
55 uint mclink_fpgacount;
56 struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
61 } strider_fans[] = CONFIG_STRIDER_FANS;
63 int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
72 res = mclink_send(fpga - 1, regoff, data);
74 printf("mclink_send reg %02lx data %04x returned %d\n",
84 int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
93 if (fpga > mclink_fpgacount)
95 res = mclink_receive(fpga - 1, regoff, data);
97 printf("mclink_receive reg %02lx returned %d\n",
108 char *s = env_get("serial#");
109 bool hw_type_cat = pca9698_get_value(0x20, 18);
113 printf("Strider %s", hw_type_cat ? "CAT" : "Fiber");
125 int last_stage_init(void)
130 uchar mclink_controllers_dvi[] = { 0x3c, 0x3d, 0x3e };
131 #ifdef CONFIG_STRIDER_CPU
132 uchar mclink_controllers_dp[] = { 0x24, 0x25, 0x26 };
134 bool hw_type_cat = pca9698_get_value(0x20, 18);
135 #ifdef CONFIG_STRIDER_CON_DP
136 bool is_dh = pca9698_get_value(0x20, 25);
138 bool ch0_sgmii2_present;
140 /* Turn on Analog Devices ADV7611 */
141 pca9698_direction_output(0x20, 8, 0);
143 /* Turn on Parade DP501 */
144 pca9698_direction_output(0x20, 10, 1);
145 pca9698_direction_output(0x20, 11, 1);
147 ch0_sgmii2_present = !pca9698_get_value(0x20, 37);
149 /* wait for FPGA done, then reset FPGA */
150 for (k = 0; k < ARRAY_SIZE(mclink_controllers_dvi); ++k) {
152 uchar *mclink_controllers = mclink_controllers_dvi;
154 #ifdef CONFIG_STRIDER_CPU
155 if (i2c_probe(mclink_controllers[k])) {
156 mclink_controllers = mclink_controllers_dp;
157 if (i2c_probe(mclink_controllers[k]))
161 if (i2c_probe(mclink_controllers[k]))
164 while (!(pca953x_get_val(mclink_controllers[k])
168 printf("no done for mclink_controller %d\n", k);
173 pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
174 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
176 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
182 struct mii_dev *mdiodev = mdio_alloc();
186 strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
187 mdiodev->read = bb_miiphy_read;
188 mdiodev->write = bb_miiphy_write;
190 retval = mdio_register(mdiodev);
193 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
194 if ((mux_ch == 1) && !ch0_sgmii2_present)
197 setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
201 /* give slave-PLLs and Parade DP501 some time to be up and running */
204 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
205 slaves = mclink_probe();
206 mclink_fpgacount = 0;
208 ioep_fpga_print_info(0);
210 if (!adv7611_probe(0))
211 printf(" Advantiv ADV7611 HDMI Receiver\n");
213 #ifdef CONFIG_STRIDER_CON
214 if (ioep_fpga_has_osd(0))
218 #ifdef CONFIG_STRIDER_CON_DP
219 if (ioep_fpga_has_osd(0)) {
226 #ifdef CONFIG_STRIDER_CPU
227 ch7301_probe(0, false);
228 dp501_probe(0, false);
234 mclink_fpgacount = slaves;
236 #ifdef CONFIG_STRIDER_CPU
237 /* get ADV7611 out of reset, power up DP501, give some time to wakeup */
238 for (k = 1; k <= slaves; ++k)
239 FPGA_SET_REG(k, extended_control, 0x10); /* enable video */
244 for (k = 1; k <= slaves; ++k) {
245 ioep_fpga_print_info(k);
246 #ifdef CONFIG_STRIDER_CON
247 if (ioep_fpga_has_osd(k))
250 #ifdef CONFIG_STRIDER_CON_DP
251 if (ioep_fpga_has_osd(k)) {
257 #ifdef CONFIG_STRIDER_CPU
258 if (!adv7611_probe(k))
259 printf(" Advantiv ADV7611 HDMI Receiver\n");
260 ch7301_probe(k, false);
261 dp501_probe(k, false);
265 struct mii_dev *mdiodev = mdio_alloc();
269 strncpy(mdiodev->name, bb_miiphy_buses[k].name,
271 mdiodev->read = bb_miiphy_read;
272 mdiodev->write = bb_miiphy_write;
274 retval = mdio_register(mdiodev);
277 setup_88e1514(bb_miiphy_buses[k].name, 0);
281 for (k = 0; k < ARRAY_SIZE(strider_fans); ++k) {
282 i2c_set_bus_num(strider_fans[k].bus);
283 init_fan_controller(strider_fans[k].addr);
290 * provide access to fpga gpios (for I2C bitbang)
291 * (these may look all too simple but make iocon.h much more readable)
293 void fpga_gpio_set(uint bus, int pin)
295 FPGA_SET_REG(bus, gpio.set, pin);
298 void fpga_gpio_clear(uint bus, int pin)
300 FPGA_SET_REG(bus, gpio.clear, pin);
303 int fpga_gpio_get(uint bus, int pin)
307 FPGA_GET_REG(bus, gpio.read, &val);
312 #ifdef CONFIG_STRIDER_CON_DP
313 void fpga_control_set(uint bus, int pin)
317 FPGA_GET_REG(bus, control, &val);
318 FPGA_SET_REG(bus, control, val | pin);
321 void fpga_control_clear(uint bus, int pin)
325 FPGA_GET_REG(bus, control, &val);
326 FPGA_SET_REG(bus, control, val & ~pin);
330 void mpc8308_init(void)
332 pca9698_direction_output(0x20, 26, 1);
335 void mpc8308_set_fpga_reset(uint state)
337 pca9698_set_value(0x20, 26, state ? 0 : 1);
340 void mpc8308_setup_hw(void)
342 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
345 * set "startup-finished"-gpios
347 setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12));
348 setbits_gpio0_out(BIT(31 - 12));
351 int mpc8308_get_fpga_done(uint fpga)
353 return pca9698_get_value(0x20, 20);
356 #ifdef CONFIG_FSL_ESDHC
357 int board_mmc_init(bd_t *bd)
359 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
360 sysconf83xx_t *sysconf = &immr->sysconf;
362 /* Enable cache snooping in eSDHC system configuration register */
363 out_be32(&sysconf->sdhccr, 0x02000000);
365 return fsl_esdhc_mmc_init(bd);
369 static struct pci_region pcie_regions_0[] = {
371 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
372 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
373 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
374 .flags = PCI_REGION_MEM,
377 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
378 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
379 .size = CONFIG_SYS_PCIE1_IO_SIZE,
380 .flags = PCI_REGION_IO,
384 void pci_init_board(void)
386 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
387 sysconf83xx_t *sysconf = &immr->sysconf;
388 law83xx_t *pcie_law = sysconf->pcielaw;
389 struct pci_region *pcie_reg[] = { pcie_regions_0 };
391 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
392 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
394 /* Deassert the resets in the control register */
395 out_be32(&sysconf->pecr1, 0xE0008000);
398 /* Configure PCI Express Local Access Windows */
399 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
400 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
402 mpc83xx_pcie_init(1, pcie_reg);
405 ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
407 info->portwidth = FLASH_CFI_16BIT;
408 info->chipwidth = FLASH_CFI_BY16;
409 info->interface = FLASH_CFI_X16;
413 #if defined(CONFIG_OF_BOARD_SETUP)
414 int ft_board_setup(void *blob, bd_t *bd)
416 ft_cpu_setup(blob, bd);
417 fsl_fdt_fixup_dr_usb(blob, bd);
418 fdt_fixup_esdhc(blob, bd);
425 * FPGA MII bitbang implementation
438 static int mii_dummy_init(struct bb_miiphy_bus *bus)
443 static int mii_mdio_active(struct bb_miiphy_bus *bus)
445 struct fpga_mii *fpga_mii = bus->priv;
448 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
450 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
455 static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
457 struct fpga_mii *fpga_mii = bus->priv;
459 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
464 static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
466 struct fpga_mii *fpga_mii = bus->priv;
469 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
471 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
478 static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
481 struct fpga_mii *fpga_mii = bus->priv;
483 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
485 *v = ((gpio & GPIO_MDIO) != 0);
490 static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
492 struct fpga_mii *fpga_mii = bus->priv;
495 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
497 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
502 static int mii_delay(struct bb_miiphy_bus *bus)
509 struct bb_miiphy_bus bb_miiphy_buses[] = {
512 .init = mii_dummy_init,
513 .mdio_active = mii_mdio_active,
514 .mdio_tristate = mii_mdio_tristate,
515 .set_mdio = mii_set_mdio,
516 .get_mdio = mii_get_mdio,
517 .set_mdc = mii_set_mdc,
519 .priv = &fpga_mii[0],
523 .init = mii_dummy_init,
524 .mdio_active = mii_mdio_active,
525 .mdio_tristate = mii_mdio_tristate,
526 .set_mdio = mii_set_mdio,
527 .get_mdio = mii_get_mdio,
528 .set_mdc = mii_set_mdc,
530 .priv = &fpga_mii[1],
534 .init = mii_dummy_init,
535 .mdio_active = mii_mdio_active,
536 .mdio_tristate = mii_mdio_tristate,
537 .set_mdio = mii_set_mdio,
538 .get_mdio = mii_get_mdio,
539 .set_mdc = mii_set_mdc,
541 .priv = &fpga_mii[2],
545 .init = mii_dummy_init,
546 .mdio_active = mii_mdio_active,
547 .mdio_tristate = mii_mdio_tristate,
548 .set_mdio = mii_set_mdio,
549 .get_mdio = mii_get_mdio,
550 .set_mdc = mii_set_mdc,
552 .priv = &fpga_mii[3],
556 int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);