fsl_pci_init.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Copyright 2007 Freescale Semiconductor, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * Version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  16. * MA 02111-1307 USA
  17. */
  18. #include <common.h>
  19. /*
  20. * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's
  21. *
  22. * Initialize controller and call the common driver/pci pci_hose_scan to
  23. * scan for bridges and devices.
  24. *
  25. * Hose fields which need to be pre-initialized by board specific code:
  26. * regions[]
  27. * first_busno
  28. *
  29. * Fields updated:
  30. * last_busno
  31. */
  32. #include <pci.h>
  33. #include <asm/immap_fsl_pci.h>
  34. void pciauto_prescan_setup_bridge(struct pci_controller *hose,
  35. pci_dev_t dev, int sub_bus);
  36. void pciauto_postscan_setup_bridge(struct pci_controller *hose,
  37. pci_dev_t dev, int sub_bus);
  38. void pciauto_config_init(struct pci_controller *hose);
  39. void
  40. fsl_pci_init(struct pci_controller *hose)
  41. {
  42. u16 temp16;
  43. u32 temp32;
  44. int busno = hose->first_busno;
  45. int enabled;
  46. u16 ltssm;
  47. u8 temp8;
  48. int r;
  49. int bridge;
  50. int inbound = 0;
  51. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) hose->cfg_addr;
  52. pci_dev_t dev = PCI_BDF(busno,0,0);
  53. /* Initialize ATMU registers based on hose regions and flags */
  54. volatile pot_t *po = &pci->pot[1]; /* skip 0 */
  55. volatile pit_t *pi = &pci->pit[0]; /* ranges from: 3 to 1 */
  56. #ifdef DEBUG
  57. int neg_link_w;
  58. #endif
  59. for (r=0; r<hose->region_count; r++) {
  60. if (hose->regions[r].flags & PCI_REGION_MEMORY) { /* inbound */
  61. pi->pitar = (hose->regions[r].bus_start >> 12) & 0x000fffff;
  62. pi->piwbar = (hose->regions[r].phys_start >> 12) & 0x000fffff;
  63. pi->piwbear = 0;
  64. pi->piwar = PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
  65. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP |
  66. (__ilog2(hose->regions[r].size) - 1);
  67. pi++;
  68. inbound = hose->regions[r].size > 0;
  69. } else { /* Outbound */
  70. po->powbar = (hose->regions[r].phys_start >> 12) & 0x000fffff;
  71. po->potar = (hose->regions[r].bus_start >> 12) & 0x000fffff;
  72. po->potear = 0;
  73. if (hose->regions[r].flags & PCI_REGION_IO)
  74. po->powar = POWAR_EN | POWAR_IO_READ | POWAR_IO_WRITE |
  75. (__ilog2(hose->regions[r].size) - 1);
  76. else
  77. po->powar = POWAR_EN | POWAR_MEM_READ | POWAR_MEM_WRITE |
  78. (__ilog2(hose->regions[r].size) - 1);
  79. po++;
  80. }
  81. }
  82. pci_register_hose(hose);
  83. pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */
  84. hose->current_busno = hose->first_busno;
  85. pci->pedr = 0xffffffff; /* Clear any errors */
  86. pci->peer = ~0x20140; /* Enable All Error Interupts except
  87. * - Master abort (pci)
  88. * - Master PERR (pci)
  89. * - ICCA (PCIe)
  90. */
  91. pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32);
  92. temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */
  93. pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32);
  94. pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8);
  95. bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */
  96. if ( bridge ) {
  97. pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
  98. enabled = ltssm >= PCI_LTSSM_L0;
  99. #ifdef CONFIG_FSL_PCIE_RESET
  100. if (ltssm == 1) {
  101. int i;
  102. debug("....PCIe link error. "
  103. "LTSSM=0x%02x.", ltssm);
  104. pci->pdb_stat |= 0x08000000; /* assert PCIe reset */
  105. temp32 = pci->pdb_stat;
  106. udelay(100);
  107. debug(" Asserting PCIe reset @%x = %x\n",
  108. &pci->pdb_stat, pci->pdb_stat);
  109. pci->pdb_stat &= ~0x08000000; /* clear reset */
  110. asm("sync;isync");
  111. for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) {
  112. pci_hose_read_config_word(hose, dev, PCI_LTSSM,
  113. &ltssm);
  114. udelay(1000);
  115. debug("....PCIe link error. "
  116. "LTSSM=0x%02x.\n", ltssm);
  117. }
  118. enabled = ltssm >= PCI_LTSSM_L0;
  119. }
  120. #endif
  121. if (!enabled) {
  122. debug("....PCIE link error. Skipping scan."
  123. "LTSSM=0x%02x\n", ltssm);
  124. hose->last_busno = hose->first_busno;
  125. return;
  126. }
  127. pci->pme_msg_det = 0xffffffff;
  128. pci->pme_msg_int_en = 0xffffffff;
  129. #ifdef DEBUG
  130. pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
  131. neg_link_w = (temp16 & 0x3f0 ) >> 4;
  132. printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n",
  133. ltssm, neg_link_w);
  134. #endif
  135. hose->current_busno++; /* Start scan with secondary */
  136. pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
  137. }
  138. /* Use generic setup_device to initialize standard pci regs,
  139. * but do not allocate any windows since any BAR found (such
  140. * as PCSRBAR) is not in this cpu's memory space.
  141. */
  142. pciauto_setup_device(hose, dev, 0, hose->pci_mem,
  143. hose->pci_prefetch, hose->pci_io);
  144. if (inbound) {
  145. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
  146. pci_hose_write_config_word(hose, dev, PCI_COMMAND,
  147. temp16 | PCI_COMMAND_MEMORY);
  148. }
  149. #ifndef CONFIG_PCI_NOSCAN
  150. pci_hose_read_config_byte(hose, dev, PCI_CLASS_PROG, &temp8);
  151. /* Programming Interface (PCI_CLASS_PROG)
  152. * 0 == pci host or pcie root-complex,
  153. * 1 == pci agent or pcie end-point
  154. */
  155. if (!temp8) {
  156. printf(" Scanning PCI bus %02x\n",
  157. hose->current_busno);
  158. hose->last_busno = pci_hose_scan_bus(hose, hose->current_busno);
  159. } else {
  160. debug(" Not scanning PCI bus %02x. PI=%x\n",
  161. hose->current_busno, temp8);
  162. hose->last_busno = hose->current_busno;
  163. }
  164. if ( bridge ) { /* update limit regs and subordinate busno */
  165. pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
  166. }
  167. #else
  168. hose->last_busno = hose->current_busno;
  169. #endif
  170. /* Clear all error indications */
  171. if (bridge)
  172. pci->pme_msg_det = 0xffffffff;
  173. pci->pedr = 0xffffffff;
  174. pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
  175. if (temp16) {
  176. pci_hose_write_config_word(hose, dev,
  177. PCI_DSR, 0xffff);
  178. }
  179. pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
  180. if (temp16) {
  181. pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
  182. }
  183. }