xref: /netbsd-src/sys/arch/news68k/dev/ms_kbc.c (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 /*	$NetBSD: ms_kbc.c,v 1.12 2008/05/14 13:29:28 tsutsui Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 Izumi Tsutsui.  All rights reserved.
5  *
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.
14  *
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.
25  */
26 
27 /*-
28  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
29  *
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.
40  *
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.
51  */
52 
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: ms_kbc.c,v 1.12 2008/05/14 13:29:28 tsutsui Exp $");
55 
56 #include <sys/param.h>
57 #include <sys/device.h>
58 #include <sys/systm.h>
59 
60 #include <dev/wscons/wsconsio.h>
61 #include <dev/wscons/wsmousevar.h>
62 
63 #include <machine/cpu.h>
64 #include <machine/bus.h>
65 
66 #include <news68k/dev/kbcreg.h>
67 #include <news68k/dev/kbcvar.h>
68 #include <news68k/dev/msvar.h>
69 
70 #include <news68k/news68k/isr.h>
71 
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 *);
76 
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 *);
80 
81 CFATTACH_DECL_NEW(ms_kbc, sizeof(struct ms_softc),
82     ms_kbc_match, ms_kbc_attach, NULL, NULL);
83 
84 struct wsmouse_accessops ms_kbc_accessops = {
85 	ms_kbc_enable,
86 	ms_kbc_ioctl,
87 	ms_kbc_disable
88 };
89 
90 static int
91 ms_kbc_match(device_t parent, cfdata_t cf, void *aux)
92 {
93 	struct kbc_attach_args *ka = aux;
94 
95 	if (strcmp(ka->ka_name, "ms"))
96 		return 0;
97 
98 	return 1;
99 }
100 
101 static void
102 ms_kbc_attach(device_t parent, device_t self, void *aux)
103 {
104 	struct ms_softc *sc = device_private(self);
105 	struct kbc_attach_args *ka = aux;
106 	struct wsmousedev_attach_args wsa;
107 	int ipl;
108 
109 	sc->sc_dev = self;
110 	aprint_normal("\n");
111 
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;
116 
117 	ms_kbc_init(sc);
118 
119 	isrlink_autovec(ms_kbc_intr, (void *)sc, ipl, IPL_TTY);
120 
121 	wsa.accessops = &ms_kbc_accessops;
122 	wsa.accesscookie = sc;
123 	sc->sc_wsmousedev = config_found(self, &wsa, wsmousedevprint);
124 }
125 
126 static void
127 ms_kbc_init(struct ms_softc *sc)
128 {
129 	bus_space_tag_t bt = sc->sc_bt;
130 	bus_space_handle_t bh = sc->sc_bh;
131 
132 	bus_space_write_1(bt, bh, KBC_MSREG_RESET, 0);
133 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
134 }
135 
136 int
137 ms_kbc_intr(void *v)
138 {
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;
143 
144 	while (bus_space_read_1(bt, bh, KBC_MSREG_STAT) & KBCSTAT_MSRDY) {
145 		ms_intr(sc);
146 		handled = 1;
147 	}
148 	if (handled)
149 		bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
150 
151 	return handled;
152 }
153 
154 static int
155 ms_kbc_enable(void *v)
156 {
157 	struct ms_softc *sc = v;
158 	bus_space_tag_t bt = sc->sc_bt;
159 	bus_space_handle_t bh = sc->sc_bh;
160 
161 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
162 
163 	return 0;
164 }
165 
166 static void
167 ms_kbc_disable(void *v)
168 {
169 	struct ms_softc *sc = v;
170 	bus_space_tag_t bt = sc->sc_bt;
171 	bus_space_handle_t bh = sc->sc_bh;
172 
173 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, 0);
174 }
175 
176 static int
177 ms_kbc_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
178 {
179 
180 	return EPASSTHROUGH;
181 }
182