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