fsl_pci_init.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. 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. } else { /* Outbound */
  69. po->powbar = (hose->regions[r].phys_start >> 12) & 0x000fffff;
  70. po->potar = (hose->regions[r].bus_start >> 12) & 0x000fffff;
  71. po->potear = 0;
  72. if (hose->regions[r].flags & PCI_REGION_IO)
  73. po->powar = POWAR_EN | POWAR_IO_READ | POWAR_IO_WRITE |
  74. (__ilog2(hose->regions[r].size) - 1);
  75. else
  76. po->powar = POWAR_EN | POWAR_MEM_READ | POWAR_MEM_WRITE |
  77. (__ilog2(hose->regions[r].size) - 1);
  78. po++;
  79. }
  80. }
  81. pci_register_hose(hose);
  82. pciauto_config_init(hose); /* grab pci_{mem,prefetch,io} */
  83. hose->current_busno = hose->first_busno;
  84. pci->pedr = 0xffffffff; /* Clear any errors */
  85. pci->peer = ~0x20140; /* Enable All Error Interupts except
  86. * - Master abort (pci)
  87. * - Master PERR (pci)
  88. * - ICCA (PCIe)
  89. */
  90. pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32);
  91. temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */
  92. pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32);
  93. pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8);
  94. bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */
  95. if ( bridge ) {
  96. pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
  97. enabled = ltssm >= PCI_LTSSM_L0;
  98. if (!enabled) {
  99. debug("....PCIE link error. Skipping scan."
  100. "LTSSM=0x%02x\n", ltssm);
  101. hose->last_busno = hose->first_busno;
  102. return;
  103. }
  104. pci->pme_msg_det = 0xffffffff;
  105. pci->pme_msg_int_en = 0xffffffff;
  106. #ifdef DEBUG
  107. pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
  108. neg_link_w = (temp16 & 0x3f0 ) >> 4;
  109. printf("...PCIE LTSSM=0x%x, Negotiated link width=%d\n",
  110. ltssm, neg_link_w);
  111. #endif
  112. hose->current_busno++; /* Start scan with secondary */
  113. pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
  114. }
  115. /* Call setup to allocate PCSRBAR window */
  116. pciauto_setup_device(hose, dev, 1, hose->pci_mem,
  117. hose->pci_prefetch, hose->pci_io);
  118. #ifndef CONFIG_PCI_NOSCAN
  119. printf (" Scanning PCI bus %02x\n", hose->current_busno);
  120. hose->last_busno = pci_hose_scan_bus(hose,hose->current_busno);
  121. if ( bridge ) { /* update limit regs and subordinate busno */
  122. pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
  123. }
  124. #else
  125. hose->last_busno = hose->current_busno;
  126. #endif
  127. /* Clear all error indications */
  128. pci->pme_msg_det = 0xffffffff;
  129. pci->pedr = 0xffffffff;
  130. pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
  131. if (temp16) {
  132. pci_hose_write_config_word(hose, dev,
  133. PCI_DSR, 0xffff);
  134. }
  135. pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
  136. if (temp16) {
  137. pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
  138. }
  139. }
  140. #endif /* CONFIG_FSL_PCI */