1 /* $NetBSD: sunms.c,v 1.30 2009/05/12 13:21:06 cegger Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
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.
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.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
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.
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
40 * @(#)ms.c 8.1 (Berkeley) 6/11/93
44 * Mouse driver (/dev/mouse)
48 * Zilog Z8530 Dual UART driver (mouse interface)
50 * This is the "slave" driver that will be attached to
51 * the "zsc" driver for a Sun mouse.
54 #include <sys/cdefs.h>
55 __KERNEL_RCSID(0, "$NetBSD: sunms.c,v 1.30 2009/05/12 13:21:06 cegger Exp $");
57 #include <sys/param.h>
58 #include <sys/systm.h>
60 #include <sys/device.h>
61 #include <sys/ioctl.h>
62 #include <sys/kernel.h>
64 #include <sys/signal.h>
65 #include <sys/signalvar.h>
67 #include <sys/select.h>
68 #include <sys/syslog.h>
69 #include <sys/fcntl.h>
72 #include <machine/vuid_event.h>
74 #include <dev/sun/event_var.h>
75 #include <dev/sun/msvar.h>
76 #include <dev/sun/kbd_ms_ttyvar.h>
78 #include <dev/wscons/wsconsio.h>
79 #include <dev/wscons/wsmousevar.h>
86 int sunms_bps
= SUN_MS_BPS
;
88 int sunms_bps
= MS_DEFAULT_BPS
;
91 static int sunms_match(device_t
, cfdata_t
, void *);
92 static void sunms_attach(device_t
, device_t
, void *);
93 static int sunmsiopen(device_t
, int mode
);
94 int sunmsinput(int, struct tty
*);
96 CFATTACH_DECL_NEW(ms_tty
, sizeof(struct ms_softc
),
97 sunms_match
, sunms_attach
, NULL
, NULL
);
99 struct linesw sunms_disc
= {
102 .l_close
= ttylclose
,
105 .l_ioctl
= ttynullioctl
,
106 .l_rint
= sunmsinput
,
108 .l_modem
= nullmodem
,
112 int sunms_enable(void *);
113 int sunms_ioctl(void *, u_long
, void *, int, struct lwp
*);
114 void sunms_disable(void *);
116 const struct wsmouse_accessops sunms_accessops
= {
123 * ms_match: how is this zs channel configured?
126 sunms_match(device_t parent
, cfdata_t cf
, void *aux
)
128 struct kbd_ms_tty_attach_args
*args
= aux
;
133 if (strcmp(args
->kmta_name
, "mouse") == 0)
140 sunms_attach(device_t parent
, device_t self
, void *aux
)
142 struct ms_softc
*ms
= device_private(self
);
143 struct kbd_ms_tty_attach_args
*args
= aux
;
145 struct tty
*tp
= args
->kmta_tp
;
148 struct wsmousedev_attach_args a
;
152 cf
= device_cfdata(self
);
153 ms_unit
= device_unit(self
);
155 tp
->t_dev
= args
->kmta_dev
;
157 ms
->ms_deviopen
= sunmsiopen
;
158 ms
->ms_deviclose
= NULL
;
162 /* Initialize the speed, etc. */
163 if (ttyldisc_attach(&sunms_disc
) != 0)
164 panic("sunms_attach: sunms_disc");
165 ttyldisc_release(tp
->t_linesw
);
166 tp
->t_linesw
= ttyldisc_lookup(sunms_disc
.l_name
);
167 KASSERT(tp
->t_linesw
== &sunms_disc
);
168 tp
->t_oflag
&= ~OPOST
;
170 /* Initialize translator. */
177 a
.accessops
= &sunms_accessops
;
180 ms
->ms_wsmousedev
= config_found(self
, &a
, wsmousedevprint
);
185 * Internal open routine. This really should be inside com.c
186 * But I'm putting it here until we have a generic internal open
190 sunmsiopen(device_t dev
, int flags
)
192 struct ms_softc
*ms
= device_private(dev
);
193 struct tty
*tp
= ms
->ms_priv
;
194 struct lwp
*l
= curlwp
? curlwp
: &lwp0
;
198 /* Open the lower device */
199 if ((error
= cdev_open(tp
->t_dev
, O_NONBLOCK
|flags
,
200 0/* ignored? */, l
)) != 0)
203 /* Now configure it for the console. */
205 t
.c_ispeed
= sunms_bps
;
206 t
.c_ospeed
= sunms_bps
;
207 t
.c_cflag
= CLOCAL
|CS8
;
208 (*tp
->t_param
)(tp
, &t
);
214 sunmsinput(int c
, struct tty
*tp
)
216 struct ms_softc
*ms
= tp
->t_sc
;
218 if (c
& TTY_ERRORMASK
) c
= -1;
219 else c
&= TTY_CHARMASK
;
221 /* Pass this up to the "middle" layer. */
227 sunms_ioctl(void *v
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
229 /* struct ms_softc *sc = v; */
232 case WSMOUSEIO_GTYPE
:
233 *(u_int
*)data
= WSMOUSE_TYPE_PS2
; /* XXX */
237 return (EPASSTHROUGH
);
243 sunms_enable(void *v
)
245 struct ms_softc
*ms
= v
;
252 err
= sunmsiopen(ms
->ms_dev
, 0);
264 sunms_disable(void *v
)
266 struct ms_softc
*ms
= v
;