pci.c 10 KB

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