eNET_pci.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * (C) Copyright 2008,2009
  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/pci.h>
  29. #include <asm/arch/pci.h>
  30. static void pci_enet_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  31. {
  32. /* a configurable lists of IRQs to steal when we need one */
  33. static int irq_list[] = {
  34. CONFIG_SYS_FIRST_PCI_IRQ,
  35. CONFIG_SYS_SECOND_PCI_IRQ,
  36. CONFIG_SYS_THIRD_PCI_IRQ,
  37. CONFIG_SYS_FORTH_PCI_IRQ
  38. };
  39. static int next_irq_index;
  40. uchar tmp_pin;
  41. int pin;
  42. pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &tmp_pin);
  43. pin = tmp_pin;
  44. pin -= 1; /* PCI config space use 1-based numbering */
  45. if (pin == -1)
  46. return; /* device use no irq */
  47. /* map device number + pin to a pin on the sc520 */
  48. switch (PCI_DEV(dev)) {
  49. case 12: /* First Ethernet Chip */
  50. pin += SC520_PCI_INTA;
  51. break;
  52. case 13: /* Second Ethernet Chip */
  53. pin += SC520_PCI_INTB;
  54. break;
  55. default:
  56. return;
  57. }
  58. pin &= 3; /* wrap around */
  59. if (sc520_pci_ints[pin] == -1) {
  60. /* re-route one interrupt for us */
  61. if (next_irq_index > 3)
  62. return;
  63. if (pci_sc520_set_irq(pin, irq_list[next_irq_index]))
  64. return;
  65. next_irq_index++;
  66. }
  67. if (-1 != sc520_pci_ints[pin])
  68. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE,
  69. sc520_pci_ints[pin]);
  70. printf("fixup_irq: device %d pin %c irq %d\n",
  71. PCI_DEV(dev), 'A' + pin, sc520_pci_ints[pin]);
  72. }
  73. static struct pci_controller enet_hose = {
  74. fixup_irq: pci_enet_fixup_irq,
  75. };
  76. void pci_init_board(void)
  77. {
  78. pci_sc520_init(&enet_hose);
  79. }
  80. int pci_set_regions(struct pci_controller *hose)
  81. {
  82. /* System memory space */
  83. pci_set_region(hose->regions + 0,
  84. SC520_PCI_MEMORY_BUS,
  85. SC520_PCI_MEMORY_PHYS,
  86. SC520_PCI_MEMORY_SIZE,
  87. PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  88. /* ISA/PCI memory space */
  89. pci_set_region(hose->regions + 1,
  90. SC520_ISA_MEM_BUS,
  91. SC520_ISA_MEM_PHYS,
  92. SC520_ISA_MEM_SIZE,
  93. PCI_REGION_MEM);
  94. /* PCI I/O space */
  95. pci_set_region(hose->regions + 2,
  96. SC520_PCI_IO_BUS,
  97. SC520_PCI_IO_PHYS,
  98. SC520_PCI_IO_SIZE,
  99. PCI_REGION_IO);
  100. /* ISA/PCI I/O space */
  101. pci_set_region(hose->regions + 3,
  102. SC520_ISA_IO_BUS,
  103. SC520_ISA_IO_PHYS,
  104. SC520_ISA_IO_SIZE,
  105. PCI_REGION_IO);
  106. return 4;
  107. }