pci.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * See file CREDITS for list of people who contributed to this
  3. * project.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. *
  20. */
  21. #include <asm/mmu.h>
  22. #include <asm/io.h>
  23. #include <common.h>
  24. #include <mpc83xx.h>
  25. #include <pci.h>
  26. #include <i2c.h>
  27. #include <asm/fsl_i2c.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. #ifdef CONFIG_PCI
  30. static struct pci_region pci1_regions[] = {
  31. {
  32. bus_start: CONFIG_SYS_PCI1_MEM_BASE,
  33. phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
  34. size: CONFIG_SYS_PCI1_MEM_SIZE,
  35. flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
  36. },
  37. {
  38. bus_start: CONFIG_SYS_PCI1_IO_BASE,
  39. phys_start: CONFIG_SYS_PCI1_IO_PHYS,
  40. size: CONFIG_SYS_PCI1_IO_SIZE,
  41. flags: PCI_REGION_IO
  42. },
  43. {
  44. bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
  45. phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
  46. size: CONFIG_SYS_PCI1_MMIO_SIZE,
  47. flags: PCI_REGION_MEM
  48. },
  49. };
  50. #ifdef CONFIG_MPC83XX_PCI2
  51. static struct pci_region pci2_regions[] = {
  52. {
  53. bus_start: CONFIG_SYS_PCI2_MEM_BASE,
  54. phys_start: CONFIG_SYS_PCI2_MEM_PHYS,
  55. size: CONFIG_SYS_PCI2_MEM_SIZE,
  56. flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
  57. },
  58. {
  59. bus_start: CONFIG_SYS_PCI2_IO_BASE,
  60. phys_start: CONFIG_SYS_PCI2_IO_PHYS,
  61. size: CONFIG_SYS_PCI2_IO_SIZE,
  62. flags: PCI_REGION_IO
  63. },
  64. {
  65. bus_start: CONFIG_SYS_PCI2_MMIO_BASE,
  66. phys_start: CONFIG_SYS_PCI2_MMIO_PHYS,
  67. size: CONFIG_SYS_PCI2_MMIO_SIZE,
  68. flags: PCI_REGION_MEM
  69. },
  70. };
  71. #endif
  72. #ifndef CONFIG_PCISLAVE
  73. void pib_init(void)
  74. {
  75. u8 val8, orig_i2c_bus;
  76. /*
  77. * Assign PIB PMC slot to desired PCI bus
  78. */
  79. /* Switch temporarily to I2C bus #2 */
  80. orig_i2c_bus = i2c_get_bus_num();
  81. i2c_set_bus_num(1);
  82. val8 = 0;
  83. i2c_write(0x23, 0x6, 1, &val8, 1);
  84. i2c_write(0x23, 0x7, 1, &val8, 1);
  85. val8 = 0xff;
  86. i2c_write(0x23, 0x2, 1, &val8, 1);
  87. i2c_write(0x23, 0x3, 1, &val8, 1);
  88. val8 = 0;
  89. i2c_write(0x26, 0x6, 1, &val8, 1);
  90. val8 = 0x34;
  91. i2c_write(0x26, 0x7, 1, &val8, 1);
  92. #if defined(PCI_64BIT)
  93. val8 = 0xf4; /* PMC2:PCI1/64-bit */
  94. #elif defined(PCI_ALL_PCI1)
  95. val8 = 0xf3; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
  96. #elif defined(PCI_ONE_PCI1)
  97. val8 = 0xf9; /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
  98. #else
  99. val8 = 0xf5; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
  100. #endif
  101. i2c_write(0x26, 0x2, 1, &val8, 1);
  102. val8 = 0xff;
  103. i2c_write(0x26, 0x3, 1, &val8, 1);
  104. val8 = 0;
  105. i2c_write(0x27, 0x6, 1, &val8, 1);
  106. i2c_write(0x27, 0x7, 1, &val8, 1);
  107. val8 = 0xff;
  108. i2c_write(0x27, 0x2, 1, &val8, 1);
  109. val8 = 0xef;
  110. i2c_write(0x27, 0x3, 1, &val8, 1);
  111. asm("eieio");
  112. #if defined(PCI_64BIT)
  113. printf("PCI1: 64-bit on PMC2\n");
  114. #elif defined(PCI_ALL_PCI1)
  115. printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
  116. #elif defined(PCI_ONE_PCI1)
  117. printf("PCI1: 32-bit on PMC1\n");
  118. printf("PCI2: 32-bit on PMC2, PMC3\n");
  119. #else
  120. printf("PCI1: 32-bit on PMC1, PMC2\n");
  121. printf("PCI2: 32-bit on PMC3\n");
  122. #endif
  123. /* Reset to original I2C bus */
  124. i2c_set_bus_num(orig_i2c_bus);
  125. }
  126. void pci_init_board(void)
  127. {
  128. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  129. volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
  130. volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
  131. #ifndef CONFIG_MPC83XX_PCI2
  132. struct pci_region *reg[] = { pci1_regions };
  133. #else
  134. struct pci_region *reg[] = { pci1_regions, pci2_regions };
  135. #endif
  136. /* initialize the PCA9555PW IO expander on the PIB board */
  137. pib_init();
  138. /* Enable all 8 PCI_CLK_OUTPUTS */
  139. clk->occr = 0xff000000;
  140. udelay(2000);
  141. /* Configure PCI Local Access Windows */
  142. pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
  143. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  144. pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
  145. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
  146. udelay(2000);
  147. #ifndef CONFIG_MPC83XX_PCI2
  148. mpc83xx_pci_init(1, reg, 0);
  149. #else
  150. mpc83xx_pci_init(2, reg, 0);
  151. #endif
  152. }
  153. #else
  154. void pci_init_board(void)
  155. {
  156. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  157. volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
  158. volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[0];
  159. struct pci_region *reg[] = { pci1_regions };
  160. /* Configure PCI Local Access Windows */
  161. pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
  162. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  163. pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
  164. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
  165. mpc83xx_pci_init(1, reg, 0);
  166. /* Configure PCI Inbound Translation Windows (3 1MB windows) */
  167. pci_ctrl->pitar0 = 0x0;
  168. pci_ctrl->pibar0 = 0x0;
  169. pci_ctrl->piwar0 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  170. PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
  171. pci_ctrl->pitar1 = 0x0;
  172. pci_ctrl->pibar1 = 0x0;
  173. pci_ctrl->piebar1 = 0x0;
  174. pci_ctrl->piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  175. PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
  176. pci_ctrl->pitar2 = 0x0;
  177. pci_ctrl->pibar2 = 0x0;
  178. pci_ctrl->piebar2 = 0x0;
  179. pci_ctrl->piwar2 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  180. PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
  181. /* Unlock the configuration bit */
  182. mpc83xx_pcislave_unlock(0);
  183. printf("PCI: Agent mode enabled\n");
  184. }
  185. #endif /* CONFIG_PCISLAVE */
  186. #endif /* CONFIG_PCI */