pci.c 7.6 KB

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