pci.c 7.9 KB

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