blob: 7189675f6a290fb9cbd85e42601ed86c989ce3e4 [file] [log] [blame]
Atsushi Nemoto94a4c322008-07-19 01:51:47 +09001/*
2 * TX4927 setup routines
3 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
4 * and RBTX49xx patch from CELF patch archive.
5 *
6 * 2003-2005 (c) MontaVista Software, Inc.
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/ioport.h>
15#include <linux/delay.h>
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090016#include <linux/param.h>
Atsushi Nemoto51f607c2008-08-19 22:55:11 +090017#include <linux/mtd/physmap.h>
Atsushi Nemoto496a3b52008-08-19 22:55:15 +090018#include <asm/reboot.h>
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090019#include <asm/txx9irq.h>
20#include <asm/txx9tmr.h>
21#include <asm/txx9pio.h>
22#include <asm/txx9/generic.h>
23#include <asm/txx9/tx4927.h>
24
Atsushi Nemoto68314722008-07-24 00:25:18 +090025static void __init tx4927_wdr_init(void)
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090026{
Atsushi Nemoto496a3b52008-08-19 22:55:15 +090027 /* report watchdog reset status */
28 if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDRST)
29 pr_warning("Watchdog reset detected at 0x%lx\n",
30 read_c0_errorepc());
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090031 /* clear WatchDogReset (W1C) */
32 tx4927_ccfg_set(TX4927_CCFG_WDRST);
33 /* do reset on watchdog */
34 tx4927_ccfg_set(TX4927_CCFG_WR);
35}
36
Atsushi Nemoto68314722008-07-24 00:25:18 +090037void __init tx4927_wdt_init(void)
38{
39 txx9_wdt_init(TX4927_TMR_REG(2) & 0xfffffffffULL);
40}
41
Atsushi Nemoto496a3b52008-08-19 22:55:15 +090042static void tx4927_machine_restart(char *command)
43{
44 local_irq_disable();
45 pr_emerg("Rebooting (with %s watchdog reset)...\n",
46 (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDREXEN) ?
47 "external" : "internal");
48 /* clear watchdog status */
49 tx4927_ccfg_set(TX4927_CCFG_WDRST); /* W1C */
50 txx9_wdt_now(TX4927_TMR_REG(2) & 0xfffffffffULL);
51 while (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDRST))
52 ;
53 mdelay(10);
54 if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_WDREXEN) {
55 pr_emerg("Rebooting (with internal watchdog reset)...\n");
56 /* External WDRST failed. Do internal watchdog reset */
57 tx4927_ccfg_clear(TX4927_CCFG_WDREXEN);
58 }
59 /* fallback */
60 (*_machine_halt)();
61}
62
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090063static struct resource tx4927_sdram_resource[4];
64
65void __init tx4927_setup(void)
66{
67 int i;
68 __u32 divmode;
69 int cpuclk = 0;
70 u64 ccfg;
71
72 txx9_reg_res_init(TX4927_REV_PCODE(), TX4927_REG_BASE,
73 TX4927_REG_SIZE);
Atsushi Nemotod10e0252008-08-19 22:55:09 +090074 set_c0_config(TX49_CONF_CWFON);
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090075
76 /* SDRAMC,EBUSC are configured by PROM */
77 for (i = 0; i < 8; i++) {
78 if (!(TX4927_EBUSC_CR(i) & 0x8))
79 continue; /* disabled */
80 txx9_ce_res[i].start = (unsigned long)TX4927_EBUSC_BA(i);
81 txx9_ce_res[i].end =
82 txx9_ce_res[i].start + TX4927_EBUSC_SIZE(i) - 1;
83 request_resource(&iomem_resource, &txx9_ce_res[i]);
84 }
85
86 /* clocks */
87 ccfg = ____raw_readq(&tx4927_ccfgptr->ccfg);
88 if (txx9_master_clock) {
89 /* calculate gbus_clock and cpu_clock from master_clock */
90 divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;
91 switch (divmode) {
92 case TX4927_CCFG_DIVMODE_8:
93 case TX4927_CCFG_DIVMODE_10:
94 case TX4927_CCFG_DIVMODE_12:
95 case TX4927_CCFG_DIVMODE_16:
96 txx9_gbus_clock = txx9_master_clock * 4; break;
97 default:
98 txx9_gbus_clock = txx9_master_clock;
99 }
100 switch (divmode) {
101 case TX4927_CCFG_DIVMODE_2:
102 case TX4927_CCFG_DIVMODE_8:
103 cpuclk = txx9_gbus_clock * 2; break;
104 case TX4927_CCFG_DIVMODE_2_5:
105 case TX4927_CCFG_DIVMODE_10:
106 cpuclk = txx9_gbus_clock * 5 / 2; break;
107 case TX4927_CCFG_DIVMODE_3:
108 case TX4927_CCFG_DIVMODE_12:
109 cpuclk = txx9_gbus_clock * 3; break;
110 case TX4927_CCFG_DIVMODE_4:
111 case TX4927_CCFG_DIVMODE_16:
112 cpuclk = txx9_gbus_clock * 4; break;
113 }
114 txx9_cpu_clock = cpuclk;
115 } else {
116 if (txx9_cpu_clock == 0)
117 txx9_cpu_clock = 200000000; /* 200MHz */
118 /* calculate gbus_clock and master_clock from cpu_clock */
119 cpuclk = txx9_cpu_clock;
120 divmode = (__u32)ccfg & TX4927_CCFG_DIVMODE_MASK;
121 switch (divmode) {
122 case TX4927_CCFG_DIVMODE_2:
123 case TX4927_CCFG_DIVMODE_8:
124 txx9_gbus_clock = cpuclk / 2; break;
125 case TX4927_CCFG_DIVMODE_2_5:
126 case TX4927_CCFG_DIVMODE_10:
127 txx9_gbus_clock = cpuclk * 2 / 5; break;
128 case TX4927_CCFG_DIVMODE_3:
129 case TX4927_CCFG_DIVMODE_12:
130 txx9_gbus_clock = cpuclk / 3; break;
131 case TX4927_CCFG_DIVMODE_4:
132 case TX4927_CCFG_DIVMODE_16:
133 txx9_gbus_clock = cpuclk / 4; break;
134 }
135 switch (divmode) {
136 case TX4927_CCFG_DIVMODE_8:
137 case TX4927_CCFG_DIVMODE_10:
138 case TX4927_CCFG_DIVMODE_12:
139 case TX4927_CCFG_DIVMODE_16:
140 txx9_master_clock = txx9_gbus_clock / 4; break;
141 default:
142 txx9_master_clock = txx9_gbus_clock;
143 }
144 }
145 /* change default value to udelay/mdelay take reasonable time */
146 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
147
148 /* CCFG */
149 tx4927_wdr_init();
150 /* clear BusErrorOnWrite flag (W1C) */
151 tx4927_ccfg_set(TX4927_CCFG_BEOW);
152 /* enable Timeout BusError */
153 if (txx9_ccfg_toeon)
154 tx4927_ccfg_set(TX4927_CCFG_TOE);
155
156 /* DMA selection */
157 txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_DMASEL_ALL);
158
159 /* Use external clock for external arbiter */
160 if (!(____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_PCIARB))
161 txx9_clear64(&tx4927_ccfgptr->pcfg, TX4927_PCFG_PCICLKEN_ALL);
162
163 printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
164 txx9_pcode_str,
165 (cpuclk + 500000) / 1000000,
166 (txx9_master_clock + 500000) / 1000000,
167 (__u32)____raw_readq(&tx4927_ccfgptr->crir),
168 (unsigned long long)____raw_readq(&tx4927_ccfgptr->ccfg),
169 (unsigned long long)____raw_readq(&tx4927_ccfgptr->pcfg));
170
171 printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
172 for (i = 0; i < 4; i++) {
173 __u64 cr = TX4927_SDRAMC_CR(i);
174 unsigned long base, size;
175 if (!((__u32)cr & 0x00000400))
176 continue; /* disabled */
177 base = (unsigned long)(cr >> 49) << 21;
178 size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
179 printk(" CR%d:%016llx", i, (unsigned long long)cr);
180 tx4927_sdram_resource[i].name = "SDRAM";
181 tx4927_sdram_resource[i].start = base;
182 tx4927_sdram_resource[i].end = base + size - 1;
183 tx4927_sdram_resource[i].flags = IORESOURCE_MEM;
184 request_resource(&iomem_resource, &tx4927_sdram_resource[i]);
185 }
186 printk(" TR:%09llx\n",
187 (unsigned long long)____raw_readq(&tx4927_sdramcptr->tr));
188
189 /* TMR */
190 /* disable all timers */
191 for (i = 0; i < TX4927_NR_TMR; i++)
192 txx9_tmr_init(TX4927_TMR_REG(i) & 0xfffffffffULL);
193
194 /* PIO */
195 txx9_gpio_init(TX4927_PIO_REG & 0xfffffffffULL, 0, TX4927_NUM_PIO);
196 __raw_writel(0, &tx4927_pioptr->maskcpu);
197 __raw_writel(0, &tx4927_pioptr->maskext);
Atsushi Nemoto496a3b52008-08-19 22:55:15 +0900198
199 _machine_restart = tx4927_machine_restart;
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900200}
201
202void __init tx4927_time_init(unsigned int tmrnr)
203{
204 if (____raw_readq(&tx4927_ccfgptr->ccfg) & TX4927_CCFG_TINTDIS)
205 txx9_clockevent_init(TX4927_TMR_REG(tmrnr) & 0xfffffffffULL,
206 TXX9_IRQ_BASE + TX4927_IR_TMR(tmrnr),
207 TXX9_IMCLK);
208}
209
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900210void __init tx4927_sio_init(unsigned int sclk, unsigned int cts_mask)
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900211{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900212 int i;
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900213
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900214 for (i = 0; i < 2; i++)
215 txx9_sio_init(TX4927_SIO_REG(i) & 0xfffffffffULL,
216 TXX9_IRQ_BASE + TX4927_IR_SIO(i),
217 i, sclk, (1 << i) & cts_mask);
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900218}
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900219
220void __init tx4927_mtd_init(int ch)
221{
222 struct physmap_flash_data pdata = {
223 .width = TX4927_EBUSC_WIDTH(ch) / 8,
224 };
225 unsigned long start = txx9_ce_res[ch].start;
226 unsigned long size = txx9_ce_res[ch].end - start + 1;
227
228 if (!(TX4927_EBUSC_CR(ch) & 0x8))
229 return; /* disabled */
230 txx9_physmap_flash_init(ch, start, size, &pdata);
231}