pci.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * Copyright (C) Freescale Semiconductor, Inc. 2006. All rights reserved.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #ifdef CONFIG_PCI
  24. #include <asm/mmu.h>
  25. #include <asm/global_data.h>
  26. #include <pci.h>
  27. #include <asm/mpc8349_pci.h>
  28. #include <i2c.h>
  29. #if defined(CONFIG_OF_FLAT_TREE)
  30. #include <ft_build.h>
  31. #endif
  32. DECLARE_GLOBAL_DATA_PTR;
  33. /* System RAM mapped to PCI space */
  34. #define CONFIG_PCI_SYS_MEM_BUS CFG_SDRAM_BASE
  35. #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE
  36. #ifndef CONFIG_PCI_PNP
  37. static struct pci_config_table pci_mpc8349itx_config_table[] = {
  38. {
  39. PCI_ANY_ID,
  40. PCI_ANY_ID,
  41. PCI_ANY_ID,
  42. PCI_ANY_ID,
  43. PCI_IDSEL_NUMBER,
  44. PCI_ANY_ID,
  45. pci_cfgfunc_config_device,
  46. {
  47. PCI_ENET0_IOADDR,
  48. PCI_ENET0_MEMADDR,
  49. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}
  50. },
  51. {}
  52. };
  53. #endif
  54. static struct pci_controller pci_hose[] = {
  55. {
  56. #ifndef CONFIG_PCI_PNP
  57. config_table:pci_mpc8349itx_config_table,
  58. #endif
  59. },
  60. {
  61. #ifndef CONFIG_PCI_PNP
  62. config_table:pci_mpc8349itx_config_table,
  63. #endif
  64. }
  65. };
  66. /**************************************************************************
  67. * pci_init_board()
  68. *
  69. * NOTICE: PCI2 is not currently supported
  70. *
  71. */
  72. void pci_init_board(void)
  73. {
  74. volatile immap_t *immr;
  75. volatile clk83xx_t *clk;
  76. volatile law83xx_t *pci_law;
  77. volatile pot83xx_t *pci_pot;
  78. volatile pcictrl83xx_t *pci_ctrl;
  79. volatile pciconf83xx_t *pci_conf;
  80. u8 reg8;
  81. u16 reg16;
  82. u32 reg32;
  83. u32 dev;
  84. struct pci_controller *hose;
  85. immr = (immap_t *) CFG_IMMR;
  86. clk = (clk83xx_t *) & immr->clk;
  87. pci_law = immr->sysconf.pcilaw;
  88. pci_pot = immr->ios.pot;
  89. pci_ctrl = immr->pci_ctrl;
  90. pci_conf = immr->pci_conf;
  91. hose = &pci_hose[0];
  92. /*
  93. * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
  94. */
  95. reg32 = clk->occr;
  96. udelay(2000);
  97. #ifdef CONFIG_HARD_I2C
  98. i2c_set_bus_num(1);
  99. /* Read the PCI_M66EN jumper setting */
  100. if ((i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &reg8, sizeof(reg8)) == 0) ||
  101. (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &reg8, sizeof(reg8)) == 0)) {
  102. if (reg8 & I2C_8574_PCI66)
  103. clk->occr = 0xff000000; /* 66 MHz PCI */
  104. else
  105. clk->occr = 0xff600001; /* 33 MHz PCI */
  106. } else {
  107. clk->occr = 0xff600001; /* 33 MHz PCI */
  108. }
  109. #else
  110. clk->occr = 0xff000000; /* 66 MHz PCI */
  111. #endif
  112. udelay(2000);
  113. /*
  114. * Release PCI RST Output signal
  115. */
  116. pci_ctrl[0].gcr = 0;
  117. udelay(2000);
  118. pci_ctrl[0].gcr = 1;
  119. #ifdef CONFIG_MPC83XX_PCI2
  120. pci_ctrl[1].gcr = 0;
  121. udelay(2000);
  122. pci_ctrl[1].gcr = 1;
  123. #endif
  124. /* We need to wait at least a 1sec based on PCI specs */
  125. {
  126. int i;
  127. for (i = 0; i < 1000; i++)
  128. udelay(1000);
  129. }
  130. /*
  131. * Configure PCI Local Access Windows
  132. */
  133. pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
  134. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  135. pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
  136. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_32M;
  137. /*
  138. * Configure PCI Outbound Translation Windows
  139. */
  140. /* PCI1 mem space - prefetch */
  141. pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
  142. pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
  143. pci_pot[0].pocmr = POCMR_EN | POCMR_PREFETCH_EN | POCMR_CM_256M;
  144. /* PCI1 IO space */
  145. pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
  146. pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
  147. pci_pot[1].pocmr = POCMR_EN | POCMR_IO | POCMR_CM_16M;
  148. /* PCI1 mmio - non-prefetch mem space */
  149. pci_pot[2].potar = (CFG_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK;
  150. pci_pot[2].pobar = (CFG_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  151. pci_pot[2].pocmr = POCMR_EN | POCMR_CM_256M;
  152. /*
  153. * Configure PCI Inbound Translation Windows
  154. */
  155. /* we need RAM mapped to PCI space for the devices to
  156. * access main memory */
  157. pci_ctrl[0].pitar1 = 0x0;
  158. pci_ctrl[0].pibar1 = 0x0;
  159. pci_ctrl[0].piebar1 = 0x0;
  160. pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  161. PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
  162. hose->first_busno = 0;
  163. hose->last_busno = 0xff;
  164. /* PCI memory prefetch space */
  165. pci_set_region(hose->regions + 0,
  166. CFG_PCI1_MEM_BASE,
  167. CFG_PCI1_MEM_PHYS,
  168. CFG_PCI1_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
  169. /* PCI memory space */
  170. pci_set_region(hose->regions + 1,
  171. CFG_PCI1_MMIO_BASE,
  172. CFG_PCI1_MMIO_PHYS, CFG_PCI1_MMIO_SIZE, PCI_REGION_MEM);
  173. /* PCI IO space */
  174. pci_set_region(hose->regions + 2,
  175. CFG_PCI1_IO_BASE,
  176. CFG_PCI1_IO_PHYS, CFG_PCI1_IO_SIZE, PCI_REGION_IO);
  177. /* System memory space */
  178. pci_set_region(hose->regions + 3,
  179. CONFIG_PCI_SYS_MEM_BUS,
  180. CONFIG_PCI_SYS_MEM_PHYS,
  181. gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
  182. hose->region_count = 4;
  183. pci_setup_indirect(hose,
  184. (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
  185. pci_register_hose(hose);
  186. /*
  187. * Write to Command register
  188. */
  189. reg16 = 0xff;
  190. dev = PCI_BDF(hose->first_busno, 0, 0);
  191. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
  192. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  193. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  194. /*
  195. * Clear non-reserved bits in status register.
  196. */
  197. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  198. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  199. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  200. #ifdef CONFIG_PCI_SCAN_SHOW
  201. printf("PCI: Bus Dev VenId DevId Class Int\n");
  202. #endif
  203. /*
  204. * Hose scan.
  205. */
  206. hose->last_busno = pci_hose_scan(hose);
  207. #ifdef CONFIG_MPC83XX_PCI2
  208. hose = &pci_hose[1];
  209. /*
  210. * Configure PCI Outbound Translation Windows
  211. */
  212. /* PCI2 mem space - prefetch */
  213. pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
  214. pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
  215. pci_pot[3].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | POCMR_CM_256M;
  216. /* PCI2 IO space */
  217. pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
  218. pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
  219. pci_pot[4].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_IO | POCMR_CM_16M;
  220. /* PCI2 mmio - non-prefetch mem space */
  221. pci_pot[5].potar = (CFG_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK;
  222. pci_pot[5].pobar = (CFG_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  223. pci_pot[5].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_CM_256M;
  224. /*
  225. * Configure PCI Inbound Translation Windows
  226. */
  227. /* we need RAM mapped to PCI space for the devices to
  228. * access main memory */
  229. pci_ctrl[1].pitar1 = 0x0;
  230. pci_ctrl[1].pibar1 = 0x0;
  231. pci_ctrl[1].piebar1 = 0x0;
  232. pci_ctrl[1].piwar1 =
  233. PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP |
  234. (__ilog2(gd->ram_size) - 1);
  235. hose->first_busno = pci_hose[0].last_busno + 1;
  236. hose->last_busno = 0xff;
  237. /* PCI memory prefetch space */
  238. pci_set_region(hose->regions + 0,
  239. CFG_PCI2_MEM_BASE,
  240. CFG_PCI2_MEM_PHYS,
  241. CFG_PCI2_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
  242. /* PCI memory space */
  243. pci_set_region(hose->regions + 1,
  244. CFG_PCI2_MMIO_BASE,
  245. CFG_PCI2_MMIO_PHYS, CFG_PCI2_MMIO_SIZE, PCI_REGION_MEM);
  246. /* PCI IO space */
  247. pci_set_region(hose->regions + 2,
  248. CFG_PCI2_IO_BASE,
  249. CFG_PCI2_IO_PHYS, CFG_PCI2_IO_SIZE, PCI_REGION_IO);
  250. /* System memory space */
  251. pci_set_region(hose->regions + 3,
  252. CONFIG_PCI_SYS_MEM_BUS,
  253. CONFIG_PCI_SYS_MEM_PHYS,
  254. gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
  255. hose->region_count = 4;
  256. pci_setup_indirect(hose,
  257. (CFG_IMMR + 0x8380), (CFG_IMMR + 0x8384));
  258. pci_register_hose(hose);
  259. /*
  260. * Write to Command register
  261. */
  262. reg16 = 0xff;
  263. dev = PCI_BDF(hose->first_busno, 0, 0);
  264. pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
  265. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  266. pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
  267. /*
  268. * Clear non-reserved bits in status register.
  269. */
  270. pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
  271. pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
  272. pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
  273. /*
  274. * Hose scan.
  275. */
  276. hose->last_busno = pci_hose_scan(hose);
  277. #endif
  278. }
  279. #endif /* CONFIG_PCI */
  280. #ifdef CONFIG_OF_FLAT_TREE
  281. void
  282. ft_pci_setup(void *blob, bd_t *bd)
  283. {
  284. u32 *p;
  285. int len;
  286. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
  287. if (p != NULL) {
  288. p[0] = pci_hose[0].first_busno;
  289. p[1] = pci_hose[0].last_busno;
  290. }
  291. #ifdef CONFIG_MPC83XX_PCI2
  292. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8600/bus-range", &len);
  293. if (p != NULL) {
  294. p[0] = pci_hose[1].first_busno;
  295. p[1] = pci_hose[1].last_busno;
  296. }
  297. #endif
  298. }
  299. #endif /* CONFIG_OF_FLAT_TREE */