fixup-cobalt.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 ([email protected])
  10. */
  11. #include <linux/types.h>
  12. #include <linux/pci.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <asm/io.h>
  16. #include <asm/gt64120.h>
  17. #include <cobalt.h>
  18. #include <irq.h>
  19. /*
  20. * PCI slot numbers
  21. */
  22. #define COBALT_PCICONF_CPU 0x06
  23. #define COBALT_PCICONF_ETH0 0x07
  24. #define COBALT_PCICONF_RAQSCSI 0x08
  25. #define COBALT_PCICONF_VIA 0x09
  26. #define COBALT_PCICONF_PCISLOT 0x0A
  27. #define COBALT_PCICONF_ETH1 0x0C
  28. /*
  29. * The Cobalt board ID information. The boards have an ID number wired
  30. * into the VIA that is available in the high nibble of register 94.
  31. */
  32. #define VIA_COBALT_BRD_ID_REG 0x94
  33. #define VIA_COBALT_BRD_REG_to_ID(reg) ((unsigned char)(reg) >> 4)
  34. /*
  35. * Default value of PCI Class Code on GT64111 is PCI_CLASS_MEMORY_OTHER (0x0580)
  36. * instead of PCI_CLASS_BRIDGE_HOST (0x0600). Galileo explained this choice in
  37. * document "GT-64111 System Controller for RC4640, RM523X and VR4300 CPUs",
  38. * section "6.5.3 PCI Autoconfiguration at RESET":
  39. *
  40. * Some PCs refuse to configure host bridges if they are found plugged into
  41. * a PCI slot (ask the BIOS vendors why...). The "Memory Controller" Class
  42. * Code does not cause a problem for these non-compliant BIOSes, so we used
  43. * this as the default in the GT-64111.
  44. *
  45. * So fix the incorrect default value of PCI Class Code. More details are on:
  46. * https://lore.kernel.org/r/20211102154831.xtrlgrmrizl5eidl@pali/
  47. * https://lore.kernel.org/r/[email protected]/
  48. */
  49. static void qube_raq_galileo_early_fixup(struct pci_dev *dev)
  50. {
  51. if (dev->devfn == PCI_DEVFN(0, 0) &&
  52. (dev->class >> 8) == PCI_CLASS_MEMORY_OTHER) {
  53. dev->class = (PCI_CLASS_BRIDGE_HOST << 8) | (dev->class & 0xff);
  54. printk(KERN_INFO "Galileo: fixed bridge class\n");
  55. }
  56. }
  57. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_GT64111,
  58. qube_raq_galileo_early_fixup);
  59. static void qube_raq_via_bmIDE_fixup(struct pci_dev *dev)
  60. {
  61. unsigned short cfgword;
  62. unsigned char lt;
  63. /* Enable Bus Mastering and fast back to back. */
  64. pci_read_config_word(dev, PCI_COMMAND, &cfgword);
  65. cfgword |= (PCI_COMMAND_FAST_BACK | PCI_COMMAND_MASTER);
  66. pci_write_config_word(dev, PCI_COMMAND, cfgword);
  67. /* Enable both ide interfaces. ROM only enables primary one. */
  68. pci_write_config_byte(dev, 0x40, 0xb);
  69. /* Set latency timer to reasonable value. */
  70. pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lt);
  71. if (lt < 64)
  72. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
  73. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 8);
  74. }
  75. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1,
  76. qube_raq_via_bmIDE_fixup);
  77. static void qube_raq_galileo_fixup(struct pci_dev *dev)
  78. {
  79. if (dev->devfn != PCI_DEVFN(0, 0))
  80. return;
  81. /* Fix PCI latency-timer and cache-line-size values in Galileo
  82. * host bridge.
  83. */
  84. pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
  85. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 8);
  86. /*
  87. * The code described by the comment below has been removed
  88. * as it causes bus mastering by the Ethernet controllers
  89. * to break under any kind of network load. We always set
  90. * the retry timeouts to their maximum.
  91. *
  92. * --x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--
  93. *
  94. * On all machines prior to Q2, we had the STOP line disconnected
  95. * from Galileo to VIA on PCI. The new Galileo does not function
  96. * correctly unless we have it connected.
  97. *
  98. * Therefore we must set the disconnect/retry cycle values to
  99. * something sensible when using the new Galileo.
  100. */
  101. printk(KERN_INFO "Galileo: revision %u\n", dev->revision);
  102. #if 0
  103. if (dev->revision >= 0x10) {
  104. /* New Galileo, assumes PCI stop line to VIA is connected. */
  105. GT_WRITE(GT_PCI0_TOR_OFS, 0x4020);
  106. } else if (dev->revision == 0x1 || dev->revision == 0x2)
  107. #endif
  108. {
  109. signed int timeo;
  110. /* XXX WE MUST DO THIS ELSE GALILEO LOCKS UP! -DaveM */
  111. timeo = GT_READ(GT_PCI0_TOR_OFS);
  112. /* Old Galileo, assumes PCI STOP line to VIA is disconnected. */
  113. GT_WRITE(GT_PCI0_TOR_OFS,
  114. (0xff << 16) | /* retry count */
  115. (0xff << 8) | /* timeout 1 */
  116. 0xff); /* timeout 0 */
  117. /* enable PCI retry exceeded interrupt */
  118. GT_WRITE(GT_INTRMASK_OFS, GT_INTR_RETRYCTR0_MSK | GT_READ(GT_INTRMASK_OFS));
  119. }
  120. }
  121. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_GT64111,
  122. qube_raq_galileo_fixup);
  123. int cobalt_board_id;
  124. static void qube_raq_via_board_id_fixup(struct pci_dev *dev)
  125. {
  126. u8 id;
  127. int retval;
  128. retval = pci_read_config_byte(dev, VIA_COBALT_BRD_ID_REG, &id);
  129. if (retval) {
  130. panic("Cannot read board ID");
  131. return;
  132. }
  133. cobalt_board_id = VIA_COBALT_BRD_REG_to_ID(id);
  134. printk(KERN_INFO "Cobalt board ID: %d\n", cobalt_board_id);
  135. }
  136. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_0,
  137. qube_raq_via_board_id_fixup);
  138. static char irq_tab_qube1[] = {
  139. [COBALT_PCICONF_CPU] = 0,
  140. [COBALT_PCICONF_ETH0] = QUBE1_ETH0_IRQ,
  141. [COBALT_PCICONF_RAQSCSI] = SCSI_IRQ,
  142. [COBALT_PCICONF_VIA] = 0,
  143. [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
  144. [COBALT_PCICONF_ETH1] = 0
  145. };
  146. static char irq_tab_cobalt[] = {
  147. [COBALT_PCICONF_CPU] = 0,
  148. [COBALT_PCICONF_ETH0] = ETH0_IRQ,
  149. [COBALT_PCICONF_RAQSCSI] = SCSI_IRQ,
  150. [COBALT_PCICONF_VIA] = 0,
  151. [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
  152. [COBALT_PCICONF_ETH1] = ETH1_IRQ
  153. };
  154. static char irq_tab_raq2[] = {
  155. [COBALT_PCICONF_CPU] = 0,
  156. [COBALT_PCICONF_ETH0] = ETH0_IRQ,
  157. [COBALT_PCICONF_RAQSCSI] = RAQ2_SCSI_IRQ,
  158. [COBALT_PCICONF_VIA] = 0,
  159. [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
  160. [COBALT_PCICONF_ETH1] = ETH1_IRQ
  161. };
  162. int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  163. {
  164. if (cobalt_board_id <= COBALT_BRD_ID_QUBE1)
  165. return irq_tab_qube1[slot];
  166. if (cobalt_board_id == COBALT_BRD_ID_RAQ2)
  167. return irq_tab_raq2[slot];
  168. return irq_tab_cobalt[slot];
  169. }
  170. /* Do platform specific device initialization at pci_enable_device() time */
  171. int pcibios_plat_dev_init(struct pci_dev *dev)
  172. {
  173. return 0;
  174. }