sc520_pci.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * (C) Copyright 2002
  3. * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
  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. /* stuff specific for the sc520, but independent of implementation */
  24. #include <common.h>
  25. #include <pci.h>
  26. #include <asm/pci.h>
  27. #include <asm/ic/sc520.h>
  28. static struct {
  29. u8 priority;
  30. u16 level_reg;
  31. u8 level_bit;
  32. } sc520_irq[] = {
  33. { SC520_IRQ0, SC520_MPICMODE, 0x01 },
  34. { SC520_IRQ1, SC520_MPICMODE, 0x02 },
  35. { SC520_IRQ2, SC520_SL1PICMODE, 0x02 },
  36. { SC520_IRQ3, SC520_MPICMODE, 0x08 },
  37. { SC520_IRQ4, SC520_MPICMODE, 0x10 },
  38. { SC520_IRQ5, SC520_MPICMODE, 0x20 },
  39. { SC520_IRQ6, SC520_MPICMODE, 0x40 },
  40. { SC520_IRQ7, SC520_MPICMODE, 0x80 },
  41. { SC520_IRQ8, SC520_SL1PICMODE, 0x01 },
  42. { SC520_IRQ9, SC520_SL1PICMODE, 0x02 },
  43. { SC520_IRQ10, SC520_SL1PICMODE, 0x04 },
  44. { SC520_IRQ11, SC520_SL1PICMODE, 0x08 },
  45. { SC520_IRQ12, SC520_SL1PICMODE, 0x10 },
  46. { SC520_IRQ13, SC520_SL1PICMODE, 0x20 },
  47. { SC520_IRQ14, SC520_SL1PICMODE, 0x40 },
  48. { SC520_IRQ15, SC520_SL1PICMODE, 0x80 }
  49. };
  50. /* The interrupt used for PCI INTA-INTD */
  51. int sc520_pci_ints[15] = {
  52. -1, -1, -1, -1, -1, -1, -1, -1,
  53. -1, -1, -1, -1, -1, -1, -1
  54. };
  55. /* utility function to configure a pci interrupt */
  56. int pci_sc520_set_irq(int pci_pin, int irq)
  57. {
  58. int i;
  59. # if 1
  60. printf("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq);
  61. #endif
  62. if (irq < 0 || irq > 15) {
  63. return -1; /* illegal irq */
  64. }
  65. if (pci_pin < 0 || pci_pin > 15) {
  66. return -1; /* illegal pci int pin */
  67. }
  68. /* first disable any non-pci interrupt source that use
  69. * this level */
  70. for (i=SC520_GPTMR0MAP;i<=SC520_GP10IMAP;i++) {
  71. if (i>=SC520_PCIINTAMAP&&i<=SC520_PCIINTDMAP) {
  72. continue;
  73. }
  74. if (read_mmcr_byte(i) == sc520_irq[irq].priority) {
  75. write_mmcr_byte(i, SC520_IRQ_DISABLED);
  76. }
  77. }
  78. /* Set the trigger to level */
  79. write_mmcr_byte(sc520_irq[irq].level_reg,
  80. read_mmcr_byte(sc520_irq[irq].level_reg) | sc520_irq[irq].level_bit);
  81. if (pci_pin < 4) {
  82. /* PCI INTA-INTD */
  83. /* route the interrupt */
  84. write_mmcr_byte(SC520_PCIINTAMAP + pci_pin, sc520_irq[irq].priority);
  85. } else {
  86. /* GPIRQ0-GPIRQ10 used for additional PCI INTS */
  87. write_mmcr_byte(SC520_GP0IMAP + pci_pin - 4, sc520_irq[irq].priority);
  88. /* also set the polarity in this case */
  89. write_mmcr_word(SC520_INTPINPOL,
  90. read_mmcr_word(SC520_INTPINPOL) | (1 << (pci_pin-4)));
  91. }
  92. /* register the pin */
  93. sc520_pci_ints[pci_pin] = irq;
  94. return 0; /* OK */
  95. }
  96. void pci_sc520_init(struct pci_controller *hose)
  97. {
  98. hose->first_busno = 0;
  99. hose->last_busno = 0xff;
  100. /* System memory space */
  101. pci_set_region(hose->regions + 0,
  102. SC520_PCI_MEMORY_BUS,
  103. SC520_PCI_MEMORY_PHYS,
  104. SC520_PCI_MEMORY_SIZE,
  105. PCI_REGION_MEM | PCI_REGION_MEMORY);
  106. /* PCI memory space */
  107. pci_set_region(hose->regions + 1,
  108. SC520_PCI_MEM_BUS,
  109. SC520_PCI_MEM_PHYS,
  110. SC520_PCI_MEM_SIZE,
  111. PCI_REGION_MEM);
  112. /* ISA/PCI memory space */
  113. pci_set_region(hose->regions + 2,
  114. SC520_ISA_MEM_BUS,
  115. SC520_ISA_MEM_PHYS,
  116. SC520_ISA_MEM_SIZE,
  117. PCI_REGION_MEM);
  118. /* PCI I/O space */
  119. pci_set_region(hose->regions + 3,
  120. SC520_PCI_IO_BUS,
  121. SC520_PCI_IO_PHYS,
  122. SC520_PCI_IO_SIZE,
  123. PCI_REGION_IO);
  124. /* ISA/PCI I/O space */
  125. pci_set_region(hose->regions + 4,
  126. SC520_ISA_IO_BUS,
  127. SC520_ISA_IO_PHYS,
  128. SC520_ISA_IO_SIZE,
  129. PCI_REGION_IO);
  130. hose->region_count = 5;
  131. pci_setup_type1(hose,
  132. SC520_REG_ADDR,
  133. SC520_REG_DATA);
  134. pci_register_hose(hose);
  135. hose->last_busno = pci_hose_scan(hose);
  136. /* enable target memory acceses on host brige */
  137. pci_write_config_word(0, PCI_COMMAND,
  138. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  139. }