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