pci_mpc5200.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * (C) Copyright 2000-2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #if defined(CONFIG_PCI) && defined(CONFIG_MPC5200)
  25. #include <asm/processor.h>
  26. #include <asm/io.h>
  27. #include <pci.h>
  28. #include <mpc5xxx.h>
  29. /* System RAM mapped over PCI */
  30. #define CONFIG_PCI_MEMORY_BUS CFG_SDRAM_BASE
  31. #define CONFIG_PCI_MEMORY_PHYS CFG_SDRAM_BASE
  32. #define CONFIG_PCI_MEMORY_SIZE (1024 * 1024 * 1024)
  33. /* PCIIWCR bit fields */
  34. #define IWCR_MEM (0 << 3)
  35. #define IWCR_IO (1 << 3)
  36. #define IWCR_READ (0 << 1)
  37. #define IWCR_READLINE (1 << 1)
  38. #define IWCR_READMULT (2 << 1)
  39. #define IWCR_EN (1 << 0)
  40. static int mpc5200_read_config_dword(struct pci_controller *hose,
  41. pci_dev_t dev, int offset, u32* value)
  42. {
  43. *(volatile u32 *)MPC5XXX_PCI_CAR = (1 << 31) | dev | offset;
  44. eieio();
  45. udelay(10);
  46. *value = in_le32((volatile u32 *)CONFIG_PCI_IO_PHYS);
  47. eieio();
  48. *(volatile u32 *)MPC5XXX_PCI_CAR = 0;
  49. udelay(10);
  50. return 0;
  51. }
  52. static int mpc5200_write_config_dword(struct pci_controller *hose,
  53. pci_dev_t dev, int offset, u32 value)
  54. {
  55. *(volatile u32 *)MPC5XXX_PCI_CAR = (1 << 31) | dev | offset;
  56. eieio();
  57. udelay(10);
  58. out_le32((volatile u32 *)CONFIG_PCI_IO_PHYS, value);
  59. eieio();
  60. *(volatile u32 *)MPC5XXX_PCI_CAR = 0;
  61. udelay(10);
  62. return 0;
  63. }
  64. void pci_mpc5xxx_init (struct pci_controller *hose)
  65. {
  66. hose->first_busno = 0;
  67. hose->last_busno = 0xff;
  68. /* System space */
  69. pci_set_region(hose->regions + 0,
  70. CONFIG_PCI_MEMORY_BUS,
  71. CONFIG_PCI_MEMORY_PHYS,
  72. CONFIG_PCI_MEMORY_SIZE,
  73. PCI_REGION_MEM | PCI_REGION_MEMORY);
  74. /* PCI memory space */
  75. pci_set_region(hose->regions + 1,
  76. CONFIG_PCI_MEM_BUS,
  77. CONFIG_PCI_MEM_PHYS,
  78. CONFIG_PCI_MEM_SIZE,
  79. PCI_REGION_MEM);
  80. /* PCI IO space */
  81. pci_set_region(hose->regions + 2,
  82. CONFIG_PCI_IO_BUS,
  83. CONFIG_PCI_IO_PHYS,
  84. CONFIG_PCI_IO_SIZE,
  85. PCI_REGION_IO);
  86. hose->region_count = 3;
  87. pci_register_hose(hose);
  88. /* GPIO Multiplexing - enable PCI */
  89. *(vu_long *)MPC5XXX_GPS_PORT_CONFIG &= ~(1 << 15);
  90. /* Set host bridge as pci master and enable memory decoding */
  91. *(vu_long *)MPC5XXX_PCI_CMD |=
  92. PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  93. /* Set maximum latency timer */
  94. *(vu_long *)MPC5XXX_PCI_CFG |= (0xf800);
  95. /* Set cache line size */
  96. *(vu_long *)MPC5XXX_PCI_CFG = (*(vu_long *)MPC5XXX_PCI_CFG & ~0xff) |
  97. (CFG_CACHELINE_SIZE / 4);
  98. /* Map MBAR to PCI space */
  99. *(vu_long *)MPC5XXX_PCI_BAR0 = CFG_MBAR;
  100. *(vu_long *)MPC5XXX_PCI_TBATR0 = CFG_MBAR | 1;
  101. /* Map RAM to PCI space */
  102. *(vu_long *)MPC5XXX_PCI_BAR1 = CONFIG_PCI_MEMORY_BUS | (1 << 3);
  103. *(vu_long *)MPC5XXX_PCI_TBATR1 = CONFIG_PCI_MEMORY_PHYS | 1;
  104. /* Enable snooping for RAM */
  105. *(vu_long *)(MPC5XXX_XLBARB + 0x40) |= (1 << 15);
  106. *(vu_long *)(MPC5XXX_XLBARB + 0x70) = CONFIG_PCI_MEMORY_PHYS | 0x1d;
  107. /* Park XLB on PCI */
  108. *(vu_long *)(MPC5XXX_XLBARB + 0x40) &= ~((7 << 8) | (3 << 5));
  109. *(vu_long *)(MPC5XXX_XLBARB + 0x40) |= (3 << 8) | (3 << 5);
  110. /* Disable interrupts from PCI controller */
  111. *(vu_long *)MPC5XXX_PCI_GSCR &= ~(7 << 12);
  112. *(vu_long *)MPC5XXX_PCI_ICR &= ~(7 << 24);
  113. /* Disable initiator windows */
  114. *(vu_long *)MPC5XXX_PCI_IWCR = 0;
  115. /* Map PCI memory to physical space */
  116. *(vu_long *)MPC5XXX_PCI_IW0BTAR = CONFIG_PCI_MEM_PHYS |
  117. (((CONFIG_PCI_MEM_SIZE - 1) >> 8) & 0x00ff0000) |
  118. (CONFIG_PCI_MEM_BUS >> 16);
  119. *(vu_long *)MPC5XXX_PCI_IWCR |= (IWCR_MEM | IWCR_READ | IWCR_EN) << 24;
  120. /* Map PCI I/O to physical space */
  121. *(vu_long *)MPC5XXX_PCI_IW1BTAR = CONFIG_PCI_IO_PHYS |
  122. (((CONFIG_PCI_IO_SIZE - 1) >> 8) & 0x00ff0000) |
  123. (CONFIG_PCI_IO_BUS >> 16);
  124. *(vu_long *)MPC5XXX_PCI_IWCR |= (IWCR_IO | IWCR_READ | IWCR_EN) << 16;
  125. /* Reset the PCI bus */
  126. *(vu_long *)MPC5XXX_PCI_GSCR |= 1;
  127. udelay(1000);
  128. *(vu_long *)MPC5XXX_PCI_GSCR &= ~1;
  129. udelay(1000);
  130. pci_set_ops(hose,
  131. pci_hose_read_config_byte_via_dword,
  132. pci_hose_read_config_word_via_dword,
  133. mpc5200_read_config_dword,
  134. pci_hose_write_config_byte_via_dword,
  135. pci_hose_write_config_word_via_dword,
  136. mpc5200_write_config_dword);
  137. udelay(1000);
  138. #ifdef CONFIG_PCI_SCAN_SHOW
  139. printf("PCI: Bus Dev VenId DevId Class Int\n");
  140. #endif
  141. hose->last_busno = pci_hose_scan(hose);
  142. }
  143. #endif /* CONFIG_PCI && CONFIG_MPC5200 */