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/ptrace.h>
18 #include <linux/mtd/physmap.h>
19 #include <linux/platform_device.h>
20 #include <asm/reboot.h>
21 #include <asm/traps.h>
22 #include <asm/txx9irq.h>
23 #include <asm/txx9tmr.h>
24 #include <asm/txx9pio.h>
25 #include <asm/txx9/generic.h>
26 #include <asm/txx9/ndfmc.h>
27 #include <asm/txx9/dmac.h>
28 #include <asm/txx9/tx4938.h>
30 static void __init
tx4938_wdr_init(void)
32 /* report watchdog reset status */
33 if (____raw_readq(&tx4938_ccfgptr
->ccfg
) & TX4938_CCFG_WDRST
)
34 pr_warning("Watchdog reset detected at 0x%lx\n",
36 /* clear WatchDogReset (W1C) */
37 tx4938_ccfg_set(TX4938_CCFG_WDRST
);
38 /* do reset on watchdog */
39 tx4938_ccfg_set(TX4938_CCFG_WR
);
42 void __init
tx4938_wdt_init(void)
44 txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL
);
47 static void tx4938_machine_restart(char *command
)
50 pr_emerg("Rebooting (with %s watchdog reset)...\n",
51 (____raw_readq(&tx4938_ccfgptr
->ccfg
) & TX4938_CCFG_WDREXEN
) ?
52 "external" : "internal");
53 /* clear watchdog status */
54 tx4938_ccfg_set(TX4938_CCFG_WDRST
); /* W1C */
55 txx9_wdt_now(TX4938_TMR_REG(2) & 0xfffffffffULL
);
56 while (!(____raw_readq(&tx4938_ccfgptr
->ccfg
) & TX4938_CCFG_WDRST
))
59 if (____raw_readq(&tx4938_ccfgptr
->ccfg
) & TX4938_CCFG_WDREXEN
) {
60 pr_emerg("Rebooting (with internal watchdog reset)...\n");
61 /* External WDRST failed. Do internal watchdog reset */
62 tx4938_ccfg_clear(TX4938_CCFG_WDREXEN
);
68 void show_registers(struct pt_regs
*regs
);
69 static int tx4938_be_handler(struct pt_regs
*regs
, int is_fixup
)
71 int data
= regs
->cp0_cause
& 4;
73 pr_err("%cBE exception at %#lx\n", data
? 'D' : 'I', regs
->cp0_epc
);
74 pr_err("ccfg:%llx, toea:%llx\n",
75 (unsigned long long)____raw_readq(&tx4938_ccfgptr
->ccfg
),
76 (unsigned long long)____raw_readq(&tx4938_ccfgptr
->toea
));
78 tx4927_report_pcic_status();
83 static void __init
tx4938_be_init(void)
85 board_be_handler
= tx4938_be_handler
;
88 static struct resource tx4938_sdram_resource
[4];
89 static struct resource tx4938_sram_resource
;
91 #define TX4938_SRAM_SIZE 0x800
93 void __init
tx4938_setup(void)
97 unsigned int cpuclk
= 0;
100 txx9_reg_res_init(TX4938_REV_PCODE(), TX4938_REG_BASE
,
102 set_c0_config(TX49_CONF_CWFON
);
104 /* SDRAMC,EBUSC are configured by PROM */
105 for (i
= 0; i
< 8; i
++) {
106 if (!(TX4938_EBUSC_CR(i
) & 0x8))
107 continue; /* disabled */
108 txx9_ce_res
[i
].start
= (unsigned long)TX4938_EBUSC_BA(i
);
110 txx9_ce_res
[i
].start
+ TX4938_EBUSC_SIZE(i
) - 1;
111 request_resource(&iomem_resource
, &txx9_ce_res
[i
]);
115 ccfg
= ____raw_readq(&tx4938_ccfgptr
->ccfg
);
116 if (txx9_master_clock
) {
117 /* calculate gbus_clock and cpu_clock from master_clock */
118 divmode
= (__u32
)ccfg
& TX4938_CCFG_DIVMODE_MASK
;
120 case TX4938_CCFG_DIVMODE_8
:
121 case TX4938_CCFG_DIVMODE_10
:
122 case TX4938_CCFG_DIVMODE_12
:
123 case TX4938_CCFG_DIVMODE_16
:
124 case TX4938_CCFG_DIVMODE_18
:
125 txx9_gbus_clock
= txx9_master_clock
* 4; break;
127 txx9_gbus_clock
= txx9_master_clock
;
130 case TX4938_CCFG_DIVMODE_2
:
131 case TX4938_CCFG_DIVMODE_8
:
132 cpuclk
= txx9_gbus_clock
* 2; break;
133 case TX4938_CCFG_DIVMODE_2_5
:
134 case TX4938_CCFG_DIVMODE_10
:
135 cpuclk
= txx9_gbus_clock
* 5 / 2; break;
136 case TX4938_CCFG_DIVMODE_3
:
137 case TX4938_CCFG_DIVMODE_12
:
138 cpuclk
= txx9_gbus_clock
* 3; break;
139 case TX4938_CCFG_DIVMODE_4
:
140 case TX4938_CCFG_DIVMODE_16
:
141 cpuclk
= txx9_gbus_clock
* 4; break;
142 case TX4938_CCFG_DIVMODE_4_5
:
143 case TX4938_CCFG_DIVMODE_18
:
144 cpuclk
= txx9_gbus_clock
* 9 / 2; break;
146 txx9_cpu_clock
= cpuclk
;
148 if (txx9_cpu_clock
== 0)
149 txx9_cpu_clock
= 300000000; /* 300MHz */
150 /* calculate gbus_clock and master_clock from cpu_clock */
151 cpuclk
= txx9_cpu_clock
;
152 divmode
= (__u32
)ccfg
& TX4938_CCFG_DIVMODE_MASK
;
154 case TX4938_CCFG_DIVMODE_2
:
155 case TX4938_CCFG_DIVMODE_8
:
156 txx9_gbus_clock
= cpuclk
/ 2; break;
157 case TX4938_CCFG_DIVMODE_2_5
:
158 case TX4938_CCFG_DIVMODE_10
:
159 txx9_gbus_clock
= cpuclk
* 2 / 5; break;
160 case TX4938_CCFG_DIVMODE_3
:
161 case TX4938_CCFG_DIVMODE_12
:
162 txx9_gbus_clock
= cpuclk
/ 3; break;
163 case TX4938_CCFG_DIVMODE_4
:
164 case TX4938_CCFG_DIVMODE_16
:
165 txx9_gbus_clock
= cpuclk
/ 4; break;
166 case TX4938_CCFG_DIVMODE_4_5
:
167 case TX4938_CCFG_DIVMODE_18
:
168 txx9_gbus_clock
= cpuclk
* 2 / 9; break;
171 case TX4938_CCFG_DIVMODE_8
:
172 case TX4938_CCFG_DIVMODE_10
:
173 case TX4938_CCFG_DIVMODE_12
:
174 case TX4938_CCFG_DIVMODE_16
:
175 case TX4938_CCFG_DIVMODE_18
:
176 txx9_master_clock
= txx9_gbus_clock
/ 4; break;
178 txx9_master_clock
= txx9_gbus_clock
;
181 /* change default value to udelay/mdelay take reasonable time */
182 loops_per_jiffy
= txx9_cpu_clock
/ HZ
/ 2;
186 /* clear BusErrorOnWrite flag (W1C) */
187 tx4938_ccfg_set(TX4938_CCFG_BEOW
);
188 /* enable Timeout BusError */
190 tx4938_ccfg_set(TX4938_CCFG_TOE
);
193 txx9_clear64(&tx4938_ccfgptr
->pcfg
, TX4938_PCFG_DMASEL_ALL
);
195 /* Use external clock for external arbiter */
196 if (!(____raw_readq(&tx4938_ccfgptr
->ccfg
) & TX4938_CCFG_PCIARB
))
197 txx9_clear64(&tx4938_ccfgptr
->pcfg
, TX4938_PCFG_PCICLKEN_ALL
);
199 printk(KERN_INFO
"%s -- %dMHz(M%dMHz) CRIR:%08x CCFG:%llx PCFG:%llx\n",
201 (cpuclk
+ 500000) / 1000000,
202 (txx9_master_clock
+ 500000) / 1000000,
203 (__u32
)____raw_readq(&tx4938_ccfgptr
->crir
),
204 (unsigned long long)____raw_readq(&tx4938_ccfgptr
->ccfg
),
205 (unsigned long long)____raw_readq(&tx4938_ccfgptr
->pcfg
));
207 printk(KERN_INFO
"%s SDRAMC --", txx9_pcode_str
);
208 for (i
= 0; i
< 4; i
++) {
209 __u64 cr
= TX4938_SDRAMC_CR(i
);
210 unsigned long base
, size
;
211 if (!((__u32
)cr
& 0x00000400))
212 continue; /* disabled */
213 base
= (unsigned long)(cr
>> 49) << 21;
214 size
= (((unsigned long)(cr
>> 33) & 0x7fff) + 1) << 21;
215 printk(" CR%d:%016llx", i
, (unsigned long long)cr
);
216 tx4938_sdram_resource
[i
].name
= "SDRAM";
217 tx4938_sdram_resource
[i
].start
= base
;
218 tx4938_sdram_resource
[i
].end
= base
+ size
- 1;
219 tx4938_sdram_resource
[i
].flags
= IORESOURCE_MEM
;
220 request_resource(&iomem_resource
, &tx4938_sdram_resource
[i
]);
222 printk(" TR:%09llx\n",
223 (unsigned long long)____raw_readq(&tx4938_sdramcptr
->tr
));
226 if (txx9_pcode
== 0x4938 && ____raw_readq(&tx4938_sramcptr
->cr
) & 1) {
227 unsigned int size
= TX4938_SRAM_SIZE
;
228 tx4938_sram_resource
.name
= "SRAM";
229 tx4938_sram_resource
.start
=
230 (____raw_readq(&tx4938_sramcptr
->cr
) >> (39-11))
232 tx4938_sram_resource
.end
=
233 tx4938_sram_resource
.start
+ TX4938_SRAM_SIZE
- 1;
234 tx4938_sram_resource
.flags
= IORESOURCE_MEM
;
235 request_resource(&iomem_resource
, &tx4938_sram_resource
);
239 /* disable all timers */
240 for (i
= 0; i
< TX4938_NR_TMR
; i
++)
241 txx9_tmr_init(TX4938_TMR_REG(i
) & 0xfffffffffULL
);
244 txx9_gpio_init(TX4938_PIO_REG
& 0xfffffffffULL
, 0, TX4938_NUM_PIO
);
245 __raw_writel(0, &tx4938_pioptr
->maskcpu
);
246 __raw_writel(0, &tx4938_pioptr
->maskext
);
248 if (txx9_pcode
== 0x4938) {
249 __u64 pcfg
= ____raw_readq(&tx4938_ccfgptr
->pcfg
);
250 /* set PCIC1 reset */
251 txx9_set64(&tx4938_ccfgptr
->clkctr
, TX4938_CLKCTR_PCIC1RST
);
252 if (pcfg
& (TX4938_PCFG_ETH0_SEL
| TX4938_PCFG_ETH1_SEL
)) {
253 mdelay(1); /* at least 128 cpu clock */
254 /* clear PCIC1 reset */
255 txx9_clear64(&tx4938_ccfgptr
->clkctr
,
256 TX4938_CLKCTR_PCIC1RST
);
258 printk(KERN_INFO
"%s: stop PCIC1\n", txx9_pcode_str
);
260 txx9_set64(&tx4938_ccfgptr
->clkctr
,
261 TX4938_CLKCTR_PCIC1CKD
);
263 if (!(pcfg
& TX4938_PCFG_ETH0_SEL
)) {
264 printk(KERN_INFO
"%s: stop ETH0\n", txx9_pcode_str
);
265 txx9_set64(&tx4938_ccfgptr
->clkctr
,
266 TX4938_CLKCTR_ETH0RST
);
267 txx9_set64(&tx4938_ccfgptr
->clkctr
,
268 TX4938_CLKCTR_ETH0CKD
);
270 if (!(pcfg
& TX4938_PCFG_ETH1_SEL
)) {
271 printk(KERN_INFO
"%s: stop ETH1\n", txx9_pcode_str
);
272 txx9_set64(&tx4938_ccfgptr
->clkctr
,
273 TX4938_CLKCTR_ETH1RST
);
274 txx9_set64(&tx4938_ccfgptr
->clkctr
,
275 TX4938_CLKCTR_ETH1CKD
);
279 _machine_restart
= tx4938_machine_restart
;
280 board_be_init
= tx4938_be_init
;
283 void __init
tx4938_time_init(unsigned int tmrnr
)
285 if (____raw_readq(&tx4938_ccfgptr
->ccfg
) & TX4938_CCFG_TINTDIS
)
286 txx9_clockevent_init(TX4938_TMR_REG(tmrnr
) & 0xfffffffffULL
,
287 TXX9_IRQ_BASE
+ TX4938_IR_TMR(tmrnr
),
291 void __init
tx4938_sio_init(unsigned int sclk
, unsigned int cts_mask
)
294 unsigned int ch_mask
= 0;
296 if (__raw_readq(&tx4938_ccfgptr
->pcfg
) & TX4938_PCFG_ETH0_SEL
)
297 ch_mask
|= 1 << 1; /* disable SIO1 by PCFG setting */
298 for (i
= 0; i
< 2; i
++) {
299 if ((1 << i
) & ch_mask
)
301 txx9_sio_init(TX4938_SIO_REG(i
) & 0xfffffffffULL
,
302 TXX9_IRQ_BASE
+ TX4938_IR_SIO(i
),
303 i
, sclk
, (1 << i
) & cts_mask
);
307 void __init
tx4938_spi_init(int busid
)
309 txx9_spi_init(busid
, TX4938_SPI_REG
& 0xfffffffffULL
,
310 TXX9_IRQ_BASE
+ TX4938_IR_SPI
);
313 void __init
tx4938_ethaddr_init(unsigned char *addr0
, unsigned char *addr1
)
315 u64 pcfg
= __raw_readq(&tx4938_ccfgptr
->pcfg
);
317 if (addr0
&& (pcfg
& TX4938_PCFG_ETH0_SEL
))
318 txx9_ethaddr_init(TXX9_IRQ_BASE
+ TX4938_IR_ETH0
, addr0
);
319 if (addr1
&& (pcfg
& TX4938_PCFG_ETH1_SEL
))
320 txx9_ethaddr_init(TXX9_IRQ_BASE
+ TX4938_IR_ETH1
, addr1
);
323 void __init
tx4938_mtd_init(int ch
)
325 struct physmap_flash_data pdata
= {
326 .width
= TX4938_EBUSC_WIDTH(ch
) / 8,
328 unsigned long start
= txx9_ce_res
[ch
].start
;
329 unsigned long size
= txx9_ce_res
[ch
].end
- start
+ 1;
331 if (!(TX4938_EBUSC_CR(ch
) & 0x8))
332 return; /* disabled */
333 txx9_physmap_flash_init(ch
, start
, size
, &pdata
);
336 void __init
tx4938_ata_init(unsigned int irq
, unsigned int shift
, int tune
)
338 struct platform_device
*pdev
;
339 struct resource res
[] = {
341 /* .start and .end are filled in later */
342 .flags
= IORESOURCE_MEM
,
345 .flags
= IORESOURCE_IRQ
,
348 struct tx4938ide_platform_info pdata
= {
349 .ioport_shift
= shift
,
351 * The IDE driver should not change bus timings if other ISA
354 .gbus_clock
= tune
? txx9_gbus_clock
: 0,
359 if ((__raw_readq(&tx4938_ccfgptr
->pcfg
) &
360 (TX4938_PCFG_ATA_SEL
| TX4938_PCFG_NDF_SEL
))
361 != TX4938_PCFG_ATA_SEL
)
363 for (i
= 0; i
< 8; i
++) {
364 /* check EBCCRn.ISA, EBCCRn.BSZ, EBCCRn.ME */
365 ebccr
= __raw_readq(&tx4938_ebuscptr
->cr
[i
]);
366 if ((ebccr
& 0x00f00008) == 0x00e00008)
372 res
[0].start
= ((ebccr
>> 48) << 20) + 0x10000;
373 res
[0].end
= res
[0].start
+ 0x20000 - 1;
374 pdev
= platform_device_alloc("tx4938ide", -1);
376 platform_device_add_resources(pdev
, res
, ARRAY_SIZE(res
)) ||
377 platform_device_add_data(pdev
, &pdata
, sizeof(pdata
)) ||
378 platform_device_add(pdev
))
379 platform_device_put(pdev
);
382 void __init
tx4938_ndfmc_init(unsigned int hold
, unsigned int spw
)
384 struct txx9ndfmc_platform_data plat_data
= {
386 .gbus_clock
= txx9_gbus_clock
,
391 unsigned long baseaddr
= TX4938_NDFMC_REG
& 0xfffffffffULL
;
396 if ((__raw_readq(&tx4938_ccfgptr
->pcfg
) &
397 (TX4938_PCFG_ATA_SEL
|TX4938_PCFG_ISA_SEL
|TX4938_PCFG_NDF_SEL
)) ==
399 txx9_ndfmc_init(baseaddr
, &plat_data
);
402 void __init
tx4938_dmac_init(int memcpy_chan0
, int memcpy_chan1
)
404 struct txx9dmac_platform_data plat_data
= {
405 .have_64bit_regs
= true,
409 for (i
= 0; i
< 2; i
++) {
410 plat_data
.memcpy_chan
= i
? memcpy_chan1
: memcpy_chan0
;
411 txx9_dmac_init(i
, TX4938_DMA_REG(i
) & 0xfffffffffULL
,
412 TXX9_IRQ_BASE
+ TX4938_IR_DMA(i
, 0),
417 void __init
tx4938_aclc_init(void)
419 u64 pcfg
= __raw_readq(&tx4938_ccfgptr
->pcfg
);
421 if ((pcfg
& TX4938_PCFG_SEL2
) &&
422 !(pcfg
& TX4938_PCFG_ETH0_SEL
))
423 txx9_aclc_init(TX4938_ACLC_REG
& 0xfffffffffULL
,
424 TXX9_IRQ_BASE
+ TX4938_IR_ACLC
,
428 void __init
tx4938_sramc_init(void)
430 if (tx4938_sram_resource
.start
)
431 txx9_sramc_init(&tx4938_sram_resource
);
434 static void __init
tx4938_stop_unused_modules(void)
436 __u64 pcfg
, rst
= 0, ckd
= 0;
441 pcfg
= ____raw_readq(&tx4938_ccfgptr
->pcfg
);
442 switch (txx9_pcode
) {
444 if (!(pcfg
& TX4938_PCFG_SEL2
)) {
445 rst
|= TX4938_CLKCTR_ACLRST
;
446 ckd
|= TX4938_CLKCTR_ACLCKD
;
447 strcat(buf
, " ACLC");
451 if (!(pcfg
& TX4938_PCFG_SEL2
) ||
452 (pcfg
& TX4938_PCFG_ETH0_SEL
)) {
453 rst
|= TX4938_CLKCTR_ACLRST
;
454 ckd
|= TX4938_CLKCTR_ACLCKD
;
455 strcat(buf
, " ACLC");
458 (TX4938_PCFG_ATA_SEL
| TX4938_PCFG_ISA_SEL
|
459 TX4938_PCFG_NDF_SEL
))
460 != TX4938_PCFG_NDF_SEL
) {
461 rst
|= TX4938_CLKCTR_NDFRST
;
462 ckd
|= TX4938_CLKCTR_NDFCKD
;
463 strcat(buf
, " NDFMC");
465 if (!(pcfg
& TX4938_PCFG_SPI_SEL
)) {
466 rst
|= TX4938_CLKCTR_SPIRST
;
467 ckd
|= TX4938_CLKCTR_SPICKD
;
473 txx9_set64(&tx4938_ccfgptr
->clkctr
, rst
);
474 txx9_set64(&tx4938_ccfgptr
->clkctr
, ckd
);
478 pr_info("%s: stop%s\n", txx9_pcode_str
, buf
);
481 static int __init
tx4938_late_init(void)
483 if (txx9_pcode
!= 0x4937 && txx9_pcode
!= 0x4938)
485 tx4938_stop_unused_modules();
488 late_initcall(tx4938_late_init
);