Home | History | Annotate | Line # | Download | only in tx
tx39.c revision 1.27.4.3
      1  1.27.4.3  nathanw /*	$NetBSD: tx39.c,v 1.27.4.3 2002/02/28 04:10:00 nathanw Exp $ */
      2  1.27.4.2  nathanw 
      3  1.27.4.2  nathanw /*-
      4  1.27.4.2  nathanw  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5  1.27.4.2  nathanw  * All rights reserved.
      6  1.27.4.2  nathanw  *
      7  1.27.4.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.27.4.2  nathanw  * by UCHIYAMA Yasushi.
      9  1.27.4.2  nathanw  *
     10  1.27.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.27.4.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.27.4.2  nathanw  * are met:
     13  1.27.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.27.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.27.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.27.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.27.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.27.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.27.4.2  nathanw  *    must display the following acknowledgement:
     20  1.27.4.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.27.4.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.27.4.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.27.4.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.27.4.2  nathanw  *    from this software without specific prior written permission.
     25  1.27.4.2  nathanw  *
     26  1.27.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.27.4.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.27.4.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.27.4.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.27.4.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.27.4.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.27.4.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.27.4.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.27.4.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.27.4.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.27.4.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.27.4.2  nathanw  */
     38  1.27.4.2  nathanw 
     39  1.27.4.2  nathanw #include "opt_vr41xx.h"
     40  1.27.4.2  nathanw #include "opt_tx39xx.h"
     41  1.27.4.2  nathanw #include "m38813c.h"
     42  1.27.4.2  nathanw #include "tc5165buf.h"
     43  1.27.4.2  nathanw 
     44  1.27.4.2  nathanw #include <sys/param.h>
     45  1.27.4.2  nathanw #include <sys/systm.h>
     46  1.27.4.2  nathanw 
     47  1.27.4.2  nathanw #include <mips/cache.h>
     48  1.27.4.2  nathanw 
     49  1.27.4.2  nathanw #include <machine/locore.h>   /* cpu_id */
     50  1.27.4.2  nathanw #include <machine/bootinfo.h> /* bootinfo */
     51  1.27.4.2  nathanw #include <machine/sysconf.h>  /* platform */
     52  1.27.4.3  nathanw #include <machine/vmparam.h>  /* mem_cluster */
     53  1.27.4.2  nathanw 
     54  1.27.4.2  nathanw #include <machine/platid.h>
     55  1.27.4.2  nathanw #include <machine/platid_mask.h>
     56  1.27.4.2  nathanw 
     57  1.27.4.2  nathanw #include <machine/bus.h>
     58  1.27.4.2  nathanw 
     59  1.27.4.2  nathanw #include <hpcmips/tx/tx39biureg.h>
     60  1.27.4.2  nathanw #include <hpcmips/tx/tx39reg.h>
     61  1.27.4.2  nathanw #include <hpcmips/tx/tx39var.h>
     62  1.27.4.2  nathanw #ifdef TX391X
     63  1.27.4.2  nathanw #include <hpcmips/tx/tx3912videovar.h>
     64  1.27.4.2  nathanw #endif
     65  1.27.4.2  nathanw 
     66  1.27.4.2  nathanw #include <sys/termios.h>
     67  1.27.4.2  nathanw #include <sys/ttydefaults.h>
     68  1.27.4.2  nathanw #include <hpcmips/tx/tx39uartvar.h>
     69  1.27.4.2  nathanw #ifndef CONSPEED
     70  1.27.4.2  nathanw #define CONSPEED TTYDEF_SPEED
     71  1.27.4.2  nathanw #endif
     72  1.27.4.2  nathanw 
     73  1.27.4.2  nathanw /* console keyboard */
     74  1.27.4.2  nathanw #if NM38813C > 0
     75  1.27.4.2  nathanw #include <hpcmips/dev/m38813cvar.h>
     76  1.27.4.2  nathanw #endif
     77  1.27.4.2  nathanw #if NTC5165BUF > 0
     78  1.27.4.2  nathanw #include <hpcmips/dev/tc5165bufvar.h>
     79  1.27.4.2  nathanw #endif
     80  1.27.4.2  nathanw 
     81  1.27.4.2  nathanw struct tx_chipset_tag tx_chipset;
     82  1.27.4.2  nathanw 
     83  1.27.4.2  nathanw void	tx_init(void);
     84  1.27.4.2  nathanw #if defined(VR41XX) && defined(TX39XX)
     85  1.27.4.2  nathanw #define	TX_INTR	tx_intr
     86  1.27.4.2  nathanw #else
     87  1.27.4.2  nathanw #define	TX_INTR	cpu_intr	/* locore_mips3 directly call this */
     88  1.27.4.2  nathanw #endif
     89  1.27.4.2  nathanw 
     90  1.27.4.2  nathanw extern void TX_INTR(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
     91  1.27.4.2  nathanw 
     92  1.27.4.2  nathanw void	tx39clock_cpuspeed(int *, int *);
     93  1.27.4.2  nathanw 
     94  1.27.4.2  nathanw /* TX39-specific initialization vector */
     95  1.27.4.2  nathanw void	tx_cons_init(void);
     96  1.27.4.2  nathanw void    tx_fb_init(caddr_t *);
     97  1.27.4.2  nathanw void    tx_mem_init(paddr_t);
     98  1.27.4.2  nathanw void	tx_find_dram(paddr_t, paddr_t);
     99  1.27.4.2  nathanw void	tx_reboot(int, char *);
    100  1.27.4.2  nathanw 
    101  1.27.4.2  nathanw void
    102  1.27.4.2  nathanw tx_init()
    103  1.27.4.2  nathanw {
    104  1.27.4.2  nathanw 	tx_chipset_tag_t tc;
    105  1.27.4.2  nathanw 	int model, rev;
    106  1.27.4.2  nathanw 	int cpuclock;
    107  1.27.4.2  nathanw 
    108  1.27.4.2  nathanw 	tc = tx_conf_get_tag();
    109  1.27.4.2  nathanw 	/*
    110  1.27.4.2  nathanw 	 * Platform Specific Function Hooks
    111  1.27.4.2  nathanw 	 */
    112  1.27.4.2  nathanw 	platform.cpu_intr	= TX_INTR;
    113  1.27.4.2  nathanw 	platform.cpu_idle	= NULL; /* not implemented yet */
    114  1.27.4.2  nathanw 	platform.cons_init	= tx_cons_init;
    115  1.27.4.2  nathanw 	platform.fb_init	= tx_fb_init;
    116  1.27.4.2  nathanw 	platform.mem_init	= tx_mem_init;
    117  1.27.4.2  nathanw 	platform.reboot		= tx_reboot;
    118  1.27.4.2  nathanw 
    119  1.27.4.2  nathanw 
    120  1.27.4.2  nathanw 	model = MIPS_PRID_REV(cpu_id);
    121  1.27.4.2  nathanw 
    122  1.27.4.2  nathanw 	switch (model) {
    123  1.27.4.2  nathanw 	default:
    124  1.27.4.2  nathanw 		/* Unknown TOSHIBA TX39-series */
    125  1.27.4.2  nathanw 		sprintf(cpu_name, "Unknown TOSHIBA TX39-series %x", model);
    126  1.27.4.2  nathanw 		break;
    127  1.27.4.2  nathanw 	case TMPR3912:
    128  1.27.4.2  nathanw 		tx39clock_cpuspeed(&cpuclock, &cpuspeed);
    129  1.27.4.2  nathanw 
    130  1.27.4.2  nathanw 		sprintf(cpu_name, "TOSHIBA TMPR3912 %d.%02d MHz",
    131  1.27.4.2  nathanw 		    cpuclock / 1000000, (cpuclock % 1000000) / 10000);
    132  1.27.4.2  nathanw 		tc->tc_chipset = __TX391X;
    133  1.27.4.2  nathanw 		break;
    134  1.27.4.2  nathanw 	case TMPR3922:
    135  1.27.4.2  nathanw 		tx39clock_cpuspeed(&cpuclock, &cpuspeed);
    136  1.27.4.2  nathanw 		rev = tx_conf_read(tc, TX3922_REVISION_REG);
    137  1.27.4.2  nathanw 
    138  1.27.4.2  nathanw 		sprintf(cpu_name, "TOSHIBA TMPR3922 rev. %x.%x "
    139  1.27.4.2  nathanw 		    "%d.%02d MHz", (rev >> 4) & 0xf, rev & 0xf,
    140  1.27.4.2  nathanw 		    cpuclock / 1000000, (cpuclock % 1000000) / 10000);
    141  1.27.4.2  nathanw 		tc->tc_chipset = __TX392X;
    142  1.27.4.2  nathanw 		break;
    143  1.27.4.2  nathanw 	}
    144  1.27.4.2  nathanw }
    145  1.27.4.2  nathanw 
    146  1.27.4.2  nathanw void
    147  1.27.4.2  nathanw tx_fb_init(caddr_t *kernend)
    148  1.27.4.2  nathanw {
    149  1.27.4.2  nathanw #ifdef TX391X
    150  1.27.4.2  nathanw 	paddr_t fb_end;
    151  1.27.4.2  nathanw 
    152  1.27.4.2  nathanw 	fb_end = MIPS_KSEG0_TO_PHYS(mem_clusters[0].start +
    153  1.27.4.2  nathanw 	    mem_clusters[0].size - 1);
    154  1.27.4.2  nathanw 	tx3912video_init(MIPS_KSEG0_TO_PHYS(*kernend), &fb_end);
    155  1.27.4.2  nathanw 
    156  1.27.4.2  nathanw 	/* Skip V-RAM area */
    157  1.27.4.2  nathanw 	*kernend = (caddr_t)MIPS_PHYS_TO_KSEG0(fb_end);
    158  1.27.4.2  nathanw #endif /* TX391X */
    159  1.27.4.2  nathanw #ifdef TX392X
    160  1.27.4.2  nathanw 	/*
    161  1.27.4.2  nathanw 	 *  Plum V-RAM isn't accessible until pmap_bootstrap,
    162  1.27.4.2  nathanw 	 * at this time, frame buffer device is disabled.
    163  1.27.4.2  nathanw 	 */
    164  1.27.4.2  nathanw 	bootinfo->fb_addr = 0;
    165  1.27.4.2  nathanw #endif /* TX392X */
    166  1.27.4.2  nathanw }
    167  1.27.4.2  nathanw 
    168  1.27.4.2  nathanw void
    169  1.27.4.2  nathanw tx_mem_init(paddr_t kernend)
    170  1.27.4.2  nathanw {
    171  1.27.4.2  nathanw 
    172  1.27.4.2  nathanw 	mem_clusters[0].start = 0;
    173  1.27.4.2  nathanw 	mem_clusters[0].size = kernend;
    174  1.27.4.2  nathanw 	mem_cluster_cnt = 1;
    175  1.27.4.2  nathanw 	/* search DRAM bank 0 */
    176  1.27.4.2  nathanw 	tx_find_dram(kernend, 0x02000000);
    177  1.27.4.2  nathanw 
    178  1.27.4.2  nathanw 	/* search DRAM bank 1 */
    179  1.27.4.2  nathanw 	tx_find_dram(0x02000000, 0x04000000);
    180  1.27.4.2  nathanw }
    181  1.27.4.2  nathanw 
    182  1.27.4.2  nathanw void
    183  1.27.4.2  nathanw tx_find_dram(paddr_t start, paddr_t end)
    184  1.27.4.2  nathanw {
    185  1.27.4.2  nathanw 	caddr_t page, startaddr, endaddr;
    186  1.27.4.2  nathanw 	u_int32_t magic0, magic1;
    187  1.27.4.2  nathanw #define MAGIC0		(*(__volatile u_int32_t *)(page + 0))
    188  1.27.4.2  nathanw #define MAGIC1		(*(__volatile u_int32_t *)(page + 4))
    189  1.27.4.2  nathanw 
    190  1.27.4.2  nathanw 	startaddr = (void *)MIPS_PHYS_TO_KSEG1(start);
    191  1.27.4.2  nathanw 	endaddr = (void *)MIPS_PHYS_TO_KSEG1(end);
    192  1.27.4.2  nathanw 
    193  1.27.4.2  nathanw 	page = startaddr;
    194  1.27.4.2  nathanw 	if (badaddr(page, 4))
    195  1.27.4.2  nathanw 		return;
    196  1.27.4.2  nathanw 
    197  1.27.4.2  nathanw 	do {
    198  1.27.4.2  nathanw 		magic0 = random();
    199  1.27.4.2  nathanw 		magic1 = random();
    200  1.27.4.2  nathanw 	} while (MAGIC0 == magic0 || MAGIC0 == magic1);
    201  1.27.4.2  nathanw 
    202  1.27.4.2  nathanw 	MAGIC0 = magic0;
    203  1.27.4.2  nathanw 	MAGIC1 = magic1;
    204  1.27.4.2  nathanw 	wbflush();
    205  1.27.4.2  nathanw 
    206  1.27.4.2  nathanw 	if (MAGIC0 != magic0 || MAGIC1 != magic1)
    207  1.27.4.2  nathanw 		return;
    208  1.27.4.2  nathanw 
    209  1.27.4.2  nathanw 	for (page += NBPG; page < endaddr; page += NBPG) {
    210  1.27.4.2  nathanw 		if (badaddr(page, 4))
    211  1.27.4.2  nathanw 			return;
    212  1.27.4.2  nathanw 		if (MAGIC0 == magic0 &&
    213  1.27.4.2  nathanw 		    MAGIC1 == magic1) {
    214  1.27.4.2  nathanw 			goto memend_found;
    215  1.27.4.2  nathanw 		}
    216  1.27.4.2  nathanw 	}
    217  1.27.4.2  nathanw 
    218  1.27.4.2  nathanw 	/* check for 32MByte memory */
    219  1.27.4.2  nathanw 	page -= NBPG;
    220  1.27.4.2  nathanw 	MAGIC0 = magic0;
    221  1.27.4.2  nathanw 	MAGIC1 = magic1;
    222  1.27.4.2  nathanw 	wbflush();
    223  1.27.4.2  nathanw 	if (MAGIC0 != magic0 || MAGIC1 != magic1)
    224  1.27.4.2  nathanw 		return; /* no memory in this bank */
    225  1.27.4.2  nathanw 
    226  1.27.4.2  nathanw  memend_found:
    227  1.27.4.2  nathanw 	mem_clusters[mem_cluster_cnt].start = start;
    228  1.27.4.2  nathanw 	mem_clusters[mem_cluster_cnt].size = page - startaddr;
    229  1.27.4.2  nathanw 
    230  1.27.4.2  nathanw 	/* skip kernel area */
    231  1.27.4.2  nathanw 	if (mem_cluster_cnt == 1)
    232  1.27.4.2  nathanw 		mem_clusters[mem_cluster_cnt].size -= start;
    233  1.27.4.2  nathanw 
    234  1.27.4.2  nathanw 	mem_cluster_cnt++;
    235  1.27.4.2  nathanw #undef MAGIC0
    236  1.27.4.2  nathanw #undef MAGIC1
    237  1.27.4.2  nathanw }
    238  1.27.4.2  nathanw 
    239  1.27.4.2  nathanw void
    240  1.27.4.2  nathanw tx_reboot(int howto, char *bootstr)
    241  1.27.4.2  nathanw {
    242  1.27.4.2  nathanw 
    243  1.27.4.2  nathanw 	goto *(u_int32_t *)MIPS_RESET_EXC_VEC;
    244  1.27.4.2  nathanw }
    245  1.27.4.2  nathanw 
    246  1.27.4.2  nathanw void
    247  1.27.4.2  nathanw tx_cons_init()
    248  1.27.4.2  nathanw {
    249  1.27.4.2  nathanw 	int slot;
    250  1.27.4.2  nathanw #define CONSPLATIDMATCH(p)						\
    251  1.27.4.2  nathanw 	platid_match(&platid, &platid_mask_MACH_##p)
    252  1.27.4.2  nathanw 
    253  1.27.4.2  nathanw #ifdef SERIALCONSSLOT
    254  1.27.4.2  nathanw 	slot = SERIALCONSSLOT;
    255  1.27.4.2  nathanw #else
    256  1.27.4.2  nathanw 	slot = TX39_UARTA;
    257  1.27.4.2  nathanw #endif
    258  1.27.4.2  nathanw 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    259  1.27.4.2  nathanw 		if(txcom_cnattach(slot, CONSPEED,
    260  1.27.4.2  nathanw 		    (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
    261  1.27.4.2  nathanw 			panic("tx_cons_init: can't attach serial console.");
    262  1.27.4.2  nathanw 		}
    263  1.27.4.2  nathanw 	} else {
    264  1.27.4.2  nathanw #if NM38813C > 0
    265  1.27.4.2  nathanw 		if(CONSPLATIDMATCH(VICTOR_INTERLINK) &&
    266  1.27.4.2  nathanw 		    m38813c_cnattach(TX39_SYSADDR_CARD1)) {
    267  1.27.4.2  nathanw 			goto panic;
    268  1.27.4.2  nathanw 		}
    269  1.27.4.2  nathanw #endif
    270  1.27.4.2  nathanw #if NTC5165BUF > 0
    271  1.27.4.2  nathanw 		if(CONSPLATIDMATCH(COMPAQ_C) &&
    272  1.27.4.2  nathanw 		    tc5165buf_cnattach(TX39_SYSADDR_CS3)) {
    273  1.27.4.2  nathanw 			goto panic;
    274  1.27.4.2  nathanw 		}
    275  1.27.4.2  nathanw 
    276  1.27.4.2  nathanw 		if(CONSPLATIDMATCH(SHARP_TELIOS) &&
    277  1.27.4.2  nathanw 		    tc5165buf_cnattach(TX39_SYSADDR_CS1)) {
    278  1.27.4.2  nathanw 			goto panic;
    279  1.27.4.2  nathanw 		}
    280  1.27.4.2  nathanw 
    281  1.27.4.2  nathanw 		if(CONSPLATIDMATCH(SHARP_MOBILON) &&
    282  1.27.4.2  nathanw 		    tc5165buf_cnattach(TX39_SYSADDR_MCS0)) {
    283  1.27.4.2  nathanw 			goto panic;
    284  1.27.4.2  nathanw 		}
    285  1.27.4.2  nathanw #endif
    286  1.27.4.2  nathanw 	}
    287  1.27.4.2  nathanw 
    288  1.27.4.2  nathanw 	return;
    289  1.27.4.2  nathanw  panic:
    290  1.27.4.2  nathanw 	panic("tx_cons_init: can't init console");
    291  1.27.4.2  nathanw 	/* NOTREACHED */
    292  1.27.4.2  nathanw }
    293  1.27.4.2  nathanw 
    294  1.27.4.2  nathanw void
    295  1.27.4.2  nathanw tx_conf_register_intr(tx_chipset_tag_t t, void *intrt)
    296  1.27.4.2  nathanw {
    297  1.27.4.2  nathanw 
    298  1.27.4.2  nathanw 	KASSERT(t == &tx_chipset);
    299  1.27.4.2  nathanw 	tx_chipset.tc_intrt = intrt;
    300  1.27.4.2  nathanw }
    301  1.27.4.2  nathanw 
    302  1.27.4.2  nathanw void
    303  1.27.4.2  nathanw tx_conf_register_power(tx_chipset_tag_t t, void *powert)
    304  1.27.4.2  nathanw {
    305  1.27.4.2  nathanw 
    306  1.27.4.2  nathanw 	KASSERT(t == &tx_chipset);
    307  1.27.4.2  nathanw 	tx_chipset.tc_powert = powert;
    308  1.27.4.2  nathanw }
    309  1.27.4.2  nathanw 
    310  1.27.4.2  nathanw void
    311  1.27.4.2  nathanw tx_conf_register_clock(tx_chipset_tag_t t, void *clockt)
    312  1.27.4.2  nathanw {
    313  1.27.4.2  nathanw 
    314  1.27.4.2  nathanw 	KASSERT(t == &tx_chipset);
    315  1.27.4.2  nathanw 	tx_chipset.tc_clockt = clockt;
    316  1.27.4.2  nathanw }
    317  1.27.4.2  nathanw 
    318  1.27.4.2  nathanw void
    319  1.27.4.2  nathanw tx_conf_register_sound(tx_chipset_tag_t t, void *soundt)
    320  1.27.4.2  nathanw {
    321  1.27.4.2  nathanw 
    322  1.27.4.2  nathanw 	KASSERT(t == &tx_chipset);
    323  1.27.4.2  nathanw 	tx_chipset.tc_soundt = soundt;
    324  1.27.4.2  nathanw }
    325  1.27.4.2  nathanw 
    326  1.27.4.2  nathanw void
    327  1.27.4.2  nathanw tx_conf_register_video(tx_chipset_tag_t t, void *videot)
    328  1.27.4.2  nathanw {
    329  1.27.4.2  nathanw 
    330  1.27.4.2  nathanw 	KASSERT(t == &tx_chipset);
    331  1.27.4.2  nathanw 	tx_chipset.tc_videot = videot;
    332  1.27.4.2  nathanw }
    333