pci.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * Copyright (C) Freescale Semiconductor, Inc. 2006. All rights reserved.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #ifdef CONFIG_PCI
  24. #include <asm/mmu.h>
  25. #include <asm/global_data.h>
  26. #include <pci.h>
  27. #include <asm/mpc8349_pci.h>
  28. #include <i2c.h>
  29. DECLARE_GLOBAL_DATA_PTR;
  30. /* System RAM mapped to PCI space */
  31. #define CONFIG_PCI_SYS_MEM_BUS CFG_SDRAM_BASE
  32. #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE
  33. #ifndef CONFIG_PCI_PNP
  34. static struct pci_config_table pci_mpc8349itx_config_table[] = {
  35. {
  36. PCI_ANY_ID,
  37. PCI_ANY_ID,
  38. PCI_ANY_ID,
  39. PCI_ANY_ID,
  40. PCI_IDSEL_NUMBER,
  41. PCI_ANY_ID,
  42. pci_cfgfunc_config_device,
  43. {
  44. PCI_ENET0_IOADDR,
  45. PCI_ENET0_MEMADDR,
  46. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}
  47. },
  48. {}
  49. };
  50. #endif
  51. static struct pci_controller pci_hose[] = {
  52. {
  53. #ifndef CONFIG_PCI_PNP
  54. config_table:pci_mpc8349itx_config_table,
  55. #endif
  56. },
  57. {
  58. #ifndef CONFIG_PCI_PNP
  59. config_table:pci_mpc8349itx_config_table,
  60. #endif
  61. }
  62. };
  63. /**************************************************************************
  64. * pci_init_board()
  65. *
  66. * NOTICE: PCI2 is not currently supported
  67. *
  68. */
  69. void 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. u8 reg8;
  78. u16 reg16;
  79. u32 reg32;
  80. u32 dev;
  81. struct pci_controller *hose;
  82. immr = (immap_t *) CFG_IMMRBAR;
  83. clk = (clk83xx_t *) & immr->clk;
  84. pci_law = immr->sysconf.pcilaw;
  85. pci_pot = immr->ios.pot;
  86. pci_ctrl = immr->pci_ctrl;
  87. pci_conf = immr->pci_conf;
  88. hose = &pci_hose[0];
  89. /*
  90. * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
  91. */
  92. reg32 = clk->occr;
  93. udelay(2000);
  94. #ifdef CONFIG_HARD_I2C
  95. i2c_set_bus_num(I2C_BUS_2);
  96. /* Read the PCI_M66EN jumper setting */
  97. if ((i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &reg8, sizeof(reg8)) == 0) ||
  98. (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &reg8, sizeof(reg8)) == 0)) {
  99. if (reg8 & I2C_8574_PCI66)
  100. clk->occr = 0xff000000; /* 66 MHz PCI */
  101. else
  102. clk->occr = 0xff600001; /* 33 MHz PCI */
  103. } else {
  104. clk->occr = 0xff600001; /* 33 MHz PCI */
  105. }
  106. #else
  107. clk->occr = 0xff000000; /* 66 MHz PCI */
  108. #endif
  109. udelay(2000);
  110. /*
  111. * Release PCI RST Output signal
  112. */
  113. pci_ctrl[0].gcr = 0;
  114. udelay(2000);
  115. pci_ctrl[0].gcr = 1;
  116. #ifdef CONFIG_MPC83XX_PCI2
  117. pci_ctrl[1].gcr = 0;
  118. udelay(2000);
  119. pci_ctrl[1].gcr = 1;
  120. #endif
  121. /* We need to wait at least a 1sec based on PCI specs */
  122. {
  123. int i;
  124. for (i = 0; i < 1000; i++)
  125. udelay(1000);
  126. }
  127. /*
  128. * Configure PCI Local Access Windows
  129. */
  130. pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
  131. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  132. pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
  133. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
  134. /*
  135. * Configure PCI Outbound Translation Windows
  136. */
  137. /* PCI1 mem space - prefetch */
  138. pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
  139. pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
  140. pci_pot[0].pocmr =
  141. POCMR_EN | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  142. /* PCI1 IO space */
  143. pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
  144. pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
  145. pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
  146. /* PCI1 mmio - non-prefetch mem space */
  147. pci_pot[2].potar = (CFG_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK;
  148. pci_pot[2].pobar = (CFG_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  149. pci_pot[2].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  150. /*
  151. * Configure PCI Inbound Translation Windows
  152. */
  153. /* we need RAM mapped to PCI space for the devices to
  154. * access main memory */
  155. pci_ctrl[0].pitar1 = 0x0;
  156. pci_ctrl[0].pibar1 = 0x0;
  157. pci_ctrl[0].piebar1 = 0x0;
  158. pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  159. PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
  160. hose->first_busno = 0;
  161. hose->last_busno = 0xff;
  162. /* PCI memory prefetch space */
  163. pci_set_region(hose->regions + 0,
  164. CFG_PCI1_MEM_BASE,
  165. CFG_PCI1_MEM_PHYS,
  166. CFG_PCI1_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
  167. /* PCI memory space */
  168. pci_set_region(hose->regions + 1,
  169. CFG_PCI1_MMIO_BASE,
  170. CFG_PCI1_MMIO_PHYS, CFG_PCI1_MMIO_SIZE, PCI_REGION_MEM);
  171. /* PCI IO space */
  172. pci_set_region(hose->regions + 2,
  173. CFG_PCI1_IO_BASE,
  174. CFG_PCI1_IO_PHYS, CFG_PCI1_IO_SIZE, PCI_REGION_IO);
  175. /* System memory space */
  176. pci_set_region(hose->regions + 3,
  177. CONFIG_PCI_SYS_MEM_BUS,
  178. CONFIG_PCI_SYS_MEM_PHYS,
  179. gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
  180. hose->region_count = 4;
  181. pci_setup_indirect(hose,
  182. (CFG_IMMRBAR + 0x8300), (CFG_IMMRBAR + 0x8304));
  183. pci_register_hose(hose);
  184. /*
  185. * Write to Command register
  186. */
  187. reg16 = 0xff;
  188. dev = PCI_BDF(hose->first_busno, 0, 0);
  189. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
  190. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  191. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  192. /*
  193. * Clear non-reserved bits in status register.
  194. */
  195. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  196. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  197. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  198. #ifdef CONFIG_PCI_SCAN_SHOW
  199. printf("PCI: Bus Dev VenId DevId Class Int\n");
  200. #endif
  201. /*
  202. * Hose scan.
  203. */
  204. hose->last_busno = pci_hose_scan(hose);
  205. #ifdef CONFIG_MPC83XX_PCI2
  206. hose = &pci_hose[1];
  207. /*
  208. * Configure PCI Outbound Translation Windows
  209. */
  210. /* PCI2 mem space - prefetch */
  211. pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
  212. pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
  213. pci_pot[3].pocmr =
  214. POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | (POCMR_CM_256M &
  215. POCMR_CM_MASK);
  216. /* PCI2 IO space */
  217. pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
  218. pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
  219. pci_pot[4].pocmr =
  220. POCMR_EN | POCMR_PCI2 | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
  221. /* PCI2 mmio - non-prefetch mem space */
  222. pci_pot[5].potar = (CFG_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK;
  223. pci_pot[5].pobar = (CFG_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  224. pci_pot[5].pocmr =
  225. POCMR_EN | POCMR_PCI2 | (POCMR_CM_256M & POCMR_CM_MASK);
  226. /*
  227. * Configure PCI Inbound Translation Windows
  228. */
  229. /* we need RAM mapped to PCI space for the devices to
  230. * access main memory */
  231. pci_ctrl[1].pitar1 = 0x0;
  232. pci_ctrl[1].pibar1 = 0x0;
  233. pci_ctrl[1].piebar1 = 0x0;
  234. pci_ctrl[1].piwar1 =
  235. PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP |
  236. (__ilog2(gd->ram_size) - 1);
  237. hose->first_busno = pci_hose[0].last_busno + 1;
  238. hose->last_busno = 0xff;
  239. /* PCI memory prefetch space */
  240. pci_set_region(hose->regions + 0,
  241. CFG_PCI2_MEM_BASE,
  242. CFG_PCI2_MEM_PHYS,
  243. CFG_PCI2_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
  244. /* PCI memory space */
  245. pci_set_region(hose->regions + 1,
  246. CFG_PCI2_MMIO_BASE,
  247. CFG_PCI2_MMIO_PHYS, CFG_PCI2_MMIO_SIZE, PCI_REGION_MEM);
  248. /* PCI IO space */
  249. pci_set_region(hose->regions + 2,
  250. CFG_PCI2_IO_BASE,
  251. CFG_PCI2_IO_PHYS, CFG_PCI2_IO_SIZE, PCI_REGION_IO);
  252. /* System memory space */
  253. pci_set_region(hose->regions + 3,
  254. CONFIG_PCI_SYS_MEM_BUS,
  255. CONFIG_PCI_SYS_MEM_PHYS,
  256. gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
  257. hose->region_count = 4;
  258. pci_setup_indirect(hose,
  259. (CFG_IMMRBAR + 0x8380), (CFG_IMMRBAR + 0x8384));
  260. pci_register_hose(hose);
  261. /*
  262. * Write to Command register
  263. */
  264. reg16 = 0xff;
  265. dev = PCI_BDF(hose->first_busno, 0, 0);
  266. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
  267. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  268. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  269. /*
  270. * Clear non-reserved bits in status register.
  271. */
  272. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  273. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  274. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  275. /*
  276. * Hose scan.
  277. */
  278. hose->last_busno = pci_hose_scan(hose);
  279. #endif
  280. }
  281. #endif /* CONFIG_PCI */