Home | History | Annotate | Line # | Download | only in dec
dzms.c revision 1.17
      1  1.17        ad /*	$NetBSD: dzms.c,v 1.17 2007/10/19 11:59:40 ad Exp $	*/
      2   1.1     ragge 
      3   1.1     ragge /*
      4   1.1     ragge  * Copyright (c) 1992, 1993
      5   1.1     ragge  *	The Regents of the University of California.  All rights reserved.
      6   1.1     ragge  *
      7   1.1     ragge  * This software was developed by the Computer Systems Engineering group
      8   1.1     ragge  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9   1.1     ragge  * contributed to Berkeley.
     10   1.1     ragge  *
     11   1.1     ragge  * All advertising materials mentioning features or use of this software
     12   1.1     ragge  * must display the following acknowledgement:
     13   1.1     ragge  *	This product includes software developed by the University of
     14   1.1     ragge  *	California, Lawrence Berkeley Laboratory.
     15   1.1     ragge  *
     16   1.1     ragge  * Redistribution and use in source and binary forms, with or without
     17   1.1     ragge  * modification, are permitted provided that the following conditions
     18   1.1     ragge  * are met:
     19   1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     20   1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     21   1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     22   1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     23   1.1     ragge  *    documentation and/or other materials provided with the distribution.
     24  1.10       agc  * 3. Neither the name of the University nor the names of its contributors
     25   1.1     ragge  *    may be used to endorse or promote products derived from this software
     26   1.1     ragge  *    without specific prior written permission.
     27   1.1     ragge  *
     28   1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29   1.1     ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30   1.1     ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31   1.1     ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32   1.1     ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33   1.1     ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34   1.1     ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35   1.1     ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36   1.1     ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37   1.1     ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38   1.1     ragge  * SUCH DAMAGE.
     39   1.1     ragge  *
     40   1.1     ragge  *	@(#)ms.c	8.1 (Berkeley) 6/11/93
     41   1.1     ragge  */
     42   1.1     ragge 
     43   1.1     ragge /*
     44   1.1     ragge  * VSXXX mice attached to line 1 of the DZ*
     45   1.1     ragge  */
     46   1.2     lukem 
     47   1.2     lukem #include <sys/cdefs.h>
     48  1.17        ad __KERNEL_RCSID(0, "$NetBSD: dzms.c,v 1.17 2007/10/19 11:59:40 ad Exp $");
     49   1.1     ragge 
     50   1.1     ragge #include <sys/param.h>
     51   1.1     ragge #include <sys/systm.h>
     52   1.1     ragge #include <sys/device.h>
     53   1.1     ragge #include <sys/ioctl.h>
     54   1.1     ragge #include <sys/syslog.h>
     55   1.6        ad #include <sys/kernel.h>
     56   1.6        ad #include <sys/proc.h>
     57   1.6        ad #include <sys/tty.h>
     58   1.1     ragge 
     59  1.17        ad #include <sys/bus.h>
     60   1.1     ragge 
     61   1.3        ad #include <dev/dec/dzreg.h>
     62   1.3        ad #include <dev/dec/dzvar.h>
     63   1.1     ragge #include <dev/dec/dzkbdvar.h>
     64   1.1     ragge #include <dev/dec/lk201.h>
     65   1.1     ragge 
     66   1.1     ragge #include <dev/wscons/wsconsio.h>
     67   1.1     ragge #include <dev/wscons/wsmousevar.h>
     68   1.1     ragge 
     69   1.1     ragge #include "locators.h"
     70   1.1     ragge 
     71   1.1     ragge struct dzms_softc {		/* driver status information */
     72   1.1     ragge 	struct	device dzms_dev;	/* required first: base device */
     73   1.1     ragge 	struct	dz_linestate *dzms_ls;
     74   1.1     ragge 
     75   1.1     ragge 	int sc_enabled;		/* input enabled? */
     76   1.6        ad 	int sc_selftest;
     77   1.1     ragge 
     78   1.1     ragge 	int inputstate;
     79   1.1     ragge 	u_int buttons;
     80   1.6        ad 	int dx, dy;
     81   1.1     ragge 
     82   1.1     ragge 	struct device *sc_wsmousedev;
     83   1.1     ragge };
     84   1.1     ragge 
     85  1.11     perry static int  dzms_match(struct device *, struct cfdata *, void *);
     86  1.11     perry static void dzms_attach(struct device *, struct device *, void *);
     87  1.11     perry static int dzms_input(void *, int);
     88   1.1     ragge 
     89   1.8   thorpej CFATTACH_DECL(dzms, sizeof(struct dzms_softc),
     90   1.9   thorpej     dzms_match, dzms_attach, NULL, NULL);
     91   1.1     ragge 
     92  1.11     perry static int  dzms_enable(void *);
     93  1.16  christos static int  dzms_ioctl(void *, u_long, void *, int, struct lwp *);
     94  1.11     perry static void dzms_disable(void *);
     95   1.1     ragge 
     96   1.1     ragge const struct wsmouse_accessops dzms_accessops = {
     97   1.1     ragge 	dzms_enable,
     98   1.1     ragge 	dzms_ioctl,
     99   1.1     ragge 	dzms_disable,
    100   1.1     ragge };
    101   1.1     ragge 
    102   1.1     ragge static int
    103   1.1     ragge dzms_match(parent, cf, aux)
    104   1.1     ragge 	struct device *parent;
    105   1.1     ragge 	struct cfdata *cf;
    106   1.1     ragge 	void *aux;
    107   1.1     ragge {
    108   1.1     ragge 	struct dzkm_attach_args *daa = aux;
    109   1.1     ragge 
    110   1.1     ragge 	/* Exact match is better than wildcard. */
    111   1.1     ragge 	if (cf->cf_loc[DZCF_LINE] == daa->daa_line)
    112   1.1     ragge 		return 2;
    113   1.1     ragge 
    114   1.1     ragge 	/* This driver accepts wildcard. */
    115   1.1     ragge 	if (cf->cf_loc[DZCF_LINE] == DZCF_LINE_DEFAULT)
    116   1.1     ragge 		return 1;
    117   1.1     ragge 
    118   1.1     ragge 	return 0;
    119   1.1     ragge }
    120   1.1     ragge 
    121   1.1     ragge static void
    122   1.1     ragge dzms_attach(parent, self, aux)
    123   1.1     ragge 	struct device *parent, *self;
    124   1.1     ragge 	void *aux;
    125   1.1     ragge {
    126  1.14   thorpej 	struct dz_softc *dz = device_private(parent);
    127  1.14   thorpej 	struct dzms_softc *dzms = device_private(self);
    128   1.1     ragge 	struct dzkm_attach_args *daa = aux;
    129   1.1     ragge 	struct dz_linestate *ls;
    130   1.1     ragge 	struct wsmousedev_attach_args a;
    131   1.1     ragge 
    132   1.1     ragge 	dz->sc_dz[daa->daa_line].dz_catch = dzms_input;
    133   1.1     ragge 	dz->sc_dz[daa->daa_line].dz_private = dzms;
    134   1.1     ragge 	ls = &dz->sc_dz[daa->daa_line];
    135   1.1     ragge 	dzms->dzms_ls = ls;
    136   1.1     ragge 
    137   1.1     ragge 	printf("\n");
    138   1.1     ragge 
    139   1.1     ragge 	a.accessops = &dzms_accessops;
    140   1.1     ragge 	a.accesscookie = dzms;
    141   1.1     ragge 
    142   1.1     ragge 	dzms->sc_enabled = 0;
    143   1.6        ad 	dzms->sc_selftest = 0;
    144   1.1     ragge 	dzms->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
    145   1.1     ragge }
    146   1.1     ragge 
    147   1.1     ragge static int
    148   1.1     ragge dzms_enable(v)
    149   1.1     ragge 	void *v;
    150   1.1     ragge {
    151   1.1     ragge 	struct dzms_softc *sc = v;
    152   1.1     ragge 
    153   1.1     ragge 	if (sc->sc_enabled)
    154   1.1     ragge 		return EBUSY;
    155   1.1     ragge 
    156   1.6        ad 	sc->sc_selftest = 4; /* wait for 4 byte reply upto 1/2 sec */
    157   1.1     ragge 	dzputc(sc->dzms_ls, MOUSE_SELF_TEST);
    158   1.6        ad 	(void)tsleep(dzms_enable, TTIPRI, "dzmsopen", hz / 2);
    159   1.6        ad 	if (sc->sc_selftest != 0) {
    160   1.6        ad 		sc->sc_selftest = 0;
    161   1.6        ad 		return ENXIO;
    162   1.1     ragge 	}
    163   1.6        ad 	DELAY(150);
    164   1.6        ad 	dzputc(sc->dzms_ls, MOUSE_INCREMENTAL);
    165   1.6        ad 	sc->sc_enabled = 1;
    166   1.1     ragge 	sc->inputstate = 0;
    167   1.1     ragge 	return 0;
    168   1.1     ragge }
    169   1.1     ragge 
    170   1.1     ragge static void
    171   1.1     ragge dzms_disable(v)
    172   1.1     ragge 	void *v;
    173   1.1     ragge {
    174   1.1     ragge 	struct dzms_softc *sc = v;
    175   1.1     ragge 
    176   1.1     ragge 	sc->sc_enabled = 0;
    177   1.1     ragge }
    178   1.1     ragge 
    179   1.1     ragge static int
    180  1.13  christos dzms_ioctl(v, cmd, data, flag, l)
    181   1.1     ragge 	void *v;
    182   1.1     ragge 	u_long cmd;
    183  1.16  christos 	void *data;
    184   1.1     ragge 	int flag;
    185  1.13  christos 	struct lwp *l;
    186   1.1     ragge {
    187   1.1     ragge 	if (cmd == WSMOUSEIO_GTYPE) {
    188   1.1     ragge 		*(u_int *)data = WSMOUSE_TYPE_VSXXX;
    189   1.1     ragge 		return 0;
    190   1.1     ragge 	}
    191   1.4    atatat 	return EPASSTHROUGH;
    192   1.1     ragge }
    193   1.1     ragge 
    194   1.1     ragge static int
    195   1.1     ragge dzms_input(vsc, data)
    196   1.1     ragge 	void *vsc;
    197   1.1     ragge 	int data;
    198   1.1     ragge {
    199   1.1     ragge 	struct dzms_softc *sc = vsc;
    200   1.1     ragge 
    201   1.6        ad 	if (sc->sc_enabled == 0) {
    202   1.6        ad 		if (sc->sc_selftest > 0) {
    203   1.6        ad 			sc->sc_selftest -= 1;
    204   1.6        ad 			if (sc->sc_selftest == 0)
    205   1.6        ad 				wakeup(dzms_enable);
    206   1.1     ragge 		}
    207   1.6        ad 		return (1);
    208   1.1     ragge 	}
    209   1.1     ragge 
    210   1.1     ragge #define WSMS_BUTTON1    0x01
    211   1.1     ragge #define WSMS_BUTTON2    0x02
    212   1.1     ragge #define WSMS_BUTTON3    0x04
    213   1.1     ragge 
    214   1.1     ragge 	if ((data & MOUSE_START_FRAME) != 0)
    215   1.1     ragge 		sc->inputstate = 1;
    216   1.1     ragge 	else
    217   1.1     ragge 		sc->inputstate++;
    218   1.1     ragge 
    219   1.1     ragge 	if (sc->inputstate == 1) {
    220   1.1     ragge 		sc->buttons = 0;
    221   1.1     ragge 		if ((data & LEFT_BUTTON) != 0)
    222   1.1     ragge 			sc->buttons |= WSMS_BUTTON1;
    223   1.1     ragge 		if ((data & MIDDLE_BUTTON) != 0)
    224   1.1     ragge 			sc->buttons |= WSMS_BUTTON2;
    225   1.1     ragge 		if ((data & RIGHT_BUTTON) != 0)
    226   1.1     ragge 			sc->buttons |= WSMS_BUTTON3;
    227  1.12     perry 
    228   1.1     ragge 		sc->dx = data & MOUSE_X_SIGN;
    229   1.1     ragge 		sc->dy = data & MOUSE_Y_SIGN;
    230   1.1     ragge 	} else if (sc->inputstate == 2) {
    231   1.1     ragge 		if (sc->dx == 0)
    232   1.1     ragge 			sc->dx = -data;
    233   1.1     ragge 		else
    234   1.1     ragge 			sc->dx = data;
    235   1.1     ragge 	} else if (sc->inputstate == 3) {
    236   1.1     ragge 		sc->inputstate = 0;
    237   1.1     ragge 		if (sc->dy == 0)
    238   1.1     ragge 			sc->dy = -data;
    239   1.1     ragge 		else
    240   1.1     ragge 			sc->dy = data;
    241  1.15    plunky 		wsmouse_input(sc->sc_wsmousedev,
    242  1.15    plunky 				sc->buttons,
    243  1.15    plunky 		    		sc->dx, sc->dy, 0, 0,
    244  1.15    plunky 				WSMOUSE_INPUT_DELTA);
    245   1.1     ragge 	}
    246   1.1     ragge 
    247   1.1     ragge 	return(1);
    248   1.1     ragge }
    249   1.1     ragge 
    250