11da177e4SLinus Torvalds /* 289d63fe1SAtsushi Nemoto * Define the pci_ops for the PCIC on Toshiba TX4927, TX4938, etc. 31da177e4SLinus Torvalds * 489d63fe1SAtsushi Nemoto * Based on linux/arch/mips/pci/ops-tx4938.c, 589d63fe1SAtsushi Nemoto * linux/arch/mips/pci/fixup-rbtx4938.c, 689d63fe1SAtsushi Nemoto * linux/arch/mips/txx9/rbtx4938/setup.c, 789d63fe1SAtsushi Nemoto * and RBTX49xx patch from CELF patch archive. 889d63fe1SAtsushi Nemoto * 989d63fe1SAtsushi Nemoto * 2003-2005 (c) MontaVista Software, Inc. 101da177e4SLinus Torvalds * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org) 1189d63fe1SAtsushi Nemoto * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007 121da177e4SLinus Torvalds * 131da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 141da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the 151da177e4SLinus Torvalds * Free Software Foundation; either version 2 of the License, or (at your 161da177e4SLinus Torvalds * option) any later version. 171da177e4SLinus Torvalds */ 181da177e4SLinus Torvalds #include <linux/kernel.h> 19*455cc256SAtsushi Nemoto #include <linux/interrupt.h> 20*455cc256SAtsushi Nemoto #include <asm/txx9/pci.h> 2189d63fe1SAtsushi Nemoto #include <asm/txx9/tx4927pcic.h> 221da177e4SLinus Torvalds 2389d63fe1SAtsushi Nemoto static struct { 2489d63fe1SAtsushi Nemoto struct pci_controller *channel; 2589d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr; 2689d63fe1SAtsushi Nemoto } pcicptrs[2]; /* TX4938 has 2 pcic */ 271da177e4SLinus Torvalds 2889d63fe1SAtsushi Nemoto static void __init set_tx4927_pcicptr(struct pci_controller *channel, 2989d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr) 301da177e4SLinus Torvalds { 3189d63fe1SAtsushi Nemoto int i; 321da177e4SLinus Torvalds 3389d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) { 3489d63fe1SAtsushi Nemoto if (pcicptrs[i].channel == channel) { 3589d63fe1SAtsushi Nemoto pcicptrs[i].pcicptr = pcicptr; 3689d63fe1SAtsushi Nemoto return; 371da177e4SLinus Torvalds } 3889d63fe1SAtsushi Nemoto } 3989d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) { 4089d63fe1SAtsushi Nemoto if (!pcicptrs[i].channel) { 4189d63fe1SAtsushi Nemoto pcicptrs[i].channel = channel; 4289d63fe1SAtsushi Nemoto pcicptrs[i].pcicptr = pcicptr; 4389d63fe1SAtsushi Nemoto return; 4489d63fe1SAtsushi Nemoto } 4589d63fe1SAtsushi Nemoto } 4689d63fe1SAtsushi Nemoto BUG(); 4789d63fe1SAtsushi Nemoto } 4889d63fe1SAtsushi Nemoto 4989d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *get_tx4927_pcicptr( 5089d63fe1SAtsushi Nemoto struct pci_controller *channel) 5189d63fe1SAtsushi Nemoto { 5289d63fe1SAtsushi Nemoto int i; 5389d63fe1SAtsushi Nemoto 5489d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) { 5589d63fe1SAtsushi Nemoto if (pcicptrs[i].channel == channel) 5689d63fe1SAtsushi Nemoto return pcicptrs[i].pcicptr; 5789d63fe1SAtsushi Nemoto } 5889d63fe1SAtsushi Nemoto return NULL; 5989d63fe1SAtsushi Nemoto } 6089d63fe1SAtsushi Nemoto 6189d63fe1SAtsushi Nemoto static int mkaddr(struct pci_bus *bus, unsigned int devfn, int where, 6289d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr) 6389d63fe1SAtsushi Nemoto { 6489d63fe1SAtsushi Nemoto if (bus->parent == NULL && 6589d63fe1SAtsushi Nemoto devfn >= PCI_DEVFN(TX4927_PCIC_MAX_DEVNU, 0)) 6689d63fe1SAtsushi Nemoto return -1; 6789d63fe1SAtsushi Nemoto __raw_writel(((bus->number & 0xff) << 0x10) 6889d63fe1SAtsushi Nemoto | ((devfn & 0xff) << 0x08) | (where & 0xfc) 6989d63fe1SAtsushi Nemoto | (bus->parent ? 1 : 0), 7089d63fe1SAtsushi Nemoto &pcicptr->g2pcfgadrs); 711da177e4SLinus Torvalds /* clear M_ABORT and Disable M_ABORT Int. */ 7289d63fe1SAtsushi Nemoto __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff) 7389d63fe1SAtsushi Nemoto | (PCI_STATUS_REC_MASTER_ABORT << 16), 7489d63fe1SAtsushi Nemoto &pcicptr->pcistatus); 751da177e4SLinus Torvalds return 0; 761da177e4SLinus Torvalds } 771da177e4SLinus Torvalds 7889d63fe1SAtsushi Nemoto static int check_abort(struct tx4927_pcic_reg __iomem *pcicptr) 791da177e4SLinus Torvalds { 801da177e4SLinus Torvalds int code = PCIBIOS_SUCCESSFUL; 8189d63fe1SAtsushi Nemoto 8289d63fe1SAtsushi Nemoto /* wait write cycle completion before checking error status */ 8389d63fe1SAtsushi Nemoto while (__raw_readl(&pcicptr->pcicstatus) & TX4927_PCIC_PCICSTATUS_IWB) 8489d63fe1SAtsushi Nemoto ; 8589d63fe1SAtsushi Nemoto if (__raw_readl(&pcicptr->pcistatus) 8689d63fe1SAtsushi Nemoto & (PCI_STATUS_REC_MASTER_ABORT << 16)) { 8789d63fe1SAtsushi Nemoto __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff) 8889d63fe1SAtsushi Nemoto | (PCI_STATUS_REC_MASTER_ABORT << 16), 8989d63fe1SAtsushi Nemoto &pcicptr->pcistatus); 9032d00d0fSAtsushi Nemoto /* flush write buffer */ 9132d00d0fSAtsushi Nemoto iob(); 921da177e4SLinus Torvalds code = PCIBIOS_DEVICE_NOT_FOUND; 931da177e4SLinus Torvalds } 941da177e4SLinus Torvalds return code; 951da177e4SLinus Torvalds } 961da177e4SLinus Torvalds 9789d63fe1SAtsushi Nemoto static u8 icd_readb(int offset, struct tx4927_pcic_reg __iomem *pcicptr) 981da177e4SLinus Torvalds { 9989d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN 10089d63fe1SAtsushi Nemoto offset ^= 3; 10189d63fe1SAtsushi Nemoto #endif 10289d63fe1SAtsushi Nemoto return __raw_readb((void __iomem *)&pcicptr->g2pcfgdata + offset); 10389d63fe1SAtsushi Nemoto } 10489d63fe1SAtsushi Nemoto static u16 icd_readw(int offset, struct tx4927_pcic_reg __iomem *pcicptr) 10589d63fe1SAtsushi Nemoto { 10689d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN 10789d63fe1SAtsushi Nemoto offset ^= 2; 10889d63fe1SAtsushi Nemoto #endif 10989d63fe1SAtsushi Nemoto return __raw_readw((void __iomem *)&pcicptr->g2pcfgdata + offset); 11089d63fe1SAtsushi Nemoto } 11189d63fe1SAtsushi Nemoto static u32 icd_readl(struct tx4927_pcic_reg __iomem *pcicptr) 11289d63fe1SAtsushi Nemoto { 11389d63fe1SAtsushi Nemoto return __raw_readl(&pcicptr->g2pcfgdata); 11489d63fe1SAtsushi Nemoto } 11589d63fe1SAtsushi Nemoto static void icd_writeb(u8 val, int offset, 11689d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr) 11789d63fe1SAtsushi Nemoto { 11889d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN 11989d63fe1SAtsushi Nemoto offset ^= 3; 12089d63fe1SAtsushi Nemoto #endif 12189d63fe1SAtsushi Nemoto __raw_writeb(val, (void __iomem *)&pcicptr->g2pcfgdata + offset); 12289d63fe1SAtsushi Nemoto } 12389d63fe1SAtsushi Nemoto static void icd_writew(u16 val, int offset, 12489d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr) 12589d63fe1SAtsushi Nemoto { 12689d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN 12789d63fe1SAtsushi Nemoto offset ^= 2; 12889d63fe1SAtsushi Nemoto #endif 12989d63fe1SAtsushi Nemoto __raw_writew(val, (void __iomem *)&pcicptr->g2pcfgdata + offset); 13089d63fe1SAtsushi Nemoto } 13189d63fe1SAtsushi Nemoto static void icd_writel(u32 val, struct tx4927_pcic_reg __iomem *pcicptr) 13289d63fe1SAtsushi Nemoto { 13389d63fe1SAtsushi Nemoto __raw_writel(val, &pcicptr->g2pcfgdata); 1341da177e4SLinus Torvalds } 1351da177e4SLinus Torvalds 13689d63fe1SAtsushi Nemoto static struct tx4927_pcic_reg __iomem *pci_bus_to_pcicptr(struct pci_bus *bus) 13789d63fe1SAtsushi Nemoto { 13889d63fe1SAtsushi Nemoto struct pci_controller *channel = bus->sysdata; 13989d63fe1SAtsushi Nemoto return get_tx4927_pcicptr(channel); 1401da177e4SLinus Torvalds } 1411da177e4SLinus Torvalds 14289d63fe1SAtsushi Nemoto static int tx4927_pci_config_read(struct pci_bus *bus, unsigned int devfn, 14389d63fe1SAtsushi Nemoto int where, int size, u32 *val) 14489d63fe1SAtsushi Nemoto { 14589d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(bus); 14689d63fe1SAtsushi Nemoto 14789d63fe1SAtsushi Nemoto if (mkaddr(bus, devfn, where, pcicptr)) { 1481da177e4SLinus Torvalds *val = 0xffffffff; 1491da177e4SLinus Torvalds return -1; 15089d63fe1SAtsushi Nemoto } 1511da177e4SLinus Torvalds switch (size) { 1521da177e4SLinus Torvalds case 1: 15389d63fe1SAtsushi Nemoto *val = icd_readb(where & 3, pcicptr); 1541da177e4SLinus Torvalds break; 1551da177e4SLinus Torvalds case 2: 15689d63fe1SAtsushi Nemoto *val = icd_readw(where & 3, pcicptr); 15789d63fe1SAtsushi Nemoto break; 15889d63fe1SAtsushi Nemoto default: 15989d63fe1SAtsushi Nemoto *val = icd_readl(pcicptr); 16089d63fe1SAtsushi Nemoto } 16189d63fe1SAtsushi Nemoto return check_abort(pcicptr); 16289d63fe1SAtsushi Nemoto } 16389d63fe1SAtsushi Nemoto 16489d63fe1SAtsushi Nemoto static int tx4927_pci_config_write(struct pci_bus *bus, unsigned int devfn, 16589d63fe1SAtsushi Nemoto int where, int size, u32 val) 16689d63fe1SAtsushi Nemoto { 16789d63fe1SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(bus); 16889d63fe1SAtsushi Nemoto 16989d63fe1SAtsushi Nemoto if (mkaddr(bus, devfn, where, pcicptr)) 17089d63fe1SAtsushi Nemoto return -1; 17189d63fe1SAtsushi Nemoto switch (size) { 17289d63fe1SAtsushi Nemoto case 1: 17389d63fe1SAtsushi Nemoto icd_writeb(val, where & 3, pcicptr); 17489d63fe1SAtsushi Nemoto break; 17589d63fe1SAtsushi Nemoto case 2: 17689d63fe1SAtsushi Nemoto icd_writew(val, where & 3, pcicptr); 17789d63fe1SAtsushi Nemoto break; 17889d63fe1SAtsushi Nemoto default: 17989d63fe1SAtsushi Nemoto icd_writel(val, pcicptr); 18089d63fe1SAtsushi Nemoto } 18189d63fe1SAtsushi Nemoto return check_abort(pcicptr); 18289d63fe1SAtsushi Nemoto } 18389d63fe1SAtsushi Nemoto 18489d63fe1SAtsushi Nemoto static struct pci_ops tx4927_pci_ops = { 18589d63fe1SAtsushi Nemoto .read = tx4927_pci_config_read, 18689d63fe1SAtsushi Nemoto .write = tx4927_pci_config_write, 18789d63fe1SAtsushi Nemoto }; 18889d63fe1SAtsushi Nemoto 18989d63fe1SAtsushi Nemoto static struct { 19089d63fe1SAtsushi Nemoto u8 trdyto; 19189d63fe1SAtsushi Nemoto u8 retryto; 19289d63fe1SAtsushi Nemoto u16 gbwc; 19389d63fe1SAtsushi Nemoto } tx4927_pci_opts __devinitdata = { 19489d63fe1SAtsushi Nemoto .trdyto = 0, 19589d63fe1SAtsushi Nemoto .retryto = 0, 19689d63fe1SAtsushi Nemoto .gbwc = 0xfe0, /* 4064 GBUSCLK for CCFG.GTOT=0b11 */ 19789d63fe1SAtsushi Nemoto }; 19889d63fe1SAtsushi Nemoto 19907517529SAtsushi Nemoto char *__devinit tx4927_pcibios_setup(char *str) 20007517529SAtsushi Nemoto { 20107517529SAtsushi Nemoto unsigned long val; 20207517529SAtsushi Nemoto 20307517529SAtsushi Nemoto if (!strncmp(str, "trdyto=", 7)) { 20407517529SAtsushi Nemoto if (strict_strtoul(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)) { 20907517529SAtsushi Nemoto if (strict_strtoul(str + 8, 0, &val) == 0) 21007517529SAtsushi Nemoto tx4927_pci_opts.retryto = val; 21107517529SAtsushi Nemoto return NULL; 21207517529SAtsushi Nemoto } 21307517529SAtsushi Nemoto if (!strncmp(str, "gbwc=", 5)) { 21407517529SAtsushi Nemoto if (strict_strtoul(str + 5, 0, &val) == 0) 21507517529SAtsushi Nemoto tx4927_pci_opts.gbwc = val; 21607517529SAtsushi Nemoto return NULL; 21707517529SAtsushi Nemoto } 21807517529SAtsushi Nemoto return str; 21907517529SAtsushi Nemoto } 22007517529SAtsushi Nemoto 22189d63fe1SAtsushi Nemoto void __init tx4927_pcic_setup(struct tx4927_pcic_reg __iomem *pcicptr, 22289d63fe1SAtsushi Nemoto struct pci_controller *channel, int extarb) 22389d63fe1SAtsushi Nemoto { 22489d63fe1SAtsushi Nemoto int i; 22589d63fe1SAtsushi Nemoto unsigned long flags; 22689d63fe1SAtsushi Nemoto 22789d63fe1SAtsushi Nemoto set_tx4927_pcicptr(channel, pcicptr); 22889d63fe1SAtsushi Nemoto 22989d63fe1SAtsushi Nemoto if (!channel->pci_ops) 23089d63fe1SAtsushi Nemoto printk(KERN_INFO 23189d63fe1SAtsushi Nemoto "PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:%s\n", 23289d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pciid) >> 16, 23389d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pciid) & 0xffff, 23489d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pciccrev) & 0xff, 23589d63fe1SAtsushi Nemoto extarb ? "External" : "Internal"); 23689d63fe1SAtsushi Nemoto channel->pci_ops = &tx4927_pci_ops; 23789d63fe1SAtsushi Nemoto 23889d63fe1SAtsushi Nemoto local_irq_save(flags); 23989d63fe1SAtsushi Nemoto 24089d63fe1SAtsushi Nemoto /* Disable All Initiator Space */ 24189d63fe1SAtsushi Nemoto __raw_writel(__raw_readl(&pcicptr->pciccfg) 24289d63fe1SAtsushi Nemoto & ~(TX4927_PCIC_PCICCFG_G2PMEN(0) 24389d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PMEN(1) 24489d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PMEN(2) 24589d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PIOEN), 24689d63fe1SAtsushi Nemoto &pcicptr->pciccfg); 24789d63fe1SAtsushi Nemoto 24889d63fe1SAtsushi Nemoto /* GB->PCI mappings */ 24989d63fe1SAtsushi Nemoto __raw_writel((channel->io_resource->end - channel->io_resource->start) 25089d63fe1SAtsushi Nemoto >> 4, 25189d63fe1SAtsushi Nemoto &pcicptr->g2piomask); 25289d63fe1SAtsushi Nemoto ____raw_writeq((channel->io_resource->start + 25389d63fe1SAtsushi Nemoto channel->io_map_base - IO_BASE) | 25489d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN 25589d63fe1SAtsushi Nemoto TX4927_PCIC_G2PIOGBASE_ECHG 2561da177e4SLinus Torvalds #else 25789d63fe1SAtsushi Nemoto TX4927_PCIC_G2PIOGBASE_BSDIS 2581da177e4SLinus Torvalds #endif 25989d63fe1SAtsushi Nemoto , &pcicptr->g2piogbase); 26089d63fe1SAtsushi Nemoto ____raw_writeq(channel->io_resource->start - channel->io_offset, 26189d63fe1SAtsushi Nemoto &pcicptr->g2piopbase); 26289d63fe1SAtsushi Nemoto for (i = 0; i < 3; i++) { 26389d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->g2pmmask[i]); 26489d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->g2pmgbase[i]); 26589d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->g2pmpbase[i]); 26689d63fe1SAtsushi Nemoto } 26789d63fe1SAtsushi Nemoto if (channel->mem_resource->end) { 26889d63fe1SAtsushi Nemoto __raw_writel((channel->mem_resource->end 26989d63fe1SAtsushi Nemoto - channel->mem_resource->start) >> 4, 27089d63fe1SAtsushi Nemoto &pcicptr->g2pmmask[0]); 27189d63fe1SAtsushi Nemoto ____raw_writeq(channel->mem_resource->start | 27289d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN 27389d63fe1SAtsushi Nemoto TX4927_PCIC_G2PMnGBASE_ECHG 27489d63fe1SAtsushi Nemoto #else 27589d63fe1SAtsushi Nemoto TX4927_PCIC_G2PMnGBASE_BSDIS 27689d63fe1SAtsushi Nemoto #endif 27789d63fe1SAtsushi Nemoto , &pcicptr->g2pmgbase[0]); 27889d63fe1SAtsushi Nemoto ____raw_writeq(channel->mem_resource->start - 27989d63fe1SAtsushi Nemoto channel->mem_offset, 28089d63fe1SAtsushi Nemoto &pcicptr->g2pmpbase[0]); 28189d63fe1SAtsushi Nemoto } 28289d63fe1SAtsushi Nemoto /* PCI->GB mappings (I/O 256B) */ 28389d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->p2giopbase); /* 256B */ 28489d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->p2giogbase); 28589d63fe1SAtsushi Nemoto /* PCI->GB mappings (MEM 512MB (64MB on R1.x)) */ 28689d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->p2gm0plbase); 28789d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->p2gm0pubase); 28889d63fe1SAtsushi Nemoto ____raw_writeq(TX4927_PCIC_P2GMnGBASE_TMEMEN | 28989d63fe1SAtsushi Nemoto #ifdef __BIG_ENDIAN 29089d63fe1SAtsushi Nemoto TX4927_PCIC_P2GMnGBASE_TECHG 29189d63fe1SAtsushi Nemoto #else 29289d63fe1SAtsushi Nemoto TX4927_PCIC_P2GMnGBASE_TBSDIS 29389d63fe1SAtsushi Nemoto #endif 29489d63fe1SAtsushi Nemoto , &pcicptr->p2gmgbase[0]); 29589d63fe1SAtsushi Nemoto /* PCI->GB mappings (MEM 16MB) */ 29689d63fe1SAtsushi Nemoto __raw_writel(0xffffffff, &pcicptr->p2gm1plbase); 29789d63fe1SAtsushi Nemoto __raw_writel(0xffffffff, &pcicptr->p2gm1pubase); 29889d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->p2gmgbase[1]); 29989d63fe1SAtsushi Nemoto /* PCI->GB mappings (MEM 1MB) */ 30089d63fe1SAtsushi Nemoto __raw_writel(0xffffffff, &pcicptr->p2gm2pbase); /* 1MB */ 30189d63fe1SAtsushi Nemoto ____raw_writeq(0, &pcicptr->p2gmgbase[2]); 30289d63fe1SAtsushi Nemoto 30389d63fe1SAtsushi Nemoto /* Clear all (including IRBER) except for GBWC */ 30489d63fe1SAtsushi Nemoto __raw_writel((tx4927_pci_opts.gbwc << 16) 30589d63fe1SAtsushi Nemoto & TX4927_PCIC_PCICCFG_GBWC_MASK, 30689d63fe1SAtsushi Nemoto &pcicptr->pciccfg); 30789d63fe1SAtsushi Nemoto /* Enable Initiator Memory Space */ 30889d63fe1SAtsushi Nemoto if (channel->mem_resource->end) 30989d63fe1SAtsushi Nemoto __raw_writel(__raw_readl(&pcicptr->pciccfg) 31089d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PMEN(0), 31189d63fe1SAtsushi Nemoto &pcicptr->pciccfg); 31289d63fe1SAtsushi Nemoto /* Enable Initiator I/O Space */ 31389d63fe1SAtsushi Nemoto if (channel->io_resource->end) 31489d63fe1SAtsushi Nemoto __raw_writel(__raw_readl(&pcicptr->pciccfg) 31589d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_G2PIOEN, 31689d63fe1SAtsushi Nemoto &pcicptr->pciccfg); 31789d63fe1SAtsushi Nemoto /* Enable Initiator Config */ 31889d63fe1SAtsushi Nemoto __raw_writel(__raw_readl(&pcicptr->pciccfg) 31989d63fe1SAtsushi Nemoto | TX4927_PCIC_PCICCFG_ICAEN | TX4927_PCIC_PCICCFG_TCAR, 32089d63fe1SAtsushi Nemoto &pcicptr->pciccfg); 32189d63fe1SAtsushi Nemoto 32289d63fe1SAtsushi Nemoto /* Do not use MEMMUL, MEMINF: YMFPCI card causes M_ABORT. */ 32389d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->pcicfg1); 32489d63fe1SAtsushi Nemoto 32589d63fe1SAtsushi Nemoto __raw_writel((__raw_readl(&pcicptr->g2ptocnt) & ~0xffff) 32689d63fe1SAtsushi Nemoto | (tx4927_pci_opts.trdyto & 0xff) 32789d63fe1SAtsushi Nemoto | ((tx4927_pci_opts.retryto & 0xff) << 8), 32889d63fe1SAtsushi Nemoto &pcicptr->g2ptocnt); 32989d63fe1SAtsushi Nemoto 33089d63fe1SAtsushi Nemoto /* Clear All Local Bus Status */ 33189d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicstatus); 33289d63fe1SAtsushi Nemoto /* Enable All Local Bus Interrupts */ 33389d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicmask); 33489d63fe1SAtsushi Nemoto /* Clear All Initiator Status */ 33589d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pstatus); 33689d63fe1SAtsushi Nemoto /* Enable All Initiator Interrupts */ 33789d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pmask); 33889d63fe1SAtsushi Nemoto /* Clear All PCI Status Error */ 33989d63fe1SAtsushi Nemoto __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff) 34089d63fe1SAtsushi Nemoto | (TX4927_PCIC_PCISTATUS_ALL << 16), 34189d63fe1SAtsushi Nemoto &pcicptr->pcistatus); 34289d63fe1SAtsushi Nemoto /* Enable All PCI Status Error Interrupts */ 34389d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PCISTATUS_ALL, &pcicptr->pcimask); 34489d63fe1SAtsushi Nemoto 34589d63fe1SAtsushi Nemoto if (!extarb) { 34689d63fe1SAtsushi Nemoto /* Reset Bus Arbiter */ 34789d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_RPBA, &pcicptr->pbacfg); 34889d63fe1SAtsushi Nemoto __raw_writel(0, &pcicptr->pbabm); 34989d63fe1SAtsushi Nemoto /* Enable Bus Arbiter */ 35089d63fe1SAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_PBAEN, &pcicptr->pbacfg); 3511da177e4SLinus Torvalds } 3521da177e4SLinus Torvalds 35389d63fe1SAtsushi Nemoto __raw_writel(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY 35489d63fe1SAtsushi Nemoto | PCI_COMMAND_PARITY | PCI_COMMAND_SERR, 35589d63fe1SAtsushi Nemoto &pcicptr->pcistatus); 35689d63fe1SAtsushi Nemoto local_irq_restore(flags); 35789d63fe1SAtsushi Nemoto 35889d63fe1SAtsushi Nemoto printk(KERN_DEBUG 35989d63fe1SAtsushi Nemoto "PCI: COMMAND=%04x,PCIMASK=%04x," 36089d63fe1SAtsushi Nemoto "TRDYTO=%02x,RETRYTO=%02x,GBWC=%03x\n", 36189d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pcistatus) & 0xffff, 36289d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->pcimask) & 0xffff, 36389d63fe1SAtsushi Nemoto __raw_readl(&pcicptr->g2ptocnt) & 0xff, 36489d63fe1SAtsushi Nemoto (__raw_readl(&pcicptr->g2ptocnt) & 0xff00) >> 8, 36589d63fe1SAtsushi Nemoto (__raw_readl(&pcicptr->pciccfg) >> 16) & 0xfff); 3661da177e4SLinus Torvalds } 3671da177e4SLinus Torvalds 36889d63fe1SAtsushi Nemoto static void tx4927_report_pcic_status1(struct tx4927_pcic_reg __iomem *pcicptr) 36989d63fe1SAtsushi Nemoto { 37089d63fe1SAtsushi Nemoto __u16 pcistatus = (__u16)(__raw_readl(&pcicptr->pcistatus) >> 16); 37189d63fe1SAtsushi Nemoto __u32 g2pstatus = __raw_readl(&pcicptr->g2pstatus); 37289d63fe1SAtsushi Nemoto __u32 pcicstatus = __raw_readl(&pcicptr->pcicstatus); 37389d63fe1SAtsushi Nemoto static struct { 37489d63fe1SAtsushi Nemoto __u32 flag; 37589d63fe1SAtsushi Nemoto const char *str; 37689d63fe1SAtsushi Nemoto } pcistat_tbl[] = { 37789d63fe1SAtsushi Nemoto { PCI_STATUS_DETECTED_PARITY, "DetectedParityError" }, 37889d63fe1SAtsushi Nemoto { PCI_STATUS_SIG_SYSTEM_ERROR, "SignaledSystemError" }, 37989d63fe1SAtsushi Nemoto { PCI_STATUS_REC_MASTER_ABORT, "ReceivedMasterAbort" }, 38089d63fe1SAtsushi Nemoto { PCI_STATUS_REC_TARGET_ABORT, "ReceivedTargetAbort" }, 38189d63fe1SAtsushi Nemoto { PCI_STATUS_SIG_TARGET_ABORT, "SignaledTargetAbort" }, 38289d63fe1SAtsushi Nemoto { PCI_STATUS_PARITY, "MasterParityError" }, 38389d63fe1SAtsushi Nemoto }, g2pstat_tbl[] = { 38489d63fe1SAtsushi Nemoto { TX4927_PCIC_G2PSTATUS_TTOE, "TIOE" }, 38589d63fe1SAtsushi Nemoto { TX4927_PCIC_G2PSTATUS_RTOE, "RTOE" }, 38689d63fe1SAtsushi Nemoto }, pcicstat_tbl[] = { 38789d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_PME, "PME" }, 38889d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_TLB, "TLB" }, 38989d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_NIB, "NIB" }, 39089d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_ZIB, "ZIB" }, 39189d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_PERR, "PERR" }, 39289d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_SERR, "SERR" }, 39389d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_GBE, "GBE" }, 39489d63fe1SAtsushi Nemoto { TX4927_PCIC_PCICSTATUS_IWB, "IWB" }, 3951da177e4SLinus Torvalds }; 39689d63fe1SAtsushi Nemoto int i, cont; 3971da177e4SLinus Torvalds 39889d63fe1SAtsushi Nemoto printk(KERN_ERR ""); 39989d63fe1SAtsushi Nemoto if (pcistatus & TX4927_PCIC_PCISTATUS_ALL) { 40089d63fe1SAtsushi Nemoto printk(KERN_CONT "pcistat:%04x(", pcistatus); 40189d63fe1SAtsushi Nemoto for (i = 0, cont = 0; i < ARRAY_SIZE(pcistat_tbl); i++) 40289d63fe1SAtsushi Nemoto if (pcistatus & pcistat_tbl[i].flag) 40389d63fe1SAtsushi Nemoto printk(KERN_CONT "%s%s", 40489d63fe1SAtsushi Nemoto cont++ ? " " : "", pcistat_tbl[i].str); 40589d63fe1SAtsushi Nemoto printk(KERN_CONT ") "); 40689d63fe1SAtsushi Nemoto } 40789d63fe1SAtsushi Nemoto if (g2pstatus & TX4927_PCIC_G2PSTATUS_ALL) { 40889d63fe1SAtsushi Nemoto printk(KERN_CONT "g2pstatus:%08x(", g2pstatus); 40989d63fe1SAtsushi Nemoto for (i = 0, cont = 0; i < ARRAY_SIZE(g2pstat_tbl); i++) 41089d63fe1SAtsushi Nemoto if (g2pstatus & g2pstat_tbl[i].flag) 41189d63fe1SAtsushi Nemoto printk(KERN_CONT "%s%s", 41289d63fe1SAtsushi Nemoto cont++ ? " " : "", g2pstat_tbl[i].str); 41389d63fe1SAtsushi Nemoto printk(KERN_CONT ") "); 41489d63fe1SAtsushi Nemoto } 41589d63fe1SAtsushi Nemoto if (pcicstatus & TX4927_PCIC_PCICSTATUS_ALL) { 41689d63fe1SAtsushi Nemoto printk(KERN_CONT "pcicstatus:%08x(", pcicstatus); 41789d63fe1SAtsushi Nemoto for (i = 0, cont = 0; i < ARRAY_SIZE(pcicstat_tbl); i++) 41889d63fe1SAtsushi Nemoto if (pcicstatus & pcicstat_tbl[i].flag) 41989d63fe1SAtsushi Nemoto printk(KERN_CONT "%s%s", 42089d63fe1SAtsushi Nemoto cont++ ? " " : "", pcicstat_tbl[i].str); 42189d63fe1SAtsushi Nemoto printk(KERN_CONT ")"); 42289d63fe1SAtsushi Nemoto } 42389d63fe1SAtsushi Nemoto printk(KERN_CONT "\n"); 42489d63fe1SAtsushi Nemoto } 42589d63fe1SAtsushi Nemoto 42689d63fe1SAtsushi Nemoto void tx4927_report_pcic_status(void) 42789d63fe1SAtsushi Nemoto { 42889d63fe1SAtsushi Nemoto int i; 42989d63fe1SAtsushi Nemoto 43089d63fe1SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) { 43189d63fe1SAtsushi Nemoto if (pcicptrs[i].pcicptr) 43289d63fe1SAtsushi Nemoto tx4927_report_pcic_status1(pcicptrs[i].pcicptr); 43389d63fe1SAtsushi Nemoto } 43489d63fe1SAtsushi Nemoto } 43532d00d0fSAtsushi Nemoto 436*455cc256SAtsushi Nemoto static void tx4927_dump_pcic_settings1(struct tx4927_pcic_reg __iomem *pcicptr) 437*455cc256SAtsushi Nemoto { 438*455cc256SAtsushi Nemoto int i; 439*455cc256SAtsushi Nemoto __u32 __iomem *preg = (__u32 __iomem *)pcicptr; 440*455cc256SAtsushi Nemoto 441*455cc256SAtsushi Nemoto printk(KERN_INFO "tx4927 pcic (0x%p) settings:", pcicptr); 442*455cc256SAtsushi Nemoto for (i = 0; i < sizeof(struct tx4927_pcic_reg); i += 4, preg++) { 443*455cc256SAtsushi Nemoto if (i % 32 == 0) { 444*455cc256SAtsushi Nemoto printk(KERN_CONT "\n"); 445*455cc256SAtsushi Nemoto printk(KERN_INFO "%04x:", i); 446*455cc256SAtsushi Nemoto } 447*455cc256SAtsushi Nemoto /* skip registers with side-effects */ 448*455cc256SAtsushi Nemoto if (i == offsetof(struct tx4927_pcic_reg, g2pintack) 449*455cc256SAtsushi Nemoto || i == offsetof(struct tx4927_pcic_reg, g2pspc) 450*455cc256SAtsushi Nemoto || i == offsetof(struct tx4927_pcic_reg, g2pcfgadrs) 451*455cc256SAtsushi Nemoto || i == offsetof(struct tx4927_pcic_reg, g2pcfgdata)) { 452*455cc256SAtsushi Nemoto printk(KERN_CONT " XXXXXXXX"); 453*455cc256SAtsushi Nemoto continue; 454*455cc256SAtsushi Nemoto } 455*455cc256SAtsushi Nemoto printk(KERN_CONT " %08x", __raw_readl(preg)); 456*455cc256SAtsushi Nemoto } 457*455cc256SAtsushi Nemoto printk(KERN_CONT "\n"); 458*455cc256SAtsushi Nemoto } 459*455cc256SAtsushi Nemoto 460*455cc256SAtsushi Nemoto void tx4927_dump_pcic_settings(void) 461*455cc256SAtsushi Nemoto { 462*455cc256SAtsushi Nemoto int i; 463*455cc256SAtsushi Nemoto 464*455cc256SAtsushi Nemoto for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) { 465*455cc256SAtsushi Nemoto if (pcicptrs[i].pcicptr) 466*455cc256SAtsushi Nemoto tx4927_dump_pcic_settings1(pcicptrs[i].pcicptr); 467*455cc256SAtsushi Nemoto } 468*455cc256SAtsushi Nemoto } 469*455cc256SAtsushi Nemoto 470*455cc256SAtsushi Nemoto irqreturn_t tx4927_pcierr_interrupt(int irq, void *dev_id) 471*455cc256SAtsushi Nemoto { 472*455cc256SAtsushi Nemoto struct pt_regs *regs = get_irq_regs(); 473*455cc256SAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr = 474*455cc256SAtsushi Nemoto (struct tx4927_pcic_reg __iomem *)(unsigned long)dev_id; 475*455cc256SAtsushi Nemoto 476*455cc256SAtsushi Nemoto if (txx9_pci_err_action != TXX9_PCI_ERR_IGNORE) { 477*455cc256SAtsushi Nemoto printk(KERN_WARNING "PCIERR interrupt at 0x%0*lx\n", 478*455cc256SAtsushi Nemoto (int)(2 * sizeof(unsigned long)), regs->cp0_epc); 479*455cc256SAtsushi Nemoto tx4927_report_pcic_status1(pcicptr); 480*455cc256SAtsushi Nemoto } 481*455cc256SAtsushi Nemoto if (txx9_pci_err_action != TXX9_PCI_ERR_PANIC) { 482*455cc256SAtsushi Nemoto /* clear all pci errors */ 483*455cc256SAtsushi Nemoto __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff) 484*455cc256SAtsushi Nemoto | (TX4927_PCIC_PCISTATUS_ALL << 16), 485*455cc256SAtsushi Nemoto &pcicptr->pcistatus); 486*455cc256SAtsushi Nemoto __raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pstatus); 487*455cc256SAtsushi Nemoto __raw_writel(TX4927_PCIC_PBASTATUS_ALL, &pcicptr->pbastatus); 488*455cc256SAtsushi Nemoto __raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicstatus); 489*455cc256SAtsushi Nemoto return IRQ_HANDLED; 490*455cc256SAtsushi Nemoto } 491*455cc256SAtsushi Nemoto console_verbose(); 492*455cc256SAtsushi Nemoto tx4927_dump_pcic_settings1(pcicptr); 493*455cc256SAtsushi Nemoto panic("PCI error."); 494*455cc256SAtsushi Nemoto } 495*455cc256SAtsushi Nemoto 49632d00d0fSAtsushi Nemoto #ifdef CONFIG_TOSHIBA_FPCIB0 49732d00d0fSAtsushi Nemoto static void __init tx4927_quirk_slc90e66_bridge(struct pci_dev *dev) 49832d00d0fSAtsushi Nemoto { 49932d00d0fSAtsushi Nemoto struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(dev->bus); 50032d00d0fSAtsushi Nemoto 50132d00d0fSAtsushi Nemoto if (!pcicptr) 50232d00d0fSAtsushi Nemoto return; 50332d00d0fSAtsushi Nemoto if (__raw_readl(&pcicptr->pbacfg) & TX4927_PCIC_PBACFG_PBAEN) { 50432d00d0fSAtsushi Nemoto /* Reset Bus Arbiter */ 50532d00d0fSAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_RPBA, &pcicptr->pbacfg); 50632d00d0fSAtsushi Nemoto /* 50732d00d0fSAtsushi Nemoto * swap reqBP and reqXP (raise priority of SLC90E66). 50832d00d0fSAtsushi Nemoto * SLC90E66(PCI-ISA bridge) is connected to REQ2 on 50932d00d0fSAtsushi Nemoto * PCI Backplane board. 51032d00d0fSAtsushi Nemoto */ 51132d00d0fSAtsushi Nemoto __raw_writel(0x72543610, &pcicptr->pbareqport); 51232d00d0fSAtsushi Nemoto __raw_writel(0, &pcicptr->pbabm); 51332d00d0fSAtsushi Nemoto /* Use Fixed ParkMaster (required by SLC90E66) */ 51432d00d0fSAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_FIXPA, &pcicptr->pbacfg); 51532d00d0fSAtsushi Nemoto /* Enable Bus Arbiter */ 51632d00d0fSAtsushi Nemoto __raw_writel(TX4927_PCIC_PBACFG_FIXPA | 51732d00d0fSAtsushi Nemoto TX4927_PCIC_PBACFG_PBAEN, 51832d00d0fSAtsushi Nemoto &pcicptr->pbacfg); 51932d00d0fSAtsushi Nemoto printk(KERN_INFO "PCI: Use Fixed Park Master (REQPORT %08x)\n", 52032d00d0fSAtsushi Nemoto __raw_readl(&pcicptr->pbareqport)); 52132d00d0fSAtsushi Nemoto } 52232d00d0fSAtsushi Nemoto } 52332d00d0fSAtsushi Nemoto #define PCI_DEVICE_ID_EFAR_SLC90E66_0 0x9460 52432d00d0fSAtsushi Nemoto DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_0, 52532d00d0fSAtsushi Nemoto tx4927_quirk_slc90e66_bridge); 52632d00d0fSAtsushi Nemoto #endif 527