bcu_vrip.c revision 1.2 1 1.2 sato /* $NetBSD: bcu_vrip.c,v 1.2 1999/12/09 02:14:00 sato Exp $ */
2 1.1 takemura
3 1.1 takemura /*-
4 1.1 takemura * Copyright (c) 1999 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 takemura #include <hpcmips/vr/vr.h>
47 1.1 takemura #include <hpcmips/vr/vripvar.h>
48 1.1 takemura #include <hpcmips/vr/vripreg.h>
49 1.1 takemura #include <hpcmips/vr/bcureg.h>
50 1.1 takemura #include <hpcmips/vr/bcuvar.h>
51 1.1 takemura
52 1.1 takemura struct vrbcu_vrip_softc {
53 1.1 takemura struct vrbcu_softc sc_vrbcu;
54 1.1 takemura };
55 1.1 takemura
56 1.1 takemura /* Definition of the mainbus driver. */
57 1.1 takemura static int vrbcu_vrip_match __P((struct device *,
58 1.1 takemura struct cfdata *, void *));
59 1.1 takemura static void vrbcu_vrip_attach __P((struct device *,
60 1.1 takemura
61 1.1 takemura struct device *, void*));
62 1.2 sato
63 1.2 sato char *vr_cpuname=NULL;
64 1.2 sato int vr_major=-1;
65 1.2 sato int vr_minor=-1;
66 1.2 sato int vr_cpuid=-1;
67 1.1 takemura
68 1.1 takemura struct cfattach vrbcu_ca = {
69 1.1 takemura sizeof(struct vrbcu_vrip_softc), vrbcu_vrip_match, vrbcu_vrip_attach
70 1.1 takemura };
71 1.1 takemura
72 1.1 takemura static int
73 1.1 takemura vrbcu_vrip_match(parent, cf, aux)
74 1.1 takemura struct device *parent;
75 1.1 takemura struct cfdata *cf;
76 1.1 takemura void *aux;
77 1.1 takemura {
78 1.2 sato return 2;
79 1.1 takemura }
80 1.1 takemura
81 1.1 takemura static void
82 1.1 takemura vrbcu_vrip_attach(parent, self, aux)
83 1.1 takemura struct device *parent;
84 1.1 takemura struct device *self;
85 1.1 takemura void *aux;
86 1.1 takemura {
87 1.1 takemura struct vrip_attach_args *va = aux;
88 1.1 takemura struct vrbcu_vrip_softc *sc = (struct vrbcu_vrip_softc *)self;
89 1.1 takemura
90 1.1 takemura sc->sc_vrbcu.sc_iot = va->va_iot;
91 1.1 takemura bus_space_map(sc->sc_vrbcu.sc_iot, va->va_addr, va->va_size,
92 1.1 takemura 0, /* no flags */
93 1.1 takemura &sc->sc_vrbcu.sc_ioh);
94 1.1 takemura
95 1.1 takemura printf("\n");
96 1.1 takemura }
97 1.1 takemura
98 1.1 takemura static char *cpuname[] = {
99 1.1 takemura "VR4101",
100 1.1 takemura "VR4102",
101 1.1 takemura "VR4111",
102 1.1 takemura "VR4121",
103 1.1 takemura "UNKNOWN",
104 1.1 takemura "UNKNOWN",
105 1.1 takemura "UNKNOWN",
106 1.1 takemura "UNKNOWN" };
107 1.1 takemura
108 1.2 sato int
109 1.2 sato vrbcu_vrip_getcpuid(void)
110 1.2 sato {
111 1.2 sato volatile u_int16_t *revreg;
112 1.2 sato
113 1.2 sato if (vr_cpuid != -1)
114 1.2 sato return vr_cpuid;
115 1.2 sato
116 1.2 sato if (vr_cpuid == -1) {
117 1.2 sato revreg = (u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCUREVID_REG_W));
118 1.2 sato
119 1.2 sato vr_cpuid = *revreg;
120 1.2 sato vr_cpuid = (vr_cpuid&BCUREVID_RIDMASK)>>BCUREVID_RIDSHFT;
121 1.2 sato }
122 1.2 sato return vr_cpuid;
123 1.2 sato }
124 1.2 sato
125 1.1 takemura char *
126 1.1 takemura vrbcu_vrip_getcpuname(void)
127 1.1 takemura {
128 1.2 sato int cpuid;
129 1.1 takemura
130 1.2 sato if (vr_cpuname != NULL)
131 1.2 sato return vr_cpuname;
132 1.1 takemura
133 1.2 sato cpuid = vrbcu_vrip_getcpuid();
134 1.2 sato vr_cpuname = cpuname[cpuid];
135 1.2 sato return vr_cpuname;
136 1.1 takemura }
137 1.1 takemura
138 1.2 sato
139 1.1 takemura int
140 1.1 takemura vrbcu_vrip_getcpumajor(void)
141 1.1 takemura {
142 1.1 takemura volatile u_int16_t *revreg;
143 1.2 sato
144 1.2 sato if (vr_major != -1)
145 1.2 sato return vr_major;
146 1.1 takemura
147 1.1 takemura revreg = (u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCUREVID_REG_W));
148 1.1 takemura
149 1.2 sato vr_major = *revreg;
150 1.2 sato vr_major = (vr_major&BCUREVID_MJREVMASK)>>BCUREVID_MJREVSHFT;
151 1.2 sato return vr_major;
152 1.1 takemura }
153 1.1 takemura
154 1.1 takemura int
155 1.1 takemura vrbcu_vrip_getcpuminor(void)
156 1.1 takemura {
157 1.1 takemura volatile u_int16_t *revreg;
158 1.2 sato
159 1.2 sato if (vr_minor != -1)
160 1.2 sato return vr_minor;
161 1.1 takemura
162 1.1 takemura revreg = (u_int16_t *)MIPS_PHYS_TO_KSEG1((VRIP_BCU_ADDR+BCUREVID_REG_W));
163 1.1 takemura
164 1.2 sato vr_minor = *revreg;
165 1.2 sato vr_minor = (vr_minor&BCUREVID_MNREVMASK)>>BCUREVID_MNREVSHFT;
166 1.2 sato return vr_minor;
167 1.1 takemura }
168