Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / news68k / dev / ms_kbc.c
blob4f35fd7fd7e4365dc1f23bbee9010b78f3dca8a9
1 /* $NetBSD: ms_kbc.c,v 1.11 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_kbc.c,v 1.11 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/cpu.h>
64 #include <machine/bus.h>
66 #include <news68k/dev/kbcreg.h>
67 #include <news68k/dev/kbcvar.h>
68 #include <news68k/dev/msvar.h>
70 #include <news68k/news68k/isr.h>
72 static int ms_kbc_match(device_t, cfdata_t, void *);
73 static void ms_kbc_attach(device_t, device_t, void *);
74 static void ms_kbc_init(struct ms_softc *);
75 int ms_kbc_intr(void *);
77 static int ms_kbc_enable(void *);
78 static void ms_kbc_disable(void *);
79 static int ms_kbc_ioctl(void *, u_long, void *, int, struct lwp *);
81 CFATTACH_DECL_NEW(ms_kbc, sizeof(struct ms_softc),
82 ms_kbc_match, ms_kbc_attach, NULL, NULL);
84 struct wsmouse_accessops ms_kbc_accessops = {
85 ms_kbc_enable,
86 ms_kbc_ioctl,
87 ms_kbc_disable
90 static int
91 ms_kbc_match(device_t parent, cfdata_t cf, void *aux)
93 struct kbc_attach_args *ka = aux;
95 if (strcmp(ka->ka_name, "ms"))
96 return 0;
98 return 1;
101 static void
102 ms_kbc_attach(device_t parent, device_t self, void *aux)
104 struct ms_softc *sc = device_private(self);
105 struct kbc_attach_args *ka = aux;
106 struct wsmousedev_attach_args wsa;
107 int ipl;
109 sc->sc_dev = self;
110 aprint_normal("\n");
112 sc->sc_bt = ka->ka_bt;
113 sc->sc_bh = ka->ka_bh;
114 sc->sc_offset = KBC_MSREG_DATA;
115 ipl = ka->ka_ipl;
117 ms_kbc_init(sc);
119 isrlink_autovec(ms_kbc_intr, (void *)sc, ipl, IPL_TTY);
121 wsa.accessops = &ms_kbc_accessops;
122 wsa.accesscookie = sc;
123 sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
126 static void
127 ms_kbc_init(struct ms_softc *sc)
129 bus_space_tag_t bt = sc->sc_bt;
130 bus_space_handle_t bh = sc->sc_bh;
132 bus_space_write_1(bt, bh, KBC_MSREG_RESET, 0);
133 bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
137 ms_kbc_intr(void *v)
139 struct ms_softc *sc = v;
140 bus_space_tag_t bt = sc->sc_bt;
141 bus_space_handle_t bh = sc->sc_bh;
142 int handled = 0;
144 while (bus_space_read_1(bt, bh, KBC_MSREG_STAT) & KBCSTAT_MSRDY) {
145 ms_intr(sc);
146 handled = 1;
148 if (handled)
149 bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
151 return handled;
154 static int
155 ms_kbc_enable(void *v)
157 struct ms_softc *sc = v;
158 bus_space_tag_t bt = sc->sc_bt;
159 bus_space_handle_t bh = sc->sc_bh;
161 bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
163 return 0;
166 static void
167 ms_kbc_disable(void *v)
169 struct ms_softc *sc = v;
170 bus_space_tag_t bt = sc->sc_bt;
171 bus_space_handle_t bh = sc->sc_bh;
173 bus_space_write_1(bt, bh, KBC_MSREG_INTE, 0);
176 static int
177 ms_kbc_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
180 return EPASSTHROUGH;