18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
38c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
48c2ecf20Sopenharmony_ci * for more details.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * SNI specific PCI support for RM200/RM300.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (C) 1997 - 2000, 2003, 04 Ralf Baechle (ralf@linux-mips.org)
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci#include <linux/kernel.h>
118c2ecf20Sopenharmony_ci#include <linux/init.h>
128c2ecf20Sopenharmony_ci#include <linux/pci.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <asm/mipsregs.h>
158c2ecf20Sopenharmony_ci#include <asm/sni.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <irq.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/*
208c2ecf20Sopenharmony_ci * PCIMT Shortcuts ...
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci#define SCSI	PCIMT_IRQ_SCSI
238c2ecf20Sopenharmony_ci#define ETH	PCIMT_IRQ_ETHERNET
248c2ecf20Sopenharmony_ci#define INTA	PCIMT_IRQ_INTA
258c2ecf20Sopenharmony_ci#define INTB	PCIMT_IRQ_INTB
268c2ecf20Sopenharmony_ci#define INTC	PCIMT_IRQ_INTC
278c2ecf20Sopenharmony_ci#define INTD	PCIMT_IRQ_INTD
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/*
308c2ecf20Sopenharmony_ci * Device 0: PCI EISA Bridge	(directly routed)
318c2ecf20Sopenharmony_ci * Device 1: NCR53c810 SCSI	(directly routed)
328c2ecf20Sopenharmony_ci * Device 2: PCnet32 Ethernet	(directly routed)
338c2ecf20Sopenharmony_ci * Device 3: VGA		(routed to INTB)
348c2ecf20Sopenharmony_ci * Device 4: Unused
358c2ecf20Sopenharmony_ci * Device 5: Slot 2
368c2ecf20Sopenharmony_ci * Device 6: Slot 3
378c2ecf20Sopenharmony_ci * Device 7: Slot 4
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci * Documentation says the VGA is device 5 and device 3 is unused but that
408c2ecf20Sopenharmony_ci * seem to be a documentation error.  At least on my RM200C the Cirrus
418c2ecf20Sopenharmony_ci * Logic CL-GD5434 VGA is device 3.
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_cistatic char irq_tab_rm200[8][5] = {
448c2ecf20Sopenharmony_ci	/*	 INTA  INTB  INTC  INTD */
458c2ecf20Sopenharmony_ci	{     0,    0,	  0,	0,    0 },	/* EISA bridge */
468c2ecf20Sopenharmony_ci	{  SCSI, SCSI, SCSI, SCSI, SCSI },	/* SCSI */
478c2ecf20Sopenharmony_ci	{   ETH,  ETH,	ETH,  ETH,  ETH },	/* Ethernet */
488c2ecf20Sopenharmony_ci	{  INTB, INTB, INTB, INTB, INTB },	/* VGA */
498c2ecf20Sopenharmony_ci	{     0,    0,	  0,	0,    0 },	/* Unused */
508c2ecf20Sopenharmony_ci	{     0, INTB, INTC, INTD, INTA },	/* Slot 2 */
518c2ecf20Sopenharmony_ci	{     0, INTC, INTD, INTA, INTB },	/* Slot 3 */
528c2ecf20Sopenharmony_ci	{     0, INTD, INTA, INTB, INTC },	/* Slot 4 */
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/*
568c2ecf20Sopenharmony_ci * In Revision D of the RM300 Device 2 has become a normal purpose Slot 1
578c2ecf20Sopenharmony_ci *
588c2ecf20Sopenharmony_ci * The VGA card is optional for RM300 systems.
598c2ecf20Sopenharmony_ci */
608c2ecf20Sopenharmony_cistatic char irq_tab_rm300d[8][5] = {
618c2ecf20Sopenharmony_ci	/*	 INTA  INTB  INTC  INTD */
628c2ecf20Sopenharmony_ci	{     0,    0,	  0,	0,    0 },	/* EISA bridge */
638c2ecf20Sopenharmony_ci	{  SCSI, SCSI, SCSI, SCSI, SCSI },	/* SCSI */
648c2ecf20Sopenharmony_ci	{     0, INTC, INTD, INTA, INTB },	/* Slot 1 */
658c2ecf20Sopenharmony_ci	{  INTB, INTB, INTB, INTB, INTB },	/* VGA */
668c2ecf20Sopenharmony_ci	{     0,    0,	  0,	0,    0 },	/* Unused */
678c2ecf20Sopenharmony_ci	{     0, INTB, INTC, INTD, INTA },	/* Slot 2 */
688c2ecf20Sopenharmony_ci	{     0, INTC, INTD, INTA, INTB },	/* Slot 3 */
698c2ecf20Sopenharmony_ci	{     0, INTD, INTA, INTB, INTC },	/* Slot 4 */
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistatic char irq_tab_rm300e[5][5] = {
738c2ecf20Sopenharmony_ci	/*	 INTA  INTB  INTC  INTD */
748c2ecf20Sopenharmony_ci	{     0,    0,	  0,	0,    0 },	/* HOST bridge */
758c2ecf20Sopenharmony_ci	{  SCSI, SCSI, SCSI, SCSI, SCSI },	/* SCSI */
768c2ecf20Sopenharmony_ci	{     0, INTC, INTD, INTA, INTB },	/* Bridge/i960 */
778c2ecf20Sopenharmony_ci	{     0, INTD, INTA, INTB, INTC },	/* Slot 1 */
788c2ecf20Sopenharmony_ci	{     0, INTA, INTB, INTC, INTD },	/* Slot 2 */
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci#undef SCSI
818c2ecf20Sopenharmony_ci#undef ETH
828c2ecf20Sopenharmony_ci#undef INTA
838c2ecf20Sopenharmony_ci#undef INTB
848c2ecf20Sopenharmony_ci#undef INTC
858c2ecf20Sopenharmony_ci#undef INTD
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/*
898c2ecf20Sopenharmony_ci * PCIT Shortcuts ...
908c2ecf20Sopenharmony_ci */
918c2ecf20Sopenharmony_ci#define SCSI0	PCIT_IRQ_SCSI0
928c2ecf20Sopenharmony_ci#define SCSI1	PCIT_IRQ_SCSI1
938c2ecf20Sopenharmony_ci#define ETH	PCIT_IRQ_ETHERNET
948c2ecf20Sopenharmony_ci#define INTA	PCIT_IRQ_INTA
958c2ecf20Sopenharmony_ci#define INTB	PCIT_IRQ_INTB
968c2ecf20Sopenharmony_ci#define INTC	PCIT_IRQ_INTC
978c2ecf20Sopenharmony_ci#define INTD	PCIT_IRQ_INTD
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic char irq_tab_pcit[13][5] = {
1008c2ecf20Sopenharmony_ci	/*	 INTA  INTB  INTC  INTD */
1018c2ecf20Sopenharmony_ci	{     0,     0,	    0,	   0,	  0 },	/* HOST bridge */
1028c2ecf20Sopenharmony_ci	{ SCSI0, SCSI0, SCSI0, SCSI0, SCSI0 },	/* SCSI */
1038c2ecf20Sopenharmony_ci	{ SCSI1, SCSI1, SCSI1, SCSI1, SCSI1 },	/* SCSI */
1048c2ecf20Sopenharmony_ci	{   ETH,   ETH,	  ETH,	 ETH,	ETH },	/* Ethernet */
1058c2ecf20Sopenharmony_ci	{     0,  INTA,	 INTB,	INTC,  INTD },	/* PCI-PCI bridge */
1068c2ecf20Sopenharmony_ci	{     0,     0,	    0,	   0,	  0 },	/* Unused */
1078c2ecf20Sopenharmony_ci	{     0,     0,	    0,	   0,	  0 },	/* Unused */
1088c2ecf20Sopenharmony_ci	{     0,     0,	    0,	   0,	  0 },	/* Unused */
1098c2ecf20Sopenharmony_ci	{     0,  INTA,	 INTB,	INTC,  INTD },	/* Slot 1 */
1108c2ecf20Sopenharmony_ci	{     0,  INTB,	 INTC,	INTD,  INTA },	/* Slot 2 */
1118c2ecf20Sopenharmony_ci	{     0,  INTC,	 INTD,	INTA,  INTB },	/* Slot 3 */
1128c2ecf20Sopenharmony_ci	{     0,  INTD,	 INTA,	INTB,  INTC },	/* Slot 4 */
1138c2ecf20Sopenharmony_ci	{     0,  INTA,	 INTB,	INTC,  INTD },	/* Slot 5 */
1148c2ecf20Sopenharmony_ci};
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic char irq_tab_pcit_cplus[13][5] = {
1178c2ecf20Sopenharmony_ci	/*	 INTA  INTB  INTC  INTD */
1188c2ecf20Sopenharmony_ci	{     0,     0,	    0,	   0,	  0 },	/* HOST bridge */
1198c2ecf20Sopenharmony_ci	{     0,  INTB,	 INTC,	INTD,  INTA },	/* PCI Slot 9 */
1208c2ecf20Sopenharmony_ci	{     0,     0,	    0,	   0,	  0 },	/* PCI-EISA */
1218c2ecf20Sopenharmony_ci	{     0,     0,	    0,	   0,	  0 },	/* Unused */
1228c2ecf20Sopenharmony_ci	{     0,  INTA,	 INTB,	INTC,  INTD },	/* PCI-PCI bridge */
1238c2ecf20Sopenharmony_ci	{     0,  INTB,	 INTC,	INTD,  INTA },	/* fixup */
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistatic inline int is_rm300_revd(void)
1278c2ecf20Sopenharmony_ci{
1288c2ecf20Sopenharmony_ci	unsigned char csmsr = *(volatile unsigned char *)PCIMT_CSMSR;
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	return (csmsr & 0xa0) == 0x20;
1318c2ecf20Sopenharmony_ci}
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ciint pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	switch (sni_brd_type) {
1368c2ecf20Sopenharmony_ci	case SNI_BRD_PCI_TOWER_CPLUS:
1378c2ecf20Sopenharmony_ci		if (slot == 4) {
1388c2ecf20Sopenharmony_ci			/*
1398c2ecf20Sopenharmony_ci			 * SNI messed up interrupt wiring for onboard
1408c2ecf20Sopenharmony_ci			 * PCI bus 1; we need to fix this up here
1418c2ecf20Sopenharmony_ci			 */
1428c2ecf20Sopenharmony_ci			while (dev && dev->bus->number != 1)
1438c2ecf20Sopenharmony_ci				dev = dev->bus->self;
1448c2ecf20Sopenharmony_ci			if (dev && dev->devfn >= PCI_DEVFN(4, 0))
1458c2ecf20Sopenharmony_ci				slot = 5;
1468c2ecf20Sopenharmony_ci		}
1478c2ecf20Sopenharmony_ci		return irq_tab_pcit_cplus[slot][pin];
1488c2ecf20Sopenharmony_ci	case SNI_BRD_PCI_TOWER:
1498c2ecf20Sopenharmony_ci		return irq_tab_pcit[slot][pin];
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	case SNI_BRD_PCI_MTOWER:
1528c2ecf20Sopenharmony_ci		if (is_rm300_revd())
1538c2ecf20Sopenharmony_ci			return irq_tab_rm300d[slot][pin];
1548c2ecf20Sopenharmony_ci		fallthrough;
1558c2ecf20Sopenharmony_ci	case SNI_BRD_PCI_DESKTOP:
1568c2ecf20Sopenharmony_ci		return irq_tab_rm200[slot][pin];
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci	case SNI_BRD_PCI_MTOWER_CPLUS:
1598c2ecf20Sopenharmony_ci		return irq_tab_rm300e[slot][pin];
1608c2ecf20Sopenharmony_ci	}
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	return 0;
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/* Do platform specific device initialization at pci_enable_device() time */
1668c2ecf20Sopenharmony_ciint pcibios_plat_dev_init(struct pci_dev *dev)
1678c2ecf20Sopenharmony_ci{
1688c2ecf20Sopenharmony_ci	return 0;
1698c2ecf20Sopenharmony_ci}
170