blob: 9b82c949b384a1542e35e046a15c91f892eae370 [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>
Simon Glass8e201882020-05-10 11:39:54 -06009#include <flash.h>
Dirk Eibachb355f172015-10-28 11:46:32 +010010#include <hwconfig.h>
11#include <i2c.h>
Simon Glass18afe102019-11-14 12:57:47 -070012#include <init.h>
Dirk Eibachb355f172015-10-28 11:46:32 +010013#include <spi.h>
Simon Glassdbd79542020-05-10 11:40:11 -060014#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090015#include <linux/libfdt.h>
Dirk Eibachb355f172015-10-28 11:46:32 +010016#include <fdt_support.h>
17#include <pci.h>
18#include <mpc83xx.h>
19#include <fsl_esdhc.h>
20#include <asm/io.h>
21#include <asm/fsl_serdes.h>
22#include <asm/fsl_mpc83xx_serdes.h>
23
24#include "mpc8308.h"
25
26#include <gdsys_fpga.h>
27
28#include "../common/adv7611.h"
29#include "../common/ch7301.h"
Dirk Eibache9539ed2016-03-16 09:20:11 +010030#include "../common/dp501.h"
Dirk Eibachb355f172015-10-28 11:46:32 +010031#include "../common/ioep-fpga.h"
32#include "../common/mclink.h"
33#include "../common/osd.h"
34#include "../common/phy.h"
Dirk Eibach94594332015-10-28 11:46:36 +010035#include "../common/fanctrl.h"
Dirk Eibachb355f172015-10-28 11:46:32 +010036
37#include <pca953x.h>
38#include <pca9698.h>
39
40#include <miiphy.h>
41
Dirk Eibachb355f172015-10-28 11:46:32 +010042#define MAX_MUX_CHANNELS 2
43
44enum {
45 MCFPGA_DONE = 1 << 0,
46 MCFPGA_INIT_N = 1 << 1,
47 MCFPGA_PROGRAM_N = 1 << 2,
48 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
49 MCFPGA_RESET_N = 1 << 4,
50};
51
52enum {
53 GPIO_MDC = 1 << 14,
54 GPIO_MDIO = 1 << 15,
55};
56
Mario Six3809c472019-03-29 10:18:06 +010057uint mclink_fpgacount;
Dirk Eibachb355f172015-10-28 11:46:32 +010058struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
59
60struct {
61 u8 bus;
62 u8 addr;
63} strider_fans[] = CONFIG_STRIDER_FANS;
64
65int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
66{
67 int res;
68
69 switch (fpga) {
70 case 0:
71 out_le16(reg, data);
72 break;
73 default:
74 res = mclink_send(fpga - 1, regoff, data);
75 if (res < 0) {
76 printf("mclink_send reg %02lx data %04x returned %d\n",
77 regoff, data, res);
78 return res;
79 }
80 break;
81 }
82
83 return 0;
84}
85
86int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
87{
88 int res;
89
90 switch (fpga) {
91 case 0:
92 *data = in_le16(reg);
93 break;
94 default:
95 if (fpga > mclink_fpgacount)
96 return -EINVAL;
97 res = mclink_receive(fpga - 1, regoff, data);
98 if (res < 0) {
99 printf("mclink_receive reg %02lx returned %d\n",
100 regoff, res);
101 return res;
102 }
103 }
104
105 return 0;
106}
107
108int checkboard(void)
109{
Simon Glass64b723f2017-08-03 12:22:12 -0600110 char *s = env_get("serial#");
Dirk Eibachb355f172015-10-28 11:46:32 +0100111 bool hw_type_cat = pca9698_get_value(0x20, 18);
112
113 puts("Board: ");
114
115 printf("Strider %s", hw_type_cat ? "CAT" : "Fiber");
116
Mario Six3809c472019-03-29 10:18:06 +0100117 if (s) {
Dirk Eibachb355f172015-10-28 11:46:32 +0100118 puts(", serial# ");
119 puts(s);
120 }
121
122 puts("\n");
123
124 return 0;
125}
126
Dirk Eibachb355f172015-10-28 11:46:32 +0100127int last_stage_init(void)
128{
129 int slaves;
Mario Six3809c472019-03-29 10:18:06 +0100130 uint k;
131 uint mux_ch;
132 uchar mclink_controllers_dvi[] = { 0x3c, 0x3d, 0x3e };
Dirk Eibache9539ed2016-03-16 09:20:11 +0100133#ifdef CONFIG_STRIDER_CPU
Mario Six3809c472019-03-29 10:18:06 +0100134 uchar mclink_controllers_dp[] = { 0x24, 0x25, 0x26 };
Dirk Eibache9539ed2016-03-16 09:20:11 +0100135#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100136 bool hw_type_cat = pca9698_get_value(0x20, 18);
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200137#ifdef CONFIG_STRIDER_CON_DP
138 bool is_dh = pca9698_get_value(0x20, 25);
139#endif
Mario Six3809c472019-03-29 10:18:06 +0100140 bool ch0_sgmii2_present;
Dirk Eibachb355f172015-10-28 11:46:32 +0100141
142 /* Turn on Analog Devices ADV7611 */
143 pca9698_direction_output(0x20, 8, 0);
144
145 /* Turn on Parade DP501 */
Dirk Eibache9539ed2016-03-16 09:20:11 +0100146 pca9698_direction_output(0x20, 10, 1);
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200147 pca9698_direction_output(0x20, 11, 1);
Dirk Eibachb355f172015-10-28 11:46:32 +0100148
149 ch0_sgmii2_present = !pca9698_get_value(0x20, 37);
150
151 /* wait for FPGA done, then reset FPGA */
Dirk Eibache9539ed2016-03-16 09:20:11 +0100152 for (k = 0; k < ARRAY_SIZE(mclink_controllers_dvi); ++k) {
Mario Six3809c472019-03-29 10:18:06 +0100153 uint ctr = 0;
154 uchar *mclink_controllers = mclink_controllers_dvi;
Dirk Eibachb355f172015-10-28 11:46:32 +0100155
Dirk Eibache9539ed2016-03-16 09:20:11 +0100156#ifdef CONFIG_STRIDER_CPU
157 if (i2c_probe(mclink_controllers[k])) {
158 mclink_controllers = mclink_controllers_dp;
159 if (i2c_probe(mclink_controllers[k]))
160 continue;
161 }
162#else
Dirk Eibachb355f172015-10-28 11:46:32 +0100163 if (i2c_probe(mclink_controllers[k]))
164 continue;
Dirk Eibache9539ed2016-03-16 09:20:11 +0100165#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100166 while (!(pca953x_get_val(mclink_controllers[k])
167 & MCFPGA_DONE)) {
Mario Six3809c472019-03-29 10:18:06 +0100168 mdelay(100);
Dirk Eibachb355f172015-10-28 11:46:32 +0100169 if (ctr++ > 5) {
170 printf("no done for mclink_controller %d\n", k);
171 break;
172 }
173 }
174
175 pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
176 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
177 udelay(10);
178 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
179 MCFPGA_RESET_N);
180 }
181
182 if (hw_type_cat) {
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500183 int retval;
184 struct mii_dev *mdiodev = mdio_alloc();
Mario Six3809c472019-03-29 10:18:06 +0100185
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500186 if (!mdiodev)
187 return -ENOMEM;
188 strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
189 mdiodev->read = bb_miiphy_read;
190 mdiodev->write = bb_miiphy_write;
191
192 retval = mdio_register(mdiodev);
193 if (retval < 0)
194 return retval;
Dirk Eibachb355f172015-10-28 11:46:32 +0100195 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
196 if ((mux_ch == 1) && !ch0_sgmii2_present)
197 continue;
198
199 setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
200 }
201 }
202
203 /* give slave-PLLs and Parade DP501 some time to be up and running */
Mario Six3809c472019-03-29 10:18:06 +0100204 mdelay(500);
Dirk Eibachb355f172015-10-28 11:46:32 +0100205
206 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
207 slaves = mclink_probe();
208 mclink_fpgacount = 0;
209
210 ioep_fpga_print_info(0);
211
212 if (!adv7611_probe(0))
213 printf(" Advantiv ADV7611 HDMI Receiver\n");
214
215#ifdef CONFIG_STRIDER_CON
216 if (ioep_fpga_has_osd(0))
217 osd_probe(0);
218#endif
219
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200220#ifdef CONFIG_STRIDER_CON_DP
221 if (ioep_fpga_has_osd(0)) {
222 osd_probe(0);
223 if (is_dh)
224 osd_probe(4);
225 }
226#endif
227
Dirk Eibachb355f172015-10-28 11:46:32 +0100228#ifdef CONFIG_STRIDER_CPU
229 ch7301_probe(0, false);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100230 dp501_probe(0, false);
Dirk Eibachb355f172015-10-28 11:46:32 +0100231#endif
232
233 if (slaves <= 0)
234 return 0;
235
236 mclink_fpgacount = slaves;
237
Dirk Eibache9539ed2016-03-16 09:20:11 +0100238#ifdef CONFIG_STRIDER_CPU
239 /* get ADV7611 out of reset, power up DP501, give some time to wakeup */
240 for (k = 1; k <= slaves; ++k)
241 FPGA_SET_REG(k, extended_control, 0x10); /* enable video */
242
Mario Six3809c472019-03-29 10:18:06 +0100243 mdelay(500);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100244#endif
245
Dirk Eibachb355f172015-10-28 11:46:32 +0100246 for (k = 1; k <= slaves; ++k) {
247 ioep_fpga_print_info(k);
248#ifdef CONFIG_STRIDER_CON
249 if (ioep_fpga_has_osd(k))
250 osd_probe(k);
251#endif
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200252#ifdef CONFIG_STRIDER_CON_DP
253 if (ioep_fpga_has_osd(k)) {
254 osd_probe(k);
255 if (is_dh)
256 osd_probe(k + 4);
257 }
258#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100259#ifdef CONFIG_STRIDER_CPU
Dirk Eibachb355f172015-10-28 11:46:32 +0100260 if (!adv7611_probe(k))
261 printf(" Advantiv ADV7611 HDMI Receiver\n");
262 ch7301_probe(k, false);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100263 dp501_probe(k, false);
Dirk Eibachb355f172015-10-28 11:46:32 +0100264#endif
265 if (hw_type_cat) {
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500266 int retval;
267 struct mii_dev *mdiodev = mdio_alloc();
Mario Six3809c472019-03-29 10:18:06 +0100268
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500269 if (!mdiodev)
270 return -ENOMEM;
271 strncpy(mdiodev->name, bb_miiphy_buses[k].name,
272 MDIO_NAME_LEN);
273 mdiodev->read = bb_miiphy_read;
274 mdiodev->write = bb_miiphy_write;
275
276 retval = mdio_register(mdiodev);
277 if (retval < 0)
278 return retval;
Dirk Eibachb355f172015-10-28 11:46:32 +0100279 setup_88e1514(bb_miiphy_buses[k].name, 0);
280 }
281 }
282
283 for (k = 0; k < ARRAY_SIZE(strider_fans); ++k) {
284 i2c_set_bus_num(strider_fans[k].bus);
285 init_fan_controller(strider_fans[k].addr);
286 }
287
288 return 0;
289}
290
291/*
292 * provide access to fpga gpios (for I2C bitbang)
293 * (these may look all too simple but make iocon.h much more readable)
294 */
Mario Six3809c472019-03-29 10:18:06 +0100295void fpga_gpio_set(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100296{
297 FPGA_SET_REG(bus, gpio.set, pin);
298}
299
Mario Six3809c472019-03-29 10:18:06 +0100300void fpga_gpio_clear(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100301{
302 FPGA_SET_REG(bus, gpio.clear, pin);
303}
304
Mario Six3809c472019-03-29 10:18:06 +0100305int fpga_gpio_get(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100306{
307 u16 val;
308
309 FPGA_GET_REG(bus, gpio.read, &val);
310
311 return val & pin;
312}
313
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200314#ifdef CONFIG_STRIDER_CON_DP
Mario Six3809c472019-03-29 10:18:06 +0100315void fpga_control_set(uint bus, int pin)
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200316{
317 u16 val;
318
319 FPGA_GET_REG(bus, control, &val);
320 FPGA_SET_REG(bus, control, val | pin);
321}
322
Mario Six3809c472019-03-29 10:18:06 +0100323void fpga_control_clear(uint bus, int pin)
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200324{
325 u16 val;
326
327 FPGA_GET_REG(bus, control, &val);
328 FPGA_SET_REG(bus, control, val & ~pin);
329}
330#endif
331
Dirk Eibachb355f172015-10-28 11:46:32 +0100332void mpc8308_init(void)
333{
334 pca9698_direction_output(0x20, 26, 1);
335}
336
Mario Six3809c472019-03-29 10:18:06 +0100337void mpc8308_set_fpga_reset(uint state)
Dirk Eibachb355f172015-10-28 11:46:32 +0100338{
339 pca9698_set_value(0x20, 26, state ? 0 : 1);
340}
341
342void mpc8308_setup_hw(void)
343{
344 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
345
346 /*
347 * set "startup-finished"-gpios
348 */
Mario Six3809c472019-03-29 10:18:06 +0100349 setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12));
Mario Sixae0feaa2019-03-29 10:18:07 +0100350 setbits_gpio0_out(BIT(31 - 12));
Dirk Eibachb355f172015-10-28 11:46:32 +0100351}
352
Mario Six3809c472019-03-29 10:18:06 +0100353int mpc8308_get_fpga_done(uint fpga)
Dirk Eibachb355f172015-10-28 11:46:32 +0100354{
355 return pca9698_get_value(0x20, 20);
356}
357
358#ifdef CONFIG_FSL_ESDHC
359int board_mmc_init(bd_t *bd)
360{
361 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
362 sysconf83xx_t *sysconf = &immr->sysconf;
363
364 /* Enable cache snooping in eSDHC system configuration register */
365 out_be32(&sysconf->sdhccr, 0x02000000);
366
367 return fsl_esdhc_mmc_init(bd);
368}
369#endif
370
371static struct pci_region pcie_regions_0[] = {
372 {
373 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
374 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
375 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
376 .flags = PCI_REGION_MEM,
377 },
378 {
379 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
380 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
381 .size = CONFIG_SYS_PCIE1_IO_SIZE,
382 .flags = PCI_REGION_IO,
383 },
384};
385
386void pci_init_board(void)
387{
388 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
389 sysconf83xx_t *sysconf = &immr->sysconf;
390 law83xx_t *pcie_law = sysconf->pcielaw;
391 struct pci_region *pcie_reg[] = { pcie_regions_0 };
392
393 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
394 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
395
396 /* Deassert the resets in the control register */
397 out_be32(&sysconf->pecr1, 0xE0008000);
398 udelay(2000);
399
400 /* Configure PCI Express Local Access Windows */
401 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
402 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
403
404 mpc83xx_pcie_init(1, pcie_reg);
405}
406
407ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
408{
409 info->portwidth = FLASH_CFI_16BIT;
410 info->chipwidth = FLASH_CFI_BY16;
411 info->interface = FLASH_CFI_X16;
412 return 1;
413}
414
415#if defined(CONFIG_OF_BOARD_SETUP)
416int ft_board_setup(void *blob, bd_t *bd)
417{
418 ft_cpu_setup(blob, bd);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530419 fsl_fdt_fixup_dr_usb(blob, bd);
Dirk Eibachb355f172015-10-28 11:46:32 +0100420 fdt_fixup_esdhc(blob, bd);
421
422 return 0;
423}
424#endif
425
426/*
427 * FPGA MII bitbang implementation
428 */
429
430struct fpga_mii {
Mario Six3809c472019-03-29 10:18:06 +0100431 uint fpga;
Dirk Eibachb355f172015-10-28 11:46:32 +0100432 int mdio;
433} fpga_mii[] = {
434 { 0, 1},
435 { 1, 1},
436 { 2, 1},
437 { 3, 1},
438};
439
440static int mii_dummy_init(struct bb_miiphy_bus *bus)
441{
442 return 0;
443}
444
445static int mii_mdio_active(struct bb_miiphy_bus *bus)
446{
447 struct fpga_mii *fpga_mii = bus->priv;
448
449 if (fpga_mii->mdio)
450 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
451 else
452 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
453
454 return 0;
455}
456
457static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
458{
459 struct fpga_mii *fpga_mii = bus->priv;
460
461 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
462
463 return 0;
464}
465
466static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
467{
468 struct fpga_mii *fpga_mii = bus->priv;
469
470 if (v)
471 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
472 else
473 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
474
475 fpga_mii->mdio = v;
476
477 return 0;
478}
479
480static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
481{
482 u16 gpio;
483 struct fpga_mii *fpga_mii = bus->priv;
484
485 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
486
487 *v = ((gpio & GPIO_MDIO) != 0);
488
489 return 0;
490}
491
492static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
493{
494 struct fpga_mii *fpga_mii = bus->priv;
495
496 if (v)
497 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
498 else
499 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
500
501 return 0;
502}
503
504static int mii_delay(struct bb_miiphy_bus *bus)
505{
506 udelay(1);
507
508 return 0;
509}
510
511struct bb_miiphy_bus bb_miiphy_buses[] = {
512 {
513 .name = "board0",
514 .init = mii_dummy_init,
515 .mdio_active = mii_mdio_active,
516 .mdio_tristate = mii_mdio_tristate,
517 .set_mdio = mii_set_mdio,
518 .get_mdio = mii_get_mdio,
519 .set_mdc = mii_set_mdc,
520 .delay = mii_delay,
521 .priv = &fpga_mii[0],
522 },
523 {
524 .name = "board1",
525 .init = mii_dummy_init,
526 .mdio_active = mii_mdio_active,
527 .mdio_tristate = mii_mdio_tristate,
528 .set_mdio = mii_set_mdio,
529 .get_mdio = mii_get_mdio,
530 .set_mdc = mii_set_mdc,
531 .delay = mii_delay,
532 .priv = &fpga_mii[1],
533 },
534 {
535 .name = "board2",
536 .init = mii_dummy_init,
537 .mdio_active = mii_mdio_active,
538 .mdio_tristate = mii_mdio_tristate,
539 .set_mdio = mii_set_mdio,
540 .get_mdio = mii_get_mdio,
541 .set_mdc = mii_set_mdc,
542 .delay = mii_delay,
543 .priv = &fpga_mii[2],
544 },
545 {
546 .name = "board3",
547 .init = mii_dummy_init,
548 .mdio_active = mii_mdio_active,
549 .mdio_tristate = mii_mdio_tristate,
550 .set_mdio = mii_set_mdio,
551 .get_mdio = mii_get_mdio,
552 .set_mdc = mii_set_mdc,
553 .delay = mii_delay,
554 .priv = &fpga_mii[3],
555 },
556};
557
Mario Six3809c472019-03-29 10:18:06 +0100558int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);