1 /***********************************************************************
3 * Copyright 2001 MontaVista Software Inc.
4 * Author: MontaVista Software, Inc.
7 * Based on arch/mips/ddb5xxx/ddb5477/setup.c
9 * Setup file for JMR3927.
11 * Copyright (C) 2000-2001 Toshiba Corporation
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
21 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * You should have received a copy of the GNU General Public License along
30 * with this program; if not, write to the Free Software Foundation, Inc.,
31 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 ***********************************************************************
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kdev_t.h>
39 #include <linux/types.h>
40 #include <linux/sched.h>
41 #include <linux/pci.h>
42 #include <linux/ide.h>
43 #include <linux/irq.h>
44 #include <linux/ioport.h>
45 #include <linux/param.h> /* for HZ */
46 #include <linux/delay.h>
48 #include <linux/platform_device.h>
49 #ifdef CONFIG_SERIAL_TXX9
50 #include <linux/tty.h>
51 #include <linux/serial.h>
52 #include <linux/serial_core.h>
55 #include <asm/addrspace.h>
57 #include <asm/reboot.h>
58 #include <asm/jmr3927/jmr3927.h>
59 #include <asm/mipsregs.h>
61 extern void puts(const char *cp
);
63 /* Tick Timer divider */
64 #define JMR3927_TIMER_CCD 0 /* 1/2 */
65 #define JMR3927_TIMER_CLK (JMR3927_IMCLK / (2 << JMR3927_TIMER_CCD))
67 /* don't enable - see errata */
68 static int jmr3927_ccfg_toeon
;
70 static inline void do_reset(void)
72 #if 1 /* Resetting PCI bus */
73 jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR
);
74 jmr3927_ioc_reg_out(JMR3927_IOC_RESET_PCI
, JMR3927_IOC_RESET_ADDR
);
75 (void)jmr3927_ioc_reg_in(JMR3927_IOC_RESET_ADDR
); /* flush WB */
77 jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR
);
79 jmr3927_ioc_reg_out(JMR3927_IOC_RESET_CPU
, JMR3927_IOC_RESET_ADDR
);
82 static void jmr3927_machine_restart(char *command
)
89 static void jmr3927_machine_halt(void)
91 puts("JMR-TX3927 halted.\n");
95 static void jmr3927_machine_power_off(void)
97 puts("JMR-TX3927 halted. Please turn off the power.\n");
101 static cycle_t
jmr3927_hpt_read(void)
103 /* We assume this function is called xtime_lock held. */
104 return jiffies
* (JMR3927_TIMER_CLK
/ HZ
) + jmr3927_tmrptr
->trr
;
107 static void jmr3927_timer_ack(void)
109 jmr3927_tmrptr
->tisr
= 0; /* ack interrupt */
112 static void __init
jmr3927_time_init(void)
114 clocksource_mips
.read
= jmr3927_hpt_read
;
115 mips_timer_ack
= jmr3927_timer_ack
;
116 mips_hpt_frequency
= JMR3927_TIMER_CLK
;
119 void __init
plat_timer_setup(struct irqaction
*irq
)
121 jmr3927_tmrptr
->cpra
= JMR3927_TIMER_CLK
/ HZ
;
122 jmr3927_tmrptr
->itmr
= TXx927_TMTITMR_TIIE
| TXx927_TMTITMR_TZCE
;
123 jmr3927_tmrptr
->ccdr
= JMR3927_TIMER_CCD
;
124 jmr3927_tmrptr
->tcr
=
125 TXx927_TMTCR_TCE
| TXx927_TMTCR_CCDE
| TXx927_TMTCR_TMODE_ITVL
;
127 setup_irq(JMR3927_IRQ_TICK
, irq
);
130 #define DO_WRITE_THROUGH
131 #define DO_ENABLE_CACHE
133 extern char * __init
prom_getcmdline(void);
134 static void jmr3927_board_init(void);
135 extern struct resource pci_io_resource
;
136 extern struct resource pci_mem_resource
;
138 void __init
plat_mem_setup(void)
142 set_io_port_base(JMR3927_PORT_BASE
+ JMR3927_PCIIO
);
144 board_time_init
= jmr3927_time_init
;
146 _machine_restart
= jmr3927_machine_restart
;
147 _machine_halt
= jmr3927_machine_halt
;
148 pm_power_off
= jmr3927_machine_power_off
;
153 ioport_resource
.start
= pci_io_resource
.start
;
154 ioport_resource
.end
= pci_io_resource
.end
;
155 iomem_resource
.start
= 0;
156 iomem_resource
.end
= 0xffffffff;
158 /* Reboot on panic */
164 #ifdef DO_ENABLE_CACHE
165 int mips_ic_disable
= 0, mips_dc_disable
= 0;
167 int mips_ic_disable
= 1, mips_dc_disable
= 1;
169 #ifdef DO_WRITE_THROUGH
170 int mips_config_cwfon
= 0;
171 int mips_config_wbon
= 0;
173 int mips_config_cwfon
= 1;
174 int mips_config_wbon
= 1;
177 conf
= read_c0_conf();
178 conf
&= ~(TX39_CONF_ICE
| TX39_CONF_DCE
| TX39_CONF_WBON
| TX39_CONF_CWFON
);
179 conf
|= mips_ic_disable
? 0 : TX39_CONF_ICE
;
180 conf
|= mips_dc_disable
? 0 : TX39_CONF_DCE
;
181 conf
|= mips_config_wbon
? TX39_CONF_WBON
: 0;
182 conf
|= mips_config_cwfon
? TX39_CONF_CWFON
: 0;
188 /* initialize board */
189 jmr3927_board_init();
191 argptr
= prom_getcmdline();
193 if ((argptr
= strstr(argptr
, "toeon")) != NULL
)
194 jmr3927_ccfg_toeon
= 1;
195 argptr
= prom_getcmdline();
196 if ((argptr
= strstr(argptr
, "ip=")) == NULL
) {
197 argptr
= prom_getcmdline();
198 strcat(argptr
, " ip=bootp");
201 #ifdef CONFIG_SERIAL_TXX9
203 extern int early_serial_txx9_setup(struct uart_port
*port
);
205 struct uart_port req
;
206 for(i
= 0; i
< 2; i
++) {
207 memset(&req
, 0, sizeof(req
));
209 req
.iotype
= UPIO_MEM
;
210 req
.membase
= (unsigned char __iomem
*)TX3927_SIO_REG(i
);
211 req
.mapbase
= TX3927_SIO_REG(i
);
213 JMR3927_IRQ_IRC_SIO0
: JMR3927_IRQ_IRC_SIO1
;
215 req
.flags
|= UPF_BUGGY_UART
/*HAVE_CTS_LINE*/;
216 req
.uartclk
= JMR3927_IMCLK
;
217 early_serial_txx9_setup(&req
);
220 #ifdef CONFIG_SERIAL_TXX9_CONSOLE
221 argptr
= prom_getcmdline();
222 if ((argptr
= strstr(argptr
, "console=")) == NULL
) {
223 argptr
= prom_getcmdline();
224 strcat(argptr
, " console=ttyS1,115200");
230 static void tx3927_setup(void);
232 static void __init
jmr3927_board_init(void)
237 jmr3927_ioc_reg_out(0, JMR3927_IOC_DTR_ADDR
);
241 printk("JMR-TX3927 (Rev %d) --- IOC(Rev %d) DIPSW:%d,%d,%d,%d\n",
242 jmr3927_ioc_reg_in(JMR3927_IOC_BREV_ADDR
) & JMR3927_REV_MASK
,
243 jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR
) & JMR3927_REV_MASK
,
244 jmr3927_dipsw1(), jmr3927_dipsw2(),
245 jmr3927_dipsw3(), jmr3927_dipsw4());
248 static void __init
tx3927_setup(void)
252 unsigned long mips_pci_io_base
= JMR3927_PCIIO
;
253 unsigned long mips_pci_io_size
= JMR3927_PCIIO_SIZE
;
254 unsigned long mips_pci_mem_base
= JMR3927_PCIMEM
;
255 unsigned long mips_pci_mem_size
= JMR3927_PCIMEM_SIZE
;
256 /* for legacy I/O, PCI I/O PCI Bus address must be 0 */
257 unsigned long mips_pci_io_pciaddr
= 0;
260 /* SDRAMC are configured by PROM */
263 tx3927_romcptr
->cr
[1] = JMR3927_ROMCE1
| 0x00030048;
264 tx3927_romcptr
->cr
[2] = JMR3927_ROMCE2
| 0x000064c8;
265 tx3927_romcptr
->cr
[3] = JMR3927_ROMCE3
| 0x0003f698;
266 tx3927_romcptr
->cr
[5] = JMR3927_ROMCE5
| 0x0000f218;
269 /* enable Timeout BusError */
270 if (jmr3927_ccfg_toeon
)
271 tx3927_ccfgptr
->ccfg
|= TX3927_CCFG_TOE
;
273 /* clear BusErrorOnWrite flag */
274 tx3927_ccfgptr
->ccfg
&= ~TX3927_CCFG_BEOW
;
275 /* Disable PCI snoop */
276 tx3927_ccfgptr
->ccfg
&= ~TX3927_CCFG_PSNP
;
278 #ifdef DO_WRITE_THROUGH
279 /* Enable PCI SNOOP - with write through only */
280 tx3927_ccfgptr
->ccfg
|= TX3927_CCFG_PSNP
;
284 tx3927_ccfgptr
->pcfg
&= ~TX3927_PCFG_SELALL
;
285 tx3927_ccfgptr
->pcfg
|=
286 TX3927_PCFG_SELSIOC(0) | TX3927_PCFG_SELSIO_ALL
|
287 (TX3927_PCFG_SELDMA_ALL
& ~TX3927_PCFG_SELDMA(1));
289 printk("TX3927 -- CRIR:%08lx CCFG:%08lx PCFG:%08lx\n",
290 tx3927_ccfgptr
->crir
,
291 tx3927_ccfgptr
->ccfg
, tx3927_ccfgptr
->pcfg
);
294 /* disable interrupt control */
295 tx3927_ircptr
->cer
= 0;
296 /* mask all IRC interrupts */
297 tx3927_ircptr
->imr
= 0;
298 for (i
= 0; i
< TX3927_NUM_IR
/ 2; i
++) {
299 tx3927_ircptr
->ilr
[i
] = 0;
301 /* setup IRC interrupt mode (Low Active) */
302 for (i
= 0; i
< TX3927_NUM_IR
/ 8; i
++) {
303 tx3927_ircptr
->cr
[i
] = 0;
307 /* disable all timers */
308 for (i
= 0; i
< TX3927_NR_TMR
; i
++) {
309 tx3927_tmrptr(i
)->tcr
= TXx927_TMTCR_CRE
;
310 tx3927_tmrptr(i
)->tisr
= 0;
311 tx3927_tmrptr(i
)->cpra
= 0xffffffff;
312 tx3927_tmrptr(i
)->itmr
= 0;
313 tx3927_tmrptr(i
)->ccdr
= 0;
314 tx3927_tmrptr(i
)->pgmr
= 0;
318 tx3927_dmaptr
->mcr
= 0;
319 for (i
= 0; i
< ARRAY_SIZE(tx3927_dmaptr
->ch
); i
++) {
321 tx3927_dmaptr
->ch
[i
].ccr
= TX3927_DMA_CCR_CHRST
;
322 tx3927_dmaptr
->ch
[i
].ccr
= 0;
326 tx3927_dmaptr
->mcr
= TX3927_DMA_MCR_MSTEN
;
328 tx3927_dmaptr
->mcr
= TX3927_DMA_MCR_MSTEN
| TX3927_DMA_MCR_LE
;
333 printk("TX3927 PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:",
334 tx3927_pcicptr
->did
, tx3927_pcicptr
->vid
,
335 tx3927_pcicptr
->rid
);
336 if (!(tx3927_ccfgptr
->ccfg
& TX3927_CCFG_PCIXARB
)) {
337 printk("External\n");
340 printk("Internal\n");
343 jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR
);
345 jmr3927_ioc_reg_out(JMR3927_IOC_RESET_PCI
,
346 JMR3927_IOC_RESET_ADDR
);
348 jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR
);
351 /* Disable External PCI Config. Access */
352 tx3927_pcicptr
->lbc
= TX3927_PCIC_LBC_EPCAD
;
354 tx3927_pcicptr
->lbc
|= TX3927_PCIC_LBC_IBSE
|
355 TX3927_PCIC_LBC_TIBSE
|
356 TX3927_PCIC_LBC_TMFBSE
| TX3927_PCIC_LBC_MSDSE
;
358 /* LB->PCI mappings */
359 tx3927_pcicptr
->iomas
= ~(mips_pci_io_size
- 1);
360 tx3927_pcicptr
->ilbioma
= mips_pci_io_base
;
361 tx3927_pcicptr
->ipbioma
= mips_pci_io_pciaddr
;
362 tx3927_pcicptr
->mmas
= ~(mips_pci_mem_size
- 1);
363 tx3927_pcicptr
->ilbmma
= mips_pci_mem_base
;
364 tx3927_pcicptr
->ipbmma
= mips_pci_mem_base
;
365 /* PCI->LB mappings */
366 tx3927_pcicptr
->iobas
= 0xffffffff;
367 tx3927_pcicptr
->ioba
= 0;
368 tx3927_pcicptr
->tlbioma
= 0;
369 tx3927_pcicptr
->mbas
= ~(mips_pci_mem_size
- 1);
370 tx3927_pcicptr
->mba
= 0;
371 tx3927_pcicptr
->tlbmma
= 0;
372 /* Enable Direct mapping Address Space Decoder */
373 tx3927_pcicptr
->lbc
|= TX3927_PCIC_LBC_ILMDE
| TX3927_PCIC_LBC_ILIDE
;
375 /* Clear All Local Bus Status */
376 tx3927_pcicptr
->lbstat
= TX3927_PCIC_LBIM_ALL
;
377 /* Enable All Local Bus Interrupts */
378 tx3927_pcicptr
->lbim
= TX3927_PCIC_LBIM_ALL
;
379 /* Clear All PCI Status Error */
380 tx3927_pcicptr
->pcistat
= TX3927_PCIC_PCISTATIM_ALL
;
381 /* Enable All PCI Status Error Interrupts */
382 tx3927_pcicptr
->pcistatim
= TX3927_PCIC_PCISTATIM_ALL
;
384 /* PCIC Int => IRC IRQ10 */
385 tx3927_pcicptr
->il
= TX3927_IR_PCI
;
386 /* Target Control (per errata) */
387 tx3927_pcicptr
->tc
= TX3927_PCIC_TC_OF8E
| TX3927_PCIC_TC_IF8E
;
389 /* Enable Bus Arbiter */
390 tx3927_pcicptr
->pbapmc
= TX3927_PCIC_PBAPMC_PBAEN
;
392 tx3927_pcicptr
->pcicmd
= PCI_COMMAND_MASTER
|
395 PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
;
397 #endif /* CONFIG_PCI */
400 /* PIO[15:12] connected to LEDs */
401 tx3927_pioptr
->dir
= 0x0000f000;
402 tx3927_pioptr
->maskcpu
= 0;
403 tx3927_pioptr
->maskext
= 0;
407 conf
= read_c0_conf();
408 if (!(conf
& TX39_CONF_ICE
))
409 printk("TX3927 I-Cache disabled.\n");
410 if (!(conf
& TX39_CONF_DCE
))
411 printk("TX3927 D-Cache disabled.\n");
412 else if (!(conf
& TX39_CONF_WBON
))
413 printk("TX3927 D-Cache WriteThrough.\n");
414 else if (!(conf
& TX39_CONF_CWFON
))
415 printk("TX3927 D-Cache WriteBack.\n");
417 printk("TX3927 D-Cache WriteBack (CWF) .\n");
421 /* This trick makes rtc-ds1742 driver usable as is. */
422 unsigned long __swizzle_addr_b(unsigned long port
)
424 if ((port
& 0xffff0000) != JMR3927_IOC_NVRAMB_ADDR
)
426 port
= (port
& 0xffff0000) | (port
& 0x7fff << 1);
433 EXPORT_SYMBOL(__swizzle_addr_b
);
435 static int __init
jmr3927_rtc_init(void)
437 struct resource res
= {
438 .start
= JMR3927_IOC_NVRAMB_ADDR
- IO_BASE
,
439 .end
= JMR3927_IOC_NVRAMB_ADDR
- IO_BASE
+ 0x800 - 1,
440 .flags
= IORESOURCE_MEM
,
442 struct platform_device
*dev
;
443 dev
= platform_device_register_simple("ds1742", -1, &res
, 1);
444 return IS_ERR(dev
) ? PTR_ERR(dev
) : 0;
446 device_initcall(jmr3927_rtc_init
);