2 * TX4938/4937 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 <linux/ptrace.h>
18 #include <linux/mtd/physmap.h>
19 #include <linux/platform_device.h>
20 #include <asm/reboot.h>
21 #include <asm/traps.h>
22 #include <asm/txx9irq.h>
23 #include <asm/txx9tmr.h>
24 #include <asm/txx9pio.h>
25 #include <asm/txx9/generic.h>
26 #include <asm/txx9/ndfmc.h>
27 #include <asm/txx9/tx4938.h>
29 static void __init tx4938_wdr_init(void)
31 /* report watchdog reset status */
32 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST)
33 pr_warning("Watchdog reset detected at 0x%lx\n",
35 /* clear WatchDogReset (W1C) */
36 tx4938_ccfg_set(TX4938_CCFG_WDRST);
37 /* do reset on watchdog */
38 tx4938_ccfg_set(TX4938_CCFG_WR);
41 void __init tx4938_wdt_init(void)
43 txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
46 static void tx4938_machine_restart(char *command)
49 pr_emerg("Rebooting (with %s watchdog reset)...\n",
50 (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ?
51 "external" : "internal");
52 /* clear watchdog status */
53 tx4938_ccfg_set(TX4938_CCFG_WDRST); /* W1C */
54 txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL);
55 while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST))
58 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) {
59 pr_emerg("Rebooting (with internal watchdog reset)...\n");
60 /* External WDRST failed. Do internal watchdog reset */
61 tx4938_ccfg_clear(TX4938_CCFG_WDREXEN);
67 void show_registers(struct pt_regs *regs);
68 static int tx4938_be_handler(struct pt_regs *regs, int is_fixup)
70 int data = regs->cp0_cause & 4;
72 pr_err("%cBE exception at %#lx\n", data ? 'D' : 'I', regs->cp0_epc);
73 pr_err("ccfg:%llx, toea:%llx\n",
74 (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
75 (unsigned long long)____raw_readq(&tx4938_ccfgptr->toea));
77 tx4927_report_pcic_status();
82 static void __init tx4938_be_init(void)
84 board_be_handler = tx4938_be_handler;
87 static struct resource tx4938_sdram_resource[4];
88 static struct resource tx4938_sram_resource;
90 #define TX4938_SRAM_SIZE 0x800
92 void __init tx4938_setup(void)
99 txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
101 set_c0_config(TX49_CONF_CWFON);
103 /* SDRAMC,EBUSC are configured by PROM */
104 for (i = 0; i < 8; i++) {
105 if (!(TX4938_EBUSC_CR(i) & 0x8))
106 continue; /* disabled */
107 txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
109 txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
110 request_resource(&iomem_resource, &txx9_ce_res[i]);
114 ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
115 if (txx9_master_clock) {
116 /* calculate gbus_clock and cpu_clock from master_clock */
117 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
119 case TX4938_CCFG_DIVMODE_8:
120 case TX4938_CCFG_DIVMODE_10:
121 case TX4938_CCFG_DIVMODE_12:
122 case TX4938_CCFG_DIVMODE_16:
123 case TX4938_CCFG_DIVMODE_18:
124 txx9_gbus_clock = txx9_master_clock * 4; break;
126 txx9_gbus_clock = txx9_master_clock;
129 case TX4938_CCFG_DIVMODE_2:
130 case TX4938_CCFG_DIVMODE_8:
131 cpuclk = txx9_gbus_clock * 2; break;
132 case TX4938_CCFG_DIVMODE_2_5:
133 case TX4938_CCFG_DIVMODE_10:
134 cpuclk = txx9_gbus_clock * 5 / 2; break;
135 case TX4938_CCFG_DIVMODE_3:
136 case TX4938_CCFG_DIVMODE_12:
137 cpuclk = txx9_gbus_clock * 3; break;
138 case TX4938_CCFG_DIVMODE_4:
139 case TX4938_CCFG_DIVMODE_16:
140 cpuclk = txx9_gbus_clock * 4; break;
141 case TX4938_CCFG_DIVMODE_4_5:
142 case TX4938_CCFG_DIVMODE_18:
143 cpuclk = txx9_gbus_clock * 9 / 2; break;
145 txx9_cpu_clock = cpuclk;
147 if (txx9_cpu_clock == 0)
148 txx9_cpu_clock = 300000000; /* 300MHz */
149 /* calculate gbus_clock and master_clock from cpu_clock */
150 cpuclk = txx9_cpu_clock;
151 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
153 case TX4938_CCFG_DIVMODE_2:
154 case TX4938_CCFG_DIVMODE_8:
155 txx9_gbus_clock = cpuclk / 2; break;
156 case TX4938_CCFG_DIVMODE_2_5:
157 case TX4938_CCFG_DIVMODE_10:
158 txx9_gbus_clock = cpuclk * 2 / 5; break;
159 case TX4938_CCFG_DIVMODE_3:
160 case TX4938_CCFG_DIVMODE_12:
161 txx9_gbus_clock = cpuclk / 3; break;
162 case TX4938_CCFG_DIVMODE_4:
163 case TX4938_CCFG_DIVMODE_16:
164 txx9_gbus_clock = cpuclk / 4; break;
165 case TX4938_CCFG_DIVMODE_4_5:
166 case TX4938_CCFG_DIVMODE_18:
167 txx9_gbus_clock = cpuclk * 2 / 9; break;
170 case TX4938_CCFG_DIVMODE_8:
171 case TX4938_CCFG_DIVMODE_10:
172 case TX4938_CCFG_DIVMODE_12:
173 case TX4938_CCFG_DIVMODE_16:
174 case TX4938_CCFG_DIVMODE_18:
175 txx9_master_clock = txx9_gbus_clock / 4; break;
177 txx9_master_clock = txx9_gbus_clock;
180 /* change default value to udelay/mdelay take reasonable time */
181 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
185 /* clear BusErrorOnWrite flag (W1C) */
186 tx4938_ccfg_set(TX4938_CCFG_BEOW);
187 /* enable Timeout BusError */
189 tx4938_ccfg_set(TX4938_CCFG_TOE);
192 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
194 /* Use external clock for external arbiter */
195 if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
196 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
198 printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
200 (cpuclk + 500000) / 1000000,
201 (txx9_master_clock + 500000) / 1000000,
202 (__u32)____raw_readq(&tx4938_ccfgptr->crir),
203 (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
204 (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
206 printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
207 for (i = 0; i < 4; i++) {
208 __u64 cr = TX4938_SDRAMC_CR(i);
209 unsigned long base, size;
210 if (!((__u32)cr & 0x00000400))
211 continue; /* disabled */
212 base = (unsigned long)(cr >> 49) << 21;
213 size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
214 printk(" CR%d:%016llx", i, (unsigned long long)cr);
215 tx4938_sdram_resource[i].name = "SDRAM";
216 tx4938_sdram_resource[i].start = base;
217 tx4938_sdram_resource[i].end = base + size - 1;
218 tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
219 request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
221 printk(" TR:%09llx\n",
222 (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
225 if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
226 unsigned int size = TX4938_SRAM_SIZE;
227 tx4938_sram_resource.name = "SRAM";
228 tx4938_sram_resource.start =
229 (____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
231 tx4938_sram_resource.end =
232 tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
233 tx4938_sram_resource.flags = IORESOURCE_MEM;
234 request_resource(&iomem_resource, &tx4938_sram_resource);
238 /* disable all timers */
239 for (i = 0; i < TX4938_NR_TMR; i++)
240 txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
243 for (i = 0; i < 2; i++)
244 ____raw_writeq(TX4938_DMA_MCR_MSTEN,
245 (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
248 txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
249 __raw_writel(0, &tx4938_pioptr->maskcpu);
250 __raw_writel(0, &tx4938_pioptr->maskext);
252 if (txx9_pcode == 0x4938) {
253 __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
254 /* set PCIC1 reset */
255 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
256 if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
257 mdelay(1); /* at least 128 cpu clock */
258 /* clear PCIC1 reset */
259 txx9_clear64(&tx4938_ccfgptr->clkctr,
260 TX4938_CLKCTR_PCIC1RST);
262 printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
264 txx9_set64(&tx4938_ccfgptr->clkctr,
265 TX4938_CLKCTR_PCIC1CKD);
267 if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
268 printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
269 txx9_set64(&tx4938_ccfgptr->clkctr,
270 TX4938_CLKCTR_ETH0RST);
271 txx9_set64(&tx4938_ccfgptr->clkctr,
272 TX4938_CLKCTR_ETH0CKD);
274 if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
275 printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
276 txx9_set64(&tx4938_ccfgptr->clkctr,
277 TX4938_CLKCTR_ETH1RST);
278 txx9_set64(&tx4938_ccfgptr->clkctr,
279 TX4938_CLKCTR_ETH1CKD);
283 _machine_restart = tx4938_machine_restart;
284 board_be_init = tx4938_be_init;
287 void __init tx4938_time_init(unsigned int tmrnr)
289 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
290 txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
291 TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
295 void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
298 unsigned int ch_mask = 0;
300 if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
301 ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
302 for (i = 0; i < 2; i++) {
303 if ((1 << i) & ch_mask)
305 txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
306 TXX9_IRQ_BASE + TX4938_IR_SIO(i),
307 i, sclk, (1 << i) & cts_mask);
311 void __init tx4938_spi_init(int busid)
313 txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
314 TXX9_IRQ_BASE + TX4938_IR_SPI);
317 void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
319 u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
321 if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
322 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
323 if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
324 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);
327 void __init tx4938_mtd_init(int ch)
329 struct physmap_flash_data pdata = {
330 .width = TX4938_EBUSC_WIDTH(ch) / 8,
332 unsigned long start = txx9_ce_res[ch].start;
333 unsigned long size = txx9_ce_res[ch].end - start + 1;
335 if (!(TX4938_EBUSC_CR(ch) & 0x8))
336 return; /* disabled */
337 txx9_physmap_flash_init(ch, start, size, &pdata);
340 void __init tx4938_ata_init(unsigned int irq, unsigned int shift, int tune)
342 struct platform_device *pdev;
343 struct resource res[] = {
345 /* .start and .end are filled in later */
346 .flags = IORESOURCE_MEM,
349 .flags = IORESOURCE_IRQ,
352 struct tx4938ide_platform_info pdata = {
353 .ioport_shift = shift,
355 * The IDE driver should not change bus timings if other ISA
358 .gbus_clock = tune ? txx9_gbus_clock : 0,
363 if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
364 (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL))
365 != TX4938_PCFG_ATA_SEL)
367 for (i = 0; i < 8; i++) {
368 /* check EBCCRn.ISA, EBCCRn.BSZ, EBCCRn.ME */
369 ebccr = __raw_readq(&tx4938_ebuscptr->cr[i]);
370 if ((ebccr & 0x00f00008) == 0x00e00008)
376 res[0].start = ((ebccr >> 48) << 20) + 0x10000;
377 res[0].end = res[0].start + 0x20000 - 1;
378 pdev = platform_device_alloc("tx4938ide", -1);
380 platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
381 platform_device_add_data(pdev, &pdata, sizeof(pdata)) ||
382 platform_device_add(pdev))
383 platform_device_put(pdev);
386 void __init tx4938_ndfmc_init(unsigned int hold, unsigned int spw)
388 struct txx9ndfmc_platform_data plat_data = {
390 .gbus_clock = txx9_gbus_clock,
395 unsigned long baseaddr = TX4938_NDFMC_REG & 0xfffffffffULL;
400 if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
401 (TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL)) ==
403 txx9_ndfmc_init(baseaddr, &plat_data);
406 static void __init tx4938_stop_unused_modules(void)
408 __u64 pcfg, rst = 0, ckd = 0;
413 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
414 switch (txx9_pcode) {
416 if (!(pcfg & TX4938_PCFG_SEL2)) {
417 rst |= TX4938_CLKCTR_ACLRST;
418 ckd |= TX4938_CLKCTR_ACLCKD;
419 strcat(buf, " ACLC");
423 if (!(pcfg & TX4938_PCFG_SEL2) ||
424 (pcfg & TX4938_PCFG_ETH0_SEL)) {
425 rst |= TX4938_CLKCTR_ACLRST;
426 ckd |= TX4938_CLKCTR_ACLCKD;
427 strcat(buf, " ACLC");
430 (TX4938_PCFG_ATA_SEL | TX4938_PCFG_ISA_SEL |
431 TX4938_PCFG_NDF_SEL))
432 != TX4938_PCFG_NDF_SEL) {
433 rst |= TX4938_CLKCTR_NDFRST;
434 ckd |= TX4938_CLKCTR_NDFCKD;
435 strcat(buf, " NDFMC");
437 if (!(pcfg & TX4938_PCFG_SPI_SEL)) {
438 rst |= TX4938_CLKCTR_SPIRST;
439 ckd |= TX4938_CLKCTR_SPICKD;
445 txx9_set64(&tx4938_ccfgptr->clkctr, rst);
446 txx9_set64(&tx4938_ccfgptr->clkctr, ckd);
450 pr_info("%s: stop%s\n", txx9_pcode_str, buf);
453 static int __init tx4938_late_init(void)
455 if (txx9_pcode != 0x4937 && txx9_pcode != 0x4938)
457 tx4938_stop_unused_modules();
460 late_initcall(tx4938_late_init);