ms_kbc.c revision 1.12 1 1.12 tsutsui /* $NetBSD: ms_kbc.c,v 1.12 2008/05/14 13:29:28 tsutsui Exp $ */
2 1.1 tsutsui
3 1.1 tsutsui /*-
4 1.1 tsutsui * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
5 1.12 tsutsui *
6 1.12 tsutsui * Redistribution and use in source and binary forms, with or without
7 1.12 tsutsui * modification, are permitted provided that the following conditions
8 1.12 tsutsui * are met:
9 1.12 tsutsui * 1. Redistributions of source code must retain the above copyright
10 1.12 tsutsui * notice, this list of conditions and the following disclaimer.
11 1.12 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
12 1.12 tsutsui * notice, this list of conditions and the following disclaimer in the
13 1.12 tsutsui * documentation and/or other materials provided with the distribution.
14 1.12 tsutsui *
15 1.12 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.12 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.12 tsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.12 tsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.12 tsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.12 tsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.12 tsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.12 tsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.12 tsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.12 tsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.12 tsutsui */
26 1.12 tsutsui
27 1.12 tsutsui /*-
28 1.1 tsutsui * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
29 1.1 tsutsui *
30 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
31 1.1 tsutsui * modification, are permitted provided that the following conditions
32 1.1 tsutsui * are met:
33 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
34 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
35 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
36 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
37 1.1 tsutsui * documentation and/or other materials provided with the distribution.
38 1.1 tsutsui * 3. The name of the author may not be used to endorse or promote products
39 1.1 tsutsui * derived from this software without specific prior written permission.
40 1.1 tsutsui *
41 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
42 1.1 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43 1.1 tsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44 1.1 tsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
45 1.1 tsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 1.1 tsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47 1.1 tsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48 1.1 tsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49 1.1 tsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50 1.1 tsutsui * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 1.1 tsutsui */
52 1.5 lukem
53 1.5 lukem #include <sys/cdefs.h>
54 1.12 tsutsui __KERNEL_RCSID(0, "$NetBSD: ms_kbc.c,v 1.12 2008/05/14 13:29:28 tsutsui Exp $");
55 1.1 tsutsui
56 1.1 tsutsui #include <sys/param.h>
57 1.1 tsutsui #include <sys/device.h>
58 1.1 tsutsui #include <sys/systm.h>
59 1.1 tsutsui
60 1.1 tsutsui #include <dev/wscons/wsconsio.h>
61 1.1 tsutsui #include <dev/wscons/wsmousevar.h>
62 1.1 tsutsui
63 1.1 tsutsui #include <machine/cpu.h>
64 1.1 tsutsui #include <machine/bus.h>
65 1.1 tsutsui
66 1.1 tsutsui #include <news68k/dev/kbcreg.h>
67 1.1 tsutsui #include <news68k/dev/kbcvar.h>
68 1.1 tsutsui #include <news68k/dev/msvar.h>
69 1.1 tsutsui
70 1.1 tsutsui #include <news68k/news68k/isr.h>
71 1.1 tsutsui
72 1.10 tsutsui static int ms_kbc_match(device_t, cfdata_t, void *);
73 1.10 tsutsui static void ms_kbc_attach(device_t, device_t, void *);
74 1.6 tsutsui static void ms_kbc_init(struct ms_softc *);
75 1.1 tsutsui int ms_kbc_intr(void *);
76 1.1 tsutsui
77 1.6 tsutsui static int ms_kbc_enable(void *);
78 1.6 tsutsui static void ms_kbc_disable(void *);
79 1.9 christos static int ms_kbc_ioctl(void *, u_long, void *, int, struct lwp *);
80 1.1 tsutsui
81 1.10 tsutsui CFATTACH_DECL_NEW(ms_kbc, sizeof(struct ms_softc),
82 1.4 thorpej ms_kbc_match, ms_kbc_attach, NULL, NULL);
83 1.1 tsutsui
84 1.1 tsutsui struct wsmouse_accessops ms_kbc_accessops = {
85 1.1 tsutsui ms_kbc_enable,
86 1.1 tsutsui ms_kbc_ioctl,
87 1.1 tsutsui ms_kbc_disable
88 1.1 tsutsui };
89 1.1 tsutsui
90 1.6 tsutsui static int
91 1.10 tsutsui ms_kbc_match(device_t parent, cfdata_t cf, void *aux)
92 1.1 tsutsui {
93 1.1 tsutsui struct kbc_attach_args *ka = aux;
94 1.1 tsutsui
95 1.1 tsutsui if (strcmp(ka->ka_name, "ms"))
96 1.1 tsutsui return 0;
97 1.1 tsutsui
98 1.1 tsutsui return 1;
99 1.1 tsutsui }
100 1.1 tsutsui
101 1.6 tsutsui static void
102 1.10 tsutsui ms_kbc_attach(device_t parent, device_t self, void *aux)
103 1.1 tsutsui {
104 1.10 tsutsui struct ms_softc *sc = device_private(self);
105 1.1 tsutsui struct kbc_attach_args *ka = aux;
106 1.1 tsutsui struct wsmousedev_attach_args wsa;
107 1.1 tsutsui int ipl;
108 1.1 tsutsui
109 1.11 tsutsui sc->sc_dev = self;
110 1.10 tsutsui aprint_normal("\n");
111 1.1 tsutsui
112 1.1 tsutsui sc->sc_bt = ka->ka_bt;
113 1.1 tsutsui sc->sc_bh = ka->ka_bh;
114 1.1 tsutsui sc->sc_offset = KBC_MSREG_DATA;
115 1.1 tsutsui ipl = ka->ka_ipl;
116 1.1 tsutsui
117 1.1 tsutsui ms_kbc_init(sc);
118 1.1 tsutsui
119 1.8 tsutsui isrlink_autovec(ms_kbc_intr, (void *)sc, ipl, IPL_TTY);
120 1.1 tsutsui
121 1.1 tsutsui wsa.accessops = &ms_kbc_accessops;
122 1.1 tsutsui wsa.accesscookie = sc;
123 1.1 tsutsui sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
124 1.1 tsutsui }
125 1.1 tsutsui
126 1.6 tsutsui static void
127 1.6 tsutsui ms_kbc_init(struct ms_softc *sc)
128 1.1 tsutsui {
129 1.1 tsutsui bus_space_tag_t bt = sc->sc_bt;
130 1.1 tsutsui bus_space_handle_t bh = sc->sc_bh;
131 1.1 tsutsui
132 1.1 tsutsui bus_space_write_1(bt, bh, KBC_MSREG_RESET, 0);
133 1.1 tsutsui bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
134 1.1 tsutsui }
135 1.1 tsutsui
136 1.1 tsutsui int
137 1.6 tsutsui ms_kbc_intr(void *v)
138 1.1 tsutsui {
139 1.1 tsutsui struct ms_softc *sc = v;
140 1.1 tsutsui bus_space_tag_t bt = sc->sc_bt;
141 1.1 tsutsui bus_space_handle_t bh = sc->sc_bh;
142 1.1 tsutsui int handled = 0;
143 1.1 tsutsui
144 1.1 tsutsui while (bus_space_read_1(bt, bh, KBC_MSREG_STAT) & KBCSTAT_MSRDY) {
145 1.1 tsutsui ms_intr(sc);
146 1.1 tsutsui handled = 1;
147 1.1 tsutsui }
148 1.1 tsutsui if (handled)
149 1.1 tsutsui bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
150 1.1 tsutsui
151 1.1 tsutsui return handled;
152 1.1 tsutsui }
153 1.1 tsutsui
154 1.6 tsutsui static int
155 1.6 tsutsui ms_kbc_enable(void *v)
156 1.1 tsutsui {
157 1.1 tsutsui struct ms_softc *sc = v;
158 1.1 tsutsui bus_space_tag_t bt = sc->sc_bt;
159 1.1 tsutsui bus_space_handle_t bh = sc->sc_bh;
160 1.1 tsutsui
161 1.1 tsutsui bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
162 1.1 tsutsui
163 1.1 tsutsui return 0;
164 1.1 tsutsui }
165 1.1 tsutsui
166 1.6 tsutsui static void
167 1.6 tsutsui ms_kbc_disable(void *v)
168 1.1 tsutsui {
169 1.1 tsutsui struct ms_softc *sc = v;
170 1.1 tsutsui bus_space_tag_t bt = sc->sc_bt;
171 1.1 tsutsui bus_space_handle_t bh = sc->sc_bh;
172 1.1 tsutsui
173 1.1 tsutsui bus_space_write_1(bt, bh, KBC_MSREG_INTE, 0);
174 1.1 tsutsui }
175 1.1 tsutsui
176 1.6 tsutsui static int
177 1.9 christos ms_kbc_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
178 1.1 tsutsui {
179 1.6 tsutsui
180 1.2 atatat return EPASSTHROUGH;
181 1.1 tsutsui }
182