pci.c 11 KB

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