fsl_pci_init.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #define DEBUG
  19. #include <common.h>
  20. #ifdef CONFIG_FSL_PCI_INIT
  21. /*
  22. * PCI/PCIE Controller initialization for mpc85xx/mpc86xx soc's
  23. *
  24. * Initialize controller and call the common driver/pci pci_hose_scan to
  25. * scan for bridges and devices.
  26. *
  27. * Hose fields which need to be pre-initialized by board specific code:
  28. * regions[]
  29. * first_busno
  30. *
  31. * Fields updated:
  32. * last_busno
  33. */
  34. #include <pci.h>
  35. #include <asm/immap_fsl_pci.h>
  36. void pciauto_prescan_setup_bridge(struct pci_controller *hose,
  37. pci_dev_t dev, int sub_bus);
  38. void pciauto_postscan_setup_bridge(struct pci_controller *hose,
  39. pci_dev_t dev, int sub_bus);
  40. void pciauto_config_init(struct pci_controller *hose);
  41. void
  42. fsl_pci_init(struct pci_controller *hose)
  43. {
  44. u16 temp16;
  45. u32 temp32;
  46. int busno = hose->first_busno;
  47. int enabled;
  48. u16 ltssm;
  49. u8 temp8;
  50. int r;
  51. int bridge;
  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. } 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 = 0xffffffff; /* Enable Error Interupts */
  87. pci_hose_read_config_dword (hose, dev, PCI_DCR, &temp32);
  88. temp32 |= 0xf000e; /* set URR, FER, NFER (but not CER) */
  89. pci_hose_write_config_dword(hose, dev, PCI_DCR, temp32);
  90. pci_hose_read_config_byte (hose, dev, PCI_HEADER_TYPE, &temp8);
  91. bridge = temp8 & PCI_HEADER_TYPE_BRIDGE; /* Bridge, such as pcie */
  92. if ( bridge ) {
  93. pci_hose_read_config_word(hose, dev, PCI_LTSSM, &ltssm);
  94. enabled = ltssm >= PCI_LTSSM_L0;
  95. if (!enabled) {
  96. debug("....PCIE link error. Skipping scan."
  97. "LTSSM=0x%02x\n", temp16);
  98. hose->last_busno = hose->first_busno;
  99. return;
  100. }
  101. pci->pme_msg_det = 0xffffffff;
  102. pci->pme_msg_int_en = 0xffffffff;
  103. #ifdef DEBUG
  104. pci_hose_read_config_word(hose, dev, PCI_LSR, &temp16);
  105. neg_link_w = (temp16 & 0x3f0 ) >> 4;
  106. debug("...PCIE LTSSM=0x%x, Negotiated link width=%d\n",
  107. ltssm, neg_link_w);
  108. #endif
  109. hose->current_busno++; /* Start scan with secondary */
  110. pciauto_prescan_setup_bridge(hose, dev, hose->current_busno);
  111. } else {
  112. #if 0
  113. /* done in pci_hose_config_device() */
  114. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &temp16);
  115. temp16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER |
  116. PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
  117. pci_hose_write_config_word(hose, dev, PCI_COMMAND, temp16);
  118. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  119. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  120. #endif
  121. }
  122. /* Call setup to allocate PCSRBAR window */
  123. pciauto_setup_device(hose, dev, 1, hose->pci_mem,
  124. hose->pci_prefetch, hose->pci_io);
  125. printf (" Scanning PCI bus %02x\n", hose->current_busno);
  126. hose->last_busno = pci_hose_scan_bus(hose,hose->current_busno);
  127. if ( bridge ) { /* update limit regs and subordinate busno */
  128. pciauto_postscan_setup_bridge(hose, dev, hose->last_busno);
  129. }
  130. /* Clear all error indications */
  131. if (pci->pme_msg_det && pci->pme_msg_det != 0xffffffff) {
  132. debug("pci_fsl_init: pme_msg_det@%x=%x. Clearing\n",
  133. &pci->pme_msg_det, pci->pme_msg_det);
  134. pci->pme_msg_det = 0xffffffff;
  135. }
  136. if (pci->pedr) {
  137. debug("pci_fsl_init: pedr@%x=%x. Clearing\n",
  138. &pci->pedr, pci->pedr);
  139. pci->pedr = 0xffffffff;
  140. }
  141. pci_hose_read_config_word (hose, dev, PCI_DSR, &temp16);
  142. if (temp16) {
  143. debug("pci_fsl_init: PCI_DSR@%x=%x. Clearing\n",
  144. PCI_DSR, temp16);
  145. pci_hose_write_config_word(hose, dev,
  146. PCI_DSR, 0xffff);
  147. }
  148. pci_hose_read_config_word (hose, dev, PCI_SEC_STATUS, &temp16);
  149. if (temp16) {
  150. debug("pci_fsl_init: PCI_SEC_STATUS@%x=%x. Clearing\n",
  151. PCI_SEC_STATUS, temp16);
  152. pci_hose_write_config_word(hose, dev, PCI_SEC_STATUS, 0xffff);
  153. }
  154. }
  155. #endif /* CONFIG_FSL_PCI */