Home | History | Annotate | Line # | Download | only in vr
vrpmu.c revision 1.1.1.1
      1 /*	$NetBSD: vrpmu.c,v 1.1.1.1 1999/09/16 12:23:33 takemura Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999 M. Warner Losh.  All rights reserved.
      5  * Copyright (c) 1999 PocketBSD Project. All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/param.h>
     30 #include <sys/systm.h>
     31 #include <sys/device.h>
     32 
     33 #include <machine/bus.h>
     34 
     35 #include <hpcmips/vr/vripvar.h>
     36 #include <hpcmips/vr/vrpmuvar.h>
     37 #include <hpcmips/vr/vrpmureg.h>
     38 
     39 static int vrpmumatch __P((struct device *, struct cfdata *, void *));
     40 static void vrpmuattach __P((struct device *, struct device *, void *));
     41 
     42 static void vrpmu_write __P((struct vrpmu_softc *, int, unsigned short));
     43 static unsigned short vrpmu_read __P((struct vrpmu_softc *, int));
     44 
     45 int vrpmu_intr __P((void *));
     46 
     47 struct cfattach vrpmu_ca = {
     48 	sizeof(struct vrpmu_softc), vrpmumatch, vrpmuattach
     49 };
     50 
     51 static int
     52 vrpmumatch(parent, cf, aux)
     53 	struct device *parent;
     54 	struct cfdata *cf;
     55 	void *aux;
     56 {
     57 	return 1;
     58 }
     59 
     60 static void
     61 vrpmuattach(parent, self, aux)
     62 	struct device *parent;
     63 	struct device *self;
     64 	void *aux;
     65 {
     66 	struct vrpmu_softc *sc = (struct vrpmu_softc *)self;
     67 	struct vrip_attach_args *va = aux;
     68 
     69 	bus_space_tag_t iot = va->va_iot;
     70 	bus_space_handle_t ioh;
     71 
     72 	if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
     73 		printf(": can't map bus space\n");
     74 		return;
     75 	}
     76 
     77 	sc->sc_iot = iot;
     78 	sc->sc_ioh = ioh;
     79 
     80 	if (!(sc->sc_handler =
     81 	      vrip_intr_establish(va->va_vc, va->va_intr, IPL_TTY,
     82 				  vrpmu_intr, sc))) {
     83 		printf (": can't map interrupt line.\n");
     84 		return;
     85 	}
     86 
     87 	printf("\n");
     88 }
     89 
     90 static inline void
     91 vrpmu_write(sc, port, val)
     92 	struct vrpmu_softc *sc;
     93 	int port;
     94 	unsigned short val;
     95 {
     96 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
     97 }
     98 
     99 static inline unsigned short
    100 vrpmu_read(sc, port)
    101 	struct vrpmu_softc *sc;
    102 	int port;
    103 {
    104 	return bus_space_read_2(sc->sc_iot, sc->sc_ioh, port);
    105 }
    106 
    107 /*
    108  * XXX
    109  *
    110  * In the following interrupt routine we should actually DO something
    111  * with the knowledge that we've gained.  For now we just report it.
    112  */
    113 int
    114 vrpmu_intr(arg)
    115 	void *arg;
    116 {
    117         struct vrpmu_softc *sc = arg;
    118 	unsigned int intmask;
    119 
    120 	intmask = vrpmu_read(sc, PMUINT_REG_W);
    121 	vrpmu_write(sc, PMUINT_REG_W, intmask);
    122 
    123 	if (intmask & PMUINT_GPIO3)
    124 		printf("vrpmu: GPIO[3] activation\n");
    125 	if (intmask & PMUINT_GPIO2)
    126 		printf("vrpmu: GPIO[2] activation\n");
    127 	if (intmask & PMUINT_GPIO1)
    128 		printf("vrpmu: GPIO[1] activation\n");
    129 	if (intmask & PMUINT_GPIO0)
    130 		printf("vrpmu: GPIO[0] activation\n");
    131 
    132 	if (intmask & PMUINT_RTC)
    133 		printf("vrpmu: RTC alarm detected\n");
    134 	if (intmask & PMUINT_BATT)
    135 		printf("vrpmu: Battery low during activation\n");
    136 
    137 	if (intmask & PMUINT_TIMOUTRST)
    138 		printf("vrpmu: HAL timer reset\n");
    139 	if (intmask & PMUINT_RTCRST)
    140 		printf("vrpmu: RTC reset detected\n");
    141 	if (intmask & PMUINT_RSTSWRST)
    142 		printf("vrpmu: RESET switch detected\n");
    143 	if (intmask & PMUINT_DMSWRST)
    144 		printf("vrpmu: Deadman's switch detected\n");
    145 	if (intmask & PMUINT_BATTINTR)
    146 		printf("vrpmu: Battery low during normal ops\n");
    147 	if (intmask & PMUINT_POWERSW)
    148 		printf("vrpmu: POWER switch detected\n");
    149 
    150 	intmask = vrpmu_read(sc, PMUINT2_REG_W);
    151 	vrpmu_write(sc, PMUINT2_REG_W, intmask);
    152 
    153 	if (intmask & PMUINT_GPIO12)
    154 		printf("vrpmu: GPIO[12] activation\n");
    155 	if (intmask & PMUINT_GPIO11)
    156 		printf("vrpmu: GPIO[11] activation\n");
    157 	if (intmask & PMUINT_GPIO10)
    158 		printf("vrpmu: GPIO[10] activation\n");
    159 	if (intmask & PMUINT_GPIO9)
    160 		printf("vrpmu: GPIO[9] activation\n");
    161 
    162 	return 0;
    163 }
    164