blob: 4fbc85a8597fafe2db012b05269c77c9e066a8be [file] [log] [blame]
Atsushi Nemoto94a4c322008-07-19 01:51:47 +09001/*
2 * TX4938/4937 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/tx4938.h>
24
Atsushi Nemoto68314722008-07-24 00:25:18 +090025static void __init tx4938_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(&tx4938_ccfgptr->ccfg) & TX4938_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 tx4938_ccfg_set(TX4938_CCFG_WDRST);
33 /* do reset on watchdog */
34 tx4938_ccfg_set(TX4938_CCFG_WR);
35}
36
Atsushi Nemoto68314722008-07-24 00:25:18 +090037void __init tx4938_wdt_init(void)
38{
39 txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
40}
41
Atsushi Nemoto496a3b52008-08-19 22:55:15 +090042static void tx4938_machine_restart(char *command)
43{
44 local_irq_disable();
45 pr_emerg("Rebooting (with %s watchdog reset)...\n",
46 (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ?
47 "external" : "internal");
48 /* clear watchdog status */
49 tx4938_ccfg_set(TX4938_CCFG_WDRST); /* W1C */
50 txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL);
51 while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST))
52 ;
53 mdelay(10);
54 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) {
55 pr_emerg("Rebooting (with internal watchdog reset)...\n");
56 /* External WDRST failed. Do internal watchdog reset */
57 tx4938_ccfg_clear(TX4938_CCFG_WDREXEN);
58 }
59 /* fallback */
60 (*_machine_halt)();
61}
62
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090063static struct resource tx4938_sdram_resource[4];
64static struct resource tx4938_sram_resource;
65
66#define TX4938_SRAM_SIZE 0x800
67
68void __init tx4938_setup(void)
69{
70 int i;
71 __u32 divmode;
72 int cpuclk = 0;
73 u64 ccfg;
74
75 txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
76 TX4938_REG_SIZE);
Atsushi Nemotod10e0252008-08-19 22:55:09 +090077 set_c0_config(TX49_CONF_CWFON);
Atsushi Nemoto94a4c322008-07-19 01:51:47 +090078
79 /* SDRAMC,EBUSC are configured by PROM */
80 for (i = 0; i < 8; i++) {
81 if (!(TX4938_EBUSC_CR(i) & 0x8))
82 continue; /* disabled */
83 txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
84 txx9_ce_res[i].end =
85 txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
86 request_resource(&iomem_resource, &txx9_ce_res[i]);
87 }
88
89 /* clocks */
90 ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
91 if (txx9_master_clock) {
92 /* calculate gbus_clock and cpu_clock from master_clock */
93 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
94 switch (divmode) {
95 case TX4938_CCFG_DIVMODE_8:
96 case TX4938_CCFG_DIVMODE_10:
97 case TX4938_CCFG_DIVMODE_12:
98 case TX4938_CCFG_DIVMODE_16:
99 case TX4938_CCFG_DIVMODE_18:
100 txx9_gbus_clock = txx9_master_clock * 4; break;
101 default:
102 txx9_gbus_clock = txx9_master_clock;
103 }
104 switch (divmode) {
105 case TX4938_CCFG_DIVMODE_2:
106 case TX4938_CCFG_DIVMODE_8:
107 cpuclk = txx9_gbus_clock * 2; break;
108 case TX4938_CCFG_DIVMODE_2_5:
109 case TX4938_CCFG_DIVMODE_10:
110 cpuclk = txx9_gbus_clock * 5 / 2; break;
111 case TX4938_CCFG_DIVMODE_3:
112 case TX4938_CCFG_DIVMODE_12:
113 cpuclk = txx9_gbus_clock * 3; break;
114 case TX4938_CCFG_DIVMODE_4:
115 case TX4938_CCFG_DIVMODE_16:
116 cpuclk = txx9_gbus_clock * 4; break;
117 case TX4938_CCFG_DIVMODE_4_5:
118 case TX4938_CCFG_DIVMODE_18:
119 cpuclk = txx9_gbus_clock * 9 / 2; break;
120 }
121 txx9_cpu_clock = cpuclk;
122 } else {
123 if (txx9_cpu_clock == 0)
124 txx9_cpu_clock = 300000000; /* 300MHz */
125 /* calculate gbus_clock and master_clock from cpu_clock */
126 cpuclk = txx9_cpu_clock;
127 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
128 switch (divmode) {
129 case TX4938_CCFG_DIVMODE_2:
130 case TX4938_CCFG_DIVMODE_8:
131 txx9_gbus_clock = cpuclk / 2; break;
132 case TX4938_CCFG_DIVMODE_2_5:
133 case TX4938_CCFG_DIVMODE_10:
134 txx9_gbus_clock = cpuclk * 2 / 5; break;
135 case TX4938_CCFG_DIVMODE_3:
136 case TX4938_CCFG_DIVMODE_12:
137 txx9_gbus_clock = cpuclk / 3; break;
138 case TX4938_CCFG_DIVMODE_4:
139 case TX4938_CCFG_DIVMODE_16:
140 txx9_gbus_clock = cpuclk / 4; break;
141 case TX4938_CCFG_DIVMODE_4_5:
142 case TX4938_CCFG_DIVMODE_18:
143 txx9_gbus_clock = cpuclk * 2 / 9; break;
144 }
145 switch (divmode) {
146 case TX4938_CCFG_DIVMODE_8:
147 case TX4938_CCFG_DIVMODE_10:
148 case TX4938_CCFG_DIVMODE_12:
149 case TX4938_CCFG_DIVMODE_16:
150 case TX4938_CCFG_DIVMODE_18:
151 txx9_master_clock = txx9_gbus_clock / 4; break;
152 default:
153 txx9_master_clock = txx9_gbus_clock;
154 }
155 }
156 /* change default value to udelay/mdelay take reasonable time */
157 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
158
159 /* CCFG */
160 tx4938_wdr_init();
161 /* clear BusErrorOnWrite flag (W1C) */
162 tx4938_ccfg_set(TX4938_CCFG_BEOW);
163 /* enable Timeout BusError */
164 if (txx9_ccfg_toeon)
165 tx4938_ccfg_set(TX4938_CCFG_TOE);
166
167 /* DMA selection */
168 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
169
170 /* Use external clock for external arbiter */
171 if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
172 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
173
174 printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
175 txx9_pcode_str,
176 (cpuclk + 500000) / 1000000,
177 (txx9_master_clock + 500000) / 1000000,
178 (__u32)____raw_readq(&tx4938_ccfgptr->crir),
179 (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
180 (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
181
182 printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
183 for (i = 0; i < 4; i++) {
184 __u64 cr = TX4938_SDRAMC_CR(i);
185 unsigned long base, size;
186 if (!((__u32)cr & 0x00000400))
187 continue; /* disabled */
188 base = (unsigned long)(cr >> 49) << 21;
189 size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
190 printk(" CR%d:%016llx", i, (unsigned long long)cr);
191 tx4938_sdram_resource[i].name = "SDRAM";
192 tx4938_sdram_resource[i].start = base;
193 tx4938_sdram_resource[i].end = base + size - 1;
194 tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
195 request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
196 }
197 printk(" TR:%09llx\n",
198 (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
199
200 /* SRAM */
201 if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
202 unsigned int size = TX4938_SRAM_SIZE;
203 tx4938_sram_resource.name = "SRAM";
204 tx4938_sram_resource.start =
205 (____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
206 & ~(size - 1);
207 tx4938_sram_resource.end =
208 tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
209 tx4938_sram_resource.flags = IORESOURCE_MEM;
210 request_resource(&iomem_resource, &tx4938_sram_resource);
211 }
212
213 /* TMR */
214 /* disable all timers */
215 for (i = 0; i < TX4938_NR_TMR; i++)
216 txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
217
218 /* DMA */
219 for (i = 0; i < 2; i++)
220 ____raw_writeq(TX4938_DMA_MCR_MSTEN,
221 (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
222
223 /* PIO */
224 txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
225 __raw_writel(0, &tx4938_pioptr->maskcpu);
226 __raw_writel(0, &tx4938_pioptr->maskext);
227
228 if (txx9_pcode == 0x4938) {
229 __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
230 /* set PCIC1 reset */
231 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
232 if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
233 mdelay(1); /* at least 128 cpu clock */
234 /* clear PCIC1 reset */
235 txx9_clear64(&tx4938_ccfgptr->clkctr,
236 TX4938_CLKCTR_PCIC1RST);
237 } else {
238 printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
239 /* stop PCIC1 */
240 txx9_set64(&tx4938_ccfgptr->clkctr,
241 TX4938_CLKCTR_PCIC1CKD);
242 }
243 if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
244 printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
245 txx9_set64(&tx4938_ccfgptr->clkctr,
246 TX4938_CLKCTR_ETH0RST);
247 txx9_set64(&tx4938_ccfgptr->clkctr,
248 TX4938_CLKCTR_ETH0CKD);
249 }
250 if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
251 printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
252 txx9_set64(&tx4938_ccfgptr->clkctr,
253 TX4938_CLKCTR_ETH1RST);
254 txx9_set64(&tx4938_ccfgptr->clkctr,
255 TX4938_CLKCTR_ETH1CKD);
256 }
257 }
Atsushi Nemoto496a3b52008-08-19 22:55:15 +0900258
259 _machine_restart = tx4938_machine_restart;
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900260}
261
262void __init tx4938_time_init(unsigned int tmrnr)
263{
264 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
265 txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
266 TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
267 TXX9_IMCLK);
268}
269
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900270void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900271{
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900272 int i;
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900273 unsigned int ch_mask = 0;
274
275 if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
276 ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
277 for (i = 0; i < 2; i++) {
278 if ((1 << i) & ch_mask)
279 continue;
Atsushi Nemoto7779a5e2008-07-25 23:08:06 +0900280 txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
281 TXX9_IRQ_BASE + TX4938_IR_SIO(i),
282 i, sclk, (1 << i) & cts_mask);
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900283 }
Atsushi Nemoto94a4c322008-07-19 01:51:47 +0900284}
Atsushi Nemotoc49f91f2008-07-24 00:25:20 +0900285
286void __init tx4938_spi_init(int busid)
287{
288 txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
289 TXX9_IRQ_BASE + TX4938_IR_SPI);
290}
291
292void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
293{
294 u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
295
296 if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
297 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
298 if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
299 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);
300}
Atsushi Nemoto51f607c2008-08-19 22:55:11 +0900301
302void __init tx4938_mtd_init(int ch)
303{
304 struct physmap_flash_data pdata = {
305 .width = TX4938_EBUSC_WIDTH(ch) / 8,
306 };
307 unsigned long start = txx9_ce_res[ch].start;
308 unsigned long size = txx9_ce_res[ch].end - start + 1;
309
310 if (!(TX4938_EBUSC_CR(ch) & 0x8))
311 return; /* disabled */
312 txx9_physmap_flash_init(ch, start, size, &pdata);
313}