pci.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
  83. pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
  84. pci_pot[3].pocmr = POCMR_EN | POCMR_DST | (POCMR_CM_512M & POCMR_CM_MASK);
  85. /* mapped to PCI2 IO space 0x0 to local 0xe3000000 */
  86. pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
  87. pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
  88. pci_pot[4].pocmr = POCMR_EN | POCMR_DST | POCMR_IO | (POCMR_CM_16M & POCMR_CM_MASK);
  89. /*
  90. * Configure PCI Inbound Translation Windows
  91. */
  92. pci_ctrl[0].pitar1 = 0x0;
  93. pci_ctrl[0].pibar1 = 0x0;
  94. pci_ctrl[0].piebar1 = 0x0;
  95. pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;
  96. pci_ctrl[1].pitar1 = 0x0;
  97. pci_ctrl[1].pibar1 = 0x0;
  98. pci_ctrl[1].piebar1 = 0x0;
  99. pci_ctrl[1].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | PIWAR_IWS_2G;
  100. /*
  101. * Assign PIB PMC slot to desired PCI bus
  102. */
  103. #ifdef CONFIG_MPC8349ADS
  104. mpc8349_i2c = (i2c_t*)(CFG_IMMRBAR + CFG_I2C2_OFFSET);
  105. i2c_init(CFG_I2C_SPEED,CFG_I2C_SLAVE);
  106. #endif
  107. val8 = 0;
  108. ret = i2c_write(0x23,0x6,1,&val8,1);
  109. ret = i2c_write(0x23,0x7,1,&val8,1);
  110. val8 = 0xff;
  111. ret = i2c_write(0x23,0x2,1,&val8,1);
  112. ret = i2c_write(0x23,0x3,1,&val8,1);
  113. val8 = 0;
  114. ret = i2c_write(0x26,0x6,1,&val8,1);
  115. val8 = 0x34;
  116. ret = i2c_write(0x26,0x7,1,&val8,1);
  117. #if defined(PCI_64BIT)
  118. val8 = 0xf4; /* PMC2<->PCI1 64bit */
  119. #elif defined(PCI_ALL_PCI1)
  120. val8 = 0xf3; /* PMC1<->PCI1,PMC2<->PCI1,PMC3<->PCI1 32bit */
  121. #elif defined(PCI_ONE_PCI1)
  122. val8 = 0xf9; /* PMC1<->PCI1,PMC2<->PCI2,PMC3<->PCI2 32bit */
  123. #elif defined(PCI_TWO_PCI1)
  124. val8 = 0xf5; /* PMC1<->PCI1,PMC2<->PCI1,PMC3<->PCI2 32bit */
  125. #else
  126. val8 = 0xf5;
  127. #endif
  128. ret = i2c_write(0x26,0x2,1,&val8,1);
  129. val8 = 0xff;
  130. ret = i2c_write(0x26,0x3,1,&val8,1);
  131. val8 = 0;
  132. ret = i2c_write(0x27,0x6,1,&val8,1);
  133. ret = i2c_write(0x27,0x7,1,&val8,1);
  134. val8 = 0xff;
  135. ret = i2c_write(0x27,0x2,1,&val8,1);
  136. val8 = 0xef;
  137. ret = i2c_write(0x27,0x3,1,&val8,1);
  138. asm("eieio");
  139. /*
  140. * Release PCI RST Output signal
  141. */
  142. udelay(2000);
  143. pci_ctrl[0].gcr = 1;
  144. #ifndef PCI_64BIT
  145. pci_ctrl[1].gcr = 1;
  146. #endif
  147. udelay(2000);
  148. hose[0].first_busno = 0;
  149. hose[0].last_busno = 0xff;
  150. pci_set_region(hose[0].regions + 0,
  151. CFG_PCI1_MEM_BASE,
  152. CFG_PCI1_MEM_PHYS,
  153. CFG_PCI1_MEM_SIZE,
  154. PCI_REGION_MEM);
  155. pci_set_region(hose[0].regions + 1,
  156. CFG_PCI1_IO_BASE,
  157. CFG_PCI1_IO_PHYS,
  158. CFG_PCI1_IO_SIZE,
  159. PCI_REGION_IO);
  160. hose[0].region_count = 2;
  161. pci_setup_indirect(&hose[0],
  162. (CFG_IMMRBAR+0x8300),
  163. (CFG_IMMRBAR+0x8304));
  164. #define PCI_CLASS_BRIDGE 0x06
  165. reg16 = 0xff;
  166. tmp32 = 0xffff;
  167. pci_hose_write_config_byte(&hose[0],PCI_BDF(0,0,0),PCI_CLASS_CODE,PCI_CLASS_BRIDGE);
  168. pci_hose_read_config_word (&hose[0],PCI_BDF(0,0,0),PCI_COMMAND, &reg16);
  169. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  170. pci_hose_write_config_word(&hose[0],PCI_BDF(0,0,0), PCI_COMMAND, reg16);
  171. /*
  172. * Clear non-reserved bits in status register.
  173. */
  174. pci_hose_write_config_word(&hose[0],PCI_BDF(0,0,0), PCI_STATUS, 0xffff);
  175. pci_hose_write_config_byte(&hose[0],PCI_BDF(0,0,0), PCI_LATENCY_TIMER,0x80);
  176. #ifndef PCI_64BIT
  177. hose[1].first_busno = 0;
  178. hose[1].last_busno = 0xff;
  179. pci_set_region(hose[1].regions + 0,
  180. CFG_PCI2_MEM_BASE,
  181. CFG_PCI2_MEM_PHYS,
  182. CFG_PCI2_MEM_SIZE,
  183. PCI_REGION_MEM);
  184. pci_set_region(hose[1].regions + 1,
  185. CFG_PCI2_IO_BASE,
  186. CFG_PCI2_IO_PHYS,
  187. CFG_PCI2_IO_SIZE,
  188. PCI_REGION_IO);
  189. hose[1].region_count = 2;
  190. pci_setup_indirect(&hose[1],
  191. (CFG_IMMRBAR+0x8380),
  192. (CFG_IMMRBAR+0x8384));
  193. pci_hose_write_config_byte(&hose[1],PCI_BDF(0,0,0),PCI_CLASS_CODE,PCI_CLASS_BRIDGE);
  194. pci_hose_read_config_word (&hose[1],PCI_BDF(0,0,0), PCI_COMMAND, &reg16);
  195. reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  196. pci_hose_write_config_word(&hose[1],PCI_BDF(0,0,0), PCI_COMMAND, reg16);
  197. /*
  198. * Clear non-reserved bits in status register.
  199. */
  200. pci_hose_write_config_word(&hose[1],PCI_BDF(0,0,0), PCI_STATUS, 0xffff);
  201. pci_hose_write_config_byte(&hose[1],PCI_BDF(0,0,0), PCI_LATENCY_TIMER,0x80);
  202. #endif
  203. #if defined(PCI_64BIT)
  204. printf("PCI1 64bit on PMC2\n");
  205. #elif defined(PCI_ALL_PCI1)
  206. printf("PCI1 32bit on PMC1 & PMC2 & PMC3\n");
  207. #elif defined(PCI_ONE_PCI1)
  208. printf("PCI1 32bit on PMC1,PCI2 32bit on PMC2 & PMC3\n");
  209. #else
  210. printf("PCI1 32bit on PMC1 & PMC2 & PMC3 in default\n");
  211. #endif
  212. #if 1
  213. /*
  214. * Hose scan.
  215. */
  216. pci_register_hose(hose);
  217. hose->last_busno = pci_hose_scan(hose);
  218. #endif
  219. }
  220. #endif /* CONFIG_PCI */