1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds #include <linux/init.h>
31da177e4SLinus Torvalds #include <linux/pci.h>
470002f76SDeng-Cheng Zhu #include <asm/mips-boards/piix4.h>
51da177e4SLinus Torvalds
61da177e4SLinus Torvalds /* PCI interrupt pins */
71da177e4SLinus Torvalds #define PCIA 1
81da177e4SLinus Torvalds #define PCIB 2
91da177e4SLinus Torvalds #define PCIC 3
101da177e4SLinus Torvalds #define PCID 4
111da177e4SLinus Torvalds
121da177e4SLinus Torvalds /* This table is filled in by interrogating the PIIX4 chip */
1328eb0e46SGreg Kroah-Hartman static char pci_irq[5] = {
142eaaac50SRalf Baechle };
151da177e4SLinus Torvalds
1619a8d6b7SLorenzo Pieralisi static char irq_tab[][5] = {
171da177e4SLinus Torvalds /* INTA INTB INTC INTD */
181da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 0: GT64120 PCI bridge */
191da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 1: Unused */
201da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 2: Unused */
211da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 3: Unused */
221da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 4: Unused */
231da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 5: Unused */
241da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 6: Unused */
251da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 7: Unused */
261da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 8: Unused */
271da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 9: Unused */
281da177e4SLinus Torvalds {0, 0, 0, 0, PCID }, /* 10: PIIX4 USB */
291da177e4SLinus Torvalds {0, PCIB, 0, 0, 0 }, /* 11: AMD 79C973 Ethernet */
301da177e4SLinus Torvalds {0, PCIC, 0, 0, 0 }, /* 12: Crystal 4281 Sound */
311da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 13: Unused */
321da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 14: Unused */
331da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 15: Unused */
341da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 16: Unused */
351da177e4SLinus Torvalds {0, 0, 0, 0, 0 }, /* 17: Bonito/SOC-it PCI Bridge*/
361da177e4SLinus Torvalds {0, PCIA, PCIB, PCIC, PCID }, /* 18: PCI Slot 1 */
371da177e4SLinus Torvalds {0, PCIB, PCIC, PCID, PCIA }, /* 19: PCI Slot 2 */
381da177e4SLinus Torvalds {0, PCIC, PCID, PCIA, PCIB }, /* 20: PCI Slot 3 */
391da177e4SLinus Torvalds {0, PCID, PCIA, PCIB, PCIC } /* 21: PCI Slot 4 */
401da177e4SLinus Torvalds };
411da177e4SLinus Torvalds
pcibios_map_irq(const struct pci_dev * dev,u8 slot,u8 pin)4219a8d6b7SLorenzo Pieralisi int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
431da177e4SLinus Torvalds {
441da177e4SLinus Torvalds int virq;
451da177e4SLinus Torvalds virq = irq_tab[slot][pin];
461da177e4SLinus Torvalds return pci_irq[virq];
471da177e4SLinus Torvalds }
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds /* Do platform specific device initialization at pci_enable_device() time */
pcibios_plat_dev_init(struct pci_dev * dev)501da177e4SLinus Torvalds int pcibios_plat_dev_init(struct pci_dev *dev)
511da177e4SLinus Torvalds {
521da177e4SLinus Torvalds return 0;
531da177e4SLinus Torvalds }
541da177e4SLinus Torvalds
malta_piix_func3_base_fixup(struct pci_dev * dev)55fa12b773SPaul Burton static void malta_piix_func3_base_fixup(struct pci_dev *dev)
56fa12b773SPaul Burton {
57fa12b773SPaul Burton /* Set a sane PM I/O base address */
58fa12b773SPaul Burton pci_write_config_word(dev, PIIX4_FUNC3_PMBA, 0x1000);
59fa12b773SPaul Burton
60fa12b773SPaul Burton /* Enable access to the PM I/O region */
61fa12b773SPaul Burton pci_write_config_byte(dev, PIIX4_FUNC3_PMREGMISC,
62fa12b773SPaul Burton PIIX4_FUNC3_PMREGMISC_EN);
63fa12b773SPaul Burton }
64fa12b773SPaul Burton
65fa12b773SPaul Burton DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3,
66fa12b773SPaul Burton malta_piix_func3_base_fixup);
67fa12b773SPaul Burton
malta_piix_func0_fixup(struct pci_dev * pdev)6828eb0e46SGreg Kroah-Hartman static void malta_piix_func0_fixup(struct pci_dev *pdev)
691da177e4SLinus Torvalds {
701da177e4SLinus Torvalds unsigned char reg_val;
71ae0d7cbcSPaul Burton u32 reg_val32;
729e53481eSPaul Burton u16 reg_val16;
7370002f76SDeng-Cheng Zhu /* PIIX PIRQC[A:D] irq mappings */
7470002f76SDeng-Cheng Zhu static int piixirqmap[PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_MAX] = {
751da177e4SLinus Torvalds 0, 0, 0, 3,
761da177e4SLinus Torvalds 4, 5, 6, 7,
771da177e4SLinus Torvalds 0, 9, 10, 11,
781da177e4SLinus Torvalds 12, 0, 14, 15
791da177e4SLinus Torvalds };
801da177e4SLinus Torvalds int i;
811da177e4SLinus Torvalds
821da177e4SLinus Torvalds /* Interrogate PIIX4 to get PCI IRQ mapping */
831da177e4SLinus Torvalds for (i = 0; i <= 3; i++) {
8470002f76SDeng-Cheng Zhu pci_read_config_byte(pdev, PIIX4_FUNC0_PIRQRC+i, ®_val);
8570002f76SDeng-Cheng Zhu if (reg_val & PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_DISABLE)
861da177e4SLinus Torvalds pci_irq[PCIA+i] = 0; /* Disabled */
871da177e4SLinus Torvalds else
8870002f76SDeng-Cheng Zhu pci_irq[PCIA+i] = piixirqmap[reg_val &
8970002f76SDeng-Cheng Zhu PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_MASK];
901da177e4SLinus Torvalds }
911da177e4SLinus Torvalds
921da177e4SLinus Torvalds /* Done by YAMON 2.00 onwards */
931da177e4SLinus Torvalds if (PCI_SLOT(pdev->devfn) == 10) {
941da177e4SLinus Torvalds /*
951da177e4SLinus Torvalds * Set top of main memory accessible by ISA or DMA
961da177e4SLinus Torvalds * devices to 16 Mb.
971da177e4SLinus Torvalds */
9870002f76SDeng-Cheng Zhu pci_read_config_byte(pdev, PIIX4_FUNC0_TOM, ®_val);
9970002f76SDeng-Cheng Zhu pci_write_config_byte(pdev, PIIX4_FUNC0_TOM, reg_val |
10070002f76SDeng-Cheng Zhu PIIX4_FUNC0_TOM_TOP_OF_MEMORY_MASK);
1011da177e4SLinus Torvalds }
102ae0d7cbcSPaul Burton
103ae0d7cbcSPaul Burton /* Mux SERIRQ to its pin */
104ae0d7cbcSPaul Burton pci_read_config_dword(pdev, PIIX4_FUNC0_GENCFG, ®_val32);
105ae0d7cbcSPaul Burton pci_write_config_dword(pdev, PIIX4_FUNC0_GENCFG,
106ae0d7cbcSPaul Burton reg_val32 | PIIX4_FUNC0_GENCFG_SERIRQ);
107ae0d7cbcSPaul Burton
108ae0d7cbcSPaul Burton /* Enable SERIRQ */
109ae0d7cbcSPaul Burton pci_read_config_byte(pdev, PIIX4_FUNC0_SERIRQC, ®_val);
110ae0d7cbcSPaul Burton reg_val |= PIIX4_FUNC0_SERIRQC_EN | PIIX4_FUNC0_SERIRQC_CONT;
111ae0d7cbcSPaul Burton pci_write_config_byte(pdev, PIIX4_FUNC0_SERIRQC, reg_val);
1129e53481eSPaul Burton
1139e53481eSPaul Burton /* Enable response to special cycles */
1149e53481eSPaul Burton pci_read_config_word(pdev, PCI_COMMAND, ®_val16);
1159e53481eSPaul Burton pci_write_config_word(pdev, PCI_COMMAND,
1169e53481eSPaul Burton reg_val16 | PCI_COMMAND_SPECIAL);
1171da177e4SLinus Torvalds }
1181da177e4SLinus Torvalds
1191da177e4SLinus Torvalds DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0,
1201da177e4SLinus Torvalds malta_piix_func0_fixup);
1211da177e4SLinus Torvalds
malta_piix_func1_fixup(struct pci_dev * pdev)12228eb0e46SGreg Kroah-Hartman static void malta_piix_func1_fixup(struct pci_dev *pdev)
1231da177e4SLinus Torvalds {
1241da177e4SLinus Torvalds unsigned char reg_val;
1251da177e4SLinus Torvalds
1261da177e4SLinus Torvalds /* Done by YAMON 2.02 onwards */
1271da177e4SLinus Torvalds if (PCI_SLOT(pdev->devfn) == 10) {
1281da177e4SLinus Torvalds /*
1291da177e4SLinus Torvalds * IDE Decode enable.
1301da177e4SLinus Torvalds */
13170002f76SDeng-Cheng Zhu pci_read_config_byte(pdev, PIIX4_FUNC1_IDETIM_PRIMARY_HI,
13270002f76SDeng-Cheng Zhu ®_val);
13370002f76SDeng-Cheng Zhu pci_write_config_byte(pdev, PIIX4_FUNC1_IDETIM_PRIMARY_HI,
13470002f76SDeng-Cheng Zhu reg_val|PIIX4_FUNC1_IDETIM_PRIMARY_HI_IDE_DECODE_EN);
13570002f76SDeng-Cheng Zhu pci_read_config_byte(pdev, PIIX4_FUNC1_IDETIM_SECONDARY_HI,
13670002f76SDeng-Cheng Zhu ®_val);
13770002f76SDeng-Cheng Zhu pci_write_config_byte(pdev, PIIX4_FUNC1_IDETIM_SECONDARY_HI,
13870002f76SDeng-Cheng Zhu reg_val|PIIX4_FUNC1_IDETIM_SECONDARY_HI_IDE_DECODE_EN);
1391da177e4SLinus Torvalds }
1401da177e4SLinus Torvalds }
1411da177e4SLinus Torvalds
1421da177e4SLinus Torvalds DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB,
1431da177e4SLinus Torvalds malta_piix_func1_fixup);
144497e5ff0SRalf Baechle
145497e5ff0SRalf Baechle /* Enable PCI 2.1 compatibility in PIIX4 */
quirk_dlcsetup(struct pci_dev * dev)14628eb0e46SGreg Kroah-Hartman static void quirk_dlcsetup(struct pci_dev *dev)
147497e5ff0SRalf Baechle {
148497e5ff0SRalf Baechle u8 odlc, ndlc;
149497e5ff0SRalf Baechle
15070002f76SDeng-Cheng Zhu (void) pci_read_config_byte(dev, PIIX4_FUNC0_DLC, &odlc);
151497e5ff0SRalf Baechle /* Enable passive releases and delayed transaction */
15270002f76SDeng-Cheng Zhu ndlc = odlc | PIIX4_FUNC0_DLC_USBPR_EN |
15370002f76SDeng-Cheng Zhu PIIX4_FUNC0_DLC_PASSIVE_RELEASE_EN |
15470002f76SDeng-Cheng Zhu PIIX4_FUNC0_DLC_DELAYED_TRANSACTION_EN;
15570002f76SDeng-Cheng Zhu (void) pci_write_config_byte(dev, PIIX4_FUNC0_DLC, ndlc);
156497e5ff0SRalf Baechle }
157497e5ff0SRalf Baechle
158497e5ff0SRalf Baechle DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0,
159497e5ff0SRalf Baechle quirk_dlcsetup);
160