Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 Keymile AG |
| 4 | * Valentin Longchamp <valentin.longchamp@keymile.com> |
| 5 | * |
| 6 | * Copyright 2007-2011 Freescale Semiconductor, Inc. |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
Simon Glass | 18afe10 | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 11 | #include <init.h> |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 12 | #include <pci.h> |
| 13 | #include <asm/fsl_pci.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 15 | #include <linux/libfdt.h> |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 16 | #include <fdt_support.h> |
| 17 | #include <asm/fsl_serdes.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 18 | #include <linux/errno.h> |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 19 | |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 20 | #include "../common/qrio.h" |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 21 | #include "kmp204x.h" |
| 22 | |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 23 | #define PROM_SEL_L 11 |
| 24 | /* control the PROM_SEL_L signal*/ |
| 25 | static void toggle_fpga_eeprom_bus(bool cpu_own) |
| 26 | { |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 27 | qrio_gpio_direction_output(QRIO_GPIO_A, PROM_SEL_L, !cpu_own); |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | #define CONF_SEL_L 10 |
| 31 | #define FPGA_PROG_L 19 |
| 32 | #define FPGA_DONE 18 |
| 33 | #define FPGA_INIT_L 17 |
| 34 | |
| 35 | int trigger_fpga_config(void) |
| 36 | { |
| 37 | int ret = 0, init_l; |
| 38 | /* approx 10ms */ |
| 39 | u32 timeout = 10000; |
| 40 | |
| 41 | /* make sure the FPGA_can access the EEPROM */ |
| 42 | toggle_fpga_eeprom_bus(false); |
| 43 | |
| 44 | /* assert CONF_SEL_L to be able to drive FPGA_PROG_L */ |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 45 | qrio_gpio_direction_output(QRIO_GPIO_A, CONF_SEL_L, 0); |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 46 | |
| 47 | /* trigger the config start */ |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 48 | qrio_gpio_direction_output(QRIO_GPIO_A, FPGA_PROG_L, 0); |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 49 | |
| 50 | /* small delay for INIT_L line */ |
| 51 | udelay(10); |
| 52 | |
| 53 | /* wait for FPGA_INIT to be asserted */ |
| 54 | do { |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 55 | init_l = qrio_get_gpio(QRIO_GPIO_A, FPGA_INIT_L); |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 56 | if (timeout-- == 0) { |
| 57 | printf("FPGA_INIT timeout\n"); |
| 58 | ret = -EFAULT; |
| 59 | break; |
| 60 | } |
| 61 | udelay(10); |
| 62 | } while (init_l); |
| 63 | |
| 64 | /* deassert FPGA_PROG, config should start */ |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 65 | qrio_set_gpio(QRIO_GPIO_A, FPGA_PROG_L, 1); |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 66 | |
| 67 | return ret; |
| 68 | } |
| 69 | |
| 70 | /* poll the FPGA_DONE signal and give the EEPROM back to the QorIQ */ |
| 71 | static int wait_for_fpga_config(void) |
| 72 | { |
| 73 | int ret = 0, done; |
| 74 | /* approx 5 s */ |
| 75 | u32 timeout = 500000; |
| 76 | |
| 77 | printf("PCIe FPGA config:"); |
| 78 | do { |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 79 | done = qrio_get_gpio(QRIO_GPIO_A, FPGA_DONE); |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 80 | if (timeout-- == 0) { |
| 81 | printf(" FPGA_DONE timeout\n"); |
| 82 | ret = -EFAULT; |
| 83 | goto err_out; |
| 84 | } |
| 85 | udelay(10); |
| 86 | } while (!done); |
| 87 | |
| 88 | printf(" done\n"); |
| 89 | |
| 90 | err_out: |
| 91 | /* deactive CONF_SEL and give the CPU conf EEPROM access */ |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 92 | qrio_set_gpio(QRIO_GPIO_A, CONF_SEL_L, 1); |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 93 | toggle_fpga_eeprom_bus(true); |
| 94 | |
| 95 | return ret; |
| 96 | } |
| 97 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 98 | #define PCIE_SW_RST 14 |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 99 | #define PEXHC_RST 13 |
| 100 | #define HOOPER_RST 12 |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 101 | |
| 102 | void pci_init_board(void) |
| 103 | { |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 104 | qrio_prstcfg(PCIE_SW_RST, PRSTCFG_POWUP_UNIT_CORE_RST); |
| 105 | qrio_prstcfg(PEXHC_RST, PRSTCFG_POWUP_UNIT_CORE_RST); |
| 106 | qrio_prstcfg(HOOPER_RST, PRSTCFG_POWUP_UNIT_CORE_RST); |
| 107 | |
| 108 | /* wait for the PCIe FPGA to be configured |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 109 | * it has been triggered earlier in board_early_init_r */ |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 110 | if (wait_for_fpga_config()) |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 111 | printf("error finishing PCIe FPGA config\n"); |
| 112 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 113 | qrio_prst(PCIE_SW_RST, false, false); |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 114 | qrio_prst(PEXHC_RST, false, false); |
| 115 | qrio_prst(HOOPER_RST, false, false); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 116 | /* Hooper is not direcly PCIe capable */ |
| 117 | mdelay(50); |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 118 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 119 | fsl_pcie_init_board(0); |
| 120 | } |
| 121 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 122 | void pci_of_setup(void *blob, struct bd_info *bd) |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 123 | { |
| 124 | FT_FSL_PCI_SETUP; |
| 125 | } |