fsl_8xxx_pci.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/io.h>
  27. #include <linux/compiler.h>
  28. #include <libfdt.h>
  29. #include <fdt_support.h>
  30. #ifdef CONFIG_PCI1
  31. static struct pci_controller pci1_hose;
  32. #endif
  33. #ifdef CONFIG_PCIE1
  34. static struct pci_controller pcie1_hose;
  35. #endif
  36. #ifdef CONFIG_PCIE2
  37. static struct pci_controller pcie2_hose;
  38. #endif
  39. #ifdef CONFIG_PCIE3
  40. static struct pci_controller pcie3_hose;
  41. #endif
  42. /*
  43. * 85xx and 86xx share naming conventions, but different layout.
  44. * Correlate names to CPU-specific values to share common
  45. * PCI code.
  46. */
  47. #if defined(CONFIG_MPC85xx)
  48. #define MPC8xxx_DEVDISR_PCIE1 MPC85xx_DEVDISR_PCIE
  49. #define MPC8xxx_DEVDISR_PCIE2 MPC85xx_DEVDISR_PCIE2
  50. #define MPC8xxx_DEVDISR_PCIE3 MPC85xx_DEVDISR_PCIE3
  51. #define MPC8xxx_PORDEVSR_IO_SEL MPC85xx_PORDEVSR_IO_SEL
  52. #define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC85xx_PORDEVSR_IO_SEL_SHIFT
  53. #define MPC8xxx_PORBMSR_HA MPC85xx_PORBMSR_HA
  54. #define MPC8xxx_PORBMSR_HA_SHIFT MPC85xx_PORBMSR_HA_SHIFT
  55. #elif defined(CONFIG_MPC86xx)
  56. #define MPC8xxx_DEVDISR_PCIE1 MPC86xx_DEVDISR_PCIEX1
  57. #define MPC8xxx_DEVDISR_PCIE2 MPC86xx_DEVDISR_PCIEX2
  58. #define MPC8xxx_DEVDISR_PCIE3 0 /* 8641 doesn't have PCIe3 */
  59. #define MPC8xxx_PORDEVSR_IO_SEL MPC8641_PORDEVSR_IO_SEL
  60. #define MPC8xxx_PORDEVSR_IO_SEL_SHIFT MPC8641_PORDEVSR_IO_SEL_SHIFT
  61. #define MPC8xxx_PORBMSR_HA MPC8641_PORBMSR_HA
  62. #define MPC8xxx_PORBMSR_HA_SHIFT MPC8641_PORBMSR_HA_SHIFT
  63. #endif
  64. void pci_init_board(void)
  65. {
  66. struct fsl_pci_info pci_info[3];
  67. int first_free_busno = 0;
  68. int num = 0;
  69. int pcie_ep;
  70. __maybe_unused int pcie_configured;
  71. #if defined(CONFIG_MPC85xx)
  72. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  73. #elif defined(CONFIG_MPC86xx)
  74. immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  75. volatile ccsr_gur_t *gur = &immap->im_gur;
  76. #endif
  77. u32 devdisr = in_be32(&gur->devdisr);
  78. u32 pordevsr = in_be32(&gur->pordevsr);
  79. __maybe_unused uint io_sel = (pordevsr & MPC8xxx_PORDEVSR_IO_SEL) >>
  80. MPC8xxx_PORDEVSR_IO_SEL_SHIFT;
  81. #ifdef CONFIG_PCI1
  82. uint pci_spd_norm = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_SPD;
  83. uint pci_32 = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_PCI32;
  84. uint pci_arb = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1_ARB;
  85. uint pcix = in_be32(&gur->pordevsr) & MPC85xx_PORDEVSR_PCI1;
  86. uint freq = CONFIG_SYS_CLK_FREQ / 1000 / 1000;
  87. if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
  88. SET_STD_PCI_INFO(pci_info[num], 1);
  89. pcie_ep = fsl_setup_hose(&pci1_hose, pci_info[num].regs);
  90. printf("\n PCI1: %d bit %s, %s %d MHz, %s, %s\n",
  91. pci_32 ? 32 : 64,
  92. pcix ? "PCIX" : "PCI",
  93. pci_spd_norm ? ">=" : "<=",
  94. pcix ? freq * 2 : freq,
  95. pcie_ep ? "agent" : "host",
  96. pci_arb ? "arbiter" : "external-arbiter");
  97. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  98. &pci1_hose, first_free_busno);
  99. } else {
  100. printf(" PCI1: disabled\n");
  101. }
  102. #elif defined CONFIG_MPC8548
  103. /* PCI1 not present on MPC8572 */
  104. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCI1);
  105. #endif
  106. #ifdef CONFIG_PCIE1
  107. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
  108. if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE1)) {
  109. SET_STD_PCIE_INFO(pci_info[num], 1);
  110. pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs);
  111. printf(" PCIE1 connected as %s\n",
  112. pcie_ep ? "Endpoint" : "Root Complex");
  113. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  114. &pcie1_hose, first_free_busno);
  115. } else {
  116. printf(" PCIE1: disabled\n");
  117. }
  118. #else
  119. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE1);
  120. #endif /* CONFIG_PCIE1 */
  121. #ifdef CONFIG_PCIE2
  122. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_2, io_sel);
  123. if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE2)) {
  124. SET_STD_PCIE_INFO(pci_info[num], 2);
  125. pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs);
  126. printf(" PCIE2 connected as %s\n",
  127. pcie_ep ? "Endpoint" : "Root Complex");
  128. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  129. &pcie2_hose, first_free_busno);
  130. } else {
  131. printf(" PCIE2: disabled\n");
  132. }
  133. #else
  134. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE2);
  135. #endif /* CONFIG_PCIE2 */
  136. #ifdef CONFIG_PCIE3
  137. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_3, io_sel);
  138. if (pcie_configured && !(devdisr & MPC8xxx_DEVDISR_PCIE3)) {
  139. SET_STD_PCIE_INFO(pci_info[num], 3);
  140. pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info[num].regs);
  141. printf(" PCIE3 connected as %s\n",
  142. pcie_ep ? "Endpoint" : "Root Complex");
  143. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  144. &pcie3_hose, first_free_busno);
  145. } else {
  146. printf(" PCIE3: disabled\n");
  147. }
  148. #else
  149. setbits_be32(&gur->devdisr, MPC8xxx_DEVDISR_PCIE3);
  150. #endif /* CONFIG_PCIE3 */
  151. }
  152. #if defined(CONFIG_OF_BOARD_SETUP)
  153. void ft_board_pci_setup(void *blob, bd_t *bd)
  154. {
  155. FT_FSL_PCI_SETUP;
  156. }
  157. #endif /* CONFIG_OF_BOARD_SETUP */