pci.c 4.7 KB

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