1*2874c5fdSThomas 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))
6389d63fe1SAtsushi Nemoto return -1;
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);
721da177e4SLinus Torvalds return 0;
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);
14389d63fe1SAtsushi Nemoto
14489d63fe1SAtsushi Nemoto if (mkaddr(bus, devfn, where, pcicptr)) {
1451da177e4SLinus Torvalds *val = 0xffffffff;
1461da177e4SLinus Torvalds return -1;
14789d63fe1SAtsushi Nemoto }
1481da177e4SLinus Torvalds switch (size) {
1491da177e4SLinus Torvalds case 1:
15089d63fe1SAtsushi Nemoto *val = icd_readb(where & 3, pcicptr);
1511da177e4SLinus Torvalds break;
1521da177e4SLinus Torvalds case 2:
15389d63fe1SAtsushi Nemoto *val = icd_readw(where & 3, pcicptr);
15489d63fe1SAtsushi Nemoto break;
15589d63fe1SAtsushi Nemoto default:
15689d63fe1SAtsushi Nemoto *val = icd_readl(pcicptr);
15789d63fe1SAtsushi Nemoto }
15889d63fe1SAtsushi Nemoto return check_abort(pcicptr);
15989d63fe1SAtsushi Nemoto }
16089d63fe1SAtsushi Nemoto
tx4927_pci_config_write(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 val)16189d63fe1SAtsushi Nemoto static int tx4927_pci_config_write(struct pci_bus *bus, unsigned int devfn,
16289d63fe1SAtsushi Nemoto int where, int size, u32 val)
16389d63fe1SAtsushi Nemoto {
16489d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(bus);
16589d63fe1SAtsushi Nemoto
16689d63fe1SAtsushi Nemoto if (mkaddr(bus, devfn, where, pcicptr))
16789d63fe1SAtsushi Nemoto return -1;
16889d63fe1SAtsushi Nemoto switch (size) {
16989d63fe1SAtsushi Nemoto case 1:
17089d63fe1SAtsushi Nemoto icd_writeb(val, where & 3, pcicptr);
17189d63fe1SAtsushi Nemoto break;
17289d63fe1SAtsushi Nemoto case 2:
17389d63fe1SAtsushi Nemoto icd_writew(val, where & 3, pcicptr);
17489d63fe1SAtsushi Nemoto break;
17589d63fe1SAtsushi Nemoto default:
17689d63fe1SAtsushi Nemoto icd_writel(val, pcicptr);
17789d63fe1SAtsushi Nemoto }
17889d63fe1SAtsushi Nemoto return check_abort(pcicptr);
17989d63fe1SAtsushi Nemoto }
18089d63fe1SAtsushi Nemoto
18189d63fe1SAtsushi Nemoto static struct pci_ops tx4927_pci_ops = {
18289d63fe1SAtsushi Nemoto .read = tx4927_pci_config_read,
18389d63fe1SAtsushi Nemoto .write = tx4927_pci_config_write,
18489d63fe1SAtsushi Nemoto };
18589d63fe1SAtsushi Nemoto
18689d63fe1SAtsushi Nemoto static struct {
18789d63fe1SAtsushi Nemoto u8 trdyto;
18889d63fe1SAtsushi Nemoto u8 retryto;
18989d63fe1SAtsushi Nemoto u16 gbwc;
19028eb0e46SGreg Kroah-Hartman } tx4927_pci_opts = {
19189d63fe1SAtsushi Nemoto .trdyto = 0,
19289d63fe1SAtsushi Nemoto .retryto = 0,
19389d63fe1SAtsushi Nemoto .gbwc = 0xfe0, /* 4064 GBUSCLK for CCFG.GTOT=0b11 */
19489d63fe1SAtsushi Nemoto };
19589d63fe1SAtsushi Nemoto
tx4927_pcibios_setup(char * str)19628eb0e46SGreg Kroah-Hartman char *tx4927_pcibios_setup(char *str)
19707517529SAtsushi Nemoto {
19807517529SAtsushi Nemoto if (!strncmp(str, "trdyto=", 7)) {
1998e9ecbc5SDaniel Walter u8 val = 0;
2008e9ecbc5SDaniel Walter if (kstrtou8(str + 7, 0, &val) == 0)
20107517529SAtsushi Nemoto tx4927_pci_opts.trdyto = val;
20207517529SAtsushi Nemoto return NULL;
20307517529SAtsushi Nemoto }
20407517529SAtsushi Nemoto if (!strncmp(str, "retryto=", 8)) {
2058e9ecbc5SDaniel Walter u8 val = 0;
2068e9ecbc5SDaniel Walter if (kstrtou8(str + 8, 0, &val) == 0)
20707517529SAtsushi Nemoto tx4927_pci_opts.retryto = val;
20807517529SAtsushi Nemoto return NULL;
20907517529SAtsushi Nemoto }
21007517529SAtsushi Nemoto if (!strncmp(str, "gbwc=", 5)) {
2118e9ecbc5SDaniel Walter u16 val;
2128e9ecbc5SDaniel Walter if (kstrtou16(str + 5, 0, &val) == 0)
21307517529SAtsushi Nemoto tx4927_pci_opts.gbwc = val;
21407517529SAtsushi Nemoto return NULL;
21507517529SAtsushi Nemoto }
21607517529SAtsushi Nemoto return str;
21707517529SAtsushi Nemoto }
21807517529SAtsushi Nemoto
tx4927_pcic_setup(struct tx4927_pcic_reg __iomem * pcicptr,struct pci_controller * channel,int extarb)21989d63fe1SAtsushi Nemoto void __init tx4927_pcic_setup(struct tx4927_pcic_reg __iomem *pcicptr,
22089d63fe1SAtsushi Nemoto struct pci_controller *channel, int extarb)
22189d63fe1SAtsushi Nemoto {
22289d63fe1SAtsushi Nemoto int i;
22389d63fe1SAtsushi Nemoto unsigned long flags;
22489d63fe1SAtsushi Nemoto
22589d63fe1SAtsushi Nemoto set_tx4927_pcicptr(channel, pcicptr);
22689d63fe1SAtsushi Nemoto
22789d63fe1SAtsushi Nemoto if (!channel->pci_ops)
22889d63fe1SAtsushi Nemoto printk(KERN_INFO
22989d63fe1SAtsushi Nemoto "PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:%s\n",
23089d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pciid) >> 16,
23189d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pciid) & 0xffff,
23289d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pciccrev) & 0xff,
23389d63fe1SAtsushi Nemoto extarb ? "External" : "Internal");
23489d63fe1SAtsushi Nemoto channel->pci_ops = &tx4927_pci_ops;
23589d63fe1SAtsushi Nemoto
23689d63fe1SAtsushi Nemoto local_irq_save(flags);
23789d63fe1SAtsushi Nemoto
23889d63fe1SAtsushi Nemoto /* Disable All Initiator Space */
23989d63fe1SAtsushi Nemoto __raw_writel(__raw_readl(&pcicptr->pciccfg)
24089d63fe1SAtsushi Nemoto & ~(TX4927_PCIC_PCICCFG_G2PMEN(0)
24189d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PMEN(1)
24289d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PMEN(2)
24389d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PIOEN),
24489d63fe1SAtsushi Nemoto &pcicptr->pciccfg);
24589d63fe1SAtsushi Nemoto
24689d63fe1SAtsushi Nemoto /* GB->PCI mappings */
24789d63fe1SAtsushi Nemoto __raw_writel((channel->io_resource->end - channel->io_resource->start)
24889d63fe1SAtsushi Nemoto >> 4,
24989d63fe1SAtsushi Nemoto &pcicptr->g2piomask);
25089d63fe1SAtsushi Nemoto ____raw_writeq((channel->io_resource->start +
25189d63fe1SAtsushi Nemoto channel->io_map_base - IO_BASE) |
25289d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
25389d63fe1SAtsushi Nemoto TX4927_PCIC_G2PIOGBASE_ECHG
2541da177e4SLinus Torvalds #else
25589d63fe1SAtsushi Nemoto TX4927_PCIC_G2PIOGBASE_BSDIS
2561da177e4SLinus Torvalds #endif
25789d63fe1SAtsushi Nemoto , &pcicptr->g2piogbase);
25889d63fe1SAtsushi Nemoto ____raw_writeq(channel->io_resource->start - channel->io_offset,
25989d63fe1SAtsushi Nemoto &pcicptr->g2piopbase);
26089d63fe1SAtsushi Nemoto for (i = 0; i < 3; i++) {
26189d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->g2pmmask[i]);
26289d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->g2pmgbase[i]);
26389d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->g2pmpbase[i]);
26489d63fe1SAtsushi Nemoto }
26589d63fe1SAtsushi Nemoto if (channel->mem_resource->end) {
26689d63fe1SAtsushi Nemoto __raw_writel((channel->mem_resource->end
26789d63fe1SAtsushi Nemoto - channel->mem_resource->start) >> 4,
26889d63fe1SAtsushi Nemoto &pcicptr->g2pmmask[0]);
26989d63fe1SAtsushi Nemoto ____raw_writeq(channel->mem_resource->start |
27089d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
27189d63fe1SAtsushi Nemoto TX4927_PCIC_G2PMnGBASE_ECHG
27289d63fe1SAtsushi Nemoto #else
27389d63fe1SAtsushi Nemoto TX4927_PCIC_G2PMnGBASE_BSDIS
27489d63fe1SAtsushi Nemoto #endif
27589d63fe1SAtsushi Nemoto , &pcicptr->g2pmgbase[0]);
27689d63fe1SAtsushi Nemoto ____raw_writeq(channel->mem_resource->start -
27789d63fe1SAtsushi Nemoto channel->mem_offset,
27889d63fe1SAtsushi Nemoto &pcicptr->g2pmpbase[0]);
27989d63fe1SAtsushi Nemoto }
28089d63fe1SAtsushi Nemoto /* PCI->GB mappings (I/O 256B) */
28189d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->p2giopbase); /* 256B */
28289d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->p2giogbase);
28389d63fe1SAtsushi Nemoto /* PCI->GB mappings (MEM 512MB (64MB on R1.x)) */
28489d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->p2gm0plbase);
28589d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->p2gm0pubase);
28689d63fe1SAtsushi Nemoto ____raw_writeq(TX4927_PCIC_P2GMnGBASE_TMEMEN |
28789d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN
28889d63fe1SAtsushi Nemoto TX4927_PCIC_P2GMnGBASE_TECHG
28989d63fe1SAtsushi Nemoto #else
29089d63fe1SAtsushi Nemoto TX4927_PCIC_P2GMnGBASE_TBSDIS
29189d63fe1SAtsushi Nemoto #endif
29289d63fe1SAtsushi Nemoto , &pcicptr->p2gmgbase[0]);
29389d63fe1SAtsushi Nemoto /* PCI->GB mappings (MEM 16MB) */
29489d63fe1SAtsushi Nemoto __raw_writel(0xffffffff, &pcicptr->p2gm1plbase);
29589d63fe1SAtsushi Nemoto __raw_writel(0xffffffff, &pcicptr->p2gm1pubase);
29689d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->p2gmgbase[1]);
29789d63fe1SAtsushi Nemoto /* PCI->GB mappings (MEM 1MB) */
29889d63fe1SAtsushi Nemoto __raw_writel(0xffffffff, &pcicptr->p2gm2pbase); /* 1MB */
29989d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->p2gmgbase[2]);
30089d63fe1SAtsushi Nemoto
30189d63fe1SAtsushi Nemoto /* Clear all (including IRBER) except for GBWC */
30289d63fe1SAtsushi Nemoto __raw_writel((tx4927_pci_opts.gbwc << 16)
30389d63fe1SAtsushi Nemoto & TX4927_PCIC_PCICCFG_GBWC_MASK,
30489d63fe1SAtsushi Nemoto &pcicptr->pciccfg);
30589d63fe1SAtsushi Nemoto /* Enable Initiator Memory Space */
30689d63fe1SAtsushi Nemoto if (channel->mem_resource->end)
30789d63fe1SAtsushi Nemoto __raw_writel(__raw_readl(&pcicptr->pciccfg)
30889d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PMEN(0),
30989d63fe1SAtsushi Nemoto &pcicptr->pciccfg);
31089d63fe1SAtsushi Nemoto /* Enable Initiator I/O Space */
31189d63fe1SAtsushi Nemoto if (channel->io_resource->end)
31289d63fe1SAtsushi Nemoto __raw_writel(__raw_readl(&pcicptr->pciccfg)
31389d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PIOEN,
31489d63fe1SAtsushi Nemoto &pcicptr->pciccfg);
31589d63fe1SAtsushi Nemoto /* Enable Initiator Config */
31689d63fe1SAtsushi Nemoto __raw_writel(__raw_readl(&pcicptr->pciccfg)
31789d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_ICAEN | TX4927_PCIC_PCICCFG_TCAR,
31889d63fe1SAtsushi Nemoto &pcicptr->pciccfg);
31989d63fe1SAtsushi Nemoto
32089d63fe1SAtsushi Nemoto /* Do not use MEMMUL, MEMINF: YMFPCI card causes M_ABORT. */
32189d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->pcicfg1);
32289d63fe1SAtsushi Nemoto
32389d63fe1SAtsushi Nemoto __raw_writel((__raw_readl(&pcicptr->g2ptocnt) & ~0xffff)
32489d63fe1SAtsushi Nemoto | (tx4927_pci_opts.trdyto & 0xff)
32589d63fe1SAtsushi Nemoto | ((tx4927_pci_opts.retryto & 0xff) << 8),
32689d63fe1SAtsushi Nemoto &pcicptr->g2ptocnt);
32789d63fe1SAtsushi Nemoto
32889d63fe1SAtsushi Nemoto /* Clear All Local Bus Status */
32989d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicstatus);
33089d63fe1SAtsushi Nemoto /* Enable All Local Bus Interrupts */
33189d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicmask);
33289d63fe1SAtsushi Nemoto /* Clear All Initiator Status */
33389d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pstatus);
33489d63fe1SAtsushi Nemoto /* Enable All Initiator Interrupts */
33589d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pmask);
33689d63fe1SAtsushi Nemoto /* Clear All PCI Status Error */
33789d63fe1SAtsushi Nemoto __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
33889d63fe1SAtsushi Nemoto | (TX4927_PCIC_PCISTATUS_ALL << 16),
33989d63fe1SAtsushi Nemoto &pcicptr->pcistatus);
34089d63fe1SAtsushi Nemoto /* Enable All PCI Status Error Interrupts */
34189d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PCISTATUS_ALL, &pcicptr->pcimask);
34289d63fe1SAtsushi Nemoto
34389d63fe1SAtsushi Nemoto if (!extarb) {
34489d63fe1SAtsushi Nemoto /* Reset Bus Arbiter */
34589d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_RPBA, &pcicptr->pbacfg);
34689d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->pbabm);
34789d63fe1SAtsushi Nemoto /* Enable Bus Arbiter */
34889d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_PBAEN, &pcicptr->pbacfg);
3491da177e4SLinus Torvalds }
3501da177e4SLinus Torvalds
35189d63fe1SAtsushi Nemoto __raw_writel(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
35289d63fe1SAtsushi Nemoto | PCI_COMMAND_PARITY | PCI_COMMAND_SERR,
35389d63fe1SAtsushi Nemoto &pcicptr->pcistatus);
35489d63fe1SAtsushi Nemoto local_irq_restore(flags);
35589d63fe1SAtsushi Nemoto
35689d63fe1SAtsushi Nemoto printk(KERN_DEBUG
35789d63fe1SAtsushi Nemoto "PCI: COMMAND=%04x,PCIMASK=%04x,"
35889d63fe1SAtsushi Nemoto "TRDYTO=%02x,RETRYTO=%02x,GBWC=%03x\n",
35989d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pcistatus) & 0xffff,
36089d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pcimask) & 0xffff,
36189d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->g2ptocnt) & 0xff,
36289d63fe1SAtsushi Nemoto (__raw_readl(&pcicptr->g2ptocnt) & 0xff00) >> 8,
36389d63fe1SAtsushi Nemoto (__raw_readl(&pcicptr->pciccfg) >> 16) & 0xfff);
3641da177e4SLinus Torvalds }
3651da177e4SLinus Torvalds
tx4927_report_pcic_status1(struct tx4927_pcic_reg __iomem * pcicptr)36689d63fe1SAtsushi Nemoto static void tx4927_report_pcic_status1(struct tx4927_pcic_reg __iomem *pcicptr)
36789d63fe1SAtsushi Nemoto {
36889d63fe1SAtsushi Nemoto __u16 pcistatus = (__u16)(__raw_readl(&pcicptr->pcistatus) >> 16);
36989d63fe1SAtsushi Nemoto __u32 g2pstatus = __raw_readl(&pcicptr->g2pstatus);
37089d63fe1SAtsushi Nemoto __u32 pcicstatus = __raw_readl(&pcicptr->pcicstatus);
37189d63fe1SAtsushi Nemoto static struct {
37289d63fe1SAtsushi Nemoto __u32 flag;
37389d63fe1SAtsushi Nemoto const char *str;
37489d63fe1SAtsushi Nemoto } pcistat_tbl[] = {
37589d63fe1SAtsushi Nemoto { PCI_STATUS_DETECTED_PARITY, "DetectedParityError" },
37689d63fe1SAtsushi Nemoto { PCI_STATUS_SIG_SYSTEM_ERROR, "SignaledSystemError" },
37789d63fe1SAtsushi Nemoto { PCI_STATUS_REC_MASTER_ABORT, "ReceivedMasterAbort" },
37889d63fe1SAtsushi Nemoto { PCI_STATUS_REC_TARGET_ABORT, "ReceivedTargetAbort" },
37989d63fe1SAtsushi Nemoto { PCI_STATUS_SIG_TARGET_ABORT, "SignaledTargetAbort" },
38089d63fe1SAtsushi Nemoto { PCI_STATUS_PARITY, "MasterParityError" },
38189d63fe1SAtsushi Nemoto }, g2pstat_tbl[] = {
38289d63fe1SAtsushi Nemoto { TX4927_PCIC_G2PSTATUS_TTOE, "TIOE" },
38389d63fe1SAtsushi Nemoto { TX4927_PCIC_G2PSTATUS_RTOE, "RTOE" },
38489d63fe1SAtsushi Nemoto }, pcicstat_tbl[] = {
38589d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_PME, "PME" },
38689d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_TLB, "TLB" },
38789d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_NIB, "NIB" },
38889d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_ZIB, "ZIB" },
38989d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_PERR, "PERR" },
39089d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_SERR, "SERR" },
39189d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_GBE, "GBE" },
39289d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_IWB, "IWB" },
3931da177e4SLinus Torvalds };
39489d63fe1SAtsushi Nemoto int i, cont;
3951da177e4SLinus Torvalds
39689d63fe1SAtsushi Nemoto printk(KERN_ERR "");
39789d63fe1SAtsushi Nemoto if (pcistatus & TX4927_PCIC_PCISTATUS_ALL) {
39889d63fe1SAtsushi Nemoto printk(KERN_CONT "pcistat:%04x(", pcistatus);
39989d63fe1SAtsushi Nemoto for (i = 0, cont = 0; i < ARRAY_SIZE(pcistat_tbl); i++)
40089d63fe1SAtsushi Nemoto if (pcistatus & pcistat_tbl[i].flag)
40189d63fe1SAtsushi Nemoto printk(KERN_CONT "%s%s",
40289d63fe1SAtsushi Nemoto cont++ ? " " : "", pcistat_tbl[i].str);
40389d63fe1SAtsushi Nemoto printk(KERN_CONT ") ");
40489d63fe1SAtsushi Nemoto }
40589d63fe1SAtsushi Nemoto if (g2pstatus & TX4927_PCIC_G2PSTATUS_ALL) {
40689d63fe1SAtsushi Nemoto printk(KERN_CONT "g2pstatus:%08x(", g2pstatus);
40789d63fe1SAtsushi Nemoto for (i = 0, cont = 0; i < ARRAY_SIZE(g2pstat_tbl); i++)
40889d63fe1SAtsushi Nemoto if (g2pstatus & g2pstat_tbl[i].flag)
40989d63fe1SAtsushi Nemoto printk(KERN_CONT "%s%s",
41089d63fe1SAtsushi Nemoto cont++ ? " " : "", g2pstat_tbl[i].str);
41189d63fe1SAtsushi Nemoto printk(KERN_CONT ") ");
41289d63fe1SAtsushi Nemoto }
41389d63fe1SAtsushi Nemoto if (pcicstatus & TX4927_PCIC_PCICSTATUS_ALL) {
41489d63fe1SAtsushi Nemoto printk(KERN_CONT "pcicstatus:%08x(", pcicstatus);
41589d63fe1SAtsushi Nemoto for (i = 0, cont = 0; i < ARRAY_SIZE(pcicstat_tbl); i++)
41689d63fe1SAtsushi Nemoto if (pcicstatus & pcicstat_tbl[i].flag)
41789d63fe1SAtsushi Nemoto printk(KERN_CONT "%s%s",
41889d63fe1SAtsushi Nemoto cont++ ? " " : "", pcicstat_tbl[i].str);
41989d63fe1SAtsushi Nemoto printk(KERN_CONT ")");
42089d63fe1SAtsushi Nemoto }
42189d63fe1SAtsushi Nemoto printk(KERN_CONT "\n");
42289d63fe1SAtsushi Nemoto }
42389d63fe1SAtsushi Nemoto
tx4927_report_pcic_status(void)42489d63fe1SAtsushi Nemoto void tx4927_report_pcic_status(void)
42589d63fe1SAtsushi Nemoto {
42689d63fe1SAtsushi Nemoto int i;
42789d63fe1SAtsushi Nemoto
42889d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
42989d63fe1SAtsushi Nemoto if (pcicptrs[i].pcicptr)
43089d63fe1SAtsushi Nemoto tx4927_report_pcic_status1(pcicptrs[i].pcicptr);
43189d63fe1SAtsushi Nemoto }
43289d63fe1SAtsushi Nemoto }
43332d00d0fSAtsushi Nemoto
tx4927_dump_pcic_settings1(struct tx4927_pcic_reg __iomem * pcicptr)434455cc256SAtsushi Nemoto static void tx4927_dump_pcic_settings1(struct tx4927_pcic_reg __iomem *pcicptr)
435455cc256SAtsushi Nemoto {
436455cc256SAtsushi Nemoto int i;
437455cc256SAtsushi Nemoto __u32 __iomem *preg = (__u32 __iomem *)pcicptr;
438455cc256SAtsushi Nemoto
439455cc256SAtsushi Nemoto printk(KERN_INFO "tx4927 pcic (0x%p) settings:", pcicptr);
440455cc256SAtsushi Nemoto for (i = 0; i < sizeof(struct tx4927_pcic_reg); i += 4, preg++) {
441455cc256SAtsushi Nemoto if (i % 32 == 0) {
442455cc256SAtsushi Nemoto printk(KERN_CONT "\n");
443455cc256SAtsushi Nemoto printk(KERN_INFO "%04x:", i);
444455cc256SAtsushi Nemoto }
445455cc256SAtsushi Nemoto /* skip registers with side-effects */
446455cc256SAtsushi Nemoto if (i == offsetof(struct tx4927_pcic_reg, g2pintack)
447455cc256SAtsushi Nemoto || i == offsetof(struct tx4927_pcic_reg, g2pspc)
448455cc256SAtsushi Nemoto || i == offsetof(struct tx4927_pcic_reg, g2pcfgadrs)
449455cc256SAtsushi Nemoto || i == offsetof(struct tx4927_pcic_reg, g2pcfgdata)) {
450455cc256SAtsushi Nemoto printk(KERN_CONT " XXXXXXXX");
451455cc256SAtsushi Nemoto continue;
452455cc256SAtsushi Nemoto }
453455cc256SAtsushi Nemoto printk(KERN_CONT " %08x", __raw_readl(preg));
454455cc256SAtsushi Nemoto }
455455cc256SAtsushi Nemoto printk(KERN_CONT "\n");
456455cc256SAtsushi Nemoto }
457455cc256SAtsushi Nemoto
tx4927_dump_pcic_settings(void)458455cc256SAtsushi Nemoto void tx4927_dump_pcic_settings(void)
459455cc256SAtsushi Nemoto {
460455cc256SAtsushi Nemoto int i;
461455cc256SAtsushi Nemoto
462455cc256SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
463455cc256SAtsushi Nemoto if (pcicptrs[i].pcicptr)
464455cc256SAtsushi Nemoto tx4927_dump_pcic_settings1(pcicptrs[i].pcicptr);
465455cc256SAtsushi Nemoto }
466455cc256SAtsushi Nemoto }
467455cc256SAtsushi Nemoto
tx4927_pcierr_interrupt(int irq,void * dev_id)468455cc256SAtsushi Nemoto irqreturn_t tx4927_pcierr_interrupt(int irq, void *dev_id)
469455cc256SAtsushi Nemoto {
470455cc256SAtsushi Nemoto struct pt_regs *regs = get_irq_regs();
471455cc256SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr =
472455cc256SAtsushi Nemoto (struct tx4927_pcic_reg __iomem *)(unsigned long)dev_id;
473455cc256SAtsushi Nemoto
474455cc256SAtsushi Nemoto if (txx9_pci_err_action != TXX9_PCI_ERR_IGNORE) {
475455cc256SAtsushi Nemoto printk(KERN_WARNING "PCIERR interrupt at 0x%0*lx\n",
476455cc256SAtsushi Nemoto (int)(2 * sizeof(unsigned long)), regs->cp0_epc);
477455cc256SAtsushi Nemoto tx4927_report_pcic_status1(pcicptr);
478455cc256SAtsushi Nemoto }
479455cc256SAtsushi Nemoto if (txx9_pci_err_action != TXX9_PCI_ERR_PANIC) {
480455cc256SAtsushi Nemoto /* clear all pci errors */
481455cc256SAtsushi Nemoto __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
482455cc256SAtsushi Nemoto | (TX4927_PCIC_PCISTATUS_ALL << 16),
483455cc256SAtsushi Nemoto &pcicptr->pcistatus);
484455cc256SAtsushi Nemoto __raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pstatus);
485455cc256SAtsushi Nemoto __raw_writel(TX4927_PCIC_PBASTATUS_ALL, &pcicptr->pbastatus);
486455cc256SAtsushi Nemoto __raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicstatus);
487455cc256SAtsushi Nemoto return IRQ_HANDLED;
488455cc256SAtsushi Nemoto }
489455cc256SAtsushi Nemoto console_verbose();
490455cc256SAtsushi Nemoto tx4927_dump_pcic_settings1(pcicptr);
491455cc256SAtsushi Nemoto panic("PCI error.");
492455cc256SAtsushi Nemoto }
493455cc256SAtsushi Nemoto
49432d00d0fSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_FPCIB0
tx4927_quirk_slc90e66_bridge(struct pci_dev * dev)49528eb0e46SGreg Kroah-Hartman static void tx4927_quirk_slc90e66_bridge(struct pci_dev *dev)
49632d00d0fSAtsushi Nemoto {
49732d00d0fSAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(dev->bus);
49832d00d0fSAtsushi Nemoto
49932d00d0fSAtsushi Nemoto if (!pcicptr)
50032d00d0fSAtsushi Nemoto return;
50132d00d0fSAtsushi Nemoto if (__raw_readl(&pcicptr->pbacfg) & TX4927_PCIC_PBACFG_PBAEN) {
50232d00d0fSAtsushi Nemoto /* Reset Bus Arbiter */
50332d00d0fSAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_RPBA, &pcicptr->pbacfg);
50432d00d0fSAtsushi Nemoto /*
50532d00d0fSAtsushi Nemoto * swap reqBP and reqXP (raise priority of SLC90E66).
50632d00d0fSAtsushi Nemoto * SLC90E66(PCI-ISA bridge) is connected to REQ2 on
50732d00d0fSAtsushi Nemoto * PCI Backplane board.
50832d00d0fSAtsushi Nemoto */
50932d00d0fSAtsushi Nemoto __raw_writel(0x72543610, &pcicptr->pbareqport);
51032d00d0fSAtsushi Nemoto __raw_writel(0, &pcicptr->pbabm);
51132d00d0fSAtsushi Nemoto /* Use Fixed ParkMaster (required by SLC90E66) */
51232d00d0fSAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_FIXPA, &pcicptr->pbacfg);
51332d00d0fSAtsushi Nemoto /* Enable Bus Arbiter */
51432d00d0fSAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_FIXPA |
51532d00d0fSAtsushi Nemoto TX4927_PCIC_PBACFG_PBAEN,
51632d00d0fSAtsushi Nemoto &pcicptr->pbacfg);
51732d00d0fSAtsushi Nemoto printk(KERN_INFO "PCI: Use Fixed Park Master (REQPORT %08x)\n",
51832d00d0fSAtsushi Nemoto __raw_readl(&pcicptr->pbareqport));
51932d00d0fSAtsushi Nemoto }
52032d00d0fSAtsushi Nemoto }
52132d00d0fSAtsushi Nemoto #define PCI_DEVICE_ID_EFAR_SLC90E66_0 0x9460
52232d00d0fSAtsushi Nemoto DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_0,
52332d00d0fSAtsushi Nemoto tx4927_quirk_slc90e66_bridge);
52432d00d0fSAtsushi Nemoto #endif
525