pci.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * Copyright (C) 2006 Freescale Semiconductor, Inc.
  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. /*
  13. * PCI Configuration space access support for MPC83xx PCI Bridge
  14. */
  15. #include <asm/mmu.h>
  16. #include <asm/io.h>
  17. #include <common.h>
  18. #include <pci.h>
  19. #include <i2c.h>
  20. #if defined(CONFIG_OF_FLAT_TREE)
  21. #include <ft_build.h>
  22. #endif
  23. #if defined(CONFIG_OF_LIBFDT)
  24. #include <libfdt.h>
  25. #include <libfdt_env.h>
  26. #endif
  27. #include <asm/fsl_i2c.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. #if defined(CONFIG_PCI)
  30. #define PCI_FUNCTION_CONFIG 0x44
  31. #define PCI_FUNCTION_CFG_LOCK 0x20
  32. /*
  33. * Initialize PCI Devices, report devices found
  34. */
  35. #ifndef CONFIG_PCI_PNP
  36. static struct pci_config_table pci_mpc83xxemds_config_table[] = {
  37. {
  38. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  39. pci_cfgfunc_config_device,
  40. {PCI_ENET0_IOADDR,
  41. PCI_ENET0_MEMADDR,
  42. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
  43. },
  44. {}
  45. }
  46. #endif
  47. static struct pci_controller hose[] = {
  48. {
  49. #ifndef CONFIG_PCI_PNP
  50. config_table:pci_mpc83xxemds_config_table,
  51. #endif
  52. },
  53. };
  54. /**********************************************************************
  55. * pci_init_board()
  56. *********************************************************************/
  57. void pci_init_board(void)
  58. #ifdef CONFIG_PCISLAVE
  59. {
  60. u16 reg16;
  61. volatile immap_t *immr;
  62. volatile law83xx_t *pci_law;
  63. volatile pot83xx_t *pci_pot;
  64. volatile pcictrl83xx_t *pci_ctrl;
  65. volatile pciconf83xx_t *pci_conf;
  66. immr = (immap_t *) CFG_IMMR;
  67. pci_law = immr->sysconf.pcilaw;
  68. pci_pot = immr->ios.pot;
  69. pci_ctrl = immr->pci_ctrl;
  70. pci_conf = immr->pci_conf;
  71. /*
  72. * Configure PCI Inbound Translation Windows
  73. */
  74. pci_ctrl[0].pitar0 = 0x0;
  75. pci_ctrl[0].pibar0 = 0x0;
  76. pci_ctrl[0].piwar0 = PIWAR_EN | PIWAR_RTT_SNOOP |
  77. PIWAR_WTT_SNOOP | PIWAR_IWS_4K;
  78. pci_ctrl[0].pitar1 = 0x0;
  79. pci_ctrl[0].pibar1 = 0x0;
  80. pci_ctrl[0].piebar1 = 0x0;
  81. pci_ctrl[0].piwar1 &= ~PIWAR_EN;
  82. pci_ctrl[0].pitar2 = 0x0;
  83. pci_ctrl[0].pibar2 = 0x0;
  84. pci_ctrl[0].piebar2 = 0x0;
  85. pci_ctrl[0].piwar2 &= ~PIWAR_EN;
  86. hose[0].first_busno = 0;
  87. hose[0].last_busno = 0xff;
  88. pci_setup_indirect(&hose[0],
  89. (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
  90. reg16 = 0xff;
  91. pci_hose_read_config_word(&hose[0], PCI_BDF(0, 0, 0),
  92. PCI_COMMAND, &reg16);
  93. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MEMORY;
  94. pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
  95. PCI_COMMAND, reg16);
  96. /*
  97. * Clear non-reserved bits in status register.
  98. */
  99. pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
  100. PCI_STATUS, 0xffff);
  101. pci_hose_write_config_byte(&hose[0], PCI_BDF(0, 0, 0),
  102. PCI_LATENCY_TIMER, 0x80);
  103. /*
  104. * Unlock configuration lock in PCI function configuration register.
  105. */
  106. pci_hose_read_config_word(&hose[0], PCI_BDF(0, 0, 0),
  107. PCI_FUNCTION_CONFIG, &reg16);
  108. reg16 &= ~(PCI_FUNCTION_CFG_LOCK);
  109. pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
  110. PCI_FUNCTION_CONFIG, reg16);
  111. printf("Enabled PCI 32bit Agent Mode\n");
  112. }
  113. #else
  114. {
  115. volatile immap_t *immr;
  116. volatile clk83xx_t *clk;
  117. volatile law83xx_t *pci_law;
  118. volatile pot83xx_t *pci_pot;
  119. volatile pcictrl83xx_t *pci_ctrl;
  120. volatile pciconf83xx_t *pci_conf;
  121. u8 val8, orig_i2c_bus;
  122. u16 reg16;
  123. u32 val32;
  124. u32 dev;
  125. immr = (immap_t *) CFG_IMMR;
  126. clk = (clk83xx_t *) & immr->clk;
  127. pci_law = immr->sysconf.pcilaw;
  128. pci_pot = immr->ios.pot;
  129. pci_ctrl = immr->pci_ctrl;
  130. pci_conf = immr->pci_conf;
  131. /*
  132. * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
  133. */
  134. val32 = clk->occr;
  135. udelay(2000);
  136. #if defined(PCI_66M)
  137. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
  138. printf("PCI clock is 66MHz\n");
  139. #elif defined(PCI_33M)
  140. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2 |
  141. OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 | OCCR_PCICR;
  142. printf("PCI clock is 33MHz\n");
  143. #else
  144. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
  145. printf("PCI clock is 66MHz\n");
  146. #endif
  147. udelay(2000);
  148. /*
  149. * Configure PCI Local Access Windows
  150. */
  151. pci_law[0].bar = CFG_PCI_MEM_PHYS & LAWBAR_BAR;
  152. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
  153. pci_law[1].bar = CFG_PCI_IO_PHYS & LAWBAR_BAR;
  154. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_1M;
  155. /*
  156. * Configure PCI Outbound Translation Windows
  157. */
  158. /* PCI mem space - prefetch */
  159. pci_pot[0].potar = (CFG_PCI_MEM_BASE >> 12) & POTAR_TA_MASK;
  160. pci_pot[0].pobar = (CFG_PCI_MEM_PHYS >> 12) & POBAR_BA_MASK;
  161. pci_pot[0].pocmr =
  162. POCMR_EN | POCMR_SE | (POCMR_CM_256M & POCMR_CM_MASK);
  163. /* PCI mmio - non-prefetch mem space */
  164. pci_pot[1].potar = (CFG_PCI_MMIO_BASE >> 12) & POTAR_TA_MASK;
  165. pci_pot[1].pobar = (CFG_PCI_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  166. pci_pot[1].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  167. /* PCI IO space */
  168. pci_pot[2].potar = (CFG_PCI_IO_BASE >> 12) & POTAR_TA_MASK;
  169. pci_pot[2].pobar = (CFG_PCI_IO_PHYS >> 12) & POBAR_BA_MASK;
  170. pci_pot[2].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
  171. /*
  172. * Configure PCI Inbound Translation Windows
  173. */
  174. pci_ctrl[0].pitar1 = (CFG_PCI_SLV_MEM_LOCAL >> 12) & PITAR_TA_MASK;
  175. pci_ctrl[0].pibar1 = (CFG_PCI_SLV_MEM_BUS >> 12) & PIBAR_MASK;
  176. pci_ctrl[0].piebar1 = 0x0;
  177. pci_ctrl[0].piwar1 =
  178. PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP |
  179. PIWAR_IWS_2G;
  180. /*
  181. * Assign PIB PMC slot to desired PCI bus
  182. */
  183. /* Switch temporarily to I2C bus #2 */
  184. orig_i2c_bus = i2c_get_bus_num();
  185. i2c_set_bus_num(1);
  186. val8 = 0;
  187. i2c_write(0x23, 0x6, 1, &val8, 1);
  188. i2c_write(0x23, 0x7, 1, &val8, 1);
  189. val8 = 0xff;
  190. i2c_write(0x23, 0x2, 1, &val8, 1);
  191. i2c_write(0x23, 0x3, 1, &val8, 1);
  192. val8 = 0;
  193. i2c_write(0x26, 0x6, 1, &val8, 1);
  194. val8 = 0x34;
  195. i2c_write(0x26, 0x7, 1, &val8, 1);
  196. val8 = 0xf3; /*PMC1, PMC2, PMC3 slot to PCI bus */
  197. i2c_write(0x26, 0x2, 1, &val8, 1);
  198. val8 = 0xff;
  199. i2c_write(0x26, 0x3, 1, &val8, 1);
  200. val8 = 0;
  201. i2c_write(0x27, 0x6, 1, &val8, 1);
  202. i2c_write(0x27, 0x7, 1, &val8, 1);
  203. val8 = 0xff;
  204. i2c_write(0x27, 0x2, 1, &val8, 1);
  205. val8 = 0xef;
  206. i2c_write(0x27, 0x3, 1, &val8, 1);
  207. asm("eieio");
  208. /* Reset to original I2C bus */
  209. i2c_set_bus_num(orig_i2c_bus);
  210. /*
  211. * Release PCI RST Output signal
  212. */
  213. udelay(2000);
  214. pci_ctrl[0].gcr = 1;
  215. udelay(2000);
  216. hose[0].first_busno = 0;
  217. hose[0].last_busno = 0xff;
  218. /* PCI memory prefetch space */
  219. pci_set_region(hose[0].regions + 0,
  220. CFG_PCI_MEM_BASE,
  221. CFG_PCI_MEM_PHYS,
  222. CFG_PCI_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
  223. /* PCI memory space */
  224. pci_set_region(hose[0].regions + 1,
  225. CFG_PCI_MMIO_BASE,
  226. CFG_PCI_MMIO_PHYS, CFG_PCI_MMIO_SIZE, PCI_REGION_MEM);
  227. /* PCI IO space */
  228. pci_set_region(hose[0].regions + 2,
  229. CFG_PCI_IO_BASE,
  230. CFG_PCI_IO_PHYS, CFG_PCI_IO_SIZE, PCI_REGION_IO);
  231. /* System memory space */
  232. pci_set_region(hose[0].regions + 3,
  233. CFG_PCI_SLV_MEM_LOCAL,
  234. CFG_PCI_SLV_MEM_BUS,
  235. CFG_PCI_SLV_MEM_SIZE,
  236. PCI_REGION_MEM | PCI_REGION_MEMORY);
  237. hose[0].region_count = 4;
  238. pci_setup_indirect(&hose[0],
  239. (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
  240. pci_register_hose(hose);
  241. /*
  242. * Write command register
  243. */
  244. reg16 = 0xff;
  245. dev = PCI_BDF(0, 0, 0);
  246. pci_hose_read_config_word(&hose[0], dev, PCI_COMMAND, &reg16);
  247. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  248. pci_hose_write_config_word(&hose[0], dev, PCI_COMMAND, reg16);
  249. /*
  250. * Clear non-reserved bits in status register.
  251. */
  252. pci_hose_write_config_word(&hose[0], dev, PCI_STATUS, 0xffff);
  253. pci_hose_write_config_byte(&hose[0], dev, PCI_LATENCY_TIMER, 0x80);
  254. pci_hose_write_config_byte(&hose[0], dev, PCI_CACHE_LINE_SIZE, 0x08);
  255. printf("PCI 32bit bus on PMC1 & PMC2 & PMC3\n");
  256. /*
  257. * Hose scan.
  258. */
  259. hose->last_busno = pci_hose_scan(hose);
  260. }
  261. #endif /* CONFIG_PCISLAVE */
  262. #if defined(CONFIG_OF_LIBFDT)
  263. void
  264. ft_pci_setup(void *blob, bd_t *bd)
  265. {
  266. int nodeoffset;
  267. int err;
  268. int tmp[2];
  269. nodeoffset = fdt_path_offset (fdt, "/" OF_SOC "/pci@8500");
  270. if (nodeoffset >= 0) {
  271. tmp[0] = cpu_to_be32(hose[0].first_busno);
  272. tmp[1] = cpu_to_be32(hose[0].last_busno);
  273. err = fdt_setprop(fdt, nodeoffset, "bus-range", tmp, sizeof(tmp));
  274. }
  275. }
  276. #endif /* CONFIG_OF_LIBFDT */
  277. #ifdef CONFIG_OF_FLAT_TREE
  278. void
  279. ft_pci_setup(void *blob, bd_t *bd)
  280. {
  281. u32 *p;
  282. int len;
  283. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
  284. if (p != NULL) {
  285. p[0] = hose[0].first_busno;
  286. p[1] = hose[0].last_busno;
  287. }
  288. }
  289. #endif /* CONFIG_OF_FLAT_TREE */
  290. #endif /* CONFIG_PCI */