pci.c 5.5 KB

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