2 * TX4939 setup routines
3 * Based on linux/arch/mips/txx9/generic/setup_tx4938.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/netdevice.h>
17 #include <linux/notifier.h>
18 #include <linux/sysdev.h>
19 #include <linux/ethtool.h>
20 #include <linux/param.h>
21 #include <linux/ptrace.h>
22 #include <linux/mtd/physmap.h>
23 #include <linux/platform_device.h>
24 #include <asm/bootinfo.h>
25 #include <asm/reboot.h>
26 #include <asm/traps.h>
27 #include <asm/txx9irq.h>
28 #include <asm/txx9tmr.h>
29 #include <asm/txx9/generic.h>
30 #include <asm/txx9/ndfmc.h>
31 #include <asm/txx9/tx4939.h>
33 static void __init tx4939_wdr_init(void)
35 /* report watchdog reset status */
36 if (____raw_readq(&tx4939_ccfgptr->ccfg) & TX4939_CCFG_WDRST)
37 pr_warning("Watchdog reset detected at 0x%lx\n",
39 /* clear WatchDogReset (W1C) */
40 tx4939_ccfg_set(TX4939_CCFG_WDRST);
41 /* do reset on watchdog */
42 tx4939_ccfg_set(TX4939_CCFG_WR);
45 void __init tx4939_wdt_init(void)
47 txx9_wdt_init(TX4939_TMR_REG(2) & 0xfffffffffULL);
50 static void tx4939_machine_restart(char *command)
53 pr_emerg("Rebooting (with %s watchdog reset)...\n",
54 (____raw_readq(&tx4939_ccfgptr->ccfg) & TX4939_CCFG_WDREXEN) ?
55 "external" : "internal");
56 /* clear watchdog status */
57 tx4939_ccfg_set(TX4939_CCFG_WDRST); /* W1C */
58 txx9_wdt_now(TX4939_TMR_REG(2) & 0xfffffffffULL);
59 while (!(____raw_readq(&tx4939_ccfgptr->ccfg) & TX4939_CCFG_WDRST))
62 if (____raw_readq(&tx4939_ccfgptr->ccfg) & TX4939_CCFG_WDREXEN) {
63 pr_emerg("Rebooting (with internal watchdog reset)...\n");
64 /* External WDRST failed. Do internal watchdog reset */
65 tx4939_ccfg_clear(TX4939_CCFG_WDREXEN);
71 void show_registers(struct pt_regs *regs);
72 static int tx4939_be_handler(struct pt_regs *regs, int is_fixup)
74 int data = regs->cp0_cause & 4;
76 pr_err("%cBE exception at %#lx\n",
77 data ? 'D' : 'I', regs->cp0_epc);
78 pr_err("ccfg:%llx, toea:%llx\n",
79 (unsigned long long)____raw_readq(&tx4939_ccfgptr->ccfg),
80 (unsigned long long)____raw_readq(&tx4939_ccfgptr->toea));
82 tx4927_report_pcic_status();
87 static void __init tx4939_be_init(void)
89 board_be_handler = tx4939_be_handler;
92 static struct resource tx4939_sdram_resource[4];
93 static struct resource tx4939_sram_resource;
94 #define TX4939_SRAM_SIZE 0x800
96 void __init tx4939_add_memory_regions(void)
99 unsigned long start, size;
102 for (i = 0; i < 4; i++) {
103 if (!((__u32)____raw_readq(&tx4939_ddrcptr->winen) & (1 << i)))
105 win = ____raw_readq(&tx4939_ddrcptr->win[i]);
106 start = (unsigned long)(win >> 48);
107 size = (((unsigned long)(win >> 32) & 0xffff) + 1) - start;
108 add_memory_region(start << 20, size << 20, BOOT_MEM_RAM);
112 void __init tx4939_setup(void)
117 unsigned int cpuclk = 0;
119 txx9_reg_res_init(TX4939_REV_PCODE(), TX4939_REG_BASE,
121 set_c0_config(TX49_CONF_CWFON);
123 /* SDRAMC,EBUSC are configured by PROM */
124 for (i = 0; i < 4; i++) {
125 if (!(TX4939_EBUSC_CR(i) & 0x8))
126 continue; /* disabled */
127 txx9_ce_res[i].start = (unsigned long)TX4939_EBUSC_BA(i);
129 txx9_ce_res[i].start + TX4939_EBUSC_SIZE(i) - 1;
130 request_resource(&iomem_resource, &txx9_ce_res[i]);
134 if (txx9_master_clock) {
135 /* calculate cpu_clock from master_clock */
136 divmode = (__u32)____raw_readq(&tx4939_ccfgptr->ccfg) &
137 TX4939_CCFG_MULCLK_MASK;
138 cpuclk = txx9_master_clock * 20 / 2;
140 case TX4939_CCFG_MULCLK_8:
141 cpuclk = cpuclk / 3 * 4 /* / 6 * 8 */; break;
142 case TX4939_CCFG_MULCLK_9:
143 cpuclk = cpuclk / 2 * 3 /* / 6 * 9 */; break;
144 case TX4939_CCFG_MULCLK_10:
145 cpuclk = cpuclk / 3 * 5 /* / 6 * 10 */; break;
146 case TX4939_CCFG_MULCLK_11:
147 cpuclk = cpuclk / 6 * 11; break;
148 case TX4939_CCFG_MULCLK_12:
149 cpuclk = cpuclk * 2 /* / 6 * 12 */; break;
150 case TX4939_CCFG_MULCLK_13:
151 cpuclk = cpuclk / 6 * 13; break;
152 case TX4939_CCFG_MULCLK_14:
153 cpuclk = cpuclk / 3 * 7 /* / 6 * 14 */; break;
154 case TX4939_CCFG_MULCLK_15:
155 cpuclk = cpuclk / 2 * 5 /* / 6 * 15 */; break;
157 txx9_cpu_clock = cpuclk;
159 if (txx9_cpu_clock == 0)
160 txx9_cpu_clock = 400000000; /* 400MHz */
161 /* calculate master_clock from cpu_clock */
162 cpuclk = txx9_cpu_clock;
163 divmode = (__u32)____raw_readq(&tx4939_ccfgptr->ccfg) &
164 TX4939_CCFG_MULCLK_MASK;
166 case TX4939_CCFG_MULCLK_8:
167 txx9_master_clock = cpuclk * 6 / 8; break;
168 case TX4939_CCFG_MULCLK_9:
169 txx9_master_clock = cpuclk * 6 / 9; break;
170 case TX4939_CCFG_MULCLK_10:
171 txx9_master_clock = cpuclk * 6 / 10; break;
172 case TX4939_CCFG_MULCLK_11:
173 txx9_master_clock = cpuclk * 6 / 11; break;
174 case TX4939_CCFG_MULCLK_12:
175 txx9_master_clock = cpuclk * 6 / 12; break;
176 case TX4939_CCFG_MULCLK_13:
177 txx9_master_clock = cpuclk * 6 / 13; break;
178 case TX4939_CCFG_MULCLK_14:
179 txx9_master_clock = cpuclk * 6 / 14; break;
180 case TX4939_CCFG_MULCLK_15:
181 txx9_master_clock = cpuclk * 6 / 15; break;
183 txx9_master_clock /= 10; /* * 2 / 20 */
185 /* calculate gbus_clock from cpu_clock */
186 divmode = (__u32)____raw_readq(&tx4939_ccfgptr->ccfg) &
187 TX4939_CCFG_YDIVMODE_MASK;
188 txx9_gbus_clock = txx9_cpu_clock;
190 case TX4939_CCFG_YDIVMODE_2:
191 txx9_gbus_clock /= 2; break;
192 case TX4939_CCFG_YDIVMODE_3:
193 txx9_gbus_clock /= 3; break;
194 case TX4939_CCFG_YDIVMODE_5:
195 txx9_gbus_clock /= 5; break;
196 case TX4939_CCFG_YDIVMODE_6:
197 txx9_gbus_clock /= 6; break;
199 /* change default value to udelay/mdelay take reasonable time */
200 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
204 /* clear BusErrorOnWrite flag (W1C) */
205 tx4939_ccfg_set(TX4939_CCFG_WDRST | TX4939_CCFG_BEOW);
206 /* enable Timeout BusError */
208 tx4939_ccfg_set(TX4939_CCFG_TOE);
211 txx9_clear64(&tx4939_ccfgptr->pcfg, TX4939_PCFG_DMASEL_ALL);
213 /* Use external clock for external arbiter */
214 if (!(____raw_readq(&tx4939_ccfgptr->ccfg) & TX4939_CCFG_PCIARB))
215 txx9_clear64(&tx4939_ccfgptr->pcfg, TX4939_PCFG_PCICLKEN_ALL);
217 pr_info("%s -- %dMHz(M%dMHz,G%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
219 (cpuclk + 500000) / 1000000,
220 (txx9_master_clock + 500000) / 1000000,
221 (txx9_gbus_clock + 500000) / 1000000,
222 (__u32)____raw_readq(&tx4939_ccfgptr->crir),
223 (unsigned long long)____raw_readq(&tx4939_ccfgptr->ccfg),
224 (unsigned long long)____raw_readq(&tx4939_ccfgptr->pcfg));
226 pr_info("%s DDRC -- EN:%08x", txx9_pcode_str,
227 (__u32)____raw_readq(&tx4939_ddrcptr->winen));
228 for (i = 0; i < 4; i++) {
229 __u64 win = ____raw_readq(&tx4939_ddrcptr->win[i]);
230 if (!((__u32)____raw_readq(&tx4939_ddrcptr->winen) & (1 << i)))
231 continue; /* disabled */
232 printk(KERN_CONT " #%d:%016llx", i, (unsigned long long)win);
233 tx4939_sdram_resource[i].name = "DDR SDRAM";
234 tx4939_sdram_resource[i].start =
235 (unsigned long)(win >> 48) << 20;
236 tx4939_sdram_resource[i].end =
237 ((((unsigned long)(win >> 32) & 0xffff) + 1) <<
239 tx4939_sdram_resource[i].flags = IORESOURCE_MEM;
240 request_resource(&iomem_resource, &tx4939_sdram_resource[i]);
242 printk(KERN_CONT "\n");
245 if (____raw_readq(&tx4939_sramcptr->cr) & 1) {
246 unsigned int size = TX4939_SRAM_SIZE;
247 tx4939_sram_resource.name = "SRAM";
248 tx4939_sram_resource.start =
249 (____raw_readq(&tx4939_sramcptr->cr) >> (39-11))
251 tx4939_sram_resource.end =
252 tx4939_sram_resource.start + TX4939_SRAM_SIZE - 1;
253 tx4939_sram_resource.flags = IORESOURCE_MEM;
254 request_resource(&iomem_resource, &tx4939_sram_resource);
258 /* disable all timers */
259 for (i = 0; i < TX4939_NR_TMR; i++)
260 txx9_tmr_init(TX4939_TMR_REG(i) & 0xfffffffffULL);
263 for (i = 0; i < 2; i++)
264 ____raw_writeq(TX4938_DMA_MCR_MSTEN,
265 (void __iomem *)(TX4939_DMA_REG(i) + 0x50));
267 /* set PCIC1 reset (required to prevent hangup on BIST) */
268 txx9_set64(&tx4939_ccfgptr->clkctr, TX4939_CLKCTR_PCI1RST);
269 pcfg = ____raw_readq(&tx4939_ccfgptr->pcfg);
270 if (pcfg & (TX4939_PCFG_ET0MODE | TX4939_PCFG_ET1MODE)) {
271 mdelay(1); /* at least 128 cpu clock */
272 /* clear PCIC1 reset */
273 txx9_clear64(&tx4939_ccfgptr->clkctr, TX4939_CLKCTR_PCI1RST);
275 pr_info("%s: stop PCIC1\n", txx9_pcode_str);
277 txx9_set64(&tx4939_ccfgptr->clkctr, TX4939_CLKCTR_PCI1CKD);
279 if (!(pcfg & TX4939_PCFG_ET0MODE)) {
280 pr_info("%s: stop ETH0\n", txx9_pcode_str);
281 txx9_set64(&tx4939_ccfgptr->clkctr, TX4939_CLKCTR_ETH0RST);
282 txx9_set64(&tx4939_ccfgptr->clkctr, TX4939_CLKCTR_ETH0CKD);
284 if (!(pcfg & TX4939_PCFG_ET1MODE)) {
285 pr_info("%s: stop ETH1\n", txx9_pcode_str);
286 txx9_set64(&tx4939_ccfgptr->clkctr, TX4939_CLKCTR_ETH1RST);
287 txx9_set64(&tx4939_ccfgptr->clkctr, TX4939_CLKCTR_ETH1CKD);
290 _machine_restart = tx4939_machine_restart;
291 board_be_init = tx4939_be_init;
294 void __init tx4939_time_init(unsigned int tmrnr)
296 if (____raw_readq(&tx4939_ccfgptr->ccfg) & TX4939_CCFG_TINTDIS)
297 txx9_clockevent_init(TX4939_TMR_REG(tmrnr) & 0xfffffffffULL,
298 TXX9_IRQ_BASE + TX4939_IR_TMR(tmrnr),
302 void __init tx4939_sio_init(unsigned int sclk, unsigned int cts_mask)
305 unsigned int ch_mask = 0;
306 __u64 pcfg = __raw_readq(&tx4939_ccfgptr->pcfg);
308 cts_mask |= ~1; /* only SIO0 have RTS/CTS */
309 if ((pcfg & TX4939_PCFG_SIO2MODE_MASK) != TX4939_PCFG_SIO2MODE_SIO0)
310 cts_mask |= 1 << 0; /* disable SIO0 RTS/CTS by PCFG setting */
311 if ((pcfg & TX4939_PCFG_SIO2MODE_MASK) != TX4939_PCFG_SIO2MODE_SIO2)
312 ch_mask |= 1 << 2; /* disable SIO2 by PCFG setting */
313 if (pcfg & TX4939_PCFG_SIO3MODE)
314 ch_mask |= 1 << 3; /* disable SIO3 by PCFG setting */
315 for (i = 0; i < 4; i++) {
316 if ((1 << i) & ch_mask)
318 txx9_sio_init(TX4939_SIO_REG(i) & 0xfffffffffULL,
319 TXX9_IRQ_BASE + TX4939_IR_SIO(i),
320 i, sclk, (1 << i) & cts_mask);
324 #if defined(CONFIG_TC35815) || defined(CONFIG_TC35815_MODULE)
325 static int tx4939_get_eth_speed(struct net_device *dev)
327 struct ethtool_cmd cmd = { ETHTOOL_GSET };
328 int speed = 100; /* default 100Mbps */
330 if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings)
332 err = dev->ethtool_ops->get_settings(dev, &cmd);
335 speed = cmd.speed == SPEED_100 ? 100 : 10;
338 static int tx4939_netdev_event(struct notifier_block *this,
342 struct net_device *dev = ptr;
343 if (event == NETDEV_CHANGE && netif_carrier_ok(dev)) {
345 if (dev->irq == TXX9_IRQ_BASE + TX4939_IR_ETH(0))
346 bit = TX4939_PCFG_SPEED0;
347 else if (dev->irq == TXX9_IRQ_BASE + TX4939_IR_ETH(1))
348 bit = TX4939_PCFG_SPEED1;
350 int speed = tx4939_get_eth_speed(dev);
352 txx9_set64(&tx4939_ccfgptr->pcfg, bit);
354 txx9_clear64(&tx4939_ccfgptr->pcfg, bit);
360 static struct notifier_block tx4939_netdev_notifier = {
361 .notifier_call = tx4939_netdev_event,
365 void __init tx4939_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
367 u64 pcfg = __raw_readq(&tx4939_ccfgptr->pcfg);
369 if (addr0 && (pcfg & TX4939_PCFG_ET0MODE))
370 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4939_IR_ETH(0), addr0);
371 if (addr1 && (pcfg & TX4939_PCFG_ET1MODE))
372 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4939_IR_ETH(1), addr1);
373 register_netdevice_notifier(&tx4939_netdev_notifier);
376 void __init tx4939_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
381 void __init tx4939_mtd_init(int ch)
383 struct physmap_flash_data pdata = {
384 .width = TX4939_EBUSC_WIDTH(ch) / 8,
386 unsigned long start = txx9_ce_res[ch].start;
387 unsigned long size = txx9_ce_res[ch].end - start + 1;
389 if (!(TX4939_EBUSC_CR(ch) & 0x8))
390 return; /* disabled */
391 txx9_physmap_flash_init(ch, start, size, &pdata);
394 #define TX4939_ATA_REG_PHYS(ch) (TX4939_ATA_REG(ch) & 0xfffffffffULL)
395 void __init tx4939_ata_init(void)
397 static struct resource ata0_res[] = {
399 .start = TX4939_ATA_REG_PHYS(0),
400 .end = TX4939_ATA_REG_PHYS(0) + 0x1000 - 1,
401 .flags = IORESOURCE_MEM,
403 .start = TXX9_IRQ_BASE + TX4939_IR_ATA(0),
404 .flags = IORESOURCE_IRQ,
407 static struct resource ata1_res[] = {
409 .start = TX4939_ATA_REG_PHYS(1),
410 .end = TX4939_ATA_REG_PHYS(1) + 0x1000 - 1,
411 .flags = IORESOURCE_MEM,
413 .start = TXX9_IRQ_BASE + TX4939_IR_ATA(1),
414 .flags = IORESOURCE_IRQ,
417 static struct platform_device ata0_dev = {
420 .num_resources = ARRAY_SIZE(ata0_res),
421 .resource = ata0_res,
423 static struct platform_device ata1_dev = {
426 .num_resources = ARRAY_SIZE(ata1_res),
427 .resource = ata1_res,
429 __u64 pcfg = __raw_readq(&tx4939_ccfgptr->pcfg);
431 if (pcfg & TX4939_PCFG_ATA0MODE)
432 platform_device_register(&ata0_dev);
433 if ((pcfg & (TX4939_PCFG_ATA1MODE |
434 TX4939_PCFG_ET1MODE |
435 TX4939_PCFG_ET0MODE)) == TX4939_PCFG_ATA1MODE)
436 platform_device_register(&ata1_dev);
439 void __init tx4939_rtc_init(void)
441 static struct resource res[] = {
443 .start = TX4939_RTC_REG & 0xfffffffffULL,
444 .end = (TX4939_RTC_REG & 0xfffffffffULL) + 0x100 - 1,
445 .flags = IORESOURCE_MEM,
447 .start = TXX9_IRQ_BASE + TX4939_IR_RTC,
448 .flags = IORESOURCE_IRQ,
451 static struct platform_device rtc_dev = {
454 .num_resources = ARRAY_SIZE(res),
458 platform_device_register(&rtc_dev);
461 void __init tx4939_ndfmc_init(unsigned int hold, unsigned int spw,
462 unsigned char ch_mask, unsigned char wide_mask)
464 struct txx9ndfmc_platform_data plat_data = {
466 .gbus_clock = txx9_gbus_clock,
469 .flags = NDFMC_PLAT_FLAG_NO_RSTR | NDFMC_PLAT_FLAG_HOLDADD |
470 NDFMC_PLAT_FLAG_DUMMYWRITE,
472 .wide_mask = wide_mask,
474 txx9_ndfmc_init(TX4939_NDFMC_REG & 0xfffffffffULL, &plat_data);
477 static void __init tx4939_stop_unused_modules(void)
479 __u64 pcfg, rst = 0, ckd = 0;
484 pcfg = ____raw_readq(&tx4939_ccfgptr->pcfg);
485 if ((pcfg & TX4939_PCFG_I2SMODE_MASK) !=
486 TX4939_PCFG_I2SMODE_ACLC) {
487 rst |= TX4939_CLKCTR_ACLRST;
488 ckd |= TX4939_CLKCTR_ACLCKD;
489 strcat(buf, " ACLC");
491 if ((pcfg & TX4939_PCFG_I2SMODE_MASK) !=
492 TX4939_PCFG_I2SMODE_I2S &&
493 (pcfg & TX4939_PCFG_I2SMODE_MASK) !=
494 TX4939_PCFG_I2SMODE_I2S_ALT) {
495 rst |= TX4939_CLKCTR_I2SRST;
496 ckd |= TX4939_CLKCTR_I2SCKD;
499 if (!(pcfg & TX4939_PCFG_ATA0MODE)) {
500 rst |= TX4939_CLKCTR_ATA0RST;
501 ckd |= TX4939_CLKCTR_ATA0CKD;
502 strcat(buf, " ATA0");
504 if (!(pcfg & TX4939_PCFG_ATA1MODE)) {
505 rst |= TX4939_CLKCTR_ATA1RST;
506 ckd |= TX4939_CLKCTR_ATA1CKD;
507 strcat(buf, " ATA1");
509 if (pcfg & TX4939_PCFG_SPIMODE) {
510 rst |= TX4939_CLKCTR_SPIRST;
511 ckd |= TX4939_CLKCTR_SPICKD;
514 if (!(pcfg & (TX4939_PCFG_VSSMODE | TX4939_PCFG_VPSMODE))) {
515 rst |= TX4939_CLKCTR_VPCRST;
516 ckd |= TX4939_CLKCTR_VPCCKD;
519 if ((pcfg & TX4939_PCFG_SIO2MODE_MASK) != TX4939_PCFG_SIO2MODE_SIO2) {
520 rst |= TX4939_CLKCTR_SIO2RST;
521 ckd |= TX4939_CLKCTR_SIO2CKD;
522 strcat(buf, " SIO2");
524 if (pcfg & TX4939_PCFG_SIO3MODE) {
525 rst |= TX4939_CLKCTR_SIO3RST;
526 ckd |= TX4939_CLKCTR_SIO3CKD;
527 strcat(buf, " SIO3");
530 txx9_set64(&tx4939_ccfgptr->clkctr, rst);
531 txx9_set64(&tx4939_ccfgptr->clkctr, ckd);
535 pr_info("%s: stop%s\n", txx9_pcode_str, buf);
538 static int __init tx4939_late_init(void)
540 if (txx9_pcode != 0x4939)
542 tx4939_stop_unused_modules();
545 late_initcall(tx4939_late_init);