Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / sun / sunms.c
blob20ed80d0306f2137be099f88d80633d187d54c79
1 /* $NetBSD: sunms.c,v 1.30 2009/05/12 13:21:06 cegger Exp $ */
3 /*
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
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.
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.
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>
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>
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>
81 #include "ms.h"
82 #include "wsmouse.h"
83 #if NMS > 0
85 #ifdef SUN_MS_BPS
86 int sunms_bps = SUN_MS_BPS;
87 #else
88 int sunms_bps = MS_DEFAULT_BPS;
89 #endif
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 = {
100 .l_name = "sunms",
101 .l_open = ttylopen,
102 .l_close = ttylclose,
103 .l_read = ttyerrio,
104 .l_write = ttyerrio,
105 .l_ioctl = ttynullioctl,
106 .l_rint = sunmsinput,
107 .l_start = ttstart,
108 .l_modem = nullmodem,
109 .l_poll = ttpoll
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 = {
117 sunms_enable,
118 sunms_ioctl,
119 sunms_disable,
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;
130 if (sunms_bps == 0)
131 return 0;
133 if (strcmp(args->kmta_name, "mouse") == 0)
134 return (1);
136 return 0;
139 void
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;
144 cfdata_t cf;
145 struct tty *tp = args->kmta_tp;
146 int ms_unit;
147 #if NWSMOUSE > 0
148 struct wsmousedev_attach_args a;
149 #endif
151 ms->ms_dev = self;
152 cf = device_cfdata(self);
153 ms_unit = device_unit(self);
154 tp->t_sc = ms;
155 tp->t_dev = args->kmta_dev;
156 ms->ms_priv = tp;
157 ms->ms_deviopen = sunmsiopen;
158 ms->ms_deviclose = NULL;
160 aprint_normal("\n");
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. */
171 ms->ms_byteno = -1;
173 #if NWSMOUSE > 0
175 * attach wsmouse
177 a.accessops = &sunms_accessops;
178 a.accesscookie = ms;
180 ms->ms_wsmousedev = config_found(self, &a, wsmousedevprint);
181 #endif
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
187 * mechanism.
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;
195 struct termios t;
196 int error;
198 /* Open the lower device */
199 if ((error = cdev_open(tp->t_dev, O_NONBLOCK|flags,
200 0/* ignored? */, l)) != 0)
201 return (error);
203 /* Now configure it for the console. */
204 tp->t_ospeed = 0;
205 t.c_ispeed = sunms_bps;
206 t.c_ospeed = sunms_bps;
207 t.c_cflag = CLOCAL|CS8;
208 (*tp->t_param)(tp, &t);
210 return (0);
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. */
222 ms_input(ms, c);
223 return (0);
227 sunms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
229 /* struct ms_softc *sc = v; */
231 switch (cmd) {
232 case WSMOUSEIO_GTYPE:
233 *(u_int *)data = WSMOUSE_TYPE_PS2; /* XXX */
234 break;
236 default:
237 return (EPASSTHROUGH);
239 return (0);
243 sunms_enable(void *v)
245 struct ms_softc *ms = v;
246 int err;
247 int s;
249 if (ms->ms_ready)
250 return EBUSY;
252 err = sunmsiopen(ms->ms_dev, 0);
253 if (err)
254 return err;
256 s = spltty();
257 ms->ms_ready = 2;
258 splx(s);
260 return 0;
263 void
264 sunms_disable(void *v)
266 struct ms_softc *ms = v;
267 int s;
269 s = spltty();
270 ms->ms_ready = 0;
271 splx(s);
273 #endif