blob: 965a8ce98b6d7814a7e3d1fdd041fbade08b6713 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Valentin Longchampc98bf292013-10-18 11:47:24 +02002/*
3 * (C) Copyright 2013 Keymile AG
4 * Valentin Longchamp <valentin.longchamp@keymile.com>
5 *
6 * Copyright 2007-2011 Freescale Semiconductor, Inc.
Valentin Longchampc98bf292013-10-18 11:47:24 +02007 */
8
9#include <common.h>
10#include <command.h>
11#include <pci.h>
12#include <asm/fsl_pci.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Valentin Longchampc98bf292013-10-18 11:47:24 +020014#include <fdt_support.h>
15#include <asm/fsl_serdes.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090016#include <linux/errno.h>
Valentin Longchampc98bf292013-10-18 11:47:24 +020017
18#include "kmp204x.h"
19
Valentin Longchampdc146da2014-01-27 11:49:12 +010020#define PROM_SEL_L 11
21/* control the PROM_SEL_L signal*/
22static void toggle_fpga_eeprom_bus(bool cpu_own)
23{
24 qrio_gpio_direction_output(GPIO_A, PROM_SEL_L, !cpu_own);
25}
26
27#define CONF_SEL_L 10
28#define FPGA_PROG_L 19
29#define FPGA_DONE 18
30#define FPGA_INIT_L 17
31
32int trigger_fpga_config(void)
33{
34 int ret = 0, init_l;
35 /* approx 10ms */
36 u32 timeout = 10000;
37
38 /* make sure the FPGA_can access the EEPROM */
39 toggle_fpga_eeprom_bus(false);
40
41 /* assert CONF_SEL_L to be able to drive FPGA_PROG_L */
42 qrio_gpio_direction_output(GPIO_A, CONF_SEL_L, 0);
43
44 /* trigger the config start */
45 qrio_gpio_direction_output(GPIO_A, FPGA_PROG_L, 0);
46
47 /* small delay for INIT_L line */
48 udelay(10);
49
50 /* wait for FPGA_INIT to be asserted */
51 do {
52 init_l = qrio_get_gpio(GPIO_A, FPGA_INIT_L);
53 if (timeout-- == 0) {
54 printf("FPGA_INIT timeout\n");
55 ret = -EFAULT;
56 break;
57 }
58 udelay(10);
59 } while (init_l);
60
61 /* deassert FPGA_PROG, config should start */
62 qrio_set_gpio(GPIO_A, FPGA_PROG_L, 1);
63
64 return ret;
65}
66
67/* poll the FPGA_DONE signal and give the EEPROM back to the QorIQ */
68static int wait_for_fpga_config(void)
69{
70 int ret = 0, done;
71 /* approx 5 s */
72 u32 timeout = 500000;
73
74 printf("PCIe FPGA config:");
75 do {
76 done = qrio_get_gpio(GPIO_A, FPGA_DONE);
77 if (timeout-- == 0) {
78 printf(" FPGA_DONE timeout\n");
79 ret = -EFAULT;
80 goto err_out;
81 }
82 udelay(10);
83 } while (!done);
84
85 printf(" done\n");
86
87err_out:
88 /* deactive CONF_SEL and give the CPU conf EEPROM access */
89 qrio_set_gpio(GPIO_A, CONF_SEL_L, 1);
90 toggle_fpga_eeprom_bus(true);
91
92 return ret;
93}
94
Valentin Longchampc98bf292013-10-18 11:47:24 +020095#define PCIE_SW_RST 14
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +020096#define PEXHC_RST 13
97#define HOOPER_RST 12
Valentin Longchampc98bf292013-10-18 11:47:24 +020098
99void pci_init_board(void)
100{
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200101 qrio_prstcfg(PCIE_SW_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
102 qrio_prstcfg(PEXHC_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
103 qrio_prstcfg(HOOPER_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
104
105 /* wait for the PCIe FPGA to be configured
Valentin Longchampdc146da2014-01-27 11:49:12 +0100106 * it has been triggered earlier in board_early_init_r */
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200107 if (wait_for_fpga_config())
Valentin Longchampdc146da2014-01-27 11:49:12 +0100108 printf("error finishing PCIe FPGA config\n");
109
Valentin Longchampc98bf292013-10-18 11:47:24 +0200110 qrio_prst(PCIE_SW_RST, false, false);
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200111 qrio_prst(PEXHC_RST, false, false);
112 qrio_prst(HOOPER_RST, false, false);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200113 /* Hooper is not direcly PCIe capable */
114 mdelay(50);
Valentin Longchampdc146da2014-01-27 11:49:12 +0100115
Valentin Longchampc98bf292013-10-18 11:47:24 +0200116 fsl_pcie_init_board(0);
117}
118
119void pci_of_setup(void *blob, bd_t *bd)
120{
121 FT_FSL_PCI_SETUP;
122}