Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / news68k / dev / ms_hb.c
blob0f34001caef89c5f436aa0efb34241007db01baa
1 /* $NetBSD: ms_hb.c,v 1.12 2008/03/29 05:48:33 tsutsui Exp $ */
3 /*-
4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 /*-
28 * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
32 * are met:
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. The name of the author may not be used to endorse or promote products
39 * derived from this software without specific prior written permission.
41 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
42 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
45 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: ms_hb.c,v 1.12 2008/03/29 05:48:33 tsutsui Exp $");
56 #include <sys/param.h>
57 #include <sys/device.h>
58 #include <sys/systm.h>
60 #include <dev/wscons/wsconsio.h>
61 #include <dev/wscons/wsmousevar.h>
63 #include <machine/bus.h>
64 #include <machine/cpu.h>
66 #include <news68k/dev/hbvar.h>
67 #include <news68k/dev/ms_hbreg.h>
68 #include <news68k/dev/msvar.h>
70 #include <news68k/news68k/isr.h>
72 #define MS_SIZE 0x10 /* XXX */
73 #define MS_IPL 5
75 static int ms_hb_match(device_t, cfdata_t, void *);
76 static void ms_hb_attach(device_t, device_t, void *);
77 static void ms_hb_init(struct ms_softc *);
78 int ms_hb_intr(void *);
80 static int ms_hb_enable(void *);
81 static int ms_hb_ioctl(void *, u_long, void *, int, struct lwp *);
82 static void ms_hb_disable(void *);
84 CFATTACH_DECL_NEW(ms_hb, sizeof(struct ms_softc),
85 ms_hb_match, ms_hb_attach, NULL, NULL);
87 struct wsmouse_accessops ms_hb_accessops = {
88 ms_hb_enable,
89 ms_hb_ioctl,
90 ms_hb_disable
93 static int
94 ms_hb_match(device_t parent, cfdata_t cf, void *aux)
96 struct hb_attach_args *ha = aux;
97 u_int addr;
99 if (strcmp(ha->ha_name, "ms"))
100 return 0;
102 /* XXX no default address */
103 if (ha->ha_address == (u_int)-1)
104 return 0;
106 addr = IIOV(ha->ha_address); /* XXX */
108 if (badaddr((void *)addr, 1))
109 return 0;
111 return 1;
114 static void
115 ms_hb_attach(device_t parent, device_t self, void *aux)
117 struct ms_softc *sc = device_private(self);
118 struct hb_attach_args *ha = aux;
119 bus_space_tag_t bt = ha->ha_bust;
120 bus_space_handle_t bh;
121 struct wsmousedev_attach_args wsa;
122 int ipl;
124 sc->sc_dev = self;
125 if (bus_space_map(bt, ha->ha_address, MS_SIZE, 0, &bh) != 0) {
126 aprint_error(": can't map device space\n");
127 return;
130 aprint_normal("\n");
132 sc->sc_bt = bt;
133 sc->sc_bh = bh;
134 sc->sc_offset = MS_REG_DATA;
135 ipl = ha->ha_ipl;
136 if (ipl == -1)
137 ipl = MS_IPL;
139 ms_hb_init(sc);
141 isrlink_autovec(ms_hb_intr, (void *)sc, ipl, IPL_TTY);
143 wsa.accessops = &ms_hb_accessops;
144 wsa.accesscookie = sc;
145 sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
148 static void
149 ms_hb_init(struct ms_softc *sc)
151 bus_space_tag_t bt = sc->sc_bt;
152 bus_space_handle_t bh = sc->sc_bh;
154 bus_space_write_1(bt, bh, MS_REG_RESET, 0);
155 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
159 ms_hb_intr(void *v)
161 struct ms_softc *sc = v;
162 bus_space_tag_t bt = sc->sc_bt;
163 bus_space_handle_t bh = sc->sc_bh;
164 int handled = 0;
166 while ((bus_space_read_1(bt, bh, MS_REG_STAT) & MSSTAT_RDY) != 0) {
167 ms_intr(sc);
168 handled = 1;
170 if (handled)
171 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
173 return handled;
176 static int
177 ms_hb_enable(void *v)
179 struct ms_softc *sc = v;
180 bus_space_tag_t bt = sc->sc_bt;
181 bus_space_handle_t bh = sc->sc_bh;
183 bus_space_write_1(bt, bh, MS_REG_INTE, MS_INTE);
185 return 0;
188 static void
189 ms_hb_disable(void *v)
191 struct ms_softc *sc = v;
192 bus_space_tag_t bt = sc->sc_bt;
193 bus_space_handle_t bh = sc->sc_bh;
195 bus_space_write_1(bt, bh, MS_REG_INTE, 0);
198 static int
199 ms_hb_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
202 return EPASSTHROUGH;