1 /* $NetBSD: sunms.c,v 1.4 2001/05/17 02:24:00 chs 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. All advertising materials mentioning features or use of this software 25 * must display the following acknowledgement: 26 * This product includes software developed by the University of 27 * California, Berkeley and its contributors. 28 * 4. Neither the name of the University nor the names of its contributors 29 * may be used to endorse or promote products derived from this software 30 * without specific prior written permission. 31 * 32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 42 * SUCH DAMAGE. 43 * 44 * @(#)ms.c 8.1 (Berkeley) 6/11/93 45 */ 46 47 /* 48 * Mouse driver (/dev/mouse) 49 */ 50 51 /* 52 * Zilog Z8530 Dual UART driver (mouse interface) 53 * 54 * This is the "slave" driver that will be attached to 55 * the "zsc" driver for a Sun mouse. 56 */ 57 58 #include <sys/param.h> 59 #include <sys/systm.h> 60 #include <sys/conf.h> 61 #include <sys/device.h> 62 #include <sys/ioctl.h> 63 #include <sys/kernel.h> 64 #include <sys/proc.h> 65 #include <sys/signal.h> 66 #include <sys/signalvar.h> 67 #include <sys/time.h> 68 #include <sys/select.h> 69 #include <sys/syslog.h> 70 #include <sys/fcntl.h> 71 #include <sys/tty.h> 72 73 #include <machine/vuid_event.h> 74 75 #include <sys/tty.h> 76 #include <dev/sun/event_var.h> 77 #include <dev/sun/msvar.h> 78 #include <dev/sun/kbd_ms_ttyvar.h> 79 80 #include "ms.h" 81 #if NMS > 0 82 83 int sunms_bps = MS_BPS; 84 85 static int sunms_match(struct device *, struct cfdata *, void *); 86 static void sunms_attach(struct device *, struct device *, void *); 87 static int sunmsiopen(struct device *, int mode); 88 int sunmsinput(int, struct tty *); 89 90 struct cfattach ms_ca = { 91 sizeof(struct ms_softc), sunms_match, sunms_attach 92 }; 93 94 struct linesw sunms_disc = 95 { "sunms", 8, ttylopen, ttylclose, ttyerrio, ttyerrio, nullioctl, 96 sunmsinput, ttstart, nullmodem, ttpoll }; /* 8- SUNMOUSEDISC */ 97 98 /* 99 * ms_match: how is this zs channel configured? 100 */ 101 int 102 sunms_match(parent, cf, aux) 103 struct device *parent; 104 struct cfdata *cf; 105 void *aux; 106 { 107 struct kbd_ms_tty_attach_args *args = aux; 108 109 if (sunms_bps == 0) 110 return 0; 111 112 if (strcmp(args->kmta_name, "mouse") == 0) 113 return (1); 114 115 return 0; 116 } 117 118 void 119 sunms_attach(parent, self, aux) 120 struct device *parent, *self; 121 void *aux; 122 123 { 124 struct ms_softc *ms = (void *) self; 125 struct kbd_ms_tty_attach_args *args = aux; 126 struct cfdata *cf; 127 struct tty *tp = args->kmta_tp; 128 int ms_unit; 129 130 cf = ms->ms_dev.dv_cfdata; 131 ms_unit = ms->ms_dev.dv_unit; 132 tp->t_sc = ms; 133 tp->t_dev = args->kmta_dev; 134 ms->ms_cs = (struct zs_chanstate *)tp; 135 ms->ms_deviopen = sunmsiopen; 136 ms->ms_deviclose = NULL; 137 138 printf("\n"); 139 140 /* Initialize the speed, etc. */ 141 if (ttyldisc_add(&sunms_disc, -1) == -1) 142 panic("sunms_attach: sunms_disc"); 143 tp->t_linesw = &sunms_disc; 144 tp->t_oflag &= ~OPOST; 145 146 /* Initialize translator. */ 147 ms->ms_byteno = -1; 148 } 149 150 /* 151 * Internal open routine. This really should be inside com.c 152 * But I'm putting it here until we have a generic internal open 153 * mechanism. 154 */ 155 int 156 sunmsiopen(dev, flags) 157 struct device *dev; 158 int flags; 159 { 160 struct ms_softc *ms = (void *) dev; 161 struct tty *tp = (struct tty *)ms->ms_cs; 162 struct proc *p = curproc; 163 struct termios t; 164 int maj; 165 int error; 166 167 maj = major(tp->t_dev); 168 if (p == NULL) 169 p = &proc0; 170 171 /* Open the lower device */ 172 if ((error = (*cdevsw[maj].d_open)(tp->t_dev, O_NONBLOCK|flags, 173 0/* ignored? */, p)) != 0) 174 return (error); 175 176 /* Now configure it for the console. */ 177 tp->t_ospeed = 0; 178 t.c_ispeed = sunms_bps; 179 t.c_ospeed = sunms_bps; 180 t.c_cflag = CLOCAL; 181 (*tp->t_param)(tp, &t); 182 183 return (0); 184 } 185 186 int 187 sunmsinput(c, tp) 188 int c; 189 struct tty *tp; 190 { 191 struct ms_softc *ms = (struct ms_softc *)tp->t_sc; 192 193 if (c & TTY_ERRORMASK) c = -1; 194 else c &= TTY_CHARMASK; 195 196 /* Pass this up to the "middle" layer. */ 197 ms_input(ms, c); 198 return (0); 199 } 200 #endif 201