pci.c 2.6 KB

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