1 /* $NetBSD: sunms.c,v 1.32 2013/09/15 14:13:19 martin 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.32 2013/09/15 14:13:19 martin 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 <dev/sun/event_var.h> 75 #include <dev/sun/msvar.h> 76 #include <dev/sun/kbd_ms_ttyvar.h> 77 78 #include <dev/wscons/wsconsio.h> 79 #include <dev/wscons/wsmousevar.h> 80 81 #include "ms.h" 82 #include "wsmouse.h" 83 #if NMS > 0 84 85 #ifdef SUN_MS_BPS 86 int sunms_bps = SUN_MS_BPS; 87 #else 88 int sunms_bps = MS_DEFAULT_BPS; 89 #endif 90 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 *); 95 96 CFATTACH_DECL_NEW(ms_tty, sizeof(struct ms_softc), 97 sunms_match, sunms_attach, NULL, NULL); 98 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 110 }; 111 112 int sunms_enable(void *); 113 int sunms_ioctl(void *, u_long, void *, int, struct lwp *); 114 void sunms_disable(void *); 115 116 const struct wsmouse_accessops sunms_accessops = { 117 sunms_enable, 118 sunms_ioctl, 119 sunms_disable, 120 }; 121 122 /* 123 * ms_match: how is this zs channel configured? 124 */ 125 int 126 sunms_match(device_t parent, cfdata_t cf, void *aux) 127 { 128 struct kbd_ms_tty_attach_args *args = aux; 129 130 if (sunms_bps == 0) 131 return 0; 132 133 if (strcmp(args->kmta_name, "mouse") == 0) 134 return (1); 135 136 return 0; 137 } 138 139 void 140 sunms_attach(device_t parent, device_t self, void *aux) 141 { 142 struct ms_softc *ms = device_private(self); 143 struct kbd_ms_tty_attach_args *args = aux; 144 struct tty *tp = args->kmta_tp; 145 #if NWSMOUSE > 0 146 struct wsmousedev_attach_args a; 147 #endif 148 149 ms->ms_dev = self; 150 tp->t_sc = ms; 151 tp->t_dev = args->kmta_dev; 152 ms->ms_priv = tp; 153 ms->ms_deviopen = sunmsiopen; 154 ms->ms_deviclose = NULL; 155 156 aprint_normal("\n"); 157 158 /* Initialize the speed, etc. */ 159 if (ttyldisc_attach(&sunms_disc) != 0) 160 panic("sunms_attach: sunms_disc"); 161 ttyldisc_release(tp->t_linesw); 162 tp->t_linesw = ttyldisc_lookup(sunms_disc.l_name); 163 KASSERT(tp->t_linesw == &sunms_disc); 164 tp->t_oflag &= ~OPOST; 165 166 /* Initialize translator. */ 167 ms->ms_byteno = -1; 168 169 #if NWSMOUSE > 0 170 /* 171 * attach wsmouse 172 */ 173 a.accessops = &sunms_accessops; 174 a.accesscookie = ms; 175 176 ms->ms_wsmousedev = config_found(self, &a, wsmousedevprint); 177 #endif 178 } 179 180 /* 181 * Internal open routine. This really should be inside com.c 182 * But I'm putting it here until we have a generic internal open 183 * mechanism. 184 */ 185 int 186 sunmsiopen(device_t dev, int flags) 187 { 188 struct ms_softc *ms = device_private(dev); 189 struct tty *tp = ms->ms_priv; 190 struct lwp *l = curlwp ? curlwp : &lwp0; 191 struct termios t; 192 int error; 193 194 /* Open the lower device */ 195 if ((error = cdev_open(tp->t_dev, O_NONBLOCK|flags, 196 0/* ignored? */, l)) != 0) 197 return (error); 198 199 /* Now configure it for the console. */ 200 tp->t_ospeed = 0; 201 t.c_ispeed = sunms_bps; 202 t.c_ospeed = sunms_bps; 203 t.c_cflag = CLOCAL|CS8; 204 (*tp->t_param)(tp, &t); 205 206 return (0); 207 } 208 209 int 210 sunmsinput(int c, struct tty *tp) 211 { 212 struct ms_softc *ms = tp->t_sc; 213 214 if (c & TTY_ERRORMASK) c = -1; 215 else c &= TTY_CHARMASK; 216 217 /* Pass this up to the "middle" layer. */ 218 ms_input(ms, c); 219 return (0); 220 } 221 222 int 223 sunms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l) 224 { 225 /* struct ms_softc *sc = v; */ 226 227 switch (cmd) { 228 case WSMOUSEIO_GTYPE: 229 *(u_int *)data = WSMOUSE_TYPE_PS2; /* XXX */ 230 break; 231 232 default: 233 return (EPASSTHROUGH); 234 } 235 return (0); 236 } 237 238 int 239 sunms_enable(void *v) 240 { 241 struct ms_softc *ms = v; 242 int err; 243 int s; 244 245 if (ms->ms_ready) 246 return EBUSY; 247 248 err = sunmsiopen(ms->ms_dev, 0); 249 if (err) 250 return err; 251 252 s = spltty(); 253 ms->ms_ready = 2; 254 splx(s); 255 256 return 0; 257 } 258 259 void 260 sunms_disable(void *v) 261 { 262 struct ms_softc *ms = v; 263 int s; 264 265 s = spltty(); 266 ms->ms_ready = 0; 267 splx(s); 268 } 269 #endif 270