pci.c 8.4 KB

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