xref: /openbmc/linux/arch/mips/txx9/generic/setup_tx4938.c (revision 5d1d2f8c26f2d197df1f4b6a7f4c0088b190343e)
194a4c329SAtsushi Nemoto /*
294a4c329SAtsushi Nemoto  * TX4938/4937 setup routines
394a4c329SAtsushi Nemoto  * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
494a4c329SAtsushi Nemoto  *	    and RBTX49xx patch from CELF patch archive.
594a4c329SAtsushi Nemoto  *
694a4c329SAtsushi Nemoto  * 2003-2005 (c) MontaVista Software, Inc.
794a4c329SAtsushi Nemoto  * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
894a4c329SAtsushi Nemoto  *
994a4c329SAtsushi Nemoto  * This file is subject to the terms and conditions of the GNU General Public
1094a4c329SAtsushi Nemoto  * License.  See the file "COPYING" in the main directory of this archive
1194a4c329SAtsushi Nemoto  * for more details.
1294a4c329SAtsushi Nemoto  */
1394a4c329SAtsushi Nemoto #include <linux/init.h>
1494a4c329SAtsushi Nemoto #include <linux/ioport.h>
1594a4c329SAtsushi Nemoto #include <linux/delay.h>
1694a4c329SAtsushi Nemoto #include <linux/param.h>
17ce8e7411SAtsushi Nemoto #include <linux/ptrace.h>
1851f607c7SAtsushi Nemoto #include <linux/mtd/physmap.h>
19*5d1d2f8cSAtsushi Nemoto #include <linux/platform_device.h>
20496a3b5cSAtsushi Nemoto #include <asm/reboot.h>
21ce8e7411SAtsushi Nemoto #include <asm/traps.h>
2294a4c329SAtsushi Nemoto #include <asm/txx9irq.h>
2394a4c329SAtsushi Nemoto #include <asm/txx9tmr.h>
2494a4c329SAtsushi Nemoto #include <asm/txx9pio.h>
2594a4c329SAtsushi Nemoto #include <asm/txx9/generic.h>
2694a4c329SAtsushi Nemoto #include <asm/txx9/tx4938.h>
2794a4c329SAtsushi Nemoto 
2868314725SAtsushi Nemoto static void __init tx4938_wdr_init(void)
2994a4c329SAtsushi Nemoto {
30496a3b5cSAtsushi Nemoto 	/* report watchdog reset status */
31496a3b5cSAtsushi Nemoto 	if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST)
32496a3b5cSAtsushi Nemoto 		pr_warning("Watchdog reset detected at 0x%lx\n",
33496a3b5cSAtsushi Nemoto 			   read_c0_errorepc());
3494a4c329SAtsushi Nemoto 	/* clear WatchDogReset (W1C) */
3594a4c329SAtsushi Nemoto 	tx4938_ccfg_set(TX4938_CCFG_WDRST);
3694a4c329SAtsushi Nemoto 	/* do reset on watchdog */
3794a4c329SAtsushi Nemoto 	tx4938_ccfg_set(TX4938_CCFG_WR);
3894a4c329SAtsushi Nemoto }
3994a4c329SAtsushi Nemoto 
4068314725SAtsushi Nemoto void __init tx4938_wdt_init(void)
4168314725SAtsushi Nemoto {
4268314725SAtsushi Nemoto 	txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
4368314725SAtsushi Nemoto }
4468314725SAtsushi Nemoto 
45496a3b5cSAtsushi Nemoto static void tx4938_machine_restart(char *command)
46496a3b5cSAtsushi Nemoto {
47496a3b5cSAtsushi Nemoto 	local_irq_disable();
48496a3b5cSAtsushi Nemoto 	pr_emerg("Rebooting (with %s watchdog reset)...\n",
49496a3b5cSAtsushi Nemoto 		 (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ?
50496a3b5cSAtsushi Nemoto 		 "external" : "internal");
51496a3b5cSAtsushi Nemoto 	/* clear watchdog status */
52496a3b5cSAtsushi Nemoto 	tx4938_ccfg_set(TX4938_CCFG_WDRST);	/* W1C */
53496a3b5cSAtsushi Nemoto 	txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL);
54496a3b5cSAtsushi Nemoto 	while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST))
55496a3b5cSAtsushi Nemoto 		;
56496a3b5cSAtsushi Nemoto 	mdelay(10);
57496a3b5cSAtsushi Nemoto 	if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) {
58496a3b5cSAtsushi Nemoto 		pr_emerg("Rebooting (with internal watchdog reset)...\n");
59496a3b5cSAtsushi Nemoto 		/* External WDRST failed.  Do internal watchdog reset */
60496a3b5cSAtsushi Nemoto 		tx4938_ccfg_clear(TX4938_CCFG_WDREXEN);
61496a3b5cSAtsushi Nemoto 	}
62496a3b5cSAtsushi Nemoto 	/* fallback */
63496a3b5cSAtsushi Nemoto 	(*_machine_halt)();
64496a3b5cSAtsushi Nemoto }
65496a3b5cSAtsushi Nemoto 
66ce8e7411SAtsushi Nemoto void show_registers(struct pt_regs *regs);
67ce8e7411SAtsushi Nemoto static int tx4938_be_handler(struct pt_regs *regs, int is_fixup)
68ce8e7411SAtsushi Nemoto {
69ce8e7411SAtsushi Nemoto 	int data = regs->cp0_cause & 4;
70ce8e7411SAtsushi Nemoto 	console_verbose();
71ce8e7411SAtsushi Nemoto 	pr_err("%cBE exception at %#lx\n", data ? 'D' : 'I', regs->cp0_epc);
72ce8e7411SAtsushi Nemoto 	pr_err("ccfg:%llx, toea:%llx\n",
73ce8e7411SAtsushi Nemoto 	       (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
74ce8e7411SAtsushi Nemoto 	       (unsigned long long)____raw_readq(&tx4938_ccfgptr->toea));
75ce8e7411SAtsushi Nemoto #ifdef CONFIG_PCI
76ce8e7411SAtsushi Nemoto 	tx4927_report_pcic_status();
77ce8e7411SAtsushi Nemoto #endif
78ce8e7411SAtsushi Nemoto 	show_registers(regs);
79ce8e7411SAtsushi Nemoto 	panic("BusError!");
80ce8e7411SAtsushi Nemoto }
81ce8e7411SAtsushi Nemoto static void __init tx4938_be_init(void)
82ce8e7411SAtsushi Nemoto {
83ce8e7411SAtsushi Nemoto 	board_be_handler = tx4938_be_handler;
84ce8e7411SAtsushi Nemoto }
85ce8e7411SAtsushi Nemoto 
8694a4c329SAtsushi Nemoto static struct resource tx4938_sdram_resource[4];
8794a4c329SAtsushi Nemoto static struct resource tx4938_sram_resource;
8894a4c329SAtsushi Nemoto 
8994a4c329SAtsushi Nemoto #define TX4938_SRAM_SIZE 0x800
9094a4c329SAtsushi Nemoto 
9194a4c329SAtsushi Nemoto void __init tx4938_setup(void)
9294a4c329SAtsushi Nemoto {
9394a4c329SAtsushi Nemoto 	int i;
9494a4c329SAtsushi Nemoto 	__u32 divmode;
9594a4c329SAtsushi Nemoto 	int cpuclk = 0;
9694a4c329SAtsushi Nemoto 	u64 ccfg;
9794a4c329SAtsushi Nemoto 
9894a4c329SAtsushi Nemoto 	txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
9994a4c329SAtsushi Nemoto 			  TX4938_REG_SIZE);
100d10e025fSAtsushi Nemoto 	set_c0_config(TX49_CONF_CWFON);
10194a4c329SAtsushi Nemoto 
10294a4c329SAtsushi Nemoto 	/* SDRAMC,EBUSC are configured by PROM */
10394a4c329SAtsushi Nemoto 	for (i = 0; i < 8; i++) {
10494a4c329SAtsushi Nemoto 		if (!(TX4938_EBUSC_CR(i) & 0x8))
10594a4c329SAtsushi Nemoto 			continue;	/* disabled */
10694a4c329SAtsushi Nemoto 		txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
10794a4c329SAtsushi Nemoto 		txx9_ce_res[i].end =
10894a4c329SAtsushi Nemoto 			txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
10994a4c329SAtsushi Nemoto 		request_resource(&iomem_resource, &txx9_ce_res[i]);
11094a4c329SAtsushi Nemoto 	}
11194a4c329SAtsushi Nemoto 
11294a4c329SAtsushi Nemoto 	/* clocks */
11394a4c329SAtsushi Nemoto 	ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
11494a4c329SAtsushi Nemoto 	if (txx9_master_clock) {
11594a4c329SAtsushi Nemoto 		/* calculate gbus_clock and cpu_clock from master_clock */
11694a4c329SAtsushi Nemoto 		divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
11794a4c329SAtsushi Nemoto 		switch (divmode) {
11894a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_8:
11994a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_10:
12094a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_12:
12194a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_16:
12294a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_18:
12394a4c329SAtsushi Nemoto 			txx9_gbus_clock = txx9_master_clock * 4; break;
12494a4c329SAtsushi Nemoto 		default:
12594a4c329SAtsushi Nemoto 			txx9_gbus_clock = txx9_master_clock;
12694a4c329SAtsushi Nemoto 		}
12794a4c329SAtsushi Nemoto 		switch (divmode) {
12894a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_2:
12994a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_8:
13094a4c329SAtsushi Nemoto 			cpuclk = txx9_gbus_clock * 2; break;
13194a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_2_5:
13294a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_10:
13394a4c329SAtsushi Nemoto 			cpuclk = txx9_gbus_clock * 5 / 2; break;
13494a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_3:
13594a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_12:
13694a4c329SAtsushi Nemoto 			cpuclk = txx9_gbus_clock * 3; break;
13794a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_4:
13894a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_16:
13994a4c329SAtsushi Nemoto 			cpuclk = txx9_gbus_clock * 4; break;
14094a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_4_5:
14194a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_18:
14294a4c329SAtsushi Nemoto 			cpuclk = txx9_gbus_clock * 9 / 2; break;
14394a4c329SAtsushi Nemoto 		}
14494a4c329SAtsushi Nemoto 		txx9_cpu_clock = cpuclk;
14594a4c329SAtsushi Nemoto 	} else {
14694a4c329SAtsushi Nemoto 		if (txx9_cpu_clock == 0)
14794a4c329SAtsushi Nemoto 			txx9_cpu_clock = 300000000;	/* 300MHz */
14894a4c329SAtsushi Nemoto 		/* calculate gbus_clock and master_clock from cpu_clock */
14994a4c329SAtsushi Nemoto 		cpuclk = txx9_cpu_clock;
15094a4c329SAtsushi Nemoto 		divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
15194a4c329SAtsushi Nemoto 		switch (divmode) {
15294a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_2:
15394a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_8:
15494a4c329SAtsushi Nemoto 			txx9_gbus_clock = cpuclk / 2; break;
15594a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_2_5:
15694a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_10:
15794a4c329SAtsushi Nemoto 			txx9_gbus_clock = cpuclk * 2 / 5; break;
15894a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_3:
15994a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_12:
16094a4c329SAtsushi Nemoto 			txx9_gbus_clock = cpuclk / 3; break;
16194a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_4:
16294a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_16:
16394a4c329SAtsushi Nemoto 			txx9_gbus_clock = cpuclk / 4; break;
16494a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_4_5:
16594a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_18:
16694a4c329SAtsushi Nemoto 			txx9_gbus_clock = cpuclk * 2 / 9; break;
16794a4c329SAtsushi Nemoto 		}
16894a4c329SAtsushi Nemoto 		switch (divmode) {
16994a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_8:
17094a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_10:
17194a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_12:
17294a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_16:
17394a4c329SAtsushi Nemoto 		case TX4938_CCFG_DIVMODE_18:
17494a4c329SAtsushi Nemoto 			txx9_master_clock = txx9_gbus_clock / 4; break;
17594a4c329SAtsushi Nemoto 		default:
17694a4c329SAtsushi Nemoto 			txx9_master_clock = txx9_gbus_clock;
17794a4c329SAtsushi Nemoto 		}
17894a4c329SAtsushi Nemoto 	}
17994a4c329SAtsushi Nemoto 	/* change default value to udelay/mdelay take reasonable time */
18094a4c329SAtsushi Nemoto 	loops_per_jiffy = txx9_cpu_clock / HZ / 2;
18194a4c329SAtsushi Nemoto 
18294a4c329SAtsushi Nemoto 	/* CCFG */
18394a4c329SAtsushi Nemoto 	tx4938_wdr_init();
18494a4c329SAtsushi Nemoto 	/* clear BusErrorOnWrite flag (W1C) */
18594a4c329SAtsushi Nemoto 	tx4938_ccfg_set(TX4938_CCFG_BEOW);
18694a4c329SAtsushi Nemoto 	/* enable Timeout BusError */
18794a4c329SAtsushi Nemoto 	if (txx9_ccfg_toeon)
18894a4c329SAtsushi Nemoto 		tx4938_ccfg_set(TX4938_CCFG_TOE);
18994a4c329SAtsushi Nemoto 
19094a4c329SAtsushi Nemoto 	/* DMA selection */
19194a4c329SAtsushi Nemoto 	txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
19294a4c329SAtsushi Nemoto 
19394a4c329SAtsushi Nemoto 	/* Use external clock for external arbiter */
19494a4c329SAtsushi Nemoto 	if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
19594a4c329SAtsushi Nemoto 		txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
19694a4c329SAtsushi Nemoto 
19794a4c329SAtsushi Nemoto 	printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
19894a4c329SAtsushi Nemoto 	       txx9_pcode_str,
19994a4c329SAtsushi Nemoto 	       (cpuclk + 500000) / 1000000,
20094a4c329SAtsushi Nemoto 	       (txx9_master_clock + 500000) / 1000000,
20194a4c329SAtsushi Nemoto 	       (__u32)____raw_readq(&tx4938_ccfgptr->crir),
20294a4c329SAtsushi Nemoto 	       (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
20394a4c329SAtsushi Nemoto 	       (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
20494a4c329SAtsushi Nemoto 
20594a4c329SAtsushi Nemoto 	printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
20694a4c329SAtsushi Nemoto 	for (i = 0; i < 4; i++) {
20794a4c329SAtsushi Nemoto 		__u64 cr = TX4938_SDRAMC_CR(i);
20894a4c329SAtsushi Nemoto 		unsigned long base, size;
20994a4c329SAtsushi Nemoto 		if (!((__u32)cr & 0x00000400))
21094a4c329SAtsushi Nemoto 			continue;	/* disabled */
21194a4c329SAtsushi Nemoto 		base = (unsigned long)(cr >> 49) << 21;
21294a4c329SAtsushi Nemoto 		size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
21394a4c329SAtsushi Nemoto 		printk(" CR%d:%016llx", i, (unsigned long long)cr);
21494a4c329SAtsushi Nemoto 		tx4938_sdram_resource[i].name = "SDRAM";
21594a4c329SAtsushi Nemoto 		tx4938_sdram_resource[i].start = base;
21694a4c329SAtsushi Nemoto 		tx4938_sdram_resource[i].end = base + size - 1;
21794a4c329SAtsushi Nemoto 		tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
21894a4c329SAtsushi Nemoto 		request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
21994a4c329SAtsushi Nemoto 	}
22094a4c329SAtsushi Nemoto 	printk(" TR:%09llx\n",
22194a4c329SAtsushi Nemoto 	       (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
22294a4c329SAtsushi Nemoto 
22394a4c329SAtsushi Nemoto 	/* SRAM */
22494a4c329SAtsushi Nemoto 	if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
22594a4c329SAtsushi Nemoto 		unsigned int size = TX4938_SRAM_SIZE;
22694a4c329SAtsushi Nemoto 		tx4938_sram_resource.name = "SRAM";
22794a4c329SAtsushi Nemoto 		tx4938_sram_resource.start =
22894a4c329SAtsushi Nemoto 			(____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
22994a4c329SAtsushi Nemoto 			& ~(size - 1);
23094a4c329SAtsushi Nemoto 		tx4938_sram_resource.end =
23194a4c329SAtsushi Nemoto 			tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
23294a4c329SAtsushi Nemoto 		tx4938_sram_resource.flags = IORESOURCE_MEM;
23394a4c329SAtsushi Nemoto 		request_resource(&iomem_resource, &tx4938_sram_resource);
23494a4c329SAtsushi Nemoto 	}
23594a4c329SAtsushi Nemoto 
23694a4c329SAtsushi Nemoto 	/* TMR */
23794a4c329SAtsushi Nemoto 	/* disable all timers */
23894a4c329SAtsushi Nemoto 	for (i = 0; i < TX4938_NR_TMR; i++)
23994a4c329SAtsushi Nemoto 		txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
24094a4c329SAtsushi Nemoto 
24194a4c329SAtsushi Nemoto 	/* DMA */
24294a4c329SAtsushi Nemoto 	for (i = 0; i < 2; i++)
24394a4c329SAtsushi Nemoto 		____raw_writeq(TX4938_DMA_MCR_MSTEN,
24494a4c329SAtsushi Nemoto 			       (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
24594a4c329SAtsushi Nemoto 
24694a4c329SAtsushi Nemoto 	/* PIO */
24794a4c329SAtsushi Nemoto 	txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
24894a4c329SAtsushi Nemoto 	__raw_writel(0, &tx4938_pioptr->maskcpu);
24994a4c329SAtsushi Nemoto 	__raw_writel(0, &tx4938_pioptr->maskext);
25094a4c329SAtsushi Nemoto 
25194a4c329SAtsushi Nemoto 	if (txx9_pcode == 0x4938) {
25294a4c329SAtsushi Nemoto 		__u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
25394a4c329SAtsushi Nemoto 		/* set PCIC1 reset */
25494a4c329SAtsushi Nemoto 		txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
25594a4c329SAtsushi Nemoto 		if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
25694a4c329SAtsushi Nemoto 			mdelay(1);	/* at least 128 cpu clock */
25794a4c329SAtsushi Nemoto 			/* clear PCIC1 reset */
25894a4c329SAtsushi Nemoto 			txx9_clear64(&tx4938_ccfgptr->clkctr,
25994a4c329SAtsushi Nemoto 				     TX4938_CLKCTR_PCIC1RST);
26094a4c329SAtsushi Nemoto 		} else {
26194a4c329SAtsushi Nemoto 			printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
26294a4c329SAtsushi Nemoto 			/* stop PCIC1 */
26394a4c329SAtsushi Nemoto 			txx9_set64(&tx4938_ccfgptr->clkctr,
26494a4c329SAtsushi Nemoto 				   TX4938_CLKCTR_PCIC1CKD);
26594a4c329SAtsushi Nemoto 		}
26694a4c329SAtsushi Nemoto 		if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
26794a4c329SAtsushi Nemoto 			printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
26894a4c329SAtsushi Nemoto 			txx9_set64(&tx4938_ccfgptr->clkctr,
26994a4c329SAtsushi Nemoto 				   TX4938_CLKCTR_ETH0RST);
27094a4c329SAtsushi Nemoto 			txx9_set64(&tx4938_ccfgptr->clkctr,
27194a4c329SAtsushi Nemoto 				   TX4938_CLKCTR_ETH0CKD);
27294a4c329SAtsushi Nemoto 		}
27394a4c329SAtsushi Nemoto 		if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
27494a4c329SAtsushi Nemoto 			printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
27594a4c329SAtsushi Nemoto 			txx9_set64(&tx4938_ccfgptr->clkctr,
27694a4c329SAtsushi Nemoto 				   TX4938_CLKCTR_ETH1RST);
27794a4c329SAtsushi Nemoto 			txx9_set64(&tx4938_ccfgptr->clkctr,
27894a4c329SAtsushi Nemoto 				   TX4938_CLKCTR_ETH1CKD);
27994a4c329SAtsushi Nemoto 		}
28094a4c329SAtsushi Nemoto 	}
281496a3b5cSAtsushi Nemoto 
282496a3b5cSAtsushi Nemoto 	_machine_restart = tx4938_machine_restart;
283ce8e7411SAtsushi Nemoto 	board_be_init = tx4938_be_init;
28494a4c329SAtsushi Nemoto }
28594a4c329SAtsushi Nemoto 
28694a4c329SAtsushi Nemoto void __init tx4938_time_init(unsigned int tmrnr)
28794a4c329SAtsushi Nemoto {
28894a4c329SAtsushi Nemoto 	if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
28994a4c329SAtsushi Nemoto 		txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
29094a4c329SAtsushi Nemoto 				     TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
29194a4c329SAtsushi Nemoto 				     TXX9_IMCLK);
29294a4c329SAtsushi Nemoto }
29394a4c329SAtsushi Nemoto 
2947779a5e0SAtsushi Nemoto void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
29594a4c329SAtsushi Nemoto {
29694a4c329SAtsushi Nemoto 	int i;
29794a4c329SAtsushi Nemoto 	unsigned int ch_mask = 0;
29894a4c329SAtsushi Nemoto 
29994a4c329SAtsushi Nemoto 	if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
30094a4c329SAtsushi Nemoto 		ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
30194a4c329SAtsushi Nemoto 	for (i = 0; i < 2; i++) {
30294a4c329SAtsushi Nemoto 		if ((1 << i) & ch_mask)
30394a4c329SAtsushi Nemoto 			continue;
3047779a5e0SAtsushi Nemoto 		txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
3057779a5e0SAtsushi Nemoto 			      TXX9_IRQ_BASE + TX4938_IR_SIO(i),
3067779a5e0SAtsushi Nemoto 			      i, sclk, (1 << i) & cts_mask);
30794a4c329SAtsushi Nemoto 	}
30894a4c329SAtsushi Nemoto }
309c49f91f5SAtsushi Nemoto 
310c49f91f5SAtsushi Nemoto void __init tx4938_spi_init(int busid)
311c49f91f5SAtsushi Nemoto {
312c49f91f5SAtsushi Nemoto 	txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
313c49f91f5SAtsushi Nemoto 		      TXX9_IRQ_BASE + TX4938_IR_SPI);
314c49f91f5SAtsushi Nemoto }
315c49f91f5SAtsushi Nemoto 
316c49f91f5SAtsushi Nemoto void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
317c49f91f5SAtsushi Nemoto {
318c49f91f5SAtsushi Nemoto 	u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
319c49f91f5SAtsushi Nemoto 
320c49f91f5SAtsushi Nemoto 	if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
321c49f91f5SAtsushi Nemoto 		txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
322c49f91f5SAtsushi Nemoto 	if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
323c49f91f5SAtsushi Nemoto 		txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);
324c49f91f5SAtsushi Nemoto }
32551f607c7SAtsushi Nemoto 
32651f607c7SAtsushi Nemoto void __init tx4938_mtd_init(int ch)
32751f607c7SAtsushi Nemoto {
32851f607c7SAtsushi Nemoto 	struct physmap_flash_data pdata = {
32951f607c7SAtsushi Nemoto 		.width = TX4938_EBUSC_WIDTH(ch) / 8,
33051f607c7SAtsushi Nemoto 	};
33151f607c7SAtsushi Nemoto 	unsigned long start = txx9_ce_res[ch].start;
33251f607c7SAtsushi Nemoto 	unsigned long size = txx9_ce_res[ch].end - start + 1;
33351f607c7SAtsushi Nemoto 
33451f607c7SAtsushi Nemoto 	if (!(TX4938_EBUSC_CR(ch) & 0x8))
33551f607c7SAtsushi Nemoto 		return;	/* disabled */
33651f607c7SAtsushi Nemoto 	txx9_physmap_flash_init(ch, start, size, &pdata);
33751f607c7SAtsushi Nemoto }
338f6d9831bSAtsushi Nemoto 
339*5d1d2f8cSAtsushi Nemoto void __init tx4938_ata_init(unsigned int irq, unsigned int shift, int tune)
340*5d1d2f8cSAtsushi Nemoto {
341*5d1d2f8cSAtsushi Nemoto 	struct platform_device *pdev;
342*5d1d2f8cSAtsushi Nemoto 	struct resource res[] = {
343*5d1d2f8cSAtsushi Nemoto 		{
344*5d1d2f8cSAtsushi Nemoto 			/* .start and .end are filled in later */
345*5d1d2f8cSAtsushi Nemoto 			.flags = IORESOURCE_MEM,
346*5d1d2f8cSAtsushi Nemoto 		}, {
347*5d1d2f8cSAtsushi Nemoto 			.start = irq,
348*5d1d2f8cSAtsushi Nemoto 			.flags = IORESOURCE_IRQ,
349*5d1d2f8cSAtsushi Nemoto 		},
350*5d1d2f8cSAtsushi Nemoto 	};
351*5d1d2f8cSAtsushi Nemoto 	struct tx4938ide_platform_info pdata = {
352*5d1d2f8cSAtsushi Nemoto 		.ioport_shift = shift,
353*5d1d2f8cSAtsushi Nemoto 		/*
354*5d1d2f8cSAtsushi Nemoto 		 * The IDE driver should not change bus timings if other ISA
355*5d1d2f8cSAtsushi Nemoto 		 * devices existed.
356*5d1d2f8cSAtsushi Nemoto 		 */
357*5d1d2f8cSAtsushi Nemoto 		.gbus_clock = tune ? txx9_gbus_clock : 0,
358*5d1d2f8cSAtsushi Nemoto 	};
359*5d1d2f8cSAtsushi Nemoto 	u64 ebccr;
360*5d1d2f8cSAtsushi Nemoto 	int i;
361*5d1d2f8cSAtsushi Nemoto 
362*5d1d2f8cSAtsushi Nemoto 	if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
363*5d1d2f8cSAtsushi Nemoto 	     (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL))
364*5d1d2f8cSAtsushi Nemoto 	    != TX4938_PCFG_ATA_SEL)
365*5d1d2f8cSAtsushi Nemoto 		return;
366*5d1d2f8cSAtsushi Nemoto 	for (i = 0; i < 8; i++) {
367*5d1d2f8cSAtsushi Nemoto 		/* check EBCCRn.ISA, EBCCRn.BSZ, EBCCRn.ME */
368*5d1d2f8cSAtsushi Nemoto 		ebccr = __raw_readq(&tx4938_ebuscptr->cr[i]);
369*5d1d2f8cSAtsushi Nemoto 		if ((ebccr & 0x00f00008) == 0x00e00008)
370*5d1d2f8cSAtsushi Nemoto 			break;
371*5d1d2f8cSAtsushi Nemoto 	}
372*5d1d2f8cSAtsushi Nemoto 	if (i == 8)
373*5d1d2f8cSAtsushi Nemoto 		return;
374*5d1d2f8cSAtsushi Nemoto 	pdata.ebus_ch = i;
375*5d1d2f8cSAtsushi Nemoto 	res[0].start = ((ebccr >> 48) << 20) + 0x10000;
376*5d1d2f8cSAtsushi Nemoto 	res[0].end = res[0].start + 0x20000 - 1;
377*5d1d2f8cSAtsushi Nemoto 	pdev = platform_device_alloc("tx4938ide", -1);
378*5d1d2f8cSAtsushi Nemoto 	if (!pdev ||
379*5d1d2f8cSAtsushi Nemoto 	    platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
380*5d1d2f8cSAtsushi Nemoto 	    platform_device_add_data(pdev, &pdata, sizeof(pdata)) ||
381*5d1d2f8cSAtsushi Nemoto 	    platform_device_add(pdev))
382*5d1d2f8cSAtsushi Nemoto 		platform_device_put(pdev);
383*5d1d2f8cSAtsushi Nemoto }
384*5d1d2f8cSAtsushi Nemoto 
385f6d9831bSAtsushi Nemoto static void __init tx4938_stop_unused_modules(void)
386f6d9831bSAtsushi Nemoto {
387f6d9831bSAtsushi Nemoto 	__u64 pcfg, rst = 0, ckd = 0;
388f6d9831bSAtsushi Nemoto 	char buf[128];
389f6d9831bSAtsushi Nemoto 
390f6d9831bSAtsushi Nemoto 	buf[0] = '\0';
391f6d9831bSAtsushi Nemoto 	local_irq_disable();
392f6d9831bSAtsushi Nemoto 	pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
393f6d9831bSAtsushi Nemoto 	switch (txx9_pcode) {
394f6d9831bSAtsushi Nemoto 	case 0x4937:
395f6d9831bSAtsushi Nemoto 		if (!(pcfg & TX4938_PCFG_SEL2)) {
396f6d9831bSAtsushi Nemoto 			rst |= TX4938_CLKCTR_ACLRST;
397f6d9831bSAtsushi Nemoto 			ckd |= TX4938_CLKCTR_ACLCKD;
398f6d9831bSAtsushi Nemoto 			strcat(buf, " ACLC");
399f6d9831bSAtsushi Nemoto 		}
400f6d9831bSAtsushi Nemoto 		break;
401f6d9831bSAtsushi Nemoto 	case 0x4938:
402f6d9831bSAtsushi Nemoto 		if (!(pcfg & TX4938_PCFG_SEL2) ||
403f6d9831bSAtsushi Nemoto 		    (pcfg & TX4938_PCFG_ETH0_SEL)) {
404f6d9831bSAtsushi Nemoto 			rst |= TX4938_CLKCTR_ACLRST;
405f6d9831bSAtsushi Nemoto 			ckd |= TX4938_CLKCTR_ACLCKD;
406f6d9831bSAtsushi Nemoto 			strcat(buf, " ACLC");
407f6d9831bSAtsushi Nemoto 		}
408f6d9831bSAtsushi Nemoto 		if ((pcfg &
409f6d9831bSAtsushi Nemoto 		     (TX4938_PCFG_ATA_SEL | TX4938_PCFG_ISA_SEL |
410f6d9831bSAtsushi Nemoto 		      TX4938_PCFG_NDF_SEL))
411f6d9831bSAtsushi Nemoto 		    != TX4938_PCFG_NDF_SEL) {
412f6d9831bSAtsushi Nemoto 			rst |= TX4938_CLKCTR_NDFRST;
413f6d9831bSAtsushi Nemoto 			ckd |= TX4938_CLKCTR_NDFCKD;
414f6d9831bSAtsushi Nemoto 			strcat(buf, " NDFMC");
415f6d9831bSAtsushi Nemoto 		}
416f6d9831bSAtsushi Nemoto 		if (!(pcfg & TX4938_PCFG_SPI_SEL)) {
417f6d9831bSAtsushi Nemoto 			rst |= TX4938_CLKCTR_SPIRST;
418f6d9831bSAtsushi Nemoto 			ckd |= TX4938_CLKCTR_SPICKD;
419f6d9831bSAtsushi Nemoto 			strcat(buf, " SPI");
420f6d9831bSAtsushi Nemoto 		}
421f6d9831bSAtsushi Nemoto 		break;
422f6d9831bSAtsushi Nemoto 	}
423f6d9831bSAtsushi Nemoto 	if (rst | ckd) {
424f6d9831bSAtsushi Nemoto 		txx9_set64(&tx4938_ccfgptr->clkctr, rst);
425f6d9831bSAtsushi Nemoto 		txx9_set64(&tx4938_ccfgptr->clkctr, ckd);
426f6d9831bSAtsushi Nemoto 	}
427f6d9831bSAtsushi Nemoto 	local_irq_enable();
428f6d9831bSAtsushi Nemoto 	if (buf[0])
429f6d9831bSAtsushi Nemoto 		pr_info("%s: stop%s\n", txx9_pcode_str, buf);
430f6d9831bSAtsushi Nemoto }
431f6d9831bSAtsushi Nemoto 
432f6d9831bSAtsushi Nemoto static int __init tx4938_late_init(void)
433f6d9831bSAtsushi Nemoto {
434f6d9831bSAtsushi Nemoto 	if (txx9_pcode != 0x4937 && txx9_pcode != 0x4938)
435f6d9831bSAtsushi Nemoto 		return -ENODEV;
436f6d9831bSAtsushi Nemoto 	tx4938_stop_unused_modules();
437f6d9831bSAtsushi Nemoto 	return 0;
438f6d9831bSAtsushi Nemoto }
439f6d9831bSAtsushi Nemoto late_initcall(tx4938_late_init);
440