pci.c 7.6 KB

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