xref: /linux/arch/mips/pci/ops-tx4927.c (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
389d63fe1SAtsushi Nemoto  * Define the pci_ops for the PCIC on Toshiba TX4927, TX4938, etc.
41da177e4SLinus Torvalds  *
589d63fe1SAtsushi Nemoto  * Based on linux/arch/mips/pci/ops-tx4938.c,
689d63fe1SAtsushi Nemoto  *	    linux/arch/mips/pci/fixup-rbtx4938.c,
789d63fe1SAtsushi Nemoto  *	    linux/arch/mips/txx9/rbtx4938/setup.c,
889d63fe1SAtsushi Nemoto  *	    and RBTX49xx patch from CELF patch archive.
989d63fe1SAtsushi Nemoto  *
1089d63fe1SAtsushi Nemoto  * 2003-2005 (c) MontaVista Software, Inc.
111da177e4SLinus Torvalds  * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
1289d63fe1SAtsushi Nemoto  * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
131da177e4SLinus Torvalds  */
141da177e4SLinus Torvalds #include <linux/kernel.h>
15455cc256SAtsushi Nemoto #include <linux/interrupt.h>
16ca4d3e67SDavid Howells #include <linux/irq.h>
17455cc256SAtsushi Nemoto #include <asm/txx9/pci.h>
1889d63fe1SAtsushi Nemoto #include <asm/txx9/tx4927pcic.h>
191da177e4SLinus Torvalds 
2089d63fe1SAtsushi Nemoto static struct {
2189d63fe1SAtsushi Nemoto 	struct pci_controller *channel;
2289d63fe1SAtsushi Nemoto 	struct tx4927_pcic_reg __iomem *pcicptr;
2389d63fe1SAtsushi Nemoto } pcicptrs[2];	/* TX4938 has 2 pcic */
241da177e4SLinus Torvalds 
set_tx4927_pcicptr(struct pci_controller * channel,struct tx4927_pcic_reg __iomem * pcicptr)2589d63fe1SAtsushi Nemoto static void __init set_tx4927_pcicptr(struct pci_controller *channel,
2689d63fe1SAtsushi Nemoto 				      struct tx4927_pcic_reg __iomem *pcicptr)
271da177e4SLinus Torvalds {
2889d63fe1SAtsushi Nemoto 	int i;
291da177e4SLinus Torvalds 
3089d63fe1SAtsushi Nemoto 	for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
3189d63fe1SAtsushi Nemoto 		if (pcicptrs[i].channel == channel) {
3289d63fe1SAtsushi Nemoto 			pcicptrs[i].pcicptr = pcicptr;
3389d63fe1SAtsushi Nemoto 			return;
341da177e4SLinus Torvalds 		}
3589d63fe1SAtsushi Nemoto 	}
3689d63fe1SAtsushi Nemoto 	for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
3789d63fe1SAtsushi Nemoto 		if (!pcicptrs[i].channel) {
3889d63fe1SAtsushi Nemoto 			pcicptrs[i].channel = channel;
3989d63fe1SAtsushi Nemoto 			pcicptrs[i].pcicptr = pcicptr;
4089d63fe1SAtsushi Nemoto 			return;
4189d63fe1SAtsushi Nemoto 		}
4289d63fe1SAtsushi Nemoto 	}
4389d63fe1SAtsushi Nemoto 	BUG();
4489d63fe1SAtsushi Nemoto }
4589d63fe1SAtsushi Nemoto 
get_tx4927_pcicptr(struct pci_controller * channel)4689d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *get_tx4927_pcicptr(
4789d63fe1SAtsushi Nemoto 	struct pci_controller *channel)
4889d63fe1SAtsushi Nemoto {
4989d63fe1SAtsushi Nemoto 	int i;
5089d63fe1SAtsushi Nemoto 
5189d63fe1SAtsushi Nemoto 	for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
5289d63fe1SAtsushi Nemoto 		if (pcicptrs[i].channel == channel)
5389d63fe1SAtsushi Nemoto 			return pcicptrs[i].pcicptr;
5489d63fe1SAtsushi Nemoto 	}
5589d63fe1SAtsushi Nemoto 	return NULL;
5689d63fe1SAtsushi Nemoto }
5789d63fe1SAtsushi Nemoto 
mkaddr(struct pci_bus * bus,unsigned int devfn,int where,struct tx4927_pcic_reg __iomem * pcicptr)5889d63fe1SAtsushi Nemoto static int mkaddr(struct pci_bus *bus, unsigned int devfn, int where,
5989d63fe1SAtsushi Nemoto 		  struct tx4927_pcic_reg __iomem *pcicptr)
6089d63fe1SAtsushi Nemoto {
6189d63fe1SAtsushi Nemoto 	if (bus->parent == NULL &&
6289d63fe1SAtsushi Nemoto 	    devfn >= PCI_DEVFN(TX4927_PCIC_MAX_DEVNU, 0))
63923cfd08SIlpo Järvinen 		return PCIBIOS_DEVICE_NOT_FOUND;
6489d63fe1SAtsushi Nemoto 	__raw_writel(((bus->number & 0xff) << 0x10)
6589d63fe1SAtsushi Nemoto 		     | ((devfn & 0xff) << 0x08) | (where & 0xfc)
6689d63fe1SAtsushi Nemoto 		     | (bus->parent ? 1 : 0),
6789d63fe1SAtsushi Nemoto 		     &pcicptr->g2pcfgadrs);
681da177e4SLinus Torvalds 	/* clear M_ABORT and Disable M_ABORT Int. */
6989d63fe1SAtsushi Nemoto 	__raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
7089d63fe1SAtsushi Nemoto 		     | (PCI_STATUS_REC_MASTER_ABORT << 16),
7189d63fe1SAtsushi Nemoto 		     &pcicptr->pcistatus);
72923cfd08SIlpo Järvinen 	return PCIBIOS_SUCCESSFUL;
731da177e4SLinus Torvalds }
741da177e4SLinus Torvalds 
check_abort(struct tx4927_pcic_reg __iomem * pcicptr)7589d63fe1SAtsushi Nemoto static int check_abort(struct tx4927_pcic_reg __iomem *pcicptr)
761da177e4SLinus Torvalds {
771da177e4SLinus Torvalds 	int code = PCIBIOS_SUCCESSFUL;
7889d63fe1SAtsushi Nemoto 
7989d63fe1SAtsushi Nemoto 	/* wait write cycle completion before checking error status */
8089d63fe1SAtsushi Nemoto 	while (__raw_readl(&pcicptr->pcicstatus) & TX4927_PCIC_PCICSTATUS_IWB)
8189d63fe1SAtsushi Nemoto 		;
8289d63fe1SAtsushi Nemoto 	if (__raw_readl(&pcicptr->pcistatus)
8389d63fe1SAtsushi Nemoto 	    & (PCI_STATUS_REC_MASTER_ABORT << 16)) {
8489d63fe1SAtsushi Nemoto 		__raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
8589d63fe1SAtsushi Nemoto 			     | (PCI_STATUS_REC_MASTER_ABORT << 16),
8689d63fe1SAtsushi Nemoto 			     &pcicptr->pcistatus);
8732d00d0fSAtsushi Nemoto 		/* flush write buffer */
8832d00d0fSAtsushi Nemoto 		iob();
891da177e4SLinus Torvalds 		code = PCIBIOS_DEVICE_NOT_FOUND;
901da177e4SLinus Torvalds 	}
911da177e4SLinus Torvalds 	return code;
921da177e4SLinus Torvalds }
931da177e4SLinus Torvalds 
icd_readb(int offset,struct tx4927_pcic_reg __iomem * pcicptr)9489d63fe1SAtsushi Nemoto static u8 icd_readb(int offset, struct tx4927_pcic_reg __iomem *pcicptr)
951da177e4SLinus Torvalds {
9689d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
9789d63fe1SAtsushi Nemoto 	offset ^= 3;
9889d63fe1SAtsushi Nemoto #endif
9989d63fe1SAtsushi Nemoto 	return __raw_readb((void __iomem *)&pcicptr->g2pcfgdata + offset);
10089d63fe1SAtsushi Nemoto }
icd_readw(int offset,struct tx4927_pcic_reg __iomem * pcicptr)10189d63fe1SAtsushi Nemoto static u16 icd_readw(int offset, struct tx4927_pcic_reg __iomem *pcicptr)
10289d63fe1SAtsushi Nemoto {
10389d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
10489d63fe1SAtsushi Nemoto 	offset ^= 2;
10589d63fe1SAtsushi Nemoto #endif
10689d63fe1SAtsushi Nemoto 	return __raw_readw((void __iomem *)&pcicptr->g2pcfgdata + offset);
10789d63fe1SAtsushi Nemoto }
icd_readl(struct tx4927_pcic_reg __iomem * pcicptr)10889d63fe1SAtsushi Nemoto static u32 icd_readl(struct tx4927_pcic_reg __iomem *pcicptr)
10989d63fe1SAtsushi Nemoto {
11089d63fe1SAtsushi Nemoto 	return __raw_readl(&pcicptr->g2pcfgdata);
11189d63fe1SAtsushi Nemoto }
icd_writeb(u8 val,int offset,struct tx4927_pcic_reg __iomem * pcicptr)11289d63fe1SAtsushi Nemoto static void icd_writeb(u8 val, int offset,
11389d63fe1SAtsushi Nemoto 		       struct tx4927_pcic_reg __iomem *pcicptr)
11489d63fe1SAtsushi Nemoto {
11589d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
11689d63fe1SAtsushi Nemoto 	offset ^= 3;
11789d63fe1SAtsushi Nemoto #endif
11889d63fe1SAtsushi Nemoto 	__raw_writeb(val, (void __iomem *)&pcicptr->g2pcfgdata + offset);
11989d63fe1SAtsushi Nemoto }
icd_writew(u16 val,int offset,struct tx4927_pcic_reg __iomem * pcicptr)12089d63fe1SAtsushi Nemoto static void icd_writew(u16 val, int offset,
12189d63fe1SAtsushi Nemoto 		       struct tx4927_pcic_reg __iomem *pcicptr)
12289d63fe1SAtsushi Nemoto {
12389d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
12489d63fe1SAtsushi Nemoto 	offset ^= 2;
12589d63fe1SAtsushi Nemoto #endif
12689d63fe1SAtsushi Nemoto 	__raw_writew(val, (void __iomem *)&pcicptr->g2pcfgdata + offset);
12789d63fe1SAtsushi Nemoto }
icd_writel(u32 val,struct tx4927_pcic_reg __iomem * pcicptr)12889d63fe1SAtsushi Nemoto static void icd_writel(u32 val, struct tx4927_pcic_reg __iomem *pcicptr)
12989d63fe1SAtsushi Nemoto {
13089d63fe1SAtsushi Nemoto 	__raw_writel(val, &pcicptr->g2pcfgdata);
1311da177e4SLinus Torvalds }
1321da177e4SLinus Torvalds 
pci_bus_to_pcicptr(struct pci_bus * bus)13389d63fe1SAtsushi Nemoto static struct tx4927_pcic_reg __iomem *pci_bus_to_pcicptr(struct pci_bus *bus)
13489d63fe1SAtsushi Nemoto {
13589d63fe1SAtsushi Nemoto 	struct pci_controller *channel = bus->sysdata;
13689d63fe1SAtsushi Nemoto 	return get_tx4927_pcicptr(channel);
1371da177e4SLinus Torvalds }
1381da177e4SLinus Torvalds 
tx4927_pci_config_read(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 * val)13989d63fe1SAtsushi Nemoto static int tx4927_pci_config_read(struct pci_bus *bus, unsigned int devfn,
14089d63fe1SAtsushi Nemoto 				  int where, int size, u32 *val)
14189d63fe1SAtsushi Nemoto {
14289d63fe1SAtsushi Nemoto 	struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(bus);
143923cfd08SIlpo Järvinen 	int ret;
14489d63fe1SAtsushi Nemoto 
145923cfd08SIlpo Järvinen 	ret = mkaddr(bus, devfn, where, pcicptr);
146923cfd08SIlpo Järvinen 	if (ret != PCIBIOS_SUCCESSFUL) {
147*3c35da51SIlpo Järvinen 		PCI_SET_ERROR_RESPONSE(val);
148923cfd08SIlpo Järvinen 		return ret;
14989d63fe1SAtsushi Nemoto 	}
1501da177e4SLinus Torvalds 	switch (size) {
1511da177e4SLinus Torvalds 	case 1:
15289d63fe1SAtsushi Nemoto 		*val = icd_readb(where & 3, pcicptr);
1531da177e4SLinus Torvalds 		break;
1541da177e4SLinus Torvalds 	case 2:
15589d63fe1SAtsushi Nemoto 		*val = icd_readw(where & 3, pcicptr);
15689d63fe1SAtsushi Nemoto 		break;
15789d63fe1SAtsushi Nemoto 	default:
15889d63fe1SAtsushi Nemoto 		*val = icd_readl(pcicptr);
15989d63fe1SAtsushi Nemoto 	}
16089d63fe1SAtsushi Nemoto 	return check_abort(pcicptr);
16189d63fe1SAtsushi Nemoto }
16289d63fe1SAtsushi Nemoto 
tx4927_pci_config_write(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 val)16389d63fe1SAtsushi Nemoto static int tx4927_pci_config_write(struct pci_bus *bus, unsigned int devfn,
16489d63fe1SAtsushi Nemoto 				   int where, int size, u32 val)
16589d63fe1SAtsushi Nemoto {
16689d63fe1SAtsushi Nemoto 	struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(bus);
167923cfd08SIlpo Järvinen 	int ret;
16889d63fe1SAtsushi Nemoto 
169923cfd08SIlpo Järvinen 	ret = mkaddr(bus, devfn, where, pcicptr);
170923cfd08SIlpo Järvinen 	if (ret != PCIBIOS_SUCCESSFUL)
171923cfd08SIlpo Järvinen 		return ret;
17289d63fe1SAtsushi Nemoto 	switch (size) {
17389d63fe1SAtsushi Nemoto 	case 1:
17489d63fe1SAtsushi Nemoto 		icd_writeb(val, where & 3, pcicptr);
17589d63fe1SAtsushi Nemoto 		break;
17689d63fe1SAtsushi Nemoto 	case 2:
17789d63fe1SAtsushi Nemoto 		icd_writew(val, where & 3, pcicptr);
17889d63fe1SAtsushi Nemoto 		break;
17989d63fe1SAtsushi Nemoto 	default:
18089d63fe1SAtsushi Nemoto 		icd_writel(val, pcicptr);
18189d63fe1SAtsushi Nemoto 	}
18289d63fe1SAtsushi Nemoto 	return check_abort(pcicptr);
18389d63fe1SAtsushi Nemoto }
18489d63fe1SAtsushi Nemoto 
18589d63fe1SAtsushi Nemoto static struct pci_ops tx4927_pci_ops = {
18689d63fe1SAtsushi Nemoto 	.read = tx4927_pci_config_read,
18789d63fe1SAtsushi Nemoto 	.write = tx4927_pci_config_write,
18889d63fe1SAtsushi Nemoto };
18989d63fe1SAtsushi Nemoto 
19089d63fe1SAtsushi Nemoto static struct {
19189d63fe1SAtsushi Nemoto 	u8 trdyto;
19289d63fe1SAtsushi Nemoto 	u8 retryto;
19389d63fe1SAtsushi Nemoto 	u16 gbwc;
19428eb0e46SGreg Kroah-Hartman } tx4927_pci_opts = {
19589d63fe1SAtsushi Nemoto 	.trdyto = 0,
19689d63fe1SAtsushi Nemoto 	.retryto = 0,
19789d63fe1SAtsushi Nemoto 	.gbwc = 0xfe0,	/* 4064 GBUSCLK for CCFG.GTOT=0b11 */
19889d63fe1SAtsushi Nemoto };
19989d63fe1SAtsushi Nemoto 
tx4927_pcibios_setup(char * str)20028eb0e46SGreg Kroah-Hartman char *tx4927_pcibios_setup(char *str)
20107517529SAtsushi Nemoto {
20207517529SAtsushi Nemoto 	if (!strncmp(str, "trdyto=", 7)) {
2038e9ecbc5SDaniel Walter 		u8 val = 0;
2048e9ecbc5SDaniel Walter 		if (kstrtou8(str + 7, 0, &val) == 0)
20507517529SAtsushi Nemoto 			tx4927_pci_opts.trdyto = val;
20607517529SAtsushi Nemoto 		return NULL;
20707517529SAtsushi Nemoto 	}
20807517529SAtsushi Nemoto 	if (!strncmp(str, "retryto=", 8)) {
2098e9ecbc5SDaniel Walter 		u8 val = 0;
2108e9ecbc5SDaniel Walter 		if (kstrtou8(str + 8, 0, &val) == 0)
21107517529SAtsushi Nemoto 			tx4927_pci_opts.retryto = val;
21207517529SAtsushi Nemoto 		return NULL;
21307517529SAtsushi Nemoto 	}
21407517529SAtsushi Nemoto 	if (!strncmp(str, "gbwc=", 5)) {
2158e9ecbc5SDaniel Walter 		u16 val;
2168e9ecbc5SDaniel Walter 		if (kstrtou16(str + 5, 0, &val) == 0)
21707517529SAtsushi Nemoto 			tx4927_pci_opts.gbwc = val;
21807517529SAtsushi Nemoto 		return NULL;
21907517529SAtsushi Nemoto 	}
22007517529SAtsushi Nemoto 	return str;
22107517529SAtsushi Nemoto }
22207517529SAtsushi Nemoto 
tx4927_pcic_setup(struct tx4927_pcic_reg __iomem * pcicptr,struct pci_controller * channel,int extarb)22389d63fe1SAtsushi Nemoto void __init tx4927_pcic_setup(struct tx4927_pcic_reg __iomem *pcicptr,
22489d63fe1SAtsushi Nemoto 			      struct pci_controller *channel, int extarb)
22589d63fe1SAtsushi Nemoto {
22689d63fe1SAtsushi Nemoto 	int i;
22789d63fe1SAtsushi Nemoto 	unsigned long flags;
22889d63fe1SAtsushi Nemoto 
22989d63fe1SAtsushi Nemoto 	set_tx4927_pcicptr(channel, pcicptr);
23089d63fe1SAtsushi Nemoto 
23189d63fe1SAtsushi Nemoto 	if (!channel->pci_ops)
23289d63fe1SAtsushi Nemoto 		printk(KERN_INFO
23389d63fe1SAtsushi Nemoto 		       "PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:%s\n",
23489d63fe1SAtsushi Nemoto 		       __raw_readl(&pcicptr->pciid) >> 16,
23589d63fe1SAtsushi Nemoto 		       __raw_readl(&pcicptr->pciid) & 0xffff,
23689d63fe1SAtsushi Nemoto 		       __raw_readl(&pcicptr->pciccrev) & 0xff,
23789d63fe1SAtsushi Nemoto 			extarb ? "External" : "Internal");
23889d63fe1SAtsushi Nemoto 	channel->pci_ops = &tx4927_pci_ops;
23989d63fe1SAtsushi Nemoto 
24089d63fe1SAtsushi Nemoto 	local_irq_save(flags);
24189d63fe1SAtsushi Nemoto 
24289d63fe1SAtsushi Nemoto 	/* Disable All Initiator Space */
24389d63fe1SAtsushi Nemoto 	__raw_writel(__raw_readl(&pcicptr->pciccfg)
24489d63fe1SAtsushi Nemoto 		     & ~(TX4927_PCIC_PCICCFG_G2PMEN(0)
24589d63fe1SAtsushi Nemoto 			 | TX4927_PCIC_PCICCFG_G2PMEN(1)
24689d63fe1SAtsushi Nemoto 			 | TX4927_PCIC_PCICCFG_G2PMEN(2)
24789d63fe1SAtsushi Nemoto 			 | TX4927_PCIC_PCICCFG_G2PIOEN),
24889d63fe1SAtsushi Nemoto 		     &pcicptr->pciccfg);
24989d63fe1SAtsushi Nemoto 
25089d63fe1SAtsushi Nemoto 	/* GB->PCI mappings */
25189d63fe1SAtsushi Nemoto 	__raw_writel((channel->io_resource->end - channel->io_resource->start)
25289d63fe1SAtsushi Nemoto 		     >> 4,
25389d63fe1SAtsushi Nemoto 		     &pcicptr->g2piomask);
25489d63fe1SAtsushi Nemoto 	____raw_writeq((channel->io_resource->start +
25589d63fe1SAtsushi Nemoto 			channel->io_map_base - IO_BASE) |
25689d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
25789d63fe1SAtsushi Nemoto 		       TX4927_PCIC_G2PIOGBASE_ECHG
2581da177e4SLinus Torvalds #else
25989d63fe1SAtsushi Nemoto 		       TX4927_PCIC_G2PIOGBASE_BSDIS
2601da177e4SLinus Torvalds #endif
26189d63fe1SAtsushi Nemoto 		       , &pcicptr->g2piogbase);
26289d63fe1SAtsushi Nemoto 	____raw_writeq(channel->io_resource->start - channel->io_offset,
26389d63fe1SAtsushi Nemoto 		       &pcicptr->g2piopbase);
26489d63fe1SAtsushi Nemoto 	for (i = 0; i < 3; i++) {
26589d63fe1SAtsushi Nemoto 		__raw_writel(0, &pcicptr->g2pmmask[i]);
26689d63fe1SAtsushi Nemoto 		____raw_writeq(0, &pcicptr->g2pmgbase[i]);
26789d63fe1SAtsushi Nemoto 		____raw_writeq(0, &pcicptr->g2pmpbase[i]);
26889d63fe1SAtsushi Nemoto 	}
26989d63fe1SAtsushi Nemoto 	if (channel->mem_resource->end) {
27089d63fe1SAtsushi Nemoto 		__raw_writel((channel->mem_resource->end
27189d63fe1SAtsushi Nemoto 			      - channel->mem_resource->start) >> 4,
27289d63fe1SAtsushi Nemoto 			     &pcicptr->g2pmmask[0]);
27389d63fe1SAtsushi Nemoto 		____raw_writeq(channel->mem_resource->start |
27489d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
27589d63fe1SAtsushi Nemoto 			       TX4927_PCIC_G2PMnGBASE_ECHG
27689d63fe1SAtsushi Nemoto #else
27789d63fe1SAtsushi Nemoto 			       TX4927_PCIC_G2PMnGBASE_BSDIS
27889d63fe1SAtsushi Nemoto #endif
27989d63fe1SAtsushi Nemoto 			       , &pcicptr->g2pmgbase[0]);
28089d63fe1SAtsushi Nemoto 		____raw_writeq(channel->mem_resource->start -
28189d63fe1SAtsushi Nemoto 			       channel->mem_offset,
28289d63fe1SAtsushi Nemoto 			       &pcicptr->g2pmpbase[0]);
28389d63fe1SAtsushi Nemoto 	}
28489d63fe1SAtsushi Nemoto 	/* PCI->GB mappings (I/O 256B) */
28589d63fe1SAtsushi Nemoto 	__raw_writel(0, &pcicptr->p2giopbase); /* 256B */
28689d63fe1SAtsushi Nemoto 	____raw_writeq(0, &pcicptr->p2giogbase);
28789d63fe1SAtsushi Nemoto 	/* PCI->GB mappings (MEM 512MB (64MB on R1.x)) */
28889d63fe1SAtsushi Nemoto 	__raw_writel(0, &pcicptr->p2gm0plbase);
28989d63fe1SAtsushi Nemoto 	__raw_writel(0, &pcicptr->p2gm0pubase);
29089d63fe1SAtsushi Nemoto 	____raw_writeq(TX4927_PCIC_P2GMnGBASE_TMEMEN |
29189d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
29289d63fe1SAtsushi Nemoto 		       TX4927_PCIC_P2GMnGBASE_TECHG
29389d63fe1SAtsushi Nemoto #else
29489d63fe1SAtsushi Nemoto 		       TX4927_PCIC_P2GMnGBASE_TBSDIS
29589d63fe1SAtsushi Nemoto #endif
29689d63fe1SAtsushi Nemoto 		       , &pcicptr->p2gmgbase[0]);
29789d63fe1SAtsushi Nemoto 	/* PCI->GB mappings (MEM 16MB) */
29889d63fe1SAtsushi Nemoto 	__raw_writel(0xffffffff, &pcicptr->p2gm1plbase);
29989d63fe1SAtsushi Nemoto 	__raw_writel(0xffffffff, &pcicptr->p2gm1pubase);
30089d63fe1SAtsushi Nemoto 	____raw_writeq(0, &pcicptr->p2gmgbase[1]);
30189d63fe1SAtsushi Nemoto 	/* PCI->GB mappings (MEM 1MB) */
30289d63fe1SAtsushi Nemoto 	__raw_writel(0xffffffff, &pcicptr->p2gm2pbase); /* 1MB */
30389d63fe1SAtsushi Nemoto 	____raw_writeq(0, &pcicptr->p2gmgbase[2]);
30489d63fe1SAtsushi Nemoto 
30589d63fe1SAtsushi Nemoto 	/* Clear all (including IRBER) except for GBWC */
30689d63fe1SAtsushi Nemoto 	__raw_writel((tx4927_pci_opts.gbwc << 16)
30789d63fe1SAtsushi Nemoto 		     & TX4927_PCIC_PCICCFG_GBWC_MASK,
30889d63fe1SAtsushi Nemoto 		     &pcicptr->pciccfg);
30989d63fe1SAtsushi Nemoto 	/* Enable Initiator Memory Space */
31089d63fe1SAtsushi Nemoto 	if (channel->mem_resource->end)
31189d63fe1SAtsushi Nemoto 		__raw_writel(__raw_readl(&pcicptr->pciccfg)
31289d63fe1SAtsushi Nemoto 			     | TX4927_PCIC_PCICCFG_G2PMEN(0),
31389d63fe1SAtsushi Nemoto 			     &pcicptr->pciccfg);
31489d63fe1SAtsushi Nemoto 	/* Enable Initiator I/O Space */
31589d63fe1SAtsushi Nemoto 	if (channel->io_resource->end)
31689d63fe1SAtsushi Nemoto 		__raw_writel(__raw_readl(&pcicptr->pciccfg)
31789d63fe1SAtsushi Nemoto 			     | TX4927_PCIC_PCICCFG_G2PIOEN,
31889d63fe1SAtsushi Nemoto 			     &pcicptr->pciccfg);
31989d63fe1SAtsushi Nemoto 	/* Enable Initiator Config */
32089d63fe1SAtsushi Nemoto 	__raw_writel(__raw_readl(&pcicptr->pciccfg)
32189d63fe1SAtsushi Nemoto 		     | TX4927_PCIC_PCICCFG_ICAEN | TX4927_PCIC_PCICCFG_TCAR,
32289d63fe1SAtsushi Nemoto 		     &pcicptr->pciccfg);
32389d63fe1SAtsushi Nemoto 
32489d63fe1SAtsushi Nemoto 	/* Do not use MEMMUL, MEMINF: YMFPCI card causes M_ABORT. */
32589d63fe1SAtsushi Nemoto 	__raw_writel(0, &pcicptr->pcicfg1);
32689d63fe1SAtsushi Nemoto 
32789d63fe1SAtsushi Nemoto 	__raw_writel((__raw_readl(&pcicptr->g2ptocnt) & ~0xffff)
32889d63fe1SAtsushi Nemoto 		     | (tx4927_pci_opts.trdyto & 0xff)
32989d63fe1SAtsushi Nemoto 		     | ((tx4927_pci_opts.retryto & 0xff) << 8),
33089d63fe1SAtsushi Nemoto 		     &pcicptr->g2ptocnt);
33189d63fe1SAtsushi Nemoto 
33289d63fe1SAtsushi Nemoto 	/* Clear All Local Bus Status */
33389d63fe1SAtsushi Nemoto 	__raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicstatus);
33489d63fe1SAtsushi Nemoto 	/* Enable All Local Bus Interrupts */
33589d63fe1SAtsushi Nemoto 	__raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicmask);
33689d63fe1SAtsushi Nemoto 	/* Clear All Initiator Status */
33789d63fe1SAtsushi Nemoto 	__raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pstatus);
33889d63fe1SAtsushi Nemoto 	/* Enable All Initiator Interrupts */
33989d63fe1SAtsushi Nemoto 	__raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pmask);
34089d63fe1SAtsushi Nemoto 	/* Clear All PCI Status Error */
34189d63fe1SAtsushi Nemoto 	__raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
34289d63fe1SAtsushi Nemoto 		     | (TX4927_PCIC_PCISTATUS_ALL << 16),
34389d63fe1SAtsushi Nemoto 		     &pcicptr->pcistatus);
34489d63fe1SAtsushi Nemoto 	/* Enable All PCI Status Error Interrupts */
34589d63fe1SAtsushi Nemoto 	__raw_writel(TX4927_PCIC_PCISTATUS_ALL, &pcicptr->pcimask);
34689d63fe1SAtsushi Nemoto 
34789d63fe1SAtsushi Nemoto 	if (!extarb) {
34889d63fe1SAtsushi Nemoto 		/* Reset Bus Arbiter */
34989d63fe1SAtsushi Nemoto 		__raw_writel(TX4927_PCIC_PBACFG_RPBA, &pcicptr->pbacfg);
35089d63fe1SAtsushi Nemoto 		__raw_writel(0, &pcicptr->pbabm);
35189d63fe1SAtsushi Nemoto 		/* Enable Bus Arbiter */
35289d63fe1SAtsushi Nemoto 		__raw_writel(TX4927_PCIC_PBACFG_PBAEN, &pcicptr->pbacfg);
3531da177e4SLinus Torvalds 	}
3541da177e4SLinus Torvalds 
35589d63fe1SAtsushi Nemoto 	__raw_writel(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
35689d63fe1SAtsushi Nemoto 		     | PCI_COMMAND_PARITY | PCI_COMMAND_SERR,
35789d63fe1SAtsushi Nemoto 		     &pcicptr->pcistatus);
35889d63fe1SAtsushi Nemoto 	local_irq_restore(flags);
35989d63fe1SAtsushi Nemoto 
36089d63fe1SAtsushi Nemoto 	printk(KERN_DEBUG
36189d63fe1SAtsushi Nemoto 	       "PCI: COMMAND=%04x,PCIMASK=%04x,"
36289d63fe1SAtsushi Nemoto 	       "TRDYTO=%02x,RETRYTO=%02x,GBWC=%03x\n",
36389d63fe1SAtsushi Nemoto 	       __raw_readl(&pcicptr->pcistatus) & 0xffff,
36489d63fe1SAtsushi Nemoto 	       __raw_readl(&pcicptr->pcimask) & 0xffff,
36589d63fe1SAtsushi Nemoto 	       __raw_readl(&pcicptr->g2ptocnt) & 0xff,
36689d63fe1SAtsushi Nemoto 	       (__raw_readl(&pcicptr->g2ptocnt) & 0xff00) >> 8,
36789d63fe1SAtsushi Nemoto 	       (__raw_readl(&pcicptr->pciccfg) >> 16) & 0xfff);
3681da177e4SLinus Torvalds }
3691da177e4SLinus Torvalds 
tx4927_report_pcic_status1(struct tx4927_pcic_reg __iomem * pcicptr)37089d63fe1SAtsushi Nemoto static void tx4927_report_pcic_status1(struct tx4927_pcic_reg __iomem *pcicptr)
37189d63fe1SAtsushi Nemoto {
37289d63fe1SAtsushi Nemoto 	__u16 pcistatus = (__u16)(__raw_readl(&pcicptr->pcistatus) >> 16);
37389d63fe1SAtsushi Nemoto 	__u32 g2pstatus = __raw_readl(&pcicptr->g2pstatus);
37489d63fe1SAtsushi Nemoto 	__u32 pcicstatus = __raw_readl(&pcicptr->pcicstatus);
37589d63fe1SAtsushi Nemoto 	static struct {
37689d63fe1SAtsushi Nemoto 		__u32 flag;
37789d63fe1SAtsushi Nemoto 		const char *str;
37889d63fe1SAtsushi Nemoto 	} pcistat_tbl[] = {
37989d63fe1SAtsushi Nemoto 		{ PCI_STATUS_DETECTED_PARITY,	"DetectedParityError" },
38089d63fe1SAtsushi Nemoto 		{ PCI_STATUS_SIG_SYSTEM_ERROR,	"SignaledSystemError" },
38189d63fe1SAtsushi Nemoto 		{ PCI_STATUS_REC_MASTER_ABORT,	"ReceivedMasterAbort" },
38289d63fe1SAtsushi Nemoto 		{ PCI_STATUS_REC_TARGET_ABORT,	"ReceivedTargetAbort" },
38389d63fe1SAtsushi Nemoto 		{ PCI_STATUS_SIG_TARGET_ABORT,	"SignaledTargetAbort" },
38489d63fe1SAtsushi Nemoto 		{ PCI_STATUS_PARITY,	"MasterParityError" },
38589d63fe1SAtsushi Nemoto 	}, g2pstat_tbl[] = {
38689d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_G2PSTATUS_TTOE,	"TIOE" },
38789d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_G2PSTATUS_RTOE,	"RTOE" },
38889d63fe1SAtsushi Nemoto 	}, pcicstat_tbl[] = {
38989d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_PCICSTATUS_PME,	"PME" },
39089d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_PCICSTATUS_TLB,	"TLB" },
39189d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_PCICSTATUS_NIB,	"NIB" },
39289d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_PCICSTATUS_ZIB,	"ZIB" },
39389d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_PCICSTATUS_PERR,	"PERR" },
39489d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_PCICSTATUS_SERR,	"SERR" },
39589d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_PCICSTATUS_GBE,	"GBE" },
39689d63fe1SAtsushi Nemoto 		{ TX4927_PCIC_PCICSTATUS_IWB,	"IWB" },
3971da177e4SLinus Torvalds 	};
39889d63fe1SAtsushi Nemoto 	int i, cont;
3991da177e4SLinus Torvalds 
40089d63fe1SAtsushi Nemoto 	printk(KERN_ERR "");
40189d63fe1SAtsushi Nemoto 	if (pcistatus & TX4927_PCIC_PCISTATUS_ALL) {
40289d63fe1SAtsushi Nemoto 		printk(KERN_CONT "pcistat:%04x(", pcistatus);
40389d63fe1SAtsushi Nemoto 		for (i = 0, cont = 0; i < ARRAY_SIZE(pcistat_tbl); i++)
40489d63fe1SAtsushi Nemoto 			if (pcistatus & pcistat_tbl[i].flag)
40589d63fe1SAtsushi Nemoto 				printk(KERN_CONT "%s%s",
40689d63fe1SAtsushi Nemoto 				       cont++ ? " " : "", pcistat_tbl[i].str);
40789d63fe1SAtsushi Nemoto 		printk(KERN_CONT ") ");
40889d63fe1SAtsushi Nemoto 	}
40989d63fe1SAtsushi Nemoto 	if (g2pstatus & TX4927_PCIC_G2PSTATUS_ALL) {
41089d63fe1SAtsushi Nemoto 		printk(KERN_CONT "g2pstatus:%08x(", g2pstatus);
41189d63fe1SAtsushi Nemoto 		for (i = 0, cont = 0; i < ARRAY_SIZE(g2pstat_tbl); i++)
41289d63fe1SAtsushi Nemoto 			if (g2pstatus & g2pstat_tbl[i].flag)
41389d63fe1SAtsushi Nemoto 				printk(KERN_CONT "%s%s",
41489d63fe1SAtsushi Nemoto 				       cont++ ? " " : "", g2pstat_tbl[i].str);
41589d63fe1SAtsushi Nemoto 		printk(KERN_CONT ") ");
41689d63fe1SAtsushi Nemoto 	}
41789d63fe1SAtsushi Nemoto 	if (pcicstatus & TX4927_PCIC_PCICSTATUS_ALL) {
41889d63fe1SAtsushi Nemoto 		printk(KERN_CONT "pcicstatus:%08x(", pcicstatus);
41989d63fe1SAtsushi Nemoto 		for (i = 0, cont = 0; i < ARRAY_SIZE(pcicstat_tbl); i++)
42089d63fe1SAtsushi Nemoto 			if (pcicstatus & pcicstat_tbl[i].flag)
42189d63fe1SAtsushi Nemoto 				printk(KERN_CONT "%s%s",
42289d63fe1SAtsushi Nemoto 				       cont++ ? " " : "", pcicstat_tbl[i].str);
42389d63fe1SAtsushi Nemoto 		printk(KERN_CONT ")");
42489d63fe1SAtsushi Nemoto 	}
42589d63fe1SAtsushi Nemoto 	printk(KERN_CONT "\n");
42689d63fe1SAtsushi Nemoto }
42789d63fe1SAtsushi Nemoto 
tx4927_report_pcic_status(void)42889d63fe1SAtsushi Nemoto void tx4927_report_pcic_status(void)
42989d63fe1SAtsushi Nemoto {
43089d63fe1SAtsushi Nemoto 	int i;
43189d63fe1SAtsushi Nemoto 
43289d63fe1SAtsushi Nemoto 	for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
43389d63fe1SAtsushi Nemoto 		if (pcicptrs[i].pcicptr)
43489d63fe1SAtsushi Nemoto 			tx4927_report_pcic_status1(pcicptrs[i].pcicptr);
43589d63fe1SAtsushi Nemoto 	}
43689d63fe1SAtsushi Nemoto }
43732d00d0fSAtsushi Nemoto 
tx4927_dump_pcic_settings1(struct tx4927_pcic_reg __iomem * pcicptr)438455cc256SAtsushi Nemoto static void tx4927_dump_pcic_settings1(struct tx4927_pcic_reg __iomem *pcicptr)
439455cc256SAtsushi Nemoto {
440455cc256SAtsushi Nemoto 	int i;
441455cc256SAtsushi Nemoto 	__u32 __iomem *preg = (__u32 __iomem *)pcicptr;
442455cc256SAtsushi Nemoto 
443455cc256SAtsushi Nemoto 	printk(KERN_INFO "tx4927 pcic (0x%p) settings:", pcicptr);
444455cc256SAtsushi Nemoto 	for (i = 0; i < sizeof(struct tx4927_pcic_reg); i += 4, preg++) {
445455cc256SAtsushi Nemoto 		if (i % 32 == 0) {
446455cc256SAtsushi Nemoto 			printk(KERN_CONT "\n");
447455cc256SAtsushi Nemoto 			printk(KERN_INFO "%04x:", i);
448455cc256SAtsushi Nemoto 		}
449455cc256SAtsushi Nemoto 		/* skip registers with side-effects */
450455cc256SAtsushi Nemoto 		if (i == offsetof(struct tx4927_pcic_reg, g2pintack)
451455cc256SAtsushi Nemoto 		    || i == offsetof(struct tx4927_pcic_reg, g2pspc)
452455cc256SAtsushi Nemoto 		    || i == offsetof(struct tx4927_pcic_reg, g2pcfgadrs)
453455cc256SAtsushi Nemoto 		    || i == offsetof(struct tx4927_pcic_reg, g2pcfgdata)) {
454455cc256SAtsushi Nemoto 			printk(KERN_CONT " XXXXXXXX");
455455cc256SAtsushi Nemoto 			continue;
456455cc256SAtsushi Nemoto 		}
457455cc256SAtsushi Nemoto 		printk(KERN_CONT " %08x", __raw_readl(preg));
458455cc256SAtsushi Nemoto 	}
459455cc256SAtsushi Nemoto 	printk(KERN_CONT "\n");
460455cc256SAtsushi Nemoto }
461455cc256SAtsushi Nemoto 
tx4927_dump_pcic_settings(void)462455cc256SAtsushi Nemoto void tx4927_dump_pcic_settings(void)
463455cc256SAtsushi Nemoto {
464455cc256SAtsushi Nemoto 	int i;
465455cc256SAtsushi Nemoto 
466455cc256SAtsushi Nemoto 	for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
467455cc256SAtsushi Nemoto 		if (pcicptrs[i].pcicptr)
468455cc256SAtsushi Nemoto 			tx4927_dump_pcic_settings1(pcicptrs[i].pcicptr);
469455cc256SAtsushi Nemoto 	}
470455cc256SAtsushi Nemoto }
471455cc256SAtsushi Nemoto 
tx4927_pcierr_interrupt(int irq,void * dev_id)472455cc256SAtsushi Nemoto irqreturn_t tx4927_pcierr_interrupt(int irq, void *dev_id)
473455cc256SAtsushi Nemoto {
474455cc256SAtsushi Nemoto 	struct pt_regs *regs = get_irq_regs();
475455cc256SAtsushi Nemoto 	struct tx4927_pcic_reg __iomem *pcicptr =
476455cc256SAtsushi Nemoto 		(struct tx4927_pcic_reg __iomem *)(unsigned long)dev_id;
477455cc256SAtsushi Nemoto 
478455cc256SAtsushi Nemoto 	if (txx9_pci_err_action != TXX9_PCI_ERR_IGNORE) {
479455cc256SAtsushi Nemoto 		printk(KERN_WARNING "PCIERR interrupt at 0x%0*lx\n",
480455cc256SAtsushi Nemoto 		       (int)(2 * sizeof(unsigned long)), regs->cp0_epc);
481455cc256SAtsushi Nemoto 		tx4927_report_pcic_status1(pcicptr);
482455cc256SAtsushi Nemoto 	}
483455cc256SAtsushi Nemoto 	if (txx9_pci_err_action != TXX9_PCI_ERR_PANIC) {
484455cc256SAtsushi Nemoto 		/* clear all pci errors */
485455cc256SAtsushi Nemoto 		__raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
486455cc256SAtsushi Nemoto 			     | (TX4927_PCIC_PCISTATUS_ALL << 16),
487455cc256SAtsushi Nemoto 			     &pcicptr->pcistatus);
488455cc256SAtsushi Nemoto 		__raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pstatus);
489455cc256SAtsushi Nemoto 		__raw_writel(TX4927_PCIC_PBASTATUS_ALL, &pcicptr->pbastatus);
490455cc256SAtsushi Nemoto 		__raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicstatus);
491455cc256SAtsushi Nemoto 		return IRQ_HANDLED;
492455cc256SAtsushi Nemoto 	}
493455cc256SAtsushi Nemoto 	console_verbose();
494455cc256SAtsushi Nemoto 	tx4927_dump_pcic_settings1(pcicptr);
495455cc256SAtsushi Nemoto 	panic("PCI error.");
496455cc256SAtsushi Nemoto }
497455cc256SAtsushi Nemoto 
49832d00d0fSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_FPCIB0
tx4927_quirk_slc90e66_bridge(struct pci_dev * dev)49928eb0e46SGreg Kroah-Hartman static void tx4927_quirk_slc90e66_bridge(struct pci_dev *dev)
50032d00d0fSAtsushi Nemoto {
50132d00d0fSAtsushi Nemoto 	struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(dev->bus);
50232d00d0fSAtsushi Nemoto 
50332d00d0fSAtsushi Nemoto 	if (!pcicptr)
50432d00d0fSAtsushi Nemoto 		return;
50532d00d0fSAtsushi Nemoto 	if (__raw_readl(&pcicptr->pbacfg) & TX4927_PCIC_PBACFG_PBAEN) {
50632d00d0fSAtsushi Nemoto 		/* Reset Bus Arbiter */
50732d00d0fSAtsushi Nemoto 		__raw_writel(TX4927_PCIC_PBACFG_RPBA, &pcicptr->pbacfg);
50832d00d0fSAtsushi Nemoto 		/*
50932d00d0fSAtsushi Nemoto 		 * swap reqBP and reqXP (raise priority of SLC90E66).
51032d00d0fSAtsushi Nemoto 		 * SLC90E66(PCI-ISA bridge) is connected to REQ2 on
51132d00d0fSAtsushi Nemoto 		 * PCI Backplane board.
51232d00d0fSAtsushi Nemoto 		 */
51332d00d0fSAtsushi Nemoto 		__raw_writel(0x72543610, &pcicptr->pbareqport);
51432d00d0fSAtsushi Nemoto 		__raw_writel(0, &pcicptr->pbabm);
51532d00d0fSAtsushi Nemoto 		/* Use Fixed ParkMaster (required by SLC90E66) */
51632d00d0fSAtsushi Nemoto 		__raw_writel(TX4927_PCIC_PBACFG_FIXPA, &pcicptr->pbacfg);
51732d00d0fSAtsushi Nemoto 		/* Enable Bus Arbiter */
51832d00d0fSAtsushi Nemoto 		__raw_writel(TX4927_PCIC_PBACFG_FIXPA |
51932d00d0fSAtsushi Nemoto 			     TX4927_PCIC_PBACFG_PBAEN,
52032d00d0fSAtsushi Nemoto 			     &pcicptr->pbacfg);
52132d00d0fSAtsushi Nemoto 		printk(KERN_INFO "PCI: Use Fixed Park Master (REQPORT %08x)\n",
52232d00d0fSAtsushi Nemoto 		       __raw_readl(&pcicptr->pbareqport));
52332d00d0fSAtsushi Nemoto 	}
52432d00d0fSAtsushi Nemoto }
52532d00d0fSAtsushi Nemoto #define PCI_DEVICE_ID_EFAR_SLC90E66_0 0x9460
52632d00d0fSAtsushi Nemoto DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_0,
52732d00d0fSAtsushi Nemoto 	tx4927_quirk_slc90e66_bridge);
52832d00d0fSAtsushi Nemoto #endif
529