FreeBSD/Linux Kernel Cross Reference
sys/dev/sun/sunms.c
1 /* $NetBSD: sunms.c,v 1.17 2003/08/07 16:31:27 agc Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 *
40 * @(#)ms.c 8.1 (Berkeley) 6/11/93
41 */
42
43 /*
44 * Mouse driver (/dev/mouse)
45 */
46
47 /*
48 * Zilog Z8530 Dual UART driver (mouse interface)
49 *
50 * This is the "slave" driver that will be attached to
51 * the "zsc" driver for a Sun mouse.
52 */
53
54 #include <sys/cdefs.h>
55 __KERNEL_RCSID(0, "$NetBSD: sunms.c,v 1.17 2003/08/07 16:31:27 agc Exp $");
56
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/conf.h>
60 #include <sys/device.h>
61 #include <sys/ioctl.h>
62 #include <sys/kernel.h>
63 #include <sys/proc.h>
64 #include <sys/signal.h>
65 #include <sys/signalvar.h>
66 #include <sys/time.h>
67 #include <sys/select.h>
68 #include <sys/syslog.h>
69 #include <sys/fcntl.h>
70 #include <sys/tty.h>
71
72 #include <machine/vuid_event.h>
73
74 #include <sys/tty.h>
75 #include <dev/sun/event_var.h>
76 #include <dev/sun/msvar.h>
77 #include <dev/sun/kbd_ms_ttyvar.h>
78
79 #include <dev/wscons/wsconsio.h>
80 #include <dev/wscons/wsmousevar.h>
81
82 #include "ms.h"
83 #include "wsmouse.h"
84 #if NMS > 0
85
86 #ifdef SUN_MS_BPS
87 int sunms_bps = SUN_MS_BPS;
88 #else
89 int sunms_bps = MS_DEFAULT_BPS;
90 #endif
91
92 static int sunms_match(struct device *, struct cfdata *, void *);
93 static void sunms_attach(struct device *, struct device *, void *);
94 static int sunmsiopen(struct device *, int mode);
95 int sunmsinput(int, struct tty *);
96
97 CFATTACH_DECL(ms_tty, sizeof(struct ms_softc),
98 sunms_match, sunms_attach, NULL, NULL);
99
100 struct linesw sunms_disc =
101 { "sunms", 8, ttylopen, ttylclose, ttyerrio, ttyerrio, ttynullioctl,
102 sunmsinput, ttstart, nullmodem, ttpoll }; /* 8- SUNMOUSEDISC */
103
104 int sunms_enable(void *);
105 int sunms_ioctl(void *, u_long, caddr_t, int, struct proc *);
106 void sunms_disable(void *);
107
108 const struct wsmouse_accessops sunms_accessops = {
109 sunms_enable,
110 sunms_ioctl,
111 sunms_disable,
112 };
113
114 /*
115 * ms_match: how is this zs channel configured?
116 */
117 int
118 sunms_match(parent, cf, aux)
119 struct device *parent;
120 struct cfdata *cf;
121 void *aux;
122 {
123 struct kbd_ms_tty_attach_args *args = aux;
124
125 if (sunms_bps == 0)
126 return 0;
127
128 if (strcmp(args->kmta_name, "mouse") == 0)
129 return (1);
130
131 return 0;
132 }
133
134 void
135 sunms_attach(parent, self, aux)
136 struct device *parent, *self;
137 void *aux;
138
139 {
140 struct ms_softc *ms = (void *) self;
141 struct kbd_ms_tty_attach_args *args = aux;
142 struct cfdata *cf;
143 struct tty *tp = args->kmta_tp;
144 int ms_unit;
145 #if NWSMOUSE > 0
146 struct wsmousedev_attach_args a;
147 #endif
148
149 cf = ms->ms_dev.dv_cfdata;
150 ms_unit = ms->ms_dev.dv_unit;
151 tp->t_sc = ms;
152 tp->t_dev = args->kmta_dev;
153 ms->ms_cs = (struct zs_chanstate *)tp;
154 ms->ms_deviopen = sunmsiopen;
155 ms->ms_deviclose = NULL;
156
157 printf("\n");
158
159 /* Initialize the speed, etc. */
160 if (ttyldisc_add(&sunms_disc, -1) == -1)
161 panic("sunms_attach: sunms_disc");
162 tp->t_linesw = &sunms_disc;
163 tp->t_oflag &= ~OPOST;
164
165 /* Initialize translator. */
166 ms->ms_byteno = -1;
167
168 #if NWSMOUSE > 0
169 /*
170 * attach wsmouse
171 */
172 a.accessops = &sunms_accessops;
173 a.accesscookie = ms;
174
175 ms->ms_wsmousedev = config_found(self, &a, wsmousedevprint);
176 #endif
177 }
178
179 /*
180 * Internal open routine. This really should be inside com.c
181 * But I'm putting it here until we have a generic internal open
182 * mechanism.
183 */
184 int
185 sunmsiopen(dev, flags)
186 struct device *dev;
187 int flags;
188 {
189 struct ms_softc *ms = (void *) dev;
190 struct tty *tp = (struct tty *)ms->ms_cs;
191 struct proc *p = curproc ? curproc : &proc0;
192 struct termios t;
193 const struct cdevsw *cdev;
194 int error;
195
196 cdev = cdevsw_lookup(tp->t_dev);
197 if (cdev == NULL)
198 return (ENXIO);
199
200 /* Open the lower device */
201 if ((error = (*cdev->d_open)(tp->t_dev, O_NONBLOCK|flags,
202 0/* ignored? */, p)) != 0)
203 return (error);
204
205 /* Now configure it for the console. */
206 tp->t_ospeed = 0;
207 t.c_ispeed = sunms_bps;
208 t.c_ospeed = sunms_bps;
209 t.c_cflag = CLOCAL|CS8;
210 (*tp->t_param)(tp, &t);
211
212 return (0);
213 }
214
215 int
216 sunmsinput(c, tp)
217 int c;
218 struct tty *tp;
219 {
220 struct ms_softc *ms = (struct ms_softc *)tp->t_sc;
221
222 if (c & TTY_ERRORMASK) c = -1;
223 else c &= TTY_CHARMASK;
224
225 /* Pass this up to the "middle" layer. */
226 ms_input(ms, c);
227 return (0);
228 }
229
230 int
231 sunms_ioctl(v, cmd, data, flag, p)
232 void *v;
233 u_long cmd;
234 caddr_t data;
235 int flag;
236 struct proc *p;
237 {
238 /* struct ms_softc *sc = v; */
239
240 switch (cmd) {
241 case WSMOUSEIO_GTYPE:
242 *(u_int *)data = WSMOUSE_TYPE_PS2; /* XXX */
243 break;
244
245 default:
246 return (EPASSTHROUGH);
247 }
248 return (0);
249 }
250
251 int
252 sunms_enable(v)
253 void *v;
254 {
255 struct ms_softc *ms = v;
256 int err;
257 int s;
258
259 if (ms->ms_ready)
260 return EBUSY;
261
262 err = sunmsiopen(v, 0);
263 if (err)
264 return err;
265
266 s = spltty();
267 ms->ms_ready = 2;
268 splx(s);
269
270 return 0;
271 }
272
273 void
274 sunms_disable(v)
275 void *v;
276 {
277 struct ms_softc *ms = v;
278 int s;
279
280 s = spltty();
281 ms->ms_ready = 0;
282 splx(s);
283 }
284 #endif
Cache object: 1ea3f293bc6f90a0674a5e8cf6a0b085
|