tx39.c revision 1.8       1  1.8       uch /*	$NetBSD: tx39.c,v 1.8 1999/12/22 15:35:35 uch Exp $ */
      2  1.1       uch 
      3  1.1       uch /*
      4  1.1       uch  * Copyright (c) 1999, by UCHIYAMA Yasushi
      5  1.1       uch  * All rights reserved.
      6  1.1       uch  *
      7  1.1       uch  * Redistribution and use in source and binary forms, with or without
      8  1.1       uch  * modification, are permitted provided that the following conditions
      9  1.1       uch  * are met:
     10  1.1       uch  * 1. Redistributions of source code must retain the above copyright
     11  1.1       uch  *    notice, this list of conditions and the following disclaimer.
     12  1.1       uch  * 2. The name of the developer may NOT be used to endorse or promote products
     13  1.1       uch  *    derived from this software without specific prior written permission.
     14  1.1       uch  *
     15  1.1       uch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1       uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1       uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1       uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1       uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1       uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1       uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1       uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1       uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1       uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1       uch  * SUCH DAMAGE.
     26  1.1       uch  *
     27  1.1       uch  */
     28  1.1       uch 
     29  1.1       uch #include "opt_tx39_debug.h"
     30  1.5       uch #include "m38813c.h"
     31  1.5       uch #include "p7416buf.h"
     32  1.6       uch #include "tc5165buf.h"
     33  1.1       uch 
     34  1.1       uch #include <sys/param.h>
     35  1.1       uch #include <sys/systm.h>
     36  1.1       uch #include <sys/device.h>
     37  1.1       uch 
     38  1.1       uch #include <machine/locore.h>   /* cpu_id */
     39  1.1       uch #include <machine/bootinfo.h> /* bootinfo */
     40  1.1       uch #include <machine/sysconf.h>  /* platform */
     41  1.1       uch 
     42  1.6       uch #include <machine/platid.h>
     43  1.6       uch #include <machine/platid_mask.h>
     44  1.6       uch 
     45  1.1       uch #include <machine/bus.h>
     46  1.1       uch #include <machine/intr.h>
     47  1.1       uch 
     48  1.1       uch #include <hpcmips/hpcmips/machdep.h> /* cpu_model */
     49  1.1       uch 
     50  1.1       uch #include <hpcmips/tx/tx39biureg.h>
     51  1.1       uch #include <hpcmips/tx/tx39reg.h>
     52  1.1       uch #include <hpcmips/tx/tx39var.h>
     53  1.1       uch #ifdef TX391X
     54  1.1       uch #include <hpcmips/tx/tx3912videovar.h>
     55  1.1       uch #endif
     56  1.1       uch 
     57  1.1       uch #include <sys/termios.h>
     58  1.1       uch #include <sys/ttydefaults.h>
     59  1.1       uch #include <hpcmips/tx/tx39uartvar.h>
     60  1.1       uch #ifndef CONSPEED
     61  1.1       uch #define CONSPEED TTYDEF_SPEED
     62  1.1       uch #endif
     63  1.1       uch 
     64  1.5       uch /* console keyboard */
     65  1.5       uch #if NP7416BUF > 0
     66  1.5       uch #include <hpcmips/dev/p7416bufvar.h>
     67  1.5       uch #endif
     68  1.5       uch #if NM38813C > 0
     69  1.5       uch #include <hpcmips/dev/m38813cvar.h>
     70  1.1       uch #endif
     71  1.6       uch #if NTC5165BUF > 0
     72  1.6       uch #include <hpcmips/dev/tc5165bufvar.h>
     73  1.6       uch #endif
     74  1.1       uch 
     75  1.1       uch extern unsigned nullclkread __P((void));
     76  1.1       uch extern unsigned (*clkread) __P((void));
     77  1.1       uch 
     78  1.1       uch struct tx_chipset_tag tx_chipset;
     79  1.1       uch 
     80  1.1       uch #ifdef TX39_DEBUG
     81  1.1       uch u_int32_t tx39debugflag;
     82  1.1       uch #endif
     83  1.1       uch 
     84  1.1       uch void	tx_init __P((void));
     85  1.1       uch int	tx39icu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
     86  1.1       uch int	tx39_find_dram __P((u_int32_t, u_int32_t));
     87  1.8       uch void	tx39clock_cpuspeed __P((int*, int*));
     88  1.1       uch 
     89  1.1       uch /* TX39-specific initialization vector */
     90  1.1       uch void	tx_os_init __P((void));
     91  1.1       uch void	tx_bus_reset __P((void));
     92  1.1       uch void	tx_cons_init __P((void));
     93  1.1       uch void	tx_device_register __P((struct device *, void *));
     94  1.1       uch void    tx_fb_init __P((caddr_t*));
     95  1.1       uch int     tx_mem_init __P((caddr_t));
     96  1.2  takemura void	tx_reboot __P((int howto, char *bootstr));
     97  1.5       uch int	tx_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg,
     98  1.5       uch 		     u_int32_t causeReg));
     99  1.1       uch 
    100  1.1       uch void
    101  1.1       uch tx_init()
    102  1.1       uch {
    103  1.1       uch 	tx_chipset_tag_t tc;
    104  1.1       uch 	int model, rev;
    105  1.8       uch 	int cpuclock;
    106  1.1       uch 
    107  1.1       uch 	tc = tx_conf_get_tag();
    108  1.1       uch 	/*
    109  1.1       uch 	 * Platform Specific Function Hooks
    110  1.1       uch 	 */
    111  1.1       uch 	platform.os_init = tx_os_init;
    112  1.1       uch 	platform.bus_reset = tx_bus_reset;
    113  1.1       uch 	platform.cons_init = tx_cons_init;
    114  1.1       uch 	platform.device_register = tx_device_register;
    115  1.1       uch 	platform.fb_init = tx_fb_init;
    116  1.1       uch 	platform.mem_init = tx_mem_init;
    117  1.2  takemura 	platform.reboot = tx_reboot;
    118  1.1       uch 
    119  1.1       uch 	model = (cpu_id.cpu.cp_majrev << 4)| cpu_id.cpu.cp_minrev;
    120  1.1       uch 
    121  1.1       uch 	switch (model) {
    122  1.1       uch 	default:
    123  1.1       uch 		 /* Unknown TOSHIBA TX39-series */
    124  1.1       uch 		sprintf(cpu_model, "Unknown TOSHIBA TX39-series %x.%x",
    125  1.1       uch 			cpu_id.cpu.cp_majrev, cpu_id.cpu.cp_minrev);
    126  1.1       uch 		break;
    127  1.1       uch 	case TMPR3912:
    128  1.8       uch 		tx39clock_cpuspeed(&cpuclock, &cpuspeed);
    129  1.8       uch 
    130  1.8       uch 		sprintf(cpu_model, "TOSHIBA TMPR3912 %d.%02d MHz",
    131  1.8       uch 			cpuclock / 1000000, (cpuclock % 1000000) / 10000);
    132  1.1       uch 		break;
    133  1.1       uch 	case TMPR3922:
    134  1.8       uch 		tx39clock_cpuspeed(&cpuclock, &cpuspeed);
    135  1.1       uch 		rev = tx_conf_read(tc, TX3922_REVISION_REG);
    136  1.8       uch 
    137  1.8       uch 		sprintf(cpu_model, "TOSHIBA TMPR3922 rev. %x.%x "
    138  1.8       uch 			"%d.%02d MHz", (rev >> 4) & 0xf, rev & 0xf,
    139  1.8       uch 			cpuclock / 1000000, (cpuclock % 1000000) / 10000);
    140  1.1       uch 		break;
    141  1.1       uch 	}
    142  1.1       uch }
    143  1.1       uch 
    144  1.1       uch void
    145  1.1       uch tx_os_init()
    146  1.1       uch {
    147  1.1       uch 	/*
    148  1.1       uch 	 * Set up interrupt handling and I/O addresses.
    149  1.1       uch 	 */
    150  1.1       uch 	mips_hardware_intr = tx39icu_intr;
    151  1.1       uch 
    152  1.1       uch 	splvec.splbio = MIPS_SPL_2_4;
    153  1.1       uch 	splvec.splnet = MIPS_SPL_2_4;
    154  1.1       uch 	splvec.spltty = MIPS_SPL_2_4;
    155  1.1       uch 	splvec.splimp = MIPS_SPL_2_4;
    156  1.1       uch 	splvec.splclock = MIPS_SPL_2_4;
    157  1.1       uch 	splvec.splstatclock = MIPS_SPL_2_4;
    158  1.1       uch 
    159  1.1       uch 	/* no high resolution timer circuit; possibly never called */
    160  1.1       uch 	clkread = nullclkread;
    161  1.1       uch }
    162  1.1       uch 
    163  1.1       uch void
    164  1.1       uch tx_fb_init(kernend)
    165  1.1       uch 	caddr_t *kernend;
    166  1.1       uch {
    167  1.1       uch #ifdef TX391X
    168  1.1       uch 	tx_chipset_tag_t tc;
    169  1.1       uch 	u_int32_t fb_start, fb_addr, fb_size, fb_line_bytes;
    170  1.1       uch 
    171  1.1       uch 	/* Initialize to access TX39 configuration register */
    172  1.1       uch 	tc = tx_conf_get_tag();
    173  1.1       uch 
    174  1.1       uch 	fb_start = MIPS_KSEG0_TO_PHYS(*kernend);
    175  1.1       uch 	tx3912video_init(tc, fb_start, bootinfo->fb_width,
    176  1.1       uch 			bootinfo->fb_height, &fb_addr, &fb_size,
    177  1.1       uch 			&fb_line_bytes);
    178  1.1       uch 
    179  1.7       uch 	/* Setup bootinfo */
    180  1.1       uch 	bootinfo->fb_line_bytes = fb_line_bytes;
    181  1.1       uch 	bootinfo->fb_addr = (unsigned char*)MIPS_PHYS_TO_KSEG1(fb_addr);
    182  1.1       uch 
    183  1.1       uch 	/* Skip V-RAM area */
    184  1.1       uch 	*kernend += fb_size;
    185  1.1       uch #endif /* TX391X */
    186  1.1       uch #ifdef TX392X
    187  1.1       uch 	/*
    188  1.1       uch 	 *  Plum V-RAM isn't accessible until pmap_bootstrap,
    189  1.7       uch 	 * at this time, frame buffer device is disabled.
    190  1.1       uch 	 */
    191  1.1       uch 	bootinfo->fb_addr = 0;
    192  1.1       uch #endif /* TX392X */
    193  1.1       uch }
    194  1.1       uch 
    195  1.1       uch int
    196  1.1       uch tx_mem_init(kernend)
    197  1.1       uch 	caddr_t kernend; /* kseg0 */
    198  1.1       uch {
    199  1.1       uch 	u_int32_t startaddr, endaddr;
    200  1.1       uch 	int npage, xpage, kpage;
    201  1.1       uch 
    202  1.1       uch 	startaddr = MIPS_PHYS_TO_KSEG1(
    203  1.1       uch 		(btoc((u_int32_t)kernend - MIPS_KSEG0_START)) << PGSHIFT);
    204  1.1       uch 	endaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK0CS1 +
    205  1.1       uch 				     TX39_SYSADDR_DRAMBANK_LEN);
    206  1.1       uch 	kpage = btoc(MIPS_KSEG1_TO_PHYS(startaddr));
    207  1.5       uch 
    208  1.1       uch 	/* D-RAM bank0 */
    209  1.1       uch 	npage = tx39_find_dram(startaddr, endaddr);
    210  1.1       uch 
    211  1.5       uch 	printf("DRAM bank0: %d pages (%dMByte) reserved %d pages\n",
    212  1.5       uch 	       npage + 1, ((npage  + 1) * NBPG) / 0x100000, kpage + 1);
    213  1.1       uch 	npage -= kpage; /* exclude kernel area */
    214  1.5       uch 
    215  1.1       uch 	/* Clear DRAM area */
    216  1.1       uch 	memset((void*)startaddr, 0, npage * NBPG);
    217  1.1       uch 
    218  1.1       uch 	/* D-RAM bank1 XXX find only. not usable yet */
    219  1.1       uch 	startaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK1CS1);
    220  1.1       uch 	endaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK1CS1 +
    221  1.1       uch 				     TX39_SYSADDR_DRAMBANK_LEN);
    222  1.1       uch 	xpage = tx39_find_dram(startaddr, endaddr);
    223  1.1       uch 	printf("DRAM bank1: %d pages (%dMByte) ...but not usable yet\n",
    224  1.1       uch 	       xpage + 1, ((xpage + 1) * NBPG) / 0x100000);
    225  1.1       uch 
    226  1.5       uch 	/*
    227  1.5       uch 	 *  Clear currently unused D-RAM area
    228  1.5       uch 	 *  (For reboot Windows CE clearly)
    229  1.5       uch 	 */
    230  1.1       uch 	memset((void*)startaddr, 0, npage * NBPG);
    231  1.5       uch 	memset((void*)(KERNBASE + 0x400), 0,
    232  1.5       uch 	       KERNTEXTOFF - KERNBASE - 0x800);
    233  1.1       uch 
    234  1.1       uch 	return npage; /* Return bank0's memory only */
    235  1.2  takemura }
    236  1.2  takemura 
    237  1.2  takemura void
    238  1.2  takemura tx_reboot(howto, bootstr)
    239  1.2  takemura 	int howto;
    240  1.2  takemura 	char *bootstr;
    241  1.2  takemura {
    242  1.2  takemura 	goto *(u_int32_t *)MIPS_RESET_EXC_VEC;
    243  1.1       uch }
    244  1.1       uch 
    245  1.1       uch int
    246  1.1       uch tx39_find_dram(startaddr, endaddr)
    247  1.1       uch 	u_int32_t startaddr; /* kseg1 */
    248  1.1       uch 	u_int32_t endaddr;    /* kseg1 */
    249  1.1       uch {
    250  1.1       uch #define DRAM_MAGIC0 0xac1dcafe
    251  1.1       uch #define DRAM_MAGIC1 0x19700220
    252  1.1       uch 	u_int32_t page;
    253  1.1       uch 	int npage;
    254  1.1       uch 
    255  1.1       uch 	page = startaddr;
    256  1.1       uch 	((volatile int *)page)[0] = DRAM_MAGIC0;
    257  1.1       uch 	((volatile int *)page)[4] = DRAM_MAGIC1;
    258  1.1       uch 	page += NBPG;
    259  1.1       uch 	for (npage = 0; page < endaddr; page += NBPG, npage++) {
    260  1.1       uch 		if ((((volatile int *)page)[0] == DRAM_MAGIC0 &&
    261  1.1       uch 		     ((volatile int *)page)[4] == DRAM_MAGIC1)) {
    262  1.1       uch 			return npage;
    263  1.1       uch 		}
    264  1.1       uch 	}
    265  1.1       uch 	/* no memory in this bank */
    266  1.1       uch 	return 0;
    267  1.1       uch }
    268  1.1       uch 
    269  1.1       uch void
    270  1.1       uch tx_bus_reset()
    271  1.1       uch {
    272  1.1       uch 	/* hpcmips port don't use */
    273  1.1       uch }
    274  1.1       uch 
    275  1.1       uch void
    276  1.1       uch tx_cons_init()
    277  1.1       uch {
    278  1.1       uch 	int slot;
    279  1.6       uch #define CONSPLATIDMATCH(p) \
    280  1.6       uch 	platid_match(&platid, &platid_mask_MACH_##p)
    281  1.1       uch 
    282  1.1       uch #ifdef SERIALCONSSLOT
    283  1.1       uch 	slot = SERIALCONSSLOT;
    284  1.1       uch #else
    285  1.1       uch 	slot = TX39_UARTA;
    286  1.1       uch #endif
    287  1.1       uch 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    288  1.1       uch 		if(txcom_cnattach(slot, CONSPEED,
    289  1.5       uch 				  (TTYDEF_CFLAG & ~(CSIZE | PARENB)) |
    290  1.5       uch 				  CS8)) {
    291  1.1       uch 			panic("tx_cons_init: can't attach serial console.");
    292  1.1       uch 		}
    293  1.5       uch 	} else {
    294  1.5       uch #if NP7416BUF > 0
    295  1.6       uch 		if(CONSPLATIDMATCH(COMPAQ_C) &&
    296  1.6       uch 		   p7416buf_cnattach(TX39_SYSADDR_CS3)) {
    297  1.5       uch 			panic("tx_cons_init: can't init console");
    298  1.5       uch 		}
    299  1.6       uch #endif
    300  1.6       uch #if NM38813C > 0
    301  1.6       uch 		if(CONSPLATIDMATCH(VICTOR_INTERLINK) &&
    302  1.6       uch 		   m38813c_cnattach(TX39_SYSADDR_CARD1)) {
    303  1.6       uch 			panic("tx_cons_init: can't init console");
    304  1.6       uch 		}
    305  1.6       uch #endif
    306  1.6       uch #if NTC5165BUF > 0
    307  1.6       uch 		if(CONSPLATIDMATCH(SHARP_TELIOS) &&
    308  1.6       uch 		   tc5165buf_cnattach(TX39_SYSADDR_CS1)) {
    309  1.5       uch 			panic("tx_cons_init: can't init console");
    310  1.5       uch 		}
    311  1.5       uch #endif
    312  1.1       uch 	}
    313  1.1       uch 
    314  1.1       uch }
    315  1.1       uch 
    316  1.1       uch void
    317  1.1       uch tx_device_register(dev, aux)
    318  1.1       uch 	struct device *dev;
    319  1.1       uch 	void *aux;
    320  1.1       uch {
    321  1.1       uch 	/* hpcmips port don't use */
    322  1.1       uch }
    323  1.1       uch 
    324  1.1       uch void
    325  1.1       uch tx_conf_register_intr(t, intrt)
    326  1.1       uch 	tx_chipset_tag_t t;
    327  1.1       uch 	void *intrt;
    328  1.1       uch {
    329  1.1       uch 	if (tx_chipset.tc_intrt) {
    330  1.1       uch 		panic("duplicate intrt");
    331  1.1       uch 	}
    332  1.1       uch 
    333  1.1       uch 	if (t != &tx_chipset) {
    334  1.1       uch 		panic("bogus tx_chipset_tag");
    335  1.1       uch 	}
    336  1.1       uch 
    337  1.1       uch 	tx_chipset.tc_intrt = intrt;
    338  1.1       uch }
    339  1.1       uch 
    340  1.1       uch #ifdef TX39_PREFER_FUNCTION
    341  1.1       uch tx_chipset_tag_t
    342  1.1       uch tx_conf_get_tag()
    343  1.1       uch {
    344  1.1       uch 	return (tx_chipset_tag_t)&tx_chipset;
    345  1.1       uch }
    346  1.1       uch 
    347  1.1       uch txreg_t
    348  1.1       uch tx_conf_read(t, reg)
    349  1.1       uch 	tx_chipset_tag_t t;
    350  1.1       uch 	int reg;
    351  1.1       uch {
    352  1.8       uch 	return *((volatile txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg));
    353  1.1       uch }
    354  1.1       uch 
    355  1.1       uch void
    356  1.1       uch tx_conf_write(t, reg, val)
    357  1.1       uch 	tx_chipset_tag_t t;
    358  1.1       uch 	int reg;
    359  1.1       uch 	txreg_t val;
    360  1.1       uch {
    361  1.8       uch 	*((volatile txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg)) = val;
    362  1.1       uch }
    363  1.1       uch #endif /* TX39_PREFER_FUNCTION */
    364  1.1       uch 
    365  1.1       uch int
    366  1.1       uch __is_set_print(reg, mask, name)
    367  1.1       uch 	u_int32_t reg;
    368  1.1       uch 	int mask;
    369  1.1       uch 	char *name;
    370  1.1       uch {
    371  1.1       uch 	if (reg & mask) {
    372  1.1       uch 		printf("%s ", name);
    373  1.1       uch 		return 1;
    374  1.1       uch 	}
    375  1.1       uch 	return 0;
    376  1.1       uch }
    377