xref: /netbsd-src/sys/arch/news68k/dev/ms_kbc.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1 /*	$NetBSD: ms_kbc.c,v 1.14 2021/08/07 16:19:00 thorpej 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.14 2021/08/07 16:19:00 thorpej 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
ms_kbc_match(device_t parent,cfdata_t cf,void * aux)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
ms_kbc_attach(device_t parent,device_t self,void * aux)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 	    CFARGS_NONE);
125 }
126 
127 static void
ms_kbc_init(struct ms_softc * sc)128 ms_kbc_init(struct ms_softc *sc)
129 {
130 	bus_space_tag_t bt = sc->sc_bt;
131 	bus_space_handle_t bh = sc->sc_bh;
132 
133 	bus_space_write_1(bt, bh, KBC_MSREG_RESET, 0);
134 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
135 }
136 
137 int
ms_kbc_intr(void * v)138 ms_kbc_intr(void *v)
139 {
140 	struct ms_softc *sc = v;
141 	bus_space_tag_t bt = sc->sc_bt;
142 	bus_space_handle_t bh = sc->sc_bh;
143 	int handled = 0;
144 
145 	while (bus_space_read_1(bt, bh, KBC_MSREG_STAT) & KBCSTAT_MSRDY) {
146 		ms_intr(sc);
147 		handled = 1;
148 	}
149 	if (handled)
150 		bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
151 
152 	return handled;
153 }
154 
155 static int
ms_kbc_enable(void * v)156 ms_kbc_enable(void *v)
157 {
158 	struct ms_softc *sc = v;
159 	bus_space_tag_t bt = sc->sc_bt;
160 	bus_space_handle_t bh = sc->sc_bh;
161 
162 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, KBC_INTE);
163 
164 	return 0;
165 }
166 
167 static void
ms_kbc_disable(void * v)168 ms_kbc_disable(void *v)
169 {
170 	struct ms_softc *sc = v;
171 	bus_space_tag_t bt = sc->sc_bt;
172 	bus_space_handle_t bh = sc->sc_bh;
173 
174 	bus_space_write_1(bt, bh, KBC_MSREG_INTE, 0);
175 }
176 
177 static int
ms_kbc_ioctl(void * v,u_long cmd,void * data,int flag,struct lwp * l)178 ms_kbc_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
179 {
180 
181 	return EPASSTHROUGH;
182 }
183