blob: 7a0eda782e35cf8c51d894c1b832dd9692f41c15 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/init.h>
2#include <linux/pci.h>
Deng-Cheng Zhu70002f72013-10-07 09:45:04 -07003#include <asm/mips-boards/piix4.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
5/* PCI interrupt pins */
6#define PCIA 1
7#define PCIB 2
8#define PCIC 3
9#define PCID 4
10
11/* This table is filled in by interrogating the PIIX4 chip */
Greg Kroah-Hartman28eb0e42012-12-21 14:04:39 -080012static char pci_irq[5] = {
Ralf Baechle2eaaac52012-10-11 11:14:12 +020013};
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15static char irq_tab[][5] __initdata = {
Ralf Baechle70342282013-01-22 12:59:30 +010016 /* INTA INTB INTC INTD */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 {0, 0, 0, 0, 0 }, /* 0: GT64120 PCI bridge */
18 {0, 0, 0, 0, 0 }, /* 1: Unused */
19 {0, 0, 0, 0, 0 }, /* 2: Unused */
20 {0, 0, 0, 0, 0 }, /* 3: Unused */
21 {0, 0, 0, 0, 0 }, /* 4: Unused */
22 {0, 0, 0, 0, 0 }, /* 5: Unused */
23 {0, 0, 0, 0, 0 }, /* 6: Unused */
24 {0, 0, 0, 0, 0 }, /* 7: Unused */
25 {0, 0, 0, 0, 0 }, /* 8: Unused */
26 {0, 0, 0, 0, 0 }, /* 9: Unused */
Ralf Baechle70342282013-01-22 12:59:30 +010027 {0, 0, 0, 0, PCID }, /* 10: PIIX4 USB */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 {0, PCIB, 0, 0, 0 }, /* 11: AMD 79C973 Ethernet */
29 {0, PCIC, 0, 0, 0 }, /* 12: Crystal 4281 Sound */
30 {0, 0, 0, 0, 0 }, /* 13: Unused */
31 {0, 0, 0, 0, 0 }, /* 14: Unused */
32 {0, 0, 0, 0, 0 }, /* 15: Unused */
33 {0, 0, 0, 0, 0 }, /* 16: Unused */
34 {0, 0, 0, 0, 0 }, /* 17: Bonito/SOC-it PCI Bridge*/
Ralf Baechle70342282013-01-22 12:59:30 +010035 {0, PCIA, PCIB, PCIC, PCID }, /* 18: PCI Slot 1 */
36 {0, PCIB, PCIC, PCID, PCIA }, /* 19: PCI Slot 2 */
37 {0, PCIC, PCID, PCIA, PCIB }, /* 20: PCI Slot 3 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 {0, PCID, PCIA, PCIB, PCIC } /* 21: PCI Slot 4 */
39};
40
Ralf Baechle19df0d12007-07-10 17:33:00 +010041int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
43 int virq;
44 virq = irq_tab[slot][pin];
45 return pci_irq[virq];
46}
47
48/* Do platform specific device initialization at pci_enable_device() time */
49int pcibios_plat_dev_init(struct pci_dev *dev)
50{
51 return 0;
52}
53
Greg Kroah-Hartman28eb0e42012-12-21 14:04:39 -080054static void malta_piix_func0_fixup(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 unsigned char reg_val;
Paul Burtonae0d7cb2013-12-02 16:48:37 +000057 u32 reg_val32;
Deng-Cheng Zhu70002f72013-10-07 09:45:04 -070058 /* PIIX PIRQC[A:D] irq mappings */
59 static int piixirqmap[PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_MAX] = {
Ralf Baechle70342282013-01-22 12:59:30 +010060 0, 0, 0, 3,
61 4, 5, 6, 7,
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 0, 9, 10, 11,
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070063 12, 0, 14, 15
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 };
65 int i;
66
67 /* Interrogate PIIX4 to get PCI IRQ mapping */
68 for (i = 0; i <= 3; i++) {
Deng-Cheng Zhu70002f72013-10-07 09:45:04 -070069 pci_read_config_byte(pdev, PIIX4_FUNC0_PIRQRC+i, &reg_val);
70 if (reg_val & PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_DISABLE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 pci_irq[PCIA+i] = 0; /* Disabled */
72 else
Deng-Cheng Zhu70002f72013-10-07 09:45:04 -070073 pci_irq[PCIA+i] = piixirqmap[reg_val &
74 PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_MASK];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
76
77 /* Done by YAMON 2.00 onwards */
78 if (PCI_SLOT(pdev->devfn) == 10) {
79 /*
80 * Set top of main memory accessible by ISA or DMA
81 * devices to 16 Mb.
82 */
Deng-Cheng Zhu70002f72013-10-07 09:45:04 -070083 pci_read_config_byte(pdev, PIIX4_FUNC0_TOM, &reg_val);
84 pci_write_config_byte(pdev, PIIX4_FUNC0_TOM, reg_val |
85 PIIX4_FUNC0_TOM_TOP_OF_MEMORY_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }
Paul Burtonae0d7cb2013-12-02 16:48:37 +000087
88 /* Mux SERIRQ to its pin */
89 pci_read_config_dword(pdev, PIIX4_FUNC0_GENCFG, &reg_val32);
90 pci_write_config_dword(pdev, PIIX4_FUNC0_GENCFG,
91 reg_val32 | PIIX4_FUNC0_GENCFG_SERIRQ);
92
93 /* Enable SERIRQ */
94 pci_read_config_byte(pdev, PIIX4_FUNC0_SERIRQC, &reg_val);
95 reg_val |= PIIX4_FUNC0_SERIRQC_EN | PIIX4_FUNC0_SERIRQC_CONT;
96 pci_write_config_byte(pdev, PIIX4_FUNC0_SERIRQC, reg_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
99DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0,
100 malta_piix_func0_fixup);
101
Greg Kroah-Hartman28eb0e42012-12-21 14:04:39 -0800102static void malta_piix_func1_fixup(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 unsigned char reg_val;
105
106 /* Done by YAMON 2.02 onwards */
107 if (PCI_SLOT(pdev->devfn) == 10) {
108 /*
109 * IDE Decode enable.
110 */
Deng-Cheng Zhu70002f72013-10-07 09:45:04 -0700111 pci_read_config_byte(pdev, PIIX4_FUNC1_IDETIM_PRIMARY_HI,
112 &reg_val);
113 pci_write_config_byte(pdev, PIIX4_FUNC1_IDETIM_PRIMARY_HI,
114 reg_val|PIIX4_FUNC1_IDETIM_PRIMARY_HI_IDE_DECODE_EN);
115 pci_read_config_byte(pdev, PIIX4_FUNC1_IDETIM_SECONDARY_HI,
116 &reg_val);
117 pci_write_config_byte(pdev, PIIX4_FUNC1_IDETIM_SECONDARY_HI,
118 reg_val|PIIX4_FUNC1_IDETIM_SECONDARY_HI_IDE_DECODE_EN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
120}
121
122DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB,
123 malta_piix_func1_fixup);
Ralf Baechle497e5ff2012-06-06 11:14:08 +0100124
125/* Enable PCI 2.1 compatibility in PIIX4 */
Greg Kroah-Hartman28eb0e42012-12-21 14:04:39 -0800126static void quirk_dlcsetup(struct pci_dev *dev)
Ralf Baechle497e5ff2012-06-06 11:14:08 +0100127{
128 u8 odlc, ndlc;
129
Deng-Cheng Zhu70002f72013-10-07 09:45:04 -0700130 (void) pci_read_config_byte(dev, PIIX4_FUNC0_DLC, &odlc);
Ralf Baechle497e5ff2012-06-06 11:14:08 +0100131 /* Enable passive releases and delayed transaction */
Deng-Cheng Zhu70002f72013-10-07 09:45:04 -0700132 ndlc = odlc | PIIX4_FUNC0_DLC_USBPR_EN |
133 PIIX4_FUNC0_DLC_PASSIVE_RELEASE_EN |
134 PIIX4_FUNC0_DLC_DELAYED_TRANSACTION_EN;
135 (void) pci_write_config_byte(dev, PIIX4_FUNC0_DLC, ndlc);
Ralf Baechle497e5ff2012-06-06 11:14:08 +0100136}
137
138DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0,
139 quirk_dlcsetup);