Home | History | Annotate | Line # | Download | only in tx
tx39.c revision 1.5
      1  1.5       uch /*	$NetBSD: tx39.c,v 1.5 1999/12/08 15:54:11 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.1       uch 
     33  1.1       uch #include <sys/param.h>
     34  1.1       uch #include <sys/systm.h>
     35  1.1       uch #include <sys/device.h>
     36  1.1       uch 
     37  1.1       uch #include <machine/locore.h>   /* cpu_id */
     38  1.1       uch #include <machine/bootinfo.h> /* bootinfo */
     39  1.1       uch #include <machine/sysconf.h>  /* platform */
     40  1.1       uch 
     41  1.1       uch #include <machine/bus.h>
     42  1.1       uch #include <machine/intr.h>
     43  1.1       uch 
     44  1.1       uch #include <hpcmips/hpcmips/machdep.h> /* cpu_model */
     45  1.1       uch #include <hpcmips/dev/biconsvar.h>
     46  1.1       uch #include <hpcmips/dev/bicons.h>
     47  1.1       uch 
     48  1.1       uch #include <hpcmips/tx/tx39biureg.h>
     49  1.1       uch #include <hpcmips/tx/tx39reg.h>
     50  1.1       uch #include <hpcmips/tx/tx39var.h>
     51  1.1       uch #ifdef TX391X
     52  1.1       uch #include <hpcmips/tx/tx3912videovar.h>
     53  1.1       uch #endif
     54  1.1       uch 
     55  1.1       uch #include <sys/termios.h>
     56  1.1       uch #include <sys/ttydefaults.h>
     57  1.1       uch #include <hpcmips/tx/tx39uartvar.h>
     58  1.1       uch #ifndef CONSPEED
     59  1.1       uch #define CONSPEED TTYDEF_SPEED
     60  1.1       uch #endif
     61  1.1       uch 
     62  1.5       uch /* console keyboard */
     63  1.5       uch #if NP7416BUF > 0
     64  1.5       uch #include <hpcmips/dev/p7416bufvar.h>
     65  1.5       uch #endif
     66  1.5       uch #if NM38813C > 0
     67  1.5       uch #include <hpcmips/dev/m38813cvar.h>
     68  1.1       uch #endif
     69  1.1       uch 
     70  1.1       uch extern unsigned nullclkread __P((void));
     71  1.1       uch extern unsigned (*clkread) __P((void));
     72  1.1       uch 
     73  1.1       uch struct tx_chipset_tag tx_chipset;
     74  1.1       uch 
     75  1.1       uch #ifdef TX39_DEBUG
     76  1.1       uch u_int32_t tx39debugflag;
     77  1.1       uch #endif
     78  1.1       uch 
     79  1.1       uch void	tx_init __P((void));
     80  1.1       uch int	tx39icu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
     81  1.1       uch int	tx39_find_dram __P((u_int32_t, u_int32_t));
     82  1.1       uch 
     83  1.1       uch /* TX39-specific initialization vector */
     84  1.1       uch void	tx_os_init __P((void));
     85  1.1       uch void	tx_bus_reset __P((void));
     86  1.1       uch void	tx_cons_init __P((void));
     87  1.1       uch void	tx_device_register __P((struct device *, void *));
     88  1.1       uch void    tx_fb_init __P((caddr_t*));
     89  1.1       uch int     tx_mem_init __P((caddr_t));
     90  1.2  takemura void	tx_reboot __P((int howto, char *bootstr));
     91  1.5       uch int	tx_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg,
     92  1.5       uch 		     u_int32_t causeReg));
     93  1.1       uch 
     94  1.1       uch void
     95  1.1       uch tx_init()
     96  1.1       uch {
     97  1.1       uch 	tx_chipset_tag_t tc;
     98  1.1       uch 	int model, rev;
     99  1.1       uch 
    100  1.1       uch 	tc = tx_conf_get_tag();
    101  1.1       uch 	/*
    102  1.1       uch 	 * Platform Specific Function Hooks
    103  1.1       uch 	 */
    104  1.1       uch 	platform.os_init = tx_os_init;
    105  1.1       uch 	platform.bus_reset = tx_bus_reset;
    106  1.1       uch 	platform.cons_init = tx_cons_init;
    107  1.1       uch 	platform.device_register = tx_device_register;
    108  1.1       uch 	platform.fb_init = tx_fb_init;
    109  1.1       uch 	platform.mem_init = tx_mem_init;
    110  1.2  takemura 	platform.reboot = tx_reboot;
    111  1.1       uch 
    112  1.1       uch 	model = (cpu_id.cpu.cp_majrev << 4)| cpu_id.cpu.cp_minrev;
    113  1.1       uch 
    114  1.1       uch 	switch (model) {
    115  1.1       uch 	default:
    116  1.1       uch 		 /* Unknown TOSHIBA TX39-series */
    117  1.1       uch 		sprintf(cpu_model, "Unknown TOSHIBA TX39-series %x.%x",
    118  1.1       uch 			cpu_id.cpu.cp_majrev, cpu_id.cpu.cp_minrev);
    119  1.1       uch 		break;
    120  1.1       uch 	case TMPR3912:
    121  1.1       uch 		sprintf(cpu_model, "TOSHIBA TMPR3912");
    122  1.1       uch 		cpuspeed = 50; /* XXX Should calibrate XXX */
    123  1.1       uch 		break;
    124  1.1       uch 	case TMPR3922:
    125  1.1       uch 		rev = tx_conf_read(tc, TX3922_REVISION_REG);
    126  1.1       uch 		sprintf(cpu_model, "TOSHIBA TMPR3922 rev. %x.%x",
    127  1.1       uch 			(rev >> 4) & 0xf, rev & 0xf);
    128  1.1       uch 		cpuspeed = 100; /* XXX Should calibrate XXX */
    129  1.1       uch 		break;
    130  1.1       uch 	}
    131  1.1       uch }
    132  1.1       uch 
    133  1.1       uch void
    134  1.1       uch tx_os_init()
    135  1.1       uch {
    136  1.1       uch 	/*
    137  1.1       uch 	 * Set up interrupt handling and I/O addresses.
    138  1.1       uch 	 */
    139  1.1       uch 	mips_hardware_intr = tx39icu_intr;
    140  1.1       uch 
    141  1.1       uch 	splvec.splbio = MIPS_SPL_2_4;
    142  1.1       uch 	splvec.splnet = MIPS_SPL_2_4;
    143  1.1       uch 	splvec.spltty = MIPS_SPL_2_4;
    144  1.1       uch 	splvec.splimp = MIPS_SPL_2_4;
    145  1.1       uch 	splvec.splclock = MIPS_SPL_2_4;
    146  1.1       uch 	splvec.splstatclock = MIPS_SPL_2_4;
    147  1.1       uch 
    148  1.1       uch 	/* no high resolution timer circuit; possibly never called */
    149  1.1       uch 	clkread = nullclkread;
    150  1.1       uch }
    151  1.1       uch 
    152  1.1       uch void
    153  1.1       uch tx_fb_init(kernend)
    154  1.1       uch 	caddr_t *kernend;
    155  1.1       uch {
    156  1.1       uch #ifdef TX391X
    157  1.1       uch 	tx_chipset_tag_t tc;
    158  1.1       uch 	u_int32_t fb_start, fb_addr, fb_size, fb_line_bytes;
    159  1.1       uch 
    160  1.1       uch 	/* Initialize to access TX39 configuration register */
    161  1.1       uch 	tc = tx_conf_get_tag();
    162  1.1       uch 
    163  1.1       uch 	fb_start = MIPS_KSEG0_TO_PHYS(*kernend);
    164  1.1       uch 	tx3912video_init(tc, fb_start, bootinfo->fb_width,
    165  1.1       uch 			bootinfo->fb_height, &fb_addr, &fb_size,
    166  1.1       uch 			&fb_line_bytes);
    167  1.1       uch 
    168  1.1       uch 	/* Set bootinfo for bicons */
    169  1.1       uch 	bootinfo->fb_line_bytes = fb_line_bytes;
    170  1.1       uch 	bootinfo->fb_addr = (unsigned char*)MIPS_PHYS_TO_KSEG1(fb_addr);
    171  1.1       uch 
    172  1.1       uch 	/* Skip V-RAM area */
    173  1.1       uch 	*kernend += fb_size;
    174  1.1       uch #endif /* TX391X */
    175  1.1       uch #ifdef TX392X
    176  1.1       uch 	/*
    177  1.1       uch 	 *  Plum V-RAM isn't accessible until pmap_bootstrap,
    178  1.1       uch 	 * at this time, bicons is disabled.
    179  1.1       uch 	 */
    180  1.1       uch 	bootinfo->fb_addr = 0;
    181  1.1       uch #endif /* TX392X */
    182  1.1       uch }
    183  1.1       uch 
    184  1.1       uch int
    185  1.1       uch tx_mem_init(kernend)
    186  1.1       uch 	caddr_t kernend; /* kseg0 */
    187  1.1       uch {
    188  1.1       uch 	u_int32_t startaddr, endaddr;
    189  1.1       uch 	int npage, xpage, kpage;
    190  1.1       uch 
    191  1.1       uch 	startaddr = MIPS_PHYS_TO_KSEG1(
    192  1.1       uch 		(btoc((u_int32_t)kernend - MIPS_KSEG0_START)) << PGSHIFT);
    193  1.1       uch 	endaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK0CS1 +
    194  1.1       uch 				     TX39_SYSADDR_DRAMBANK_LEN);
    195  1.1       uch 	kpage = btoc(MIPS_KSEG1_TO_PHYS(startaddr));
    196  1.5       uch 
    197  1.1       uch 	/* D-RAM bank0 */
    198  1.1       uch 	npage = tx39_find_dram(startaddr, endaddr);
    199  1.1       uch 
    200  1.5       uch 	printf("DRAM bank0: %d pages (%dMByte) reserved %d pages\n",
    201  1.5       uch 	       npage + 1, ((npage  + 1) * NBPG) / 0x100000, kpage + 1);
    202  1.1       uch 	npage -= kpage; /* exclude kernel area */
    203  1.5       uch 
    204  1.1       uch 	/* Clear DRAM area */
    205  1.1       uch 	memset((void*)startaddr, 0, npage * NBPG);
    206  1.1       uch 
    207  1.1       uch 	/* D-RAM bank1 XXX find only. not usable yet */
    208  1.1       uch 	startaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK1CS1);
    209  1.1       uch 	endaddr = MIPS_PHYS_TO_KSEG1(TX39_SYSADDR_DRAMBANK1CS1 +
    210  1.1       uch 				     TX39_SYSADDR_DRAMBANK_LEN);
    211  1.1       uch 	xpage = tx39_find_dram(startaddr, endaddr);
    212  1.1       uch 	printf("DRAM bank1: %d pages (%dMByte) ...but not usable yet\n",
    213  1.1       uch 	       xpage + 1, ((xpage + 1) * NBPG) / 0x100000);
    214  1.1       uch 
    215  1.5       uch 	/*
    216  1.5       uch 	 *  Clear currently unused D-RAM area
    217  1.5       uch 	 *  (For reboot Windows CE clearly)
    218  1.5       uch 	 */
    219  1.1       uch 	memset((void*)startaddr, 0, npage * NBPG);
    220  1.5       uch 	memset((void*)(KERNBASE + 0x400), 0,
    221  1.5       uch 	       KERNTEXTOFF - KERNBASE - 0x800);
    222  1.1       uch 
    223  1.1       uch 	return npage; /* Return bank0's memory only */
    224  1.2  takemura }
    225  1.2  takemura 
    226  1.2  takemura void
    227  1.2  takemura tx_reboot(howto, bootstr)
    228  1.2  takemura 	int howto;
    229  1.2  takemura 	char *bootstr;
    230  1.2  takemura {
    231  1.2  takemura 	goto *(u_int32_t *)MIPS_RESET_EXC_VEC;
    232  1.1       uch }
    233  1.1       uch 
    234  1.1       uch int
    235  1.1       uch tx39_find_dram(startaddr, endaddr)
    236  1.1       uch 	u_int32_t startaddr; /* kseg1 */
    237  1.1       uch 	u_int32_t endaddr;    /* kseg1 */
    238  1.1       uch {
    239  1.1       uch #define DRAM_MAGIC0 0xac1dcafe
    240  1.1       uch #define DRAM_MAGIC1 0x19700220
    241  1.1       uch 	u_int32_t page;
    242  1.1       uch 	int npage;
    243  1.1       uch 
    244  1.1       uch 	page = startaddr;
    245  1.1       uch 	((volatile int *)page)[0] = DRAM_MAGIC0;
    246  1.1       uch 	((volatile int *)page)[4] = DRAM_MAGIC1;
    247  1.1       uch 	page += NBPG;
    248  1.1       uch 	for (npage = 0; page < endaddr; page += NBPG, npage++) {
    249  1.1       uch 		if ((((volatile int *)page)[0] == DRAM_MAGIC0 &&
    250  1.1       uch 		     ((volatile int *)page)[4] == DRAM_MAGIC1)) {
    251  1.1       uch 			return npage;
    252  1.1       uch 		}
    253  1.1       uch 	}
    254  1.1       uch 	/* no memory in this bank */
    255  1.1       uch 	return 0;
    256  1.1       uch }
    257  1.1       uch 
    258  1.1       uch void
    259  1.1       uch tx_bus_reset()
    260  1.1       uch {
    261  1.1       uch 	/* hpcmips port don't use */
    262  1.1       uch }
    263  1.1       uch 
    264  1.1       uch void
    265  1.1       uch tx_cons_init()
    266  1.1       uch {
    267  1.1       uch 	int slot;
    268  1.1       uch 
    269  1.1       uch #ifdef SERIALCONSSLOT
    270  1.1       uch 	slot = SERIALCONSSLOT;
    271  1.1       uch #else
    272  1.1       uch 	slot = TX39_UARTA;
    273  1.1       uch #endif
    274  1.1       uch 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    275  1.1       uch 		if(txcom_cnattach(slot, CONSPEED,
    276  1.5       uch 				  (TTYDEF_CFLAG & ~(CSIZE | PARENB)) |
    277  1.5       uch 				  CS8)) {
    278  1.1       uch 			panic("tx_cons_init: can't attach serial console.");
    279  1.1       uch 		}
    280  1.5       uch 	} else {
    281  1.5       uch #if NP7416BUF > 0
    282  1.5       uch 		if(p7416buf_cnattach(TX39_SYSADDR_CS3)) {
    283  1.5       uch 			panic("tx_cons_init: can't init console");
    284  1.5       uch 		}
    285  1.5       uch #elif NM38813C > 0
    286  1.5       uch 		if(m38813c_cnattach(TX39_SYSADDR_CARD1)) {
    287  1.5       uch 			panic("tx_cons_init: can't init console");
    288  1.5       uch 		}
    289  1.5       uch #endif
    290  1.1       uch 	}
    291  1.1       uch 
    292  1.1       uch }
    293  1.1       uch 
    294  1.1       uch void
    295  1.1       uch tx_device_register(dev, aux)
    296  1.1       uch 	struct device *dev;
    297  1.1       uch 	void *aux;
    298  1.1       uch {
    299  1.1       uch 	/* hpcmips port don't use */
    300  1.1       uch }
    301  1.1       uch 
    302  1.1       uch void
    303  1.1       uch tx_conf_register_intr(t, intrt)
    304  1.1       uch 	tx_chipset_tag_t t;
    305  1.1       uch 	void *intrt;
    306  1.1       uch {
    307  1.1       uch 	if (tx_chipset.tc_intrt) {
    308  1.1       uch 		panic("duplicate intrt");
    309  1.1       uch 	}
    310  1.1       uch 
    311  1.1       uch 	if (t != &tx_chipset) {
    312  1.1       uch 		panic("bogus tx_chipset_tag");
    313  1.1       uch 	}
    314  1.1       uch 
    315  1.1       uch 	tx_chipset.tc_intrt = intrt;
    316  1.1       uch }
    317  1.1       uch 
    318  1.1       uch #ifdef TX39_PREFER_FUNCTION
    319  1.1       uch tx_chipset_tag_t
    320  1.1       uch tx_conf_get_tag()
    321  1.1       uch {
    322  1.1       uch 	return (tx_chipset_tag_t)&tx_chipset;
    323  1.1       uch }
    324  1.1       uch 
    325  1.1       uch txreg_t
    326  1.1       uch tx_conf_read(t, reg)
    327  1.1       uch 	tx_chipset_tag_t t;
    328  1.1       uch 	int reg;
    329  1.1       uch {
    330  1.1       uch 	return *((txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg));
    331  1.1       uch }
    332  1.1       uch 
    333  1.1       uch void
    334  1.1       uch tx_conf_write(t, reg, val)
    335  1.1       uch 	tx_chipset_tag_t t;
    336  1.1       uch 	int reg;
    337  1.1       uch 	txreg_t val;
    338  1.1       uch {
    339  1.1       uch 	*((txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg)) = val;
    340  1.1       uch }
    341  1.1       uch #endif /* TX39_PREFER_FUNCTION */
    342  1.1       uch 
    343  1.1       uch int
    344  1.1       uch __is_set_print(reg, mask, name)
    345  1.1       uch 	u_int32_t reg;
    346  1.1       uch 	int mask;
    347  1.1       uch 	char *name;
    348  1.1       uch {
    349  1.1       uch 	if (reg & mask) {
    350  1.1       uch 		printf("%s ", name);
    351  1.1       uch 		return 1;
    352  1.1       uch 	}
    353  1.1       uch 	return 0;
    354  1.1       uch }
    355