fixup-fuloong2e.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2004 ICT CAS
  4. * Author: Li xiaoyu, ICT CAS
  5. * [email protected]
  6. *
  7. * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
  8. * Author: Fuxin Zhang, [email protected]
  9. */
  10. #include <linux/init.h>
  11. #include <linux/pci.h>
  12. #include <loongson.h>
  13. /* South bridge slot number is set by the pci probe process */
  14. static u8 sb_slot = 5;
  15. int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  16. {
  17. int irq = 0;
  18. if (slot == sb_slot) {
  19. switch (PCI_FUNC(dev->devfn)) {
  20. case 2:
  21. irq = 10;
  22. break;
  23. case 3:
  24. irq = 11;
  25. break;
  26. case 5:
  27. irq = 9;
  28. break;
  29. }
  30. } else {
  31. irq = LOONGSON_IRQ_BASE + 25 + pin;
  32. }
  33. return irq;
  34. }
  35. /* Do platform specific device initialization at pci_enable_device() time */
  36. int pcibios_plat_dev_init(struct pci_dev *dev)
  37. {
  38. return 0;
  39. }
  40. static void loongson2e_nec_fixup(struct pci_dev *pdev)
  41. {
  42. unsigned int val;
  43. /* Configures port 1, 2, 3, 4 to be validate*/
  44. pci_read_config_dword(pdev, 0xe0, &val);
  45. pci_write_config_dword(pdev, 0xe0, (val & ~7) | 0x4);
  46. /* System clock is 48-MHz Oscillator. */
  47. pci_write_config_dword(pdev, 0xe4, 1 << 5);
  48. }
  49. static void loongson2e_686b_func0_fixup(struct pci_dev *pdev)
  50. {
  51. unsigned char c;
  52. sb_slot = PCI_SLOT(pdev->devfn);
  53. printk(KERN_INFO "via686b fix: ISA bridge\n");
  54. /* Enable I/O Recovery time */
  55. pci_write_config_byte(pdev, 0x40, 0x08);
  56. /* Enable ISA refresh */
  57. pci_write_config_byte(pdev, 0x41, 0x01);
  58. /* disable ISA line buffer */
  59. pci_write_config_byte(pdev, 0x45, 0x00);
  60. /* Gate INTR, and flush line buffer */
  61. pci_write_config_byte(pdev, 0x46, 0xe0);
  62. /* Disable PCI Delay Transaction, Enable EISA ports 4D0/4D1. */
  63. /* pci_write_config_byte(pdev, 0x47, 0x20); */
  64. /*
  65. * enable PCI Delay Transaction, Enable EISA ports 4D0/4D1.
  66. * enable time-out timer
  67. */
  68. pci_write_config_byte(pdev, 0x47, 0xe6);
  69. /*
  70. * enable level trigger on pci irqs: 9,10,11,13
  71. * important! without this PCI interrupts won't work
  72. */
  73. outb(0x2e, 0x4d1);
  74. /* 512 K PCI Decode */
  75. pci_write_config_byte(pdev, 0x48, 0x01);
  76. /* Wait for PGNT before grant to ISA Master/DMA */
  77. pci_write_config_byte(pdev, 0x4a, 0x84);
  78. /*
  79. * Plug'n'Play
  80. *
  81. * Parallel DRQ 3, Floppy DRQ 2 (default)
  82. */
  83. pci_write_config_byte(pdev, 0x50, 0x0e);
  84. /*
  85. * IRQ Routing for Floppy and Parallel port
  86. *
  87. * IRQ 6 for floppy, IRQ 7 for parallel port
  88. */
  89. pci_write_config_byte(pdev, 0x51, 0x76);
  90. /* IRQ Routing for serial ports (take IRQ 3 and 4) */
  91. pci_write_config_byte(pdev, 0x52, 0x34);
  92. /* All IRQ's level triggered. */
  93. pci_write_config_byte(pdev, 0x54, 0x00);
  94. /* route PIRQA-D irq */
  95. pci_write_config_byte(pdev, 0x55, 0x90); /* bit 7-4, PIRQA */
  96. pci_write_config_byte(pdev, 0x56, 0xba); /* bit 7-4, PIRQC; */
  97. /* 3-0, PIRQB */
  98. pci_write_config_byte(pdev, 0x57, 0xd0); /* bit 7-4, PIRQD */
  99. /* enable function 5/6, audio/modem */
  100. pci_read_config_byte(pdev, 0x85, &c);
  101. c &= ~(0x3 << 2);
  102. pci_write_config_byte(pdev, 0x85, c);
  103. printk(KERN_INFO"via686b fix: ISA bridge done\n");
  104. }
  105. static void loongson2e_686b_func1_fixup(struct pci_dev *pdev)
  106. {
  107. printk(KERN_INFO"via686b fix: IDE\n");
  108. /* Modify IDE controller setup */
  109. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 48);
  110. pci_write_config_byte(pdev, PCI_COMMAND,
  111. PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
  112. PCI_COMMAND_MASTER);
  113. pci_write_config_byte(pdev, 0x40, 0x0b);
  114. /* legacy mode */
  115. pci_write_config_byte(pdev, 0x42, 0x09);
  116. #if 1/* play safe, otherwise we may see notebook's usb keyboard lockup */
  117. /* disable read prefetch/write post buffers */
  118. pci_write_config_byte(pdev, 0x41, 0x02);
  119. /* use 3/4 as fifo thresh hold */
  120. pci_write_config_byte(pdev, 0x43, 0x0a);
  121. pci_write_config_byte(pdev, 0x44, 0x00);
  122. pci_write_config_byte(pdev, 0x45, 0x00);
  123. #else
  124. pci_write_config_byte(pdev, 0x41, 0xc2);
  125. pci_write_config_byte(pdev, 0x43, 0x35);
  126. pci_write_config_byte(pdev, 0x44, 0x1c);
  127. pci_write_config_byte(pdev, 0x45, 0x10);
  128. #endif
  129. printk(KERN_INFO"via686b fix: IDE done\n");
  130. }
  131. static void loongson2e_686b_func2_fixup(struct pci_dev *pdev)
  132. {
  133. /* irq routing */
  134. pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, 10);
  135. }
  136. static void loongson2e_686b_func3_fixup(struct pci_dev *pdev)
  137. {
  138. /* irq routing */
  139. pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, 11);
  140. }
  141. static void loongson2e_686b_func5_fixup(struct pci_dev *pdev)
  142. {
  143. unsigned int val;
  144. unsigned char c;
  145. /* enable IO */
  146. pci_write_config_byte(pdev, PCI_COMMAND,
  147. PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
  148. PCI_COMMAND_MASTER);
  149. pci_read_config_dword(pdev, 0x4, &val);
  150. pci_write_config_dword(pdev, 0x4, val | 1);
  151. /* route ac97 IRQ */
  152. pci_write_config_byte(pdev, 0x3c, 9);
  153. pci_read_config_byte(pdev, 0x8, &c);
  154. /* link control: enable link & SGD PCM output */
  155. pci_write_config_byte(pdev, 0x41, 0xcc);
  156. /* disable game port, FM, midi, sb, enable write to reg2c-2f */
  157. pci_write_config_byte(pdev, 0x42, 0x20);
  158. /* we are using Avance logic codec */
  159. pci_write_config_word(pdev, 0x2c, 0x1005);
  160. pci_write_config_word(pdev, 0x2e, 0x4710);
  161. pci_read_config_dword(pdev, 0x2c, &val);
  162. pci_write_config_byte(pdev, 0x42, 0x0);
  163. }
  164. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686,
  165. loongson2e_686b_func0_fixup);
  166. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1,
  167. loongson2e_686b_func1_fixup);
  168. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_2,
  169. loongson2e_686b_func2_fixup);
  170. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3,
  171. loongson2e_686b_func3_fixup);
  172. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5,
  173. loongson2e_686b_func5_fixup);
  174. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB,
  175. loongson2e_nec_fixup);