xref: /openbmc/linux/arch/mips/pci/fixup-sni.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * This file is subject to the terms and conditions of the GNU General Public
31da177e4SLinus Torvalds  * License.  See the file "COPYING" in the main directory of this archive
41da177e4SLinus Torvalds  * for more details.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * SNI specific PCI support for RM200/RM300.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Copyright (C) 1997 - 2000, 2003, 04 Ralf Baechle (ralf@linux-mips.org)
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds #include <linux/kernel.h>
111da177e4SLinus Torvalds #include <linux/init.h>
121da177e4SLinus Torvalds #include <linux/pci.h>
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #include <asm/mipsregs.h>
151da177e4SLinus Torvalds #include <asm/sni.h>
161da177e4SLinus Torvalds 
173a1d8217SRalf Baechle #include <irq.h>
183a1d8217SRalf Baechle 
191da177e4SLinus Torvalds /*
20c066a32aSThomas Bogendoerfer  * PCIMT Shortcuts ...
211da177e4SLinus Torvalds  */
221da177e4SLinus Torvalds #define SCSI	PCIMT_IRQ_SCSI
231da177e4SLinus Torvalds #define ETH	PCIMT_IRQ_ETHERNET
241da177e4SLinus Torvalds #define INTA	PCIMT_IRQ_INTA
251da177e4SLinus Torvalds #define INTB	PCIMT_IRQ_INTB
261da177e4SLinus Torvalds #define INTC	PCIMT_IRQ_INTC
271da177e4SLinus Torvalds #define INTD	PCIMT_IRQ_INTD
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds /*
301da177e4SLinus Torvalds  * Device 0: PCI EISA Bridge	(directly routed)
311da177e4SLinus Torvalds  * Device 1: NCR53c810 SCSI	(directly routed)
321da177e4SLinus Torvalds  * Device 2: PCnet32 Ethernet	(directly routed)
331da177e4SLinus Torvalds  * Device 3: VGA		(routed to INTB)
341da177e4SLinus Torvalds  * Device 4: Unused
351da177e4SLinus Torvalds  * Device 5: Slot 2
361da177e4SLinus Torvalds  * Device 6: Slot 3
371da177e4SLinus Torvalds  * Device 7: Slot 4
381da177e4SLinus Torvalds  *
391da177e4SLinus Torvalds  * Documentation says the VGA is device 5 and device 3 is unused but that
401da177e4SLinus Torvalds  * seem to be a documentation error.  At least on my RM200C the Cirrus
411da177e4SLinus Torvalds  * Logic CL-GD5434 VGA is device 3.
421da177e4SLinus Torvalds  */
4319a8d6b7SLorenzo Pieralisi static char irq_tab_rm200[8][5] = {
441da177e4SLinus Torvalds 	/*	 INTA  INTB  INTC  INTD */
451da177e4SLinus Torvalds 	{     0,    0,	  0,	0,    0 },	/* EISA bridge */
461da177e4SLinus Torvalds 	{  SCSI, SCSI, SCSI, SCSI, SCSI },	/* SCSI */
471da177e4SLinus Torvalds 	{   ETH,  ETH,	ETH,  ETH,  ETH },	/* Ethernet */
481da177e4SLinus Torvalds 	{  INTB, INTB, INTB, INTB, INTB },	/* VGA */
491da177e4SLinus Torvalds 	{     0,    0,	  0,	0,    0 },	/* Unused */
501da177e4SLinus Torvalds 	{     0, INTB, INTC, INTD, INTA },	/* Slot 2 */
511da177e4SLinus Torvalds 	{     0, INTC, INTD, INTA, INTB },	/* Slot 3 */
521da177e4SLinus Torvalds 	{     0, INTD, INTA, INTB, INTC },	/* Slot 4 */
531da177e4SLinus Torvalds };
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds /*
561da177e4SLinus Torvalds  * In Revision D of the RM300 Device 2 has become a normal purpose Slot 1
571da177e4SLinus Torvalds  *
581da177e4SLinus Torvalds  * The VGA card is optional for RM300 systems.
591da177e4SLinus Torvalds  */
6019a8d6b7SLorenzo Pieralisi static char irq_tab_rm300d[8][5] = {
611da177e4SLinus Torvalds 	/*	 INTA  INTB  INTC  INTD */
621da177e4SLinus Torvalds 	{     0,    0,	  0,	0,    0 },	/* EISA bridge */
631da177e4SLinus Torvalds 	{  SCSI, SCSI, SCSI, SCSI, SCSI },	/* SCSI */
641da177e4SLinus Torvalds 	{     0, INTC, INTD, INTA, INTB },	/* Slot 1 */
651da177e4SLinus Torvalds 	{  INTB, INTB, INTB, INTB, INTB },	/* VGA */
661da177e4SLinus Torvalds 	{     0,    0,	  0,	0,    0 },	/* Unused */
671da177e4SLinus Torvalds 	{     0, INTB, INTC, INTD, INTA },	/* Slot 2 */
681da177e4SLinus Torvalds 	{     0, INTC, INTD, INTA, INTB },	/* Slot 3 */
691da177e4SLinus Torvalds 	{     0, INTD, INTA, INTB, INTC },	/* Slot 4 */
701da177e4SLinus Torvalds };
711da177e4SLinus Torvalds 
7219a8d6b7SLorenzo Pieralisi static char irq_tab_rm300e[5][5] = {
73c066a32aSThomas Bogendoerfer 	/*	 INTA  INTB  INTC  INTD */
74c066a32aSThomas Bogendoerfer 	{     0,    0,	  0,	0,    0 },	/* HOST bridge */
75c066a32aSThomas Bogendoerfer 	{  SCSI, SCSI, SCSI, SCSI, SCSI },	/* SCSI */
76c066a32aSThomas Bogendoerfer 	{     0, INTC, INTD, INTA, INTB },	/* Bridge/i960 */
77c066a32aSThomas Bogendoerfer 	{     0, INTD, INTA, INTB, INTC },	/* Slot 1 */
78c066a32aSThomas Bogendoerfer 	{     0, INTA, INTB, INTC, INTD },	/* Slot 2 */
79c066a32aSThomas Bogendoerfer };
80c066a32aSThomas Bogendoerfer #undef SCSI
81c066a32aSThomas Bogendoerfer #undef ETH
82c066a32aSThomas Bogendoerfer #undef INTA
83c066a32aSThomas Bogendoerfer #undef INTB
84c066a32aSThomas Bogendoerfer #undef INTC
85c066a32aSThomas Bogendoerfer #undef INTD
86c066a32aSThomas Bogendoerfer 
87c066a32aSThomas Bogendoerfer 
88c066a32aSThomas Bogendoerfer /*
89c066a32aSThomas Bogendoerfer  * PCIT Shortcuts ...
90c066a32aSThomas Bogendoerfer  */
91c066a32aSThomas Bogendoerfer #define SCSI0	PCIT_IRQ_SCSI0
92c066a32aSThomas Bogendoerfer #define SCSI1	PCIT_IRQ_SCSI1
93c066a32aSThomas Bogendoerfer #define ETH	PCIT_IRQ_ETHERNET
94c066a32aSThomas Bogendoerfer #define INTA	PCIT_IRQ_INTA
95c066a32aSThomas Bogendoerfer #define INTB	PCIT_IRQ_INTB
96c066a32aSThomas Bogendoerfer #define INTC	PCIT_IRQ_INTC
97c066a32aSThomas Bogendoerfer #define INTD	PCIT_IRQ_INTD
98c066a32aSThomas Bogendoerfer 
9919a8d6b7SLorenzo Pieralisi static char irq_tab_pcit[13][5] = {
100c066a32aSThomas Bogendoerfer 	/*	 INTA  INTB  INTC  INTD */
101c066a32aSThomas Bogendoerfer 	{     0,     0,	    0,	   0,	  0 },	/* HOST bridge */
102c066a32aSThomas Bogendoerfer 	{ SCSI0, SCSI0, SCSI0, SCSI0, SCSI0 },	/* SCSI */
103c066a32aSThomas Bogendoerfer 	{ SCSI1, SCSI1, SCSI1, SCSI1, SCSI1 },	/* SCSI */
104c066a32aSThomas Bogendoerfer 	{   ETH,   ETH,	  ETH,	 ETH,	ETH },	/* Ethernet */
105c066a32aSThomas Bogendoerfer 	{     0,  INTA,	 INTB,	INTC,  INTD },	/* PCI-PCI bridge */
106c066a32aSThomas Bogendoerfer 	{     0,     0,	    0,	   0,	  0 },	/* Unused */
107c066a32aSThomas Bogendoerfer 	{     0,     0,	    0,	   0,	  0 },	/* Unused */
108c066a32aSThomas Bogendoerfer 	{     0,     0,	    0,	   0,	  0 },	/* Unused */
109c066a32aSThomas Bogendoerfer 	{     0,  INTA,	 INTB,	INTC,  INTD },	/* Slot 1 */
110c066a32aSThomas Bogendoerfer 	{     0,  INTB,	 INTC,	INTD,  INTA },	/* Slot 2 */
111c066a32aSThomas Bogendoerfer 	{     0,  INTC,	 INTD,	INTA,  INTB },	/* Slot 3 */
112c066a32aSThomas Bogendoerfer 	{     0,  INTD,	 INTA,	INTB,  INTC },	/* Slot 4 */
113c066a32aSThomas Bogendoerfer 	{     0,  INTA,	 INTB,	INTC,  INTD },	/* Slot 5 */
114c066a32aSThomas Bogendoerfer };
115c066a32aSThomas Bogendoerfer 
11619a8d6b7SLorenzo Pieralisi static char irq_tab_pcit_cplus[13][5] = {
117fcee3fafSThomas Bogendoerfer 	/*	 INTA  INTB  INTC  INTD */
118fcee3fafSThomas Bogendoerfer 	{     0,     0,	    0,	   0,	  0 },	/* HOST bridge */
119fcee3fafSThomas Bogendoerfer 	{     0,  INTB,	 INTC,	INTD,  INTA },	/* PCI Slot 9 */
120fcee3fafSThomas Bogendoerfer 	{     0,     0,	    0,	   0,	  0 },	/* PCI-EISA */
121fcee3fafSThomas Bogendoerfer 	{     0,     0,	    0,	   0,	  0 },	/* Unused */
122fcee3fafSThomas Bogendoerfer 	{     0,  INTA,	 INTB,	INTC,  INTD },	/* PCI-PCI bridge */
123fcee3fafSThomas Bogendoerfer 	{     0,  INTB,	 INTC,	INTD,  INTA },	/* fixup */
124fcee3fafSThomas Bogendoerfer };
125fcee3fafSThomas Bogendoerfer 
is_rm300_revd(void)1261da177e4SLinus Torvalds static inline int is_rm300_revd(void)
1271da177e4SLinus Torvalds {
1281da177e4SLinus Torvalds 	unsigned char csmsr = *(volatile unsigned char *)PCIMT_CSMSR;
1291da177e4SLinus Torvalds 
1301da177e4SLinus Torvalds 	return (csmsr & 0xa0) == 0x20;
1311da177e4SLinus Torvalds }
1321da177e4SLinus Torvalds 
pcibios_map_irq(const struct pci_dev * dev,u8 slot,u8 pin)13319a8d6b7SLorenzo Pieralisi int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
1341da177e4SLinus Torvalds {
135c066a32aSThomas Bogendoerfer 	switch (sni_brd_type) {
136c066a32aSThomas Bogendoerfer 	case SNI_BRD_PCI_TOWER_CPLUS:
137fcee3fafSThomas Bogendoerfer 		if (slot == 4) {
138fcee3fafSThomas Bogendoerfer 			/*
139fcee3fafSThomas Bogendoerfer 			 * SNI messed up interrupt wiring for onboard
140fcee3fafSThomas Bogendoerfer 			 * PCI bus 1; we need to fix this up here
141fcee3fafSThomas Bogendoerfer 			 */
142fcee3fafSThomas Bogendoerfer 			while (dev && dev->bus->number != 1)
143fcee3fafSThomas Bogendoerfer 				dev = dev->bus->self;
144fcee3fafSThomas Bogendoerfer 			if (dev && dev->devfn >= PCI_DEVFN(4, 0))
145fcee3fafSThomas Bogendoerfer 				slot = 5;
146fcee3fafSThomas Bogendoerfer 		}
147fcee3fafSThomas Bogendoerfer 		return irq_tab_pcit_cplus[slot][pin];
148fcee3fafSThomas Bogendoerfer 	case SNI_BRD_PCI_TOWER:
149c066a32aSThomas Bogendoerfer 		return irq_tab_pcit[slot][pin];
150c066a32aSThomas Bogendoerfer 
151c066a32aSThomas Bogendoerfer 	case SNI_BRD_PCI_MTOWER:
1521da177e4SLinus Torvalds 		if (is_rm300_revd())
1531da177e4SLinus Torvalds 			return irq_tab_rm300d[slot][pin];
154*c9b02990SLiangliang Huang 		fallthrough;
155c066a32aSThomas Bogendoerfer 	case SNI_BRD_PCI_DESKTOP:
1561da177e4SLinus Torvalds 		return irq_tab_rm200[slot][pin];
157c066a32aSThomas Bogendoerfer 
158c066a32aSThomas Bogendoerfer 	case SNI_BRD_PCI_MTOWER_CPLUS:
159c066a32aSThomas Bogendoerfer 		return irq_tab_rm300e[slot][pin];
160c066a32aSThomas Bogendoerfer 	}
161c066a32aSThomas Bogendoerfer 
162c066a32aSThomas Bogendoerfer 	return 0;
1631da177e4SLinus Torvalds }
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds /* Do platform specific device initialization at pci_enable_device() time */
pcibios_plat_dev_init(struct pci_dev * dev)1661da177e4SLinus Torvalds int pcibios_plat_dev_init(struct pci_dev *dev)
1671da177e4SLinus Torvalds {
1681da177e4SLinus Torvalds 	return 0;
1691da177e4SLinus Torvalds }
170