pci-ddb5477.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * PCI code for DDB5477.
  3. *
  4. * Copyright (C) 2001 MontaVista Software Inc.
  5. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  6. *
  7. * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/types.h>
  17. #include <linux/pci.h>
  18. #include <asm/bootinfo.h>
  19. #include <asm/debug.h>
  20. #include <asm/ddb5xxx/ddb5xxx.h>
  21. static struct resource extpci_io_resource = {
  22. "ext pci IO space",
  23. DDB_PCI0_IO_BASE - DDB_PCI_IO_BASE + 0x4000,
  24. DDB_PCI0_IO_BASE - DDB_PCI_IO_BASE + DDB_PCI0_IO_SIZE - 1,
  25. IORESOURCE_IO
  26. };
  27. static struct resource extpci_mem_resource = {
  28. "ext pci memory space",
  29. DDB_PCI0_MEM_BASE + 0x100000,
  30. DDB_PCI0_MEM_BASE + DDB_PCI0_MEM_SIZE - 1,
  31. IORESOURCE_MEM
  32. };
  33. static struct resource iopci_io_resource = {
  34. "io pci IO space",
  35. DDB_PCI1_IO_BASE - DDB_PCI_IO_BASE,
  36. DDB_PCI1_IO_BASE - DDB_PCI_IO_BASE + DDB_PCI1_IO_SIZE - 1,
  37. IORESOURCE_IO
  38. };
  39. static struct resource iopci_mem_resource = {
  40. "ext pci memory space",
  41. DDB_PCI1_MEM_BASE,
  42. DDB_PCI1_MEM_BASE + DDB_PCI1_MEM_SIZE - 1,
  43. IORESOURCE_MEM
  44. };
  45. extern struct pci_ops ddb5477_ext_pci_ops;
  46. extern struct pci_ops ddb5477_io_pci_ops;
  47. struct pci_controller ddb5477_ext_controller = {
  48. .pci_ops = &ddb5477_ext_pci_ops,
  49. .io_resource = &extpci_io_resource,
  50. .mem_resource = &extpci_mem_resource
  51. };
  52. struct pci_controller ddb5477_io_controller = {
  53. .pci_ops = &ddb5477_io_pci_ops,
  54. .io_resource = &iopci_io_resource,
  55. .mem_resource = &iopci_mem_resource
  56. };
  57. /*
  58. * we fix up irqs based on the slot number.
  59. * The first entry is at AD:11.
  60. * Fortunately this works because, although we have two pci buses,
  61. * they all have different slot numbers (except for rockhopper slot 20
  62. * which is handled below).
  63. *
  64. */
  65. /*
  66. * irq mapping : device -> pci int # -> vrc4377 irq# ,
  67. * ddb5477 board manual page 4 and vrc5477 manual page 46
  68. */
  69. /*
  70. * based on ddb5477 manual page 11
  71. */
  72. #define MAX_SLOT_NUM 21
  73. static unsigned char irq_map[MAX_SLOT_NUM] = {
  74. /* SLOT: 0, AD:11 */ 0xff,
  75. /* SLOT: 1, AD:12 */ 0xff,
  76. /* SLOT: 2, AD:13 */ 0xff,
  77. /* SLOT: 3, AD:14 */ 0xff,
  78. /* SLOT: 4, AD:15 */ VRC5477_IRQ_INTA, /* onboard tulip */
  79. /* SLOT: 5, AD:16 */ VRC5477_IRQ_INTB, /* slot 1 */
  80. /* SLOT: 6, AD:17 */ VRC5477_IRQ_INTC, /* slot 2 */
  81. /* SLOT: 7, AD:18 */ VRC5477_IRQ_INTD, /* slot 3 */
  82. /* SLOT: 8, AD:19 */ VRC5477_IRQ_INTE, /* slot 4 */
  83. /* SLOT: 9, AD:20 */ 0xff,
  84. /* SLOT: 10, AD:21 */ 0xff,
  85. /* SLOT: 11, AD:22 */ 0xff,
  86. /* SLOT: 12, AD:23 */ 0xff,
  87. /* SLOT: 13, AD:24 */ 0xff,
  88. /* SLOT: 14, AD:25 */ 0xff,
  89. /* SLOT: 15, AD:26 */ 0xff,
  90. /* SLOT: 16, AD:27 */ 0xff,
  91. /* SLOT: 17, AD:28 */ 0xff,
  92. /* SLOT: 18, AD:29 */ VRC5477_IRQ_IOPCI_INTC, /* vrc5477 ac97 */
  93. /* SLOT: 19, AD:30 */ VRC5477_IRQ_IOPCI_INTB, /* vrc5477 usb peri */
  94. /* SLOT: 20, AD:31 */ VRC5477_IRQ_IOPCI_INTA, /* vrc5477 usb host */
  95. };
  96. static unsigned char rockhopperII_irq_map[MAX_SLOT_NUM] = {
  97. /* SLOT: 0, AD:11 */ 0xff,
  98. /* SLOT: 1, AD:12 */ VRC5477_IRQ_INTB, /* onboard AMD PCNET */
  99. /* SLOT: 2, AD:13 */ 0xff,
  100. /* SLOT: 3, AD:14 */ 0xff,
  101. /* SLOT: 4, AD:15 */ 14, /* M5229 ide ISA irq */
  102. /* SLOT: 5, AD:16 */ VRC5477_IRQ_INTD, /* slot 3 */
  103. /* SLOT: 6, AD:17 */ VRC5477_IRQ_INTA, /* slot 4 */
  104. /* SLOT: 7, AD:18 */ VRC5477_IRQ_INTD, /* slot 5 */
  105. /* SLOT: 8, AD:19 */ 0, /* M5457 modem nop */
  106. /* SLOT: 9, AD:20 */ VRC5477_IRQ_INTA, /* slot 2 */
  107. /* SLOT: 10, AD:21 */ 0xff,
  108. /* SLOT: 11, AD:22 */ 0xff,
  109. /* SLOT: 12, AD:23 */ 0xff,
  110. /* SLOT: 13, AD:24 */ 0xff,
  111. /* SLOT: 14, AD:25 */ 0xff,
  112. /* SLOT: 15, AD:26 */ 0xff,
  113. /* SLOT: 16, AD:27 */ 0xff,
  114. /* SLOT: 17, AD:28 */ 0, /* M7101 PMU nop */
  115. /* SLOT: 18, AD:29 */ VRC5477_IRQ_IOPCI_INTC, /* vrc5477 ac97 */
  116. /* SLOT: 19, AD:30 */ VRC5477_IRQ_IOPCI_INTB, /* vrc5477 usb peri */
  117. /* SLOT: 20, AD:31 */ VRC5477_IRQ_IOPCI_INTA, /* vrc5477 usb host */
  118. };
  119. int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  120. {
  121. int slot_num;
  122. unsigned char *slot_irq_map;
  123. unsigned char irq;
  124. /*
  125. * We ignore the swizzled slot and pin values. The original
  126. * pci_fixup_irq() codes largely base irq number on the dev slot
  127. * numbers because except for one case they are unique even
  128. * though there are multiple pci buses.
  129. */
  130. if (mips_machtype == MACH_NEC_ROCKHOPPERII)
  131. slot_irq_map = rockhopperII_irq_map;
  132. else
  133. slot_irq_map = irq_map;
  134. slot_num = PCI_SLOT(dev->devfn);
  135. irq = slot_irq_map[slot_num];
  136. db_assert(slot_num < MAX_SLOT_NUM);
  137. db_assert(irq != 0xff);
  138. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  139. if (mips_machtype == MACH_NEC_ROCKHOPPERII) {
  140. /* hack to distinquish overlapping slot 20s, one
  141. * on bus 0 (ALI USB on the M1535 on the backplane),
  142. * and one on bus 2 (NEC USB controller on the CPU board)
  143. * Make the M1535 USB - ISA IRQ number 9.
  144. */
  145. if (slot_num == 20 && dev->bus->number == 0) {
  146. pci_write_config_byte(dev,
  147. PCI_INTERRUPT_LINE,
  148. 9);
  149. irq = 9;
  150. }
  151. }
  152. return irq;
  153. }
  154. /* Do platform specific device initialization at pci_enable_device() time */
  155. int pcibios_plat_dev_init(struct pci_dev *dev)
  156. {
  157. return 0;
  158. }
  159. void ddb_pci_reset_bus(void)
  160. {
  161. u32 temp;
  162. /*
  163. * I am not sure about the "official" procedure, the following
  164. * steps work as far as I know:
  165. * We first set PCI cold reset bit (bit 31) in PCICTRL-H.
  166. * Then we clear the PCI warm reset bit (bit 30) to 0 in PCICTRL-H.
  167. * The same is true for both PCI channels.
  168. */
  169. temp = ddb_in32(DDB_PCICTL0_H);
  170. temp |= 0x80000000;
  171. ddb_out32(DDB_PCICTL0_H, temp);
  172. temp &= ~0xc0000000;
  173. ddb_out32(DDB_PCICTL0_H, temp);
  174. temp = ddb_in32(DDB_PCICTL1_H);
  175. temp |= 0x80000000;
  176. ddb_out32(DDB_PCICTL1_H, temp);
  177. temp &= ~0xc0000000;
  178. ddb_out32(DDB_PCICTL1_H, temp);
  179. }