pci.c 10 KB

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