pci.c 9.7 KB

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