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