xref: /linux/arch/mips/pci/fixup-fuloong2e.c (revision 2874c5fd)
1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
28e497117SWu Zhangjin /*
38e497117SWu Zhangjin  * Copyright (C) 2004 ICT CAS
48e497117SWu Zhangjin  * Author: Li xiaoyu, ICT CAS
58e497117SWu Zhangjin  *   lixy@ict.ac.cn
68e497117SWu Zhangjin  *
78e497117SWu Zhangjin  * Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology
88e497117SWu Zhangjin  * Author: Fuxin Zhang, zhangfx@lemote.com
98e497117SWu Zhangjin  */
108e497117SWu Zhangjin #include <linux/init.h>
118e497117SWu Zhangjin #include <linux/pci.h>
12e2fee572SWu Zhangjin 
13e2fee572SWu Zhangjin #include <loongson.h>
148e497117SWu Zhangjin 
158e497117SWu Zhangjin /* South bridge slot number is set by the pci probe process */
168e497117SWu Zhangjin static u8 sb_slot = 5;
178e497117SWu Zhangjin 
pcibios_map_irq(const struct pci_dev * dev,u8 slot,u8 pin)188eba3651SManuel Lauss int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
198e497117SWu Zhangjin {
208e497117SWu Zhangjin 	int irq = 0;
218e497117SWu Zhangjin 
228e497117SWu Zhangjin 	if (slot == sb_slot) {
238e497117SWu Zhangjin 		switch (PCI_FUNC(dev->devfn)) {
248e497117SWu Zhangjin 		case 2:
258e497117SWu Zhangjin 			irq = 10;
268e497117SWu Zhangjin 			break;
278e497117SWu Zhangjin 		case 3:
288e497117SWu Zhangjin 			irq = 11;
298e497117SWu Zhangjin 			break;
308e497117SWu Zhangjin 		case 5:
318e497117SWu Zhangjin 			irq = 9;
328e497117SWu Zhangjin 			break;
338e497117SWu Zhangjin 		}
348e497117SWu Zhangjin 	} else {
35e2fee572SWu Zhangjin 		irq = LOONGSON_IRQ_BASE + 25 + pin;
368e497117SWu Zhangjin 	}
378e497117SWu Zhangjin 	return irq;
388e497117SWu Zhangjin 
398e497117SWu Zhangjin }
408e497117SWu Zhangjin 
418e497117SWu Zhangjin /* Do platform specific device initialization at pci_enable_device() time */
pcibios_plat_dev_init(struct pci_dev * dev)428e497117SWu Zhangjin int pcibios_plat_dev_init(struct pci_dev *dev)
438e497117SWu Zhangjin {
448e497117SWu Zhangjin 	return 0;
458e497117SWu Zhangjin }
468e497117SWu Zhangjin 
loongson2e_nec_fixup(struct pci_dev * pdev)4728eb0e46SGreg Kroah-Hartman static void loongson2e_nec_fixup(struct pci_dev *pdev)
488e497117SWu Zhangjin {
498e497117SWu Zhangjin 	unsigned int val;
508e497117SWu Zhangjin 
51b42e1796SThomas Weber 	/* Configures port 1, 2, 3, 4 to be validate*/
528e497117SWu Zhangjin 	pci_read_config_dword(pdev, 0xe0, &val);
538e497117SWu Zhangjin 	pci_write_config_dword(pdev, 0xe0, (val & ~7) | 0x4);
548e497117SWu Zhangjin 
558e497117SWu Zhangjin 	/* System clock is 48-MHz Oscillator. */
568e497117SWu Zhangjin 	pci_write_config_dword(pdev, 0xe4, 1 << 5);
578e497117SWu Zhangjin }
588e497117SWu Zhangjin 
loongson2e_686b_func0_fixup(struct pci_dev * pdev)5928eb0e46SGreg Kroah-Hartman static void loongson2e_686b_func0_fixup(struct pci_dev *pdev)
608e497117SWu Zhangjin {
618e497117SWu Zhangjin 	unsigned char c;
628e497117SWu Zhangjin 
638e497117SWu Zhangjin 	sb_slot = PCI_SLOT(pdev->devfn);
648e497117SWu Zhangjin 
658e497117SWu Zhangjin 	printk(KERN_INFO "via686b fix: ISA bridge\n");
668e497117SWu Zhangjin 
678e497117SWu Zhangjin 	/*  Enable I/O Recovery time */
688e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x40, 0x08);
698e497117SWu Zhangjin 
708e497117SWu Zhangjin 	/*  Enable ISA refresh */
718e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x41, 0x01);
728e497117SWu Zhangjin 
738e497117SWu Zhangjin 	/*  disable ISA line buffer */
748e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x45, 0x00);
758e497117SWu Zhangjin 
768e497117SWu Zhangjin 	/*  Gate INTR, and flush line buffer */
778e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x46, 0xe0);
788e497117SWu Zhangjin 
798e497117SWu Zhangjin 	/*  Disable PCI Delay Transaction, Enable EISA ports 4D0/4D1. */
808e497117SWu Zhangjin 	/* pci_write_config_byte(pdev, 0x47, 0x20); */
818e497117SWu Zhangjin 
828e497117SWu Zhangjin 	/*
838e497117SWu Zhangjin 	 *  enable PCI Delay Transaction, Enable EISA ports 4D0/4D1.
848e497117SWu Zhangjin 	 *  enable time-out timer
858e497117SWu Zhangjin 	 */
868e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x47, 0xe6);
878e497117SWu Zhangjin 
888e497117SWu Zhangjin 	/*
898e497117SWu Zhangjin 	 * enable level trigger on pci irqs: 9,10,11,13
908e497117SWu Zhangjin 	 * important! without this PCI interrupts won't work
918e497117SWu Zhangjin 	 */
928e497117SWu Zhangjin 	outb(0x2e, 0x4d1);
938e497117SWu Zhangjin 
948e497117SWu Zhangjin 	/*  512 K PCI Decode */
958e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x48, 0x01);
968e497117SWu Zhangjin 
978e497117SWu Zhangjin 	/*  Wait for PGNT before grant to ISA Master/DMA */
988e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x4a, 0x84);
998e497117SWu Zhangjin 
1008e497117SWu Zhangjin 	/*
1018e497117SWu Zhangjin 	 * Plug'n'Play
1028e497117SWu Zhangjin 	 *
1038e497117SWu Zhangjin 	 *  Parallel DRQ 3, Floppy DRQ 2 (default)
1048e497117SWu Zhangjin 	 */
1058e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x50, 0x0e);
1068e497117SWu Zhangjin 
1078e497117SWu Zhangjin 	/*
1088e497117SWu Zhangjin 	 * IRQ Routing for Floppy and Parallel port
1098e497117SWu Zhangjin 	 *
1108e497117SWu Zhangjin 	 *  IRQ 6 for floppy, IRQ 7 for parallel port
1118e497117SWu Zhangjin 	 */
1128e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x51, 0x76);
1138e497117SWu Zhangjin 
1148e497117SWu Zhangjin 	/* IRQ Routing for serial ports (take IRQ 3 and 4) */
1158e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x52, 0x34);
1168e497117SWu Zhangjin 
1178e497117SWu Zhangjin 	/*  All IRQ's level triggered. */
1188e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x54, 0x00);
1198e497117SWu Zhangjin 
1208e497117SWu Zhangjin 	/* route PIRQA-D irq */
1218e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x55, 0x90);	/* bit 7-4, PIRQA */
1228e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x56, 0xba);	/* bit 7-4, PIRQC; */
1238e497117SWu Zhangjin 							/* 3-0, PIRQB */
1248e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x57, 0xd0);	/* bit 7-4, PIRQD */
1258e497117SWu Zhangjin 
1268e497117SWu Zhangjin 	/* enable function 5/6, audio/modem */
1278e497117SWu Zhangjin 	pci_read_config_byte(pdev, 0x85, &c);
1288e497117SWu Zhangjin 	c &= ~(0x3 << 2);
1298e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x85, c);
1308e497117SWu Zhangjin 
1318e497117SWu Zhangjin 	printk(KERN_INFO"via686b fix: ISA bridge done\n");
1328e497117SWu Zhangjin }
1338e497117SWu Zhangjin 
loongson2e_686b_func1_fixup(struct pci_dev * pdev)13428eb0e46SGreg Kroah-Hartman static void loongson2e_686b_func1_fixup(struct pci_dev *pdev)
1358e497117SWu Zhangjin {
1368e497117SWu Zhangjin 	printk(KERN_INFO"via686b fix: IDE\n");
1378e497117SWu Zhangjin 
1388e497117SWu Zhangjin 	/* Modify IDE controller setup */
1398e497117SWu Zhangjin 	pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 48);
1408e497117SWu Zhangjin 	pci_write_config_byte(pdev, PCI_COMMAND,
1418e497117SWu Zhangjin 			      PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
1428e497117SWu Zhangjin 			      PCI_COMMAND_MASTER);
1438e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x40, 0x0b);
1448e497117SWu Zhangjin 	/* legacy mode */
1458e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x42, 0x09);
1468e497117SWu Zhangjin 
1478e497117SWu Zhangjin #if 1/* play safe, otherwise we may see notebook's usb keyboard lockup */
1488e497117SWu Zhangjin 	/* disable read prefetch/write post buffers */
1498e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x41, 0x02);
1508e497117SWu Zhangjin 
1518e497117SWu Zhangjin 	/* use 3/4 as fifo thresh hold	*/
1528e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x43, 0x0a);
1538e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x44, 0x00);
1548e497117SWu Zhangjin 
1558e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x45, 0x00);
1568e497117SWu Zhangjin #else
1578e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x41, 0xc2);
1588e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x43, 0x35);
1598e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x44, 0x1c);
1608e497117SWu Zhangjin 
1618e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x45, 0x10);
1628e497117SWu Zhangjin #endif
1638e497117SWu Zhangjin 
1648e497117SWu Zhangjin 	printk(KERN_INFO"via686b fix: IDE done\n");
1658e497117SWu Zhangjin }
1668e497117SWu Zhangjin 
loongson2e_686b_func2_fixup(struct pci_dev * pdev)16728eb0e46SGreg Kroah-Hartman static void loongson2e_686b_func2_fixup(struct pci_dev *pdev)
1688e497117SWu Zhangjin {
1698e497117SWu Zhangjin 	/* irq routing */
1708e497117SWu Zhangjin 	pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, 10);
1718e497117SWu Zhangjin }
1728e497117SWu Zhangjin 
loongson2e_686b_func3_fixup(struct pci_dev * pdev)17328eb0e46SGreg Kroah-Hartman static void loongson2e_686b_func3_fixup(struct pci_dev *pdev)
1748e497117SWu Zhangjin {
1758e497117SWu Zhangjin 	/* irq routing */
1768e497117SWu Zhangjin 	pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, 11);
1778e497117SWu Zhangjin }
1788e497117SWu Zhangjin 
loongson2e_686b_func5_fixup(struct pci_dev * pdev)17928eb0e46SGreg Kroah-Hartman static void loongson2e_686b_func5_fixup(struct pci_dev *pdev)
1808e497117SWu Zhangjin {
1818e497117SWu Zhangjin 	unsigned int val;
1828e497117SWu Zhangjin 	unsigned char c;
1838e497117SWu Zhangjin 
1848e497117SWu Zhangjin 	/* enable IO */
1858e497117SWu Zhangjin 	pci_write_config_byte(pdev, PCI_COMMAND,
1868e497117SWu Zhangjin 			      PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
1878e497117SWu Zhangjin 			      PCI_COMMAND_MASTER);
1888e497117SWu Zhangjin 	pci_read_config_dword(pdev, 0x4, &val);
1898e497117SWu Zhangjin 	pci_write_config_dword(pdev, 0x4, val | 1);
1908e497117SWu Zhangjin 
1918e497117SWu Zhangjin 	/* route ac97 IRQ */
1928e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x3c, 9);
1938e497117SWu Zhangjin 
1948e497117SWu Zhangjin 	pci_read_config_byte(pdev, 0x8, &c);
1958e497117SWu Zhangjin 
1968e497117SWu Zhangjin 	/* link control: enable link & SGD PCM output */
1978e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x41, 0xcc);
1988e497117SWu Zhangjin 
1998e497117SWu Zhangjin 	/* disable game port, FM, midi, sb, enable write to reg2c-2f */
2008e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x42, 0x20);
2018e497117SWu Zhangjin 
2028e497117SWu Zhangjin 	/* we are using Avance logic codec */
2038e497117SWu Zhangjin 	pci_write_config_word(pdev, 0x2c, 0x1005);
2048e497117SWu Zhangjin 	pci_write_config_word(pdev, 0x2e, 0x4710);
2058e497117SWu Zhangjin 	pci_read_config_dword(pdev, 0x2c, &val);
2068e497117SWu Zhangjin 
2078e497117SWu Zhangjin 	pci_write_config_byte(pdev, 0x42, 0x0);
2088e497117SWu Zhangjin }
2098e497117SWu Zhangjin 
2108e497117SWu Zhangjin DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686,
2118e497117SWu Zhangjin 			 loongson2e_686b_func0_fixup);
2128e497117SWu Zhangjin DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1,
2138e497117SWu Zhangjin 			 loongson2e_686b_func1_fixup);
2148e497117SWu Zhangjin DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_2,
2158e497117SWu Zhangjin 			 loongson2e_686b_func2_fixup);
2168e497117SWu Zhangjin DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3,
2178e497117SWu Zhangjin 			 loongson2e_686b_func3_fixup);
2188e497117SWu Zhangjin DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5,
2198e497117SWu Zhangjin 			 loongson2e_686b_func5_fixup);
2208e497117SWu Zhangjin DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB,
2218e497117SWu Zhangjin 			 loongson2e_nec_fixup);
222