cmu.c revision 1.3 1 /* $NetBSD: cmu.c,v 1.3 2001/04/18 10:48:58 sato Exp $ */
2
3 /*-
4 * Copyright (c) 1999 SASAKI Takesi
5 * Copyright (c) 1999,2000 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 "opt_vr41xx.h"
46 #include <hpcmips/vr/vr.h>
47 #include <hpcmips/vr/vrcpudef.h>
48 #include <hpcmips/vr/vripreg.h>
49 #include <hpcmips/vr/vripvar.h>
50
51 #include <hpcmips/vr/cmureg.h>
52
53 #include <machine/config_hook.h>
54
55 struct vrcmu_softc {
56 struct device sc_dev;
57 bus_space_tag_t sc_iot;
58 bus_space_handle_t sc_ioh;
59 config_hook_tag sc_hardpower;
60 int sc_save;
61 };
62
63 int vrcmu_match __P((struct device *, struct cfdata *, void *));
64 void vrcmu_attach __P((struct device *, struct device *, void *));
65
66 int vrcmu_supply __P((vrcmu_chipset_tag_t, u_int16_t, int));
67
68 int vrcmu_hardpower __P((void *, int, long, void *));
69
70 struct vrcmu_function_tag vrcmu_functions = {
71 vrcmu_supply
72 };
73
74 struct cfattach vrcmu_ca = {
75 sizeof(struct vrcmu_softc), vrcmu_match, vrcmu_attach
76 };
77
78 int
79 vrcmu_match(parent, cf, aux)
80 struct device *parent;
81 struct cfdata *cf;
82 void *aux;
83 {
84 return 2; /* 1st attach group of vrip */
85 }
86
87 void
88 vrcmu_attach(parent, self, aux)
89 struct device *parent;
90 struct device *self;
91 void *aux;
92 {
93 struct vrip_attach_args *va = aux;
94 struct vrcmu_softc *sc = (void*)self;
95
96 sc->sc_iot = va->va_iot;
97 if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
98 0 /* no flags */, &sc->sc_ioh)) {
99 printf("vrcmu_attach: can't map i/o space\n");
100 return;
101 }
102 vrip_cmu_function_register(va->va_vc, &vrcmu_functions, self);
103 printf ("\n");
104 sc->sc_hardpower = config_hook(CONFIG_HOOK_PMEVENT,
105 CONFIG_HOOK_PMEVENT_HARDPOWER,
106 CONFIG_HOOK_SHARE,
107 vrcmu_hardpower, sc);
108
109 }
110 /* For serial console */
111 void
112 __vrcmu_supply(mask, onoff)
113 u_int16_t mask;
114 int onoff;
115 {
116 u_int16_t reg;
117 u_int32_t addr;
118 addr = MIPS_PHYS_TO_KSEG1(VRIP_CMU_ADDR);
119 reg = *((volatile u_int16_t*)addr);
120 if (onoff)
121 reg |= mask;
122 else
123 reg &= ~mask;
124 *((volatile u_int16_t*)addr) = reg;
125 }
126
127
128 int
129 vrcmu_supply(cc, mask, onoff)
130 vrcmu_chipset_tag_t cc;
131 u_int16_t mask;
132 int onoff;
133 {
134 struct vrcmu_softc *sc = (void*)cc;
135 u_int16_t reg;
136
137 reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
138 #ifdef VRCMU_VERBOSE
139 printf("cmu register(enter):");
140 bitdisp16(reg);
141 #endif
142 if (onoff)
143 reg |= mask;
144 else
145 reg &= ~mask;
146 bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, reg);
147 #ifdef VRCMU_VERBOSE
148 printf("cmu register(exit) :");
149 bitdisp16(reg);
150 #endif
151 return 0;
152 }
153
154 int
155 vrcmu_hardpower(ctx, type, id, msg)
156 void *ctx;
157 int type;
158 long id;
159 void *msg;
160 {
161 struct vrcmu_softc *sc = ctx;
162 int why =(int)msg;
163
164 switch (why) {
165 case PWR_STANDBY:
166 case PWR_SUSPEND:
167 sc->sc_save = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
168 bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, 0);
169 break;
170 case PWR_RESUME:
171 bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, sc->sc_save);
172 break;
173 }
174 return (0);
175 }
176