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