fsl_pci_init.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. if (!enabled) {
  101. debug("....PCIE link error. Skipping scan."
  102. "LTSSM=0x%02x\n", ltssm);
  103. hose->last_busno = hose->first_busno;
  104. return;
  105. }
  106. pci->pme_msg_det = 0xffffffff;
  107. pci->pme_msg_int_en = 0xffffffff;
  108. #ifdef DEBUG
  109. pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
  110. neg_link_w = (temp16 & 0x3f0 ) >> 4;
  111. printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n",
  112. ltssm, neg_link_w);
  113. #endif
  114. hose->current_busno++; /* Start scan with secondary */
  115. pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
  116. }
  117. /* Use generic setup_device to initialize standard pci regs,
  118. * but do not allocate any windows since any BAR found (such
  119. * as PCSRBAR) is not in this cpu's memory space.
  120. */
  121. pciauto_setup_device(hose, dev, 0, hose->pci_mem,
  122. hose->pci_prefetch, hose->pci_io);
  123. if (inbound) {
  124. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
  125. pci_hose_write_config_word(hose, dev, PCI_COMMAND,
  126. temp16 | PCI_COMMAND_MEMORY);
  127. }
  128. #ifndef CONFIG_PCI_NOSCAN
  129. printf (" Scanning PCI bus %02x\n", hose->current_busno);
  130. hose->last_busno = pci_hose_scan_bus(hose,hose->current_busno);
  131. if ( bridge ) { /* update limit regs and subordinate busno */
  132. pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
  133. }
  134. #else
  135. hose->last_busno = hose->current_busno;
  136. #endif
  137. /* Clear all error indications */
  138. pci->pme_msg_det = 0xffffffff;
  139. pci->pedr = 0xffffffff;
  140. pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
  141. if (temp16) {
  142. pci_hose_write_config_word(hose, dev,
  143. PCI_DSR, 0xffff);
  144. }
  145. pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
  146. if (temp16) {
  147. pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
  148. }
  149. }
  150. #endif /* CONFIG_FSL_PCI */