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