pci.c 9.9 KB

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