sc520_pci.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * (C) Copyright 2008-2011
  3. * Graeme Russ, <graeme.russ@gmail.com>
  4. *
  5. * (C) Copyright 2002
  6. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <pci.h>
  28. #include <asm/io.h>
  29. #include <asm/pci.h>
  30. #include <asm/arch/pci.h>
  31. #include <asm/arch/sc520.h>
  32. static struct {
  33. u8 priority;
  34. u16 level_reg;
  35. u8 level_bit;
  36. } sc520_irq[] = {
  37. { SC520_IRQ0, 0, 0x01 },
  38. { SC520_IRQ1, 0, 0x02 },
  39. { SC520_IRQ2, 1, 0x02 },
  40. { SC520_IRQ3, 0, 0x08 },
  41. { SC520_IRQ4, 0, 0x10 },
  42. { SC520_IRQ5, 0, 0x20 },
  43. { SC520_IRQ6, 0, 0x40 },
  44. { SC520_IRQ7, 0, 0x80 },
  45. { SC520_IRQ8, 1, 0x01 },
  46. { SC520_IRQ9, 1, 0x02 },
  47. { SC520_IRQ10, 1, 0x04 },
  48. { SC520_IRQ11, 1, 0x08 },
  49. { SC520_IRQ12, 1, 0x10 },
  50. { SC520_IRQ13, 1, 0x20 },
  51. { SC520_IRQ14, 1, 0x40 },
  52. { SC520_IRQ15, 1, 0x80 }
  53. };
  54. /* The interrupt used for PCI INTA-INTD */
  55. int sc520_pci_ints[15] = {
  56. -1, -1, -1, -1, -1, -1, -1, -1,
  57. -1, -1, -1, -1, -1, -1, -1
  58. };
  59. /* utility function to configure a pci interrupt */
  60. int pci_sc520_set_irq(int pci_pin, int irq)
  61. {
  62. int i;
  63. u8 tmpb;
  64. u16 tmpw;
  65. debug("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq);
  66. if (irq < 0 || irq > 15)
  67. return -1; /* illegal irq */
  68. if (pci_pin < 0 || pci_pin > 15)
  69. return -1; /* illegal pci int pin */
  70. /* first disable any non-pci interrupt source that use
  71. * this level */
  72. /* PCI interrupt mapping (A through D)*/
  73. for (i = 0; i <= 3 ; i++) {
  74. tmpb = readb(&sc520_mmcr->pci_int_map[i]);
  75. if (tmpb == sc520_irq[irq].priority)
  76. writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[i]);
  77. }
  78. /* GP IRQ interrupt mapping */
  79. for (i = 0; i <= 10 ; i++) {
  80. tmpb = readb(&sc520_mmcr->gp_int_map[i]);
  81. if (tmpb == 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,
  92. &sc520_mmcr->pci_int_map[pci_pin]);
  93. } else {
  94. /* GPIRQ0-GPIRQ10 used for additional PCI INTS */
  95. writeb(sc520_irq[irq].priority,
  96. &sc520_mmcr->gp_int_map[pci_pin - 4]);
  97. /* also set the polarity in this case */
  98. tmpw = readw(&sc520_mmcr->intpinpol);
  99. tmpw |= (1 << (pci_pin-4));
  100. writew(tmpw, &sc520_mmcr->intpinpol);
  101. }
  102. /* register the pin */
  103. sc520_pci_ints[pci_pin] = irq;
  104. return 0; /* OK */
  105. }
  106. void pci_sc520_init(struct pci_controller *hose)
  107. {
  108. hose->first_busno = 0;
  109. hose->last_busno = 0xff;
  110. hose->region_count = pci_set_regions(hose);
  111. pci_setup_type1(hose);
  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. }