pci.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * pci.c -- WindRiver SBC8349 PCI board support.
  3. * Copyright (c) 2006 Wind River Systems, Inc.
  4. *
  5. * Based on MPC8349 PCI support but w/o PIB related code.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. *
  25. */
  26. #include <asm/mmu.h>
  27. #include <common.h>
  28. #include <asm/global_data.h>
  29. #include <pci.h>
  30. #include <asm/mpc8349_pci.h>
  31. #include <i2c.h>
  32. #if defined(CONFIG_OF_LIBFDT)
  33. #include <libfdt.h>
  34. #include <fdt_support.h>
  35. #endif
  36. DECLARE_GLOBAL_DATA_PTR;
  37. #ifdef CONFIG_PCI
  38. /* System RAM mapped to PCI space */
  39. #define CONFIG_PCI_SYS_MEM_BUS CONFIG_SYS_SDRAM_BASE
  40. #define CONFIG_PCI_SYS_MEM_PHYS CONFIG_SYS_SDRAM_BASE
  41. #ifndef CONFIG_PCI_PNP
  42. static struct pci_config_table pci_mpc8349emds_config_table[] = {
  43. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  44. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  45. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  46. PCI_ENET0_MEMADDR,
  47. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  48. }
  49. },
  50. {}
  51. };
  52. #endif
  53. static struct pci_controller pci_hose[] = {
  54. {
  55. #ifndef CONFIG_PCI_PNP
  56. config_table:pci_mpc8349emds_config_table,
  57. #endif
  58. },
  59. {
  60. #ifndef CONFIG_PCI_PNP
  61. config_table:pci_mpc8349emds_config_table,
  62. #endif
  63. }
  64. };
  65. /**************************************************************************
  66. * pci_init_board()
  67. *
  68. * NOTICE: PCI2 is not supported. There is only one
  69. * physical PCI slot on the board.
  70. *
  71. */
  72. void
  73. pci_init_board(void)
  74. {
  75. volatile immap_t * immr;
  76. volatile clk83xx_t * clk;
  77. volatile law83xx_t * pci_law;
  78. volatile pot83xx_t * pci_pot;
  79. volatile pcictrl83xx_t * pci_ctrl;
  80. volatile pciconf83xx_t * pci_conf;
  81. u16 reg16;
  82. u32 reg32;
  83. u32 dev;
  84. struct pci_controller * hose;
  85. immr = (immap_t *)CONFIG_SYS_IMMR;
  86. clk = (clk83xx_t *)&immr->clk;
  87. pci_law = immr->sysconf.pcilaw;
  88. pci_pot = immr->ios.pot;
  89. pci_ctrl = immr->pci_ctrl;
  90. pci_conf = immr->pci_conf;
  91. hose = &pci_hose[0];
  92. /*
  93. * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
  94. */
  95. reg32 = clk->occr;
  96. udelay(2000);
  97. clk->occr = 0xff000000;
  98. udelay(2000);
  99. /*
  100. * Release PCI RST Output signal
  101. */
  102. pci_ctrl[0].gcr = 0;
  103. udelay(2000);
  104. pci_ctrl[0].gcr = 1;
  105. #ifdef CONFIG_MPC83XX_PCI2
  106. pci_ctrl[1].gcr = 0;
  107. udelay(2000);
  108. pci_ctrl[1].gcr = 1;
  109. #endif
  110. /* We need to wait at least a 1sec based on PCI specs */
  111. {
  112. int i;
  113. for (i = 0; i < 1000; ++i)
  114. udelay (1000);
  115. }
  116. /*
  117. * Configure PCI Local Access Windows
  118. */
  119. pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
  120. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  121. pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
  122. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
  123. /*
  124. * Configure PCI Outbound Translation Windows
  125. */
  126. /* PCI1 mem space - prefetch */
  127. pci_pot[0].potar = (CONFIG_SYS_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
  128. pci_pot[0].pobar = (CONFIG_SYS_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
  129. pci_pot[0].pocmr = POCMR_EN | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  130. /* PCI1 IO space */
  131. pci_pot[1].potar = (CONFIG_SYS_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
  132. pci_pot[1].pobar = (CONFIG_SYS_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
  133. pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
  134. /* PCI1 mmio - non-prefetch mem space */
  135. pci_pot[2].potar = (CONFIG_SYS_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK;
  136. pci_pot[2].pobar = (CONFIG_SYS_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  137. pci_pot[2].pocmr = POCMR_EN | (POCMR_CM_256M & 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 | (__ilog2(gd->ram_size) - 1);
  147. hose->first_busno = 0;
  148. hose->last_busno = 0xff;
  149. /* PCI memory prefetch 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|PCI_REGION_PREFETCH);
  155. /* PCI memory space */
  156. pci_set_region(hose->regions + 1,
  157. CONFIG_SYS_PCI1_MMIO_BASE,
  158. CONFIG_SYS_PCI1_MMIO_PHYS,
  159. CONFIG_SYS_PCI1_MMIO_SIZE,
  160. PCI_REGION_MEM);
  161. /* PCI IO space */
  162. pci_set_region(hose->regions + 2,
  163. CONFIG_SYS_PCI1_IO_BASE,
  164. CONFIG_SYS_PCI1_IO_PHYS,
  165. CONFIG_SYS_PCI1_IO_SIZE,
  166. PCI_REGION_IO);
  167. /* System memory space */
  168. pci_set_region(hose->regions + 3,
  169. CONFIG_PCI_SYS_MEM_BUS,
  170. CONFIG_PCI_SYS_MEM_PHYS,
  171. gd->ram_size,
  172. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  173. hose->region_count = 4;
  174. pci_setup_indirect(hose,
  175. (CONFIG_SYS_IMMR+0x8300),
  176. (CONFIG_SYS_IMMR+0x8304));
  177. pci_register_hose(hose);
  178. /*
  179. * Write to Command register
  180. */
  181. reg16 = 0xff;
  182. dev = PCI_BDF(hose->first_busno, 0, 0);
  183. pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
  184. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  185. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  186. /*
  187. * Clear non-reserved bits in status register.
  188. */
  189. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  190. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  191. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  192. #ifdef CONFIG_PCI_SCAN_SHOW
  193. printf("PCI: Bus Dev VenId DevId Class Int\n");
  194. #endif
  195. /*
  196. * Hose scan.
  197. */
  198. hose->last_busno = pci_hose_scan(hose);
  199. #ifdef CONFIG_MPC83XX_PCI2
  200. hose = &pci_hose[1];
  201. /*
  202. * Configure PCI Outbound Translation Windows
  203. */
  204. /* PCI2 mem space - prefetch */
  205. pci_pot[3].potar = (CONFIG_SYS_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
  206. pci_pot[3].pobar = (CONFIG_SYS_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
  207. pci_pot[3].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  208. /* PCI2 IO space */
  209. pci_pot[4].potar = (CONFIG_SYS_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
  210. pci_pot[4].pobar = (CONFIG_SYS_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
  211. pci_pot[4].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
  212. /* PCI2 mmio - non-prefetch mem space */
  213. pci_pot[5].potar = (CONFIG_SYS_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK;
  214. pci_pot[5].pobar = (CONFIG_SYS_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  215. pci_pot[5].pocmr = POCMR_EN | POCMR_PCI2 | (POCMR_CM_256M & POCMR_CM_MASK);
  216. /*
  217. * Configure PCI Inbound Translation Windows
  218. */
  219. /* we need RAM mapped to PCI space for the devices to
  220. * access main memory */
  221. pci_ctrl[1].pitar1 = 0x0;
  222. pci_ctrl[1].pibar1 = 0x0;
  223. pci_ctrl[1].piebar1 = 0x0;
  224. pci_ctrl[1].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
  225. hose->first_busno = pci_hose[0].last_busno + 1;
  226. hose->last_busno = 0xff;
  227. /* PCI memory prefetch space */
  228. pci_set_region(hose->regions + 0,
  229. CONFIG_SYS_PCI2_MEM_BASE,
  230. CONFIG_SYS_PCI2_MEM_PHYS,
  231. CONFIG_SYS_PCI2_MEM_SIZE,
  232. PCI_REGION_MEM|PCI_REGION_PREFETCH);
  233. /* PCI memory space */
  234. pci_set_region(hose->regions + 1,
  235. CONFIG_SYS_PCI2_MMIO_BASE,
  236. CONFIG_SYS_PCI2_MMIO_PHYS,
  237. CONFIG_SYS_PCI2_MMIO_SIZE,
  238. PCI_REGION_MEM);
  239. /* PCI IO space */
  240. pci_set_region(hose->regions + 2,
  241. CONFIG_SYS_PCI2_IO_BASE,
  242. CONFIG_SYS_PCI2_IO_PHYS,
  243. CONFIG_SYS_PCI2_IO_SIZE,
  244. PCI_REGION_IO);
  245. /* System memory space */
  246. pci_set_region(hose->regions + 3,
  247. CONFIG_PCI_SYS_MEM_BUS,
  248. CONFIG_PCI_SYS_MEM_PHYS,
  249. gd->ram_size,
  250. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  251. hose->region_count = 4;
  252. pci_setup_indirect(hose,
  253. (CONFIG_SYS_IMMR+0x8380),
  254. (CONFIG_SYS_IMMR+0x8384));
  255. pci_register_hose(hose);
  256. /*
  257. * Write to Command register
  258. */
  259. reg16 = 0xff;
  260. dev = PCI_BDF(hose->first_busno, 0, 0);
  261. pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
  262. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  263. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  264. /*
  265. * Clear non-reserved bits in status register.
  266. */
  267. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  268. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  269. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  270. /*
  271. * Hose scan.
  272. */
  273. hose->last_busno = pci_hose_scan(hose);
  274. #endif
  275. }
  276. #if defined(CONFIG_OF_LIBFDT)
  277. void ft_pci_setup(void *blob, bd_t *bd)
  278. {
  279. int nodeoffset;
  280. int tmp[2];
  281. const char *path;
  282. nodeoffset = fdt_path_offset(blob, "/aliases");
  283. if (nodeoffset >= 0) {
  284. path = fdt_getprop(blob, nodeoffset, "pci0", NULL);
  285. if (path) {
  286. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  287. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  288. do_fixup_by_path(blob, path, "bus-range",
  289. &tmp, sizeof(tmp), 1);
  290. tmp[0] = cpu_to_be32(gd->pci_clk);
  291. do_fixup_by_path(blob, path, "clock-frequency",
  292. &tmp, sizeof(tmp[0]), 1);
  293. }
  294. #ifdef CONFIG_MPC83XX_PCI2
  295. path = fdt_getprop(blob, nodeoffset, "pci1", NULL);
  296. if (path) {
  297. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  298. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  299. do_fixup_by_path(blob, path, "bus-range",
  300. &tmp, sizeof(tmp), 1);
  301. tmp[0] = cpu_to_be32(gd->pci_clk);
  302. do_fixup_by_path(blob, path, "clock-frequency",
  303. &tmp, sizeof(tmp[0]), 1);
  304. }
  305. #endif
  306. }
  307. }
  308. #endif /* CONFIG_OF_LIBFDT */
  309. #endif /* CONFIG_PCI */