pci.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 <fdt_support.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. u16 reg16;
  121. u32 val32;
  122. u32 dev;
  123. immr = (immap_t *) CFG_IMMR;
  124. clk = (clk83xx_t *) & immr->clk;
  125. pci_law = immr->sysconf.pcilaw;
  126. pci_pot = immr->ios.pot;
  127. pci_ctrl = immr->pci_ctrl;
  128. pci_conf = immr->pci_conf;
  129. /*
  130. * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
  131. */
  132. val32 = clk->occr;
  133. udelay(2000);
  134. #if defined(PCI_66M)
  135. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
  136. printf("PCI clock is 66MHz\n");
  137. #elif defined(PCI_33M)
  138. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2 |
  139. OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 | OCCR_PCICR;
  140. printf("PCI clock is 33MHz\n");
  141. #else
  142. clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
  143. printf("PCI clock is 66MHz\n");
  144. #endif
  145. udelay(2000);
  146. /*
  147. * Configure PCI Local Access Windows
  148. */
  149. pci_law[0].bar = CFG_PCI_MEM_PHYS & LAWBAR_BAR;
  150. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
  151. pci_law[1].bar = CFG_PCI_IO_PHYS & LAWBAR_BAR;
  152. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_1M;
  153. /*
  154. * Configure PCI Outbound Translation Windows
  155. */
  156. /* PCI mem space - prefetch */
  157. pci_pot[0].potar = (CFG_PCI_MEM_BASE >> 12) & POTAR_TA_MASK;
  158. pci_pot[0].pobar = (CFG_PCI_MEM_PHYS >> 12) & POBAR_BA_MASK;
  159. pci_pot[0].pocmr =
  160. POCMR_EN | POCMR_SE | (POCMR_CM_256M & POCMR_CM_MASK);
  161. /* PCI mmio - non-prefetch mem space */
  162. pci_pot[1].potar = (CFG_PCI_MMIO_BASE >> 12) & POTAR_TA_MASK;
  163. pci_pot[1].pobar = (CFG_PCI_MMIO_PHYS >> 12) & POBAR_BA_MASK;
  164. pci_pot[1].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK);
  165. /* PCI IO space */
  166. pci_pot[2].potar = (CFG_PCI_IO_BASE >> 12) & POTAR_TA_MASK;
  167. pci_pot[2].pobar = (CFG_PCI_IO_PHYS >> 12) & POBAR_BA_MASK;
  168. pci_pot[2].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
  169. /*
  170. * Configure PCI Inbound Translation Windows
  171. */
  172. pci_ctrl[0].pitar1 = (CFG_PCI_SLV_MEM_LOCAL >> 12) & PITAR_TA_MASK;
  173. pci_ctrl[0].pibar1 = (CFG_PCI_SLV_MEM_BUS >> 12) & PIBAR_MASK;
  174. pci_ctrl[0].piebar1 = 0x0;
  175. pci_ctrl[0].piwar1 =
  176. PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP |
  177. PIWAR_IWS_2G;
  178. /*
  179. * Release PCI RST Output signal
  180. */
  181. udelay(2000);
  182. pci_ctrl[0].gcr = 1;
  183. udelay(2000);
  184. hose[0].first_busno = 0;
  185. hose[0].last_busno = 0xff;
  186. /* PCI memory prefetch space */
  187. pci_set_region(hose[0].regions + 0,
  188. CFG_PCI_MEM_BASE,
  189. CFG_PCI_MEM_PHYS,
  190. CFG_PCI_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
  191. /* PCI memory space */
  192. pci_set_region(hose[0].regions + 1,
  193. CFG_PCI_MMIO_BASE,
  194. CFG_PCI_MMIO_PHYS, CFG_PCI_MMIO_SIZE, PCI_REGION_MEM);
  195. /* PCI IO space */
  196. pci_set_region(hose[0].regions + 2,
  197. CFG_PCI_IO_BASE,
  198. CFG_PCI_IO_PHYS, CFG_PCI_IO_SIZE, PCI_REGION_IO);
  199. /* System memory space */
  200. pci_set_region(hose[0].regions + 3,
  201. CFG_PCI_SLV_MEM_LOCAL,
  202. CFG_PCI_SLV_MEM_BUS,
  203. CFG_PCI_SLV_MEM_SIZE,
  204. PCI_REGION_MEM | PCI_REGION_MEMORY);
  205. hose[0].region_count = 4;
  206. pci_setup_indirect(&hose[0],
  207. (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
  208. pci_register_hose(hose);
  209. /*
  210. * Write command register
  211. */
  212. reg16 = 0xff;
  213. dev = PCI_BDF(0, 0, 0);
  214. pci_hose_read_config_word(&hose[0], dev, PCI_COMMAND, &reg16);
  215. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  216. pci_hose_write_config_word(&hose[0], dev, PCI_COMMAND, reg16);
  217. /*
  218. * Clear non-reserved bits in status register.
  219. */
  220. pci_hose_write_config_word(&hose[0], dev, PCI_STATUS, 0xffff);
  221. pci_hose_write_config_byte(&hose[0], dev, PCI_LATENCY_TIMER, 0x80);
  222. pci_hose_write_config_byte(&hose[0], dev, PCI_CACHE_LINE_SIZE, 0x08);
  223. /*
  224. * Hose scan.
  225. */
  226. hose->last_busno = pci_hose_scan(hose);
  227. }
  228. #endif /* CONFIG_PCISLAVE */
  229. #if defined(CONFIG_OF_LIBFDT)
  230. void ft_pci_setup(void *blob, bd_t *bd)
  231. {
  232. int nodeoffset;
  233. int tmp[2];
  234. const char *path;
  235. nodeoffset = fdt_path_offset(blob, "/aliases");
  236. if (nodeoffset >= 0) {
  237. path = fdt_getprop(blob, nodeoffset, "pci0", NULL);
  238. if (path) {
  239. tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
  240. tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
  241. do_fixup_by_path(blob, path, "bus-range",
  242. &tmp, sizeof(tmp), 1);
  243. tmp[0] = cpu_to_be32(gd->pci_clk);
  244. do_fixup_by_path(blob, path, "clock-frequency",
  245. &tmp, sizeof(tmp[0]), 1);
  246. }
  247. }
  248. }
  249. #elif defined(CONFIG_OF_FLAT_TREE)
  250. void
  251. ft_pci_setup(void *blob, bd_t *bd)
  252. {
  253. u32 *p;
  254. int len;
  255. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
  256. if (p != NULL) {
  257. p[0] = hose[0].first_busno;
  258. p[1] = hose[0].last_busno;
  259. }
  260. }
  261. #endif /* CONFIG_OF_FLAT_TREE */
  262. #endif /* CONFIG_PCI */