xref: /linux/arch/mips/pci/pci-tx4938.c (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
189d63fe1SAtsushi Nemoto /*
289d63fe1SAtsushi Nemoto  * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
389d63fe1SAtsushi Nemoto  *	    and RBTX49xx patch from CELF patch archive.
489d63fe1SAtsushi Nemoto  *
589d63fe1SAtsushi Nemoto  * Copyright 2001, 2003-2005 MontaVista Software Inc.
689d63fe1SAtsushi Nemoto  * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
789d63fe1SAtsushi Nemoto  * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
889d63fe1SAtsushi Nemoto  *
989d63fe1SAtsushi Nemoto  * This file is subject to the terms and conditions of the GNU General Public
1089d63fe1SAtsushi Nemoto  * License.  See the file "COPYING" in the main directory of this archive
1189d63fe1SAtsushi Nemoto  * for more details.
1289d63fe1SAtsushi Nemoto  */
1389d63fe1SAtsushi Nemoto #include <linux/init.h>
1489d63fe1SAtsushi Nemoto #include <linux/pci.h>
1589d63fe1SAtsushi Nemoto #include <linux/kernel.h>
16455cc256SAtsushi Nemoto #include <linux/interrupt.h>
1789d63fe1SAtsushi Nemoto #include <asm/txx9/generic.h>
1889d63fe1SAtsushi Nemoto #include <asm/txx9/tx4938.h>
1989d63fe1SAtsushi Nemoto 
tx4938_report_pciclk(void)2089d63fe1SAtsushi Nemoto int __init tx4938_report_pciclk(void)
2189d63fe1SAtsushi Nemoto {
2289d63fe1SAtsushi Nemoto 	int pciclk = 0;
2389d63fe1SAtsushi Nemoto 
242cec11d8SGeert Uytterhoeven 	pr_info("PCIC --%s PCICLK:",
2589d63fe1SAtsushi Nemoto 		(__raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCI66) ?
2689d63fe1SAtsushi Nemoto 		" PCI66" : "");
2789d63fe1SAtsushi Nemoto 	if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_PCICLKEN_ALL) {
2889d63fe1SAtsushi Nemoto 		u64 ccfg = __raw_readq(&tx4938_ccfgptr->ccfg);
2989d63fe1SAtsushi Nemoto 		switch ((unsigned long)ccfg &
3089d63fe1SAtsushi Nemoto 			TX4938_CCFG_PCIDIVMODE_MASK) {
3189d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_4:
3289d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock / 4; break;
3389d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_4_5:
3489d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock * 2 / 9; break;
3589d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_5:
3689d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock / 5; break;
3789d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_5_5:
3889d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock * 2 / 11; break;
3989d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_8:
4089d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock / 8; break;
4189d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_9:
4289d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock / 9; break;
4389d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_10:
4489d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock / 10; break;
4589d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_11:
4689d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock / 11; break;
4789d63fe1SAtsushi Nemoto 		}
482cec11d8SGeert Uytterhoeven 		pr_cont("Internal(%u.%uMHz)",
4989d63fe1SAtsushi Nemoto 			(pciclk + 50000) / 1000000,
5089d63fe1SAtsushi Nemoto 			((pciclk + 50000) / 100000) % 10);
5189d63fe1SAtsushi Nemoto 	} else {
522cec11d8SGeert Uytterhoeven 		pr_cont("External");
5389d63fe1SAtsushi Nemoto 		pciclk = -1;
5489d63fe1SAtsushi Nemoto 	}
552cec11d8SGeert Uytterhoeven 	pr_cont("\n");
5689d63fe1SAtsushi Nemoto 	return pciclk;
5789d63fe1SAtsushi Nemoto }
5889d63fe1SAtsushi Nemoto 
tx4938_report_pci1clk(void)5989d63fe1SAtsushi Nemoto void __init tx4938_report_pci1clk(void)
6089d63fe1SAtsushi Nemoto {
6189d63fe1SAtsushi Nemoto 	__u64 ccfg = __raw_readq(&tx4938_ccfgptr->ccfg);
6289d63fe1SAtsushi Nemoto 	unsigned int pciclk =
6389d63fe1SAtsushi Nemoto 		txx9_gbus_clock / ((ccfg & TX4938_CCFG_PCI1DMD) ? 4 : 2);
6489d63fe1SAtsushi Nemoto 
652cec11d8SGeert Uytterhoeven 	pr_info("PCIC1 -- %sPCICLK:%u.%uMHz\n",
6689d63fe1SAtsushi Nemoto 		(ccfg & TX4938_CCFG_PCI1_66) ? "PCI66 " : "",
6789d63fe1SAtsushi Nemoto 		(pciclk + 50000) / 1000000,
6889d63fe1SAtsushi Nemoto 		((pciclk + 50000) / 100000) % 10);
6989d63fe1SAtsushi Nemoto }
7089d63fe1SAtsushi Nemoto 
tx4938_pciclk66_setup(void)7189d63fe1SAtsushi Nemoto int __init tx4938_pciclk66_setup(void)
7289d63fe1SAtsushi Nemoto {
7389d63fe1SAtsushi Nemoto 	int pciclk;
7489d63fe1SAtsushi Nemoto 
7589d63fe1SAtsushi Nemoto 	/* Assert M66EN */
7689d63fe1SAtsushi Nemoto 	tx4938_ccfg_set(TX4938_CCFG_PCI66);
7789d63fe1SAtsushi Nemoto 	/* Double PCICLK (if possible) */
7889d63fe1SAtsushi Nemoto 	if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_PCICLKEN_ALL) {
7989d63fe1SAtsushi Nemoto 		unsigned int pcidivmode = 0;
8089d63fe1SAtsushi Nemoto 		u64 ccfg = __raw_readq(&tx4938_ccfgptr->ccfg);
8189d63fe1SAtsushi Nemoto 		pcidivmode = (unsigned long)ccfg &
8289d63fe1SAtsushi Nemoto 			TX4938_CCFG_PCIDIVMODE_MASK;
8389d63fe1SAtsushi Nemoto 		switch (pcidivmode) {
8489d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_8:
8589d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_4:
8689d63fe1SAtsushi Nemoto 			pcidivmode = TX4938_CCFG_PCIDIVMODE_4;
8789d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock / 4;
8889d63fe1SAtsushi Nemoto 			break;
8989d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_9:
9089d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_4_5:
9189d63fe1SAtsushi Nemoto 			pcidivmode = TX4938_CCFG_PCIDIVMODE_4_5;
9289d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock * 2 / 9;
9389d63fe1SAtsushi Nemoto 			break;
9489d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_10:
9589d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_5:
9689d63fe1SAtsushi Nemoto 			pcidivmode = TX4938_CCFG_PCIDIVMODE_5;
9789d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock / 5;
9889d63fe1SAtsushi Nemoto 			break;
9989d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_11:
10089d63fe1SAtsushi Nemoto 		case TX4938_CCFG_PCIDIVMODE_5_5:
10189d63fe1SAtsushi Nemoto 		default:
10289d63fe1SAtsushi Nemoto 			pcidivmode = TX4938_CCFG_PCIDIVMODE_5_5;
10389d63fe1SAtsushi Nemoto 			pciclk = txx9_cpu_clock * 2 / 11;
10489d63fe1SAtsushi Nemoto 			break;
10589d63fe1SAtsushi Nemoto 		}
10689d63fe1SAtsushi Nemoto 		tx4938_ccfg_change(TX4938_CCFG_PCIDIVMODE_MASK,
10789d63fe1SAtsushi Nemoto 				   pcidivmode);
1082cec11d8SGeert Uytterhoeven 		pr_debug("PCICLK: ccfg:%08lx\n",
10989d63fe1SAtsushi Nemoto 			 (unsigned long)__raw_readq(&tx4938_ccfgptr->ccfg));
11089d63fe1SAtsushi Nemoto 	} else
11189d63fe1SAtsushi Nemoto 		pciclk = -1;
11289d63fe1SAtsushi Nemoto 	return pciclk;
11389d63fe1SAtsushi Nemoto }
11489d63fe1SAtsushi Nemoto 
tx4938_pcic1_map_irq(const struct pci_dev * dev,u8 slot)115*19a8d6b7SLorenzo Pieralisi int tx4938_pcic1_map_irq(const struct pci_dev *dev, u8 slot)
11689d63fe1SAtsushi Nemoto {
11789d63fe1SAtsushi Nemoto 	if (get_tx4927_pcicptr(dev->bus->sysdata) == tx4938_pcic1ptr) {
11889d63fe1SAtsushi Nemoto 		switch (slot) {
11989d63fe1SAtsushi Nemoto 		case TX4927_PCIC_IDSEL_AD_TO_SLOT(31):
12089d63fe1SAtsushi Nemoto 			if (__raw_readq(&tx4938_ccfgptr->pcfg) &
12189d63fe1SAtsushi Nemoto 			    TX4938_PCFG_ETH0_SEL)
12289d63fe1SAtsushi Nemoto 				return TXX9_IRQ_BASE + TX4938_IR_ETH0;
12389d63fe1SAtsushi Nemoto 			break;
12489d63fe1SAtsushi Nemoto 		case TX4927_PCIC_IDSEL_AD_TO_SLOT(30):
12589d63fe1SAtsushi Nemoto 			if (__raw_readq(&tx4938_ccfgptr->pcfg) &
12689d63fe1SAtsushi Nemoto 			    TX4938_PCFG_ETH1_SEL)
12789d63fe1SAtsushi Nemoto 				return TXX9_IRQ_BASE + TX4938_IR_ETH1;
12889d63fe1SAtsushi Nemoto 			break;
12989d63fe1SAtsushi Nemoto 		}
13089d63fe1SAtsushi Nemoto 		return 0;
13189d63fe1SAtsushi Nemoto 	}
13289d63fe1SAtsushi Nemoto 	return -1;
13389d63fe1SAtsushi Nemoto }
134455cc256SAtsushi Nemoto 
tx4938_setup_pcierr_irq(void)135455cc256SAtsushi Nemoto void __init tx4938_setup_pcierr_irq(void)
136455cc256SAtsushi Nemoto {
137455cc256SAtsushi Nemoto 	if (request_irq(TXX9_IRQ_BASE + TX4938_IR_PCIERR,
138455cc256SAtsushi Nemoto 			tx4927_pcierr_interrupt,
1398b5690f8SYong Zhang 			0, "PCI error",
140455cc256SAtsushi Nemoto 			(void *)TX4927_PCIC_REG))
1412cec11d8SGeert Uytterhoeven 		pr_warn("Failed to request irq for PCIERR\n");
142455cc256SAtsushi Nemoto }
143