pci.c 11 KB

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