fixup-fuloong2e.c 5.9 KB

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