NetBSD/sys/arch/hpcmips/tx/tx39.c

457 lines
9.8 KiB
C
Raw Normal View History

/* $NetBSD: tx39.c,v 1.19 2000/07/27 17:29:05 cgd Exp $ */
1999-11-20 22:56:31 +03:00
2000-05-21 15:24:45 +04:00
/*-
* Copyright (c) 1999, 2000 UCHIYAMA Yasushi. All rights reserved.
1999-11-20 22:56:31 +03:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
2000-04-24 17:02:13 +04:00
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
2000-05-21 15:24:45 +04:00
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
1999-11-20 22:56:31 +03:00
*
2000-04-24 17:02:13 +04:00
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2000-05-21 15:24:45 +04:00
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1999-11-20 22:56:31 +03:00
*/
#include "opt_tx39_debug.h"
1999-12-08 18:54:11 +03:00
#include "m38813c.h"
1999-12-12 20:08:37 +03:00
#include "tc5165buf.h"
1999-11-20 22:56:31 +03:00
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kcore.h>
1999-11-20 22:56:31 +03:00
#include <machine/locore.h> /* cpu_id */
#include <machine/bootinfo.h> /* bootinfo */
#include <machine/sysconf.h> /* platform */
1999-12-12 20:08:37 +03:00
#include <machine/platid.h>
#include <machine/platid_mask.h>
1999-11-20 22:56:31 +03:00
#include <machine/bus.h>
#include <machine/intr.h>
2000-02-10 05:15:01 +03:00
#include <hpcmips/hpcmips/machdep.h> /* cpu_name */
1999-11-20 22:56:31 +03:00
#include <hpcmips/tx/tx39biureg.h>
#include <hpcmips/tx/tx39reg.h>
#include <hpcmips/tx/tx39var.h>
#ifdef TX391X
#include <hpcmips/tx/tx3912videovar.h>
#endif
#include <sys/termios.h>
#include <sys/ttydefaults.h>
#include <hpcmips/tx/tx39uartvar.h>
#ifndef CONSPEED
#define CONSPEED TTYDEF_SPEED
#endif
1999-12-08 18:54:11 +03:00
/* console keyboard */
#if NM38813C > 0
#include <hpcmips/dev/m38813cvar.h>
1999-11-20 22:56:31 +03:00
#endif
1999-12-12 20:08:37 +03:00
#if NTC5165BUF > 0
#include <hpcmips/dev/tc5165bufvar.h>
#endif
1999-11-20 22:56:31 +03:00
extern unsigned nullclkread __P((void));
extern unsigned (*clkread) __P((void));
struct tx_chipset_tag tx_chipset;
#ifdef TX39_DEBUG
u_int32_t tx39debugflag;
#endif
void tx_init __P((void));
int tx39icu_intr __P((u_int32_t, u_int32_t, u_int32_t, u_int32_t));
void tx39clock_cpuspeed __P((int*, int*));
1999-11-20 22:56:31 +03:00
/* TX39-specific initialization vector */
void tx_os_init __P((void));
void tx_bus_reset __P((void));
void tx_cons_init __P((void));
void tx_device_register __P((struct device *, void *));
void tx_fb_init __P((caddr_t*));
void tx_mem_init __P((paddr_t));
void tx_find_dram __P((paddr_t, paddr_t));
void tx_reboot __P((int howto, char *bootstr));
1999-12-08 18:54:11 +03:00
int tx_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg,
u_int32_t causeReg));
1999-11-20 22:56:31 +03:00
extern phys_ram_seg_t mem_clusters[];
extern int mem_cluster_cnt;
1999-11-20 22:56:31 +03:00
void
tx_init()
{
tx_chipset_tag_t tc;
int model, rev;
int cpuclock;
1999-11-20 22:56:31 +03:00
tc = tx_conf_get_tag();
/*
* Platform Specific Function Hooks
*/
platform.os_init = tx_os_init;
platform.bus_reset = tx_bus_reset;
platform.cons_init = tx_cons_init;
platform.device_register = tx_device_register;
platform.fb_init = tx_fb_init;
platform.mem_init = tx_mem_init;
platform.reboot = tx_reboot;
2000-04-11 21:57:42 +04:00
platform.iointr = tx39icu_intr;
1999-11-20 22:56:31 +03:00
model = MIPS_PRID_REV(cpu_id);
1999-11-20 22:56:31 +03:00
switch (model) {
default:
/* Unknown TOSHIBA TX39-series */
sprintf(cpu_name, "Unknown TOSHIBA TX39-series %x", model);
1999-11-20 22:56:31 +03:00
break;
case TMPR3912:
tx39clock_cpuspeed(&cpuclock, &cpuspeed);
2000-02-10 05:15:01 +03:00
sprintf(cpu_name, "TOSHIBA TMPR3912 %d.%02d MHz",
cpuclock / 1000000, (cpuclock % 1000000) / 10000);
1999-11-20 22:56:31 +03:00
break;
case TMPR3922:
tx39clock_cpuspeed(&cpuclock, &cpuspeed);
1999-11-20 22:56:31 +03:00
rev = tx_conf_read(tc, TX3922_REVISION_REG);
2000-02-10 05:15:01 +03:00
sprintf(cpu_name, "TOSHIBA TMPR3922 rev. %x.%x "
"%d.%02d MHz", (rev >> 4) & 0xf, rev & 0xf,
cpuclock / 1000000, (cpuclock % 1000000) / 10000);
1999-11-20 22:56:31 +03:00
break;
}
}
void
tx_os_init()
{
/*
* Set up interrupt handling and I/O addresses.
*/
splvec.splbio = MIPS_SPL_2_4;
splvec.splnet = MIPS_SPL_2_4;
splvec.spltty = MIPS_SPL_2_4;
splvec.splimp = MIPS_SPL_2_4;
splvec.splclock = MIPS_SPL_2_4;
splvec.splstatclock = MIPS_SPL_2_4;
/* no high resolution timer circuit; possibly never called */
clkread = nullclkread;
}
void
tx_fb_init(kernend)
caddr_t *kernend;
{
#ifdef TX391X
2000-04-24 17:02:13 +04:00
paddr_t fb_end;
1999-11-20 22:56:31 +03:00
2000-04-24 17:02:13 +04:00
fb_end = MIPS_KSEG0_TO_PHYS(mem_clusters[0].start +
mem_clusters[0].size - 1);
tx3912video_init(MIPS_KSEG0_TO_PHYS(*kernend), &fb_end);
1999-11-20 22:56:31 +03:00
/* Skip V-RAM area */
2000-04-24 17:02:13 +04:00
*kernend = (caddr_t)MIPS_PHYS_TO_KSEG0(fb_end);
1999-11-20 22:56:31 +03:00
#endif /* TX391X */
#ifdef TX392X
/*
* Plum V-RAM isn't accessible until pmap_bootstrap,
1999-12-12 21:40:33 +03:00
* at this time, frame buffer device is disabled.
1999-11-20 22:56:31 +03:00
*/
bootinfo->fb_addr = 0;
#endif /* TX392X */
}
void
1999-11-20 22:56:31 +03:00
tx_mem_init(kernend)
paddr_t kernend;
1999-11-20 22:56:31 +03:00
{
mem_clusters[0].start = 0;
mem_clusters[0].size = kernend;
mem_cluster_cnt = 1;
/* search DRAM bank 0 */
tx_find_dram(kernend, 0x02000000);
1999-11-20 22:56:31 +03:00
/* search DRAM bank 1 */
tx_find_dram(0x02000000, 0x04000000);
1999-12-08 18:54:11 +03:00
/*
* Clear currently unused D-RAM area
* (For reboot Windows CE clearly)
*/
memset((void *)(KERNBASE + 0x400), 0, KERNTEXTOFF -
(KERNBASE + 0x800));
1999-11-20 22:56:31 +03:00
}
void
tx_find_dram(start, end)
paddr_t start, end;
{
caddr_t page, startaddr, endaddr;
startaddr = (void*)MIPS_PHYS_TO_KSEG1(start);
endaddr = (void*)MIPS_PHYS_TO_KSEG1(end);
1999-11-20 22:56:31 +03:00
#define DRAM_MAGIC0 0xac1dcafe
#define DRAM_MAGIC1 0x19700220
page = startaddr;
if (badaddr(page, 4))
return;
2000-05-21 15:24:45 +04:00
*(volatile int *)(page + 0) = DRAM_MAGIC0;
*(volatile int *)(page + 4) = DRAM_MAGIC1;
wbflush();
2000-05-21 15:24:45 +04:00
if (*(volatile int *)(page + 0) != DRAM_MAGIC0 ||
*(volatile int *)(page + 4) != DRAM_MAGIC1)
return;
for (page += NBPG; page < endaddr; page += NBPG) {
if (badaddr(page, 4))
return;
2000-05-21 15:24:45 +04:00
if (*(volatile int *)(page + 0) == DRAM_MAGIC0 &&
*(volatile int *)(page + 4) == DRAM_MAGIC1) {
goto memend_found;
1999-11-20 22:56:31 +03:00
}
}
2000-05-21 15:24:45 +04:00
/* check for 32MByte memory */
page -= NBPG;
*(volatile int *)(page + 0) = DRAM_MAGIC0;
*(volatile int *)(page + 4) = DRAM_MAGIC1;
wbflush();
if (*(volatile int *)(page + 0) != DRAM_MAGIC0 ||
*(volatile int *)(page + 4) != DRAM_MAGIC1)
return; /* no memory in this bank */
memend_found:
mem_clusters[mem_cluster_cnt].start = start;
mem_clusters[mem_cluster_cnt].size = page - startaddr;
/* skip kernel area */
if (mem_cluster_cnt == 1)
mem_clusters[mem_cluster_cnt].size -= start;
mem_cluster_cnt++;
}
void
tx_reboot(howto, bootstr)
int howto;
char *bootstr;
{
goto *(u_int32_t *)MIPS_RESET_EXC_VEC;
1999-11-20 22:56:31 +03:00
}
void
tx_bus_reset()
{
/* hpcmips port don't use */
}
void
tx_cons_init()
{
int slot;
1999-12-12 20:08:37 +03:00
#define CONSPLATIDMATCH(p) \
platid_match(&platid, &platid_mask_MACH_##p)
1999-11-20 22:56:31 +03:00
#ifdef SERIALCONSSLOT
slot = SERIALCONSSLOT;
#else
slot = TX39_UARTA;
#endif
if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
if(txcom_cnattach(slot, CONSPEED,
1999-12-08 18:54:11 +03:00
(TTYDEF_CFLAG & ~(CSIZE | PARENB)) |
CS8)) {
1999-11-20 22:56:31 +03:00
panic("tx_cons_init: can't attach serial console.");
}
1999-12-08 18:54:11 +03:00
} else {
1999-12-12 20:08:37 +03:00
#if NM38813C > 0
if(CONSPLATIDMATCH(VICTOR_INTERLINK) &&
m38813c_cnattach(TX39_SYSADDR_CARD1)) {
2000-01-07 18:19:12 +03:00
goto panic;
1999-12-12 20:08:37 +03:00
}
#endif
#if NTC5165BUF > 0
2000-01-07 18:19:12 +03:00
if(CONSPLATIDMATCH(COMPAQ_C) &&
tc5165buf_cnattach(TX39_SYSADDR_CS3)) {
goto panic;
}
1999-12-12 20:08:37 +03:00
if(CONSPLATIDMATCH(SHARP_TELIOS) &&
tc5165buf_cnattach(TX39_SYSADDR_CS1)) {
2000-01-07 18:19:12 +03:00
goto panic;
}
if(CONSPLATIDMATCH(SHARP_MOBILON) &&
tc5165buf_cnattach(TX39_SYSADDR_MCS0)) {
goto panic;
1999-12-08 18:54:11 +03:00
}
1999-11-20 22:56:31 +03:00
#endif
1999-12-08 18:54:11 +03:00
}
2000-01-07 18:19:12 +03:00
return;
panic:
panic("tx_cons_init: can't init console");
/* NOTREACHED */
1999-11-20 22:56:31 +03:00
}
void
tx_device_register(dev, aux)
struct device *dev;
void *aux;
{
/* hpcmips port don't use */
}
void
tx_conf_register_intr(t, intrt)
tx_chipset_tag_t t;
void *intrt;
{
if (tx_chipset.tc_intrt) {
panic("duplicate intrt");
}
if (t != &tx_chipset) {
panic("bogus tx_chipset_tag");
}
tx_chipset.tc_intrt = intrt;
}
void
tx_conf_register_power(t, powert)
tx_chipset_tag_t t;
void *powert;
{
if (tx_chipset.tc_powert) {
panic("duplicate powert");
}
if (t != &tx_chipset) {
panic("bogus tx_chipset_tag");
}
tx_chipset.tc_powert = powert;
}
void
tx_conf_register_clock(t, clockt)
tx_chipset_tag_t t;
void *clockt;
{
if (tx_chipset.tc_clockt) {
panic("duplicate clockt");
}
if (t != &tx_chipset) {
panic("bogus tx_chipset_tag");
}
tx_chipset.tc_clockt = clockt;
}
void
tx_conf_register_sound(t, soundt)
tx_chipset_tag_t t;
void *soundt;
{
if (t != &tx_chipset) {
panic("bogus tx_chipset_tag");
}
tx_chipset.tc_soundt = soundt;
}
void
tx_conf_register_ioman(t, iomant)
tx_chipset_tag_t t;
void *iomant;
{
if (tx_chipset.tc_iomant) {
panic("duplicate iomant");
}
if (t != &tx_chipset) {
panic("bogus tx_chipset_tag");
}
tx_chipset.tc_iomant = iomant;
}
void
tx_conf_register_video(t, videot)
tx_chipset_tag_t t;
void *videot;
{
if (t != &tx_chipset) {
panic("bogus tx_chipset_tag");
}
tx_chipset.tc_videot = videot;
}
1999-11-20 22:56:31 +03:00
#ifdef TX39_PREFER_FUNCTION
tx_chipset_tag_t
tx_conf_get_tag()
{
return (tx_chipset_tag_t)&tx_chipset;
}
txreg_t
tx_conf_read(t, reg)
tx_chipset_tag_t t;
int reg;
{
return *((volatile txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg));
1999-11-20 22:56:31 +03:00
}
void
tx_conf_write(t, reg, val)
tx_chipset_tag_t t;
int reg;
txreg_t val;
{
*((volatile txreg_t*)(TX39_SYSADDR_CONFIG_REG_KSEG1 + reg)) = val;
1999-11-20 22:56:31 +03:00
}
#endif /* TX39_PREFER_FUNCTION */
int
__is_set_print(reg, mask, name)
u_int32_t reg;
int mask;
char *name;
{
const char onoff[2] = "_x";
int ret = reg & mask ? 1 : 0;
printf("%s[%c] ", name, onoff[ret]);
return ret;
1999-11-20 22:56:31 +03:00
}