pci.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. *
  3. * BRIEF MODULE DESCRIPTION
  4. *
  5. * Author: source@mvista.com
  6. *
  7. * This program is free software; you can distribute it and/or modify it
  8. * under the terms of the GNU General Public License (Version 2) as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  19. */
  20. #include <linux/types.h>
  21. #include <linux/pci.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <pci.h>
  25. #include <glb.h>
  26. #include <nand.h>
  27. static struct resource pci_io_resource = {
  28. .start = PNX8550_PCIIO + 0x1000, /* reserve regacy I/O space */
  29. .end = PNX8550_PCIIO + PNX8550_PCIIO_SIZE,
  30. .name = "pci IO space",
  31. .flags = IORESOURCE_IO
  32. };
  33. static struct resource pci_mem_resource = {
  34. .start = PNX8550_PCIMEM,
  35. .end = PNX8550_PCIMEM + PNX8550_PCIMEM_SIZE - 1,
  36. .name = "pci memory space",
  37. .flags = IORESOURCE_MEM
  38. };
  39. extern struct pci_ops pnx8550_pci_ops;
  40. static struct pci_controller pnx8550_controller = {
  41. .pci_ops = &pnx8550_pci_ops,
  42. .io_map_base = PNX8550_PORT_BASE,
  43. .io_resource = &pci_io_resource,
  44. .mem_resource = &pci_mem_resource,
  45. };
  46. /* Return the total size of DRAM-memory, (RANK0 + RANK1) */
  47. static inline unsigned long get_system_mem_size(void)
  48. {
  49. /* Read IP2031_RANK0_ADDR_LO */
  50. unsigned long dram_r0_lo = inl(PCI_BASE | 0x65010);
  51. /* Read IP2031_RANK1_ADDR_HI */
  52. unsigned long dram_r1_hi = inl(PCI_BASE | 0x65018);
  53. return dram_r1_hi - dram_r0_lo + 1;
  54. }
  55. static int __init pnx8550_pci_setup(void)
  56. {
  57. int pci_mem_code;
  58. int mem_size = get_system_mem_size() >> 20;
  59. /* Clear the Global 2 Register, PCI Inta Output Enable Registers
  60. Bit 1:Enable DAC Powerdown
  61. -> 0:DACs are enabled and are working normally
  62. 1:DACs are powerdown
  63. Bit 0:Enable of PCI inta output
  64. -> 0 = Disable PCI inta output
  65. 1 = Enable PCI inta output
  66. */
  67. PNX8550_GLB2_ENAB_INTA_O = 0;
  68. /* Calc the PCI mem size code */
  69. if (mem_size >= 128)
  70. pci_mem_code = SIZE_128M;
  71. else if (mem_size >= 64)
  72. pci_mem_code = SIZE_64M;
  73. else if (mem_size >= 32)
  74. pci_mem_code = SIZE_32M;
  75. else
  76. pci_mem_code = SIZE_16M;
  77. /* Set PCI_XIO registers */
  78. outl(pci_mem_resource.start, PCI_BASE | PCI_BASE1_LO);
  79. outl(pci_mem_resource.end + 1, PCI_BASE | PCI_BASE1_HI);
  80. outl(pci_io_resource.start, PCI_BASE | PCI_BASE2_LO);
  81. outl(pci_io_resource.end, PCI_BASE | PCI_BASE2_HI);
  82. /* Send memory transaction via PCI_BASE2 */
  83. outl(0x00000001, PCI_BASE | PCI_IO);
  84. /* Unlock the setup register */
  85. outl(0xca, PCI_BASE | PCI_UNLOCKREG);
  86. /*
  87. * BAR0 of PNX8550 (pci base 10) must be zero in order for ide
  88. * to work, and in order for bus_to_baddr to work without any
  89. * hacks.
  90. */
  91. outl(0x00000000, PCI_BASE | PCI_BASE10);
  92. /*
  93. *These two bars are set by default or the boot code.
  94. * However, it's safer to set them here so we're not boot
  95. * code dependent.
  96. */
  97. outl(0x1be00000, PCI_BASE | PCI_BASE14); /* PNX MMIO */
  98. outl(PNX8550_NAND_BASE_ADDR, PCI_BASE | PCI_BASE18); /* XIO */
  99. outl(PCI_EN_TA |
  100. PCI_EN_PCI2MMI |
  101. PCI_EN_XIO |
  102. PCI_SETUP_BASE18_SIZE(SIZE_32M) |
  103. PCI_SETUP_BASE18_EN |
  104. PCI_SETUP_BASE14_EN |
  105. PCI_SETUP_BASE10_PREF |
  106. PCI_SETUP_BASE10_SIZE(pci_mem_code) |
  107. PCI_SETUP_CFGMANAGE_EN |
  108. PCI_SETUP_PCIARB_EN,
  109. PCI_BASE |
  110. PCI_SETUP); /* PCI_SETUP */
  111. outl(0x00000000, PCI_BASE | PCI_CTRL); /* PCI_CONTROL */
  112. register_pci_controller(&pnx8550_controller);
  113. return 0;
  114. }
  115. arch_initcall(pnx8550_pci_setup);