pci.c 8.9 KB

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