pci.c 2.7 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0+
2 3 4 5 6 7 8 9 10
/*
 * (C) Copyright 2013 Keymile AG
 * Valentin Longchamp <valentin.longchamp@keymile.com>
 *
 * Copyright 2007-2011 Freescale Semiconductor, Inc.
 */

#include <common.h>
#include <command.h>
11
#include <init.h>
12 13
#include <pci.h>
#include <asm/fsl_pci.h>
14
#include <linux/delay.h>
15
#include <linux/libfdt.h>
16 17
#include <fdt_support.h>
#include <asm/fsl_serdes.h>
18
#include <linux/errno.h>
19

20
#include "../common/qrio.h"
21 22
#include "kmp204x.h"

23 24 25 26
#define PROM_SEL_L	11
/* control the PROM_SEL_L signal*/
static void toggle_fpga_eeprom_bus(bool cpu_own)
{
27
	qrio_gpio_direction_output(QRIO_GPIO_A, PROM_SEL_L, !cpu_own);
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
}

#define CONF_SEL_L	10
#define FPGA_PROG_L	19
#define FPGA_DONE	18
#define FPGA_INIT_L	17

int trigger_fpga_config(void)
{
	int ret = 0, init_l;
	/* approx 10ms */
	u32 timeout = 10000;

	/* make sure the FPGA_can access the EEPROM */
	toggle_fpga_eeprom_bus(false);

	/* assert CONF_SEL_L to be able to drive FPGA_PROG_L */
45
	qrio_gpio_direction_output(QRIO_GPIO_A, CONF_SEL_L, 0);
46 47

	/* trigger the config start */
48
	qrio_gpio_direction_output(QRIO_GPIO_A, FPGA_PROG_L, 0);
49 50 51 52 53 54

	/* small delay for INIT_L line */
	udelay(10);

	/* wait for FPGA_INIT to be asserted */
	do {
55
		init_l = qrio_get_gpio(QRIO_GPIO_A, FPGA_INIT_L);
56 57 58 59 60 61 62 63 64
		if (timeout-- == 0) {
			printf("FPGA_INIT timeout\n");
			ret = -EFAULT;
			break;
		}
		udelay(10);
	} while (init_l);

	/* deassert FPGA_PROG, config should start */
65
	qrio_set_gpio(QRIO_GPIO_A, FPGA_PROG_L, 1);
66 67 68 69 70 71 72 73 74 75 76 77 78

	return ret;
}

/* poll the FPGA_DONE signal and give the EEPROM back to the QorIQ */
static int wait_for_fpga_config(void)
{
	int ret = 0, done;
	/* approx 5 s */
	u32 timeout = 500000;

	printf("PCIe FPGA config:");
	do {
79
		done = qrio_get_gpio(QRIO_GPIO_A, FPGA_DONE);
80 81 82 83 84 85 86 87 88 89 90 91
		if (timeout-- == 0) {
			printf(" FPGA_DONE timeout\n");
			ret = -EFAULT;
			goto err_out;
		}
		udelay(10);
	} while (!done);

	printf(" done\n");

err_out:
	/* deactive CONF_SEL and give the CPU conf EEPROM access */
92
	qrio_set_gpio(QRIO_GPIO_A, CONF_SEL_L, 1);
93 94 95 96 97
	toggle_fpga_eeprom_bus(true);

	return ret;
}

98
#define PCIE_SW_RST	14
99 100
#define PEXHC_RST	13
#define HOOPER_RST	12
101 102 103

void pci_init_board(void)
{
104 105 106 107 108
	qrio_prstcfg(PCIE_SW_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
	qrio_prstcfg(PEXHC_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
	qrio_prstcfg(HOOPER_RST, PRSTCFG_POWUP_UNIT_CORE_RST);

	/* wait for the PCIe FPGA to be configured
109
	 * it has been triggered earlier in board_early_init_r */
110
	if (wait_for_fpga_config())
111 112
		printf("error finishing PCIe FPGA config\n");

113
	qrio_prst(PCIE_SW_RST, false, false);
114 115
	qrio_prst(PEXHC_RST, false, false);
	qrio_prst(HOOPER_RST, false, false);
116 117
	/* Hooper is not direcly PCIe capable */
	mdelay(50);
118

119 120 121 122 123 124 125
	fsl_pcie_init_board(0);
}

void pci_of_setup(void *blob, bd_t *bd)
{
	FT_FSL_PCI_SETUP;
}