pci.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * (C) Copyright 2005
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. */
  24. #include <asm/mmu.h>
  25. #include <common.h>
  26. #include <asm/global_data.h>
  27. #include <pci.h>
  28. #include <asm/mpc8349_pci.h>
  29. #if defined(CONFIG_OF_LIBFDT)
  30. #include <libfdt.h>
  31. #include <fdt_support.h>
  32. #endif
  33. DECLARE_GLOBAL_DATA_PTR;
  34. #ifdef CONFIG_PCI
  35. /* System RAM mapped to PCI space */
  36. #define CONFIG_PCI_SYS_MEM_BUS CONFIG_SYS_SDRAM_BASE
  37. #define CONFIG_PCI_SYS_MEM_PHYS CONFIG_SYS_SDRAM_BASE
  38. #define CONFIG_PCI_SYS_MEM_SIZE (1024 * 1024 * 1024)
  39. #ifndef CONFIG_PCI_PNP
  40. static struct pci_config_table pci_tqm834x_config_table[] = {
  41. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  42. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  43. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  44. PCI_ENET0_MEMADDR,
  45. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  46. }
  47. },
  48. {}
  49. };
  50. #endif
  51. static struct pci_controller pci1_hose = {
  52. #ifndef CONFIG_PCI_PNP
  53. config_table:pci_tqm834x_config_table,
  54. #endif
  55. };
  56. /**************************************************************************
  57. * pci_init_board()
  58. *
  59. * NOTICE: MPC8349 internally has two PCI controllers (PCI1 and PCI2) but since
  60. * per TQM834x design physical connections to external devices (PCI sockets)
  61. * are routed only to the PCI1 we do not account for the second one - this code
  62. * supports PCI1 module only. Should support for the PCI2 be required in the
  63. * future it needs a separate pci_controller structure (above) and handling -
  64. * please refer to other boards' implementation for dual PCI host controllers,
  65. * for example board/Marvell/db64360/pci.c, pci_init_board()
  66. *
  67. */
  68. void
  69. pci_init_board(void)
  70. {
  71. volatile immap_t * immr;
  72. volatile clk83xx_t * clk;
  73. volatile law83xx_t * pci_law;
  74. volatile pot83xx_t * pci_pot;
  75. volatile pcictrl83xx_t * pci_ctrl;
  76. volatile pciconf83xx_t * pci_conf;
  77. u16 reg16;
  78. u32 reg32;
  79. struct pci_controller * hose;
  80. immr = (immap_t *)CONFIG_SYS_IMMR;
  81. clk = (clk83xx_t *)&immr->clk;
  82. pci_law = immr->sysconf.pcilaw;
  83. pci_pot = immr->ios.pot;
  84. pci_ctrl = immr->pci_ctrl;
  85. pci_conf = immr->pci_conf;
  86. hose = &pci1_hose;
  87. /*
  88. * Configure PCI controller and PCI_CLK_OUTPUT
  89. */
  90. /*
  91. * WARNING! only PCI_CLK_OUTPUT1 is enabled here as this is the one
  92. * line actually used for clocking all external PCI devices in TQM83xx.
  93. * Enabling other PCI_CLK_OUTPUT lines may lead to board's hang for
  94. * unknown reasons - particularly PCI_CLK_OUTPUT6 and PCI_CLK_OUTPUT7
  95. * are known to hang the board; this issue is under investigation
  96. * (13 oct 05)
  97. */
  98. reg32 = OCCR_PCICOE1;
  99. #if 0
  100. /* enabling all PCI_CLK_OUTPUT lines HANGS the board... */
  101. reg32 = 0xff000000;
  102. #endif
  103. if (clk->spmr & SPMR_CKID) {
  104. /* PCI Clock is half CONFIG_83XX_CLKIN so need to set up OCCR
  105. * fields accordingly */
  106. reg32 |= (OCCR_PCI1CR | OCCR_PCI2CR);
  107. reg32 |= (OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 \
  108. | OCCR_PCICD3 | OCCR_PCICD4 | OCCR_PCICD5 \
  109. | OCCR_PCICD6 | OCCR_PCICD7);
  110. }
  111. clk->occr = reg32;
  112. udelay(2000);
  113. /*
  114. * Release PCI RST Output signal
  115. */
  116. pci_ctrl[0].gcr = 0;
  117. udelay(2000);
  118. pci_ctrl[0].gcr = 1;
  119. udelay(2000);
  120. /*
  121. * Configure PCI Local Access Windows
  122. */
  123. pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
  124. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
  125. pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
  126. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_16M;
  127. /*
  128. * Configure PCI Outbound Translation Windows
  129. */
  130. /* PCI1 mem space */
  131. pci_pot[0].potar = (CONFIG_SYS_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
  132. pci_pot[0].pobar = (CONFIG_SYS_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
  133. pci_pot[0].pocmr = POCMR_EN | (POCMR_CM_512M & POCMR_CM_MASK);
  134. /* PCI1 IO space */
  135. pci_pot[1].potar = (CONFIG_SYS_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
  136. pci_pot[1].pobar = (CONFIG_SYS_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
  137. pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);
  138. /*
  139. * Configure PCI Inbound Translation Windows
  140. */
  141. /* we need RAM mapped to PCI space for the devices to
  142. * access main memory */
  143. pci_ctrl[0].pitar1 = 0x0;
  144. pci_ctrl[0].pibar1 = 0x0;
  145. pci_ctrl[0].piebar1 = 0x0;
  146. pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_256M;
  147. hose->first_busno = 0;
  148. hose->last_busno = 0xff;
  149. /* PCI memory space */
  150. pci_set_region(hose->regions + 0,
  151. CONFIG_SYS_PCI1_MEM_BASE,
  152. CONFIG_SYS_PCI1_MEM_PHYS,
  153. CONFIG_SYS_PCI1_MEM_SIZE,
  154. PCI_REGION_MEM);
  155. /* PCI IO space */
  156. pci_set_region(hose->regions + 1,
  157. CONFIG_SYS_PCI1_IO_BASE,
  158. CONFIG_SYS_PCI1_IO_PHYS,
  159. CONFIG_SYS_PCI1_IO_SIZE,
  160. PCI_REGION_IO);
  161. /* System memory space */
  162. pci_set_region(hose->regions + 2,
  163. CONFIG_PCI_SYS_MEM_BUS,
  164. CONFIG_PCI_SYS_MEM_PHYS,
  165. CONFIG_PCI_SYS_MEM_SIZE,
  166. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  167. hose->region_count = 3;
  168. pci_setup_indirect(hose,
  169. (CONFIG_SYS_IMMR+0x8300),
  170. (CONFIG_SYS_IMMR+0x8304));
  171. pci_register_hose(hose);
  172. /*
  173. * Write to Command register
  174. */
  175. reg16 = 0xff;
  176. pci_hose_read_config_word (hose, PCI_BDF(0,0,0), PCI_COMMAND,
  177. &reg16);
  178. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  179. pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_COMMAND,
  180. reg16);
  181. /*
  182. * Clear non-reserved bits in status register.
  183. */
  184. pci_hose_write_config_word(hose, PCI_BDF(0,0,0), PCI_STATUS,
  185. 0xffff);
  186. pci_hose_write_config_byte(hose, PCI_BDF(0,0,0), PCI_LATENCY_TIMER,
  187. 0x80);
  188. #ifdef CONFIG_PCI_SCAN_SHOW
  189. printf("PCI: Bus Dev VenId DevId Class Int\n");
  190. #endif
  191. /*
  192. * Hose scan.
  193. */
  194. hose->last_busno = pci_hose_scan(hose);
  195. }
  196. #if defined(CONFIG_OF_LIBFDT)
  197. void ft_pci_setup(void *blob, bd_t *bd)
  198. {
  199. int nodeoffset;
  200. int tmp[2];
  201. const char *path;
  202. nodeoffset = fdt_path_offset(blob, "/aliases");
  203. if (nodeoffset >= 0) {
  204. path = fdt_getprop(blob, nodeoffset, "pci0", NULL);
  205. if (path) {
  206. tmp[0] = cpu_to_be32(pci1_hose.first_busno);
  207. tmp[1] = cpu_to_be32(pci1_hose.last_busno);
  208. do_fixup_by_path(blob, path, "bus-range",
  209. &tmp, sizeof(tmp), 1);
  210. tmp[0] = cpu_to_be32(gd->pci_clk);
  211. do_fixup_by_path(blob, path, "clock-frequency",
  212. &tmp, sizeof(tmp[0]), 1);
  213. }
  214. #ifdef CONFIG_MPC83XX_PCI2
  215. path = fdt_getprop(blob, nodeoffset, "pci1", NULL);
  216. if (path) {
  217. tmp[0] = cpu_to_be32(pci2_hose.first_busno);
  218. tmp[1] = cpu_to_be32(pci2_hose.last_busno);
  219. do_fixup_by_path(blob, path, "bus-range",
  220. &tmp, sizeof(tmp), 1);
  221. tmp[0] = cpu_to_be32(gd->pci_clk);
  222. do_fixup_by_path(blob, path, "clock-frequency",
  223. &tmp, sizeof(tmp[0]), 1);
  224. }
  225. #endif
  226. }
  227. }
  228. #endif /* CONFIG_OF_LIBFDT */
  229. #endif /* CONFIG_PCI */