1 // SPDX-License-Identifier: GPL-2.0+
4 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
11 #include <linux/libfdt.h>
12 #include <fdt_support.h>
15 #include <fsl_esdhc.h>
17 #include <asm/fsl_serdes.h>
18 #include <asm/fsl_mpc83xx_serdes.h>
22 #include <gdsys_fpga.h>
24 #include "../common/ioep-fpga.h"
25 #include "../common/osd.h"
26 #include "../common/mclink.h"
27 #include "../common/phy.h"
28 #include "../common/fanctrl.h"
35 #define MAX_MUX_CHANNELS 2
39 MCFPGA_INIT_N = 1 << 1,
40 MCFPGA_PROGRAM_N = 1 << 2,
41 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
42 MCFPGA_RESET_N = 1 << 4,
50 unsigned int mclink_fpgacount;
51 struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
56 } hrcon_fans[] = CONFIG_HRCON_FANS;
58 int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
67 res = mclink_send(fpga - 1, regoff, data);
69 printf("mclink_send reg %02lx data %04x returned %d\n",
79 int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
88 if (fpga > mclink_fpgacount)
90 res = mclink_receive(fpga - 1, regoff, data);
92 printf("mclink_receive reg %02lx returned %d\n",
103 char *s = env_get("serial#");
104 bool hw_type_cat = pca9698_get_value(0x20, 20);
108 printf("HRCon %s", hw_type_cat ? "CAT" : "Fiber");
120 int last_stage_init(void)
125 unsigned char mclink_controllers[] = { 0x3c, 0x3d, 0x3e };
127 bool hw_type_cat = pca9698_get_value(0x20, 20);
128 bool ch0_rgmii2_present = false;
130 FPGA_GET_REG(0, fpga_features, &fpga_features);
132 /* Turn on Parade DP501 */
133 pca9698_direction_output(0x20, 10, 1);
134 pca9698_direction_output(0x20, 11, 1);
136 ch0_rgmii2_present = !pca9698_get_value(0x20, 30);
138 /* wait for FPGA done, then reset FPGA */
139 for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) {
140 unsigned int ctr = 0;
142 if (i2c_probe(mclink_controllers[k]))
145 while (!(pca953x_get_val(mclink_controllers[k])
149 printf("no done for mclink_controller %d\n", k);
154 pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
155 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
157 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
163 struct mii_dev *mdiodev = mdio_alloc();
166 strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
167 mdiodev->read = bb_miiphy_read;
168 mdiodev->write = bb_miiphy_write;
170 retval = mdio_register(mdiodev);
173 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
174 if ((mux_ch == 1) && !ch0_rgmii2_present)
177 setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
181 /* give slave-PLLs and Parade DP501 some time to be up and running */
184 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
185 slaves = mclink_probe();
186 mclink_fpgacount = 0;
188 ioep_fpga_print_info(0);
190 #ifdef CONFIG_SYS_OSD_DH
197 mclink_fpgacount = slaves;
199 for (k = 1; k <= slaves; ++k) {
200 FPGA_GET_REG(k, fpga_features, &fpga_features);
202 ioep_fpga_print_info(k);
204 #ifdef CONFIG_SYS_OSD_DH
209 struct mii_dev *mdiodev = mdio_alloc();
212 strncpy(mdiodev->name, bb_miiphy_buses[k].name,
214 mdiodev->read = bb_miiphy_read;
215 mdiodev->write = bb_miiphy_write;
217 retval = mdio_register(mdiodev);
220 setup_88e1514(bb_miiphy_buses[k].name, 0);
224 for (k = 0; k < ARRAY_SIZE(hrcon_fans); ++k) {
225 i2c_set_bus_num(hrcon_fans[k].bus);
226 init_fan_controller(hrcon_fans[k].addr);
233 * provide access to fpga gpios and controls (for I2C bitbang)
234 * (these may look all too simple but make iocon.h much more readable)
236 void fpga_gpio_set(unsigned int bus, int pin)
238 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.set, pin);
241 void fpga_gpio_clear(unsigned int bus, int pin)
243 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.clear, pin);
246 int fpga_gpio_get(unsigned int bus, int pin)
250 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, gpio.read, &val);
255 void fpga_control_set(unsigned int bus, int pin)
259 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, control, &val);
260 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val | pin);
263 void fpga_control_clear(unsigned int bus, int pin)
267 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, control, &val);
268 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val & ~pin);
271 void mpc8308_init(void)
273 pca9698_direction_output(0x20, 4, 1);
276 void mpc8308_set_fpga_reset(unsigned state)
278 pca9698_set_value(0x20, 4, state ? 0 : 1);
281 void mpc8308_setup_hw(void)
283 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
286 * set "startup-finished"-gpios
288 setbits_be32(&immr->gpio[0].dir, (1 << (31-11)) | (1 << (31-12)));
289 setbits_be32(&immr->gpio[0].dat, 1 << (31-12));
292 int mpc8308_get_fpga_done(unsigned fpga)
294 return pca9698_get_value(0x20, 19);
297 #ifdef CONFIG_FSL_ESDHC
298 int board_mmc_init(bd_t *bd)
300 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
301 sysconf83xx_t *sysconf = &immr->sysconf;
303 /* Enable cache snooping in eSDHC system configuration register */
304 out_be32(&sysconf->sdhccr, 0x02000000);
306 return fsl_esdhc_mmc_init(bd);
310 static struct pci_region pcie_regions_0[] = {
312 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
313 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
314 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
315 .flags = PCI_REGION_MEM,
318 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
319 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
320 .size = CONFIG_SYS_PCIE1_IO_SIZE,
321 .flags = PCI_REGION_IO,
325 void pci_init_board(void)
327 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
328 sysconf83xx_t *sysconf = &immr->sysconf;
329 law83xx_t *pcie_law = sysconf->pcielaw;
330 struct pci_region *pcie_reg[] = { pcie_regions_0 };
332 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
333 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
335 /* Deassert the resets in the control register */
336 out_be32(&sysconf->pecr1, 0xE0008000);
339 /* Configure PCI Express Local Access Windows */
340 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
341 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
343 mpc83xx_pcie_init(1, pcie_reg);
346 ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
348 info->portwidth = FLASH_CFI_16BIT;
349 info->chipwidth = FLASH_CFI_BY16;
350 info->interface = FLASH_CFI_X16;
354 #if defined(CONFIG_OF_BOARD_SETUP)
355 int ft_board_setup(void *blob, bd_t *bd)
357 ft_cpu_setup(blob, bd);
358 fsl_fdt_fixup_dr_usb(blob, bd);
359 fdt_fixup_esdhc(blob, bd);
366 * FPGA MII bitbang implementation
379 static int mii_dummy_init(struct bb_miiphy_bus *bus)
384 static int mii_mdio_active(struct bb_miiphy_bus *bus)
386 struct fpga_mii *fpga_mii = bus->priv;
389 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
391 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
396 static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
398 struct fpga_mii *fpga_mii = bus->priv;
400 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
405 static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
407 struct fpga_mii *fpga_mii = bus->priv;
410 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
412 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
419 static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
422 struct fpga_mii *fpga_mii = bus->priv;
424 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
426 *v = ((gpio & GPIO_MDIO) != 0);
431 static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
433 struct fpga_mii *fpga_mii = bus->priv;
436 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
438 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
443 static int mii_delay(struct bb_miiphy_bus *bus)
450 struct bb_miiphy_bus bb_miiphy_buses[] = {
453 .init = mii_dummy_init,
454 .mdio_active = mii_mdio_active,
455 .mdio_tristate = mii_mdio_tristate,
456 .set_mdio = mii_set_mdio,
457 .get_mdio = mii_get_mdio,
458 .set_mdc = mii_set_mdc,
460 .priv = &fpga_mii[0],
464 .init = mii_dummy_init,
465 .mdio_active = mii_mdio_active,
466 .mdio_tristate = mii_mdio_tristate,
467 .set_mdio = mii_set_mdio,
468 .get_mdio = mii_get_mdio,
469 .set_mdc = mii_set_mdc,
471 .priv = &fpga_mii[1],
475 .init = mii_dummy_init,
476 .mdio_active = mii_mdio_active,
477 .mdio_tristate = mii_mdio_tristate,
478 .set_mdio = mii_set_mdio,
479 .get_mdio = mii_get_mdio,
480 .set_mdc = mii_set_mdc,
482 .priv = &fpga_mii[2],
486 .init = mii_dummy_init,
487 .mdio_active = mii_mdio_active,
488 .mdio_tristate = mii_mdio_tristate,
489 .set_mdio = mii_set_mdio,
490 .get_mdio = mii_get_mdio,
491 .set_mdc = mii_set_mdc,
493 .priv = &fpga_mii[3],
497 int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
498 sizeof(bb_miiphy_buses[0]);