Home | History | Annotate | Line # | Download | only in vr
cmu.c revision 1.6
      1 /*	$NetBSD: cmu.c,v 1.6 2002/01/26 10:50:44 takemura 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 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/device.h>
     41 
     42 #include <mips/cpuregs.h>
     43 
     44 #include <machine/bus.h>
     45 #include <machine/bitdisp.h>
     46 
     47 #include "opt_vr41xx.h"
     48 #include <hpcmips/vr/vr.h>
     49 #include <hpcmips/vr/vrcpudef.h>
     50 #include <hpcmips/vr/vripreg.h>
     51 #include <hpcmips/vr/vripvar.h>
     52 
     53 #include <hpcmips/vr/cmureg.h>
     54 
     55 #include <machine/config_hook.h>
     56 
     57 struct vrcmu_softc {
     58 	struct device sc_dev;
     59 	bus_space_tag_t sc_iot;
     60 	bus_space_handle_t sc_ioh;
     61 	config_hook_tag sc_hardpower;
     62 	int sc_save;
     63 };
     64 
     65 int	vrcmu_match(struct device *, struct cfdata *, void *);
     66 void	vrcmu_attach(struct device *, struct device *, void *);
     67 int	vrcmu_supply(vrcmu_chipset_tag_t, u_int16_t, int);
     68 int	vrcmu_hardpower(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(struct device *parent, struct cfdata *cf, void *aux)
     80 {
     81 
     82 	return (2);		/* 1st attach group of vrip */
     83 }
     84 
     85 void
     86 vrcmu_attach(struct device *parent, struct device *self, void *aux)
     87 {
     88 	struct vrip_attach_args *va = aux;
     89 	struct vrcmu_softc *sc = (void *)self;
     90 
     91 	sc->sc_iot = va->va_iot;
     92 	if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
     93 	    0 /* no flags */, &sc->sc_ioh)) {
     94 		printf(": can't map i/o space\n");
     95 		return;
     96 	}
     97 	printf ("\n");
     98 
     99 	vrip_cmu_function_register(va->va_vc, &vrcmu_functions, self);
    100 	sc->sc_hardpower = config_hook(CONFIG_HOOK_PMEVENT,
    101 	    CONFIG_HOOK_PMEVENT_HARDPOWER,
    102 	    CONFIG_HOOK_SHARE,
    103 	    vrcmu_hardpower, sc);
    104 }
    105 
    106 /* For serial console */
    107 void
    108 __vrcmu_supply(u_int16_t mask, int onoff)
    109 {
    110 	u_int16_t reg;
    111 	u_int32_t addr;
    112 
    113 	addr = MIPS_PHYS_TO_KSEG1(VRIP_CMU_ADDR);
    114 	reg = *((volatile u_int16_t *)addr);
    115 	if (onoff)
    116 		reg |= mask;
    117 	else
    118 		reg &= ~mask;
    119 	*((volatile u_int16_t *)addr) = reg;
    120 }
    121 
    122 int
    123 vrcmu_supply(vrcmu_chipset_tag_t cc, u_int16_t mask, int onoff)
    124 {
    125 	struct vrcmu_softc *sc = (void *)cc;
    126 	u_int16_t reg;
    127 
    128 	reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
    129 #ifdef VRCMU_VERBOSE
    130 	printf("cmu register(enter):");
    131 	bitdisp16(reg);
    132 #endif
    133 	if (onoff)
    134 		reg |= mask;
    135 	else
    136 		reg &= ~mask;
    137 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, reg);
    138 #ifdef VRCMU_VERBOSE
    139 	printf("cmu register(exit) :");
    140 	bitdisp16(reg);
    141 #endif
    142 	return (0);
    143 }
    144 
    145 int
    146 vrcmu_hardpower(void *ctx, int type, long id, void *msg)
    147 {
    148 	struct vrcmu_softc *sc = ctx;
    149 	int why = (int)msg;
    150 
    151 	switch (why) {
    152 	case PWR_STANDBY:
    153 	case PWR_SUSPEND:
    154 		sc->sc_save = bus_space_read_2(sc->sc_iot, sc->sc_ioh, 0);
    155 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, 0);
    156 		break;
    157 	case PWR_RESUME:
    158 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, 0, sc->sc_save);
    159 		break;
    160 	}
    161 	return (0);
    162 }
    163