Home | History | Annotate | Line # | Download | only in dec
dzms.c revision 1.25
      1  1.25   tsutsui /*	$NetBSD: dzms.c,v 1.25 2024/02/02 15:44:43 tsutsui 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.25   tsutsui __KERNEL_RCSID(0, "$NetBSD: dzms.c,v 1.25 2024/02/02 15:44:43 tsutsui 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	dz_linestate *dzms_ls;
     73   1.1     ragge 
     74   1.1     ragge 	int sc_enabled;		/* input enabled? */
     75   1.6        ad 	int sc_selftest;
     76   1.1     ragge 
     77   1.1     ragge 	int inputstate;
     78   1.1     ragge 	u_int buttons;
     79   1.6        ad 	int dx, dy;
     80   1.1     ragge 
     81  1.21    cegger 	device_t sc_wsmousedev;
     82   1.1     ragge };
     83   1.1     ragge 
     84  1.21    cegger static int  dzms_match(device_t, cfdata_t, void *);
     85  1.21    cegger static void dzms_attach(device_t, device_t, void *);
     86  1.11     perry static int dzms_input(void *, int);
     87   1.1     ragge 
     88  1.22       chs CFATTACH_DECL_NEW(dzms, sizeof(struct dzms_softc),
     89   1.9   thorpej     dzms_match, dzms_attach, NULL, NULL);
     90   1.1     ragge 
     91  1.11     perry static int  dzms_enable(void *);
     92  1.16  christos static int  dzms_ioctl(void *, u_long, void *, int, struct lwp *);
     93  1.11     perry static void dzms_disable(void *);
     94   1.1     ragge 
     95   1.1     ragge const struct wsmouse_accessops dzms_accessops = {
     96   1.1     ragge 	dzms_enable,
     97   1.1     ragge 	dzms_ioctl,
     98   1.1     ragge 	dzms_disable,
     99   1.1     ragge };
    100   1.1     ragge 
    101   1.1     ragge static int
    102  1.21    cegger dzms_match(device_t parent, cfdata_t cf, void *aux)
    103   1.1     ragge {
    104   1.1     ragge 	struct dzkm_attach_args *daa = aux;
    105   1.1     ragge 
    106   1.1     ragge 	/* Exact match is better than wildcard. */
    107   1.1     ragge 	if (cf->cf_loc[DZCF_LINE] == daa->daa_line)
    108   1.1     ragge 		return 2;
    109   1.1     ragge 
    110   1.1     ragge 	/* This driver accepts wildcard. */
    111   1.1     ragge 	if (cf->cf_loc[DZCF_LINE] == DZCF_LINE_DEFAULT)
    112   1.1     ragge 		return 1;
    113   1.1     ragge 
    114   1.1     ragge 	return 0;
    115   1.1     ragge }
    116   1.1     ragge 
    117   1.1     ragge static void
    118  1.21    cegger dzms_attach(device_t parent, device_t self, void *aux)
    119   1.1     ragge {
    120  1.14   thorpej 	struct dz_softc *dz = device_private(parent);
    121  1.14   thorpej 	struct dzms_softc *dzms = device_private(self);
    122   1.1     ragge 	struct dzkm_attach_args *daa = aux;
    123   1.1     ragge 	struct dz_linestate *ls;
    124   1.1     ragge 	struct wsmousedev_attach_args a;
    125   1.1     ragge 
    126   1.1     ragge 	dz->sc_dz[daa->daa_line].dz_catch = dzms_input;
    127   1.1     ragge 	dz->sc_dz[daa->daa_line].dz_private = dzms;
    128   1.1     ragge 	ls = &dz->sc_dz[daa->daa_line];
    129   1.1     ragge 	dzms->dzms_ls = ls;
    130   1.1     ragge 
    131  1.25   tsutsui 	aprint_normal("\n");
    132   1.1     ragge 
    133   1.1     ragge 	a.accessops = &dzms_accessops;
    134   1.1     ragge 	a.accesscookie = dzms;
    135   1.1     ragge 
    136   1.1     ragge 	dzms->sc_enabled = 0;
    137   1.6        ad 	dzms->sc_selftest = 0;
    138  1.23   thorpej 	dzms->sc_wsmousedev = config_found(self, &a, wsmousedevprint,
    139  1.24   thorpej 	    CFARGS_NONE);
    140   1.1     ragge }
    141   1.1     ragge 
    142   1.1     ragge static int
    143  1.18       dsl dzms_enable(void *v)
    144   1.1     ragge {
    145   1.1     ragge 	struct dzms_softc *sc = v;
    146   1.1     ragge 
    147   1.1     ragge 	if (sc->sc_enabled)
    148   1.1     ragge 		return EBUSY;
    149   1.1     ragge 
    150   1.6        ad 	sc->sc_selftest = 4; /* wait for 4 byte reply upto 1/2 sec */
    151   1.1     ragge 	dzputc(sc->dzms_ls, MOUSE_SELF_TEST);
    152   1.6        ad 	(void)tsleep(dzms_enable, TTIPRI, "dzmsopen", hz / 2);
    153   1.6        ad 	if (sc->sc_selftest != 0) {
    154   1.6        ad 		sc->sc_selftest = 0;
    155   1.6        ad 		return ENXIO;
    156   1.1     ragge 	}
    157   1.6        ad 	DELAY(150);
    158   1.6        ad 	dzputc(sc->dzms_ls, MOUSE_INCREMENTAL);
    159   1.6        ad 	sc->sc_enabled = 1;
    160   1.1     ragge 	sc->inputstate = 0;
    161   1.1     ragge 	return 0;
    162   1.1     ragge }
    163   1.1     ragge 
    164   1.1     ragge static void
    165  1.18       dsl dzms_disable(void *v)
    166   1.1     ragge {
    167   1.1     ragge 	struct dzms_softc *sc = v;
    168   1.1     ragge 
    169   1.1     ragge 	sc->sc_enabled = 0;
    170   1.1     ragge }
    171   1.1     ragge 
    172   1.1     ragge static int
    173  1.18       dsl dzms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
    174   1.1     ragge {
    175   1.1     ragge 	if (cmd == WSMOUSEIO_GTYPE) {
    176   1.1     ragge 		*(u_int *)data = WSMOUSE_TYPE_VSXXX;
    177   1.1     ragge 		return 0;
    178   1.1     ragge 	}
    179   1.4    atatat 	return EPASSTHROUGH;
    180   1.1     ragge }
    181   1.1     ragge 
    182   1.1     ragge static int
    183  1.18       dsl dzms_input(void *vsc, int data)
    184   1.1     ragge {
    185   1.1     ragge 	struct dzms_softc *sc = vsc;
    186   1.1     ragge 
    187   1.6        ad 	if (sc->sc_enabled == 0) {
    188   1.6        ad 		if (sc->sc_selftest > 0) {
    189   1.6        ad 			sc->sc_selftest -= 1;
    190   1.6        ad 			if (sc->sc_selftest == 0)
    191   1.6        ad 				wakeup(dzms_enable);
    192   1.1     ragge 		}
    193   1.6        ad 		return (1);
    194   1.1     ragge 	}
    195   1.1     ragge 
    196   1.1     ragge #define WSMS_BUTTON1    0x01
    197   1.1     ragge #define WSMS_BUTTON2    0x02
    198   1.1     ragge #define WSMS_BUTTON3    0x04
    199   1.1     ragge 
    200   1.1     ragge 	if ((data & MOUSE_START_FRAME) != 0)
    201   1.1     ragge 		sc->inputstate = 1;
    202   1.1     ragge 	else
    203   1.1     ragge 		sc->inputstate++;
    204   1.1     ragge 
    205   1.1     ragge 	if (sc->inputstate == 1) {
    206   1.1     ragge 		sc->buttons = 0;
    207   1.1     ragge 		if ((data & LEFT_BUTTON) != 0)
    208   1.1     ragge 			sc->buttons |= WSMS_BUTTON1;
    209   1.1     ragge 		if ((data & MIDDLE_BUTTON) != 0)
    210   1.1     ragge 			sc->buttons |= WSMS_BUTTON2;
    211   1.1     ragge 		if ((data & RIGHT_BUTTON) != 0)
    212   1.1     ragge 			sc->buttons |= WSMS_BUTTON3;
    213  1.12     perry 
    214   1.1     ragge 		sc->dx = data & MOUSE_X_SIGN;
    215   1.1     ragge 		sc->dy = data & MOUSE_Y_SIGN;
    216   1.1     ragge 	} else if (sc->inputstate == 2) {
    217   1.1     ragge 		if (sc->dx == 0)
    218   1.1     ragge 			sc->dx = -data;
    219   1.1     ragge 		else
    220   1.1     ragge 			sc->dx = data;
    221   1.1     ragge 	} else if (sc->inputstate == 3) {
    222   1.1     ragge 		sc->inputstate = 0;
    223   1.1     ragge 		if (sc->dy == 0)
    224   1.1     ragge 			sc->dy = -data;
    225   1.1     ragge 		else
    226   1.1     ragge 			sc->dy = data;
    227  1.15    plunky 		wsmouse_input(sc->sc_wsmousedev,
    228  1.15    plunky 				sc->buttons,
    229  1.15    plunky 		    		sc->dx, sc->dy, 0, 0,
    230  1.15    plunky 				WSMOUSE_INPUT_DELTA);
    231   1.1     ragge 	}
    232   1.1     ragge 
    233   1.1     ragge 	return(1);
    234   1.1     ragge }
    235   1.1     ragge 
    236