pci.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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)
  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 immap_t *immap = (immap_t *)CFG_CCSRBAR;
  38. volatile ccsr_pcix_t *pcix = &immap->im_pcix;
  39. volatile ccsr_pcix_t *pcix2 = &immap->im_pcix2;
  40. volatile ccsr_gur_t *gur = &immap->im_gur;
  41. struct pci_controller * hose;
  42. pci_hose = board_hose;
  43. hose = &pci_hose[0];
  44. hose->first_busno = 0;
  45. hose->last_busno = 0xff;
  46. pci_setup_indirect(hose,
  47. (CFG_IMMR+0x8000),
  48. (CFG_IMMR+0x8004));
  49. /*
  50. * Hose scan.
  51. */
  52. dev = PCI_BDF(hose->first_busno, 0, 0);
  53. pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
  54. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  55. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  56. /*
  57. * Clear non-reserved bits in status register.
  58. */
  59. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  60. if (!(gur->pordevsr & PORDEVSR_PCI)) {
  61. /* PCI-X init */
  62. if (CONFIG_SYS_CLK_FREQ < 66000000)
  63. printf("PCI-X will only work at 66 MHz\n");
  64. reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
  65. | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
  66. pci_hose_write_config_word(hose, dev, PCIX_COMMAND, reg16);
  67. }
  68. pcix->potar1 = (CFG_PCI1_MEM_BASE >> 12) & 0x000fffff;
  69. pcix->potear1 = 0x00000000;
  70. pcix->powbar1 = (CFG_PCI1_MEM_PHYS >> 12) & 0x000fffff;
  71. pcix->powbear1 = 0x00000000;
  72. pcix->powar1 = (POWAR_EN | POWAR_MEM_READ |
  73. POWAR_MEM_WRITE | POWAR_MEM_512M);
  74. pcix->potar2 = (CFG_PCI1_IO_BASE >> 12) & 0x000fffff;
  75. pcix->potear2 = 0x00000000;
  76. pcix->powbar2 = (CFG_PCI1_IO_PHYS >> 12) & 0x000fffff;
  77. pcix->powbear2 = 0x00000000;
  78. pcix->powar2 = (POWAR_EN | POWAR_IO_READ |
  79. POWAR_IO_WRITE | POWAR_IO_1M);
  80. pcix->pitar1 = 0x00000000;
  81. pcix->piwbar1 = 0x00000000;
  82. pcix->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
  83. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
  84. pcix->powar3 = 0;
  85. pcix->powar4 = 0;
  86. pcix->piwar2 = 0;
  87. pcix->piwar3 = 0;
  88. pci_set_region(hose->regions + 0,
  89. CFG_PCI1_MEM_BASE,
  90. CFG_PCI1_MEM_PHYS,
  91. CFG_PCI1_MEM_SIZE,
  92. PCI_REGION_MEM);
  93. pci_set_region(hose->regions + 1,
  94. CFG_PCI1_IO_BASE,
  95. CFG_PCI1_IO_PHYS,
  96. CFG_PCI1_IO_SIZE,
  97. PCI_REGION_IO);
  98. hose->region_count = 2;
  99. pci_register_hose(hose);
  100. #if defined(CONFIG_MPC8555CDS) || defined(CONFIG_MPC8541CDS)
  101. /*
  102. * This is a SW workaround for an apparent HW problem
  103. * in the PCI controller on the MPC85555/41 CDS boards.
  104. * The first config cycle must be to a valid, known
  105. * device on the PCI bus in order to trick the PCI
  106. * controller state machine into a known valid state.
  107. * Without this, the first config cycle has the chance
  108. * of hanging the controller permanently, just leaving
  109. * it in a semi-working state, or leaving it working.
  110. *
  111. * Pick on the Tundra, Device 17, to get it right.
  112. */
  113. {
  114. u8 header_type;
  115. pci_hose_read_config_byte(hose,
  116. PCI_BDF(0,17,0),
  117. PCI_HEADER_TYPE,
  118. &header_type);
  119. }
  120. #endif
  121. hose->last_busno = pci_hose_scan(hose);
  122. #ifdef CONFIG_MPC85XX_PCI2
  123. hose = &pci_hose[1];
  124. hose->first_busno = pci_hose[0].last_busno + 1;
  125. hose->last_busno = 0xff;
  126. pci_setup_indirect(hose,
  127. (CFG_IMMR+0x9000),
  128. (CFG_IMMR+0x9004));
  129. dev = PCI_BDF(hose->first_busno, 0, 0);
  130. pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
  131. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  132. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  133. /*
  134. * Clear non-reserved bits in status register.
  135. */
  136. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  137. pcix2->potar1 = (CFG_PCI2_MEM_BASE >> 12) & 0x000fffff;
  138. pcix2->potear1 = 0x00000000;
  139. pcix2->powbar1 = (CFG_PCI2_MEM_PHYS >> 12) & 0x000fffff;
  140. pcix2->powbear1 = 0x00000000;
  141. pcix2->powar1 = (POWAR_EN | POWAR_MEM_READ |
  142. POWAR_MEM_WRITE | POWAR_MEM_512M);
  143. pcix2->potar2 = (CFG_PCI2_IO_BASE >> 12) & 0x000fffff;
  144. pcix2->potear2 = 0x00000000;
  145. pcix2->powbar2 = (CFG_PCI2_IO_PHYS >> 12) & 0x000fffff;
  146. pcix2->powbear2 = 0x00000000;
  147. pcix2->powar2 = (POWAR_EN | POWAR_IO_READ |
  148. POWAR_IO_WRITE | POWAR_IO_1M);
  149. pcix2->pitar1 = 0x00000000;
  150. pcix2->piwbar1 = 0x00000000;
  151. pcix2->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
  152. PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
  153. pcix2->powar3 = 0;
  154. pcix2->powar4 = 0;
  155. pcix2->piwar2 = 0;
  156. pcix2->piwar3 = 0;
  157. pci_set_region(hose->regions + 0,
  158. CFG_PCI2_MEM_BASE,
  159. CFG_PCI2_MEM_PHYS,
  160. CFG_PCI2_MEM_SIZE,
  161. PCI_REGION_MEM);
  162. pci_set_region(hose->regions + 1,
  163. CFG_PCI2_IO_BASE,
  164. CFG_PCI2_IO_PHYS,
  165. CFG_PCI2_IO_SIZE,
  166. PCI_REGION_IO);
  167. hose->region_count = 2;
  168. /*
  169. * Hose scan.
  170. */
  171. pci_register_hose(hose);
  172. hose->last_busno = pci_hose_scan(hose);
  173. #endif
  174. }
  175. #ifdef CONFIG_OF_FLAT_TREE
  176. void
  177. ft_pci_setup(void *blob, bd_t *bd)
  178. {
  179. u32 *p;
  180. int len;
  181. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8000/bus-range", &len);
  182. if (p != NULL) {
  183. p[0] = pci_hose[0].first_busno;
  184. p[1] = pci_hose[0].last_busno;
  185. }
  186. #ifdef CONFIG_MPC85XX_PCI2
  187. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@9000/bus-range", &len);
  188. if (p != NULL) {
  189. p[0] = pci_hose[1].first_busno;
  190. p[1] = pci_hose[1].last_busno;
  191. }
  192. #endif
  193. }
  194. #endif /* CONFIG_OF_FLAT_TREE */
  195. #endif /* CONFIG_PCI */