2 * Copyright (C) 2004 ICT CAS
3 * Author: Li xiaoyu, ICT CAS
6 * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
7 * Author: Fuxin Zhang, zhangfx@lemote.com
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.
14 #include <linux/init.h>
15 #include <linux/pci.h>
19 /* South bridge slot number is set by the pci probe process */
20 static u8 sb_slot
= 5;
22 int __init
pcibios_map_irq(const struct pci_dev
*dev
, u8 slot
, u8 pin
)
26 if (slot
== sb_slot
) {
27 switch (PCI_FUNC(dev
->devfn
)) {
39 irq
= LOONGSON_IRQ_BASE
+ 25 + pin
;
45 /* Do platform specific device initialization at pci_enable_device() time */
46 int pcibios_plat_dev_init(struct pci_dev
*dev
)
51 static void __devinit
loongson2e_nec_fixup(struct pci_dev
*pdev
)
55 /* Configures port 1, 2, 3, 4 to be validate*/
56 pci_read_config_dword(pdev
, 0xe0, &val
);
57 pci_write_config_dword(pdev
, 0xe0, (val
& ~7) | 0x4);
59 /* System clock is 48-MHz Oscillator. */
60 pci_write_config_dword(pdev
, 0xe4, 1 << 5);
63 static void __devinit
loongson2e_686b_func0_fixup(struct pci_dev
*pdev
)
67 sb_slot
= PCI_SLOT(pdev
->devfn
);
69 printk(KERN_INFO
"via686b fix: ISA bridge\n");
71 /* Enable I/O Recovery time */
72 pci_write_config_byte(pdev
, 0x40, 0x08);
74 /* Enable ISA refresh */
75 pci_write_config_byte(pdev
, 0x41, 0x01);
77 /* disable ISA line buffer */
78 pci_write_config_byte(pdev
, 0x45, 0x00);
80 /* Gate INTR, and flush line buffer */
81 pci_write_config_byte(pdev
, 0x46, 0xe0);
83 /* Disable PCI Delay Transaction, Enable EISA ports 4D0/4D1. */
84 /* pci_write_config_byte(pdev, 0x47, 0x20); */
87 * enable PCI Delay Transaction, Enable EISA ports 4D0/4D1.
88 * enable time-out timer
90 pci_write_config_byte(pdev
, 0x47, 0xe6);
93 * enable level trigger on pci irqs: 9,10,11,13
94 * important! without this PCI interrupts won't work
98 /* 512 K PCI Decode */
99 pci_write_config_byte(pdev
, 0x48, 0x01);
101 /* Wait for PGNT before grant to ISA Master/DMA */
102 pci_write_config_byte(pdev
, 0x4a, 0x84);
107 * Parallel DRQ 3, Floppy DRQ 2 (default)
109 pci_write_config_byte(pdev
, 0x50, 0x0e);
112 * IRQ Routing for Floppy and Parallel port
114 * IRQ 6 for floppy, IRQ 7 for parallel port
116 pci_write_config_byte(pdev
, 0x51, 0x76);
118 /* IRQ Routing for serial ports (take IRQ 3 and 4) */
119 pci_write_config_byte(pdev
, 0x52, 0x34);
121 /* All IRQ's level triggered. */
122 pci_write_config_byte(pdev
, 0x54, 0x00);
124 /* route PIRQA-D irq */
125 pci_write_config_byte(pdev
, 0x55, 0x90); /* bit 7-4, PIRQA */
126 pci_write_config_byte(pdev
, 0x56, 0xba); /* bit 7-4, PIRQC; */
128 pci_write_config_byte(pdev
, 0x57, 0xd0); /* bit 7-4, PIRQD */
130 /* enable function 5/6, audio/modem */
131 pci_read_config_byte(pdev
, 0x85, &c
);
133 pci_write_config_byte(pdev
, 0x85, c
);
135 printk(KERN_INFO
"via686b fix: ISA bridge done\n");
138 static void __devinit
loongson2e_686b_func1_fixup(struct pci_dev
*pdev
)
140 printk(KERN_INFO
"via686b fix: IDE\n");
142 /* Modify IDE controller setup */
143 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 48);
144 pci_write_config_byte(pdev
, PCI_COMMAND
,
145 PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
|
147 pci_write_config_byte(pdev
, 0x40, 0x0b);
149 pci_write_config_byte(pdev
, 0x42, 0x09);
151 #if 1/* play safe, otherwise we may see notebook's usb keyboard lockup */
152 /* disable read prefetch/write post buffers */
153 pci_write_config_byte(pdev
, 0x41, 0x02);
155 /* use 3/4 as fifo thresh hold */
156 pci_write_config_byte(pdev
, 0x43, 0x0a);
157 pci_write_config_byte(pdev
, 0x44, 0x00);
159 pci_write_config_byte(pdev
, 0x45, 0x00);
161 pci_write_config_byte(pdev
, 0x41, 0xc2);
162 pci_write_config_byte(pdev
, 0x43, 0x35);
163 pci_write_config_byte(pdev
, 0x44, 0x1c);
165 pci_write_config_byte(pdev
, 0x45, 0x10);
168 printk(KERN_INFO
"via686b fix: IDE done\n");
171 static void __devinit
loongson2e_686b_func2_fixup(struct pci_dev
*pdev
)
174 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, 10);
177 static void __devinit
loongson2e_686b_func3_fixup(struct pci_dev
*pdev
)
180 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, 11);
183 static void __devinit
loongson2e_686b_func5_fixup(struct pci_dev
*pdev
)
189 pci_write_config_byte(pdev
, PCI_COMMAND
,
190 PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
|
192 pci_read_config_dword(pdev
, 0x4, &val
);
193 pci_write_config_dword(pdev
, 0x4, val
| 1);
196 pci_write_config_byte(pdev
, 0x3c, 9);
198 pci_read_config_byte(pdev
, 0x8, &c
);
200 /* link control: enable link & SGD PCM output */
201 pci_write_config_byte(pdev
, 0x41, 0xcc);
203 /* disable game port, FM, midi, sb, enable write to reg2c-2f */
204 pci_write_config_byte(pdev
, 0x42, 0x20);
206 /* we are using Avance logic codec */
207 pci_write_config_word(pdev
, 0x2c, 0x1005);
208 pci_write_config_word(pdev
, 0x2e, 0x4710);
209 pci_read_config_dword(pdev
, 0x2c, &val
);
211 pci_write_config_byte(pdev
, 0x42, 0x0);
214 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C686
,
215 loongson2e_686b_func0_fixup
);
216 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C586_1
,
217 loongson2e_686b_func1_fixup
);
218 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C586_2
,
219 loongson2e_686b_func2_fixup
);
220 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C586_3
,
221 loongson2e_686b_func3_fixup
);
222 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C686_5
,
223 loongson2e_686b_func5_fixup
);
224 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NEC
, PCI_DEVICE_ID_NEC_USB
,
225 loongson2e_nec_fixup
);