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