pci.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. #include <asm/fsl_i2c.h>
  24. DECLARE_GLOBAL_DATA_PTR;
  25. #if defined(CONFIG_PCI)
  26. #define PCI_FUNCTION_CONFIG 0x44
  27. #define PCI_FUNCTION_CFG_LOCK 0x20
  28. /*
  29. * Initialize PCI Devices, report devices found
  30. */
  31. #ifndef CONFIG_PCI_PNP
  32. static struct pci_config_table pci_mpc83xxemds_config_table[] = {
  33. {
  34. PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  35. pci_cfgfunc_config_device,
  36. {PCI_ENET0_IOADDR,
  37. PCI_ENET0_MEMADDR,
  38. PCI_COMMON_MEMORY | PCI_COMMAND_MASTER}
  39. },
  40. {}
  41. }
  42. #endif
  43. static struct pci_controller hose[] = {
  44. {
  45. #ifndef CONFIG_PCI_PNP
  46. config_table:pci_mpc83xxemds_config_table,
  47. #endif
  48. },
  49. };
  50. /**********************************************************************
  51. * pci_init_board()
  52. *********************************************************************/
  53. void pci_init_board(void)
  54. #ifdef CONFIG_PCISLAVE
  55. {
  56. u16 reg16;
  57. volatile immap_t *immr;
  58. volatile law83xx_t *pci_law;
  59. volatile pot83xx_t *pci_pot;
  60. volatile pcictrl83xx_t *pci_ctrl;
  61. volatile pciconf83xx_t *pci_conf;
  62. immr = (immap_t *) CFG_IMMR;
  63. pci_law = immr->sysconf.pcilaw;
  64. pci_pot = immr->ios.pot;
  65. pci_ctrl = immr->pci_ctrl;
  66. pci_conf = immr->pci_conf;
  67. /*
  68. * Configure PCI Inbound Translation Windows
  69. */
  70. pci_ctrl[0].pitar0 = 0x0;
  71. pci_ctrl[0].pibar0 = 0x0;
  72. pci_ctrl[0].piwar0 = PIWAR_EN | PIWAR_RTT_SNOOP |
  73. PIWAR_WTT_SNOOP | PIWAR_IWS_4K;
  74. pci_ctrl[0].pitar1 = 0x0;
  75. pci_ctrl[0].pibar1 = 0x0;
  76. pci_ctrl[0].piebar1 = 0x0;
  77. pci_ctrl[0].piwar1 &= ~PIWAR_EN;
  78. pci_ctrl[0].pitar2 = 0x0;
  79. pci_ctrl[0].pibar2 = 0x0;
  80. pci_ctrl[0].piebar2 = 0x0;
  81. pci_ctrl[0].piwar2 &= ~PIWAR_EN;
  82. hose[0].first_busno = 0;
  83. hose[0].last_busno = 0xff;
  84. pci_setup_indirect(&hose[0],
  85. (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
  86. reg16 = 0xff;
  87. pci_hose_read_config_word(&hose[0], PCI_BDF(0, 0, 0),
  88. PCI_COMMAND, &reg16);
  89. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MEMORY;
  90. pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
  91. PCI_COMMAND, reg16);
  92. /*
  93. * Clear non-reserved bits in status register.
  94. */
  95. pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
  96. PCI_STATUS, 0xffff);
  97. pci_hose_write_config_byte(&hose[0], PCI_BDF(0, 0, 0),
  98. PCI_LATENCY_TIMER, 0x80);
  99. /*
  100. * Unlock configuration lock in PCI function configuration register.
  101. */
  102. pci_hose_read_config_word(&hose[0], PCI_BDF(0, 0, 0),
  103. PCI_FUNCTION_CONFIG, &reg16);
  104. reg16 &= ~(PCI_FUNCTION_CFG_LOCK);
  105. pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0),
  106. PCI_FUNCTION_CONFIG, reg16);
  107. printf("Enabled PCI 32bit Agent Mode\n");
  108. }
  109. #else
  110. {
  111. volatile immap_t *immr;
  112. volatile clk83xx_t *clk;
  113. volatile law83xx_t *pci_law;
  114. volatile pot83xx_t *pci_pot;
  115. volatile pcictrl83xx_t *pci_ctrl;
  116. volatile pciconf83xx_t *pci_conf;
  117. u8 val8, orig_i2c_bus;
  118. u16 reg16;
  119. u32 val32;
  120. u32 dev;
  121. immr = (immap_t *) CFG_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 = CFG_PCI_MEM_PHYS & LAWBAR_BAR;
  148. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
  149. pci_law[1].bar = CFG_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 = (CFG_PCI_MEM_BASE >> 12) & POTAR_TA_MASK;
  156. pci_pot[0].pobar = (CFG_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 = (CFG_PCI_MMIO_BASE >> 12) & POTAR_TA_MASK;
  161. pci_pot[1].pobar = (CFG_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 = (CFG_PCI_IO_BASE >> 12) & POTAR_TA_MASK;
  165. pci_pot[2].pobar = (CFG_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 = (CFG_PCI_SLV_MEM_LOCAL >> 12) & PITAR_TA_MASK;
  171. pci_ctrl[0].pibar1 = (CFG_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. * Assign PIB PMC slot to desired PCI bus
  178. */
  179. /* Switch temporarily to I2C bus #2 */
  180. orig_i2c_bus = i2c_get_bus_num();
  181. i2c_set_bus_num(1);
  182. val8 = 0;
  183. i2c_write(0x23, 0x6, 1, &val8, 1);
  184. i2c_write(0x23, 0x7, 1, &val8, 1);
  185. val8 = 0xff;
  186. i2c_write(0x23, 0x2, 1, &val8, 1);
  187. i2c_write(0x23, 0x3, 1, &val8, 1);
  188. val8 = 0;
  189. i2c_write(0x26, 0x6, 1, &val8, 1);
  190. val8 = 0x34;
  191. i2c_write(0x26, 0x7, 1, &val8, 1);
  192. val8 = 0xf9; /* PMC2, PMC3 slot to PCI bus */
  193. i2c_write(0x26, 0x2, 1, &val8, 1);
  194. val8 = 0xff;
  195. i2c_write(0x26, 0x3, 1, &val8, 1);
  196. val8 = 0;
  197. i2c_write(0x27, 0x6, 1, &val8, 1);
  198. i2c_write(0x27, 0x7, 1, &val8, 1);
  199. val8 = 0xff;
  200. i2c_write(0x27, 0x2, 1, &val8, 1);
  201. val8 = 0xef;
  202. i2c_write(0x27, 0x3, 1, &val8, 1);
  203. asm("eieio");
  204. /* Reset to original I2C bus */
  205. i2c_set_bus_num(orig_i2c_bus);
  206. /*
  207. * Release PCI RST Output signal
  208. */
  209. udelay(2000);
  210. pci_ctrl[0].gcr = 1;
  211. udelay(2000);
  212. hose[0].first_busno = 0;
  213. hose[0].last_busno = 0xff;
  214. /* PCI memory prefetch space */
  215. pci_set_region(hose[0].regions + 0,
  216. CFG_PCI_MEM_BASE,
  217. CFG_PCI_MEM_PHYS,
  218. CFG_PCI_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
  219. /* PCI memory space */
  220. pci_set_region(hose[0].regions + 1,
  221. CFG_PCI_MMIO_BASE,
  222. CFG_PCI_MMIO_PHYS, CFG_PCI_MMIO_SIZE, PCI_REGION_MEM);
  223. /* PCI IO space */
  224. pci_set_region(hose[0].regions + 2,
  225. CFG_PCI_IO_BASE,
  226. CFG_PCI_IO_PHYS, CFG_PCI_IO_SIZE, PCI_REGION_IO);
  227. /* System memory space */
  228. pci_set_region(hose[0].regions + 3,
  229. CFG_PCI_SLV_MEM_LOCAL,
  230. CFG_PCI_SLV_MEM_BUS,
  231. CFG_PCI_SLV_MEM_SIZE,
  232. PCI_REGION_MEM | PCI_REGION_MEMORY);
  233. hose[0].region_count = 4;
  234. pci_setup_indirect(&hose[0],
  235. (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
  236. pci_register_hose(hose);
  237. /*
  238. * Write command register
  239. */
  240. reg16 = 0xff;
  241. dev = PCI_BDF(0, 0, 0);
  242. pci_hose_read_config_word(&hose[0], dev, PCI_COMMAND, &reg16);
  243. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  244. pci_hose_write_config_word(&hose[0], dev, PCI_COMMAND, reg16);
  245. /*
  246. * Clear non-reserved bits in status register.
  247. */
  248. pci_hose_write_config_word(&hose[0], dev, PCI_STATUS, 0xffff);
  249. pci_hose_write_config_byte(&hose[0], dev, PCI_LATENCY_TIMER, 0x80);
  250. pci_hose_write_config_byte(&hose[0], dev, PCI_CACHE_LINE_SIZE, 0x08);
  251. printf("PCI 32bit bus on PMC2 & PMC3\n");
  252. /*
  253. * Hose scan.
  254. */
  255. hose->last_busno = pci_hose_scan(hose);
  256. }
  257. #endif /* CONFIG_PCISLAVE */
  258. #ifdef CONFIG_OF_FLAT_TREE
  259. void
  260. ft_pci_setup(void *blob, bd_t *bd)
  261. {
  262. u32 *p;
  263. int len;
  264. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
  265. if (p != NULL) {
  266. p[0] = hose[0].first_busno;
  267. p[1] = hose[0].last_busno;
  268. }
  269. }
  270. #endif /* CONFIG_OF_FLAT_TREE */
  271. #endif /* CONFIG_PCI */