2 * TX4927 setup routines
3 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
4 * and RBTX49xx patch from CELF patch archive.
6 * 2003-2005 (c) MontaVista Software, Inc.
7 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
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
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/delay.h>
16 #include <linux/param.h>
17 #include <asm/txx9irq.h>
18 #include <asm/txx9tmr.h>
19 #include <asm/txx9pio.h>
20 #include <asm/txx9/generic.h>
21 #include <asm/txx9/tx4927.h>
23 static void __init tx4927_wdr_init(void)
25 /* clear WatchDogReset (W1C) */
26 tx4927_ccfg_set(TX4927_CCFG_WDRST);
27 /* do reset on watchdog */
28 tx4927_ccfg_set(TX4927_CCFG_WR);
31 void __init tx4927_wdt_init(void)
33 txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL);
36 static struct resource tx4927_sdram_resource[4];
38 void __init tx4927_setup(void)
45 txx9_reg_res_init(TX4927_REV_PCODE(), TX4927_REG_BASE,
48 /* SDRAMC,EBUSC are configured by PROM */
49 for (i = 0; i < 8; i++) {
50 if (!(TX4927_EBUSC_CR(i) & 0x8))
51 continue; /* disabled */
52 txx9_ce_res[i].start = (unsigned long)TX4927_EBUSC_BA(i);
54 txx9_ce_res[i].start + TX4927_EBUSC_SIZE(i) - 1;
55 request_resource(&iomem_resource, &txx9_ce_res[i]);
59 ccfg = ____raw_readq(&tx4927_ccfgptr->ccfg);
60 if (txx9_master_clock) {
61 /* calculate gbus_clock and cpu_clock from master_clock */
62 divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;
64 case TX4927_CCFG_DIVMODE_8:
65 case TX4927_CCFG_DIVMODE_10:
66 case TX4927_CCFG_DIVMODE_12:
67 case TX4927_CCFG_DIVMODE_16:
68 txx9_gbus_clock = txx9_master_clock * 4; break;
70 txx9_gbus_clock = txx9_master_clock;
73 case TX4927_CCFG_DIVMODE_2:
74 case TX4927_CCFG_DIVMODE_8:
75 cpuclk = txx9_gbus_clock * 2; break;
76 case TX4927_CCFG_DIVMODE_2_5:
77 case TX4927_CCFG_DIVMODE_10:
78 cpuclk = txx9_gbus_clock * 5 / 2; break;
79 case TX4927_CCFG_DIVMODE_3:
80 case TX4927_CCFG_DIVMODE_12:
81 cpuclk = txx9_gbus_clock * 3; break;
82 case TX4927_CCFG_DIVMODE_4:
83 case TX4927_CCFG_DIVMODE_16:
84 cpuclk = txx9_gbus_clock * 4; break;
86 txx9_cpu_clock = cpuclk;
88 if (txx9_cpu_clock == 0)
89 txx9_cpu_clock = 200000000; /* 200MHz */
90 /* calculate gbus_clock and master_clock from cpu_clock */
91 cpuclk = txx9_cpu_clock;
92 divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;
94 case TX4927_CCFG_DIVMODE_2:
95 case TX4927_CCFG_DIVMODE_8:
96 txx9_gbus_clock = cpuclk / 2; break;
97 case TX4927_CCFG_DIVMODE_2_5:
98 case TX4927_CCFG_DIVMODE_10:
99 txx9_gbus_clock = cpuclk * 2 / 5; break;
100 case TX4927_CCFG_DIVMODE_3:
101 case TX4927_CCFG_DIVMODE_12:
102 txx9_gbus_clock = cpuclk / 3; break;
103 case TX4927_CCFG_DIVMODE_4:
104 case TX4927_CCFG_DIVMODE_16:
105 txx9_gbus_clock = cpuclk / 4; break;
108 case TX4927_CCFG_DIVMODE_8:
109 case TX4927_CCFG_DIVMODE_10:
110 case TX4927_CCFG_DIVMODE_12:
111 case TX4927_CCFG_DIVMODE_16:
112 txx9_master_clock = txx9_gbus_clock / 4; break;
114 txx9_master_clock = txx9_gbus_clock;
117 /* change default value to udelay/mdelay take reasonable time */
118 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
122 /* clear BusErrorOnWrite flag (W1C) */
123 tx4927_ccfg_set(TX4927_CCFG_BEOW);
124 /* enable Timeout BusError */
126 tx4927_ccfg_set(TX4927_CCFG_TOE);
129 txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_DMASEL_ALL);
131 /* Use external clock for external arbiter */
132 if (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB))
133 txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_PCICLKEN_ALL);
135 printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
137 (cpuclk + 500000) / 1000000,
138 (txx9_master_clock + 500000) / 1000000,
139 (__u32)____raw_readq(&tx4927_ccfgptr->crir),
140 (unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg),
141 (unsigned long long)____raw_readq(&tx4927_ccfgptr->pcfg));
143 printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
144 for (i = 0; i < 4; i++) {
145 __u64 cr = TX4927_SDRAMC_CR(i);
146 unsigned long base, size;
147 if (!((__u32)cr & 0x00000400))
148 continue; /* disabled */
149 base = (unsigned long)(cr >> 49) << 21;
150 size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
151 printk(" CR%d:%016llx", i, (unsigned long long)cr);
152 tx4927_sdram_resource[i].name = "SDRAM";
153 tx4927_sdram_resource[i].start = base;
154 tx4927_sdram_resource[i].end = base + size - 1;
155 tx4927_sdram_resource[i].flags = IORESOURCE_MEM;
156 request_resource(&iomem_resource, &tx4927_sdram_resource[i]);
158 printk(" TR:%09llx\n",
159 (unsigned long long)____raw_readq(&tx4927_sdramcptr->tr));
162 /* disable all timers */
163 for (i = 0; i < TX4927_NR_TMR; i++)
164 txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL);
167 txx9_gpio_init(TX4927_PIO_REG & 0xfffffffffULL, 0, TX4927_NUM_PIO);
168 __raw_writel(0, &tx4927_pioptr->maskcpu);
169 __raw_writel(0, &tx4927_pioptr->maskext);
172 void __init tx4927_time_init(unsigned int tmrnr)
174 if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS)
175 txx9_clockevent_init(TX4927_TMR_REG(tmrnr) & 0xfffffffffULL,
176 TXX9_IRQ_BASE + TX4927_IR_TMR(tmrnr),
180 void __init tx4927_sio_init(unsigned int sclk, unsigned int cts_mask)
184 for (i = 0; i < 2; i++)
185 txx9_sio_init(TX4927_SIO_REG(i) & 0xfffffffffULL,
186 TXX9_IRQ_BASE + TX4927_IR_SIO(i),
187 i, sclk, (1 << i) & cts_mask);