3 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
5 * SPDX-License-Identifier: GPL-2.0+
12 #include <linux/libfdt.h>
13 #include <fdt_support.h>
16 #include <fsl_esdhc.h>
18 #include <asm/fsl_serdes.h>
19 #include <asm/fsl_mpc83xx_serdes.h>
23 #include <gdsys_fpga.h>
25 #include "../common/ioep-fpga.h"
26 #include "../common/osd.h"
27 #include "../common/mclink.h"
28 #include "../common/phy.h"
29 #include "../common/fanctrl.h"
36 #define MAX_MUX_CHANNELS 2
40 MCFPGA_INIT_N = 1 << 1,
41 MCFPGA_PROGRAM_N = 1 << 2,
42 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
43 MCFPGA_RESET_N = 1 << 4,
51 unsigned int mclink_fpgacount;
52 struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
57 } hrcon_fans[] = CONFIG_HRCON_FANS;
59 int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
68 res = mclink_send(fpga - 1, regoff, data);
70 printf("mclink_send reg %02lx data %04x returned %d\n",
80 int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
89 if (fpga > mclink_fpgacount)
91 res = mclink_receive(fpga - 1, regoff, data);
93 printf("mclink_receive reg %02lx returned %d\n",
104 char *s = env_get("serial#");
105 bool hw_type_cat = pca9698_get_value(0x20, 20);
109 printf("HRCon %s", hw_type_cat ? "CAT" : "Fiber");
121 int last_stage_init(void)
126 unsigned char mclink_controllers[] = { 0x3c, 0x3d, 0x3e };
128 bool hw_type_cat = pca9698_get_value(0x20, 20);
129 bool ch0_rgmii2_present = false;
131 FPGA_GET_REG(0, fpga_features, &fpga_features);
133 /* Turn on Parade DP501 */
134 pca9698_direction_output(0x20, 10, 1);
135 pca9698_direction_output(0x20, 11, 1);
137 ch0_rgmii2_present = !pca9698_get_value(0x20, 30);
139 /* wait for FPGA done, then reset FPGA */
140 for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) {
141 unsigned int ctr = 0;
143 if (i2c_probe(mclink_controllers[k]))
146 while (!(pca953x_get_val(mclink_controllers[k])
150 printf("no done for mclink_controller %d\n", k);
155 pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
156 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
158 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
164 struct mii_dev *mdiodev = mdio_alloc();
167 strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
168 mdiodev->read = bb_miiphy_read;
169 mdiodev->write = bb_miiphy_write;
171 retval = mdio_register(mdiodev);
174 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
175 if ((mux_ch == 1) && !ch0_rgmii2_present)
178 setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
182 /* give slave-PLLs and Parade DP501 some time to be up and running */
185 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
186 slaves = mclink_probe();
187 mclink_fpgacount = 0;
189 ioep_fpga_print_info(0);
191 #ifdef CONFIG_SYS_OSD_DH
198 mclink_fpgacount = slaves;
200 for (k = 1; k <= slaves; ++k) {
201 FPGA_GET_REG(k, fpga_features, &fpga_features);
203 ioep_fpga_print_info(k);
205 #ifdef CONFIG_SYS_OSD_DH
210 struct mii_dev *mdiodev = mdio_alloc();
213 strncpy(mdiodev->name, bb_miiphy_buses[k].name,
215 mdiodev->read = bb_miiphy_read;
216 mdiodev->write = bb_miiphy_write;
218 retval = mdio_register(mdiodev);
221 setup_88e1514(bb_miiphy_buses[k].name, 0);
225 for (k = 0; k < ARRAY_SIZE(hrcon_fans); ++k) {
226 i2c_set_bus_num(hrcon_fans[k].bus);
227 init_fan_controller(hrcon_fans[k].addr);
234 * provide access to fpga gpios and controls (for I2C bitbang)
235 * (these may look all too simple but make iocon.h much more readable)
237 void fpga_gpio_set(unsigned int bus, int pin)
239 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.set, pin);
242 void fpga_gpio_clear(unsigned int bus, int pin)
244 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.clear, pin);
247 int fpga_gpio_get(unsigned int bus, int pin)
251 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, gpio.read, &val);
256 void fpga_control_set(unsigned int bus, int pin)
260 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, control, &val);
261 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val | pin);
264 void fpga_control_clear(unsigned int bus, int pin)
268 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, control, &val);
269 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val & ~pin);
272 void mpc8308_init(void)
274 pca9698_direction_output(0x20, 4, 1);
277 void mpc8308_set_fpga_reset(unsigned state)
279 pca9698_set_value(0x20, 4, state ? 0 : 1);
282 void mpc8308_setup_hw(void)
284 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
287 * set "startup-finished"-gpios
289 setbits_be32(&immr->gpio[0].dir, (1 << (31-11)) | (1 << (31-12)));
290 setbits_be32(&immr->gpio[0].dat, 1 << (31-12));
293 int mpc8308_get_fpga_done(unsigned fpga)
295 return pca9698_get_value(0x20, 19);
298 #ifdef CONFIG_FSL_ESDHC
299 int board_mmc_init(bd_t *bd)
301 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
302 sysconf83xx_t *sysconf = &immr->sysconf;
304 /* Enable cache snooping in eSDHC system configuration register */
305 out_be32(&sysconf->sdhccr, 0x02000000);
307 return fsl_esdhc_mmc_init(bd);
311 static struct pci_region pcie_regions_0[] = {
313 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
314 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
315 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
316 .flags = PCI_REGION_MEM,
319 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
320 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
321 .size = CONFIG_SYS_PCIE1_IO_SIZE,
322 .flags = PCI_REGION_IO,
326 void pci_init_board(void)
328 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
329 sysconf83xx_t *sysconf = &immr->sysconf;
330 law83xx_t *pcie_law = sysconf->pcielaw;
331 struct pci_region *pcie_reg[] = { pcie_regions_0 };
333 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
334 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
336 /* Deassert the resets in the control register */
337 out_be32(&sysconf->pecr1, 0xE0008000);
340 /* Configure PCI Express Local Access Windows */
341 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
342 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
344 mpc83xx_pcie_init(1, pcie_reg);
347 ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
349 info->portwidth = FLASH_CFI_16BIT;
350 info->chipwidth = FLASH_CFI_BY16;
351 info->interface = FLASH_CFI_X16;
355 #if defined(CONFIG_OF_BOARD_SETUP)
356 int ft_board_setup(void *blob, bd_t *bd)
358 ft_cpu_setup(blob, bd);
359 fsl_fdt_fixup_dr_usb(blob, bd);
360 fdt_fixup_esdhc(blob, bd);
367 * FPGA MII bitbang implementation
380 static int mii_dummy_init(struct bb_miiphy_bus *bus)
385 static int mii_mdio_active(struct bb_miiphy_bus *bus)
387 struct fpga_mii *fpga_mii = bus->priv;
390 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
392 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
397 static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
399 struct fpga_mii *fpga_mii = bus->priv;
401 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
406 static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
408 struct fpga_mii *fpga_mii = bus->priv;
411 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
413 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
420 static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
423 struct fpga_mii *fpga_mii = bus->priv;
425 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
427 *v = ((gpio & GPIO_MDIO) != 0);
432 static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
434 struct fpga_mii *fpga_mii = bus->priv;
437 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
439 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
444 static int mii_delay(struct bb_miiphy_bus *bus)
451 struct bb_miiphy_bus bb_miiphy_buses[] = {
454 .init = mii_dummy_init,
455 .mdio_active = mii_mdio_active,
456 .mdio_tristate = mii_mdio_tristate,
457 .set_mdio = mii_set_mdio,
458 .get_mdio = mii_get_mdio,
459 .set_mdc = mii_set_mdc,
461 .priv = &fpga_mii[0],
465 .init = mii_dummy_init,
466 .mdio_active = mii_mdio_active,
467 .mdio_tristate = mii_mdio_tristate,
468 .set_mdio = mii_set_mdio,
469 .get_mdio = mii_get_mdio,
470 .set_mdc = mii_set_mdc,
472 .priv = &fpga_mii[1],
476 .init = mii_dummy_init,
477 .mdio_active = mii_mdio_active,
478 .mdio_tristate = mii_mdio_tristate,
479 .set_mdio = mii_set_mdio,
480 .get_mdio = mii_get_mdio,
481 .set_mdc = mii_set_mdc,
483 .priv = &fpga_mii[2],
487 .init = mii_dummy_init,
488 .mdio_active = mii_mdio_active,
489 .mdio_tristate = mii_mdio_tristate,
490 .set_mdio = mii_set_mdio,
491 .get_mdio = mii_get_mdio,
492 .set_mdc = mii_set_mdc,
494 .priv = &fpga_mii[3],
498 int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
499 sizeof(bb_miiphy_buses[0]);