pci.c 11 KB

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