1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2004 ICT CAS
4 * Author: Li xiaoyu, ICT CAS
7 * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
8 * Author: Fuxin Zhang, zhangfx@lemote.com
10 #include <linux/init.h>
11 #include <linux/pci.h>
15 /* South bridge slot number is set by the pci probe process */
16 static u8 sb_slot
= 5;
18 int pcibios_map_irq(const struct pci_dev
*dev
, u8 slot
, u8 pin
)
22 if (slot
== sb_slot
) {
23 switch (PCI_FUNC(dev
->devfn
)) {
35 irq
= LOONGSON_IRQ_BASE
+ 25 + pin
;
41 /* Do platform specific device initialization at pci_enable_device() time */
42 int pcibios_plat_dev_init(struct pci_dev
*dev
)
47 static void loongson2e_nec_fixup(struct pci_dev
*pdev
)
51 /* Configures port 1, 2, 3, 4 to be validate*/
52 pci_read_config_dword(pdev
, 0xe0, &val
);
53 pci_write_config_dword(pdev
, 0xe0, (val
& ~7) | 0x4);
55 /* System clock is 48-MHz Oscillator. */
56 pci_write_config_dword(pdev
, 0xe4, 1 << 5);
59 static void loongson2e_686b_func0_fixup(struct pci_dev
*pdev
)
63 sb_slot
= PCI_SLOT(pdev
->devfn
);
65 printk(KERN_INFO
"via686b fix: ISA bridge\n");
67 /* Enable I/O Recovery time */
68 pci_write_config_byte(pdev
, 0x40, 0x08);
70 /* Enable ISA refresh */
71 pci_write_config_byte(pdev
, 0x41, 0x01);
73 /* disable ISA line buffer */
74 pci_write_config_byte(pdev
, 0x45, 0x00);
76 /* Gate INTR, and flush line buffer */
77 pci_write_config_byte(pdev
, 0x46, 0xe0);
79 /* Disable PCI Delay Transaction, Enable EISA ports 4D0/4D1. */
80 /* pci_write_config_byte(pdev, 0x47, 0x20); */
83 * enable PCI Delay Transaction, Enable EISA ports 4D0/4D1.
84 * enable time-out timer
86 pci_write_config_byte(pdev
, 0x47, 0xe6);
89 * enable level trigger on pci irqs: 9,10,11,13
90 * important! without this PCI interrupts won't work
94 /* 512 K PCI Decode */
95 pci_write_config_byte(pdev
, 0x48, 0x01);
97 /* Wait for PGNT before grant to ISA Master/DMA */
98 pci_write_config_byte(pdev
, 0x4a, 0x84);
103 * Parallel DRQ 3, Floppy DRQ 2 (default)
105 pci_write_config_byte(pdev
, 0x50, 0x0e);
108 * IRQ Routing for Floppy and Parallel port
110 * IRQ 6 for floppy, IRQ 7 for parallel port
112 pci_write_config_byte(pdev
, 0x51, 0x76);
114 /* IRQ Routing for serial ports (take IRQ 3 and 4) */
115 pci_write_config_byte(pdev
, 0x52, 0x34);
117 /* All IRQ's level triggered. */
118 pci_write_config_byte(pdev
, 0x54, 0x00);
120 /* route PIRQA-D irq */
121 pci_write_config_byte(pdev
, 0x55, 0x90); /* bit 7-4, PIRQA */
122 pci_write_config_byte(pdev
, 0x56, 0xba); /* bit 7-4, PIRQC; */
124 pci_write_config_byte(pdev
, 0x57, 0xd0); /* bit 7-4, PIRQD */
126 /* enable function 5/6, audio/modem */
127 pci_read_config_byte(pdev
, 0x85, &c
);
129 pci_write_config_byte(pdev
, 0x85, c
);
131 printk(KERN_INFO
"via686b fix: ISA bridge done\n");
134 static void loongson2e_686b_func1_fixup(struct pci_dev
*pdev
)
136 printk(KERN_INFO
"via686b fix: IDE\n");
138 /* Modify IDE controller setup */
139 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 48);
140 pci_write_config_byte(pdev
, PCI_COMMAND
,
141 PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
|
143 pci_write_config_byte(pdev
, 0x40, 0x0b);
145 pci_write_config_byte(pdev
, 0x42, 0x09);
147 #if 1/* play safe, otherwise we may see notebook's usb keyboard lockup */
148 /* disable read prefetch/write post buffers */
149 pci_write_config_byte(pdev
, 0x41, 0x02);
151 /* use 3/4 as fifo thresh hold */
152 pci_write_config_byte(pdev
, 0x43, 0x0a);
153 pci_write_config_byte(pdev
, 0x44, 0x00);
155 pci_write_config_byte(pdev
, 0x45, 0x00);
157 pci_write_config_byte(pdev
, 0x41, 0xc2);
158 pci_write_config_byte(pdev
, 0x43, 0x35);
159 pci_write_config_byte(pdev
, 0x44, 0x1c);
161 pci_write_config_byte(pdev
, 0x45, 0x10);
164 printk(KERN_INFO
"via686b fix: IDE done\n");
167 static void loongson2e_686b_func2_fixup(struct pci_dev
*pdev
)
170 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, 10);
173 static void loongson2e_686b_func3_fixup(struct pci_dev
*pdev
)
176 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, 11);
179 static void loongson2e_686b_func5_fixup(struct pci_dev
*pdev
)
185 pci_write_config_byte(pdev
, PCI_COMMAND
,
186 PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
|
188 pci_read_config_dword(pdev
, 0x4, &val
);
189 pci_write_config_dword(pdev
, 0x4, val
| 1);
192 pci_write_config_byte(pdev
, 0x3c, 9);
194 pci_read_config_byte(pdev
, 0x8, &c
);
196 /* link control: enable link & SGD PCM output */
197 pci_write_config_byte(pdev
, 0x41, 0xcc);
199 /* disable game port, FM, midi, sb, enable write to reg2c-2f */
200 pci_write_config_byte(pdev
, 0x42, 0x20);
202 /* we are using Avance logic codec */
203 pci_write_config_word(pdev
, 0x2c, 0x1005);
204 pci_write_config_word(pdev
, 0x2e, 0x4710);
205 pci_read_config_dword(pdev
, 0x2c, &val
);
207 pci_write_config_byte(pdev
, 0x42, 0x0);
210 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C686
,
211 loongson2e_686b_func0_fixup
);
212 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C586_1
,
213 loongson2e_686b_func1_fixup
);
214 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C586_2
,
215 loongson2e_686b_func2_fixup
);
216 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C586_3
,
217 loongson2e_686b_func3_fixup
);
218 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA
, PCI_DEVICE_ID_VIA_82C686_5
,
219 loongson2e_686b_func5_fixup
);
220 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NEC
, PCI_DEVICE_ID_NEC_USB
,
221 loongson2e_nec_fixup
);