pci.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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_FLAT_TREE)
  33. #include <ft_build.h>
  34. #elif defined(CONFIG_OF_LIBFDT)
  35. #include <libfdt.h>
  36. #include <fdt_support.h>
  37. #endif
  38. DECLARE_GLOBAL_DATA_PTR;
  39. #ifdef CONFIG_PCI
  40. /* System RAM mapped to PCI space */
  41. #define CONFIG_PCI_SYS_MEM_BUS CFG_SDRAM_BASE
  42. #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE
  43. #ifndef CONFIG_PCI_PNP
  44. static struct pci_config_table pci_mpc8349emds_config_table[] = {
  45. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  46. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  47. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  48. PCI_ENET0_MEMADDR,
  49. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
  50. }
  51. },
  52. {}
  53. };
  54. #endif
  55. static struct pci_controller pci_hose[] = {
  56. {
  57. #ifndef CONFIG_PCI_PNP
  58. config_table:pci_mpc8349emds_config_table,
  59. #endif
  60. },
  61. {
  62. #ifndef CONFIG_PCI_PNP
  63. config_table:pci_mpc8349emds_config_table,
  64. #endif
  65. }
  66. };
  67. /**************************************************************************
  68. * pci_init_board()
  69. *
  70. * NOTICE: PCI2 is not supported. There is only one
  71. * physical PCI slot on the board.
  72. *
  73. */
  74. void
  75. pci_init_board(void)
  76. {
  77. volatile immap_t * immr;
  78. volatile clk83xx_t * clk;
  79. volatile law83xx_t * pci_law;
  80. volatile pot83xx_t * pci_pot;
  81. volatile pcictrl83xx_t * pci_ctrl;
  82. volatile pciconf83xx_t * pci_conf;
  83. u16 reg16;
  84. u32 reg32;
  85. u32 dev;
  86. struct pci_controller * hose;
  87. immr = (immap_t *)CFG_IMMR;
  88. clk = (clk83xx_t *)&immr->clk;
  89. pci_law = immr->sysconf.pcilaw;
  90. pci_pot = immr->ios.pot;
  91. pci_ctrl = immr->pci_ctrl;
  92. pci_conf = immr->pci_conf;
  93. hose = &pci_hose[0];
  94. /*
  95. * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
  96. */
  97. reg32 = clk->occr;
  98. udelay(2000);
  99. clk->occr = 0xff000000;
  100. udelay(2000);
  101. /*
  102. * Release PCI RST Output signal
  103. */
  104. pci_ctrl[0].gcr = 0;
  105. udelay(2000);
  106. pci_ctrl[0].gcr = 1;
  107. #ifdef CONFIG_MPC83XX_PCI2
  108. pci_ctrl[1].gcr = 0;
  109. udelay(2000);
  110. pci_ctrl[1].gcr = 1;
  111. #endif
  112. /* We need to wait at least a 1sec based on PCI specs */
  113. {
  114. int i;
  115. for (i = 0; i < 1000; ++i)
  116. udelay (1000);
  117. }
  118. /*
  119. * Configure PCI Local Access Windows
  120. */
  121. pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
  122. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  123. pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
  124. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
  125. /*
  126. * Configure PCI Outbound Translation Windows
  127. */
  128. /* PCI1 mem space - prefetch */
  129. pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
  130. pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
  131. pci_pot[0].pocmr = POCMR_EN | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  132. /* PCI1 IO space */
  133. pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
  134. pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
  135. pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
  136. /* PCI1 mmio - non-prefetch mem space */
  137. pci_pot[2].potar = (CFG_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK;
  138. pci_pot[2].pobar = (CFG_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  139. pci_pot[2].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  140. /*
  141. * Configure PCI Inbound Translation Windows
  142. */
  143. /* we need RAM mapped to PCI space for the devices to
  144. * access main memory */
  145. pci_ctrl[0].pitar1 = 0x0;
  146. pci_ctrl[0].pibar1 = 0x0;
  147. pci_ctrl[0].piebar1 = 0x0;
  148. pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
  149. hose->first_busno = 0;
  150. hose->last_busno = 0xff;
  151. /* PCI memory prefetch space */
  152. pci_set_region(hose->regions + 0,
  153. CFG_PCI1_MEM_BASE,
  154. CFG_PCI1_MEM_PHYS,
  155. CFG_PCI1_MEM_SIZE,
  156. PCI_REGION_MEM|PCI_REGION_PREFETCH);
  157. /* PCI memory space */
  158. pci_set_region(hose->regions + 1,
  159. CFG_PCI1_MMIO_BASE,
  160. CFG_PCI1_MMIO_PHYS,
  161. CFG_PCI1_MMIO_SIZE,
  162. PCI_REGION_MEM);
  163. /* PCI IO space */
  164. pci_set_region(hose->regions + 2,
  165. CFG_PCI1_IO_BASE,
  166. CFG_PCI1_IO_PHYS,
  167. CFG_PCI1_IO_SIZE,
  168. PCI_REGION_IO);
  169. /* System memory space */
  170. pci_set_region(hose->regions + 3,
  171. CONFIG_PCI_SYS_MEM_BUS,
  172. CONFIG_PCI_SYS_MEM_PHYS,
  173. gd->ram_size,
  174. PCI_REGION_MEM | PCI_REGION_MEMORY);
  175. hose->region_count = 4;
  176. pci_setup_indirect(hose,
  177. (CFG_IMMR+0x8300),
  178. (CFG_IMMR+0x8304));
  179. pci_register_hose(hose);
  180. /*
  181. * Write to Command register
  182. */
  183. reg16 = 0xff;
  184. dev = PCI_BDF(hose->first_busno, 0, 0);
  185. pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
  186. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  187. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  188. /*
  189. * Clear non-reserved bits in status register.
  190. */
  191. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  192. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  193. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  194. #ifdef CONFIG_PCI_SCAN_SHOW
  195. printf("PCI: Bus Dev VenId DevId Class Int\n");
  196. #endif
  197. /*
  198. * Hose scan.
  199. */
  200. hose->last_busno = pci_hose_scan(hose);
  201. #ifdef CONFIG_MPC83XX_PCI2
  202. hose = &pci_hose[1];
  203. /*
  204. * Configure PCI Outbound Translation Windows
  205. */
  206. /* PCI2 mem space - prefetch */
  207. pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
  208. pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
  209. pci_pot[3].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  210. /* PCI2 IO space */
  211. pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
  212. pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
  213. pci_pot[4].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
  214. /* PCI2 mmio - non-prefetch mem space */
  215. pci_pot[5].potar = (CFG_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK;
  216. pci_pot[5].pobar = (CFG_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  217. pci_pot[5].pocmr = POCMR_EN | POCMR_PCI2 | (POCMR_CM_256M & POCMR_CM_MASK);
  218. /*
  219. * Configure PCI Inbound Translation Windows
  220. */
  221. /* we need RAM mapped to PCI space for the devices to
  222. * access main memory */
  223. pci_ctrl[1].pitar1 = 0x0;
  224. pci_ctrl[1].pibar1 = 0x0;
  225. pci_ctrl[1].piebar1 = 0x0;
  226. pci_ctrl[1].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
  227. hose->first_busno = pci_hose[0].last_busno + 1;
  228. hose->last_busno = 0xff;
  229. /* PCI memory prefetch space */
  230. pci_set_region(hose->regions + 0,
  231. CFG_PCI2_MEM_BASE,
  232. CFG_PCI2_MEM_PHYS,
  233. CFG_PCI2_MEM_SIZE,
  234. PCI_REGION_MEM|PCI_REGION_PREFETCH);
  235. /* PCI memory space */
  236. pci_set_region(hose->regions + 1,
  237. CFG_PCI2_MMIO_BASE,
  238. CFG_PCI2_MMIO_PHYS,
  239. CFG_PCI2_MMIO_SIZE,
  240. PCI_REGION_MEM);
  241. /* PCI IO space */
  242. pci_set_region(hose->regions + 2,
  243. CFG_PCI2_IO_BASE,
  244. CFG_PCI2_IO_PHYS,
  245. CFG_PCI2_IO_SIZE,
  246. PCI_REGION_IO);
  247. /* System memory space */
  248. pci_set_region(hose->regions + 3,
  249. CONFIG_PCI_SYS_MEM_BUS,
  250. CONFIG_PCI_SYS_MEM_PHYS,
  251. gd->ram_size,
  252. PCI_REGION_MEM | PCI_REGION_MEMORY);
  253. hose->region_count = 4;
  254. pci_setup_indirect(hose,
  255. (CFG_IMMR+0x8380),
  256. (CFG_IMMR+0x8384));
  257. pci_register_hose(hose);
  258. /*
  259. * Write to Command register
  260. */
  261. reg16 = 0xff;
  262. dev = PCI_BDF(hose->first_busno, 0, 0);
  263. pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
  264. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  265. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  266. /*
  267. * Clear non-reserved bits in status register.
  268. */
  269. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  270. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  271. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  272. /*
  273. * Hose scan.
  274. */
  275. hose->last_busno = pci_hose_scan(hose);
  276. #endif
  277. }
  278. #if defined(CONFIG_OF_LIBFDT)
  279. void ft_pci_setup(void *blob, bd_t *bd)
  280. {
  281. int nodeoffset;
  282. int tmp[2];
  283. const char *path;
  284. nodeoffset = fdt_path_offset(blob, "/aliases");
  285. if (nodeoffset >= 0) {
  286. path = fdt_getprop(blob, nodeoffset, "pci0", NULL);
  287. if (path) {
  288. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  289. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  290. do_fixup_by_path(blob, path, "bus-range",
  291. &tmp, sizeof(tmp), 1);
  292. tmp[0] = cpu_to_be32(gd->pci_clk);
  293. do_fixup_by_path(blob, path, "clock-frequency",
  294. &tmp, sizeof(tmp[0]), 1);
  295. }
  296. #ifdef CONFIG_MPC83XX_PCI2
  297. path = fdt_getprop(blob, nodeoffset, "pci1", NULL);
  298. if (path) {
  299. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  300. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  301. do_fixup_by_path(blob, path, "bus-range",
  302. &tmp, sizeof(tmp), 1);
  303. tmp[0] = cpu_to_be32(gd->pci_clk);
  304. do_fixup_by_path(blob, path, "clock-frequency",
  305. &tmp, sizeof(tmp[0]), 1);
  306. }
  307. #endif
  308. }
  309. }
  310. #elif defined(CONFIG_OF_FLAT_TREE)
  311. void
  312. ft_pci_setup(void *blob, bd_t *bd)
  313. {
  314. u32 *p;
  315. int len;
  316. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
  317. if (p != NULL) {
  318. p[0] = pci_hose[0].first_busno;
  319. p[1] = pci_hose[0].last_busno;
  320. }
  321. #ifdef CONFIG_MPC83XX_PCI2
  322. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8600/bus-range", &len);
  323. if (p != NULL) {
  324. p[0] = pci_hose[1].first_busno;
  325. p[1] = pci_hose[1].last_busno;
  326. }
  327. #endif
  328. }
  329. #endif /* CONFIG_OF_FLAT_TREE */
  330. #endif /* CONFIG_PCI */