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>
195d1d2f8cSAtsushi Nemoto #include <linux/platform_device.h>
20dc2865acSBoris Brezillon #include <linux/platform_data/txx9/ndfmc.h>
21496a3b5cSAtsushi Nemoto #include <asm/reboot.h>
22ce8e7411SAtsushi Nemoto #include <asm/traps.h>
2394a4c329SAtsushi Nemoto #include <asm/txx9irq.h>
2494a4c329SAtsushi Nemoto #include <asm/txx9tmr.h>
2594a4c329SAtsushi Nemoto #include <asm/txx9pio.h>
2694a4c329SAtsushi Nemoto #include <asm/txx9/generic.h>
27f48c8c95SAtsushi Nemoto #include <asm/txx9/dmac.h>
2894a4c329SAtsushi Nemoto #include <asm/txx9/tx4938.h>
2994a4c329SAtsushi Nemoto
tx4938_wdr_init(void)3068314725SAtsushi Nemoto static void __init tx4938_wdr_init(void)
3194a4c329SAtsushi Nemoto {
32496a3b5cSAtsushi Nemoto /* report watchdog reset status */
33496a3b5cSAtsushi Nemoto if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST)
347178d2cdSJoe Perches pr_warn("Watchdog reset detected at 0x%lx\n",
35496a3b5cSAtsushi Nemoto read_c0_errorepc());
3694a4c329SAtsushi Nemoto /* clear WatchDogReset (W1C) */
3794a4c329SAtsushi Nemoto tx4938_ccfg_set(TX4938_CCFG_WDRST);
3894a4c329SAtsushi Nemoto /* do reset on watchdog */
3994a4c329SAtsushi Nemoto tx4938_ccfg_set(TX4938_CCFG_WR);
4094a4c329SAtsushi Nemoto }
4194a4c329SAtsushi Nemoto
tx4938_wdt_init(void)4268314725SAtsushi Nemoto void __init tx4938_wdt_init(void)
4368314725SAtsushi Nemoto {
4468314725SAtsushi Nemoto txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
4568314725SAtsushi Nemoto }
4668314725SAtsushi Nemoto
tx4938_machine_restart(char * command)47496a3b5cSAtsushi Nemoto static void tx4938_machine_restart(char *command)
48496a3b5cSAtsushi Nemoto {
49496a3b5cSAtsushi Nemoto local_irq_disable();
50496a3b5cSAtsushi Nemoto pr_emerg("Rebooting (with %s watchdog reset)...\n",
51496a3b5cSAtsushi Nemoto (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ?
52496a3b5cSAtsushi Nemoto "external" : "internal");
53496a3b5cSAtsushi Nemoto /* clear watchdog status */
54496a3b5cSAtsushi Nemoto tx4938_ccfg_set(TX4938_CCFG_WDRST); /* W1C */
55496a3b5cSAtsushi Nemoto txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL);
56496a3b5cSAtsushi Nemoto while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST))
57496a3b5cSAtsushi Nemoto ;
58496a3b5cSAtsushi Nemoto mdelay(10);
59496a3b5cSAtsushi Nemoto if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) {
60496a3b5cSAtsushi Nemoto pr_emerg("Rebooting (with internal watchdog reset)...\n");
61496a3b5cSAtsushi Nemoto /* External WDRST failed. Do internal watchdog reset */
62496a3b5cSAtsushi Nemoto tx4938_ccfg_clear(TX4938_CCFG_WDREXEN);
63496a3b5cSAtsushi Nemoto }
64496a3b5cSAtsushi Nemoto /* fallback */
65496a3b5cSAtsushi Nemoto (*_machine_halt)();
66496a3b5cSAtsushi Nemoto }
67496a3b5cSAtsushi Nemoto
68ce8e7411SAtsushi Nemoto void show_registers(struct pt_regs *regs);
tx4938_be_handler(struct pt_regs * regs,int is_fixup)69ce8e7411SAtsushi Nemoto static int tx4938_be_handler(struct pt_regs *regs, int is_fixup)
70ce8e7411SAtsushi Nemoto {
71ce8e7411SAtsushi Nemoto int data = regs->cp0_cause & 4;
72ce8e7411SAtsushi Nemoto console_verbose();
73ce8e7411SAtsushi Nemoto pr_err("%cBE exception at %#lx\n", data ? 'D' : 'I', regs->cp0_epc);
74ce8e7411SAtsushi Nemoto pr_err("ccfg:%llx, toea:%llx\n",
75ce8e7411SAtsushi Nemoto (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
76ce8e7411SAtsushi Nemoto (unsigned long long)____raw_readq(&tx4938_ccfgptr->toea));
77ce8e7411SAtsushi Nemoto #ifdef CONFIG_PCI
78ce8e7411SAtsushi Nemoto tx4927_report_pcic_status();
79ce8e7411SAtsushi Nemoto #endif
80ce8e7411SAtsushi Nemoto show_registers(regs);
81ce8e7411SAtsushi Nemoto panic("BusError!");
82ce8e7411SAtsushi Nemoto }
tx4938_be_init(void)83ce8e7411SAtsushi Nemoto static void __init tx4938_be_init(void)
84ce8e7411SAtsushi Nemoto {
85*1f761b3eSFlorian Fainelli mips_set_be_handler(tx4938_be_handler);
86ce8e7411SAtsushi Nemoto }
87ce8e7411SAtsushi Nemoto
8894a4c329SAtsushi Nemoto static struct resource tx4938_sdram_resource[4];
8994a4c329SAtsushi Nemoto static struct resource tx4938_sram_resource;
9094a4c329SAtsushi Nemoto
9194a4c329SAtsushi Nemoto #define TX4938_SRAM_SIZE 0x800
9294a4c329SAtsushi Nemoto
tx4938_setup(void)9394a4c329SAtsushi Nemoto void __init tx4938_setup(void)
9494a4c329SAtsushi Nemoto {
9594a4c329SAtsushi Nemoto int i;
9694a4c329SAtsushi Nemoto __u32 divmode;
97740ebe4aSAtsushi Nemoto unsigned int cpuclk = 0;
9894a4c329SAtsushi Nemoto u64 ccfg;
9994a4c329SAtsushi Nemoto
10094a4c329SAtsushi Nemoto txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
10194a4c329SAtsushi Nemoto TX4938_REG_SIZE);
102d10e025fSAtsushi Nemoto set_c0_config(TX49_CONF_CWFON);
10394a4c329SAtsushi Nemoto
10494a4c329SAtsushi Nemoto /* SDRAMC,EBUSC are configured by PROM */
10594a4c329SAtsushi Nemoto for (i = 0; i < 8; i++) {
10694a4c329SAtsushi Nemoto if (!(TX4938_EBUSC_CR(i) & 0x8))
10794a4c329SAtsushi Nemoto continue; /* disabled */
10894a4c329SAtsushi Nemoto txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
10994a4c329SAtsushi Nemoto txx9_ce_res[i].end =
11094a4c329SAtsushi Nemoto txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
11194a4c329SAtsushi Nemoto request_resource(&iomem_resource, &txx9_ce_res[i]);
11294a4c329SAtsushi Nemoto }
11394a4c329SAtsushi Nemoto
11494a4c329SAtsushi Nemoto /* clocks */
11594a4c329SAtsushi Nemoto ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
11694a4c329SAtsushi Nemoto if (txx9_master_clock) {
11794a4c329SAtsushi Nemoto /* calculate gbus_clock and cpu_clock from master_clock */
11894a4c329SAtsushi Nemoto divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
11994a4c329SAtsushi Nemoto switch (divmode) {
12094a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_8:
12194a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_10:
12294a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_12:
12394a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_16:
12494a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_18:
12594a4c329SAtsushi Nemoto txx9_gbus_clock = txx9_master_clock * 4; break;
12694a4c329SAtsushi Nemoto default:
12794a4c329SAtsushi Nemoto txx9_gbus_clock = txx9_master_clock;
12894a4c329SAtsushi Nemoto }
12994a4c329SAtsushi Nemoto switch (divmode) {
13094a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_2:
13194a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_8:
13294a4c329SAtsushi Nemoto cpuclk = txx9_gbus_clock * 2; break;
13394a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_2_5:
13494a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_10:
13594a4c329SAtsushi Nemoto cpuclk = txx9_gbus_clock * 5 / 2; break;
13694a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_3:
13794a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_12:
13894a4c329SAtsushi Nemoto cpuclk = txx9_gbus_clock * 3; break;
13994a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_4:
14094a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_16:
14194a4c329SAtsushi Nemoto cpuclk = txx9_gbus_clock * 4; break;
14294a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_4_5:
14394a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_18:
14494a4c329SAtsushi Nemoto cpuclk = txx9_gbus_clock * 9 / 2; break;
14594a4c329SAtsushi Nemoto }
14694a4c329SAtsushi Nemoto txx9_cpu_clock = cpuclk;
14794a4c329SAtsushi Nemoto } else {
14894a4c329SAtsushi Nemoto if (txx9_cpu_clock == 0)
14994a4c329SAtsushi Nemoto txx9_cpu_clock = 300000000; /* 300MHz */
15094a4c329SAtsushi Nemoto /* calculate gbus_clock and master_clock from cpu_clock */
15194a4c329SAtsushi Nemoto cpuclk = txx9_cpu_clock;
15294a4c329SAtsushi Nemoto divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
15394a4c329SAtsushi Nemoto switch (divmode) {
15494a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_2:
15594a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_8:
15694a4c329SAtsushi Nemoto txx9_gbus_clock = cpuclk / 2; break;
15794a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_2_5:
15894a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_10:
15994a4c329SAtsushi Nemoto txx9_gbus_clock = cpuclk * 2 / 5; break;
16094a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_3:
16194a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_12:
16294a4c329SAtsushi Nemoto txx9_gbus_clock = cpuclk / 3; break;
16394a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_4:
16494a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_16:
16594a4c329SAtsushi Nemoto txx9_gbus_clock = cpuclk / 4; break;
16694a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_4_5:
16794a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_18:
16894a4c329SAtsushi Nemoto txx9_gbus_clock = cpuclk * 2 / 9; break;
16994a4c329SAtsushi Nemoto }
17094a4c329SAtsushi Nemoto switch (divmode) {
17194a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_8:
17294a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_10:
17394a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_12:
17494a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_16:
17594a4c329SAtsushi Nemoto case TX4938_CCFG_DIVMODE_18:
17694a4c329SAtsushi Nemoto txx9_master_clock = txx9_gbus_clock / 4; break;
17794a4c329SAtsushi Nemoto default:
17894a4c329SAtsushi Nemoto txx9_master_clock = txx9_gbus_clock;
17994a4c329SAtsushi Nemoto }
18094a4c329SAtsushi Nemoto }
18194a4c329SAtsushi Nemoto /* change default value to udelay/mdelay take reasonable time */
18294a4c329SAtsushi Nemoto loops_per_jiffy = txx9_cpu_clock / HZ / 2;
18394a4c329SAtsushi Nemoto
18494a4c329SAtsushi Nemoto /* CCFG */
18594a4c329SAtsushi Nemoto tx4938_wdr_init();
18694a4c329SAtsushi Nemoto /* clear BusErrorOnWrite flag (W1C) */
18794a4c329SAtsushi Nemoto tx4938_ccfg_set(TX4938_CCFG_BEOW);
18894a4c329SAtsushi Nemoto /* enable Timeout BusError */
18994a4c329SAtsushi Nemoto if (txx9_ccfg_toeon)
19094a4c329SAtsushi Nemoto tx4938_ccfg_set(TX4938_CCFG_TOE);
19194a4c329SAtsushi Nemoto
19294a4c329SAtsushi Nemoto /* DMA selection */
19394a4c329SAtsushi Nemoto txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
19494a4c329SAtsushi Nemoto
19594a4c329SAtsushi Nemoto /* Use external clock for external arbiter */
19694a4c329SAtsushi Nemoto if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
19794a4c329SAtsushi Nemoto txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
19894a4c329SAtsushi Nemoto
1992cec11d8SGeert Uytterhoeven pr_info("%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
2002cec11d8SGeert Uytterhoeven txx9_pcode_str, (cpuclk + 500000) / 1000000,
20194a4c329SAtsushi Nemoto (txx9_master_clock + 500000) / 1000000,
20294a4c329SAtsushi Nemoto (__u32)____raw_readq(&tx4938_ccfgptr->crir),
2032cec11d8SGeert Uytterhoeven ____raw_readq(&tx4938_ccfgptr->ccfg),
2042cec11d8SGeert Uytterhoeven ____raw_readq(&tx4938_ccfgptr->pcfg));
20594a4c329SAtsushi Nemoto
2062cec11d8SGeert Uytterhoeven pr_info("%s SDRAMC --", txx9_pcode_str);
20794a4c329SAtsushi Nemoto for (i = 0; i < 4; i++) {
20894a4c329SAtsushi Nemoto __u64 cr = TX4938_SDRAMC_CR(i);
20994a4c329SAtsushi Nemoto unsigned long base, size;
21094a4c329SAtsushi Nemoto if (!((__u32)cr & 0x00000400))
21194a4c329SAtsushi Nemoto continue; /* disabled */
21294a4c329SAtsushi Nemoto base = (unsigned long)(cr >> 49) << 21;
21394a4c329SAtsushi Nemoto size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
2142cec11d8SGeert Uytterhoeven pr_cont(" CR%d:%016llx", i, cr);
21594a4c329SAtsushi Nemoto tx4938_sdram_resource[i].name = "SDRAM";
21694a4c329SAtsushi Nemoto tx4938_sdram_resource[i].start = base;
21794a4c329SAtsushi Nemoto tx4938_sdram_resource[i].end = base + size - 1;
21894a4c329SAtsushi Nemoto tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
21994a4c329SAtsushi Nemoto request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
22094a4c329SAtsushi Nemoto }
2212cec11d8SGeert Uytterhoeven pr_cont(" TR:%09llx\n", ____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 /* PIO */
24294a4c329SAtsushi Nemoto __raw_writel(0, &tx4938_pioptr->maskcpu);
24394a4c329SAtsushi Nemoto __raw_writel(0, &tx4938_pioptr->maskext);
24494a4c329SAtsushi Nemoto
24594a4c329SAtsushi Nemoto if (txx9_pcode == 0x4938) {
24694a4c329SAtsushi Nemoto __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
24794a4c329SAtsushi Nemoto /* set PCIC1 reset */
24894a4c329SAtsushi Nemoto txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
24994a4c329SAtsushi Nemoto if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
25094a4c329SAtsushi Nemoto mdelay(1); /* at least 128 cpu clock */
25194a4c329SAtsushi Nemoto /* clear PCIC1 reset */
25294a4c329SAtsushi Nemoto txx9_clear64(&tx4938_ccfgptr->clkctr,
25394a4c329SAtsushi Nemoto TX4938_CLKCTR_PCIC1RST);
25494a4c329SAtsushi Nemoto } else {
2552cec11d8SGeert Uytterhoeven pr_info("%s: stop PCIC1\n", txx9_pcode_str);
25694a4c329SAtsushi Nemoto /* stop PCIC1 */
25794a4c329SAtsushi Nemoto txx9_set64(&tx4938_ccfgptr->clkctr,
25894a4c329SAtsushi Nemoto TX4938_CLKCTR_PCIC1CKD);
25994a4c329SAtsushi Nemoto }
26094a4c329SAtsushi Nemoto if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
2612cec11d8SGeert Uytterhoeven pr_info("%s: stop ETH0\n", txx9_pcode_str);
26294a4c329SAtsushi Nemoto txx9_set64(&tx4938_ccfgptr->clkctr,
26394a4c329SAtsushi Nemoto TX4938_CLKCTR_ETH0RST);
26494a4c329SAtsushi Nemoto txx9_set64(&tx4938_ccfgptr->clkctr,
26594a4c329SAtsushi Nemoto TX4938_CLKCTR_ETH0CKD);
26694a4c329SAtsushi Nemoto }
26794a4c329SAtsushi Nemoto if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
2682cec11d8SGeert Uytterhoeven pr_info("%s: stop ETH1\n", txx9_pcode_str);
26994a4c329SAtsushi Nemoto txx9_set64(&tx4938_ccfgptr->clkctr,
27094a4c329SAtsushi Nemoto TX4938_CLKCTR_ETH1RST);
27194a4c329SAtsushi Nemoto txx9_set64(&tx4938_ccfgptr->clkctr,
27294a4c329SAtsushi Nemoto TX4938_CLKCTR_ETH1CKD);
27394a4c329SAtsushi Nemoto }
27494a4c329SAtsushi Nemoto }
275496a3b5cSAtsushi Nemoto
276496a3b5cSAtsushi Nemoto _machine_restart = tx4938_machine_restart;
277ce8e7411SAtsushi Nemoto board_be_init = tx4938_be_init;
27894a4c329SAtsushi Nemoto }
27994a4c329SAtsushi Nemoto
tx4938_time_init(unsigned int tmrnr)28094a4c329SAtsushi Nemoto void __init tx4938_time_init(unsigned int tmrnr)
28194a4c329SAtsushi Nemoto {
28294a4c329SAtsushi Nemoto if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
28394a4c329SAtsushi Nemoto txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
28494a4c329SAtsushi Nemoto TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
28594a4c329SAtsushi Nemoto TXX9_IMCLK);
28694a4c329SAtsushi Nemoto }
28794a4c329SAtsushi Nemoto
tx4938_sio_init(unsigned int sclk,unsigned int cts_mask)2887779a5e0SAtsushi Nemoto void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
28994a4c329SAtsushi Nemoto {
29094a4c329SAtsushi Nemoto int i;
29194a4c329SAtsushi Nemoto unsigned int ch_mask = 0;
29294a4c329SAtsushi Nemoto
29394a4c329SAtsushi Nemoto if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
29494a4c329SAtsushi Nemoto ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
29594a4c329SAtsushi Nemoto for (i = 0; i < 2; i++) {
29694a4c329SAtsushi Nemoto if ((1 << i) & ch_mask)
29794a4c329SAtsushi Nemoto continue;
2987779a5e0SAtsushi Nemoto txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
2997779a5e0SAtsushi Nemoto TXX9_IRQ_BASE + TX4938_IR_SIO(i),
3007779a5e0SAtsushi Nemoto i, sclk, (1 << i) & cts_mask);
30194a4c329SAtsushi Nemoto }
30294a4c329SAtsushi Nemoto }
303c49f91f5SAtsushi Nemoto
tx4938_spi_init(int busid)304c49f91f5SAtsushi Nemoto void __init tx4938_spi_init(int busid)
305c49f91f5SAtsushi Nemoto {
306c49f91f5SAtsushi Nemoto txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
307c49f91f5SAtsushi Nemoto TXX9_IRQ_BASE + TX4938_IR_SPI);
308c49f91f5SAtsushi Nemoto }
309c49f91f5SAtsushi Nemoto
tx4938_ethaddr_init(unsigned char * addr0,unsigned char * addr1)310c49f91f5SAtsushi Nemoto void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
311c49f91f5SAtsushi Nemoto {
312c49f91f5SAtsushi Nemoto u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
313c49f91f5SAtsushi Nemoto
314c49f91f5SAtsushi Nemoto if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
315c49f91f5SAtsushi Nemoto txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
316c49f91f5SAtsushi Nemoto if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
317c49f91f5SAtsushi Nemoto txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);
318c49f91f5SAtsushi Nemoto }
31951f607c7SAtsushi Nemoto
tx4938_mtd_init(int ch)32051f607c7SAtsushi Nemoto void __init tx4938_mtd_init(int ch)
32151f607c7SAtsushi Nemoto {
32251f607c7SAtsushi Nemoto struct physmap_flash_data pdata = {
32351f607c7SAtsushi Nemoto .width = TX4938_EBUSC_WIDTH(ch) / 8,
32451f607c7SAtsushi Nemoto };
32551f607c7SAtsushi Nemoto unsigned long start = txx9_ce_res[ch].start;
32651f607c7SAtsushi Nemoto unsigned long size = txx9_ce_res[ch].end - start + 1;
32751f607c7SAtsushi Nemoto
32851f607c7SAtsushi Nemoto if (!(TX4938_EBUSC_CR(ch) & 0x8))
32951f607c7SAtsushi Nemoto return; /* disabled */
33051f607c7SAtsushi Nemoto txx9_physmap_flash_init(ch, start, size, &pdata);
33151f607c7SAtsushi Nemoto }
332f6d9831bSAtsushi Nemoto
tx4938_ata_init(unsigned int irq,unsigned int shift,int tune)3335d1d2f8cSAtsushi Nemoto void __init tx4938_ata_init(unsigned int irq, unsigned int shift, int tune)
3345d1d2f8cSAtsushi Nemoto {
3355d1d2f8cSAtsushi Nemoto struct platform_device *pdev;
3365d1d2f8cSAtsushi Nemoto struct resource res[] = {
3375d1d2f8cSAtsushi Nemoto {
3385d1d2f8cSAtsushi Nemoto /* .start and .end are filled in later */
3395d1d2f8cSAtsushi Nemoto .flags = IORESOURCE_MEM,
3405d1d2f8cSAtsushi Nemoto }, {
3415d1d2f8cSAtsushi Nemoto .start = irq,
3425d1d2f8cSAtsushi Nemoto .flags = IORESOURCE_IRQ,
3435d1d2f8cSAtsushi Nemoto },
3445d1d2f8cSAtsushi Nemoto };
3455d1d2f8cSAtsushi Nemoto struct tx4938ide_platform_info pdata = {
3465d1d2f8cSAtsushi Nemoto .ioport_shift = shift,
3475d1d2f8cSAtsushi Nemoto /*
3485d1d2f8cSAtsushi Nemoto * The IDE driver should not change bus timings if other ISA
3495d1d2f8cSAtsushi Nemoto * devices existed.
3505d1d2f8cSAtsushi Nemoto */
3515d1d2f8cSAtsushi Nemoto .gbus_clock = tune ? txx9_gbus_clock : 0,
3525d1d2f8cSAtsushi Nemoto };
3535d1d2f8cSAtsushi Nemoto u64 ebccr;
3545d1d2f8cSAtsushi Nemoto int i;
3555d1d2f8cSAtsushi Nemoto
3565d1d2f8cSAtsushi Nemoto if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
3575d1d2f8cSAtsushi Nemoto (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL))
3585d1d2f8cSAtsushi Nemoto != TX4938_PCFG_ATA_SEL)
3595d1d2f8cSAtsushi Nemoto return;
3605d1d2f8cSAtsushi Nemoto for (i = 0; i < 8; i++) {
3615d1d2f8cSAtsushi Nemoto /* check EBCCRn.ISA, EBCCRn.BSZ, EBCCRn.ME */
3625d1d2f8cSAtsushi Nemoto ebccr = __raw_readq(&tx4938_ebuscptr->cr[i]);
3635d1d2f8cSAtsushi Nemoto if ((ebccr & 0x00f00008) == 0x00e00008)
3645d1d2f8cSAtsushi Nemoto break;
3655d1d2f8cSAtsushi Nemoto }
3665d1d2f8cSAtsushi Nemoto if (i == 8)
3675d1d2f8cSAtsushi Nemoto return;
3685d1d2f8cSAtsushi Nemoto pdata.ebus_ch = i;
3695d1d2f8cSAtsushi Nemoto res[0].start = ((ebccr >> 48) << 20) + 0x10000;
3705d1d2f8cSAtsushi Nemoto res[0].end = res[0].start + 0x20000 - 1;
3715d1d2f8cSAtsushi Nemoto pdev = platform_device_alloc("tx4938ide", -1);
3725d1d2f8cSAtsushi Nemoto if (!pdev ||
3735d1d2f8cSAtsushi Nemoto platform_device_add_resources(pdev, res, ARRAY_SIZE(res)) ||
3745d1d2f8cSAtsushi Nemoto platform_device_add_data(pdev, &pdata, sizeof(pdata)) ||
3755d1d2f8cSAtsushi Nemoto platform_device_add(pdev))
3765d1d2f8cSAtsushi Nemoto platform_device_put(pdev);
3775d1d2f8cSAtsushi Nemoto }
3785d1d2f8cSAtsushi Nemoto
tx4938_ndfmc_init(unsigned int hold,unsigned int spw)379a591f5d3SAtsushi Nemoto void __init tx4938_ndfmc_init(unsigned int hold, unsigned int spw)
380a591f5d3SAtsushi Nemoto {
381a591f5d3SAtsushi Nemoto struct txx9ndfmc_platform_data plat_data = {
382a591f5d3SAtsushi Nemoto .shift = 1,
383a591f5d3SAtsushi Nemoto .gbus_clock = txx9_gbus_clock,
384a591f5d3SAtsushi Nemoto .hold = hold,
385a591f5d3SAtsushi Nemoto .spw = spw,
386a591f5d3SAtsushi Nemoto .ch_mask = 1,
387a591f5d3SAtsushi Nemoto };
388a591f5d3SAtsushi Nemoto unsigned long baseaddr = TX4938_NDFMC_REG & 0xfffffffffULL;
389a591f5d3SAtsushi Nemoto
390a591f5d3SAtsushi Nemoto #ifdef __BIG_ENDIAN
391a591f5d3SAtsushi Nemoto baseaddr += 4;
392a591f5d3SAtsushi Nemoto #endif
393a591f5d3SAtsushi Nemoto if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
394a591f5d3SAtsushi Nemoto (TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL)) ==
395a591f5d3SAtsushi Nemoto TX4938_PCFG_NDF_SEL)
396a591f5d3SAtsushi Nemoto txx9_ndfmc_init(baseaddr, &plat_data);
397a591f5d3SAtsushi Nemoto }
398a591f5d3SAtsushi Nemoto
tx4938_dmac_init(int memcpy_chan0,int memcpy_chan1)399f48c8c95SAtsushi Nemoto void __init tx4938_dmac_init(int memcpy_chan0, int memcpy_chan1)
400f48c8c95SAtsushi Nemoto {
401f48c8c95SAtsushi Nemoto struct txx9dmac_platform_data plat_data = {
402f48c8c95SAtsushi Nemoto .have_64bit_regs = true,
403f48c8c95SAtsushi Nemoto };
404f48c8c95SAtsushi Nemoto int i;
405f48c8c95SAtsushi Nemoto
406f48c8c95SAtsushi Nemoto for (i = 0; i < 2; i++) {
407f48c8c95SAtsushi Nemoto plat_data.memcpy_chan = i ? memcpy_chan1 : memcpy_chan0;
408f48c8c95SAtsushi Nemoto txx9_dmac_init(i, TX4938_DMA_REG(i) & 0xfffffffffULL,
409f48c8c95SAtsushi Nemoto TXX9_IRQ_BASE + TX4938_IR_DMA(i, 0),
410f48c8c95SAtsushi Nemoto &plat_data);
411f48c8c95SAtsushi Nemoto }
412f48c8c95SAtsushi Nemoto }
413f48c8c95SAtsushi Nemoto
tx4938_aclc_init(void)414742cd586SAtsushi Nemoto void __init tx4938_aclc_init(void)
415742cd586SAtsushi Nemoto {
416742cd586SAtsushi Nemoto u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
417742cd586SAtsushi Nemoto
418742cd586SAtsushi Nemoto if ((pcfg & TX4938_PCFG_SEL2) &&
419742cd586SAtsushi Nemoto !(pcfg & TX4938_PCFG_ETH0_SEL))
420742cd586SAtsushi Nemoto txx9_aclc_init(TX4938_ACLC_REG & 0xfffffffffULL,
421742cd586SAtsushi Nemoto TXX9_IRQ_BASE + TX4938_IR_ACLC,
422742cd586SAtsushi Nemoto 1, 0, 1);
423742cd586SAtsushi Nemoto }
424742cd586SAtsushi Nemoto
tx4938_sramc_init(void)425c3b28ae2SAtsushi Nemoto void __init tx4938_sramc_init(void)
426c3b28ae2SAtsushi Nemoto {
427c3b28ae2SAtsushi Nemoto if (tx4938_sram_resource.start)
428c3b28ae2SAtsushi Nemoto txx9_sramc_init(&tx4938_sram_resource);
429c3b28ae2SAtsushi Nemoto }
430c3b28ae2SAtsushi Nemoto
tx4938_stop_unused_modules(void)431f6d9831bSAtsushi Nemoto static void __init tx4938_stop_unused_modules(void)
432f6d9831bSAtsushi Nemoto {
433f6d9831bSAtsushi Nemoto __u64 pcfg, rst = 0, ckd = 0;
434f6d9831bSAtsushi Nemoto char buf[128];
435f6d9831bSAtsushi Nemoto
436f6d9831bSAtsushi Nemoto buf[0] = '\0';
437f6d9831bSAtsushi Nemoto local_irq_disable();
438f6d9831bSAtsushi Nemoto pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
439f6d9831bSAtsushi Nemoto switch (txx9_pcode) {
440f6d9831bSAtsushi Nemoto case 0x4937:
441f6d9831bSAtsushi Nemoto if (!(pcfg & TX4938_PCFG_SEL2)) {
442f6d9831bSAtsushi Nemoto rst |= TX4938_CLKCTR_ACLRST;
443f6d9831bSAtsushi Nemoto ckd |= TX4938_CLKCTR_ACLCKD;
444f6d9831bSAtsushi Nemoto strcat(buf, " ACLC");
445f6d9831bSAtsushi Nemoto }
446f6d9831bSAtsushi Nemoto break;
447f6d9831bSAtsushi Nemoto case 0x4938:
448f6d9831bSAtsushi Nemoto if (!(pcfg & TX4938_PCFG_SEL2) ||
449f6d9831bSAtsushi Nemoto (pcfg & TX4938_PCFG_ETH0_SEL)) {
450f6d9831bSAtsushi Nemoto rst |= TX4938_CLKCTR_ACLRST;
451f6d9831bSAtsushi Nemoto ckd |= TX4938_CLKCTR_ACLCKD;
452f6d9831bSAtsushi Nemoto strcat(buf, " ACLC");
453f6d9831bSAtsushi Nemoto }
454f6d9831bSAtsushi Nemoto if ((pcfg &
455f6d9831bSAtsushi Nemoto (TX4938_PCFG_ATA_SEL | TX4938_PCFG_ISA_SEL |
456f6d9831bSAtsushi Nemoto TX4938_PCFG_NDF_SEL))
457f6d9831bSAtsushi Nemoto != TX4938_PCFG_NDF_SEL) {
458f6d9831bSAtsushi Nemoto rst |= TX4938_CLKCTR_NDFRST;
459f6d9831bSAtsushi Nemoto ckd |= TX4938_CLKCTR_NDFCKD;
460f6d9831bSAtsushi Nemoto strcat(buf, " NDFMC");
461f6d9831bSAtsushi Nemoto }
462f6d9831bSAtsushi Nemoto if (!(pcfg & TX4938_PCFG_SPI_SEL)) {
463f6d9831bSAtsushi Nemoto rst |= TX4938_CLKCTR_SPIRST;
464f6d9831bSAtsushi Nemoto ckd |= TX4938_CLKCTR_SPICKD;
465f6d9831bSAtsushi Nemoto strcat(buf, " SPI");
466f6d9831bSAtsushi Nemoto }
467f6d9831bSAtsushi Nemoto break;
468f6d9831bSAtsushi Nemoto }
469f6d9831bSAtsushi Nemoto if (rst | ckd) {
470f6d9831bSAtsushi Nemoto txx9_set64(&tx4938_ccfgptr->clkctr, rst);
471f6d9831bSAtsushi Nemoto txx9_set64(&tx4938_ccfgptr->clkctr, ckd);
472f6d9831bSAtsushi Nemoto }
473f6d9831bSAtsushi Nemoto local_irq_enable();
474f6d9831bSAtsushi Nemoto if (buf[0])
475f6d9831bSAtsushi Nemoto pr_info("%s: stop%s\n", txx9_pcode_str, buf);
476f6d9831bSAtsushi Nemoto }
477f6d9831bSAtsushi Nemoto
tx4938_late_init(void)478f6d9831bSAtsushi Nemoto static int __init tx4938_late_init(void)
479f6d9831bSAtsushi Nemoto {
480f6d9831bSAtsushi Nemoto if (txx9_pcode != 0x4937 && txx9_pcode != 0x4938)
481f6d9831bSAtsushi Nemoto return -ENODEV;
482f6d9831bSAtsushi Nemoto tx4938_stop_unused_modules();
483f6d9831bSAtsushi Nemoto return 0;
484f6d9831bSAtsushi Nemoto }
485f6d9831bSAtsushi Nemoto late_initcall(tx4938_late_init);
486