18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * TX4938/4937 setup routines
38c2ecf20Sopenharmony_ci * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
48c2ecf20Sopenharmony_ci *	    and RBTX49xx patch from CELF patch archive.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * 2003-2005 (c) MontaVista Software, Inc.
78c2ecf20Sopenharmony_ci * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
108c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
118c2ecf20Sopenharmony_ci * for more details.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci#include <linux/init.h>
148c2ecf20Sopenharmony_ci#include <linux/ioport.h>
158c2ecf20Sopenharmony_ci#include <linux/delay.h>
168c2ecf20Sopenharmony_ci#include <linux/param.h>
178c2ecf20Sopenharmony_ci#include <linux/ptrace.h>
188c2ecf20Sopenharmony_ci#include <linux/mtd/physmap.h>
198c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
208c2ecf20Sopenharmony_ci#include <linux/platform_data/txx9/ndfmc.h>
218c2ecf20Sopenharmony_ci#include <asm/reboot.h>
228c2ecf20Sopenharmony_ci#include <asm/traps.h>
238c2ecf20Sopenharmony_ci#include <asm/txx9irq.h>
248c2ecf20Sopenharmony_ci#include <asm/txx9tmr.h>
258c2ecf20Sopenharmony_ci#include <asm/txx9pio.h>
268c2ecf20Sopenharmony_ci#include <asm/txx9/generic.h>
278c2ecf20Sopenharmony_ci#include <asm/txx9/dmac.h>
288c2ecf20Sopenharmony_ci#include <asm/txx9/tx4938.h>
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistatic void __init tx4938_wdr_init(void)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	/* report watchdog reset status */
338c2ecf20Sopenharmony_ci	if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST)
348c2ecf20Sopenharmony_ci		pr_warn("Watchdog reset detected at 0x%lx\n",
358c2ecf20Sopenharmony_ci			read_c0_errorepc());
368c2ecf20Sopenharmony_ci	/* clear WatchDogReset (W1C) */
378c2ecf20Sopenharmony_ci	tx4938_ccfg_set(TX4938_CCFG_WDRST);
388c2ecf20Sopenharmony_ci	/* do reset on watchdog */
398c2ecf20Sopenharmony_ci	tx4938_ccfg_set(TX4938_CCFG_WR);
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_civoid __init tx4938_wdt_init(void)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic void tx4938_machine_restart(char *command)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	local_irq_disable();
508c2ecf20Sopenharmony_ci	pr_emerg("Rebooting (with %s watchdog reset)...\n",
518c2ecf20Sopenharmony_ci		 (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ?
528c2ecf20Sopenharmony_ci		 "external" : "internal");
538c2ecf20Sopenharmony_ci	/* clear watchdog status */
548c2ecf20Sopenharmony_ci	tx4938_ccfg_set(TX4938_CCFG_WDRST);	/* W1C */
558c2ecf20Sopenharmony_ci	txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL);
568c2ecf20Sopenharmony_ci	while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST))
578c2ecf20Sopenharmony_ci		;
588c2ecf20Sopenharmony_ci	mdelay(10);
598c2ecf20Sopenharmony_ci	if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) {
608c2ecf20Sopenharmony_ci		pr_emerg("Rebooting (with internal watchdog reset)...\n");
618c2ecf20Sopenharmony_ci		/* External WDRST failed.  Do internal watchdog reset */
628c2ecf20Sopenharmony_ci		tx4938_ccfg_clear(TX4938_CCFG_WDREXEN);
638c2ecf20Sopenharmony_ci	}
648c2ecf20Sopenharmony_ci	/* fallback */
658c2ecf20Sopenharmony_ci	(*_machine_halt)();
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_civoid show_registers(struct pt_regs *regs);
698c2ecf20Sopenharmony_cistatic int tx4938_be_handler(struct pt_regs *regs, int is_fixup)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	int data = regs->cp0_cause & 4;
728c2ecf20Sopenharmony_ci	console_verbose();
738c2ecf20Sopenharmony_ci	pr_err("%cBE exception at %#lx\n", data ? 'D' : 'I', regs->cp0_epc);
748c2ecf20Sopenharmony_ci	pr_err("ccfg:%llx, toea:%llx\n",
758c2ecf20Sopenharmony_ci	       (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
768c2ecf20Sopenharmony_ci	       (unsigned long long)____raw_readq(&tx4938_ccfgptr->toea));
778c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
788c2ecf20Sopenharmony_ci	tx4927_report_pcic_status();
798c2ecf20Sopenharmony_ci#endif
808c2ecf20Sopenharmony_ci	show_registers(regs);
818c2ecf20Sopenharmony_ci	panic("BusError!");
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_cistatic void __init tx4938_be_init(void)
848c2ecf20Sopenharmony_ci{
858c2ecf20Sopenharmony_ci	board_be_handler = tx4938_be_handler;
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic struct resource tx4938_sdram_resource[4];
898c2ecf20Sopenharmony_cistatic struct resource tx4938_sram_resource;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define TX4938_SRAM_SIZE 0x800
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_civoid __init tx4938_setup(void)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	int i;
968c2ecf20Sopenharmony_ci	__u32 divmode;
978c2ecf20Sopenharmony_ci	unsigned int cpuclk = 0;
988c2ecf20Sopenharmony_ci	u64 ccfg;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
1018c2ecf20Sopenharmony_ci			  TX4938_REG_SIZE);
1028c2ecf20Sopenharmony_ci	set_c0_config(TX49_CONF_CWFON);
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	/* SDRAMC,EBUSC are configured by PROM */
1058c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++) {
1068c2ecf20Sopenharmony_ci		if (!(TX4938_EBUSC_CR(i) & 0x8))
1078c2ecf20Sopenharmony_ci			continue;	/* disabled */
1088c2ecf20Sopenharmony_ci		txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
1098c2ecf20Sopenharmony_ci		txx9_ce_res[i].end =
1108c2ecf20Sopenharmony_ci			txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
1118c2ecf20Sopenharmony_ci		request_resource(&iomem_resource, &txx9_ce_res[i]);
1128c2ecf20Sopenharmony_ci	}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci	/* clocks */
1158c2ecf20Sopenharmony_ci	ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
1168c2ecf20Sopenharmony_ci	if (txx9_master_clock) {
1178c2ecf20Sopenharmony_ci		/* calculate gbus_clock and cpu_clock from master_clock */
1188c2ecf20Sopenharmony_ci		divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
1198c2ecf20Sopenharmony_ci		switch (divmode) {
1208c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_8:
1218c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_10:
1228c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_12:
1238c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_16:
1248c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_18:
1258c2ecf20Sopenharmony_ci			txx9_gbus_clock = txx9_master_clock * 4; break;
1268c2ecf20Sopenharmony_ci		default:
1278c2ecf20Sopenharmony_ci			txx9_gbus_clock = txx9_master_clock;
1288c2ecf20Sopenharmony_ci		}
1298c2ecf20Sopenharmony_ci		switch (divmode) {
1308c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_2:
1318c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_8:
1328c2ecf20Sopenharmony_ci			cpuclk = txx9_gbus_clock * 2; break;
1338c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_2_5:
1348c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_10:
1358c2ecf20Sopenharmony_ci			cpuclk = txx9_gbus_clock * 5 / 2; break;
1368c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_3:
1378c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_12:
1388c2ecf20Sopenharmony_ci			cpuclk = txx9_gbus_clock * 3; break;
1398c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_4:
1408c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_16:
1418c2ecf20Sopenharmony_ci			cpuclk = txx9_gbus_clock * 4; break;
1428c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_4_5:
1438c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_18:
1448c2ecf20Sopenharmony_ci			cpuclk = txx9_gbus_clock * 9 / 2; break;
1458c2ecf20Sopenharmony_ci		}
1468c2ecf20Sopenharmony_ci		txx9_cpu_clock = cpuclk;
1478c2ecf20Sopenharmony_ci	} else {
1488c2ecf20Sopenharmony_ci		if (txx9_cpu_clock == 0)
1498c2ecf20Sopenharmony_ci			txx9_cpu_clock = 300000000;	/* 300MHz */
1508c2ecf20Sopenharmony_ci		/* calculate gbus_clock and master_clock from cpu_clock */
1518c2ecf20Sopenharmony_ci		cpuclk = txx9_cpu_clock;
1528c2ecf20Sopenharmony_ci		divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
1538c2ecf20Sopenharmony_ci		switch (divmode) {
1548c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_2:
1558c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_8:
1568c2ecf20Sopenharmony_ci			txx9_gbus_clock = cpuclk / 2; break;
1578c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_2_5:
1588c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_10:
1598c2ecf20Sopenharmony_ci			txx9_gbus_clock = cpuclk * 2 / 5; break;
1608c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_3:
1618c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_12:
1628c2ecf20Sopenharmony_ci			txx9_gbus_clock = cpuclk / 3; break;
1638c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_4:
1648c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_16:
1658c2ecf20Sopenharmony_ci			txx9_gbus_clock = cpuclk / 4; break;
1668c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_4_5:
1678c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_18:
1688c2ecf20Sopenharmony_ci			txx9_gbus_clock = cpuclk * 2 / 9; break;
1698c2ecf20Sopenharmony_ci		}
1708c2ecf20Sopenharmony_ci		switch (divmode) {
1718c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_8:
1728c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_10:
1738c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_12:
1748c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_16:
1758c2ecf20Sopenharmony_ci		case TX4938_CCFG_DIVMODE_18:
1768c2ecf20Sopenharmony_ci			txx9_master_clock = txx9_gbus_clock / 4; break;
1778c2ecf20Sopenharmony_ci		default:
1788c2ecf20Sopenharmony_ci			txx9_master_clock = txx9_gbus_clock;
1798c2ecf20Sopenharmony_ci		}
1808c2ecf20Sopenharmony_ci	}
1818c2ecf20Sopenharmony_ci	/* change default value to udelay/mdelay take reasonable time */
1828c2ecf20Sopenharmony_ci	loops_per_jiffy = txx9_cpu_clock / HZ / 2;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	/* CCFG */
1858c2ecf20Sopenharmony_ci	tx4938_wdr_init();
1868c2ecf20Sopenharmony_ci	/* clear BusErrorOnWrite flag (W1C) */
1878c2ecf20Sopenharmony_ci	tx4938_ccfg_set(TX4938_CCFG_BEOW);
1888c2ecf20Sopenharmony_ci	/* enable Timeout BusError */
1898c2ecf20Sopenharmony_ci	if (txx9_ccfg_toeon)
1908c2ecf20Sopenharmony_ci		tx4938_ccfg_set(TX4938_CCFG_TOE);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	/* DMA selection */
1938c2ecf20Sopenharmony_ci	txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci	/* Use external clock for external arbiter */
1968c2ecf20Sopenharmony_ci	if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
1978c2ecf20Sopenharmony_ci		txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	pr_info("%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
2008c2ecf20Sopenharmony_ci		txx9_pcode_str, (cpuclk + 500000) / 1000000,
2018c2ecf20Sopenharmony_ci		(txx9_master_clock + 500000) / 1000000,
2028c2ecf20Sopenharmony_ci		(__u32)____raw_readq(&tx4938_ccfgptr->crir),
2038c2ecf20Sopenharmony_ci		____raw_readq(&tx4938_ccfgptr->ccfg),
2048c2ecf20Sopenharmony_ci		____raw_readq(&tx4938_ccfgptr->pcfg));
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci	pr_info("%s SDRAMC --", txx9_pcode_str);
2078c2ecf20Sopenharmony_ci	for (i = 0; i < 4; i++) {
2088c2ecf20Sopenharmony_ci		__u64 cr = TX4938_SDRAMC_CR(i);
2098c2ecf20Sopenharmony_ci		unsigned long base, size;
2108c2ecf20Sopenharmony_ci		if (!((__u32)cr & 0x00000400))
2118c2ecf20Sopenharmony_ci			continue;	/* disabled */
2128c2ecf20Sopenharmony_ci		base = (unsigned long)(cr >> 49) << 21;
2138c2ecf20Sopenharmony_ci		size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
2148c2ecf20Sopenharmony_ci		pr_cont(" CR%d:%016llx", i, cr);
2158c2ecf20Sopenharmony_ci		tx4938_sdram_resource[i].name = "SDRAM";
2168c2ecf20Sopenharmony_ci		tx4938_sdram_resource[i].start = base;
2178c2ecf20Sopenharmony_ci		tx4938_sdram_resource[i].end = base + size - 1;
2188c2ecf20Sopenharmony_ci		tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
2198c2ecf20Sopenharmony_ci		request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
2208c2ecf20Sopenharmony_ci	}
2218c2ecf20Sopenharmony_ci	pr_cont(" TR:%09llx\n", ____raw_readq(&tx4938_sdramcptr->tr));
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	/* SRAM */
2248c2ecf20Sopenharmony_ci	if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
2258c2ecf20Sopenharmony_ci		unsigned int size = TX4938_SRAM_SIZE;
2268c2ecf20Sopenharmony_ci		tx4938_sram_resource.name = "SRAM";
2278c2ecf20Sopenharmony_ci		tx4938_sram_resource.start =
2288c2ecf20Sopenharmony_ci			(____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
2298c2ecf20Sopenharmony_ci			& ~(size - 1);
2308c2ecf20Sopenharmony_ci		tx4938_sram_resource.end =
2318c2ecf20Sopenharmony_ci			tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
2328c2ecf20Sopenharmony_ci		tx4938_sram_resource.flags = IORESOURCE_MEM;
2338c2ecf20Sopenharmony_ci		request_resource(&iomem_resource, &tx4938_sram_resource);
2348c2ecf20Sopenharmony_ci	}
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	/* TMR */
2378c2ecf20Sopenharmony_ci	/* disable all timers */
2388c2ecf20Sopenharmony_ci	for (i = 0; i < TX4938_NR_TMR; i++)
2398c2ecf20Sopenharmony_ci		txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci	/* PIO */
2428c2ecf20Sopenharmony_ci	__raw_writel(0, &tx4938_pioptr->maskcpu);
2438c2ecf20Sopenharmony_ci	__raw_writel(0, &tx4938_pioptr->maskext);
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	if (txx9_pcode == 0x4938) {
2468c2ecf20Sopenharmony_ci		__u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
2478c2ecf20Sopenharmony_ci		/* set PCIC1 reset */
2488c2ecf20Sopenharmony_ci		txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
2498c2ecf20Sopenharmony_ci		if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
2508c2ecf20Sopenharmony_ci			mdelay(1);	/* at least 128 cpu clock */
2518c2ecf20Sopenharmony_ci			/* clear PCIC1 reset */
2528c2ecf20Sopenharmony_ci			txx9_clear64(&tx4938_ccfgptr->clkctr,
2538c2ecf20Sopenharmony_ci				     TX4938_CLKCTR_PCIC1RST);
2548c2ecf20Sopenharmony_ci		} else {
2558c2ecf20Sopenharmony_ci			pr_info("%s: stop PCIC1\n", txx9_pcode_str);
2568c2ecf20Sopenharmony_ci			/* stop PCIC1 */
2578c2ecf20Sopenharmony_ci			txx9_set64(&tx4938_ccfgptr->clkctr,
2588c2ecf20Sopenharmony_ci				   TX4938_CLKCTR_PCIC1CKD);
2598c2ecf20Sopenharmony_ci		}
2608c2ecf20Sopenharmony_ci		if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
2618c2ecf20Sopenharmony_ci			pr_info("%s: stop ETH0\n", txx9_pcode_str);
2628c2ecf20Sopenharmony_ci			txx9_set64(&tx4938_ccfgptr->clkctr,
2638c2ecf20Sopenharmony_ci				   TX4938_CLKCTR_ETH0RST);
2648c2ecf20Sopenharmony_ci			txx9_set64(&tx4938_ccfgptr->clkctr,
2658c2ecf20Sopenharmony_ci				   TX4938_CLKCTR_ETH0CKD);
2668c2ecf20Sopenharmony_ci		}
2678c2ecf20Sopenharmony_ci		if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
2688c2ecf20Sopenharmony_ci			pr_info("%s: stop ETH1\n", txx9_pcode_str);
2698c2ecf20Sopenharmony_ci			txx9_set64(&tx4938_ccfgptr->clkctr,
2708c2ecf20Sopenharmony_ci				   TX4938_CLKCTR_ETH1RST);
2718c2ecf20Sopenharmony_ci			txx9_set64(&tx4938_ccfgptr->clkctr,
2728c2ecf20Sopenharmony_ci				   TX4938_CLKCTR_ETH1CKD);
2738c2ecf20Sopenharmony_ci		}
2748c2ecf20Sopenharmony_ci	}
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	_machine_restart = tx4938_machine_restart;
2778c2ecf20Sopenharmony_ci	board_be_init = tx4938_be_init;
2788c2ecf20Sopenharmony_ci}
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_civoid __init tx4938_time_init(unsigned int tmrnr)
2818c2ecf20Sopenharmony_ci{
2828c2ecf20Sopenharmony_ci	if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
2838c2ecf20Sopenharmony_ci		txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
2848c2ecf20Sopenharmony_ci				     TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
2858c2ecf20Sopenharmony_ci				     TXX9_IMCLK);
2868c2ecf20Sopenharmony_ci}
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_civoid __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
2898c2ecf20Sopenharmony_ci{
2908c2ecf20Sopenharmony_ci	int i;
2918c2ecf20Sopenharmony_ci	unsigned int ch_mask = 0;
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
2948c2ecf20Sopenharmony_ci		ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
2958c2ecf20Sopenharmony_ci	for (i = 0; i < 2; i++) {
2968c2ecf20Sopenharmony_ci		if ((1 << i) & ch_mask)
2978c2ecf20Sopenharmony_ci			continue;
2988c2ecf20Sopenharmony_ci		txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
2998c2ecf20Sopenharmony_ci			      TXX9_IRQ_BASE + TX4938_IR_SIO(i),
3008c2ecf20Sopenharmony_ci			      i, sclk, (1 << i) & cts_mask);
3018c2ecf20Sopenharmony_ci	}
3028c2ecf20Sopenharmony_ci}
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_civoid __init tx4938_spi_init(int busid)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci	txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
3078c2ecf20Sopenharmony_ci		      TXX9_IRQ_BASE + TX4938_IR_SPI);
3088c2ecf20Sopenharmony_ci}
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_civoid __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
3118c2ecf20Sopenharmony_ci{
3128c2ecf20Sopenharmony_ci	u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci	if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
3158c2ecf20Sopenharmony_ci		txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
3168c2ecf20Sopenharmony_ci	if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
3178c2ecf20Sopenharmony_ci		txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);
3188c2ecf20Sopenharmony_ci}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_civoid __init tx4938_mtd_init(int ch)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci	struct physmap_flash_data pdata = {
3238c2ecf20Sopenharmony_ci		.width = TX4938_EBUSC_WIDTH(ch) / 8,
3248c2ecf20Sopenharmony_ci	};
3258c2ecf20Sopenharmony_ci	unsigned long start = txx9_ce_res[ch].start;
3268c2ecf20Sopenharmony_ci	unsigned long size = txx9_ce_res[ch].end - start + 1;
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	if (!(TX4938_EBUSC_CR(ch) & 0x8))
3298c2ecf20Sopenharmony_ci		return; /* disabled */
3308c2ecf20Sopenharmony_ci	txx9_physmap_flash_init(ch, start, size, &pdata);
3318c2ecf20Sopenharmony_ci}
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_civoid __init tx4938_ata_init(unsigned int irq, unsigned int shift, int tune)
3348c2ecf20Sopenharmony_ci{
3358c2ecf20Sopenharmony_ci	struct platform_device *pdev;
3368c2ecf20Sopenharmony_ci	struct resource res[] = {
3378c2ecf20Sopenharmony_ci		{
3388c2ecf20Sopenharmony_ci			/* .start and .end are filled in later */
3398c2ecf20Sopenharmony_ci			.flags = IORESOURCE_MEM,
3408c2ecf20Sopenharmony_ci		}, {
3418c2ecf20Sopenharmony_ci			.start = irq,
3428c2ecf20Sopenharmony_ci			.flags = IORESOURCE_IRQ,
3438c2ecf20Sopenharmony_ci		},
3448c2ecf20Sopenharmony_ci	};
3458c2ecf20Sopenharmony_ci	struct tx4938ide_platform_info pdata = {
3468c2ecf20Sopenharmony_ci		.ioport_shift = shift,
3478c2ecf20Sopenharmony_ci		/*
3488c2ecf20Sopenharmony_ci		 * The IDE driver should not change bus timings if other ISA
3498c2ecf20Sopenharmony_ci		 * devices existed.
3508c2ecf20Sopenharmony_ci		 */
3518c2ecf20Sopenharmony_ci		.gbus_clock = tune ? txx9_gbus_clock : 0,
3528c2ecf20Sopenharmony_ci	};
3538c2ecf20Sopenharmony_ci	u64 ebccr;
3548c2ecf20Sopenharmony_ci	int i;
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
3578c2ecf20Sopenharmony_ci	     (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL))
3588c2ecf20Sopenharmony_ci	    != TX4938_PCFG_ATA_SEL)
3598c2ecf20Sopenharmony_ci		return;
3608c2ecf20Sopenharmony_ci	for (i = 0; i < 8; i++) {
3618c2ecf20Sopenharmony_ci		/* check EBCCRn.ISA, EBCCRn.BSZ, EBCCRn.ME */
3628c2ecf20Sopenharmony_ci		ebccr = __raw_readq(&tx4938_ebuscptr->cr[i]);
3638c2ecf20Sopenharmony_ci		if ((ebccr & 0x00f00008) == 0x00e00008)
3648c2ecf20Sopenharmony_ci			break;
3658c2ecf20Sopenharmony_ci	}
3668c2ecf20Sopenharmony_ci	if (i == 8)
3678c2ecf20Sopenharmony_ci		return;
3688c2ecf20Sopenharmony_ci	pdata.ebus_ch = i;
3698c2ecf20Sopenharmony_ci	res[0].start = ((ebccr >> 48) << 20) + 0x10000;
3708c2ecf20Sopenharmony_ci	res[0].end = res[0].start + 0x20000 - 1;
3718c2ecf20Sopenharmony_ci	pdev = platform_device_alloc("tx4938ide", -1);
3728c2ecf20Sopenharmony_ci	if (!pdev ||
3738c2ecf20Sopenharmony_ci	    platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
3748c2ecf20Sopenharmony_ci	    platform_device_add_data(pdev, &pdata, sizeof(pdata)) ||
3758c2ecf20Sopenharmony_ci	    platform_device_add(pdev))
3768c2ecf20Sopenharmony_ci		platform_device_put(pdev);
3778c2ecf20Sopenharmony_ci}
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_civoid __init tx4938_ndfmc_init(unsigned int hold, unsigned int spw)
3808c2ecf20Sopenharmony_ci{
3818c2ecf20Sopenharmony_ci	struct txx9ndfmc_platform_data plat_data = {
3828c2ecf20Sopenharmony_ci		.shift = 1,
3838c2ecf20Sopenharmony_ci		.gbus_clock = txx9_gbus_clock,
3848c2ecf20Sopenharmony_ci		.hold = hold,
3858c2ecf20Sopenharmony_ci		.spw = spw,
3868c2ecf20Sopenharmony_ci		.ch_mask = 1,
3878c2ecf20Sopenharmony_ci	};
3888c2ecf20Sopenharmony_ci	unsigned long baseaddr = TX4938_NDFMC_REG & 0xfffffffffULL;
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN
3918c2ecf20Sopenharmony_ci	baseaddr += 4;
3928c2ecf20Sopenharmony_ci#endif
3938c2ecf20Sopenharmony_ci	if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
3948c2ecf20Sopenharmony_ci	     (TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL)) ==
3958c2ecf20Sopenharmony_ci	    TX4938_PCFG_NDF_SEL)
3968c2ecf20Sopenharmony_ci		txx9_ndfmc_init(baseaddr, &plat_data);
3978c2ecf20Sopenharmony_ci}
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_civoid __init tx4938_dmac_init(int memcpy_chan0, int memcpy_chan1)
4008c2ecf20Sopenharmony_ci{
4018c2ecf20Sopenharmony_ci	struct txx9dmac_platform_data plat_data = {
4028c2ecf20Sopenharmony_ci		.have_64bit_regs = true,
4038c2ecf20Sopenharmony_ci	};
4048c2ecf20Sopenharmony_ci	int i;
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	for (i = 0; i < 2; i++) {
4078c2ecf20Sopenharmony_ci		plat_data.memcpy_chan = i ? memcpy_chan1 : memcpy_chan0;
4088c2ecf20Sopenharmony_ci		txx9_dmac_init(i, TX4938_DMA_REG(i) & 0xfffffffffULL,
4098c2ecf20Sopenharmony_ci			       TXX9_IRQ_BASE + TX4938_IR_DMA(i, 0),
4108c2ecf20Sopenharmony_ci			       &plat_data);
4118c2ecf20Sopenharmony_ci	}
4128c2ecf20Sopenharmony_ci}
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_civoid __init tx4938_aclc_init(void)
4158c2ecf20Sopenharmony_ci{
4168c2ecf20Sopenharmony_ci	u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	if ((pcfg & TX4938_PCFG_SEL2) &&
4198c2ecf20Sopenharmony_ci	    !(pcfg & TX4938_PCFG_ETH0_SEL))
4208c2ecf20Sopenharmony_ci		txx9_aclc_init(TX4938_ACLC_REG & 0xfffffffffULL,
4218c2ecf20Sopenharmony_ci			       TXX9_IRQ_BASE + TX4938_IR_ACLC,
4228c2ecf20Sopenharmony_ci			       1, 0, 1);
4238c2ecf20Sopenharmony_ci}
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_civoid __init tx4938_sramc_init(void)
4268c2ecf20Sopenharmony_ci{
4278c2ecf20Sopenharmony_ci	if (tx4938_sram_resource.start)
4288c2ecf20Sopenharmony_ci		txx9_sramc_init(&tx4938_sram_resource);
4298c2ecf20Sopenharmony_ci}
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_cistatic void __init tx4938_stop_unused_modules(void)
4328c2ecf20Sopenharmony_ci{
4338c2ecf20Sopenharmony_ci	__u64 pcfg, rst = 0, ckd = 0;
4348c2ecf20Sopenharmony_ci	char buf[128];
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	buf[0] = '\0';
4378c2ecf20Sopenharmony_ci	local_irq_disable();
4388c2ecf20Sopenharmony_ci	pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
4398c2ecf20Sopenharmony_ci	switch (txx9_pcode) {
4408c2ecf20Sopenharmony_ci	case 0x4937:
4418c2ecf20Sopenharmony_ci		if (!(pcfg & TX4938_PCFG_SEL2)) {
4428c2ecf20Sopenharmony_ci			rst |= TX4938_CLKCTR_ACLRST;
4438c2ecf20Sopenharmony_ci			ckd |= TX4938_CLKCTR_ACLCKD;
4448c2ecf20Sopenharmony_ci			strcat(buf, " ACLC");
4458c2ecf20Sopenharmony_ci		}
4468c2ecf20Sopenharmony_ci		break;
4478c2ecf20Sopenharmony_ci	case 0x4938:
4488c2ecf20Sopenharmony_ci		if (!(pcfg & TX4938_PCFG_SEL2) ||
4498c2ecf20Sopenharmony_ci		    (pcfg & TX4938_PCFG_ETH0_SEL)) {
4508c2ecf20Sopenharmony_ci			rst |= TX4938_CLKCTR_ACLRST;
4518c2ecf20Sopenharmony_ci			ckd |= TX4938_CLKCTR_ACLCKD;
4528c2ecf20Sopenharmony_ci			strcat(buf, " ACLC");
4538c2ecf20Sopenharmony_ci		}
4548c2ecf20Sopenharmony_ci		if ((pcfg &
4558c2ecf20Sopenharmony_ci		     (TX4938_PCFG_ATA_SEL | TX4938_PCFG_ISA_SEL |
4568c2ecf20Sopenharmony_ci		      TX4938_PCFG_NDF_SEL))
4578c2ecf20Sopenharmony_ci		    != TX4938_PCFG_NDF_SEL) {
4588c2ecf20Sopenharmony_ci			rst |= TX4938_CLKCTR_NDFRST;
4598c2ecf20Sopenharmony_ci			ckd |= TX4938_CLKCTR_NDFCKD;
4608c2ecf20Sopenharmony_ci			strcat(buf, " NDFMC");
4618c2ecf20Sopenharmony_ci		}
4628c2ecf20Sopenharmony_ci		if (!(pcfg & TX4938_PCFG_SPI_SEL)) {
4638c2ecf20Sopenharmony_ci			rst |= TX4938_CLKCTR_SPIRST;
4648c2ecf20Sopenharmony_ci			ckd |= TX4938_CLKCTR_SPICKD;
4658c2ecf20Sopenharmony_ci			strcat(buf, " SPI");
4668c2ecf20Sopenharmony_ci		}
4678c2ecf20Sopenharmony_ci		break;
4688c2ecf20Sopenharmony_ci	}
4698c2ecf20Sopenharmony_ci	if (rst | ckd) {
4708c2ecf20Sopenharmony_ci		txx9_set64(&tx4938_ccfgptr->clkctr, rst);
4718c2ecf20Sopenharmony_ci		txx9_set64(&tx4938_ccfgptr->clkctr, ckd);
4728c2ecf20Sopenharmony_ci	}
4738c2ecf20Sopenharmony_ci	local_irq_enable();
4748c2ecf20Sopenharmony_ci	if (buf[0])
4758c2ecf20Sopenharmony_ci		pr_info("%s: stop%s\n", txx9_pcode_str, buf);
4768c2ecf20Sopenharmony_ci}
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_cistatic int __init tx4938_late_init(void)
4798c2ecf20Sopenharmony_ci{
4808c2ecf20Sopenharmony_ci	if (txx9_pcode != 0x4937 && txx9_pcode != 0x4938)
4818c2ecf20Sopenharmony_ci		return -ENODEV;
4828c2ecf20Sopenharmony_ci	tx4938_stop_unused_modules();
4838c2ecf20Sopenharmony_ci	return 0;
4848c2ecf20Sopenharmony_ci}
4858c2ecf20Sopenharmony_cilate_initcall(tx4938_late_init);
486