pci.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * Copyright (C) 2003 Motorola Inc.
  4. * Xianghua Xiao (x.xiao@motorola.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. *
  24. * Change log:
  25. *
  26. * 20050101: Eran Liberty (liberty@freescale.com)
  27. * Initial file creating (porting from 85XX & 8260)
  28. */
  29. /*
  30. * PCI Configuration space access support for MPC85xx PCI Bridge
  31. */
  32. #include <asm/mmu.h>
  33. #include <asm/io.h>
  34. #include <common.h>
  35. #include <pci.h>
  36. #ifdef CONFIG_MPC8349ADS
  37. #include <asm/i2c.h>
  38. #endif
  39. #if defined(CONFIG_PCI)
  40. void
  41. pci_mpc83xx_init(volatile struct pci_controller *hose)
  42. {
  43. volatile immap_t * immr;
  44. volatile clk8349_t * clk;
  45. volatile law8349_t * pci_law;
  46. volatile pot8349_t * pci_pot;
  47. volatile pcictrl8349_t * pci_ctrl;
  48. volatile pciconf8349_t * pci_conf;
  49. u8 val8,tmp8,ret;
  50. u16 reg16,tmp16;
  51. u32 val32,tmp32;
  52. immr = (immap_t *)CFG_IMMRBAR;
  53. clk = (clk8349_t *)&immr->clk;
  54. pci_law = immr->sysconf.pcilaw;
  55. pci_pot = immr->ios.pot;
  56. pci_ctrl = immr->pci_ctrl;
  57. pci_conf = immr->pci_conf;
  58. /*
  59. * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
  60. */
  61. val32 = clk->occr;
  62. udelay(2000);
  63. clk->occr = 0xff000000;
  64. udelay(2000);
  65. /*
  66. * Configure PCI Local Access Windows
  67. */
  68. pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
  69. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  70. pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
  71. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_32M;
  72. /*
  73. * Configure PCI Outbound Translation Windows
  74. */
  75. pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
  76. pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
  77. pci_pot[0].pocmr = POCMR_EN | (POCMR_CM_512M & POCMR_CM_MASK);
  78. /* mapped to PCI1 IO space 0x0 to local 0xe2000000 */
  79. pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
  80. pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
  81. pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);
  82. //#if defined(CONFIG_PCI_2)
  83. pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
  84. pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
  85. pci_pot[3].pocmr = POCMR_EN | POCMR_DST | (POCMR_CM_512M & POCMR_CM_MASK);
  86. /* mapped to PCI2 IO space 0x0 to local 0xe3000000 */
  87. pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
  88. pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
  89. pci_pot[4].pocmr = POCMR_EN | POCMR_DST | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);
  90. //#endif
  91. /*
  92. * Configure PCI Inbound Translation Windows
  93. */
  94. pci_ctrl[0].pitar1 = 0x0;
  95. pci_ctrl[0].pibar1 = 0x0;
  96. pci_ctrl[0].piebar1 = 0x0;
  97. pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;
  98. pci_ctrl[1].pitar1 = 0x0;
  99. pci_ctrl[1].pibar1 = 0x0;
  100. pci_ctrl[1].piebar1 = 0x0;
  101. pci_ctrl[1].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;
  102. /*
  103. * Assign PIB PMC slot to desired PCI bus
  104. */
  105. #ifdef CONFIG_MPC8349ADS
  106. mpc8349_i2c = (i2c_t*)(CFG_IMMRBAR + CFG_I2C2_OFFSET);
  107. i2c_init(CFG_I2C_SPEED,CFG_I2C_SLAVE);
  108. #endif
  109. val8 = 0;
  110. ret = i2c_write(0x23,0x6,1,&val8,1);
  111. ret = i2c_write(0x23,0x7,1,&val8,1);
  112. val8 = 0xff;
  113. ret = i2c_write(0x23,0x2,1,&val8,1);
  114. ret = i2c_write(0x23,0x3,1,&val8,1);
  115. val8 = 0;
  116. ret = i2c_write(0x26,0x6,1,&val8,1);
  117. val8 = 0x34;
  118. ret = i2c_write(0x26,0x7,1,&val8,1);
  119. #if defined(PCI_64BIT)
  120. val8 = 0xf4; // PMC2<->PCI1 64bit
  121. #elif defined(PCI_ALL_PCI1)
  122. val8 = 0xf3; // PMC1<->PCI1,PMC2<->PCI1,PMC3<->PCI1 32bit
  123. #elif defined(PCI_ONE_PCI1)
  124. val8 = 0xf9; // PMC1<->PCI1,PMC2<->PCI2,PMC3<->PCI2 32bit
  125. #elif defined(PCI_TWO_PCI1)
  126. val8 = 0xf5; // PMC1<->PCI1,PMC2<->PCI1,PMC3<->PCI2 32bit
  127. #else
  128. val8 = 0xf5;
  129. #endif
  130. ret = i2c_write(0x26,0x2,1,&val8,1);
  131. val8 = 0xff;
  132. ret = i2c_write(0x26,0x3,1,&val8,1);
  133. val8 = 0;
  134. ret = i2c_write(0x27,0x6,1,&val8,1);
  135. ret = i2c_write(0x27,0x7,1,&val8,1);
  136. val8 = 0xff;
  137. ret = i2c_write(0x27,0x2,1,&val8,1);
  138. val8 = 0xef;
  139. ret = i2c_write(0x27,0x3,1,&val8,1);
  140. asm("eieio");
  141. /*
  142. * Release PCI RST Output signal
  143. */
  144. udelay(2000);
  145. pci_ctrl[0].gcr = 1;
  146. #ifndef PCI_64BIT
  147. pci_ctrl[1].gcr = 1;
  148. #endif
  149. udelay(2000);
  150. hose[0].first_busno = 0;
  151. hose[0].last_busno = 0xff;
  152. pci_set_region(hose[0].regions + 0,
  153. CFG_PCI1_MEM_BASE,
  154. CFG_PCI1_MEM_PHYS,
  155. CFG_PCI1_MEM_SIZE,
  156. PCI_REGION_MEM);
  157. pci_set_region(hose[0].regions + 1,
  158. CFG_PCI1_IO_BASE,
  159. CFG_PCI1_IO_PHYS,
  160. CFG_PCI1_IO_SIZE,
  161. PCI_REGION_IO);
  162. hose[0].region_count = 2;
  163. pci_setup_indirect(&hose[0],
  164. (CFG_IMMRBAR+0x8300),
  165. (CFG_IMMRBAR+0x8304));
  166. #define PCI_CLASS_BRIDGE 0x06
  167. reg16 = 0xff;
  168. tmp32 = 0xffff;
  169. pci_hose_write_config_byte(&hose[0],PCI_BDF(0,0,0),PCI_CLASS_CODE,PCI_CLASS_BRIDGE);
  170. pci_hose_read_config_word (&hose[0],PCI_BDF(0,0,0),PCI_COMMAND, &reg16);
  171. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  172. pci_hose_write_config_word(&hose[0],PCI_BDF(0,0,0), PCI_COMMAND, reg16);
  173. /*
  174. * Clear non-reserved bits in status register.
  175. */
  176. pci_hose_write_config_word(&hose[0],PCI_BDF(0,0,0), PCI_STATUS, 0xffff);
  177. pci_hose_write_config_byte(&hose[0],PCI_BDF(0,0,0), PCI_LATENCY_TIMER,0x80);
  178. #ifndef PCI_64BIT
  179. hose[1].first_busno = 0;
  180. hose[1].last_busno = 0xff;
  181. pci_set_region(hose[1].regions + 0,
  182. CFG_PCI2_MEM_BASE,
  183. CFG_PCI2_MEM_PHYS,
  184. CFG_PCI2_MEM_SIZE,
  185. PCI_REGION_MEM);
  186. pci_set_region(hose[1].regions + 1,
  187. CFG_PCI2_IO_BASE,
  188. CFG_PCI2_IO_PHYS,
  189. CFG_PCI2_IO_SIZE,
  190. PCI_REGION_IO);
  191. hose[1].region_count = 2;
  192. pci_setup_indirect(&hose[1],
  193. (CFG_IMMRBAR+0x8380),
  194. (CFG_IMMRBAR+0x8384));
  195. pci_hose_write_config_byte(&hose[1],PCI_BDF(0,0,0),PCI_CLASS_CODE,PCI_CLASS_BRIDGE);
  196. pci_hose_read_config_word (&hose[1],PCI_BDF(0,0,0), PCI_COMMAND, &reg16);
  197. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  198. pci_hose_write_config_word(&hose[1],PCI_BDF(0,0,0), PCI_COMMAND, reg16);
  199. /*
  200. * Clear non-reserved bits in status register.
  201. */
  202. pci_hose_write_config_word(&hose[1],PCI_BDF(0,0,0), PCI_STATUS, 0xffff);
  203. pci_hose_write_config_byte(&hose[1],PCI_BDF(0,0,0), PCI_LATENCY_TIMER,0x80);
  204. #endif
  205. #if defined(PCI_64BIT)
  206. printf("PCI1 64bit on PMC2\n");
  207. #elif defined(PCI_ALL_PCI1)
  208. printf("PCI1 32bit on PMC1 & PMC2 & PMC3\n");
  209. #elif defined(PCI_ONE_PCI1)
  210. printf("PCI1 32bit on PMC1,PCI2 32bit on PMC2 & PMC3\n");
  211. #else
  212. printf("PCI1 32bit on PMC1 & PMC2 & PMC3 in default\n");
  213. #endif
  214. #if 1
  215. /*
  216. * Hose scan.
  217. */
  218. pci_register_hose(hose);
  219. hose->last_busno = pci_hose_scan(hose);
  220. #endif
  221. }
  222. #endif /* CONFIG_PCI */