blob: 9b3301d19a63f5b50af2ba1c1df3eeca8aecdf90 [file] [log] [blame]
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +09001/*
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +09002 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
3 * and RBTX49xx patch from CELF patch archive.
4 *
5 * Copyright 2001, 2003-2005 MontaVista Software Inc.
6 * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
7 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13#include <linux/init.h>
14#include <linux/pci.h>
15#include <linux/kernel.h>
Atsushi Nemoto455cc252008-07-25 23:01:35 +090016#include <linux/interrupt.h>
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090017#include <asm/txx9/generic.h>
18#include <asm/txx9/tx4927.h>
19
20int __init tx4927_report_pciclk(void)
21{
22 int pciclk = 0;
23
Geert Uytterhoeven2cec11d2016-12-07 10:05:15 +010024 pr_info("PCIC --%s PCICLK:",
25 (__raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCI66) ?
26 " PCI66" : "");
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090027 if (__raw_readq(&tx4927_ccfgptr->pcfg) & TX4927_PCFG_PCICLKEN_ALL) {
28 u64 ccfg = __raw_readq(&tx4927_ccfgptr->ccfg);
29 switch ((unsigned long)ccfg &
30 TX4927_CCFG_PCIDIVMODE_MASK) {
31 case TX4927_CCFG_PCIDIVMODE_2_5:
32 pciclk = txx9_cpu_clock * 2 / 5; break;
33 case TX4927_CCFG_PCIDIVMODE_3:
34 pciclk = txx9_cpu_clock / 3; break;
35 case TX4927_CCFG_PCIDIVMODE_5:
36 pciclk = txx9_cpu_clock / 5; break;
37 case TX4927_CCFG_PCIDIVMODE_6:
38 pciclk = txx9_cpu_clock / 6; break;
39 }
Geert Uytterhoeven2cec11d2016-12-07 10:05:15 +010040 pr_cont("Internal(%u.%uMHz)",
41 (pciclk + 50000) / 1000000,
42 ((pciclk + 50000) / 100000) % 10);
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090043 } else {
Geert Uytterhoeven2cec11d2016-12-07 10:05:15 +010044 pr_cont("External");
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090045 pciclk = -1;
46 }
Geert Uytterhoeven2cec11d2016-12-07 10:05:15 +010047 pr_cont("\n");
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090048 return pciclk;
49}
50
51int __init tx4927_pciclk66_setup(void)
52{
53 int pciclk;
54
55 /* Assert M66EN */
56 tx4927_ccfg_set(TX4927_CCFG_PCI66);
57 /* Double PCICLK (if possible) */
58 if (__raw_readq(&tx4927_ccfgptr->pcfg) & TX4927_PCFG_PCICLKEN_ALL) {
59 unsigned int pcidivmode = 0;
60 u64 ccfg = __raw_readq(&tx4927_ccfgptr->ccfg);
61 pcidivmode = (unsigned long)ccfg &
62 TX4927_CCFG_PCIDIVMODE_MASK;
63 switch (pcidivmode) {
64 case TX4927_CCFG_PCIDIVMODE_5:
65 case TX4927_CCFG_PCIDIVMODE_2_5:
66 pcidivmode = TX4927_CCFG_PCIDIVMODE_2_5;
67 pciclk = txx9_cpu_clock * 2 / 5;
68 break;
69 case TX4927_CCFG_PCIDIVMODE_6:
70 case TX4927_CCFG_PCIDIVMODE_3:
71 default:
72 pcidivmode = TX4927_CCFG_PCIDIVMODE_3;
73 pciclk = txx9_cpu_clock / 3;
74 }
75 tx4927_ccfg_change(TX4927_CCFG_PCIDIVMODE_MASK,
76 pcidivmode);
Geert Uytterhoeven2cec11d2016-12-07 10:05:15 +010077 pr_debug("PCICLK: ccfg:%08lx\n",
78 (unsigned long)__raw_readq(&tx4927_ccfgptr->ccfg));
Atsushi Nemoto89d63fe2008-07-11 00:33:08 +090079 } else
80 pciclk = -1;
81 return pciclk;
82}
Atsushi Nemoto455cc252008-07-25 23:01:35 +090083
84void __init tx4927_setup_pcierr_irq(void)
85{
86 if (request_irq(TXX9_IRQ_BASE + TX4927_IR_PCIERR,
87 tx4927_pcierr_interrupt,
Yong Zhang8b5690f2011-11-22 14:38:03 +000088 0, "PCI error",
Atsushi Nemoto455cc252008-07-25 23:01:35 +090089 (void *)TX4927_PCIC_REG))
Geert Uytterhoeven2cec11d2016-12-07 10:05:15 +010090 pr_warn("Failed to request irq for PCIERR\n");
Atsushi Nemoto455cc252008-07-25 23:01:35 +090091}