Home | History | Annotate | Line # | Download | only in dev
ms_hb.c revision 1.1.6.2
      1  1.1.6.2  jdolecek /*	$NetBSD: ms_hb.c,v 1.1.6.2 2002/10/10 18:34:34 jdolecek Exp $	*/
      2      1.1    tsubai 
      3      1.1    tsubai /*-
      4      1.1    tsubai  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
      5      1.1    tsubai  *
      6      1.1    tsubai  * Redistribution and use in source and binary forms, with or without
      7      1.1    tsubai  * modification, are permitted provided that the following conditions
      8      1.1    tsubai  * are met:
      9      1.1    tsubai  * 1. Redistributions of source code must retain the above copyright
     10      1.1    tsubai  *    notice, this list of conditions and the following disclaimer.
     11      1.1    tsubai  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1    tsubai  *    notice, this list of conditions and the following disclaimer in the
     13      1.1    tsubai  *    documentation and/or other materials provided with the distribution.
     14      1.1    tsubai  * 3. The name of the author may not be used to endorse or promote products
     15      1.1    tsubai  *    derived from this software without specific prior written permission.
     16      1.1    tsubai  *
     17      1.1    tsubai  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18      1.1    tsubai  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19      1.1    tsubai  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20      1.1    tsubai  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21      1.1    tsubai  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22      1.1    tsubai  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23      1.1    tsubai  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24      1.1    tsubai  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25      1.1    tsubai  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26      1.1    tsubai  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27      1.1    tsubai  */
     28      1.1    tsubai 
     29      1.1    tsubai #include <sys/param.h>
     30      1.1    tsubai #include <sys/device.h>
     31      1.1    tsubai #include <sys/systm.h>
     32      1.1    tsubai 
     33      1.1    tsubai #include <dev/wscons/wsconsio.h>
     34      1.1    tsubai #include <dev/wscons/wsmousevar.h>
     35      1.1    tsubai 
     36      1.1    tsubai #include <machine/autoconf.h>
     37      1.1    tsubai #include <machine/adrsmap.h>
     38      1.1    tsubai 
     39      1.1    tsubai struct msreg {
     40      1.1    tsubai 	u_char ms_data;
     41      1.1    tsubai 	u_char ms_stat;
     42      1.1    tsubai 	u_char ms_reset;
     43      1.1    tsubai 	u_char ms_init;
     44      1.1    tsubai };
     45      1.1    tsubai 
     46      1.1    tsubai struct ms_hb_softc {
     47      1.1    tsubai 	struct device sc_dev;
     48      1.1    tsubai 	volatile struct msreg *sc_reg;
     49      1.1    tsubai 	struct device *sc_wsmousedev;
     50      1.1    tsubai 	int sc_ndata;
     51      1.1    tsubai 	u_char sc_buf[3];
     52      1.1    tsubai };
     53      1.1    tsubai 
     54      1.1    tsubai int ms_hb_match(struct device *, struct cfdata *, void *);
     55      1.1    tsubai void ms_hb_attach(struct device *, struct device *, void *);
     56      1.1    tsubai int ms_hb_intr(void *);
     57      1.1    tsubai 
     58      1.1    tsubai int ms_hb_enable(void *);
     59      1.1    tsubai int ms_hb_ioctl(void *, u_long, caddr_t, int, struct proc *);
     60      1.1    tsubai void ms_hb_disable(void *);
     61      1.1    tsubai 
     62  1.1.6.2  jdolecek CFATTACH_DECL(ms_hb, sizeof(struct ms_hb_softc),
     63  1.1.6.2  jdolecek     ms_hb_match, ms_hb_attach, NULL, NULL);
     64      1.1    tsubai 
     65      1.1    tsubai struct wsmouse_accessops ms_hb_accessops = {
     66      1.1    tsubai 	ms_hb_enable,
     67      1.1    tsubai 	ms_hb_ioctl,
     68      1.1    tsubai 	ms_hb_disable
     69      1.1    tsubai };
     70      1.1    tsubai 
     71      1.1    tsubai int
     72      1.1    tsubai ms_hb_match(parent, cf, aux)
     73      1.1    tsubai 	struct device *parent;
     74      1.1    tsubai 	struct cfdata *cf;
     75      1.1    tsubai 	void *aux;
     76      1.1    tsubai {
     77      1.1    tsubai 	struct confargs *ca = aux;
     78      1.1    tsubai 
     79      1.1    tsubai 	if (strcmp(ca->ca_name, "ms") == 0)
     80      1.1    tsubai 		return 1;
     81      1.1    tsubai 
     82      1.1    tsubai 	return 0;
     83      1.1    tsubai }
     84      1.1    tsubai 
     85      1.1    tsubai void
     86      1.1    tsubai ms_hb_attach(parent, self, aux)
     87      1.1    tsubai 	struct device *parent, *self;
     88      1.1    tsubai 	void *aux;
     89      1.1    tsubai {
     90      1.1    tsubai 	struct ms_hb_softc *sc = (void *)self;
     91      1.1    tsubai 	volatile struct msreg *reg = (void *)self->dv_cfdata->cf_addr;
     92      1.1    tsubai 	int intr = self->dv_cfdata->cf_level;
     93      1.1    tsubai 	struct wsmousedev_attach_args aa;
     94      1.1    tsubai 
     95      1.1    tsubai 	if (intr == -1)
     96      1.1    tsubai 		intr = 2;
     97      1.1    tsubai 
     98      1.1    tsubai 	sc->sc_reg = reg;
     99      1.1    tsubai 	reg->ms_reset = 0x01;
    100      1.1    tsubai 	reg->ms_init = 0x80;	/* 1200 bps */
    101      1.1    tsubai 
    102      1.1    tsubai 	printf(" level %d\n", intr);
    103      1.1    tsubai 
    104      1.1    tsubai 	hb_intr_establish(intr, IPL_TTY, ms_hb_intr, sc);
    105      1.1    tsubai 
    106      1.1    tsubai 	aa.accessops = &ms_hb_accessops;
    107      1.1    tsubai 	aa.accesscookie = sc;
    108      1.1    tsubai 	sc->sc_wsmousedev = config_found(self, &aa, wsmousedevprint);
    109      1.1    tsubai }
    110      1.1    tsubai 
    111      1.1    tsubai int
    112      1.1    tsubai ms_hb_intr(v)
    113      1.1    tsubai 	void *v;
    114      1.1    tsubai {
    115      1.1    tsubai 	struct ms_hb_softc *sc = v;
    116      1.1    tsubai 	volatile struct msreg *reg = sc->sc_reg;
    117      1.1    tsubai 	volatile u_char *ien = (void *)INTEN0;
    118      1.1    tsubai 	int code, index, byte0, byte1, byte2;
    119      1.1    tsubai 	int button, dx, dy;
    120      1.1    tsubai 	int rv = 0;
    121      1.1    tsubai 
    122      1.1    tsubai 	*ien &= ~RX_MSINTE;
    123      1.1    tsubai 
    124      1.1    tsubai 	while (reg->ms_stat & RX_MSRDY) {
    125      1.1    tsubai 		rv = 1;
    126      1.1    tsubai 		code = reg->ms_data;
    127      1.1    tsubai 		index = sc->sc_ndata;
    128      1.1    tsubai 
    129      1.1    tsubai 		if (sc->sc_wsmousedev == NULL)
    130      1.1    tsubai 			continue;
    131      1.1    tsubai 
    132      1.1    tsubai 		if (code & 0x80) {
    133      1.1    tsubai 			sc->sc_buf[0] = code;
    134      1.1    tsubai 			sc->sc_ndata = 1;
    135      1.1    tsubai 			continue;
    136      1.1    tsubai 		}
    137      1.1    tsubai 
    138      1.1    tsubai 		if (index == 1) {
    139      1.1    tsubai 			sc->sc_buf[1] = code;
    140      1.1    tsubai 			sc->sc_ndata++;
    141      1.1    tsubai 			continue;
    142      1.1    tsubai 		}
    143      1.1    tsubai 
    144      1.1    tsubai 		if (index == 2) {
    145      1.1    tsubai 			sc->sc_buf[2] = code;
    146      1.1    tsubai 			sc->sc_ndata++;
    147      1.1    tsubai 
    148      1.1    tsubai 			byte0 = sc->sc_buf[0];
    149      1.1    tsubai 			byte1 = sc->sc_buf[1];
    150      1.1    tsubai 			byte2 = sc->sc_buf[2];
    151      1.1    tsubai 
    152      1.1    tsubai 			button = 0;
    153      1.1    tsubai 			if (byte0 & 0x01)
    154      1.1    tsubai 				button |= 1;
    155      1.1    tsubai 			if (byte0 & 0x04)
    156      1.1    tsubai 				button |= 2;
    157      1.1    tsubai 			if (byte0 & 0x02)
    158      1.1    tsubai 				button |= 4;
    159      1.1    tsubai 
    160      1.1    tsubai 			if (byte0 & 0x08)
    161      1.1    tsubai 				dx = byte1 - 0x80;
    162      1.1    tsubai 			else
    163      1.1    tsubai 				dx = byte1;
    164      1.1    tsubai 			if (byte0 & 0x10)
    165      1.1    tsubai 				dy = byte2 - 0x80;
    166      1.1    tsubai 			else
    167      1.1    tsubai 				dy = byte2;
    168      1.1    tsubai 
    169      1.1    tsubai 			wsmouse_input(sc->sc_wsmousedev, button, dx, -dy, 0,
    170      1.1    tsubai 			    WSMOUSE_INPUT_DELTA);
    171      1.1    tsubai 		}
    172      1.1    tsubai 	}
    173      1.1    tsubai 
    174      1.1    tsubai 	*ien |= RX_MSINTE;
    175      1.1    tsubai 	return rv;
    176      1.1    tsubai }
    177      1.1    tsubai 
    178      1.1    tsubai int
    179      1.1    tsubai ms_hb_enable(v)
    180      1.1    tsubai 	void *v;
    181      1.1    tsubai {
    182      1.1    tsubai 	volatile u_char *ien = (void *)INTEN0;
    183      1.1    tsubai 
    184      1.1    tsubai 	*ien |= RX_MSINTE;
    185      1.1    tsubai 	return 0;
    186      1.1    tsubai }
    187      1.1    tsubai 
    188      1.1    tsubai void
    189      1.1    tsubai ms_hb_disable(v)
    190      1.1    tsubai 	void *v;
    191      1.1    tsubai {
    192      1.1    tsubai 	volatile u_char *ien = (void *)INTEN0;
    193      1.1    tsubai 
    194      1.1    tsubai 	*ien &= ~RX_MSINTE;
    195      1.1    tsubai }
    196      1.1    tsubai 
    197      1.1    tsubai int
    198      1.1    tsubai ms_hb_ioctl(v, cmd, data, flag, p)
    199      1.1    tsubai 	void *v;
    200      1.1    tsubai 	u_long cmd;
    201      1.1    tsubai 	caddr_t data;
    202      1.1    tsubai 	int flag;
    203      1.1    tsubai 	struct proc *p;
    204      1.1    tsubai {
    205  1.1.6.1  jdolecek 	return EPASSTHROUGH;
    206      1.1    tsubai }
    207