fixup-cobalt.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Cobalt Qube/Raq PCI support
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 1995, 1996, 1997, 2002, 2003 by Ralf Baechle
  9. * Copyright (C) 2001, 2002, 2003 by Liam Davies (ldavies@agile.tv)
  10. */
  11. #include <linux/types.h>
  12. #include <linux/pci.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <asm/pci.h>
  16. #include <asm/io.h>
  17. #include <asm/gt64120.h>
  18. #include <cobalt.h>
  19. #include <irq.h>
  20. /*
  21. * PCI slot numbers
  22. */
  23. #define COBALT_PCICONF_CPU 0x06
  24. #define COBALT_PCICONF_ETH0 0x07
  25. #define COBALT_PCICONF_RAQSCSI 0x08
  26. #define COBALT_PCICONF_VIA 0x09
  27. #define COBALT_PCICONF_PCISLOT 0x0A
  28. #define COBALT_PCICONF_ETH1 0x0C
  29. /*
  30. * The Cobalt board ID information. The boards have an ID number wired
  31. * into the VIA that is available in the high nibble of register 94.
  32. */
  33. #define VIA_COBALT_BRD_ID_REG 0x94
  34. #define VIA_COBALT_BRD_REG_to_ID(reg) ((unsigned char)(reg) >> 4)
  35. static void qube_raq_galileo_early_fixup(struct pci_dev *dev)
  36. {
  37. if (dev->devfn == PCI_DEVFN(0, 0) &&
  38. (dev->class >> 8) == PCI_CLASS_MEMORY_OTHER) {
  39. dev->class = (PCI_CLASS_BRIDGE_HOST << 8) | (dev->class & 0xff);
  40. printk(KERN_INFO "Galileo: fixed bridge class\n");
  41. }
  42. }
  43. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_GT64111,
  44. qube_raq_galileo_early_fixup);
  45. static void __devinit cobalt_legacy_ide_resource_fixup(struct pci_dev *dev,
  46. struct resource *res)
  47. {
  48. struct pci_controller *hose = (struct pci_controller *)dev->sysdata;
  49. unsigned long offset = hose->io_offset;
  50. struct resource orig = *res;
  51. if (!(res->flags & IORESOURCE_IO) ||
  52. !(res->flags & IORESOURCE_PCI_FIXED))
  53. return;
  54. res->start -= offset;
  55. res->end -= offset;
  56. dev_printk(KERN_DEBUG, &dev->dev, "converted legacy %pR to bus %pR\n",
  57. &orig, res);
  58. }
  59. static void __devinit cobalt_legacy_ide_fixup(struct pci_dev *dev)
  60. {
  61. u32 class;
  62. u8 progif;
  63. /*
  64. * If the IDE controller is in legacy mode, pci_setup_device() fills in
  65. * the resources with the legacy addresses that normally appear on the
  66. * PCI bus, just as if we had read them from a BAR.
  67. *
  68. * However, with the GT-64111, those legacy addresses, e.g., 0x1f0,
  69. * will never appear on the PCI bus because it converts memory accesses
  70. * in the PCI I/O region (which is never at address zero) into I/O port
  71. * accesses with no address translation.
  72. *
  73. * For example, if GT_DEF_PCI0_IO_BASE is 0x10000000, a load or store
  74. * to physical address 0x100001f0 will become a PCI access to I/O port
  75. * 0x100001f0. There's no way to generate an access to I/O port 0x1f0,
  76. * but the VT82C586 IDE controller does respond at 0x100001f0 because
  77. * it only decodes the low 24 bits of the address.
  78. *
  79. * When this quirk runs, the pci_dev resources should contain bus
  80. * addresses, not Linux I/O port numbers, so convert legacy addresses
  81. * like 0x1f0 to bus addresses like 0x100001f0. Later, we'll convert
  82. * them back with pcibios_fixup_bus() or pcibios_bus_to_resource().
  83. */
  84. class = dev->class >> 8;
  85. if (class != PCI_CLASS_STORAGE_IDE)
  86. return;
  87. pci_read_config_byte(dev, PCI_CLASS_PROG, &progif);
  88. if ((progif & 1) == 0) {
  89. cobalt_legacy_ide_resource_fixup(dev, &dev->resource[0]);
  90. cobalt_legacy_ide_resource_fixup(dev, &dev->resource[1]);
  91. }
  92. if ((progif & 4) == 0) {
  93. cobalt_legacy_ide_resource_fixup(dev, &dev->resource[2]);
  94. cobalt_legacy_ide_resource_fixup(dev, &dev->resource[3]);
  95. }
  96. }
  97. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1,
  98. cobalt_legacy_ide_fixup);
  99. static void qube_raq_via_bmIDE_fixup(struct pci_dev *dev)
  100. {
  101. unsigned short cfgword;
  102. unsigned char lt;
  103. /* Enable Bus Mastering and fast back to back. */
  104. pci_read_config_word(dev, PCI_COMMAND, &cfgword);
  105. cfgword |= (PCI_COMMAND_FAST_BACK | PCI_COMMAND_MASTER);
  106. pci_write_config_word(dev, PCI_COMMAND, cfgword);
  107. /* Enable both ide interfaces. ROM only enables primary one. */
  108. pci_write_config_byte(dev, 0x40, 0xb);
  109. /* Set latency timer to reasonable value. */
  110. pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lt);
  111. if (lt < 64)
  112. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
  113. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 8);
  114. }
  115. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1,
  116. qube_raq_via_bmIDE_fixup);
  117. static void qube_raq_galileo_fixup(struct pci_dev *dev)
  118. {
  119. if (dev->devfn != PCI_DEVFN(0, 0))
  120. return;
  121. /* Fix PCI latency-timer and cache-line-size values in Galileo
  122. * host bridge.
  123. */
  124. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
  125. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 8);
  126. /*
  127. * The code described by the comment below has been removed
  128. * as it causes bus mastering by the Ethernet controllers
  129. * to break under any kind of network load. We always set
  130. * the retry timeouts to their maximum.
  131. *
  132. * --x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--
  133. *
  134. * On all machines prior to Q2, we had the STOP line disconnected
  135. * from Galileo to VIA on PCI. The new Galileo does not function
  136. * correctly unless we have it connected.
  137. *
  138. * Therefore we must set the disconnect/retry cycle values to
  139. * something sensible when using the new Galileo.
  140. */
  141. printk(KERN_INFO "Galileo: revision %u\n", dev->revision);
  142. #if 0
  143. if (dev->revision >= 0x10) {
  144. /* New Galileo, assumes PCI stop line to VIA is connected. */
  145. GT_WRITE(GT_PCI0_TOR_OFS, 0x4020);
  146. } else if (dev->revision == 0x1 || dev->revision == 0x2)
  147. #endif
  148. {
  149. signed int timeo;
  150. /* XXX WE MUST DO THIS ELSE GALILEO LOCKS UP! -DaveM */
  151. timeo = GT_READ(GT_PCI0_TOR_OFS);
  152. /* Old Galileo, assumes PCI STOP line to VIA is disconnected. */
  153. GT_WRITE(GT_PCI0_TOR_OFS,
  154. (0xff << 16) | /* retry count */
  155. (0xff << 8) | /* timeout 1 */
  156. 0xff); /* timeout 0 */
  157. /* enable PCI retry exceeded interrupt */
  158. GT_WRITE(GT_INTRMASK_OFS, GT_INTR_RETRYCTR0_MSK | GT_READ(GT_INTRMASK_OFS));
  159. }
  160. }
  161. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_GT64111,
  162. qube_raq_galileo_fixup);
  163. int cobalt_board_id;
  164. static void qube_raq_via_board_id_fixup(struct pci_dev *dev)
  165. {
  166. u8 id;
  167. int retval;
  168. retval = pci_read_config_byte(dev, VIA_COBALT_BRD_ID_REG, &id);
  169. if (retval) {
  170. panic("Cannot read board ID");
  171. return;
  172. }
  173. cobalt_board_id = VIA_COBALT_BRD_REG_to_ID(id);
  174. printk(KERN_INFO "Cobalt board ID: %d\n", cobalt_board_id);
  175. }
  176. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_0,
  177. qube_raq_via_board_id_fixup);
  178. static char irq_tab_qube1[] __initdata = {
  179. [COBALT_PCICONF_CPU] = 0,
  180. [COBALT_PCICONF_ETH0] = QUBE1_ETH0_IRQ,
  181. [COBALT_PCICONF_RAQSCSI] = SCSI_IRQ,
  182. [COBALT_PCICONF_VIA] = 0,
  183. [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
  184. [COBALT_PCICONF_ETH1] = 0
  185. };
  186. static char irq_tab_cobalt[] __initdata = {
  187. [COBALT_PCICONF_CPU] = 0,
  188. [COBALT_PCICONF_ETH0] = ETH0_IRQ,
  189. [COBALT_PCICONF_RAQSCSI] = SCSI_IRQ,
  190. [COBALT_PCICONF_VIA] = 0,
  191. [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
  192. [COBALT_PCICONF_ETH1] = ETH1_IRQ
  193. };
  194. static char irq_tab_raq2[] __initdata = {
  195. [COBALT_PCICONF_CPU] = 0,
  196. [COBALT_PCICONF_ETH0] = ETH0_IRQ,
  197. [COBALT_PCICONF_RAQSCSI] = RAQ2_SCSI_IRQ,
  198. [COBALT_PCICONF_VIA] = 0,
  199. [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
  200. [COBALT_PCICONF_ETH1] = ETH1_IRQ
  201. };
  202. int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  203. {
  204. if (cobalt_board_id <= COBALT_BRD_ID_QUBE1)
  205. return irq_tab_qube1[slot];
  206. if (cobalt_board_id == COBALT_BRD_ID_RAQ2)
  207. return irq_tab_raq2[slot];
  208. return irq_tab_cobalt[slot];
  209. }
  210. /* Do platform specific device initialization at pci_enable_device() time */
  211. int pcibios_plat_dev_init(struct pci_dev *dev)
  212. {
  213. return 0;
  214. }