2 * TX4938/4937 setup routines
3 * Based on linux/arch/mips/txx9/rbtx4938/setup.c,
4 * and RBTX49xx patch from CELF patch archive.
6 * 2003-2005 (c) MontaVista Software, Inc.
7 * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/delay.h>
16 #include <linux/param.h>
17 #include <asm/txx9irq.h>
18 #include <asm/txx9tmr.h>
19 #include <asm/txx9pio.h>
20 #include <asm/txx9/generic.h>
21 #include <asm/txx9/tx4938.h>
23 static void __init tx4938_wdr_init(void)
25 /* clear WatchDogReset (W1C) */
26 tx4938_ccfg_set(TX4938_CCFG_WDRST);
27 /* do reset on watchdog */
28 tx4938_ccfg_set(TX4938_CCFG_WR);
31 void __init tx4938_wdt_init(void)
33 txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
36 static struct resource tx4938_sdram_resource[4];
37 static struct resource tx4938_sram_resource;
39 #define TX4938_SRAM_SIZE 0x800
41 void __init tx4938_setup(void)
48 txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
51 /* SDRAMC,EBUSC are configured by PROM */
52 for (i = 0; i < 8; i++) {
53 if (!(TX4938_EBUSC_CR(i) & 0x8))
54 continue; /* disabled */
55 txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
57 txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
58 request_resource(&iomem_resource, &txx9_ce_res[i]);
62 ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
63 if (txx9_master_clock) {
64 /* calculate gbus_clock and cpu_clock from master_clock */
65 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
67 case TX4938_CCFG_DIVMODE_8:
68 case TX4938_CCFG_DIVMODE_10:
69 case TX4938_CCFG_DIVMODE_12:
70 case TX4938_CCFG_DIVMODE_16:
71 case TX4938_CCFG_DIVMODE_18:
72 txx9_gbus_clock = txx9_master_clock * 4; break;
74 txx9_gbus_clock = txx9_master_clock;
77 case TX4938_CCFG_DIVMODE_2:
78 case TX4938_CCFG_DIVMODE_8:
79 cpuclk = txx9_gbus_clock * 2; break;
80 case TX4938_CCFG_DIVMODE_2_5:
81 case TX4938_CCFG_DIVMODE_10:
82 cpuclk = txx9_gbus_clock * 5 / 2; break;
83 case TX4938_CCFG_DIVMODE_3:
84 case TX4938_CCFG_DIVMODE_12:
85 cpuclk = txx9_gbus_clock * 3; break;
86 case TX4938_CCFG_DIVMODE_4:
87 case TX4938_CCFG_DIVMODE_16:
88 cpuclk = txx9_gbus_clock * 4; break;
89 case TX4938_CCFG_DIVMODE_4_5:
90 case TX4938_CCFG_DIVMODE_18:
91 cpuclk = txx9_gbus_clock * 9 / 2; break;
93 txx9_cpu_clock = cpuclk;
95 if (txx9_cpu_clock == 0)
96 txx9_cpu_clock = 300000000; /* 300MHz */
97 /* calculate gbus_clock and master_clock from cpu_clock */
98 cpuclk = txx9_cpu_clock;
99 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
101 case TX4938_CCFG_DIVMODE_2:
102 case TX4938_CCFG_DIVMODE_8:
103 txx9_gbus_clock = cpuclk / 2; break;
104 case TX4938_CCFG_DIVMODE_2_5:
105 case TX4938_CCFG_DIVMODE_10:
106 txx9_gbus_clock = cpuclk * 2 / 5; break;
107 case TX4938_CCFG_DIVMODE_3:
108 case TX4938_CCFG_DIVMODE_12:
109 txx9_gbus_clock = cpuclk / 3; break;
110 case TX4938_CCFG_DIVMODE_4:
111 case TX4938_CCFG_DIVMODE_16:
112 txx9_gbus_clock = cpuclk / 4; break;
113 case TX4938_CCFG_DIVMODE_4_5:
114 case TX4938_CCFG_DIVMODE_18:
115 txx9_gbus_clock = cpuclk * 2 / 9; break;
118 case TX4938_CCFG_DIVMODE_8:
119 case TX4938_CCFG_DIVMODE_10:
120 case TX4938_CCFG_DIVMODE_12:
121 case TX4938_CCFG_DIVMODE_16:
122 case TX4938_CCFG_DIVMODE_18:
123 txx9_master_clock = txx9_gbus_clock / 4; break;
125 txx9_master_clock = txx9_gbus_clock;
128 /* change default value to udelay/mdelay take reasonable time */
129 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
133 /* clear BusErrorOnWrite flag (W1C) */
134 tx4938_ccfg_set(TX4938_CCFG_BEOW);
135 /* enable Timeout BusError */
137 tx4938_ccfg_set(TX4938_CCFG_TOE);
140 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
142 /* Use external clock for external arbiter */
143 if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
144 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
146 printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
148 (cpuclk + 500000) / 1000000,
149 (txx9_master_clock + 500000) / 1000000,
150 (__u32)____raw_readq(&tx4938_ccfgptr->crir),
151 (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
152 (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
154 printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
155 for (i = 0; i < 4; i++) {
156 __u64 cr = TX4938_SDRAMC_CR(i);
157 unsigned long base, size;
158 if (!((__u32)cr & 0x00000400))
159 continue; /* disabled */
160 base = (unsigned long)(cr >> 49) << 21;
161 size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
162 printk(" CR%d:%016llx", i, (unsigned long long)cr);
163 tx4938_sdram_resource[i].name = "SDRAM";
164 tx4938_sdram_resource[i].start = base;
165 tx4938_sdram_resource[i].end = base + size - 1;
166 tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
167 request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
169 printk(" TR:%09llx\n",
170 (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
173 if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
174 unsigned int size = TX4938_SRAM_SIZE;
175 tx4938_sram_resource.name = "SRAM";
176 tx4938_sram_resource.start =
177 (____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
179 tx4938_sram_resource.end =
180 tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
181 tx4938_sram_resource.flags = IORESOURCE_MEM;
182 request_resource(&iomem_resource, &tx4938_sram_resource);
186 /* disable all timers */
187 for (i = 0; i < TX4938_NR_TMR; i++)
188 txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
191 for (i = 0; i < 2; i++)
192 ____raw_writeq(TX4938_DMA_MCR_MSTEN,
193 (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
196 txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
197 __raw_writel(0, &tx4938_pioptr->maskcpu);
198 __raw_writel(0, &tx4938_pioptr->maskext);
200 if (txx9_pcode == 0x4938) {
201 __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
202 /* set PCIC1 reset */
203 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
204 if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
205 mdelay(1); /* at least 128 cpu clock */
206 /* clear PCIC1 reset */
207 txx9_clear64(&tx4938_ccfgptr->clkctr,
208 TX4938_CLKCTR_PCIC1RST);
210 printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
212 txx9_set64(&tx4938_ccfgptr->clkctr,
213 TX4938_CLKCTR_PCIC1CKD);
215 if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
216 printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
217 txx9_set64(&tx4938_ccfgptr->clkctr,
218 TX4938_CLKCTR_ETH0RST);
219 txx9_set64(&tx4938_ccfgptr->clkctr,
220 TX4938_CLKCTR_ETH0CKD);
222 if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
223 printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
224 txx9_set64(&tx4938_ccfgptr->clkctr,
225 TX4938_CLKCTR_ETH1RST);
226 txx9_set64(&tx4938_ccfgptr->clkctr,
227 TX4938_CLKCTR_ETH1CKD);
232 void __init tx4938_time_init(unsigned int tmrnr)
234 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
235 txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
236 TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
240 void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
243 unsigned int ch_mask = 0;
245 if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
246 ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
247 for (i = 0; i < 2; i++) {
248 if ((1 << i) & ch_mask)
250 txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
251 TXX9_IRQ_BASE + TX4938_IR_SIO(i),
252 i, sclk, (1 << i) & cts_mask);
256 void __init tx4938_spi_init(int busid)
258 txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
259 TXX9_IRQ_BASE + TX4938_IR_SPI);
262 void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
264 u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
266 if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
267 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
268 if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
269 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);