ms_hb.c revision 1.6 1 /* $NetBSD: ms_hb.c,v 1.6 2003/07/15 02:59:26 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
5 * Copyright (c) 2000 Tsubai Masanari. 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 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: ms_hb.c,v 1.6 2003/07/15 02:59:26 lukem Exp $");
32
33 #include <sys/param.h>
34 #include <sys/device.h>
35 #include <sys/systm.h>
36
37 #include <dev/wscons/wsconsio.h>
38 #include <dev/wscons/wsmousevar.h>
39
40 #include <machine/bus.h>
41 #include <machine/cpu.h>
42
43 #include <news68k/dev/hbvar.h>
44 #include <news68k/dev/ms_hbreg.h>
45 #include <news68k/dev/msvar.h>
46
47 #include <news68k/news68k/isr.h>
48
49 #define MS_SIZE 0x10 /* XXX */
50 #define MS_IPL 5
51
52 int ms_hb_match(struct device *, struct cfdata *, void *);
53 void ms_hb_attach(struct device *, struct device *, void *);
54 void ms_hb_init(struct ms_softc *);
55 int ms_hb_intr(void *);
56
57 int ms_hb_enable(void *);
58 int ms_hb_ioctl(void *, u_long, caddr_t, int, struct proc *);
59 void ms_hb_disable(void *);
60
61 CFATTACH_DECL(ms_hb, sizeof(struct ms_softc),
62 ms_hb_match, ms_hb_attach, NULL, NULL);
63
64 struct wsmouse_accessops ms_hb_accessops = {
65 ms_hb_enable,
66 ms_hb_ioctl,
67 ms_hb_disable
68 };
69
70 int
71 ms_hb_match(parent, cf, aux)
72 struct device *parent;
73 struct cfdata *cf;
74 void *aux;
75 {
76 struct hb_attach_args *ha = aux;
77 u_int addr;
78
79 if (strcmp(ha->ha_name, "ms"))
80 return 0;
81
82 /* XXX no default address */
83 if (ha->ha_address == (u_int)-1)
84 return 0;
85
86 addr = IIOV(ha->ha_address); /* XXX */
87
88 if (badaddr((void *)addr, 1))
89 return 0;
90
91 return 1;
92 }
93
94 void
95 ms_hb_attach(parent, self, aux)
96 struct device *parent;
97 struct device *self;
98 void *aux;
99 {
100 struct ms_softc *sc = (void *)self;
101 struct hb_attach_args *ha = aux;
102 bus_space_tag_t bt = ha->ha_bust;
103 bus_space_handle_t bh;
104 struct wsmousedev_attach_args wsa;
105 int ipl;
106
107 if (bus_space_map(bt, ha->ha_address, MS_SIZE, 0, &bh) != 0) {
108 printf("can't map device space\n");
109 return;
110 }
111
112 printf("\n");
113
114 sc->sc_bt = bt;
115 sc->sc_bh = bh;
116 sc->sc_offset = MS_REG_DATA;
117 ipl = ha->ha_ipl;
118 if (ipl == -1)
119 ipl = MS_IPL;
120
121 ms_hb_init(sc);
122
123 isrlink_autovec(ms_hb_intr, (void *)sc, ipl, ISRPRI_TTY);
124
125 wsa.accessops = &ms_hb_accessops;
126 wsa.accesscookie = sc;
127 sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
128 }
129
130 void
131 ms_hb_init(sc)
132 struct ms_softc *sc;
133 {
134 bus_space_tag_t bt = sc->sc_bt;
135 bus_space_handle_t bh = sc->sc_bh;
136
137 bus_space_write_1(bt, bh, MS_REG_RESET, 0);
138 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
139 }
140
141 int
142 ms_hb_intr(v)
143 void *v;
144 {
145 struct ms_softc *sc = v;
146 bus_space_tag_t bt = sc->sc_bt;
147 bus_space_handle_t bh = sc->sc_bh;
148 int handled = 0;
149
150 while ((bus_space_read_1(bt, bh, MS_REG_STAT) & MSSTAT_RDY) != 0) {
151 ms_intr(sc);
152 handled = 1;
153 }
154 if (handled)
155 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
156
157 return handled;
158 }
159
160 int
161 ms_hb_enable(v)
162 void *v;
163 {
164 struct ms_softc *sc = v;
165 bus_space_tag_t bt = sc->sc_bt;
166 bus_space_handle_t bh = sc->sc_bh;
167
168 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
169
170 return 0;
171 }
172
173 void
174 ms_hb_disable(v)
175 void *v;
176 {
177 struct ms_softc *sc = v;
178 bus_space_tag_t bt = sc->sc_bt;
179 bus_space_handle_t bh = sc->sc_bh;
180
181 bus_space_write_1(bt, bh, MS_REG_INTE, 0);
182 }
183
184 int
185 ms_hb_ioctl(v, cmd, data, flag, p)
186 void *v;
187 u_long cmd;
188 caddr_t data;
189 int flag;
190 struct proc *p;
191 {
192 return EPASSTHROUGH;
193 }
194