1 // SPDX-License-Identifier: GPL-2.0+
14 #include <linux/libfdt.h>
15 #include <fdt_support.h>
18 #include <fsl_esdhc.h>
20 #include <asm/fsl_serdes.h>
21 #include <asm/fsl_mpc83xx_serdes.h>
25 #include <gdsys_fpga.h>
27 #include "../common/ioep-fpga.h"
28 #include "../common/osd.h"
29 #include "../common/mclink.h"
30 #include "../common/phy.h"
31 #include "../common/fanctrl.h"
38 #define MAX_MUX_CHANNELS 2
42 MCFPGA_INIT_N = BIT(1),
43 MCFPGA_PROGRAM_N = BIT(2),
44 MCFPGA_UPDATE_ENABLE_N = BIT(3),
45 MCFPGA_RESET_N = BIT(4),
53 uint mclink_fpgacount;
54 struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
59 } hrcon_fans[] = CONFIG_HRCON_FANS;
61 int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
70 res = mclink_send(fpga - 1, regoff, data);
72 printf("mclink_send reg %02lx data %04x returned %d\n",
82 int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
91 if (fpga > mclink_fpgacount)
93 res = mclink_receive(fpga - 1, regoff, data);
95 printf("mclink_receive reg %02lx returned %d\n",
106 char *s = env_get("serial#");
107 bool hw_type_cat = pca9698_get_value(0x20, 20);
111 printf("HRCon %s", hw_type_cat ? "CAT" : "Fiber");
123 int last_stage_init(void)
127 uchar mclink_controllers[] = { 0x3c, 0x3d, 0x3e };
129 bool hw_type_cat = pca9698_get_value(0x20, 20);
130 bool ch0_rgmii2_present;
132 FPGA_GET_REG(0, fpga_features, &fpga_features);
134 /* Turn on Parade DP501 */
135 pca9698_direction_output(0x20, 10, 1);
136 pca9698_direction_output(0x20, 11, 1);
138 ch0_rgmii2_present = !pca9698_get_value(0x20, 30);
140 /* wait for FPGA done, then reset FPGA */
141 for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) {
144 if (i2c_probe(mclink_controllers[k]))
147 while (!(pca953x_get_val(mclink_controllers[k])
151 printf("no done for mclink_controller %u\n", k);
156 pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
157 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
159 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
166 struct mii_dev *mdiodev = mdio_alloc();
170 strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
171 mdiodev->read = bb_miiphy_read;
172 mdiodev->write = bb_miiphy_write;
174 retval = mdio_register(mdiodev);
177 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
178 if ((mux_ch == 1) && !ch0_rgmii2_present)
181 setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
185 /* give slave-PLLs and Parade DP501 some time to be up and running */
188 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
189 slaves = mclink_probe();
190 mclink_fpgacount = 0;
192 ioep_fpga_print_info(0);
194 #ifdef CONFIG_SYS_OSD_DH
201 mclink_fpgacount = slaves;
203 for (k = 1; k <= slaves; ++k) {
204 FPGA_GET_REG(k, fpga_features, &fpga_features);
206 ioep_fpga_print_info(k);
208 #ifdef CONFIG_SYS_OSD_DH
213 struct mii_dev *mdiodev = mdio_alloc();
217 strncpy(mdiodev->name, bb_miiphy_buses[k].name,
219 mdiodev->read = bb_miiphy_read;
220 mdiodev->write = bb_miiphy_write;
222 retval = mdio_register(mdiodev);
225 setup_88e1514(bb_miiphy_buses[k].name, 0);
229 for (k = 0; k < ARRAY_SIZE(hrcon_fans); ++k) {
230 i2c_set_bus_num(hrcon_fans[k].bus);
231 init_fan_controller(hrcon_fans[k].addr);
238 * provide access to fpga gpios and controls (for I2C bitbang)
239 * (these may look all too simple but make iocon.h much more readable)
241 void fpga_gpio_set(uint bus, int pin)
243 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.set, pin);
246 void fpga_gpio_clear(uint bus, int pin)
248 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, gpio.clear, pin);
251 int fpga_gpio_get(uint bus, int pin)
255 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, gpio.read, &val);
260 void fpga_control_set(uint bus, int pin)
264 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, control, &val);
265 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val | pin);
268 void fpga_control_clear(uint bus, int pin)
272 FPGA_GET_REG(bus >= 4 ? (bus - 4) : bus, control, &val);
273 FPGA_SET_REG(bus >= 4 ? (bus - 4) : bus, control, val & ~pin);
276 void mpc8308_init(void)
278 pca9698_direction_output(0x20, 4, 1);
281 void mpc8308_set_fpga_reset(uint state)
283 pca9698_set_value(0x20, 4, state ? 0 : 1);
286 void mpc8308_setup_hw(void)
288 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
291 * set "startup-finished"-gpios
293 setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12));
294 setbits_gpio0_out(BIT(31 - 12));
297 int mpc8308_get_fpga_done(uint fpga)
299 return pca9698_get_value(0x20, 19);
302 #ifdef CONFIG_FSL_ESDHC
303 int board_mmc_init(bd_t *bd)
305 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
306 sysconf83xx_t *sysconf = &immr->sysconf;
308 /* Enable cache snooping in eSDHC system configuration register */
309 out_be32(&sysconf->sdhccr, 0x02000000);
311 return fsl_esdhc_mmc_init(bd);
315 static struct pci_region pcie_regions_0[] = {
317 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
318 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
319 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
320 .flags = PCI_REGION_MEM,
323 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
324 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
325 .size = CONFIG_SYS_PCIE1_IO_SIZE,
326 .flags = PCI_REGION_IO,
330 void pci_init_board(void)
332 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
333 sysconf83xx_t *sysconf = &immr->sysconf;
334 law83xx_t *pcie_law = sysconf->pcielaw;
335 struct pci_region *pcie_reg[] = { pcie_regions_0 };
337 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
338 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
340 /* Deassert the resets in the control register */
341 out_be32(&sysconf->pecr1, 0xE0008000);
344 /* Configure PCI Express Local Access Windows */
345 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
346 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
348 mpc83xx_pcie_init(1, pcie_reg);
351 ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
353 info->portwidth = FLASH_CFI_16BIT;
354 info->chipwidth = FLASH_CFI_BY16;
355 info->interface = FLASH_CFI_X16;
359 #if defined(CONFIG_OF_BOARD_SETUP)
360 int ft_board_setup(void *blob, bd_t *bd)
362 ft_cpu_setup(blob, bd);
363 fsl_fdt_fixup_dr_usb(blob, bd);
364 fdt_fixup_esdhc(blob, bd);
371 * FPGA MII bitbang implementation
384 static int mii_dummy_init(struct bb_miiphy_bus *bus)
389 static int mii_mdio_active(struct bb_miiphy_bus *bus)
391 struct fpga_mii *fpga_mii = bus->priv;
394 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
396 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
401 static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
403 struct fpga_mii *fpga_mii = bus->priv;
405 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
410 static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
412 struct fpga_mii *fpga_mii = bus->priv;
415 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
417 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
424 static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
427 struct fpga_mii *fpga_mii = bus->priv;
429 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
431 *v = ((gpio & GPIO_MDIO) != 0);
436 static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
438 struct fpga_mii *fpga_mii = bus->priv;
441 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
443 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
448 static int mii_delay(struct bb_miiphy_bus *bus)
455 struct bb_miiphy_bus bb_miiphy_buses[] = {
458 .init = mii_dummy_init,
459 .mdio_active = mii_mdio_active,
460 .mdio_tristate = mii_mdio_tristate,
461 .set_mdio = mii_set_mdio,
462 .get_mdio = mii_get_mdio,
463 .set_mdc = mii_set_mdc,
465 .priv = &fpga_mii[0],
469 .init = mii_dummy_init,
470 .mdio_active = mii_mdio_active,
471 .mdio_tristate = mii_mdio_tristate,
472 .set_mdio = mii_set_mdio,
473 .get_mdio = mii_get_mdio,
474 .set_mdc = mii_set_mdc,
476 .priv = &fpga_mii[1],
480 .init = mii_dummy_init,
481 .mdio_active = mii_mdio_active,
482 .mdio_tristate = mii_mdio_tristate,
483 .set_mdio = mii_set_mdio,
484 .get_mdio = mii_get_mdio,
485 .set_mdc = mii_set_mdc,
487 .priv = &fpga_mii[2],
491 .init = mii_dummy_init,
492 .mdio_active = mii_mdio_active,
493 .mdio_tristate = mii_mdio_tristate,
494 .set_mdio = mii_set_mdio,
495 .get_mdio = mii_get_mdio,
496 .set_mdc = mii_set_mdc,
498 .priv = &fpga_mii[3],
502 int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);