sc520_pci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/io.h>
  27. #include <asm/pci.h>
  28. #include <asm/ic/pci.h>
  29. #include <asm/ic/sc520.h>
  30. static struct {
  31. u8 priority;
  32. u16 level_reg;
  33. u8 level_bit;
  34. } sc520_irq[] = {
  35. { SC520_IRQ0, 0, 0x01 },
  36. { SC520_IRQ1, 0, 0x02 },
  37. { SC520_IRQ2, 1, 0x02 },
  38. { SC520_IRQ3, 0, 0x08 },
  39. { SC520_IRQ4, 0, 0x10 },
  40. { SC520_IRQ5, 0, 0x20 },
  41. { SC520_IRQ6, 0, 0x40 },
  42. { SC520_IRQ7, 0, 0x80 },
  43. { SC520_IRQ8, 1, 0x01 },
  44. { SC520_IRQ9, 1, 0x02 },
  45. { SC520_IRQ10, 1, 0x04 },
  46. { SC520_IRQ11, 1, 0x08 },
  47. { SC520_IRQ12, 1, 0x10 },
  48. { SC520_IRQ13, 1, 0x20 },
  49. { SC520_IRQ14, 1, 0x40 },
  50. { SC520_IRQ15, 1, 0x80 }
  51. };
  52. /* The interrupt used for PCI INTA-INTD */
  53. int sc520_pci_ints[15] = {
  54. -1, -1, -1, -1, -1, -1, -1, -1,
  55. -1, -1, -1, -1, -1, -1, -1
  56. };
  57. /* utility function to configure a pci interrupt */
  58. int pci_sc520_set_irq(int pci_pin, int irq)
  59. {
  60. int i;
  61. u8 tmpb;
  62. u16 tmpw;
  63. # if 1
  64. printf("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq);
  65. #endif
  66. if (irq < 0 || irq > 15) {
  67. return -1; /* illegal irq */
  68. }
  69. if (pci_pin < 0 || pci_pin > 15) {
  70. return -1; /* illegal pci int pin */
  71. }
  72. /* first disable any non-pci interrupt source that use
  73. * this level */
  74. /* PCI interrupt mapping (A through D)*/
  75. for (i=0; i<=3 ;i++) {
  76. if (readb(&sc520_mmcr->pci_int_map[i]) == sc520_irq[irq].priority)
  77. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[i]);
  78. }
  79. /* GP IRQ interrupt mapping */
  80. for (i=0; i<=10 ;i++) {
  81. if (readb(&sc520_mmcr->gp_int_map[i]) == sc520_irq[irq].priority)
  82. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_int_map[i]);
  83. }
  84. /* Set the trigger to level */
  85. tmpb = readb(&sc520_mmcr->pic_mode[sc520_irq[irq].level_reg]);
  86. tmpb |= sc520_irq[irq].level_bit;
  87. writeb(tmpb, &sc520_mmcr->pic_mode[sc520_irq[irq].level_reg]);
  88. if (pci_pin < 4) {
  89. /* PCI INTA-INTD */
  90. /* route the interrupt */
  91. writeb(sc520_irq[irq].priority, &sc520_mmcr->pci_int_map[pci_pin]);
  92. } else {
  93. /* GPIRQ0-GPIRQ10 used for additional PCI INTS */
  94. writeb(sc520_irq[irq].priority, &sc520_mmcr->gp_int_map[pci_pin - 4]);
  95. /* also set the polarity in this case */
  96. tmpw = readw(&sc520_mmcr->intpinpol);
  97. tmpw |= (1 << (pci_pin-4));
  98. writew(tmpw, &sc520_mmcr->intpinpol);
  99. }
  100. /* register the pin */
  101. sc520_pci_ints[pci_pin] = irq;
  102. return 0; /* OK */
  103. }
  104. void pci_sc520_init(struct pci_controller *hose)
  105. {
  106. hose->first_busno = 0;
  107. hose->last_busno = 0xff;
  108. hose->region_count = pci_set_regions(hose);
  109. pci_setup_type1(hose,
  110. SC520_REG_ADDR,
  111. SC520_REG_DATA);
  112. pci_register_hose(hose);
  113. hose->last_busno = pci_hose_scan(hose);
  114. /* enable target memory acceses on host brige */
  115. pci_write_config_word(0, PCI_COMMAND,
  116. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  117. }