pci.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <asm/mmu.h>
  7. #include <asm/io.h>
  8. #include <common.h>
  9. #include <mpc83xx.h>
  10. #include <pci.h>
  11. #include <i2c.h>
  12. #include <asm/fsl_i2c.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. static struct pci_region pci1_regions[] = {
  15. {
  16. bus_start: CONFIG_SYS_PCI1_MEM_BASE,
  17. phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
  18. size: CONFIG_SYS_PCI1_MEM_SIZE,
  19. flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
  20. },
  21. {
  22. bus_start: CONFIG_SYS_PCI1_IO_BASE,
  23. phys_start: CONFIG_SYS_PCI1_IO_PHYS,
  24. size: CONFIG_SYS_PCI1_IO_SIZE,
  25. flags: PCI_REGION_IO
  26. },
  27. {
  28. bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
  29. phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
  30. size: CONFIG_SYS_PCI1_MMIO_SIZE,
  31. flags: PCI_REGION_MEM
  32. },
  33. };
  34. #ifdef CONFIG_MPC83XX_PCI2
  35. static struct pci_region pci2_regions[] = {
  36. {
  37. bus_start: CONFIG_SYS_PCI2_MEM_BASE,
  38. phys_start: CONFIG_SYS_PCI2_MEM_PHYS,
  39. size: CONFIG_SYS_PCI2_MEM_SIZE,
  40. flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
  41. },
  42. {
  43. bus_start: CONFIG_SYS_PCI2_IO_BASE,
  44. phys_start: CONFIG_SYS_PCI2_IO_PHYS,
  45. size: CONFIG_SYS_PCI2_IO_SIZE,
  46. flags: PCI_REGION_IO
  47. },
  48. {
  49. bus_start: CONFIG_SYS_PCI2_MMIO_BASE,
  50. phys_start: CONFIG_SYS_PCI2_MMIO_PHYS,
  51. size: CONFIG_SYS_PCI2_MMIO_SIZE,
  52. flags: PCI_REGION_MEM
  53. },
  54. };
  55. #endif
  56. #ifndef CONFIG_PCISLAVE
  57. void pib_init(void)
  58. {
  59. u8 val8, orig_i2c_bus;
  60. /*
  61. * Assign PIB PMC slot to desired PCI bus
  62. */
  63. /* Switch temporarily to I2C bus #2 */
  64. orig_i2c_bus = i2c_get_bus_num();
  65. i2c_set_bus_num(1);
  66. val8 = 0;
  67. i2c_write(0x23, 0x6, 1, &val8, 1);
  68. i2c_write(0x23, 0x7, 1, &val8, 1);
  69. val8 = 0xff;
  70. i2c_write(0x23, 0x2, 1, &val8, 1);
  71. i2c_write(0x23, 0x3, 1, &val8, 1);
  72. val8 = 0;
  73. i2c_write(0x26, 0x6, 1, &val8, 1);
  74. val8 = 0x34;
  75. i2c_write(0x26, 0x7, 1, &val8, 1);
  76. #if defined(PCI_64BIT)
  77. val8 = 0xf4; /* PMC2:PCI1/64-bit */
  78. #elif defined(PCI_ALL_PCI1)
  79. val8 = 0xf3; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
  80. #elif defined(PCI_ONE_PCI1)
  81. val8 = 0xf9; /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
  82. #else
  83. val8 = 0xf5; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
  84. #endif
  85. i2c_write(0x26, 0x2, 1, &val8, 1);
  86. val8 = 0xff;
  87. i2c_write(0x26, 0x3, 1, &val8, 1);
  88. val8 = 0;
  89. i2c_write(0x27, 0x6, 1, &val8, 1);
  90. i2c_write(0x27, 0x7, 1, &val8, 1);
  91. val8 = 0xff;
  92. i2c_write(0x27, 0x2, 1, &val8, 1);
  93. val8 = 0xef;
  94. i2c_write(0x27, 0x3, 1, &val8, 1);
  95. asm("eieio");
  96. #if defined(PCI_64BIT)
  97. printf("PCI1: 64-bit on PMC2\n");
  98. #elif defined(PCI_ALL_PCI1)
  99. printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
  100. #elif defined(PCI_ONE_PCI1)
  101. printf("PCI1: 32-bit on PMC1\n");
  102. printf("PCI2: 32-bit on PMC2, PMC3\n");
  103. #else
  104. printf("PCI1: 32-bit on PMC1, PMC2\n");
  105. printf("PCI2: 32-bit on PMC3\n");
  106. #endif
  107. /* Reset to original I2C bus */
  108. i2c_set_bus_num(orig_i2c_bus);
  109. }
  110. void pci_init_board(void)
  111. {
  112. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  113. volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
  114. volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
  115. #ifndef CONFIG_MPC83XX_PCI2
  116. struct pci_region *reg[] = { pci1_regions };
  117. #else
  118. struct pci_region *reg[] = { pci1_regions, pci2_regions };
  119. #endif
  120. /* initialize the PCA9555PW IO expander on the PIB board */
  121. pib_init();
  122. /* Enable all 8 PCI_CLK_OUTPUTS */
  123. clk->occr = 0xff000000;
  124. udelay(2000);
  125. /* Configure PCI Local Access Windows */
  126. pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
  127. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  128. pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
  129. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
  130. udelay(2000);
  131. #ifndef CONFIG_MPC83XX_PCI2
  132. mpc83xx_pci_init(1, reg);
  133. #else
  134. mpc83xx_pci_init(2, reg);
  135. #endif
  136. }
  137. #else
  138. void pci_init_board(void)
  139. {
  140. volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
  141. volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
  142. volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[0];
  143. struct pci_region *reg[] = { pci1_regions };
  144. /* Configure PCI Local Access Windows */
  145. pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
  146. pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
  147. pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
  148. pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
  149. mpc83xx_pci_init(1, reg);
  150. /* Configure PCI Inbound Translation Windows (3 1MB windows) */
  151. pci_ctrl->pitar0 = 0x0;
  152. pci_ctrl->pibar0 = 0x0;
  153. pci_ctrl->piwar0 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  154. PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
  155. pci_ctrl->pitar1 = 0x0;
  156. pci_ctrl->pibar1 = 0x0;
  157. pci_ctrl->piebar1 = 0x0;
  158. pci_ctrl->piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  159. PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
  160. pci_ctrl->pitar2 = 0x0;
  161. pci_ctrl->pibar2 = 0x0;
  162. pci_ctrl->piebar2 = 0x0;
  163. pci_ctrl->piwar2 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
  164. PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
  165. /* Unlock the configuration bit */
  166. mpc83xx_pcislave_unlock(0);
  167. printf("PCI: Agent mode enabled\n");
  168. }
  169. #endif /* CONFIG_PCISLAVE */