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 <linux/mtd/physmap.h>
18 #include <asm/reboot.h>
19 #include <asm/txx9irq.h>
20 #include <asm/txx9tmr.h>
21 #include <asm/txx9pio.h>
22 #include <asm/txx9/generic.h>
23 #include <asm/txx9/tx4938.h>
25 static void __init tx4938_wdr_init(void)
27 /* report watchdog reset status */
28 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST)
29 pr_warning("Watchdog reset detected at 0x%lx\n",
31 /* clear WatchDogReset (W1C) */
32 tx4938_ccfg_set(TX4938_CCFG_WDRST);
33 /* do reset on watchdog */
34 tx4938_ccfg_set(TX4938_CCFG_WR);
37 void __init tx4938_wdt_init(void)
39 txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
42 static void tx4938_machine_restart(char *command)
45 pr_emerg("Rebooting (with %s watchdog reset)...\n",
46 (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) ?
47 "external" : "internal");
48 /* clear watchdog status */
49 tx4938_ccfg_set(TX4938_CCFG_WDRST); /* W1C */
50 txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL);
51 while (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDRST))
54 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_WDREXEN) {
55 pr_emerg("Rebooting (with internal watchdog reset)...\n");
56 /* External WDRST failed. Do internal watchdog reset */
57 tx4938_ccfg_clear(TX4938_CCFG_WDREXEN);
63 static struct resource tx4938_sdram_resource[4];
64 static struct resource tx4938_sram_resource;
66 #define TX4938_SRAM_SIZE 0x800
68 void __init tx4938_setup(void)
75 txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE,
77 set_c0_config(TX49_CONF_CWFON);
79 /* SDRAMC,EBUSC are configured by PROM */
80 for (i = 0; i < 8; i++) {
81 if (!(TX4938_EBUSC_CR(i) & 0x8))
82 continue; /* disabled */
83 txx9_ce_res[i].start = (unsigned long)TX4938_EBUSC_BA(i);
85 txx9_ce_res[i].start + TX4938_EBUSC_SIZE(i) - 1;
86 request_resource(&iomem_resource, &txx9_ce_res[i]);
90 ccfg = ____raw_readq(&tx4938_ccfgptr->ccfg);
91 if (txx9_master_clock) {
92 /* calculate gbus_clock and cpu_clock from master_clock */
93 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
95 case TX4938_CCFG_DIVMODE_8:
96 case TX4938_CCFG_DIVMODE_10:
97 case TX4938_CCFG_DIVMODE_12:
98 case TX4938_CCFG_DIVMODE_16:
99 case TX4938_CCFG_DIVMODE_18:
100 txx9_gbus_clock = txx9_master_clock * 4; break;
102 txx9_gbus_clock = txx9_master_clock;
105 case TX4938_CCFG_DIVMODE_2:
106 case TX4938_CCFG_DIVMODE_8:
107 cpuclk = txx9_gbus_clock * 2; break;
108 case TX4938_CCFG_DIVMODE_2_5:
109 case TX4938_CCFG_DIVMODE_10:
110 cpuclk = txx9_gbus_clock * 5 / 2; break;
111 case TX4938_CCFG_DIVMODE_3:
112 case TX4938_CCFG_DIVMODE_12:
113 cpuclk = txx9_gbus_clock * 3; break;
114 case TX4938_CCFG_DIVMODE_4:
115 case TX4938_CCFG_DIVMODE_16:
116 cpuclk = txx9_gbus_clock * 4; break;
117 case TX4938_CCFG_DIVMODE_4_5:
118 case TX4938_CCFG_DIVMODE_18:
119 cpuclk = txx9_gbus_clock * 9 / 2; break;
121 txx9_cpu_clock = cpuclk;
123 if (txx9_cpu_clock == 0)
124 txx9_cpu_clock = 300000000; /* 300MHz */
125 /* calculate gbus_clock and master_clock from cpu_clock */
126 cpuclk = txx9_cpu_clock;
127 divmode = (__u32)ccfg & TX4938_CCFG_DIVMODE_MASK;
129 case TX4938_CCFG_DIVMODE_2:
130 case TX4938_CCFG_DIVMODE_8:
131 txx9_gbus_clock = cpuclk / 2; break;
132 case TX4938_CCFG_DIVMODE_2_5:
133 case TX4938_CCFG_DIVMODE_10:
134 txx9_gbus_clock = cpuclk * 2 / 5; break;
135 case TX4938_CCFG_DIVMODE_3:
136 case TX4938_CCFG_DIVMODE_12:
137 txx9_gbus_clock = cpuclk / 3; break;
138 case TX4938_CCFG_DIVMODE_4:
139 case TX4938_CCFG_DIVMODE_16:
140 txx9_gbus_clock = cpuclk / 4; break;
141 case TX4938_CCFG_DIVMODE_4_5:
142 case TX4938_CCFG_DIVMODE_18:
143 txx9_gbus_clock = cpuclk * 2 / 9; break;
146 case TX4938_CCFG_DIVMODE_8:
147 case TX4938_CCFG_DIVMODE_10:
148 case TX4938_CCFG_DIVMODE_12:
149 case TX4938_CCFG_DIVMODE_16:
150 case TX4938_CCFG_DIVMODE_18:
151 txx9_master_clock = txx9_gbus_clock / 4; break;
153 txx9_master_clock = txx9_gbus_clock;
156 /* change default value to udelay/mdelay take reasonable time */
157 loops_per_jiffy = txx9_cpu_clock / HZ / 2;
161 /* clear BusErrorOnWrite flag (W1C) */
162 tx4938_ccfg_set(TX4938_CCFG_BEOW);
163 /* enable Timeout BusError */
165 tx4938_ccfg_set(TX4938_CCFG_TOE);
168 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_DMASEL_ALL);
170 /* Use external clock for external arbiter */
171 if (!(____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_PCIARB))
172 txx9_clear64(&tx4938_ccfgptr->pcfg, TX4938_PCFG_PCICLKEN_ALL);
174 printk(KERN_INFO "%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
176 (cpuclk + 500000) / 1000000,
177 (txx9_master_clock + 500000) / 1000000,
178 (__u32)____raw_readq(&tx4938_ccfgptr->crir),
179 (unsigned long long)____raw_readq(&tx4938_ccfgptr->ccfg),
180 (unsigned long long)____raw_readq(&tx4938_ccfgptr->pcfg));
182 printk(KERN_INFO "%s SDRAMC --", txx9_pcode_str);
183 for (i = 0; i < 4; i++) {
184 __u64 cr = TX4938_SDRAMC_CR(i);
185 unsigned long base, size;
186 if (!((__u32)cr & 0x00000400))
187 continue; /* disabled */
188 base = (unsigned long)(cr >> 49) << 21;
189 size = (((unsigned long)(cr >> 33) & 0x7fff) + 1) << 21;
190 printk(" CR%d:%016llx", i, (unsigned long long)cr);
191 tx4938_sdram_resource[i].name = "SDRAM";
192 tx4938_sdram_resource[i].start = base;
193 tx4938_sdram_resource[i].end = base + size - 1;
194 tx4938_sdram_resource[i].flags = IORESOURCE_MEM;
195 request_resource(&iomem_resource, &tx4938_sdram_resource[i]);
197 printk(" TR:%09llx\n",
198 (unsigned long long)____raw_readq(&tx4938_sdramcptr->tr));
201 if (txx9_pcode == 0x4938 && ____raw_readq(&tx4938_sramcptr->cr) & 1) {
202 unsigned int size = TX4938_SRAM_SIZE;
203 tx4938_sram_resource.name = "SRAM";
204 tx4938_sram_resource.start =
205 (____raw_readq(&tx4938_sramcptr->cr) >> (39-11))
207 tx4938_sram_resource.end =
208 tx4938_sram_resource.start + TX4938_SRAM_SIZE - 1;
209 tx4938_sram_resource.flags = IORESOURCE_MEM;
210 request_resource(&iomem_resource, &tx4938_sram_resource);
214 /* disable all timers */
215 for (i = 0; i < TX4938_NR_TMR; i++)
216 txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
219 for (i = 0; i < 2; i++)
220 ____raw_writeq(TX4938_DMA_MCR_MSTEN,
221 (void __iomem *)(TX4938_DMA_REG(i) + 0x50));
224 txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, TX4938_NUM_PIO);
225 __raw_writel(0, &tx4938_pioptr->maskcpu);
226 __raw_writel(0, &tx4938_pioptr->maskext);
228 if (txx9_pcode == 0x4938) {
229 __u64 pcfg = ____raw_readq(&tx4938_ccfgptr->pcfg);
230 /* set PCIC1 reset */
231 txx9_set64(&tx4938_ccfgptr->clkctr, TX4938_CLKCTR_PCIC1RST);
232 if (pcfg & (TX4938_PCFG_ETH0_SEL | TX4938_PCFG_ETH1_SEL)) {
233 mdelay(1); /* at least 128 cpu clock */
234 /* clear PCIC1 reset */
235 txx9_clear64(&tx4938_ccfgptr->clkctr,
236 TX4938_CLKCTR_PCIC1RST);
238 printk(KERN_INFO "%s: stop PCIC1\n", txx9_pcode_str);
240 txx9_set64(&tx4938_ccfgptr->clkctr,
241 TX4938_CLKCTR_PCIC1CKD);
243 if (!(pcfg & TX4938_PCFG_ETH0_SEL)) {
244 printk(KERN_INFO "%s: stop ETH0\n", txx9_pcode_str);
245 txx9_set64(&tx4938_ccfgptr->clkctr,
246 TX4938_CLKCTR_ETH0RST);
247 txx9_set64(&tx4938_ccfgptr->clkctr,
248 TX4938_CLKCTR_ETH0CKD);
250 if (!(pcfg & TX4938_PCFG_ETH1_SEL)) {
251 printk(KERN_INFO "%s: stop ETH1\n", txx9_pcode_str);
252 txx9_set64(&tx4938_ccfgptr->clkctr,
253 TX4938_CLKCTR_ETH1RST);
254 txx9_set64(&tx4938_ccfgptr->clkctr,
255 TX4938_CLKCTR_ETH1CKD);
259 _machine_restart = tx4938_machine_restart;
262 void __init tx4938_time_init(unsigned int tmrnr)
264 if (____raw_readq(&tx4938_ccfgptr->ccfg) & TX4938_CCFG_TINTDIS)
265 txx9_clockevent_init(TX4938_TMR_REG(tmrnr) & 0xfffffffffULL,
266 TXX9_IRQ_BASE + TX4938_IR_TMR(tmrnr),
270 void __init tx4938_sio_init(unsigned int sclk, unsigned int cts_mask)
273 unsigned int ch_mask = 0;
275 if (__raw_readq(&tx4938_ccfgptr->pcfg) & TX4938_PCFG_ETH0_SEL)
276 ch_mask |= 1 << 1; /* disable SIO1 by PCFG setting */
277 for (i = 0; i < 2; i++) {
278 if ((1 << i) & ch_mask)
280 txx9_sio_init(TX4938_SIO_REG(i) & 0xfffffffffULL,
281 TXX9_IRQ_BASE + TX4938_IR_SIO(i),
282 i, sclk, (1 << i) & cts_mask);
286 void __init tx4938_spi_init(int busid)
288 txx9_spi_init(busid, TX4938_SPI_REG & 0xfffffffffULL,
289 TXX9_IRQ_BASE + TX4938_IR_SPI);
292 void __init tx4938_ethaddr_init(unsigned char *addr0, unsigned char *addr1)
294 u64 pcfg = __raw_readq(&tx4938_ccfgptr->pcfg);
296 if (addr0 && (pcfg & TX4938_PCFG_ETH0_SEL))
297 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH0, addr0);
298 if (addr1 && (pcfg & TX4938_PCFG_ETH1_SEL))
299 txx9_ethaddr_init(TXX9_IRQ_BASE + TX4938_IR_ETH1, addr1);
302 void __init tx4938_mtd_init(int ch)
304 struct physmap_flash_data pdata = {
305 .width = TX4938_EBUSC_WIDTH(ch) / 8,
307 unsigned long start = txx9_ce_res[ch].start;
308 unsigned long size = txx9_ce_res[ch].end - start + 1;
310 if (!(TX4938_EBUSC_CR(ch) & 0x8))
311 return; /* disabled */
312 txx9_physmap_flash_init(ch, start, size, &pdata);