cmu.c revision 1.1 1 /* $NetBSD: cmu.c,v 1.1 1999/09/16 12:23:31 takemura Exp $ */
2
3 /*-
4 * Copyright (c) 1999 SASAKI Takesi
5 * Copyright (c) 1999 PocketBSD Project. All rights reserved.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the PocketBSD project
19 * and its contributors.
20 * 4. Neither the name of the project nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 */
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40
41 #include <mips/cpuregs.h>
42
43 #include <machine/bus.h>
44
45 #include <hpcmips/vr/vr.h>
46 #include <hpcmips/vr/vripvar.h>
47
48 #include <hpcmips/vr/cmureg.h>
49
50 struct vrcmu_softc {
51 struct device sc_dev;
52 bus_space_tag_t sc_iot;
53 bus_space_handle_t sc_ioh;
54 };
55
56 int vrcmu_match __P((struct device *, struct cfdata *, void *));
57 void vrcmu_attach __P((struct device *, struct device *, void *));
58
59 int vrcmu_supply __P((vrcmu_chipset_tag_t, u_int16_t, int));
60
61 struct vrcmu_function_tag vrcmu_functions = {
62 vrcmu_supply
63 };
64
65 struct cfattach vrcmu_ca = {
66 sizeof(struct vrcmu_softc), vrcmu_match, vrcmu_attach
67 };
68
69 int
70 vrcmu_match(parent, cf, aux)
71 struct device *parent;
72 struct cfdata *cf;
73 void *aux;
74 {
75 return 2; /* 1st attach group of vrip */
76 }
77
78 void
79 vrcmu_attach(parent, self, aux)
80 struct device *parent;
81 struct device *self;
82 void *aux;
83 {
84 struct vrip_attach_args *va = aux;
85 struct vrcmu_softc *sc = (void*)self;
86
87 sc->sc_iot = va->va_iot;
88 if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
89 0 /* no flags */, &sc->sc_ioh)) {
90 printf("vrcmu_attach: can't map i/o space\n");
91 return;
92 }
93 vrip_cmu_function_register(va->va_vc, &vrcmu_functions, self);
94 printf ("\n");
95 }
96
97 /* For serial console */
98 void
99 __vrcmu_supply(mask, onoff)
100 u_int16_t mask;
101 int onoff;
102 {
103 u_int16_t reg;
104 u_int32_t addr;
105 addr = MIPS_PHYS_TO_KSEG1(VRIP_CMU_ADDR);
106 reg = *((volatile u_int16_t*)addr);
107 if (onoff)
108 reg |= mask;
109 else
110 reg &= ~mask;
111 *((volatile u_int16_t*)addr) = reg;
112 }
113
114
115 int
116 vrcmu_supply(cc, mask, onoff)
117 vrcmu_chipset_tag_t cc;
118 u_int16_t mask;
119 int onoff;
120 {
121 struct vrcmu_softc *sc = (void*)cc;
122 u_int16_t reg;
123
124 reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
125 #ifdef VRCMU_VERBOSE
126 printf("cmu register(enter):");
127 bitdisp16(reg);
128 #endif
129 if (onoff)
130 reg |= mask;
131 else
132 reg &= ~mask;
133 bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, reg);
134 #ifdef VRCMU_VERBOSE
135 printf("cmu register(exit) :");
136 bitdisp16(reg);
137 #endif
138 return 0;
139 }
140
141