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