3 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
5 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/processor.h>
13 #include <asm/ppc4xx-gpio.h>
16 #include <gdsys_fpga.h>
18 #include "../common/osd.h"
19 #include "../common/mclink.h"
27 DECLARE_GLOBAL_DATA_PTR;
29 #define LATCH0_BASE (CONFIG_SYS_LATCH_BASE)
30 #define LATCH1_BASE (CONFIG_SYS_LATCH_BASE + 0x100)
31 #define LATCH2_BASE (CONFIG_SYS_LATCH_BASE + 0x200)
34 UNITTYPE_MAIN_SERVER = 0,
35 UNITTYPE_MAIN_USER = 1,
36 UNITTYPE_VIDEO_SERVER = 2,
37 UNITTYPE_VIDEO_USER = 3,
56 COMPRESSION_TYPE1_DELTA = 1,
57 COMPRESSION_TYPE1_TYPE2_DELTA = 3,
78 MCFPGA_INIT_N = 1 << 1,
79 MCFPGA_PROGRAM_N = 1 << 2,
80 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
81 MCFPGA_RESET_N = 1 << 4,
89 unsigned int mclink_fpgacount;
90 struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
92 static int setup_88e1518(const char *bus, unsigned char addr);
93 static int verify_88e1518(const char *bus, unsigned char addr);
95 int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
104 res = mclink_send(fpga - 1, regoff, data);
106 printf("mclink_send reg %02lx data %04x returned %d\n",
116 int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
122 *data = in_le16(reg);
125 if (fpga > mclink_fpgacount)
127 res = mclink_receive(fpga - 1, regoff, data);
129 printf("mclink_receive reg %02lx returned %d\n",
139 * Check Board Identity:
143 char *s = getenv("serial#");
159 static void print_fpga_info(unsigned int fpga)
165 unsigned hardware_version;
166 unsigned feature_compression;
167 unsigned feature_osd;
168 unsigned feature_audio;
169 unsigned feature_sysclock;
170 unsigned feature_ramconfig;
171 unsigned feature_carriers;
172 unsigned feature_video_channels;
173 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
175 FPGA_GET_REG(0, versions, &versions);
176 FPGA_GET_REG(0, fpga_version, &fpga_version);
177 FPGA_GET_REG(0, fpga_features, &fpga_features);
179 unit_type = (versions & 0xf000) >> 12;
180 feature_compression = (fpga_features & 0xe000) >> 13;
181 feature_osd = fpga_features & (1<<11);
182 feature_audio = (fpga_features & 0x0600) >> 9;
183 feature_sysclock = (fpga_features & 0x0180) >> 7;
184 feature_ramconfig = (fpga_features & 0x0060) >> 5;
185 feature_carriers = (fpga_features & 0x000c) >> 2;
186 feature_video_channels = fpga_features & 0x0003;
192 case UNITTYPE_MAIN_USER:
193 printf("Mainchannel");
196 case UNITTYPE_VIDEO_USER:
197 printf("Videochannel");
201 printf("UnitType %d(not supported)", unit_type);
205 if (unit_type == UNITTYPE_MAIN_USER) {
208 (in_le16((void *)LATCH2_BASE)>>8) & 0x0f;
211 (!!pca9698_get_value(0x20, 24) << 0)
212 | (!!pca9698_get_value(0x20, 25) << 1)
213 | (!!pca9698_get_value(0x20, 26) << 2)
214 | (!!pca9698_get_value(0x20, 27) << 3);
215 switch (hardware_version) {
217 printf(" HW-Ver 1.00,");
221 printf(" HW-Ver 1.04,");
225 printf(" HW-Ver 1.10,");
229 printf(" HW-Ver 1.20-1.21,");
233 printf(" HW-Ver 2.00,");
237 printf(" HW-Ver 2.10,");
241 printf(" HW-Ver %d(not supported),",
247 if (unit_type == UNITTYPE_VIDEO_USER) {
248 hardware_version = versions & 0x000f;
249 switch (hardware_version) {
251 printf(" HW-Ver 2.00,");
255 printf(" HW-Ver 2.10,");
259 printf(" HW-Ver %d(not supported),",
265 printf(" FPGA V %d.%02d\n features:",
266 fpga_version / 100, fpga_version % 100);
269 switch (feature_compression) {
270 case COMPRESSION_NONE:
271 printf(" no compression");
274 case COMPRESSION_TYPE1_DELTA:
275 printf(" type1-deltacompression");
278 case COMPRESSION_TYPE1_TYPE2_DELTA:
279 printf(" type1-deltacompression, type2-inlinecompression");
283 printf(" compression %d(not supported)", feature_compression);
287 printf(", %sosd", feature_osd ? "" : "no ");
289 switch (feature_audio) {
291 printf(", no audio");
295 printf(", audio tx");
299 printf(", audio rx");
303 printf(", audio rx+tx");
307 printf(", audio %d(not supported)", feature_audio);
313 switch (feature_sysclock) {
315 printf("clock 147.456 MHz");
319 printf("clock %d(not supported)", feature_sysclock);
323 switch (feature_ramconfig) {
325 printf(", RAM 32 bit DDR2");
329 printf(", RAM 32 bit DDR3");
333 printf(", RAM %d(not supported)", feature_ramconfig);
337 printf(", %d carrier(s)", feature_carriers);
339 printf(", %d video channel(s)\n", feature_video_channels);
342 int last_stage_init(void)
346 unsigned char mclink_controllers[] = { 0x24, 0x25, 0x26 };
347 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
352 /* wait for FPGA done */
353 for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) {
354 unsigned int ctr = 0;
356 if (i2c_probe(mclink_controllers[k]))
359 while (!(pca953x_get_val(mclink_controllers[k])
363 printf("no done for mclink_controller %d\n", k);
370 miiphy_register(bb_miiphy_buses[0].name, bb_miiphy_read,
372 if (!verify_88e1518(bb_miiphy_buses[0].name, 0)) {
373 printf("Fixup 88e1518 erratum on %s\n",
374 bb_miiphy_buses[0].name);
375 setup_88e1518(bb_miiphy_buses[0].name, 0);
379 /* wait for slave-PLLs to be up and running */
382 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
383 slaves = mclink_probe();
384 mclink_fpgacount = 0;
389 mclink_fpgacount = slaves;
391 for (k = 1; k <= slaves; ++k) {
394 miiphy_register(bb_miiphy_buses[k].name,
395 bb_miiphy_read, bb_miiphy_write);
396 if (!verify_88e1518(bb_miiphy_buses[k].name, 0)) {
397 printf("Fixup 88e1518 erratum on %s\n",
398 bb_miiphy_buses[k].name);
399 setup_88e1518(bb_miiphy_buses[k].name, 0);
407 * provide access to fpga gpios (for I2C bitbang)
408 * (these may look all too simple but make iocon.h much more readable)
410 void fpga_gpio_set(unsigned int bus, int pin)
412 FPGA_SET_REG(bus, gpio.set, pin);
415 void fpga_gpio_clear(unsigned int bus, int pin)
417 FPGA_SET_REG(bus, gpio.clear, pin);
420 int fpga_gpio_get(unsigned int bus, int pin)
424 FPGA_GET_REG(bus, gpio.read, &val);
429 void gd405ep_init(void)
433 if (i2c_probe(0x20)) { /* i2c_probe returns 0 on success */
434 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
435 gd->arch.fpga_state[k] |= FPGA_STATE_PLATFORM;
437 pca9698_direction_output(0x20, 4, 1);
441 void gd405ep_set_fpga_reset(unsigned state)
443 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
447 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
448 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
450 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
451 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
454 pca9698_set_value(0x20, 4, state ? 0 : 1);
458 void gd405ep_setup_hw(void)
461 * set "startup-finished"-gpios
463 gpio_write_bit(21, 0);
464 gpio_write_bit(22, 1);
467 int gd405ep_get_fpga_done(unsigned fpga)
469 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
472 return in_le16((void *)LATCH2_BASE)
473 & CONFIG_SYS_FPGA_DONE(fpga);
475 return pca9698_get_value(0x20, 20);
479 * FPGA MII bitbang implementation
492 static int mii_dummy_init(struct bb_miiphy_bus *bus)
497 static int mii_mdio_active(struct bb_miiphy_bus *bus)
499 struct fpga_mii *fpga_mii = bus->priv;
502 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
504 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
509 static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
511 struct fpga_mii *fpga_mii = bus->priv;
513 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
518 static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
520 struct fpga_mii *fpga_mii = bus->priv;
523 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
525 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
532 static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
535 struct fpga_mii *fpga_mii = bus->priv;
537 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
539 *v = ((gpio & GPIO_MDIO) != 0);
544 static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
546 struct fpga_mii *fpga_mii = bus->priv;
549 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
551 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
556 static int mii_delay(struct bb_miiphy_bus *bus)
563 struct bb_miiphy_bus bb_miiphy_buses[] = {
566 .init = mii_dummy_init,
567 .mdio_active = mii_mdio_active,
568 .mdio_tristate = mii_mdio_tristate,
569 .set_mdio = mii_set_mdio,
570 .get_mdio = mii_get_mdio,
571 .set_mdc = mii_set_mdc,
573 .priv = &fpga_mii[0],
577 .init = mii_dummy_init,
578 .mdio_active = mii_mdio_active,
579 .mdio_tristate = mii_mdio_tristate,
580 .set_mdio = mii_set_mdio,
581 .get_mdio = mii_get_mdio,
582 .set_mdc = mii_set_mdc,
584 .priv = &fpga_mii[1],
588 .init = mii_dummy_init,
589 .mdio_active = mii_mdio_active,
590 .mdio_tristate = mii_mdio_tristate,
591 .set_mdio = mii_set_mdio,
592 .get_mdio = mii_get_mdio,
593 .set_mdc = mii_set_mdc,
595 .priv = &fpga_mii[2],
599 .init = mii_dummy_init,
600 .mdio_active = mii_mdio_active,
601 .mdio_tristate = mii_mdio_tristate,
602 .set_mdio = mii_set_mdio,
603 .get_mdio = mii_get_mdio,
604 .set_mdc = mii_set_mdc,
606 .priv = &fpga_mii[3],
610 int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
611 sizeof(bb_miiphy_buses[0]);
614 * Workaround for erratum mentioned in 88E1518 release notes
617 static int verify_88e1518(const char *bus, unsigned char addr)
619 u16 phy_id1, phy_id2;
621 if (miiphy_read(bus, addr, 2, &phy_id1) ||
622 miiphy_read(bus, addr, 3, &phy_id2)) {
623 printf("Error reading from the PHY addr=%02x\n", addr);
627 if ((phy_id1 != 0x0141) || ((phy_id2 & 0xfff0) != 0x0dd0))
633 struct regfix_88e1518 {
636 } regfix_88e1518[] = {
651 static int setup_88e1518(const char *bus, unsigned char addr)
655 for (k = 0; k < ARRAY_SIZE(regfix_88e1518); ++k) {
656 if (miiphy_write(bus, addr,
657 regfix_88e1518[k].reg,
658 regfix_88e1518[k].data)) {
659 printf("Error writing to the PHY addr=%02x\n", addr);