tx39.c revision 1.14       1  1.14      shin /*	$NetBSD: tx39.c,v 1.14 2000/02/21 13:46:04 shin Exp $ */
      2   1.1       uch 
      3   1.1       uch /*
      4   1.9       uch  * Copyright (c) 1999, 2000, 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.6       uch #include "tc5165buf.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.14      shin #include <sys/kcore.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.13      sato #include <hpcmips/hpcmips/machdep.h> /* cpu_name */
     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 NM38813C > 0
     66   1.5       uch #include <hpcmips/dev/m38813cvar.h>
     67   1.1       uch #endif
     68   1.6       uch #if NTC5165BUF > 0
     69   1.6       uch #include <hpcmips/dev/tc5165bufvar.h>
     70   1.6       uch #endif
     71   1.1       uch 
     72   1.1       uch extern unsigned nullclkread __P((void));
     73   1.1       uch extern unsigned (*clkread) __P((void));
     74   1.1       uch 
     75   1.1       uch struct tx_chipset_tag tx_chipset;
     76   1.1       uch 
     77   1.1       uch #ifdef TX39_DEBUG
     78   1.1       uch u_int32_t tx39debugflag;
     79   1.1       uch #endif
     80   1.1       uch 
     81   1.1       uch void	tx_init __P((void));
     82   1.1       uch int	tx39icu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
     83   1.8       uch void	tx39clock_cpuspeed __P((int*, int*));
     84   1.1       uch 
     85   1.1       uch /* TX39-specific initialization vector */
     86   1.1       uch void	tx_os_init __P((void));
     87   1.1       uch void	tx_bus_reset __P((void));
     88   1.1       uch void	tx_cons_init __P((void));
     89   1.1       uch void	tx_device_register __P((struct device *, void *));
     90   1.1       uch void    tx_fb_init __P((caddr_t*));
     91  1.14      shin void    tx_mem_init __P((paddr_t));
     92  1.14      shin void	tx_find_dram __P((paddr_t, paddr_t));
     93   1.2  takemura void	tx_reboot __P((int howto, char *bootstr));
     94   1.5       uch int	tx_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg,
     95   1.5       uch 		     u_int32_t causeReg));
     96   1.1       uch 
     97  1.14      shin extern phys_ram_seg_t mem_clusters[];
     98  1.14      shin extern int mem_cluster_cnt;
     99  1.14      shin 
    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.13      sato 		sprintf(cpu_name, "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.13      sato 		sprintf(cpu_name, "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.13      sato 		sprintf(cpu_name, "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.14      shin void
    196   1.1       uch tx_mem_init(kernend)
    197  1.14      shin 	paddr_t kernend;
    198   1.1       uch {
    199  1.14      shin 	mem_clusters[0].start = 0;
    200  1.14      shin 	mem_clusters[0].size = kernend;
    201  1.14      shin 	mem_cluster_cnt = 1;
    202  1.14      shin 	/* search DRAM bank 0 */
    203  1.14      shin 	tx_find_dram(kernend, 0x02000000);
    204   1.1       uch 
    205  1.14      shin 	/* search DRAM bank 1 */
    206  1.14      shin 	tx_find_dram(0x02000000, 0x04000000);
    207   1.5       uch 	/*
    208   1.5       uch 	 *  Clear currently unused D-RAM area
    209   1.5       uch 	 *  (For reboot Windows CE clearly)
    210   1.5       uch 	 */
    211  1.14      shin 	memset((void *)(KERNBASE + 0x400), 0, KERNTEXTOFF -
    212  1.14      shin 	       (KERNBASE + 0x800));
    213   1.2  takemura }
    214   1.2  takemura 
    215   1.2  takemura void
    216  1.14      shin tx_find_dram(start, end)
    217  1.14      shin 	paddr_t start, end;
    218   1.2  takemura {
    219  1.14      shin 	caddr_t page, startaddr, endaddr;
    220  1.14      shin 
    221  1.14      shin 	startaddr = (void*)MIPS_PHYS_TO_KSEG1(start);
    222  1.14      shin 	endaddr = (void*)MIPS_PHYS_TO_KSEG1(end);
    223   1.1       uch 
    224   1.1       uch #define DRAM_MAGIC0 0xac1dcafe
    225   1.1       uch #define DRAM_MAGIC1 0x19700220
    226   1.1       uch 
    227   1.1       uch 	page = startaddr;
    228  1.14      shin 	if (badaddr(page, 4))
    229  1.14      shin 		return;
    230  1.14      shin 
    231  1.14      shin 	*(volatile int *)(page+0) = DRAM_MAGIC0;
    232  1.14      shin 	*(volatile int *)(page+4) = DRAM_MAGIC1;
    233  1.14      shin 	wbflush();
    234  1.14      shin 
    235  1.14      shin 	if (*(volatile int *)(page+0) != DRAM_MAGIC0 ||
    236  1.14      shin 	    *(volatile int *)(page+4) != DRAM_MAGIC1)
    237  1.14      shin 		return;
    238  1.14      shin 
    239  1.14      shin 	for (page += NBPG; page < endaddr; page += NBPG) {
    240  1.14      shin 		if (badaddr(page, 4))
    241  1.14      shin 			return;
    242  1.14      shin 
    243  1.14      shin 		if (*(volatile int *)(page+0) == DRAM_MAGIC0 &&
    244  1.14      shin 		    *(volatile int *)(page+4) == DRAM_MAGIC1) {
    245  1.14      shin 			mem_clusters[mem_cluster_cnt].start = start;
    246  1.14      shin 			mem_clusters[mem_cluster_cnt].size =
    247  1.14      shin 				page - startaddr;
    248  1.14      shin 			/* skip kernel area */
    249  1.14      shin 			if (mem_cluster_cnt == 1)
    250  1.14      shin 				mem_clusters[mem_cluster_cnt].size -= start;
    251  1.14      shin 
    252  1.14      shin 			mem_cluster_cnt++;
    253  1.14      shin 
    254  1.14      shin 			return;
    255   1.1       uch 		}
    256   1.1       uch 	}
    257  1.14      shin 
    258   1.1       uch 	/* no memory in this bank */
    259  1.14      shin 	return;
    260  1.14      shin }
    261  1.14      shin 
    262  1.14      shin void
    263  1.14      shin tx_reboot(howto, bootstr)
    264  1.14      shin 	int howto;
    265  1.14      shin 	char *bootstr;
    266  1.14      shin {
    267  1.14      shin 	goto *(u_int32_t *)MIPS_RESET_EXC_VEC;
    268   1.1       uch }
    269   1.1       uch 
    270   1.1       uch void
    271   1.1       uch tx_bus_reset()
    272   1.1       uch {
    273   1.1       uch 	/* hpcmips port don't use */
    274   1.1       uch }
    275   1.1       uch 
    276   1.1       uch void
    277   1.1       uch tx_cons_init()
    278   1.1       uch {
    279   1.1       uch 	int slot;
    280   1.6       uch #define CONSPLATIDMATCH(p) \
    281   1.6       uch 	platid_match(&platid, &platid_mask_MACH_##p)
    282   1.1       uch 
    283   1.1       uch #ifdef SERIALCONSSLOT
    284   1.1       uch 	slot = SERIALCONSSLOT;
    285   1.1       uch #else
    286   1.1       uch 	slot = TX39_UARTA;
    287   1.1       uch #endif
    288   1.1       uch 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    289   1.1       uch 		if(txcom_cnattach(slot, CONSPEED,
    290   1.5       uch 				  (TTYDEF_CFLAG & ~(CSIZE | PARENB)) |
    291   1.5       uch 				  CS8)) {
    292   1.1       uch 			panic("tx_cons_init: can't attach serial console.");
    293   1.1       uch 		}
    294   1.5       uch 	} else {
    295   1.6       uch #if NM38813C > 0
    296   1.6       uch 		if(CONSPLATIDMATCH(VICTOR_INTERLINK) &&
    297   1.6       uch 		   m38813c_cnattach(TX39_SYSADDR_CARD1)) {
    298  1.10       uch 			goto panic;
    299   1.6       uch 		}
    300   1.6       uch #endif
    301   1.6       uch #if NTC5165BUF > 0
    302  1.10       uch 		if(CONSPLATIDMATCH(COMPAQ_C) &&
    303  1.10       uch 		   tc5165buf_cnattach(TX39_SYSADDR_CS3)) {
    304  1.10       uch 			goto panic;
    305  1.10       uch 		}
    306  1.10       uch 
    307   1.6       uch 		if(CONSPLATIDMATCH(SHARP_TELIOS) &&
    308   1.6       uch 		   tc5165buf_cnattach(TX39_SYSADDR_CS1)) {
    309  1.10       uch 			goto panic;
    310  1.10       uch 		}
    311  1.10       uch 
    312  1.10       uch 		if(CONSPLATIDMATCH(SHARP_MOBILON) &&
    313  1.10       uch 		   tc5165buf_cnattach(TX39_SYSADDR_MCS0)) {
    314  1.10       uch 			goto panic;
    315   1.5       uch 		}
    316   1.5       uch #endif
    317   1.1       uch 	}
    318  1.10       uch 
    319  1.10       uch 	return;
    320  1.10       uch  panic:
    321  1.10       uch 	panic("tx_cons_init: can't init console");
    322  1.10       uch 	/* NOTREACHED */
    323   1.1       uch }
    324   1.1       uch 
    325   1.1       uch void
    326   1.1       uch tx_device_register(dev, aux)
    327   1.1       uch 	struct device *dev;
    328   1.1       uch 	void *aux;
    329   1.1       uch {
    330   1.1       uch 	/* hpcmips port don't use */
    331   1.1       uch }
    332   1.1       uch 
    333   1.1       uch void
    334   1.1       uch tx_conf_register_intr(t, intrt)
    335   1.1       uch 	tx_chipset_tag_t t;
    336   1.1       uch 	void *intrt;
    337   1.1       uch {
    338   1.1       uch 	if (tx_chipset.tc_intrt) {
    339   1.1       uch 		panic("duplicate intrt");
    340   1.1       uch 	}
    341   1.1       uch 
    342   1.1       uch 	if (t != &tx_chipset) {
    343   1.1       uch 		panic("bogus tx_chipset_tag");
    344   1.1       uch 	}
    345   1.1       uch 
    346   1.1       uch 	tx_chipset.tc_intrt = intrt;
    347   1.1       uch }
    348   1.1       uch 
    349   1.9       uch void
    350   1.9       uch tx_conf_register_power(t, powert)
    351   1.9       uch 	tx_chipset_tag_t t;
    352   1.9       uch 	void *powert;
    353   1.9       uch {
    354   1.9       uch 	if (tx_chipset.tc_powert) {
    355   1.9       uch 		panic("duplicate powert");
    356   1.9       uch 	}
    357   1.9       uch 
    358   1.9       uch 	if (t != &tx_chipset) {
    359   1.9       uch 		panic("bogus tx_chipset_tag");
    360   1.9       uch 	}
    361   1.9       uch 
    362   1.9       uch 	tx_chipset.tc_powert = powert;
    363   1.9       uch }
    364   1.9       uch 
    365   1.9       uch void
    366   1.9       uch tx_conf_register_clock(t, clockt)
    367   1.9       uch 	tx_chipset_tag_t t;
    368   1.9       uch 	void *clockt;
    369   1.9       uch {
    370   1.9       uch 	if (tx_chipset.tc_clockt) {
    371   1.9       uch 		panic("duplicate clockt");
    372   1.9       uch 	}
    373   1.9       uch 
    374   1.9       uch 	if (t != &tx_chipset) {
    375   1.9       uch 		panic("bogus tx_chipset_tag");
    376   1.9       uch 	}
    377   1.9       uch 
    378   1.9       uch 	tx_chipset.tc_clockt = clockt;
    379  1.11       uch }
    380  1.11       uch 
    381  1.11       uch void
    382  1.11       uch tx_conf_register_sound(t, soundt)
    383  1.11       uch 	tx_chipset_tag_t t;
    384  1.11       uch 	void *soundt;
    385  1.11       uch {
    386  1.11       uch 	if (t != &tx_chipset) {
    387  1.11       uch 		panic("bogus tx_chipset_tag");
    388  1.11       uch 	}
    389  1.11       uch 
    390  1.11       uch 	tx_chipset.tc_soundt = soundt;
    391  1.12       uch }
    392  1.12       uch 
    393  1.12       uch void
    394  1.12       uch tx_conf_register_ioman(t, iomant)
    395  1.12       uch 	tx_chipset_tag_t t;
    396  1.12       uch 	void *iomant;
    397  1.12       uch {
    398  1.12       uch 	if (tx_chipset.tc_iomant) {
    399  1.12       uch 		panic("duplicate iomant");
    400  1.12       uch 	}
    401  1.12       uch 
    402  1.12       uch 	if (t != &tx_chipset) {
    403  1.12       uch 		panic("bogus tx_chipset_tag");
    404  1.12       uch 	}
    405  1.12       uch 
    406  1.12       uch 	tx_chipset.tc_iomant = iomant;
    407   1.9       uch }
    408   1.9       uch 
    409   1.1       uch #ifdef TX39_PREFER_FUNCTION
    410   1.1       uch tx_chipset_tag_t
    411   1.1       uch tx_conf_get_tag()
    412   1.1       uch {
    413   1.1       uch 	return (tx_chipset_tag_t)&tx_chipset;
    414   1.1       uch }
    415   1.1       uch 
    416   1.1       uch txreg_t
    417   1.1       uch tx_conf_read(t, reg)
    418   1.1       uch 	tx_chipset_tag_t t;
    419   1.1       uch 	int reg;
    420   1.1       uch {
    421   1.8       uch 	return *((volatile txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg));
    422   1.1       uch }
    423   1.1       uch 
    424   1.1       uch void
    425   1.1       uch tx_conf_write(t, reg, val)
    426   1.1       uch 	tx_chipset_tag_t t;
    427   1.1       uch 	int reg;
    428   1.1       uch 	txreg_t val;
    429   1.1       uch {
    430   1.8       uch 	*((volatile txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg)) = val;
    431   1.1       uch }
    432   1.1       uch #endif /* TX39_PREFER_FUNCTION */
    433   1.1       uch 
    434   1.1       uch int
    435   1.1       uch __is_set_print(reg, mask, name)
    436   1.1       uch 	u_int32_t reg;
    437   1.1       uch 	int mask;
    438   1.1       uch 	char *name;
    439   1.1       uch {
    440   1.9       uch 	const char onoff[2] = "_x";
    441   1.9       uch 	int ret = reg & mask ? 1 : 0;
    442   1.9       uch 
    443   1.9       uch 	printf("%s[%c] ", name, onoff[ret]);
    444   1.9       uch 
    445   1.9       uch 	return ret;
    446   1.1       uch }
    447