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)
33 #define MAX_MUX_CHANNELS 2
36 UNITTYPE_MAIN_SERVER = 0,
37 UNITTYPE_MAIN_USER = 1,
38 UNITTYPE_VIDEO_SERVER = 2,
39 UNITTYPE_VIDEO_USER = 3,
60 COMPRESSION_TYPE1_DELTA = 1,
61 COMPRESSION_TYPE1_TYPE2_DELTA = 3,
82 CARRIER_SPEED_2_5G = 1,
87 MCFPGA_INIT_N = 1 << 1,
88 MCFPGA_PROGRAM_N = 1 << 2,
89 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
90 MCFPGA_RESET_N = 1 << 4,
98 unsigned int mclink_fpgacount;
99 struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
101 static int setup_88e1518(const char *bus, unsigned char addr);
102 static int verify_88e1518(const char *bus, unsigned char addr);
104 int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
113 res = mclink_send(fpga - 1, regoff, data);
115 printf("mclink_send reg %02lx data %04x returned %d\n",
125 int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
131 *data = in_le16(reg);
134 if (fpga > mclink_fpgacount)
136 res = mclink_receive(fpga - 1, regoff, data);
138 printf("mclink_receive reg %02lx returned %d\n",
148 * Check Board Identity:
152 char *s = getenv("serial#");
168 static void print_fpga_info(unsigned int fpga, bool rgmii2_present)
174 unsigned hardware_version;
175 unsigned feature_compression;
176 unsigned feature_osd;
177 unsigned feature_audio;
178 unsigned feature_sysclock;
179 unsigned feature_ramconfig;
180 unsigned feature_carrier_speed;
181 unsigned feature_carriers;
182 unsigned feature_video_channels;
184 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
186 FPGA_GET_REG(0, versions, &versions);
187 FPGA_GET_REG(0, fpga_version, &fpga_version);
188 FPGA_GET_REG(0, fpga_features, &fpga_features);
190 unit_type = (versions & 0xf000) >> 12;
191 feature_compression = (fpga_features & 0xe000) >> 13;
192 feature_osd = fpga_features & (1<<11);
193 feature_audio = (fpga_features & 0x0600) >> 9;
194 feature_sysclock = (fpga_features & 0x0180) >> 7;
195 feature_ramconfig = (fpga_features & 0x0060) >> 5;
196 feature_carrier_speed = fpga_features & (1<<4);
197 feature_carriers = (fpga_features & 0x000c) >> 2;
198 feature_video_channels = fpga_features & 0x0003;
204 case UNITTYPE_MAIN_USER:
205 printf("Mainchannel");
208 case UNITTYPE_VIDEO_USER:
209 printf("Videochannel");
213 printf("UnitType %d(not supported)", unit_type);
217 if (unit_type == UNITTYPE_MAIN_USER) {
220 (in_le16((void *)LATCH2_BASE)>>8) & 0x0f;
223 (!!pca9698_get_value(0x20, 24) << 0)
224 | (!!pca9698_get_value(0x20, 25) << 1)
225 | (!!pca9698_get_value(0x20, 26) << 2)
226 | (!!pca9698_get_value(0x20, 27) << 3);
227 switch (hardware_version) {
229 printf(" HW-Ver 1.00,");
233 printf(" HW-Ver 1.04,");
237 printf(" HW-Ver 1.10,");
241 printf(" HW-Ver 1.20-1.21,");
245 printf(" HW-Ver 2.00,");
249 printf(" HW-Ver 2.10,");
253 printf(" HW-Ver 2.20,");
257 printf(" HW-Ver 2.30,");
261 printf(" HW-Ver %d(not supported),",
269 if (unit_type == UNITTYPE_VIDEO_USER) {
270 hardware_version = versions & 0x000f;
271 switch (hardware_version) {
273 printf(" HW-Ver 2.00,");
277 printf(" HW-Ver 2.10,");
281 printf(" HW-Ver %d(not supported),",
287 printf(" FPGA V %d.%02d\n features:",
288 fpga_version / 100, fpga_version % 100);
291 switch (feature_compression) {
292 case COMPRESSION_NONE:
293 printf(" no compression");
296 case COMPRESSION_TYPE1_DELTA:
297 printf(" type1-deltacompression");
300 case COMPRESSION_TYPE1_TYPE2_DELTA:
301 printf(" type1-deltacompression, type2-inlinecompression");
305 printf(" compression %d(not supported)", feature_compression);
309 printf(", %sosd", feature_osd ? "" : "no ");
311 switch (feature_audio) {
313 printf(", no audio");
317 printf(", audio tx");
321 printf(", audio rx");
325 printf(", audio rx+tx");
329 printf(", audio %d(not supported)", feature_audio);
335 switch (feature_sysclock) {
337 printf("clock 147.456 MHz");
341 printf("clock %d(not supported)", feature_sysclock);
345 switch (feature_ramconfig) {
347 printf(", RAM 32 bit DDR2");
351 printf(", RAM 32 bit DDR3");
355 printf(", RAM %d(not supported)", feature_ramconfig);
359 printf(", %d carrier(s) %s", feature_carriers,
360 feature_carrier_speed ? "2.5Gbit/s" : "1Gbit/s");
362 printf(", %d video channel(s)\n", feature_video_channels);
365 int last_stage_init(void)
370 unsigned char mclink_controllers[] = { 0x24, 0x25, 0x26 };
371 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
373 int feature_carrier_speed = fpga_features & (1<<4);
374 bool ch0_rgmii2_present = false;
376 FPGA_GET_REG(0, fpga_features, &fpga_features);
379 ch0_rgmii2_present = !pca9698_get_value(0x20, 30);
381 print_fpga_info(0, ch0_rgmii2_present);
384 /* wait for FPGA done */
385 for (k = 0; k < ARRAY_SIZE(mclink_controllers); ++k) {
386 unsigned int ctr = 0;
388 if (i2c_probe(mclink_controllers[k]))
391 while (!(pca953x_get_val(mclink_controllers[k])
395 printf("no done for mclink_controller %d\n", k);
401 if (!legacy && (feature_carrier_speed == CARRIER_SPEED_1G)) {
402 miiphy_register(bb_miiphy_buses[0].name, bb_miiphy_read,
404 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
405 if ((mux_ch == 1) && !ch0_rgmii2_present)
408 if (!verify_88e1518(bb_miiphy_buses[0].name, mux_ch)) {
409 printf("Fixup 88e1518 erratum on %s phy %u\n",
410 bb_miiphy_buses[0].name, mux_ch);
411 setup_88e1518(bb_miiphy_buses[0].name, mux_ch);
416 /* wait for slave-PLLs to be up and running */
419 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
420 slaves = mclink_probe();
421 mclink_fpgacount = 0;
426 mclink_fpgacount = slaves;
428 for (k = 1; k <= slaves; ++k) {
429 FPGA_GET_REG(k, fpga_features, &fpga_features);
430 feature_carrier_speed = fpga_features & (1<<4);
432 print_fpga_info(k, false);
434 if (feature_carrier_speed == CARRIER_SPEED_1G) {
435 miiphy_register(bb_miiphy_buses[k].name,
436 bb_miiphy_read, bb_miiphy_write);
437 if (!verify_88e1518(bb_miiphy_buses[k].name, 0)) {
438 printf("Fixup 88e1518 erratum on %s\n",
439 bb_miiphy_buses[k].name);
440 setup_88e1518(bb_miiphy_buses[k].name, 0);
449 * provide access to fpga gpios (for I2C bitbang)
450 * (these may look all too simple but make iocon.h much more readable)
452 void fpga_gpio_set(unsigned int bus, int pin)
454 FPGA_SET_REG(bus, gpio.set, pin);
457 void fpga_gpio_clear(unsigned int bus, int pin)
459 FPGA_SET_REG(bus, gpio.clear, pin);
462 int fpga_gpio_get(unsigned int bus, int pin)
466 FPGA_GET_REG(bus, gpio.read, &val);
471 void gd405ep_init(void)
475 if (i2c_probe(0x20)) { /* i2c_probe returns 0 on success */
476 for (k = 0; k < CONFIG_SYS_FPGA_COUNT; ++k)
477 gd->arch.fpga_state[k] |= FPGA_STATE_PLATFORM;
479 pca9698_direction_output(0x20, 4, 1);
483 void gd405ep_set_fpga_reset(unsigned state)
485 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
489 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_RESET);
490 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_RESET);
492 out_le16((void *)LATCH0_BASE, CONFIG_SYS_LATCH0_BOOT);
493 out_le16((void *)LATCH1_BASE, CONFIG_SYS_LATCH1_BOOT);
496 pca9698_set_value(0x20, 4, state ? 0 : 1);
500 void gd405ep_setup_hw(void)
503 * set "startup-finished"-gpios
505 gpio_write_bit(21, 0);
506 gpio_write_bit(22, 1);
509 int gd405ep_get_fpga_done(unsigned fpga)
511 int legacy = get_fpga_state(0) & FPGA_STATE_PLATFORM;
514 return in_le16((void *)LATCH2_BASE)
515 & CONFIG_SYS_FPGA_DONE(fpga);
517 return pca9698_get_value(0x20, 20);
521 * FPGA MII bitbang implementation
534 static int mii_dummy_init(struct bb_miiphy_bus *bus)
539 static int mii_mdio_active(struct bb_miiphy_bus *bus)
541 struct fpga_mii *fpga_mii = bus->priv;
544 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
546 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
551 static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
553 struct fpga_mii *fpga_mii = bus->priv;
555 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
560 static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
562 struct fpga_mii *fpga_mii = bus->priv;
565 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
567 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
574 static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
577 struct fpga_mii *fpga_mii = bus->priv;
579 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
581 *v = ((gpio & GPIO_MDIO) != 0);
586 static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
588 struct fpga_mii *fpga_mii = bus->priv;
591 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
593 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
598 static int mii_delay(struct bb_miiphy_bus *bus)
605 struct bb_miiphy_bus bb_miiphy_buses[] = {
608 .init = mii_dummy_init,
609 .mdio_active = mii_mdio_active,
610 .mdio_tristate = mii_mdio_tristate,
611 .set_mdio = mii_set_mdio,
612 .get_mdio = mii_get_mdio,
613 .set_mdc = mii_set_mdc,
615 .priv = &fpga_mii[0],
619 .init = mii_dummy_init,
620 .mdio_active = mii_mdio_active,
621 .mdio_tristate = mii_mdio_tristate,
622 .set_mdio = mii_set_mdio,
623 .get_mdio = mii_get_mdio,
624 .set_mdc = mii_set_mdc,
626 .priv = &fpga_mii[1],
630 .init = mii_dummy_init,
631 .mdio_active = mii_mdio_active,
632 .mdio_tristate = mii_mdio_tristate,
633 .set_mdio = mii_set_mdio,
634 .get_mdio = mii_get_mdio,
635 .set_mdc = mii_set_mdc,
637 .priv = &fpga_mii[2],
641 .init = mii_dummy_init,
642 .mdio_active = mii_mdio_active,
643 .mdio_tristate = mii_mdio_tristate,
644 .set_mdio = mii_set_mdio,
645 .get_mdio = mii_get_mdio,
646 .set_mdc = mii_set_mdc,
648 .priv = &fpga_mii[3],
652 int bb_miiphy_buses_num = sizeof(bb_miiphy_buses) /
653 sizeof(bb_miiphy_buses[0]);
656 * Workaround for erratum mentioned in 88E1518 release notes
659 static int verify_88e1518(const char *bus, unsigned char addr)
661 u16 phy_id1, phy_id2;
663 if (miiphy_read(bus, addr, 2, &phy_id1) ||
664 miiphy_read(bus, addr, 3, &phy_id2)) {
665 printf("Error reading from the PHY addr=%02x\n", addr);
669 if ((phy_id1 != 0x0141) || ((phy_id2 & 0xfff0) != 0x0dd0))
675 struct regfix_88e1518 {
678 } regfix_88e1518[] = {
693 static int setup_88e1518(const char *bus, unsigned char addr)
697 for (k = 0; k < ARRAY_SIZE(regfix_88e1518); ++k) {
698 if (miiphy_write(bus, addr,
699 regfix_88e1518[k].reg,
700 regfix_88e1518[k].data)) {
701 printf("Error writing to the PHY addr=%02x\n", addr);