blob: 91fec74fb0328d543ad162048bacbc92950139e4 [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 Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090016#include <linux/libfdt.h>
Dirk Eibachb355f172015-10-28 11:46:32 +010017#include <fdt_support.h>
18#include <pci.h>
19#include <mpc83xx.h>
20#include <fsl_esdhc.h>
21#include <asm/io.h>
22#include <asm/fsl_serdes.h>
23#include <asm/fsl_mpc83xx_serdes.h>
24
25#include "mpc8308.h"
26
27#include <gdsys_fpga.h>
28
29#include "../common/adv7611.h"
30#include "../common/ch7301.h"
Dirk Eibache9539ed2016-03-16 09:20:11 +010031#include "../common/dp501.h"
Dirk Eibachb355f172015-10-28 11:46:32 +010032#include "../common/ioep-fpga.h"
33#include "../common/mclink.h"
34#include "../common/osd.h"
35#include "../common/phy.h"
Dirk Eibach94594332015-10-28 11:46:36 +010036#include "../common/fanctrl.h"
Dirk Eibachb355f172015-10-28 11:46:32 +010037
38#include <pca953x.h>
39#include <pca9698.h>
40
41#include <miiphy.h>
42
Dirk Eibachb355f172015-10-28 11:46:32 +010043#define MAX_MUX_CHANNELS 2
44
45enum {
46 MCFPGA_DONE = 1 << 0,
47 MCFPGA_INIT_N = 1 << 1,
48 MCFPGA_PROGRAM_N = 1 << 2,
49 MCFPGA_UPDATE_ENABLE_N = 1 << 3,
50 MCFPGA_RESET_N = 1 << 4,
51};
52
53enum {
54 GPIO_MDC = 1 << 14,
55 GPIO_MDIO = 1 << 15,
56};
57
Mario Six3809c472019-03-29 10:18:06 +010058uint mclink_fpgacount;
Dirk Eibachb355f172015-10-28 11:46:32 +010059struct ihs_fpga *fpga_ptr[] = CONFIG_SYS_FPGA_PTR;
60
61struct {
62 u8 bus;
63 u8 addr;
64} strider_fans[] = CONFIG_STRIDER_FANS;
65
66int fpga_set_reg(u32 fpga, u16 *reg, off_t regoff, u16 data)
67{
68 int res;
69
70 switch (fpga) {
71 case 0:
72 out_le16(reg, data);
73 break;
74 default:
75 res = mclink_send(fpga - 1, regoff, data);
76 if (res < 0) {
77 printf("mclink_send reg %02lx data %04x returned %d\n",
78 regoff, data, res);
79 return res;
80 }
81 break;
82 }
83
84 return 0;
85}
86
87int fpga_get_reg(u32 fpga, u16 *reg, off_t regoff, u16 *data)
88{
89 int res;
90
91 switch (fpga) {
92 case 0:
93 *data = in_le16(reg);
94 break;
95 default:
96 if (fpga > mclink_fpgacount)
97 return -EINVAL;
98 res = mclink_receive(fpga - 1, regoff, data);
99 if (res < 0) {
100 printf("mclink_receive reg %02lx returned %d\n",
101 regoff, res);
102 return res;
103 }
104 }
105
106 return 0;
107}
108
109int checkboard(void)
110{
Simon Glass64b723f2017-08-03 12:22:12 -0600111 char *s = env_get("serial#");
Dirk Eibachb355f172015-10-28 11:46:32 +0100112 bool hw_type_cat = pca9698_get_value(0x20, 18);
113
114 puts("Board: ");
115
116 printf("Strider %s", hw_type_cat ? "CAT" : "Fiber");
117
Mario Six3809c472019-03-29 10:18:06 +0100118 if (s) {
Dirk Eibachb355f172015-10-28 11:46:32 +0100119 puts(", serial# ");
120 puts(s);
121 }
122
123 puts("\n");
124
125 return 0;
126}
127
Dirk Eibachb355f172015-10-28 11:46:32 +0100128int last_stage_init(void)
129{
130 int slaves;
Mario Six3809c472019-03-29 10:18:06 +0100131 uint k;
132 uint mux_ch;
133 uchar mclink_controllers_dvi[] = { 0x3c, 0x3d, 0x3e };
Dirk Eibache9539ed2016-03-16 09:20:11 +0100134#ifdef CONFIG_STRIDER_CPU
Mario Six3809c472019-03-29 10:18:06 +0100135 uchar mclink_controllers_dp[] = { 0x24, 0x25, 0x26 };
Dirk Eibache9539ed2016-03-16 09:20:11 +0100136#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100137 bool hw_type_cat = pca9698_get_value(0x20, 18);
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200138#ifdef CONFIG_STRIDER_CON_DP
139 bool is_dh = pca9698_get_value(0x20, 25);
140#endif
Mario Six3809c472019-03-29 10:18:06 +0100141 bool ch0_sgmii2_present;
Dirk Eibachb355f172015-10-28 11:46:32 +0100142
143 /* Turn on Analog Devices ADV7611 */
144 pca9698_direction_output(0x20, 8, 0);
145
146 /* Turn on Parade DP501 */
Dirk Eibache9539ed2016-03-16 09:20:11 +0100147 pca9698_direction_output(0x20, 10, 1);
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200148 pca9698_direction_output(0x20, 11, 1);
Dirk Eibachb355f172015-10-28 11:46:32 +0100149
150 ch0_sgmii2_present = !pca9698_get_value(0x20, 37);
151
152 /* wait for FPGA done, then reset FPGA */
Dirk Eibache9539ed2016-03-16 09:20:11 +0100153 for (k = 0; k < ARRAY_SIZE(mclink_controllers_dvi); ++k) {
Mario Six3809c472019-03-29 10:18:06 +0100154 uint ctr = 0;
155 uchar *mclink_controllers = mclink_controllers_dvi;
Dirk Eibachb355f172015-10-28 11:46:32 +0100156
Dirk Eibache9539ed2016-03-16 09:20:11 +0100157#ifdef CONFIG_STRIDER_CPU
158 if (i2c_probe(mclink_controllers[k])) {
159 mclink_controllers = mclink_controllers_dp;
160 if (i2c_probe(mclink_controllers[k]))
161 continue;
162 }
163#else
Dirk Eibachb355f172015-10-28 11:46:32 +0100164 if (i2c_probe(mclink_controllers[k]))
165 continue;
Dirk Eibache9539ed2016-03-16 09:20:11 +0100166#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100167 while (!(pca953x_get_val(mclink_controllers[k])
168 & MCFPGA_DONE)) {
Mario Six3809c472019-03-29 10:18:06 +0100169 mdelay(100);
Dirk Eibachb355f172015-10-28 11:46:32 +0100170 if (ctr++ > 5) {
171 printf("no done for mclink_controller %d\n", k);
172 break;
173 }
174 }
175
176 pca953x_set_dir(mclink_controllers[k], MCFPGA_RESET_N, 0);
177 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N, 0);
178 udelay(10);
179 pca953x_set_val(mclink_controllers[k], MCFPGA_RESET_N,
180 MCFPGA_RESET_N);
181 }
182
183 if (hw_type_cat) {
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500184 int retval;
185 struct mii_dev *mdiodev = mdio_alloc();
Mario Six3809c472019-03-29 10:18:06 +0100186
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500187 if (!mdiodev)
188 return -ENOMEM;
189 strncpy(mdiodev->name, bb_miiphy_buses[0].name, MDIO_NAME_LEN);
190 mdiodev->read = bb_miiphy_read;
191 mdiodev->write = bb_miiphy_write;
192
193 retval = mdio_register(mdiodev);
194 if (retval < 0)
195 return retval;
Dirk Eibachb355f172015-10-28 11:46:32 +0100196 for (mux_ch = 0; mux_ch < MAX_MUX_CHANNELS; ++mux_ch) {
197 if ((mux_ch == 1) && !ch0_sgmii2_present)
198 continue;
199
200 setup_88e1514(bb_miiphy_buses[0].name, mux_ch);
201 }
202 }
203
204 /* give slave-PLLs and Parade DP501 some time to be up and running */
Mario Six3809c472019-03-29 10:18:06 +0100205 mdelay(500);
Dirk Eibachb355f172015-10-28 11:46:32 +0100206
207 mclink_fpgacount = CONFIG_SYS_MCLINK_MAX;
208 slaves = mclink_probe();
209 mclink_fpgacount = 0;
210
211 ioep_fpga_print_info(0);
212
213 if (!adv7611_probe(0))
214 printf(" Advantiv ADV7611 HDMI Receiver\n");
215
216#ifdef CONFIG_STRIDER_CON
217 if (ioep_fpga_has_osd(0))
218 osd_probe(0);
219#endif
220
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200221#ifdef CONFIG_STRIDER_CON_DP
222 if (ioep_fpga_has_osd(0)) {
223 osd_probe(0);
224 if (is_dh)
225 osd_probe(4);
226 }
227#endif
228
Dirk Eibachb355f172015-10-28 11:46:32 +0100229#ifdef CONFIG_STRIDER_CPU
230 ch7301_probe(0, false);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100231 dp501_probe(0, false);
Dirk Eibachb355f172015-10-28 11:46:32 +0100232#endif
233
234 if (slaves <= 0)
235 return 0;
236
237 mclink_fpgacount = slaves;
238
Dirk Eibache9539ed2016-03-16 09:20:11 +0100239#ifdef CONFIG_STRIDER_CPU
240 /* get ADV7611 out of reset, power up DP501, give some time to wakeup */
241 for (k = 1; k <= slaves; ++k)
242 FPGA_SET_REG(k, extended_control, 0x10); /* enable video */
243
Mario Six3809c472019-03-29 10:18:06 +0100244 mdelay(500);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100245#endif
246
Dirk Eibachb355f172015-10-28 11:46:32 +0100247 for (k = 1; k <= slaves; ++k) {
248 ioep_fpga_print_info(k);
249#ifdef CONFIG_STRIDER_CON
250 if (ioep_fpga_has_osd(k))
251 osd_probe(k);
252#endif
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200253#ifdef CONFIG_STRIDER_CON_DP
254 if (ioep_fpga_has_osd(k)) {
255 osd_probe(k);
256 if (is_dh)
257 osd_probe(k + 4);
258 }
259#endif
Dirk Eibachb355f172015-10-28 11:46:32 +0100260#ifdef CONFIG_STRIDER_CPU
Dirk Eibachb355f172015-10-28 11:46:32 +0100261 if (!adv7611_probe(k))
262 printf(" Advantiv ADV7611 HDMI Receiver\n");
263 ch7301_probe(k, false);
Dirk Eibache9539ed2016-03-16 09:20:11 +0100264 dp501_probe(k, false);
Dirk Eibachb355f172015-10-28 11:46:32 +0100265#endif
266 if (hw_type_cat) {
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500267 int retval;
268 struct mii_dev *mdiodev = mdio_alloc();
Mario Six3809c472019-03-29 10:18:06 +0100269
Joe Hershberger1fbcbed2016-08-08 11:28:38 -0500270 if (!mdiodev)
271 return -ENOMEM;
272 strncpy(mdiodev->name, bb_miiphy_buses[k].name,
273 MDIO_NAME_LEN);
274 mdiodev->read = bb_miiphy_read;
275 mdiodev->write = bb_miiphy_write;
276
277 retval = mdio_register(mdiodev);
278 if (retval < 0)
279 return retval;
Dirk Eibachb355f172015-10-28 11:46:32 +0100280 setup_88e1514(bb_miiphy_buses[k].name, 0);
281 }
282 }
283
284 for (k = 0; k < ARRAY_SIZE(strider_fans); ++k) {
285 i2c_set_bus_num(strider_fans[k].bus);
286 init_fan_controller(strider_fans[k].addr);
287 }
288
289 return 0;
290}
291
292/*
293 * provide access to fpga gpios (for I2C bitbang)
294 * (these may look all too simple but make iocon.h much more readable)
295 */
Mario Six3809c472019-03-29 10:18:06 +0100296void fpga_gpio_set(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100297{
298 FPGA_SET_REG(bus, gpio.set, pin);
299}
300
Mario Six3809c472019-03-29 10:18:06 +0100301void fpga_gpio_clear(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100302{
303 FPGA_SET_REG(bus, gpio.clear, pin);
304}
305
Mario Six3809c472019-03-29 10:18:06 +0100306int fpga_gpio_get(uint bus, int pin)
Dirk Eibachb355f172015-10-28 11:46:32 +0100307{
308 u16 val;
309
310 FPGA_GET_REG(bus, gpio.read, &val);
311
312 return val & pin;
313}
314
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200315#ifdef CONFIG_STRIDER_CON_DP
Mario Six3809c472019-03-29 10:18:06 +0100316void fpga_control_set(uint bus, int pin)
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200317{
318 u16 val;
319
320 FPGA_GET_REG(bus, control, &val);
321 FPGA_SET_REG(bus, control, val | pin);
322}
323
Mario Six3809c472019-03-29 10:18:06 +0100324void fpga_control_clear(uint bus, int pin)
Dirk Eibach3c6a5092016-06-02 09:05:41 +0200325{
326 u16 val;
327
328 FPGA_GET_REG(bus, control, &val);
329 FPGA_SET_REG(bus, control, val & ~pin);
330}
331#endif
332
Dirk Eibachb355f172015-10-28 11:46:32 +0100333void mpc8308_init(void)
334{
335 pca9698_direction_output(0x20, 26, 1);
336}
337
Mario Six3809c472019-03-29 10:18:06 +0100338void mpc8308_set_fpga_reset(uint state)
Dirk Eibachb355f172015-10-28 11:46:32 +0100339{
340 pca9698_set_value(0x20, 26, state ? 0 : 1);
341}
342
343void mpc8308_setup_hw(void)
344{
345 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
346
347 /*
348 * set "startup-finished"-gpios
349 */
Mario Six3809c472019-03-29 10:18:06 +0100350 setbits_be32(&immr->gpio[0].dir, BIT(31 - 11) | BIT(31 - 12));
Mario Sixae0feaa2019-03-29 10:18:07 +0100351 setbits_gpio0_out(BIT(31 - 12));
Dirk Eibachb355f172015-10-28 11:46:32 +0100352}
353
Mario Six3809c472019-03-29 10:18:06 +0100354int mpc8308_get_fpga_done(uint fpga)
Dirk Eibachb355f172015-10-28 11:46:32 +0100355{
356 return pca9698_get_value(0x20, 20);
357}
358
359#ifdef CONFIG_FSL_ESDHC
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900360int board_mmc_init(struct bd_info *bd)
Dirk Eibachb355f172015-10-28 11:46:32 +0100361{
362 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
363 sysconf83xx_t *sysconf = &immr->sysconf;
364
365 /* Enable cache snooping in eSDHC system configuration register */
366 out_be32(&sysconf->sdhccr, 0x02000000);
367
368 return fsl_esdhc_mmc_init(bd);
369}
370#endif
371
372static struct pci_region pcie_regions_0[] = {
373 {
374 .bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
375 .phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
376 .size = CONFIG_SYS_PCIE1_MEM_SIZE,
377 .flags = PCI_REGION_MEM,
378 },
379 {
380 .bus_start = CONFIG_SYS_PCIE1_IO_BASE,
381 .phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
382 .size = CONFIG_SYS_PCIE1_IO_SIZE,
383 .flags = PCI_REGION_IO,
384 },
385};
386
387void pci_init_board(void)
388{
389 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
390 sysconf83xx_t *sysconf = &immr->sysconf;
391 law83xx_t *pcie_law = sysconf->pcielaw;
392 struct pci_region *pcie_reg[] = { pcie_regions_0 };
393
394 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
395 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
396
397 /* Deassert the resets in the control register */
398 out_be32(&sysconf->pecr1, 0xE0008000);
399 udelay(2000);
400
401 /* Configure PCI Express Local Access Windows */
402 out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
403 out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
404
405 mpc83xx_pcie_init(1, pcie_reg);
406}
407
408ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
409{
410 info->portwidth = FLASH_CFI_16BIT;
411 info->chipwidth = FLASH_CFI_BY16;
412 info->interface = FLASH_CFI_X16;
413 return 1;
414}
415
416#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900417int ft_board_setup(void *blob, struct bd_info *bd)
Dirk Eibachb355f172015-10-28 11:46:32 +0100418{
419 ft_cpu_setup(blob, bd);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530420 fsl_fdt_fixup_dr_usb(blob, bd);
Dirk Eibachb355f172015-10-28 11:46:32 +0100421 fdt_fixup_esdhc(blob, bd);
422
423 return 0;
424}
425#endif
426
427/*
428 * FPGA MII bitbang implementation
429 */
430
431struct fpga_mii {
Mario Six3809c472019-03-29 10:18:06 +0100432 uint fpga;
Dirk Eibachb355f172015-10-28 11:46:32 +0100433 int mdio;
434} fpga_mii[] = {
435 { 0, 1},
436 { 1, 1},
437 { 2, 1},
438 { 3, 1},
439};
440
441static int mii_dummy_init(struct bb_miiphy_bus *bus)
442{
443 return 0;
444}
445
446static int mii_mdio_active(struct bb_miiphy_bus *bus)
447{
448 struct fpga_mii *fpga_mii = bus->priv;
449
450 if (fpga_mii->mdio)
451 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
452 else
453 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
454
455 return 0;
456}
457
458static int mii_mdio_tristate(struct bb_miiphy_bus *bus)
459{
460 struct fpga_mii *fpga_mii = bus->priv;
461
462 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
463
464 return 0;
465}
466
467static int mii_set_mdio(struct bb_miiphy_bus *bus, int v)
468{
469 struct fpga_mii *fpga_mii = bus->priv;
470
471 if (v)
472 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDIO);
473 else
474 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDIO);
475
476 fpga_mii->mdio = v;
477
478 return 0;
479}
480
481static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v)
482{
483 u16 gpio;
484 struct fpga_mii *fpga_mii = bus->priv;
485
486 FPGA_GET_REG(fpga_mii->fpga, gpio.read, &gpio);
487
488 *v = ((gpio & GPIO_MDIO) != 0);
489
490 return 0;
491}
492
493static int mii_set_mdc(struct bb_miiphy_bus *bus, int v)
494{
495 struct fpga_mii *fpga_mii = bus->priv;
496
497 if (v)
498 FPGA_SET_REG(fpga_mii->fpga, gpio.set, GPIO_MDC);
499 else
500 FPGA_SET_REG(fpga_mii->fpga, gpio.clear, GPIO_MDC);
501
502 return 0;
503}
504
505static int mii_delay(struct bb_miiphy_bus *bus)
506{
507 udelay(1);
508
509 return 0;
510}
511
512struct bb_miiphy_bus bb_miiphy_buses[] = {
513 {
514 .name = "board0",
515 .init = mii_dummy_init,
516 .mdio_active = mii_mdio_active,
517 .mdio_tristate = mii_mdio_tristate,
518 .set_mdio = mii_set_mdio,
519 .get_mdio = mii_get_mdio,
520 .set_mdc = mii_set_mdc,
521 .delay = mii_delay,
522 .priv = &fpga_mii[0],
523 },
524 {
525 .name = "board1",
526 .init = mii_dummy_init,
527 .mdio_active = mii_mdio_active,
528 .mdio_tristate = mii_mdio_tristate,
529 .set_mdio = mii_set_mdio,
530 .get_mdio = mii_get_mdio,
531 .set_mdc = mii_set_mdc,
532 .delay = mii_delay,
533 .priv = &fpga_mii[1],
534 },
535 {
536 .name = "board2",
537 .init = mii_dummy_init,
538 .mdio_active = mii_mdio_active,
539 .mdio_tristate = mii_mdio_tristate,
540 .set_mdio = mii_set_mdio,
541 .get_mdio = mii_get_mdio,
542 .set_mdc = mii_set_mdc,
543 .delay = mii_delay,
544 .priv = &fpga_mii[2],
545 },
546 {
547 .name = "board3",
548 .init = mii_dummy_init,
549 .mdio_active = mii_mdio_active,
550 .mdio_tristate = mii_mdio_tristate,
551 .set_mdio = mii_set_mdio,
552 .get_mdio = mii_get_mdio,
553 .set_mdc = mii_set_mdc,
554 .delay = mii_delay,
555 .priv = &fpga_mii[3],
556 },
557};
558
Mario Six3809c472019-03-29 10:18:06 +0100559int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);