pci.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * Copyright (C) 2003 Motorola Inc.
  4. * Xianghua Xiao (x.xiao@motorola.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /*
  25. * PCI Configuration space access support for MPC85xx PCI Bridge
  26. */
  27. #include <common.h>
  28. #include <asm/cpm_85xx.h>
  29. #include <pci.h>
  30. #if defined(CONFIG_PCI) && !defined(CONFIG_FSL_PCI_INIT)
  31. static struct pci_controller *pci_hose;
  32. void
  33. pci_mpc85xx_init(struct pci_controller *board_hose)
  34. {
  35. u16 reg16;
  36. u32 dev;
  37. volatile ccsr_pcix_t *pcix = (void *)(CONFIG_SYS_MPC85xx_PCIX_ADDR);
  38. #ifdef CONFIG_MPC85XX_PCI2
  39. volatile ccsr_pcix_t *pcix2 = (void *)(CONFIG_SYS_MPC85xx_PCIX2_ADDR);
  40. #endif
  41. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  42. struct pci_controller * hose;
  43. pci_hose = board_hose;
  44. hose = &pci_hose[0];
  45. hose->first_busno = 0;
  46. hose->last_busno = 0xff;
  47. pci_setup_indirect(hose,
  48. (CONFIG_SYS_IMMR+0x8000),
  49. (CONFIG_SYS_IMMR+0x8004));
  50. /*
  51. * Hose scan.
  52. */
  53. dev = PCI_BDF(hose->first_busno, 0, 0);
  54. pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
  55. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  56. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  57. /*
  58. * Clear non-reserved bits in status register.
  59. */
  60. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  61. if (!(gur->pordevsr & MPC85xx_PORDEVSR_PCI1)) {
  62. /* PCI-X init */
  63. if (CONFIG_SYS_CLK_FREQ < 66000000)
  64. printf("PCI-X will only work at 66 MHz\n");
  65. reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  66. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  67. pci_hose_write_config_word(hose, dev, PCIX_COMMAND, reg16);
  68. }
  69. pcix->potar1 = (CONFIG_SYS_PCI1_MEM_BASE >> 12) & 0x000fffff;
  70. pcix->potear1 = 0x00000000;
  71. pcix->powbar1 = (CONFIG_SYS_PCI1_MEM_PHYS >> 12) & 0x000fffff;
  72. pcix->powbear1 = 0x00000000;
  73. pcix->powar1 = (POWAR_EN | POWAR_MEM_READ |
  74. POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI1_MEM_SIZE) - 1));
  75. pcix->potar2 = (CONFIG_SYS_PCI1_IO_BASE >> 12) & 0x000fffff;
  76. pcix->potear2 = 0x00000000;
  77. pcix->powbar2 = (CONFIG_SYS_PCI1_IO_PHYS >> 12) & 0x000fffff;
  78. pcix->powbear2 = 0x00000000;
  79. pcix->powar2 = (POWAR_EN | POWAR_IO_READ |
  80. POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI1_IO_SIZE) - 1));
  81. pcix->pitar1 = 0x00000000;
  82. pcix->piwbar1 = 0x00000000;
  83. pcix->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
  84. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
  85. pcix->powar3 = 0;
  86. pcix->powar4 = 0;
  87. pcix->piwar2 = 0;
  88. pcix->piwar3 = 0;
  89. pci_set_region(hose->regions + 0,
  90. CONFIG_SYS_PCI1_MEM_BASE,
  91. CONFIG_SYS_PCI1_MEM_PHYS,
  92. CONFIG_SYS_PCI1_MEM_SIZE,
  93. PCI_REGION_MEM);
  94. pci_set_region(hose->regions + 1,
  95. CONFIG_SYS_PCI1_IO_BASE,
  96. CONFIG_SYS_PCI1_IO_PHYS,
  97. CONFIG_SYS_PCI1_IO_SIZE,
  98. PCI_REGION_IO);
  99. hose->region_count = 2;
  100. pci_register_hose(hose);
  101. #if defined(CONFIG_MPC8555CDS) || defined(CONFIG_MPC8541CDS)
  102. /*
  103. * This is a SW workaround for an apparent HW problem
  104. * in the PCI controller on the MPC85555/41 CDS boards.
  105. * The first config cycle must be to a valid, known
  106. * device on the PCI bus in order to trick the PCI
  107. * controller state machine into a known valid state.
  108. * Without this, the first config cycle has the chance
  109. * of hanging the controller permanently, just leaving
  110. * it in a semi-working state, or leaving it working.
  111. *
  112. * Pick on the Tundra, Device 17, to get it right.
  113. */
  114. {
  115. u8 header_type;
  116. pci_hose_read_config_byte(hose,
  117. PCI_BDF(0,BRIDGE_ID,0),
  118. PCI_HEADER_TYPE,
  119. &header_type);
  120. }
  121. #endif
  122. hose->last_busno = pci_hose_scan(hose);
  123. #ifdef CONFIG_MPC85XX_PCI2
  124. hose = &pci_hose[1];
  125. hose->first_busno = pci_hose[0].last_busno + 1;
  126. hose->last_busno = 0xff;
  127. pci_setup_indirect(hose,
  128. (CONFIG_SYS_IMMR+0x9000),
  129. (CONFIG_SYS_IMMR+0x9004));
  130. dev = PCI_BDF(hose->first_busno, 0, 0);
  131. pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
  132. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  133. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  134. /*
  135. * Clear non-reserved bits in status register.
  136. */
  137. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  138. pcix2->potar1 = (CONFIG_SYS_PCI2_MEM_BASE >> 12) & 0x000fffff;
  139. pcix2->potear1 = 0x00000000;
  140. pcix2->powbar1 = (CONFIG_SYS_PCI2_MEM_PHYS >> 12) & 0x000fffff;
  141. pcix2->powbear1 = 0x00000000;
  142. pcix2->powar1 = (POWAR_EN | POWAR_MEM_READ |
  143. POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI2_MEM_SIZE) - 1));
  144. pcix2->potar2 = (CONFIG_SYS_PCI2_IO_BASE >> 12) & 0x000fffff;
  145. pcix2->potear2 = 0x00000000;
  146. pcix2->powbar2 = (CONFIG_SYS_PCI2_IO_PHYS >> 12) & 0x000fffff;
  147. pcix2->powbear2 = 0x00000000;
  148. pcix2->powar2 = (POWAR_EN | POWAR_IO_READ |
  149. POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI2_IO_SIZE) - 1));
  150. pcix2->pitar1 = 0x00000000;
  151. pcix2->piwbar1 = 0x00000000;
  152. pcix2->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
  153. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
  154. pcix2->powar3 = 0;
  155. pcix2->powar4 = 0;
  156. pcix2->piwar2 = 0;
  157. pcix2->piwar3 = 0;
  158. pci_set_region(hose->regions + 0,
  159. CONFIG_SYS_PCI2_MEM_BASE,
  160. CONFIG_SYS_PCI2_MEM_PHYS,
  161. CONFIG_SYS_PCI2_MEM_SIZE,
  162. PCI_REGION_MEM);
  163. pci_set_region(hose->regions + 1,
  164. CONFIG_SYS_PCI2_IO_BASE,
  165. CONFIG_SYS_PCI2_IO_PHYS,
  166. CONFIG_SYS_PCI2_IO_SIZE,
  167. PCI_REGION_IO);
  168. hose->region_count = 2;
  169. /*
  170. * Hose scan.
  171. */
  172. pci_register_hose(hose);
  173. hose->last_busno = pci_hose_scan(hose);
  174. #endif
  175. }
  176. #endif /* CONFIG_PCI */