fsl_8xxx_pci.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright 2008 Extreme Engineering Solutions, Inc.
  3. * Copyright 2007-2008 Freescale Semiconductor, Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <pci.h>
  25. #include <asm/fsl_pci.h>
  26. #include <asm/fsl_serdes.h>
  27. #include <asm/io.h>
  28. #include <linux/compiler.h>
  29. #include <libfdt.h>
  30. #include <fdt_support.h>
  31. #ifdef CONFIG_PCI1
  32. static struct pci_controller pci1_hose;
  33. #endif
  34. #ifdef CONFIG_PCIE1
  35. static struct pci_controller pcie1_hose;
  36. #endif
  37. #ifdef CONFIG_PCIE2
  38. static struct pci_controller pcie2_hose;
  39. #endif
  40. #ifdef CONFIG_PCIE3
  41. static struct pci_controller pcie3_hose;
  42. #endif
  43. /*
  44. * 85xx and 86xx share naming conventions, but different layout.
  45. * Correlate names to CPU-specific values to share common
  46. * PCI code.
  47. */
  48. #if defined(CONFIG_MPC85xx)
  49. #define MPC8xxx_DEVDISR_PCIE1 MPC85xx_DEVDISR_PCIE
  50. #define MPC8xxx_DEVDISR_PCIE2 MPC85xx_DEVDISR_PCIE2
  51. #define MPC8xxx_DEVDISR_PCIE3 MPC85xx_DEVDISR_PCIE3
  52. #define MPC8xxx_PORDEVSR_IO_SEL MPC85xx_PORDEVSR_IO_SEL
  53. #define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC85xx_PORDEVSR_IO_SEL_SHIFT
  54. #define MPC8xxx_PORBMSR_HA MPC85xx_PORBMSR_HA
  55. #define MPC8xxx_PORBMSR_HA_SHIFT MPC85xx_PORBMSR_HA_SHIFT
  56. #elif defined(CONFIG_MPC86xx)
  57. #define MPC8xxx_DEVDISR_PCIE1 MPC86xx_DEVDISR_PCIEX1
  58. #define MPC8xxx_DEVDISR_PCIE2 MPC86xx_DEVDISR_PCIEX2
  59. #define MPC8xxx_DEVDISR_PCIE3 0 /* 8641 doesn't have PCIe3 */
  60. #define MPC8xxx_PORDEVSR_IO_SEL MPC8641_PORDEVSR_IO_SEL
  61. #define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC8641_PORDEVSR_IO_SEL_SHIFT
  62. #define MPC8xxx_PORBMSR_HA MPC8641_PORBMSR_HA
  63. #define MPC8xxx_PORBMSR_HA_SHIFT MPC8641_PORBMSR_HA_SHIFT
  64. #endif
  65. void pci_init_board(void)
  66. {
  67. struct fsl_pci_info pci_info[3];
  68. int first_free_busno = 0;
  69. int num = 0;
  70. int pcie_ep;
  71. __maybe_unused int pcie_configured;
  72. #if defined(CONFIG_MPC85xx)
  73. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  74. #elif defined(CONFIG_MPC86xx)
  75. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  76. volatile ccsr_gur_t *gur = &immap->im_gur;
  77. #endif
  78. u32 devdisr = in_be32(&gur->devdisr);
  79. #ifdef CONFIG_PCI1
  80. u32 pordevsr = in_be32(&gur->pordevsr);
  81. uint pci_spd_norm = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_SPD;
  82. uint pci_32 = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_PCI32;
  83. uint pci_arb = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_ARB;
  84. uint pcix = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1;
  85. uint freq = CONFIG_SYS_CLK_FREQ / 1000 / 1000;
  86. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  87. SET_STD_PCI_INFO(pci_info[num], 1);
  88. pcie_ep = fsl_setup_hose(&pci1_hose, pci_info[num].regs);
  89. printf("PCI1: %d bit %s, %s %d MHz, %s, %s\n",
  90. pci_32 ? 32 : 64,
  91. pcix ? "PCIX" : "PCI",
  92. pci_spd_norm ? ">=" : "<=",
  93. pcix ? freq * 2 : freq,
  94. pcie_ep ? "agent" : "host",
  95. pci_arb ? "arbiter" : "external-arbiter");
  96. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  97. &pci1_hose, first_free_busno);
  98. } else {
  99. printf("PCI1: disabled\n");
  100. }
  101. #elif defined CONFIG_MPC8548
  102. /* PCI1 not present on MPC8572 */
  103. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1);
  104. #endif
  105. #ifdef CONFIG_PCIE1
  106. pcie_configured = is_serdes_configured(PCIE1);
  107. if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE1)) {
  108. SET_STD_PCIE_INFO(pci_info[num], 1);
  109. pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs);
  110. printf("PCIE1: connected as %s\n",
  111. pcie_ep ? "Endpoint" : "Root Complex");
  112. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  113. &pcie1_hose, first_free_busno);
  114. } else {
  115. printf("PCIE1: disabled\n");
  116. }
  117. #else
  118. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE1);
  119. #endif /* CONFIG_PCIE1 */
  120. #ifdef CONFIG_PCIE2
  121. pcie_configured = is_serdes_configured(PCIE2);
  122. if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE2)) {
  123. SET_STD_PCIE_INFO(pci_info[num], 2);
  124. pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs);
  125. printf("PCIE2: connected as %s\n",
  126. pcie_ep ? "Endpoint" : "Root Complex");
  127. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  128. &pcie2_hose, first_free_busno);
  129. } else {
  130. printf("PCIE2: disabled\n");
  131. }
  132. #else
  133. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE2);
  134. #endif /* CONFIG_PCIE2 */
  135. #ifdef CONFIG_PCIE3
  136. pcie_configured = is_serdes_configured(PCIE3);
  137. if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE3)) {
  138. SET_STD_PCIE_INFO(pci_info[num], 3);
  139. pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info[num].regs);
  140. printf("PCIE3: connected as %s\n",
  141. pcie_ep ? "Endpoint" : "Root Complex");
  142. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  143. &pcie3_hose, first_free_busno);
  144. } else {
  145. printf("PCIE3: disabled\n");
  146. }
  147. #else
  148. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE3);
  149. #endif /* CONFIG_PCIE3 */
  150. }
  151. #if defined(CONFIG_OF_BOARD_SETUP)
  152. void ft_board_pci_setup(void *blob, bd_t *bd)
  153. {
  154. FT_FSL_PCI_SETUP;
  155. }
  156. #endif /* CONFIG_OF_BOARD_SETUP */