blob: 9ba9e4278a515e79b007d6c6523e9559b362a798 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dirk Eibachb355f172015-10-28 11:46:32 +01002/*
3 * (C) Copyright 2014
Mario Sixb4893582018-03-06 08:04:58 +01004 * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
Dirk Eibachb355f172015-10-28 11:46:32 +01005 */
6
7#include <common.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06008#include <env.h>
Dirk Eibachb355f172015-10-28 11:46:32 +01009#include <hwconfig.h>
10#include <i2c.h>
Simon Glass18afe102019-11-14 12:57:47 -070011#include <init.h>
Dirk Eibachb355f172015-10-28 11:46:32 +010012#include <spi.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Dirk Eibachb355f172015-10-28 11:46:32 +010014#include <fdt_support.h>
15#include <pci.h>
16#include <mpc83xx.h>
17#include <fsl_esdhc.h>
18#include <asm/io.h>
19#include <asm/fsl_serdes.h>
20#include <asm/fsl_mpc83xx_serdes.h>
21
22#include "mpc8308.h"
23
24#include <gdsys_fpga.h>
25
26#include "../common/adv7611.h"
27#include "../common/ch7301.h"
Dirk Eibache9539ed2016-03-16 09:20:11 +010028#include "../common/dp501.h"
Dirk Eibachb355f172015-10-28 11:46:32 +010029#include "../common/ioep-fpga.h"
30#include "../common/mclink.h"
31#include "../common/osd.h"
32#include "../common/phy.h"
Dirk Eibach94594332015-10-28 11:46:36 +010033#include "../common/fanctrl.h"
Dirk Eibachb355f172015-10-28 11:46:32 +010034
35#include <pca953x.h>
36#include <pca9698.h>
37
38#include <miiphy.h>
39
Dirk Eibachb355f172015-10-28 11:46:32 +010040#define MAX_MUX_CHANNELS 2
41
42enum {
43 MCFPGA_DONE = 1 << 0,
44 MCFPGA_INIT_N = 1 << 1,
45 MCFPGA_PROGRAM_N = 1 << 2,
46 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
47 MCFPGA_RESET_N = 1 << 4,
48};
49
50enum {
51 GPIO_MDC = 1 << 14,
52 GPIO_MDIO = 1 << 15,
53};
54
Mario Six3809c472019-03-29 10:18:06 +010055uint mclink_fpgacount;
Dirk Eibachb355f172015-10-28 11:46:32 +010056struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
57
58struct {
59 u8 bus;
60 u8 addr;
61} strider_fans[] = CONFIG_STRIDER_FANS;
62
63int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
64{
65 int res;
66
67 switch (fpga) {
68 case 0:
69 out_le16(reg, data);
70 break;
71 default:
72 res = mclink_send(fpga - 1, regoff, data);
73 if (res < 0) {
74 printf("mclink_send reg %02lx data %04x returned %d\n",
75 regoff, data, res);
76 return res;
77 }
78 break;
79 }
80
81 return 0;
82}
83
84int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
85{
86 int res;
87
88 switch (fpga) {
89 case 0:
90 *data = in_le16(reg);
91 break;
92 default:
93 if (fpga > mclink_fpgacount)
94 return -EINVAL;
95 res = mclink_receive(fpga - 1, regoff, data);
96 if (res < 0) {
97 printf("mclink_receive reg %02lx returned %d\n",
98 regoff, res);
99 return res;
100 }
101 }
102
103 return 0;
104}
105
106int checkboard(void)
107{
Simon Glass64b723f2017-08-03 12:22:12 -0600108 char *s = env_get("serial#");
Dirk Eibachb355f172015-10-28 11:46:32 +0100109 bool hw_type_cat = pca9698_get_value(0x20, 18);
110
111 puts("Board: ");
112
113 printf("Strider %s", hw_type_cat ? "CAT" : "Fiber");
114
Mario Six3809c472019-03-29 10:18:06 +0100115 if (s) {
Dirk Eibachb355f172015-10-28 11:46:32 +0100116 puts(", serial# ");
117 puts(s);
118 }
119
120 puts("\n");
121
122 return 0;
123}
124
Dirk Eibachb355f172015-10-28 11:46:32 +0100125int last_stage_init(void)
126{
127 int slaves;
Mario Six3809c472019-03-29 10:18:06 +0100128 uint k;
129 uint mux_ch;
130 uchar mclink_controllers_dvi[] = { 0x3c, 0x3d, 0x3e };
Dirk Eibache9539ed2016-03-16 09:20:11 +0100131#ifdef CONFIG_STRIDER_CPU
Mario Six3809c472019-03-29 10:18:06 +0100132 uchar mclink_controllers_dp[] = { 0x24, 0x25, 0x26 };
Dirk Eibache9539ed2016-03-16 09:20:11 +0100133#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100134 bool hw_type_cat = pca9698_get_value(0x20, 18);
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200135#ifdef CONFIG_STRIDER_CON_DP
136 bool is_dh = pca9698_get_value(0x20, 25);
137#endif
Mario Six3809c472019-03-29 10:18:06 +0100138 bool ch0_sgmii2_present;
Dirk Eibachb355f172015-10-28 11:46:32 +0100139
140 /* Turn on Analog Devices ADV7611 */
141 pca9698_direction_output(0x20, 8, 0);
142
143 /* Turn on Parade DP501 */
Dirk Eibache9539ed2016-03-16 09:20:11 +0100144 pca9698_direction_output(0x20, 10, 1);
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200145 pca9698_direction_output(0x20, 11, 1);
Dirk Eibachb355f172015-10-28 11:46:32 +0100146
147 ch0_sgmii2_present = !pca9698_get_value(0x20, 37);
148
149 /* wait for FPGA done, then reset FPGA */
Dirk Eibache9539ed2016-03-16 09:20:11 +0100150 for (k = 0; k < ARRAY_SIZE(mclink_controllers_dvi); ++k) {
Mario Six3809c472019-03-29 10:18:06 +0100151 uint ctr = 0;
152 uchar *mclink_controllers = mclink_controllers_dvi;
Dirk Eibachb355f172015-10-28 11:46:32 +0100153
Dirk Eibache9539ed2016-03-16 09:20:11 +0100154#ifdef CONFIG_STRIDER_CPU
155 if (i2c_probe(mclink_controllers[k])) {
156 mclink_controllers = mclink_controllers_dp;
157 if (i2c_probe(mclink_controllers[k]))
158 continue;
159 }
160#else
Dirk Eibachb355f172015-10-28 11:46:32 +0100161 if (i2c_probe(mclink_controllers[k]))
162 continue;
Dirk Eibache9539ed2016-03-16 09:20:11 +0100163#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100164 while (!(pca953x_get_val(mclink_controllers[k])
165 & MCFPGA_DONE)) {
Mario Six3809c472019-03-29 10:18:06 +0100166 mdelay(100);
Dirk Eibachb355f172015-10-28 11:46:32 +0100167 if (ctr++ > 5) {
168 printf("no done for mclink_controller %d\n", k);
169 break;
170 }
171 }
172
173 pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
174 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
175 udelay(10);
176 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
177 MCFPGA_RESET_N);
178 }
179
180 if (hw_type_cat) {
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500181 int retval;
182 struct mii_dev *mdiodev = mdio_alloc();
Mario Six3809c472019-03-29 10:18:06 +0100183
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500184 if (!mdiodev)
185 return -ENOMEM;
186 strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
187 mdiodev->read = bb_miiphy_read;
188 mdiodev->write = bb_miiphy_write;
189
190 retval = mdio_register(mdiodev);
191 if (retval < 0)
192 return retval;
Dirk Eibachb355f172015-10-28 11:46:32 +0100193 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
194 if ((mux_ch == 1) && !ch0_sgmii2_present)
195 continue;
196
197 setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
198 }
199 }
200
201 /* give slave-PLLs and Parade DP501 some time to be up and running */
Mario Six3809c472019-03-29 10:18:06 +0100202 mdelay(500);
Dirk Eibachb355f172015-10-28 11:46:32 +0100203
204 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
205 slaves = mclink_probe();
206 mclink_fpgacount = 0;
207
208 ioep_fpga_print_info(0);
209
210 if (!adv7611_probe(0))
211 printf(" Advantiv ADV7611 HDMI Receiver\n");
212
213#ifdef CONFIG_STRIDER_CON
214 if (ioep_fpga_has_osd(0))
215 osd_probe(0);
216#endif
217
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200218#ifdef CONFIG_STRIDER_CON_DP
219 if (ioep_fpga_has_osd(0)) {
220 osd_probe(0);
221 if (is_dh)
222 osd_probe(4);
223 }
224#endif
225
Dirk Eibachb355f172015-10-28 11:46:32 +0100226#ifdef CONFIG_STRIDER_CPU
227 ch7301_probe(0, false);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100228 dp501_probe(0, false);
Dirk Eibachb355f172015-10-28 11:46:32 +0100229#endif
230
231 if (slaves <= 0)
232 return 0;
233
234 mclink_fpgacount = slaves;
235
Dirk Eibache9539ed2016-03-16 09:20:11 +0100236#ifdef CONFIG_STRIDER_CPU
237 /* get ADV7611 out of reset, power up DP501, give some time to wakeup */
238 for (k = 1; k <= slaves; ++k)
239 FPGA_SET_REG(k, extended_control, 0x10); /* enable video */
240
Mario Six3809c472019-03-29 10:18:06 +0100241 mdelay(500);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100242#endif
243
Dirk Eibachb355f172015-10-28 11:46:32 +0100244 for (k = 1; k <= slaves; ++k) {
245 ioep_fpga_print_info(k);
246#ifdef CONFIG_STRIDER_CON
247 if (ioep_fpga_has_osd(k))
248 osd_probe(k);
249#endif
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200250#ifdef CONFIG_STRIDER_CON_DP
251 if (ioep_fpga_has_osd(k)) {
252 osd_probe(k);
253 if (is_dh)
254 osd_probe(k + 4);
255 }
256#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100257#ifdef CONFIG_STRIDER_CPU
Dirk Eibachb355f172015-10-28 11:46:32 +0100258 if (!adv7611_probe(k))
259 printf(" Advantiv ADV7611 HDMI Receiver\n");
260 ch7301_probe(k, false);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100261 dp501_probe(k, false);
Dirk Eibachb355f172015-10-28 11:46:32 +0100262#endif
263 if (hw_type_cat) {
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500264 int retval;
265 struct mii_dev *mdiodev = mdio_alloc();
Mario Six3809c472019-03-29 10:18:06 +0100266
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500267 if (!mdiodev)
268 return -ENOMEM;
269 strncpy(mdiodev->name, bb_miiphy_buses[k].name,
270 MDIO_NAME_LEN);
271 mdiodev->read = bb_miiphy_read;
272 mdiodev->write = bb_miiphy_write;
273
274 retval = mdio_register(mdiodev);
275 if (retval < 0)
276 return retval;
Dirk Eibachb355f172015-10-28 11:46:32 +0100277 setup_88e1514(bb_miiphy_buses[k].name, 0);
278 }
279 }
280
281 for (k = 0; k < ARRAY_SIZE(strider_fans); ++k) {
282 i2c_set_bus_num(strider_fans[k].bus);
283 init_fan_controller(strider_fans[k].addr);
284 }
285
286 return 0;
287}
288
289/*
290 * provide access to fpga gpios (for I2C bitbang)
291 * (these may look all too simple but make iocon.h much more readable)
292 */
Mario Six3809c472019-03-29 10:18:06 +0100293void fpga_gpio_set(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100294{
295 FPGA_SET_REG(bus, gpio.set, pin);
296}
297
Mario Six3809c472019-03-29 10:18:06 +0100298void fpga_gpio_clear(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100299{
300 FPGA_SET_REG(bus, gpio.clear, pin);
301}
302
Mario Six3809c472019-03-29 10:18:06 +0100303int fpga_gpio_get(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100304{
305 u16 val;
306
307 FPGA_GET_REG(bus, gpio.read, &val);
308
309 return val & pin;
310}
311
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200312#ifdef CONFIG_STRIDER_CON_DP
Mario Six3809c472019-03-29 10:18:06 +0100313void fpga_control_set(uint bus, int pin)
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200314{
315 u16 val;
316
317 FPGA_GET_REG(bus, control, &val);
318 FPGA_SET_REG(bus, control, val | pin);
319}
320
Mario Six3809c472019-03-29 10:18:06 +0100321void fpga_control_clear(uint bus, int pin)
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200322{
323 u16 val;
324
325 FPGA_GET_REG(bus, control, &val);
326 FPGA_SET_REG(bus, control, val & ~pin);
327}
328#endif
329
Dirk Eibachb355f172015-10-28 11:46:32 +0100330void mpc8308_init(void)
331{
332 pca9698_direction_output(0x20, 26, 1);
333}
334
Mario Six3809c472019-03-29 10:18:06 +0100335void mpc8308_set_fpga_reset(uint state)
Dirk Eibachb355f172015-10-28 11:46:32 +0100336{
337 pca9698_set_value(0x20, 26, state ? 0 : 1);
338}
339
340void mpc8308_setup_hw(void)
341{
342 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
343
344 /*
345 * set "startup-finished"-gpios
346 */
Mario Six3809c472019-03-29 10:18:06 +0100347 setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12));
Mario Sixae0feaa2019-03-29 10:18:07 +0100348 setbits_gpio0_out(BIT(31 - 12));
Dirk Eibachb355f172015-10-28 11:46:32 +0100349}
350
Mario Six3809c472019-03-29 10:18:06 +0100351int mpc8308_get_fpga_done(uint fpga)
Dirk Eibachb355f172015-10-28 11:46:32 +0100352{
353 return pca9698_get_value(0x20, 20);
354}
355
356#ifdef CONFIG_FSL_ESDHC
357int board_mmc_init(bd_t *bd)
358{
359 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
360 sysconf83xx_t *sysconf = &immr->sysconf;
361
362 /* Enable cache snooping in eSDHC system configuration register */
363 out_be32(&sysconf->sdhccr, 0x02000000);
364
365 return fsl_esdhc_mmc_init(bd);
366}
367#endif
368
369static struct pci_region pcie_regions_0[] = {
370 {
371 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
372 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
373 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
374 .flags = PCI_REGION_MEM,
375 },
376 {
377 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
378 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
379 .size = CONFIG_SYS_PCIE1_IO_SIZE,
380 .flags = PCI_REGION_IO,
381 },
382};
383
384void pci_init_board(void)
385{
386 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
387 sysconf83xx_t *sysconf = &immr->sysconf;
388 law83xx_t *pcie_law = sysconf->pcielaw;
389 struct pci_region *pcie_reg[] = { pcie_regions_0 };
390
391 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
392 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
393
394 /* Deassert the resets in the control register */
395 out_be32(&sysconf->pecr1, 0xE0008000);
396 udelay(2000);
397
398 /* Configure PCI Express Local Access Windows */
399 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
400 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
401
402 mpc83xx_pcie_init(1, pcie_reg);
403}
404
405ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
406{
407 info->portwidth = FLASH_CFI_16BIT;
408 info->chipwidth = FLASH_CFI_BY16;
409 info->interface = FLASH_CFI_X16;
410 return 1;
411}
412
413#if defined(CONFIG_OF_BOARD_SETUP)
414int ft_board_setup(void *blob, bd_t *bd)
415{
416 ft_cpu_setup(blob, bd);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530417 fsl_fdt_fixup_dr_usb(blob, bd);
Dirk Eibachb355f172015-10-28 11:46:32 +0100418 fdt_fixup_esdhc(blob, bd);
419
420 return 0;
421}
422#endif
423
424/*
425 * FPGA MII bitbang implementation
426 */
427
428struct fpga_mii {
Mario Six3809c472019-03-29 10:18:06 +0100429 uint fpga;
Dirk Eibachb355f172015-10-28 11:46:32 +0100430 int mdio;
431} fpga_mii[] = {
432 { 0, 1},
433 { 1, 1},
434 { 2, 1},
435 { 3, 1},
436};
437
438static int mii_dummy_init(struct bb_miiphy_bus *bus)
439{
440 return 0;
441}
442
443static int mii_mdio_active(struct bb_miiphy_bus *bus)
444{
445 struct fpga_mii *fpga_mii = bus->priv;
446
447 if (fpga_mii->mdio)
448 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
449 else
450 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
451
452 return 0;
453}
454
455static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
456{
457 struct fpga_mii *fpga_mii = bus->priv;
458
459 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
460
461 return 0;
462}
463
464static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
465{
466 struct fpga_mii *fpga_mii = bus->priv;
467
468 if (v)
469 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
470 else
471 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
472
473 fpga_mii->mdio = v;
474
475 return 0;
476}
477
478static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
479{
480 u16 gpio;
481 struct fpga_mii *fpga_mii = bus->priv;
482
483 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
484
485 *v = ((gpio & GPIO_MDIO) != 0);
486
487 return 0;
488}
489
490static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
491{
492 struct fpga_mii *fpga_mii = bus->priv;
493
494 if (v)
495 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
496 else
497 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
498
499 return 0;
500}
501
502static int mii_delay(struct bb_miiphy_bus *bus)
503{
504 udelay(1);
505
506 return 0;
507}
508
509struct bb_miiphy_bus bb_miiphy_buses[] = {
510 {
511 .name = "board0",
512 .init = mii_dummy_init,
513 .mdio_active = mii_mdio_active,
514 .mdio_tristate = mii_mdio_tristate,
515 .set_mdio = mii_set_mdio,
516 .get_mdio = mii_get_mdio,
517 .set_mdc = mii_set_mdc,
518 .delay = mii_delay,
519 .priv = &fpga_mii[0],
520 },
521 {
522 .name = "board1",
523 .init = mii_dummy_init,
524 .mdio_active = mii_mdio_active,
525 .mdio_tristate = mii_mdio_tristate,
526 .set_mdio = mii_set_mdio,
527 .get_mdio = mii_get_mdio,
528 .set_mdc = mii_set_mdc,
529 .delay = mii_delay,
530 .priv = &fpga_mii[1],
531 },
532 {
533 .name = "board2",
534 .init = mii_dummy_init,
535 .mdio_active = mii_mdio_active,
536 .mdio_tristate = mii_mdio_tristate,
537 .set_mdio = mii_set_mdio,
538 .get_mdio = mii_get_mdio,
539 .set_mdc = mii_set_mdc,
540 .delay = mii_delay,
541 .priv = &fpga_mii[2],
542 },
543 {
544 .name = "board3",
545 .init = mii_dummy_init,
546 .mdio_active = mii_mdio_active,
547 .mdio_tristate = mii_mdio_tristate,
548 .set_mdio = mii_set_mdio,
549 .get_mdio = mii_get_mdio,
550 .set_mdc = mii_set_mdc,
551 .delay = mii_delay,
552 .priv = &fpga_mii[3],
553 },
554};
555
Mario Six3809c472019-03-29 10:18:06 +0100556int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);