Home | History | Annotate | Line # | Download | only in sun
sunms.c revision 1.29.2.1
      1  1.29.2.1      yamt /*	$NetBSD: sunms.c,v 1.29.2.1 2009/05/16 10:41:45 yamt 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.17       agc  * 3. Neither the name of the University nor the names of its contributors
     25       1.1       eeh  *    may be used to endorse or promote products derived from this software
     26       1.1       eeh  *    without specific prior written permission.
     27       1.1       eeh  *
     28       1.1       eeh  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29       1.1       eeh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30       1.1       eeh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31       1.1       eeh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32       1.1       eeh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33       1.1       eeh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34       1.1       eeh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35       1.1       eeh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36       1.1       eeh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37       1.1       eeh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38       1.1       eeh  * SUCH DAMAGE.
     39       1.1       eeh  *
     40       1.1       eeh  *	@(#)ms.c	8.1 (Berkeley) 6/11/93
     41       1.1       eeh  */
     42       1.1       eeh 
     43       1.1       eeh /*
     44       1.1       eeh  * Mouse driver (/dev/mouse)
     45       1.1       eeh  */
     46       1.1       eeh 
     47       1.1       eeh /*
     48       1.1       eeh  * Zilog Z8530 Dual UART driver (mouse interface)
     49       1.1       eeh  *
     50       1.1       eeh  * This is the "slave" driver that will be attached to
     51       1.1       eeh  * the "zsc" driver for a Sun mouse.
     52       1.1       eeh  */
     53       1.5     lukem 
     54       1.5     lukem #include <sys/cdefs.h>
     55  1.29.2.1      yamt __KERNEL_RCSID(0, "$NetBSD: sunms.c,v 1.29.2.1 2009/05/16 10:41:45 yamt Exp $");
     56       1.1       eeh 
     57       1.1       eeh #include <sys/param.h>
     58       1.1       eeh #include <sys/systm.h>
     59       1.1       eeh #include <sys/conf.h>
     60       1.1       eeh #include <sys/device.h>
     61       1.1       eeh #include <sys/ioctl.h>
     62       1.1       eeh #include <sys/kernel.h>
     63       1.1       eeh #include <sys/proc.h>
     64       1.1       eeh #include <sys/signal.h>
     65       1.1       eeh #include <sys/signalvar.h>
     66       1.1       eeh #include <sys/time.h>
     67       1.1       eeh #include <sys/select.h>
     68       1.1       eeh #include <sys/syslog.h>
     69       1.1       eeh #include <sys/fcntl.h>
     70       1.1       eeh #include <sys/tty.h>
     71       1.1       eeh 
     72       1.1       eeh #include <machine/vuid_event.h>
     73       1.1       eeh 
     74       1.1       eeh #include <dev/sun/event_var.h>
     75       1.1       eeh #include <dev/sun/msvar.h>
     76       1.1       eeh #include <dev/sun/kbd_ms_ttyvar.h>
     77       1.1       eeh 
     78      1.14    petrov #include <dev/wscons/wsconsio.h>
     79      1.14    petrov #include <dev/wscons/wsmousevar.h>
     80      1.14    petrov 
     81       1.1       eeh #include "ms.h"
     82      1.14    petrov #include "wsmouse.h"
     83       1.1       eeh #if NMS > 0
     84       1.1       eeh 
     85       1.7        pk #ifdef SUN_MS_BPS
     86       1.7        pk int	sunms_bps = SUN_MS_BPS;
     87       1.7        pk #else
     88       1.7        pk int	sunms_bps = MS_DEFAULT_BPS;
     89       1.7        pk #endif
     90       1.1       eeh 
     91      1.28   tsutsui static int	sunms_match(device_t, cfdata_t, void *);
     92      1.28   tsutsui static void	sunms_attach(device_t, device_t, void *);
     93  1.29.2.1      yamt static int	sunmsiopen(device_t, int mode);
     94       1.1       eeh int	sunmsinput(int, struct tty *);
     95       1.1       eeh 
     96      1.28   tsutsui CFATTACH_DECL_NEW(ms_tty, sizeof(struct ms_softc),
     97      1.11   thorpej     sunms_match, sunms_attach, NULL, NULL);
     98       1.1       eeh 
     99      1.20   thorpej struct linesw sunms_disc = {
    100      1.20   thorpej 	.l_name = "sunms",
    101      1.20   thorpej 	.l_open = ttylopen,
    102      1.20   thorpej 	.l_close = ttylclose,
    103      1.20   thorpej 	.l_read = ttyerrio,
    104      1.20   thorpej 	.l_write = ttyerrio,
    105      1.20   thorpej 	.l_ioctl = ttynullioctl,
    106      1.20   thorpej 	.l_rint = sunmsinput,
    107      1.20   thorpej 	.l_start = ttstart,
    108      1.20   thorpej 	.l_modem = nullmodem,
    109      1.20   thorpej 	.l_poll = ttpoll
    110      1.20   thorpej };
    111       1.3       eeh 
    112      1.14    petrov int	sunms_enable(void *);
    113      1.26  christos int	sunms_ioctl(void *, u_long, void *, int, struct lwp *);
    114      1.14    petrov void	sunms_disable(void *);
    115      1.14    petrov 
    116      1.14    petrov const struct wsmouse_accessops	sunms_accessops = {
    117      1.14    petrov 	sunms_enable,
    118      1.14    petrov 	sunms_ioctl,
    119      1.14    petrov 	sunms_disable,
    120      1.14    petrov };
    121      1.14    petrov 
    122       1.1       eeh /*
    123       1.1       eeh  * ms_match: how is this zs channel configured?
    124       1.1       eeh  */
    125       1.2        pk int
    126      1.28   tsutsui sunms_match(device_t parent, cfdata_t cf, void *aux)
    127       1.1       eeh {
    128       1.1       eeh 	struct kbd_ms_tty_attach_args *args = aux;
    129       1.1       eeh 
    130       1.1       eeh 	if (sunms_bps == 0)
    131       1.1       eeh 		return 0;
    132       1.1       eeh 
    133       1.1       eeh 	if (strcmp(args->kmta_name, "mouse") == 0)
    134       1.1       eeh 		return (1);
    135       1.1       eeh 
    136       1.1       eeh 	return 0;
    137       1.1       eeh }
    138       1.1       eeh 
    139       1.2        pk void
    140      1.28   tsutsui sunms_attach(device_t parent, device_t self, void *aux)
    141       1.1       eeh {
    142      1.24   thorpej 	struct ms_softc *ms = device_private(self);
    143       1.1       eeh 	struct kbd_ms_tty_attach_args *args = aux;
    144  1.29.2.1      yamt 	cfdata_t cf;
    145       1.1       eeh 	struct tty *tp = args->kmta_tp;
    146       1.1       eeh 	int ms_unit;
    147      1.14    petrov #if NWSMOUSE > 0
    148      1.14    petrov 	struct wsmousedev_attach_args a;
    149      1.14    petrov #endif
    150       1.1       eeh 
    151      1.28   tsutsui 	ms->ms_dev = self;
    152      1.28   tsutsui 	cf = device_cfdata(self);
    153      1.28   tsutsui 	ms_unit = device_unit(self);
    154       1.1       eeh 	tp->t_sc  = ms;
    155       1.1       eeh 	tp->t_dev = args->kmta_dev;
    156      1.28   tsutsui 	ms->ms_priv = tp;
    157      1.28   tsutsui 	ms->ms_deviopen = sunmsiopen;
    158      1.28   tsutsui 	ms->ms_deviclose = NULL;
    159       1.1       eeh 
    160      1.28   tsutsui 	aprint_normal("\n");
    161       1.1       eeh 
    162       1.1       eeh 	/* Initialize the speed, etc. */
    163      1.20   thorpej 	if (ttyldisc_attach(&sunms_disc) != 0)
    164       1.3       eeh 		panic("sunms_attach: sunms_disc");
    165      1.20   thorpej 	ttyldisc_release(tp->t_linesw);
    166      1.20   thorpej 	tp->t_linesw = ttyldisc_lookup(sunms_disc.l_name);
    167      1.20   thorpej 	KASSERT(tp->t_linesw == &sunms_disc);
    168       1.1       eeh 	tp->t_oflag &= ~OPOST;
    169       1.1       eeh 
    170       1.1       eeh 	/* Initialize translator. */
    171       1.1       eeh 	ms->ms_byteno = -1;
    172      1.14    petrov 
    173      1.14    petrov #if NWSMOUSE > 0
    174      1.14    petrov 	/*
    175      1.14    petrov 	 * attach wsmouse
    176      1.14    petrov 	 */
    177      1.14    petrov 	a.accessops = &sunms_accessops;
    178      1.14    petrov 	a.accesscookie = ms;
    179      1.14    petrov 
    180      1.14    petrov 	ms->ms_wsmousedev = config_found(self, &a, wsmousedevprint);
    181      1.14    petrov #endif
    182       1.1       eeh }
    183       1.1       eeh 
    184       1.1       eeh /*
    185       1.1       eeh  * Internal open routine.  This really should be inside com.c
    186       1.1       eeh  * But I'm putting it here until we have a generic internal open
    187       1.1       eeh  * mechanism.
    188       1.1       eeh  */
    189       1.1       eeh int
    190      1.28   tsutsui sunmsiopen(device_t dev, int flags)
    191       1.1       eeh {
    192      1.28   tsutsui 	struct ms_softc *ms = device_private(dev);
    193      1.28   tsutsui 	struct tty *tp = ms->ms_priv;
    194      1.21  christos 	struct lwp *l = curlwp ? curlwp : &lwp0;
    195       1.1       eeh 	struct termios t;
    196       1.2        pk 	int error;
    197       1.1       eeh 
    198       1.1       eeh 	/* Open the lower device */
    199      1.27        ad 	if ((error = cdev_open(tp->t_dev, O_NONBLOCK|flags,
    200      1.21  christos 				     0/* ignored? */, l)) != 0)
    201       1.2        pk 		return (error);
    202       1.1       eeh 
    203       1.1       eeh 	/* Now configure it for the console. */
    204       1.1       eeh 	tp->t_ospeed = 0;
    205       1.1       eeh 	t.c_ispeed = sunms_bps;
    206       1.1       eeh 	t.c_ospeed = sunms_bps;
    207       1.6  fredette 	t.c_cflag =  CLOCAL|CS8;
    208       1.1       eeh 	(*tp->t_param)(tp, &t);
    209       1.1       eeh 
    210       1.2        pk 	return (0);
    211       1.1       eeh }
    212       1.1       eeh 
    213       1.1       eeh int
    214      1.28   tsutsui sunmsinput(int c, struct tty *tp)
    215       1.1       eeh {
    216      1.28   tsutsui 	struct ms_softc *ms = tp->t_sc;
    217       1.1       eeh 
    218       1.1       eeh 	if (c & TTY_ERRORMASK) c = -1;
    219       1.1       eeh 	else c &= TTY_CHARMASK;
    220       1.1       eeh 
    221       1.1       eeh 	/* Pass this up to the "middle" layer. */
    222       1.1       eeh 	ms_input(ms, c);
    223       1.2        pk 	return (0);
    224      1.14    petrov }
    225      1.14    petrov 
    226      1.14    petrov int
    227      1.28   tsutsui sunms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    228      1.14    petrov {
    229      1.14    petrov /*	struct ms_softc *sc = v; */
    230      1.14    petrov 
    231      1.14    petrov 	switch (cmd) {
    232      1.14    petrov 	case WSMOUSEIO_GTYPE:
    233      1.14    petrov 		*(u_int *)data = WSMOUSE_TYPE_PS2; /* XXX  */
    234      1.14    petrov 		break;
    235      1.19     perry 
    236      1.14    petrov 	default:
    237      1.14    petrov 		return (EPASSTHROUGH);
    238      1.14    petrov 	}
    239      1.14    petrov 	return (0);
    240      1.14    petrov }
    241      1.14    petrov 
    242      1.14    petrov int
    243      1.28   tsutsui sunms_enable(void *v)
    244      1.14    petrov {
    245      1.14    petrov 	struct ms_softc *ms = v;
    246      1.14    petrov 	int err;
    247      1.14    petrov 	int s;
    248      1.14    petrov 
    249      1.14    petrov 	if (ms->ms_ready)
    250      1.14    petrov 		return EBUSY;
    251      1.14    petrov 
    252      1.29    martin 	err = sunmsiopen(ms->ms_dev, 0);
    253      1.14    petrov 	if (err)
    254      1.14    petrov 		return err;
    255      1.14    petrov 
    256      1.14    petrov 	s = spltty();
    257      1.14    petrov 	ms->ms_ready = 2;
    258      1.14    petrov 	splx(s);
    259      1.14    petrov 
    260      1.14    petrov 	return 0;
    261      1.14    petrov }
    262      1.14    petrov 
    263      1.14    petrov void
    264      1.28   tsutsui sunms_disable(void *v)
    265      1.14    petrov {
    266      1.14    petrov 	struct ms_softc *ms = v;
    267      1.14    petrov 	int s;
    268      1.14    petrov 
    269      1.14    petrov 	s = spltty();
    270      1.14    petrov 	ms->ms_ready = 0;
    271      1.14    petrov 	splx(s);
    272       1.1       eeh }
    273       1.1       eeh #endif
    274