bcu_vrip.c revision 1.1.1.1.2.4       1  1.1.1.1.2.4    bouyer /*	$NetBSD: bcu_vrip.c,v 1.1.1.1.2.4 2001/04/23 09:41:44 bouyer Exp $	*/
      2          1.1  takemura 
      3          1.1  takemura /*-
      4  1.1.1.1.2.3    bouyer  * Copyright (c) 1999-2001 SATO Kazumi. All rights reserved.
      5          1.1  takemura  * Copyright (c) 1999 PocketBSD Project. All rights reserved.
      6          1.1  takemura  *
      7          1.1  takemura  * Redistribution and use in source and binary forms, with or without
      8          1.1  takemura  * modification, are permitted provided that the following conditions
      9          1.1  takemura  * are met:
     10          1.1  takemura  * 1. Redistributions of source code must retain the above copyright
     11          1.1  takemura  *    notice, this list of conditions and the following disclaimer.
     12          1.1  takemura  * 2. Redistributions in binary form must reproduce the above copyright
     13          1.1  takemura  *    notice, this list of conditions and the following disclaimer in the
     14          1.1  takemura  *    documentation and/or other materials provided with the distribution.
     15          1.1  takemura  * 3. All advertising materials mentioning features or use of this software
     16          1.1  takemura  *    must display the following acknowledgement:
     17          1.1  takemura  *	This product includes software developed by the PocketBSD project
     18          1.1  takemura  *	and its contributors.
     19          1.1  takemura  * 4. Neither the name of the project nor the names of its contributors
     20          1.1  takemura  *    may be used to endorse or promote products derived from this software
     21          1.1  takemura  *    without specific prior written permission.
     22          1.1  takemura  *
     23          1.1  takemura  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24          1.1  takemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25          1.1  takemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26          1.1  takemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27          1.1  takemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28          1.1  takemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29          1.1  takemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30          1.1  takemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31          1.1  takemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32          1.1  takemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33          1.1  takemura  * SUCH DAMAGE.
     34          1.1  takemura  *
     35          1.1  takemura  */
     36          1.1  takemura 
     37          1.1  takemura #include <sys/param.h>
     38          1.1  takemura #include <sys/systm.h>
     39          1.1  takemura #include <sys/device.h>
     40          1.1  takemura #include <sys/reboot.h>
     41          1.1  takemura 
     42          1.1  takemura #include <machine/bus.h>
     43          1.1  takemura 
     44          1.1  takemura #include <mips/cpuregs.h>
     45          1.1  takemura 
     46  1.1.1.1.2.3    bouyer #include "opt_vr41xx.h"
     47          1.1  takemura #include <hpcmips/vr/vr.h>
     48  1.1.1.1.2.3    bouyer #include <hpcmips/vr/vrcpudef.h>
     49          1.1  takemura #include <hpcmips/vr/vripvar.h>
     50          1.1  takemura #include <hpcmips/vr/vripreg.h>
     51          1.1  takemura #include <hpcmips/vr/bcureg.h>
     52          1.1  takemura #include <hpcmips/vr/bcuvar.h>
     53          1.1  takemura 
     54  1.1.1.1.2.1    bouyer static int vrbcu_match __P((struct device *, struct cfdata *, void *));
     55  1.1.1.1.2.1    bouyer static void vrbcu_attach __P((struct device *, struct device *, void *));
     56  1.1.1.1.2.1    bouyer 
     57  1.1.1.1.2.1    bouyer static void vrbcu_write __P((struct vrbcu_softc *, int, unsigned short));
     58  1.1.1.1.2.1    bouyer static unsigned short vrbcu_read __P((struct vrbcu_softc *, int));
     59  1.1.1.1.2.1    bouyer 
     60  1.1.1.1.2.1    bouyer static void vrbcu_dump_regs __P((void));
     61          1.1  takemura 
     62  1.1.1.1.2.1    bouyer char	*vr_cpuname=NULL;
     63  1.1.1.1.2.1    bouyer int	vr_major=-1;
     64  1.1.1.1.2.1    bouyer int	vr_minor=-1;
     65  1.1.1.1.2.1    bouyer int	vr_cpuid=-1;
     66          1.1  takemura 
     67          1.1  takemura struct cfattach vrbcu_ca = {
     68  1.1.1.1.2.1    bouyer 	sizeof(struct vrbcu_softc), vrbcu_match, vrbcu_attach
     69          1.1  takemura };
     70          1.1  takemura 
     71  1.1.1.1.2.1    bouyer struct vrbcu_softc *the_bcu_sc = NULL;
     72  1.1.1.1.2.1    bouyer 
     73  1.1.1.1.2.1    bouyer static inline void
     74  1.1.1.1.2.1    bouyer vrbcu_write(sc, port, val)
     75  1.1.1.1.2.1    bouyer 	struct vrbcu_softc *sc;
     76  1.1.1.1.2.1    bouyer 	int port;
     77  1.1.1.1.2.1    bouyer 	unsigned short val;
     78  1.1.1.1.2.1    bouyer {
     79  1.1.1.1.2.1    bouyer 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
     80  1.1.1.1.2.1    bouyer }
     81  1.1.1.1.2.1    bouyer 
     82  1.1.1.1.2.1    bouyer static inline unsigned short
     83  1.1.1.1.2.1    bouyer vrbcu_read(sc, port)
     84  1.1.1.1.2.1    bouyer 	struct vrbcu_softc *sc;
     85  1.1.1.1.2.1    bouyer 	int port;
     86  1.1.1.1.2.1    bouyer {
     87  1.1.1.1.2.1    bouyer 	return bus_space_read_2(sc->sc_iot, sc->sc_ioh, port);
     88  1.1.1.1.2.1    bouyer }
     89  1.1.1.1.2.1    bouyer 
     90          1.1  takemura static int
     91  1.1.1.1.2.1    bouyer vrbcu_match(parent, cf, aux)
     92          1.1  takemura      struct device *parent;
     93          1.1  takemura      struct cfdata *cf;
     94          1.1  takemura      void *aux;
     95          1.1  takemura {
     96  1.1.1.1.2.1    bouyer 	return 2;
     97          1.1  takemura }
     98          1.1  takemura 
     99          1.1  takemura static void
    100  1.1.1.1.2.1    bouyer vrbcu_attach(parent, self, aux)
    101          1.1  takemura      struct device *parent;
    102          1.1  takemura      struct device *self;
    103          1.1  takemura      void *aux;
    104          1.1  takemura {
    105          1.1  takemura 	struct vrip_attach_args *va = aux;
    106  1.1.1.1.2.1    bouyer 	struct vrbcu_softc *sc = (struct vrbcu_softc *)self;
    107          1.1  takemura 
    108  1.1.1.1.2.1    bouyer 	sc->sc_iot = va->va_iot;
    109  1.1.1.1.2.1    bouyer 	bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
    110          1.1  takemura 		0, /* no flags */
    111  1.1.1.1.2.1    bouyer 		&sc->sc_ioh);
    112          1.1  takemura 
    113          1.1  takemura 	printf("\n");
    114  1.1.1.1.2.1    bouyer 	the_bcu_sc = sc;
    115  1.1.1.1.2.1    bouyer 	vrbcu_dump_regs();
    116  1.1.1.1.2.1    bouyer }
    117  1.1.1.1.2.1    bouyer 
    118  1.1.1.1.2.1    bouyer static void
    119  1.1.1.1.2.1    bouyer vrbcu_dump_regs()
    120  1.1.1.1.2.1    bouyer {
    121  1.1.1.1.2.1    bouyer 	struct vrbcu_softc *sc = the_bcu_sc;
    122  1.1.1.1.2.3    bouyer 	int cpuclock = 0, tclock = 0, vtclock = 0, cpuid;
    123  1.1.1.1.2.4    bouyer #if !defined(ONLY_VR4102)
    124  1.1.1.1.2.3    bouyer 	int spdreg;
    125  1.1.1.1.2.3    bouyer #endif
    126  1.1.1.1.2.3    bouyer #ifdef VRBCUDEBUG
    127  1.1.1.1.2.1    bouyer 	int reg;
    128  1.1.1.1.2.3    bouyer #endif /* VRBCUDEBUG */
    129  1.1.1.1.2.1    bouyer 
    130  1.1.1.1.2.3    bouyer 	cpuid = vrbcu_vrip_getcpuid();
    131  1.1.1.1.2.4    bouyer #if !defined(ONLY_VR4181) && !defined(ONLY_VR4102)
    132  1.1.1.1.2.3    bouyer 	if (cpuid != BCUREVID_FIXRID_4181
    133  1.1.1.1.2.3    bouyer 		&& cpuid <= BCUREVID_RID_4122
    134  1.1.1.1.2.3    bouyer 		&& cpuid >= BCUREVID_RID_4111) {
    135  1.1.1.1.2.3    bouyer 		spdreg = vrbcu_read(sc, BCUCLKSPEED_REG_W);
    136  1.1.1.1.2.1    bouyer #ifdef VRBCUDEBUG
    137  1.1.1.1.2.3    bouyer 		printf("vrbcu: CLKSPEED %x: \n",  spdreg);
    138  1.1.1.1.2.3    bouyer #endif /* VRBCUDEBUG */
    139  1.1.1.1.2.3    bouyer 	}
    140  1.1.1.1.2.3    bouyer #endif
    141  1.1.1.1.2.4    bouyer #if defined VR4181
    142  1.1.1.1.2.4    bouyer 	if (cpuid == BCUREVID_FIXRID_4181){
    143  1.1.1.1.2.4    bouyer 		spdreg = vrbcu_read(sc, BCU81CLKSPEED_REG_W);
    144  1.1.1.1.2.4    bouyer #ifdef VRBCUDEBUG
    145  1.1.1.1.2.4    bouyer 		printf("vrbcu: CLKSPEED %x: \n",  spdreg);
    146  1.1.1.1.2.4    bouyer #endif /* VRBCUDEBUG */
    147  1.1.1.1.2.4    bouyer 	}
    148  1.1.1.1.2.4    bouyer #endif
    149  1.1.1.1.2.3    bouyer 
    150  1.1.1.1.2.1    bouyer 	cpuclock = vrbcu_vrip_getcpuclock();
    151  1.1.1.1.2.1    bouyer 
    152  1.1.1.1.2.1    bouyer 	switch (cpuid) {
    153  1.1.1.1.2.4    bouyer #if defined VR4181
    154  1.1.1.1.2.3    bouyer 	case BCUREVID_FIXRID_4181:
    155  1.1.1.1.2.4    bouyer 		switch ((spdreg&BCU81CLKSPEED_DIVTMASK)>>BCU81CLKSPEED_DIVTSHFT){
    156  1.1.1.1.2.4    bouyer 		case BCU81CLKSPEED_DIVT1:
    157  1.1.1.1.2.4    bouyer 			vtclock = tclock = cpuclock;
    158  1.1.1.1.2.4    bouyer 			break;
    159  1.1.1.1.2.4    bouyer 		case BCU81CLKSPEED_DIVT2:
    160  1.1.1.1.2.4    bouyer 			vtclock = tclock = cpuclock/2;
    161  1.1.1.1.2.4    bouyer 			break;
    162  1.1.1.1.2.4    bouyer 		case BCU81CLKSPEED_DIVT3:
    163  1.1.1.1.2.4    bouyer 			vtclock = tclock = cpuclock/3;
    164  1.1.1.1.2.4    bouyer 			break;
    165  1.1.1.1.2.4    bouyer 		case BCU81CLKSPEED_DIVT4:
    166  1.1.1.1.2.4    bouyer 			vtclock = tclock = cpuclock/4;
    167  1.1.1.1.2.4    bouyer 			break;
    168  1.1.1.1.2.4    bouyer 		default:
    169  1.1.1.1.2.4    bouyer 			vtclock = tclock = 0;
    170  1.1.1.1.2.4    bouyer 		}
    171  1.1.1.1.2.4    bouyer 		break;
    172  1.1.1.1.2.4    bouyer #endif /* VR4181 */
    173  1.1.1.1.2.1    bouyer 	case BCUREVID_RID_4101:
    174  1.1.1.1.2.1    bouyer 	case BCUREVID_RID_4102:
    175  1.1.1.1.2.1    bouyer 		vtclock = tclock = cpuclock/2;
    176  1.1.1.1.2.1    bouyer 		break;
    177  1.1.1.1.2.3    bouyer #if defined VR4111
    178  1.1.1.1.2.1    bouyer 	case BCUREVID_RID_4111:
    179  1.1.1.1.2.3    bouyer 		if ((spdreg&BCUCLKSPEED_DIVT2B) == 0)
    180  1.1.1.1.2.1    bouyer 			vtclock = tclock = cpuclock/2;
    181  1.1.1.1.2.3    bouyer 		else if ((spdreg&BCUCLKSPEED_DIVT3B) == 0)
    182  1.1.1.1.2.1    bouyer 			vtclock = tclock = cpuclock/3;
    183  1.1.1.1.2.3    bouyer 		else if ((spdreg&BCUCLKSPEED_DIVT4B) == 0)
    184  1.1.1.1.2.1    bouyer 			vtclock = tclock = cpuclock/4;
    185  1.1.1.1.2.1    bouyer 		else
    186  1.1.1.1.2.1    bouyer 			vtclock = tclock = 0; /* XXX */
    187  1.1.1.1.2.1    bouyer 		break;
    188  1.1.1.1.2.3    bouyer #endif /* VR4111 */
    189  1.1.1.1.2.3    bouyer #if defined VR4121
    190  1.1.1.1.2.1    bouyer 	case BCUREVID_RID_4121:
    191  1.1.1.1.2.3    bouyer 		{
    192  1.1.1.1.2.3    bouyer 			int vt;
    193  1.1.1.1.2.3    bouyer 			tclock = cpuclock / ((spdreg&BCUCLKSPEED_DIVTMASK)>>BCUCLKSPEED_DIVTSHFT);
    194  1.1.1.1.2.3    bouyer 			vt = ((spdreg&BCUCLKSPEED_DIVVTMASK)>>BCUCLKSPEED_DIVVTSHFT);
    195  1.1.1.1.2.1    bouyer 			if (vt == 0)
    196  1.1.1.1.2.1    bouyer 				vtclock = 0; /* XXX */
    197  1.1.1.1.2.1    bouyer 			else if (vt < 0x9)
    198  1.1.1.1.2.1    bouyer 				vtclock = cpuclock / vt;
    199  1.1.1.1.2.1    bouyer 			else
    200  1.1.1.1.2.1    bouyer 				vtclock = cpuclock / ((vt - 8)*2+1) * 2;
    201  1.1.1.1.2.3    bouyer 		}
    202  1.1.1.1.2.1    bouyer 		break;
    203  1.1.1.1.2.3    bouyer #endif /* VR4121 */
    204  1.1.1.1.2.1    bouyer 	default:
    205  1.1.1.1.2.1    bouyer 		break;
    206  1.1.1.1.2.1    bouyer 	}
    207  1.1.1.1.2.3    bouyer 	if (tclock)
    208  1.1.1.1.2.3    bouyer 		printf("%s: cpu %d.%03dMHz, bus %d.%03dMHz, ram %d.%03dMHz\n",
    209  1.1.1.1.2.3    bouyer 			sc->sc_dev.dv_xname,
    210  1.1.1.1.2.3    bouyer 			cpuclock/1000000, (cpuclock%1000000)/1000,
    211  1.1.1.1.2.3    bouyer 			tclock/1000000, (tclock%1000000)/1000,
    212  1.1.1.1.2.3    bouyer 			vtclock/1000000, (vtclock%1000000)/1000);
    213  1.1.1.1.2.3    bouyer 	else {
    214  1.1.1.1.2.3    bouyer 		printf("%s: cpu %d.%03dMHz\n",
    215  1.1.1.1.2.3    bouyer 			sc->sc_dev.dv_xname,
    216  1.1.1.1.2.3    bouyer 			cpuclock/1000000, (cpuclock%1000000)/1000);
    217  1.1.1.1.2.3    bouyer 		printf("%s: UNKNOWN BUS CLOCK SPEED: CPU is UNKNOWN or NOT CONFIGURED\n",
    218  1.1.1.1.2.3    bouyer 			sc->sc_dev.dv_xname);
    219  1.1.1.1.2.3    bouyer 	}
    220  1.1.1.1.2.1    bouyer #ifdef VRBCUDEBUG
    221  1.1.1.1.2.3    bouyer 	reg = vrbcu_read(sc, BCUCNT1_REG_W);
    222  1.1.1.1.2.3    bouyer 	printf("vrbcu: CNT1 %x: ",  reg);
    223  1.1.1.1.2.3    bouyer 	bitdisp16(reg);
    224  1.1.1.1.2.3    bouyer #if !defined(ONLY_VR4181)
    225  1.1.1.1.2.3    bouyer 	if (cpuid != BCUREVID_FIXRID_4181
    226  1.1.1.1.2.3    bouyer 		&& cpuid <= BCUREVID_RID_4121
    227  1.1.1.1.2.3    bouyer 		&& cpuid >= BCUREVID_RID_4102) {
    228  1.1.1.1.2.3    bouyer 		reg = vrbcu_read(sc, BCUCNT2_REG_W);
    229  1.1.1.1.2.3    bouyer 		printf("vrbcu: CNT2 %x: ",  reg);
    230  1.1.1.1.2.3    bouyer 		bitdisp16(reg);
    231  1.1.1.1.2.3    bouyer 	}
    232  1.1.1.1.2.3    bouyer #endif /* !defined ONLY_VR4181 */
    233  1.1.1.1.2.3    bouyer #if !defined(ONLY_VR4181) || !defined(ONLY_VR4122)
    234  1.1.1.1.2.3    bouyer 	if (cpuid != BCUREVID_FIXRID_4181
    235  1.1.1.1.2.3    bouyer 		&& cpuid <= BCUREVID_RID_4121
    236  1.1.1.1.2.3    bouyer 		&& cpuid >= BCUREVID_RID_4102) {
    237  1.1.1.1.2.3    bouyer 		reg = vrbcu_read(sc, BCUSPEED_REG_W);
    238  1.1.1.1.2.3    bouyer 		printf("vrbcu: SPEED %x: ",  reg);
    239  1.1.1.1.2.3    bouyer 		bitdisp16(reg);
    240  1.1.1.1.2.3    bouyer 		reg = vrbcu_read(sc, BCUERRST_REG_W);
    241  1.1.1.1.2.3    bouyer 		printf("vrbcu: ERRST %x: ",  reg);
    242  1.1.1.1.2.3    bouyer 		bitdisp16(reg);
    243  1.1.1.1.2.3    bouyer 		reg = vrbcu_read(sc, BCURFCNT_REG_W);
    244  1.1.1.1.2.3    bouyer 		printf("vrbcu: RFCNT %x\n",  reg);
    245  1.1.1.1.2.3    bouyer 		reg = vrbcu_read(sc, BCUREFCOUNT_REG_W);
    246  1.1.1.1.2.3    bouyer 		printf("vrbcu: RFCOUNT %x\n",  reg);
    247  1.1.1.1.2.3    bouyer 	}
    248  1.1.1.1.2.3    bouyer #endif /* !defined(ONLY_VR4181) || !defined(ONLY_VR4122) */
    249  1.1.1.1.2.3    bouyer #if !defined(ONLY_VR4181)
    250  1.1.1.1.2.3    bouyer 	if (cpuid != BCUREVID_FIXRID_4181
    251  1.1.1.1.2.3    bouyer 		&& cpuid <= BCUREVID_RID_4122
    252  1.1.1.1.2.3    bouyer 		&& cpuid >= BCUREVID_RID_4111)
    253  1.1.1.1.2.3    bouyer 	{
    254  1.1.1.1.2.1    bouyer 		reg = vrbcu_read(sc, BCUCNT3_REG_W);
    255  1.1.1.1.2.1    bouyer 		printf("vrbcu: CNT3 %x: ",  reg);
    256  1.1.1.1.2.1    bouyer 		bitdisp16(reg);
    257  1.1.1.1.2.1    bouyer 	}
    258  1.1.1.1.2.3    bouyer #endif /* !defined ONLY_VR4181 */
    259  1.1.1.1.2.1    bouyer #endif /* VRBCUDEBUG */
    260  1.1.1.1.2.1    bouyer 
    261          1.1  takemura }
    262          1.1  takemura 
    263          1.1  takemura static char *cpuname[] = {
    264  1.1.1.1.2.3    bouyer 	"VR4101",	/* 0 */
    265  1.1.1.1.2.3    bouyer 	"VR4102",	/* 1 */
    266  1.1.1.1.2.3    bouyer 	"VR4111",	/* 2 */
    267  1.1.1.1.2.3    bouyer 	"VR4121",	/* 3 */
    268  1.1.1.1.2.3    bouyer 	"VR4122",	/* 4 */
    269  1.1.1.1.2.3    bouyer 	"UNKNOWN",
    270  1.1.1.1.2.3    bouyer 	"UNKNOWN",
    271  1.1.1.1.2.3    bouyer 	"UNKNOWN",
    272          1.1  takemura 	"UNKNOWN",
    273          1.1  takemura 	"UNKNOWN",
    274          1.1  takemura 	"UNKNOWN",
    275  1.1.1.1.2.3    bouyer 	"UNKNOWN",
    276  1.1.1.1.2.3    bouyer 	"UNKNOWN",
    277  1.1.1.1.2.3    bouyer 	"UNKNOWN",
    278  1.1.1.1.2.3    bouyer 	"UNKNOWN",
    279  1.1.1.1.2.3    bouyer 	"UNKNOWN",
    280  1.1.1.1.2.3    bouyer 	"VR4181",	/* 0x10 + 0 */
    281  1.1.1.1.2.3    bouyer };
    282          1.1  takemura 
    283  1.1.1.1.2.1    bouyer int
    284  1.1.1.1.2.1    bouyer vrbcu_vrip_getcpuid(void)
    285  1.1.1.1.2.1    bouyer {
    286  1.1.1.1.2.1    bouyer 	volatile u_int16_t *revreg;
    287  1.1.1.1.2.1    bouyer 
    288  1.1.1.1.2.1    bouyer 	if (vr_cpuid != -1)
    289  1.1.1.1.2.1    bouyer 		return vr_cpuid;
    290  1.1.1.1.2.1    bouyer 
    291  1.1.1.1.2.1    bouyer 	if (vr_cpuid == -1) {
    292  1.1.1.1.2.4    bouyer 		if (VRIP_BCU_ADDR == VR4181_BCU_ADDR)
    293  1.1.1.1.2.4    bouyer 			revreg = (u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCU81REVID_REG_W));
    294  1.1.1.1.2.4    bouyer 		else
    295  1.1.1.1.2.4    bouyer 			revreg = (u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCUREVID_REG_W));
    296  1.1.1.1.2.1    bouyer 
    297  1.1.1.1.2.1    bouyer 		vr_cpuid = *revreg;
    298  1.1.1.1.2.1    bouyer 		vr_cpuid = (vr_cpuid&BCUREVID_RIDMASK)>>BCUREVID_RIDSHFT;
    299  1.1.1.1.2.4    bouyer 		if (VRIP_BCU_ADDR == VR4181_BCU_ADDR
    300  1.1.1.1.2.4    bouyer 		    && vr_cpuid == BCUREVID_RID_4181) /* conflict vr4101 */
    301  1.1.1.1.2.3    bouyer 			vr_cpuid = BCUREVID_FIXRID_4181;
    302  1.1.1.1.2.1    bouyer 	}
    303  1.1.1.1.2.1    bouyer 	return vr_cpuid;
    304  1.1.1.1.2.1    bouyer }
    305  1.1.1.1.2.1    bouyer 
    306          1.1  takemura char *
    307          1.1  takemura vrbcu_vrip_getcpuname(void)
    308          1.1  takemura {
    309  1.1.1.1.2.1    bouyer 	int cpuid;
    310          1.1  takemura 
    311  1.1.1.1.2.1    bouyer 	if (vr_cpuname != NULL)
    312  1.1.1.1.2.1    bouyer 		return vr_cpuname;
    313          1.1  takemura 
    314  1.1.1.1.2.1    bouyer 	cpuid = vrbcu_vrip_getcpuid();
    315  1.1.1.1.2.1    bouyer 	vr_cpuname = cpuname[cpuid];
    316  1.1.1.1.2.1    bouyer 	return vr_cpuname;
    317          1.1  takemura }
    318          1.1  takemura 
    319  1.1.1.1.2.1    bouyer 
    320          1.1  takemura int
    321          1.1  takemura vrbcu_vrip_getcpumajor(void)
    322          1.1  takemura {
    323          1.1  takemura 	volatile u_int16_t *revreg;
    324  1.1.1.1.2.1    bouyer 
    325  1.1.1.1.2.1    bouyer 	if (vr_major != -1)
    326  1.1.1.1.2.1    bouyer 		return vr_major;
    327          1.1  takemura 
    328          1.1  takemura 	revreg = (u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCUREVID_REG_W));
    329          1.1  takemura 
    330  1.1.1.1.2.1    bouyer 	vr_major = *revreg;
    331  1.1.1.1.2.1    bouyer 	vr_major = (vr_major&BCUREVID_MJREVMASK)>>BCUREVID_MJREVSHFT;
    332  1.1.1.1.2.1    bouyer 	return vr_major;
    333          1.1  takemura }
    334          1.1  takemura 
    335          1.1  takemura int
    336          1.1  takemura vrbcu_vrip_getcpuminor(void)
    337          1.1  takemura {
    338          1.1  takemura 	volatile u_int16_t *revreg;
    339  1.1.1.1.2.1    bouyer 
    340  1.1.1.1.2.1    bouyer 	if (vr_minor != -1)
    341  1.1.1.1.2.1    bouyer 		return vr_minor;
    342          1.1  takemura 
    343          1.1  takemura 	revreg = (u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCUREVID_REG_W));
    344          1.1  takemura 
    345  1.1.1.1.2.1    bouyer 	vr_minor = *revreg;
    346  1.1.1.1.2.1    bouyer 	vr_minor = (vr_minor&BCUREVID_MNREVMASK)>>BCUREVID_MNREVSHFT;
    347  1.1.1.1.2.1    bouyer 	return vr_minor;
    348          1.1  takemura }
    349  1.1.1.1.2.1    bouyer 
    350  1.1.1.1.2.1    bouyer #define CLKX	18432000	/* CLKX1,CLKX2: 18.432MHz */
    351  1.1.1.1.2.1    bouyer #define MHZ	1000000
    352  1.1.1.1.2.1    bouyer 
    353  1.1.1.1.2.1    bouyer int
    354  1.1.1.1.2.1    bouyer vrbcu_vrip_getcpuclock(void)
    355  1.1.1.1.2.1    bouyer {
    356  1.1.1.1.2.1    bouyer 	u_int16_t clksp;
    357  1.1.1.1.2.1    bouyer 	int cpuid, cpuclock;
    358  1.1.1.1.2.1    bouyer 
    359  1.1.1.1.2.1    bouyer 	cpuid = vrbcu_vrip_getcpuid();
    360  1.1.1.1.2.3    bouyer 	if (cpuid != BCUREVID_FIXRID_4181 && cpuid >= BCUREVID_RID_4111) {
    361  1.1.1.1.2.3    bouyer 		clksp = *(u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCUCLKSPEED_REG_W)) & BCUCLKSPEED_CLKSPMASK;
    362  1.1.1.1.2.4    bouyer 	} else if (cpuid == BCUREVID_FIXRID_4181) {
    363  1.1.1.1.2.4    bouyer 		clksp = *(u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCU81CLKSPEED_REG_W)) & BCUCLKSPEED_CLKSPMASK;
    364  1.1.1.1.2.3    bouyer 	}
    365  1.1.1.1.2.1    bouyer 
    366  1.1.1.1.2.1    bouyer 	switch (cpuid) {
    367  1.1.1.1.2.3    bouyer 	case BCUREVID_FIXRID_4181:
    368  1.1.1.1.2.4    bouyer 		cpuclock = CLKX / clksp * 64;
    369  1.1.1.1.2.3    bouyer 		/* branch delay is 1 clock; 2 clock/loop */
    370  1.1.1.1.2.3    bouyer 		cpuspeed = (cpuclock / 2 + MHZ / 2) / MHZ;
    371  1.1.1.1.2.3    bouyer 		break;
    372  1.1.1.1.2.1    bouyer 	case BCUREVID_RID_4101:
    373  1.1.1.1.2.1    bouyer 		/* assume 33MHz */
    374  1.1.1.1.2.1    bouyer 		cpuclock = 33000000;
    375  1.1.1.1.2.1    bouyer 		/* branch delay is 1 clock; 2 clock/loop */
    376  1.1.1.1.2.1    bouyer 		cpuspeed = (cpuclock / 2 + MHZ / 2) / MHZ;
    377  1.1.1.1.2.1    bouyer 		break;
    378  1.1.1.1.2.1    bouyer 	case BCUREVID_RID_4102:
    379  1.1.1.1.2.1    bouyer 		cpuclock = CLKX / clksp * 32;
    380  1.1.1.1.2.1    bouyer 		/* branch delay is 1 clock; 2 clock/loop */
    381  1.1.1.1.2.1    bouyer 		cpuspeed = (cpuclock / 2 + MHZ / 2) / MHZ;
    382  1.1.1.1.2.1    bouyer 		break;
    383  1.1.1.1.2.1    bouyer 	case BCUREVID_RID_4111:
    384  1.1.1.1.2.1    bouyer 		cpuclock = CLKX / clksp * 64;
    385  1.1.1.1.2.1    bouyer 		/* branch delay is 1 clock; 2 clock/loop */
    386  1.1.1.1.2.1    bouyer 		cpuspeed = (cpuclock / 2 + MHZ / 2) / MHZ;
    387  1.1.1.1.2.1    bouyer 		break;
    388  1.1.1.1.2.1    bouyer 	case BCUREVID_RID_4121:
    389  1.1.1.1.2.1    bouyer 		cpuclock = CLKX / clksp * 64;
    390  1.1.1.1.2.1    bouyer 		/* branch delay is 2 clock; 3 clock/loop */
    391  1.1.1.1.2.1    bouyer 		cpuspeed = (cpuclock / 3 + MHZ / 2) / MHZ;
    392  1.1.1.1.2.1    bouyer 		break;
    393  1.1.1.1.2.1    bouyer 	default:
    394  1.1.1.1.2.1    bouyer 		panic("unknown CPU type %d\n", cpuid);
    395  1.1.1.1.2.1    bouyer 		break;
    396  1.1.1.1.2.1    bouyer 	}
    397  1.1.1.1.2.1    bouyer 	return cpuclock;
    398  1.1.1.1.2.1    bouyer }
    399