fsl_pci_init.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. #ifdef CONFIG_FSL_PCI_INIT
  20. /*
  21. * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's
  22. *
  23. * Initialize controller and call the common driver/pci pci_hose_scan to
  24. * scan for bridges and devices.
  25. *
  26. * Hose fields which need to be pre-initialized by board specific code:
  27. * regions[]
  28. * first_busno
  29. *
  30. * Fields updated:
  31. * last_busno
  32. */
  33. #include <pci.h>
  34. #include <asm/immap_fsl_pci.h>
  35. void pciauto_prescan_setup_bridge(struct pci_controller *hose,
  36. pci_dev_t dev, int sub_bus);
  37. void pciauto_postscan_setup_bridge(struct pci_controller *hose,
  38. pci_dev_t dev, int sub_bus);
  39. void pciauto_config_init(struct pci_controller *hose);
  40. void
  41. fsl_pci_init(struct pci_controller *hose)
  42. {
  43. u16 temp16;
  44. u32 temp32;
  45. int busno = hose->first_busno;
  46. int enabled;
  47. u16 ltssm;
  48. u8 temp8;
  49. int r;
  50. int bridge;
  51. int inbound = 0;
  52. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) hose->cfg_addr;
  53. pci_dev_t dev = PCI_BDF(busno,0,0);
  54. /* Initialize ATMU registers based on hose regions and flags */
  55. volatile pot_t *po=&pci->pot[1]; /* skip 0 */
  56. volatile pit_t *pi=&pci->pit[0]; /* ranges from: 3 to 1 */
  57. #ifdef DEBUG
  58. int neg_link_w;
  59. #endif
  60. for (r=0; r<hose->region_count; r++) {
  61. if (hose->regions[r].flags & PCI_REGION_MEMORY) { /* inbound */
  62. pi->pitar = (hose->regions[r].bus_start >> 12) & 0x000fffff;
  63. pi->piwbar = (hose->regions[r].phys_start >> 12) & 0x000fffff;
  64. pi->piwbear = 0;
  65. pi->piwar = PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
  66. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP |
  67. (__ilog2(hose->regions[r].size) - 1);
  68. pi++;
  69. inbound = hose->regions[r].size > 0;
  70. } else { /* Outbound */
  71. po->powbar = (hose->regions[r].phys_start >> 12) & 0x000fffff;
  72. po->potar = (hose->regions[r].bus_start >> 12) & 0x000fffff;
  73. po->potear = 0;
  74. if (hose->regions[r].flags & PCI_REGION_IO)
  75. po->powar = POWAR_EN | POWAR_IO_READ | POWAR_IO_WRITE |
  76. (__ilog2(hose->regions[r].size) - 1);
  77. else
  78. po->powar = POWAR_EN | POWAR_MEM_READ | POWAR_MEM_WRITE |
  79. (__ilog2(hose->regions[r].size) - 1);
  80. po++;
  81. }
  82. }
  83. pci_register_hose(hose);
  84. pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */
  85. hose->current_busno = hose->first_busno;
  86. pci->pedr = 0xffffffff; /* Clear any errors */
  87. pci->peer = ~0x20140; /* Enable All Error Interupts except
  88. * - Master abort (pci)
  89. * - Master PERR (pci)
  90. * - ICCA (PCIe)
  91. */
  92. pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32);
  93. temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */
  94. pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32);
  95. pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8);
  96. bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */
  97. if ( bridge ) {
  98. pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
  99. enabled = ltssm >= PCI_LTSSM_L0;
  100. #ifdef CONFIG_FSL_PCIE_RESET
  101. if (ltssm == 1) {
  102. int i;
  103. debug("....PCIe link error. "
  104. "LTSSM=0x%02x.", ltssm);
  105. pci->pdb_stat |= 0x08000000; /* assert PCIe reset */
  106. temp32 = pci->pdb_stat;
  107. udelay(100);
  108. debug(" Asserting PCIe reset @%x = %x\n",
  109. &pci->pdb_stat, pci->pdb_stat);
  110. pci->pdb_stat &= ~0x08000000; /* clear reset */
  111. asm("sync;isync");
  112. for (i=0; i<100 && ltssm < PCI_LTSSM_L0; i++) {
  113. pci_hose_read_config_word(hose, dev, PCI_LTSSM,
  114. &ltssm);
  115. udelay(1000);
  116. debug("....PCIe link error. "
  117. "LTSSM=0x%02x.\n", ltssm);
  118. }
  119. enabled = ltssm >= PCI_LTSSM_L0;
  120. }
  121. #endif
  122. if (!enabled) {
  123. debug("....PCIE link error. Skipping scan."
  124. "LTSSM=0x%02x\n", ltssm);
  125. hose->last_busno = hose->first_busno;
  126. return;
  127. }
  128. pci->pme_msg_det = 0xffffffff;
  129. pci->pme_msg_int_en = 0xffffffff;
  130. #ifdef DEBUG
  131. pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
  132. neg_link_w = (temp16 & 0x3f0 ) >> 4;
  133. printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n",
  134. ltssm, neg_link_w);
  135. #endif
  136. hose->current_busno++; /* Start scan with secondary */
  137. pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
  138. }
  139. /* Use generic setup_device to initialize standard pci regs,
  140. * but do not allocate any windows since any BAR found (such
  141. * as PCSRBAR) is not in this cpu's memory space.
  142. */
  143. pciauto_setup_device(hose, dev, 0, hose->pci_mem,
  144. hose->pci_prefetch, hose->pci_io);
  145. if (inbound) {
  146. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
  147. pci_hose_write_config_word(hose, dev, PCI_COMMAND,
  148. temp16 | PCI_COMMAND_MEMORY);
  149. }
  150. #ifndef CONFIG_PCI_NOSCAN
  151. printf (" Scanning PCI bus %02x\n", hose->current_busno);
  152. hose->last_busno = pci_hose_scan_bus(hose,hose->current_busno);
  153. if ( bridge ) { /* update limit regs and subordinate busno */
  154. pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
  155. }
  156. #else
  157. hose->last_busno = hose->current_busno;
  158. #endif
  159. /* Clear all error indications */
  160. pci->pme_msg_det = 0xffffffff;
  161. pci->pedr = 0xffffffff;
  162. pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
  163. if (temp16) {
  164. pci_hose_write_config_word(hose, dev,
  165. PCI_DSR, 0xffff);
  166. }
  167. pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
  168. if (temp16) {
  169. pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
  170. }
  171. }
  172. #endif /* CONFIG_FSL_PCI */