pci.c 10 KB

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