Home | History | Annotate | Line # | Download | only in sun
sunms.c revision 1.3.2.2
      1  1.3.2.2  bouyer /*	$NetBSD: sunms.c,v 1.3.2.2 2000/11/20 11:43:11 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.2  bouyer /*
     95  1.3.2.2  bouyer  * ms_match: how is this zs channel configured?
     96  1.3.2.2  bouyer  */
     97  1.3.2.2  bouyer int
     98  1.3.2.2  bouyer sunms_match(parent, cf, aux)
     99  1.3.2.2  bouyer 	struct device *parent;
    100  1.3.2.2  bouyer 	struct cfdata *cf;
    101  1.3.2.2  bouyer 	void   *aux;
    102  1.3.2.2  bouyer {
    103  1.3.2.2  bouyer 	struct kbd_ms_tty_attach_args *args = aux;
    104  1.3.2.2  bouyer 
    105  1.3.2.2  bouyer 	if (sunms_bps == 0)
    106  1.3.2.2  bouyer 		return 0;
    107  1.3.2.2  bouyer 
    108  1.3.2.2  bouyer 	if (strcmp(args->kmta_name, "mouse") == 0)
    109  1.3.2.2  bouyer 		return (1);
    110  1.3.2.2  bouyer 
    111  1.3.2.2  bouyer 	return 0;
    112  1.3.2.2  bouyer }
    113  1.3.2.2  bouyer 
    114  1.3.2.2  bouyer void
    115  1.3.2.2  bouyer sunms_attach(parent, self, aux)
    116  1.3.2.2  bouyer 	struct device *parent, *self;
    117  1.3.2.2  bouyer 	void   *aux;
    118  1.3.2.2  bouyer 
    119  1.3.2.2  bouyer {
    120  1.3.2.2  bouyer 	struct ms_softc *ms = (void *) self;
    121  1.3.2.2  bouyer 	struct kbd_ms_tty_attach_args *args = aux;
    122  1.3.2.2  bouyer 	struct cfdata *cf;
    123  1.3.2.2  bouyer 	struct tty *tp = args->kmta_tp;
    124  1.3.2.2  bouyer 	int ms_unit;
    125  1.3.2.2  bouyer 
    126  1.3.2.2  bouyer 	cf = ms->ms_dev.dv_cfdata;
    127  1.3.2.2  bouyer 	ms_unit = ms->ms_dev.dv_unit;
    128  1.3.2.2  bouyer 	tp->t_sc  = ms;
    129  1.3.2.2  bouyer 	tp->t_dev = args->kmta_dev;
    130  1.3.2.2  bouyer 	ms->ms_cs = (struct zs_chanstate *)tp;
    131  1.3.2.2  bouyer         ms->ms_deviopen = sunmsiopen;
    132  1.3.2.2  bouyer         ms->ms_deviclose = NULL;
    133  1.3.2.2  bouyer 
    134  1.3.2.2  bouyer 	printf("\n");
    135  1.3.2.2  bouyer 
    136  1.3.2.2  bouyer 	/* Remove tty from system */
    137  1.3.2.2  bouyer 	tty_detach(tp);
    138  1.3.2.2  bouyer #if 0
    139  1.3.2.2  bouyer 	callout_stop(&tp->t_outq_ch);
    140  1.3.2.2  bouyer 	callout_stop(&tp->t_rstrt_ch);
    141  1.3.2.2  bouyer #endif
    142  1.3.2.2  bouyer 
    143  1.3.2.2  bouyer 	/* Initialize the speed, etc. */
    144  1.3.2.2  bouyer 	tp->t_line = 8;
    145  1.3.2.2  bouyer 	tp->t_oflag &= ~OPOST;
    146  1.3.2.2  bouyer 
    147  1.3.2.2  bouyer 	/* Initialize translator. */
    148  1.3.2.2  bouyer 	ms->ms_byteno = -1;
    149  1.3.2.2  bouyer }
    150  1.3.2.2  bouyer 
    151  1.3.2.2  bouyer /*
    152  1.3.2.2  bouyer  * Internal open routine.  This really should be inside com.c
    153  1.3.2.2  bouyer  * But I'm putting it here until we have a generic internal open
    154  1.3.2.2  bouyer  * mechanism.
    155  1.3.2.2  bouyer  */
    156  1.3.2.2  bouyer int
    157  1.3.2.2  bouyer sunmsiopen(dev, flags)
    158  1.3.2.2  bouyer 	struct device *dev;
    159  1.3.2.2  bouyer 	int flags;
    160  1.3.2.2  bouyer {
    161  1.3.2.2  bouyer 	struct ms_softc *ms = (void *) dev;
    162  1.3.2.2  bouyer 	struct tty *tp = (struct tty *)ms->ms_cs;
    163  1.3.2.2  bouyer 	struct proc *p = curproc;
    164  1.3.2.2  bouyer 	struct termios t;
    165  1.3.2.2  bouyer 	int maj;
    166  1.3.2.2  bouyer 	int error;
    167  1.3.2.2  bouyer 
    168  1.3.2.2  bouyer 	maj = major(tp->t_dev);
    169  1.3.2.2  bouyer 	if (p == NULL)
    170  1.3.2.2  bouyer 		p = &proc0;
    171  1.3.2.2  bouyer 
    172  1.3.2.2  bouyer 	/* Open the lower device */
    173  1.3.2.2  bouyer 	if ((error = (*cdevsw[maj].d_open)(tp->t_dev, O_NONBLOCK|flags,
    174  1.3.2.2  bouyer 					   0/* ignored? */, p)) != 0)
    175  1.3.2.2  bouyer 		return (error);
    176  1.3.2.2  bouyer 
    177  1.3.2.2  bouyer 	/* Now configure it for the console. */
    178  1.3.2.2  bouyer 	tp->t_ospeed = 0;
    179  1.3.2.2  bouyer 	t.c_ispeed = sunms_bps;
    180  1.3.2.2  bouyer 	t.c_ospeed = sunms_bps;
    181  1.3.2.2  bouyer 	t.c_cflag =  CLOCAL;
    182  1.3.2.2  bouyer 	(*tp->t_param)(tp, &t);
    183  1.3.2.2  bouyer 
    184  1.3.2.2  bouyer 	return (0);
    185  1.3.2.2  bouyer }
    186  1.3.2.2  bouyer 
    187  1.3.2.2  bouyer int
    188  1.3.2.2  bouyer sunmsinput(c, tp)
    189  1.3.2.2  bouyer 	int c;
    190  1.3.2.2  bouyer 	struct tty *tp;
    191  1.3.2.2  bouyer {
    192  1.3.2.2  bouyer 	struct ms_softc *ms = (struct ms_softc *)tp->t_sc;
    193  1.3.2.2  bouyer 
    194  1.3.2.2  bouyer 	if (c & TTY_ERRORMASK) c = -1;
    195  1.3.2.2  bouyer 	else c &= TTY_CHARMASK;
    196  1.3.2.2  bouyer 
    197  1.3.2.2  bouyer 	/* Pass this up to the "middle" layer. */
    198  1.3.2.2  bouyer 	ms_input(ms, c);
    199  1.3.2.2  bouyer 	return (0);
    200  1.3.2.2  bouyer }
    201  1.3.2.2  bouyer #endif
    202