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