fixup-lm2e.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * fixup-lm2e.c
  3. *
  4. * Copyright (C) 2004 ICT CAS
  5. * Author: Li xiaoyu, ICT CAS
  6. * lixy@ict.ac.cn
  7. *
  8. * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
  9. * Author: Fuxin Zhang, zhangfx@lemote.com
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  19. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  22. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * You should have received a copy of the GNU General Public License along
  28. * with this program; if not, write to the Free Software Foundation, Inc.,
  29. * 675 Mass Ave, Cambridge, MA 02139, USA.
  30. *
  31. */
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <asm/mips-boards/bonito64.h>
  35. /* South bridge slot number is set by the pci probe process */
  36. static u8 sb_slot = 5;
  37. int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  38. {
  39. int irq = 0;
  40. if (slot == sb_slot) {
  41. switch (PCI_FUNC(dev->devfn)) {
  42. case 2:
  43. irq = 10;
  44. break;
  45. case 3:
  46. irq = 11;
  47. break;
  48. case 5:
  49. irq = 9;
  50. break;
  51. }
  52. } else {
  53. irq = BONITO_IRQ_BASE + 25 + pin;
  54. }
  55. return irq;
  56. }
  57. /* Do platform specific device initialization at pci_enable_device() time */
  58. int pcibios_plat_dev_init(struct pci_dev *dev)
  59. {
  60. return 0;
  61. }
  62. static void __init loongson2e_nec_fixup(struct pci_dev *pdev)
  63. {
  64. unsigned int val;
  65. /* Configues port 1, 2, 3, 4 to be validate*/
  66. pci_read_config_dword(pdev, 0xe0, &val);
  67. pci_write_config_dword(pdev, 0xe0, (val & ~7) | 0x4);
  68. /* System clock is 48-MHz Oscillator. */
  69. pci_write_config_dword(pdev, 0xe4, 1 << 5);
  70. }
  71. static void __init loongson2e_686b_func0_fixup(struct pci_dev *pdev)
  72. {
  73. unsigned char c;
  74. sb_slot = PCI_SLOT(pdev->devfn);
  75. printk(KERN_INFO "via686b fix: ISA bridge\n");
  76. /* Enable I/O Recovery time */
  77. pci_write_config_byte(pdev, 0x40, 0x08);
  78. /* Enable ISA refresh */
  79. pci_write_config_byte(pdev, 0x41, 0x01);
  80. /* disable ISA line buffer */
  81. pci_write_config_byte(pdev, 0x45, 0x00);
  82. /* Gate INTR, and flush line buffer */
  83. pci_write_config_byte(pdev, 0x46, 0xe0);
  84. /* Disable PCI Delay Transaction, Enable EISA ports 4D0/4D1. */
  85. /* pci_write_config_byte(pdev, 0x47, 0x20); */
  86. /*
  87. * enable PCI Delay Transaction, Enable EISA ports 4D0/4D1.
  88. * enable time-out timer
  89. */
  90. pci_write_config_byte(pdev, 0x47, 0xe6);
  91. /*
  92. * enable level trigger on pci irqs: 9,10,11,13
  93. * important! without this PCI interrupts won't work
  94. */
  95. outb(0x2e, 0x4d1);
  96. /* 512 K PCI Decode */
  97. pci_write_config_byte(pdev, 0x48, 0x01);
  98. /* Wait for PGNT before grant to ISA Master/DMA */
  99. pci_write_config_byte(pdev, 0x4a, 0x84);
  100. /*
  101. * Plug'n'Play
  102. *
  103. * Parallel DRQ 3, Floppy DRQ 2 (default)
  104. */
  105. pci_write_config_byte(pdev, 0x50, 0x0e);
  106. /*
  107. * IRQ Routing for Floppy and Parallel port
  108. *
  109. * IRQ 6 for floppy, IRQ 7 for parallel port
  110. */
  111. pci_write_config_byte(pdev, 0x51, 0x76);
  112. /* IRQ Routing for serial ports (take IRQ 3 and 4) */
  113. pci_write_config_byte(pdev, 0x52, 0x34);
  114. /* All IRQ's level triggered. */
  115. pci_write_config_byte(pdev, 0x54, 0x00);
  116. /* route PIRQA-D irq */
  117. pci_write_config_byte(pdev, 0x55, 0x90); /* bit 7-4, PIRQA */
  118. pci_write_config_byte(pdev, 0x56, 0xba); /* bit 7-4, PIRQC; */
  119. /* 3-0, PIRQB */
  120. pci_write_config_byte(pdev, 0x57, 0xd0); /* bit 7-4, PIRQD */
  121. /* enable function 5/6, audio/modem */
  122. pci_read_config_byte(pdev, 0x85, &c);
  123. c &= ~(0x3 << 2);
  124. pci_write_config_byte(pdev, 0x85, c);
  125. printk(KERN_INFO"via686b fix: ISA bridge done\n");
  126. }
  127. static void __init loongson2e_686b_func1_fixup(struct pci_dev *pdev)
  128. {
  129. printk(KERN_INFO"via686b fix: IDE\n");
  130. /* Modify IDE controller setup */
  131. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 48);
  132. pci_write_config_byte(pdev, PCI_COMMAND,
  133. PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
  134. PCI_COMMAND_MASTER);
  135. pci_write_config_byte(pdev, 0x40, 0x0b);
  136. /* legacy mode */
  137. pci_write_config_byte(pdev, 0x42, 0x09);
  138. #if 1/* play safe, otherwise we may see notebook's usb keyboard lockup */
  139. /* disable read prefetch/write post buffers */
  140. pci_write_config_byte(pdev, 0x41, 0x02);
  141. /* use 3/4 as fifo thresh hold */
  142. pci_write_config_byte(pdev, 0x43, 0x0a);
  143. pci_write_config_byte(pdev, 0x44, 0x00);
  144. pci_write_config_byte(pdev, 0x45, 0x00);
  145. #else
  146. pci_write_config_byte(pdev, 0x41, 0xc2);
  147. pci_write_config_byte(pdev, 0x43, 0x35);
  148. pci_write_config_byte(pdev, 0x44, 0x1c);
  149. pci_write_config_byte(pdev, 0x45, 0x10);
  150. #endif
  151. printk(KERN_INFO"via686b fix: IDE done\n");
  152. }
  153. static void __init loongson2e_686b_func2_fixup(struct pci_dev *pdev)
  154. {
  155. /* irq routing */
  156. pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, 10);
  157. }
  158. static void __init loongson2e_686b_func3_fixup(struct pci_dev *pdev)
  159. {
  160. /* irq routing */
  161. pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, 11);
  162. }
  163. static void __init loongson2e_686b_func5_fixup(struct pci_dev *pdev)
  164. {
  165. unsigned int val;
  166. unsigned char c;
  167. /* enable IO */
  168. pci_write_config_byte(pdev, PCI_COMMAND,
  169. PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
  170. PCI_COMMAND_MASTER);
  171. pci_read_config_dword(pdev, 0x4, &val);
  172. pci_write_config_dword(pdev, 0x4, val | 1);
  173. /* route ac97 IRQ */
  174. pci_write_config_byte(pdev, 0x3c, 9);
  175. pci_read_config_byte(pdev, 0x8, &c);
  176. /* link control: enable link & SGD PCM output */
  177. pci_write_config_byte(pdev, 0x41, 0xcc);
  178. /* disable game port, FM, midi, sb, enable write to reg2c-2f */
  179. pci_write_config_byte(pdev, 0x42, 0x20);
  180. /* we are using Avance logic codec */
  181. pci_write_config_word(pdev, 0x2c, 0x1005);
  182. pci_write_config_word(pdev, 0x2e, 0x4710);
  183. pci_read_config_dword(pdev, 0x2c, &val);
  184. pci_write_config_byte(pdev, 0x42, 0x0);
  185. }
  186. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686,
  187. loongson2e_686b_func0_fixup);
  188. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1,
  189. loongson2e_686b_func1_fixup);
  190. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_2,
  191. loongson2e_686b_func2_fixup);
  192. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3,
  193. loongson2e_686b_func3_fixup);
  194. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5,
  195. loongson2e_686b_func5_fixup);
  196. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB,
  197. loongson2e_nec_fixup);