summaryrefslogtreecommitdiff
path: root/sys/dev/dec/vsxxx.c
blob: 9d074efbdd7e4ac7301364b6490bad4fdf692f49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* $NetBSD: vsxxx.c,v 1.12 2017/10/28 04:53:54 riastradh Exp $ */

/*-
 * Copyright (c) 1999 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Tohru Nishimura.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vsxxx.c,v 1.12 2017/10/28 04:53:54 riastradh Exp $");

/*
 * Common machinary for VSXXX mice and tablet
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsmousevar.h>

#include <dev/dec/vsxxxvar.h>

#include "ioconf.h"

/*
 * XXX XXX XXX
 *
 * collect various mice and tablet parameters/protocol design
 * and establish vsxxx.h
 *
 * XXX XXX XXX
 */
#define	VS_SELFTEST	'T'
#define	VS_INCREMENTAL	'R'
#define	VS_PROMPTING	'D'
#define	VS_REQ_POSITION	'P'

#define	VS_MOUSE_REPSZ	3
#define	VS_TABLET_REPSZ	5

/* first octet */
#define	VS_START_FRAME	0x80
#define	VS_R_BUTTON	0x01
#define	VS_M_BUTTON	0x02
#define	VS_L_BUTTON	0x04
#define	VS_Y_SIGN	0x08
#define	VS_X_SIGN	0x10

/* low order 4 bit of the second octet in a SELFTEST reply */
#define	VS_MOUSE	0x2
#define	VS_TABLET	0x4

static int  vsxxx_enable(void *);
static int  vsxxx_ioctl(void *, u_long, void *, int, struct proc *);
static void vsxxx_disable(void *);

struct wsmouse_accessops vsxxx_accessops = {	/* EXPORT */
	vsxxx_enable,				/* MD? */
	vsxxx_ioctl,
	vsxxx_disable,				/* MD? */
};

static int
vsxxx_enable(void *v)
{
	/* turn on the hardware? */
	((struct vsxxx_softc *)v)->sc_nbyte = 0;
	return 0;
}

static void
vsxxx_disable(void *v)
{
	/* turn off the hardware? */
}

/*ARGUSED*/
static int
vsxxx_ioctl(void *v, u_long cmd, void *data, int flag, struct proc *p)
{
	if (cmd == WSMOUSEIO_GTYPE) {
		*(u_int *)data = WSMOUSE_TYPE_VSXXX;
		return 0;
	}
	return EPASSTHROUGH;
}

/* EXPORT */ void
vsxxx_input(int data)
{
	struct vsxxx_softc *sc = device_lookup_private(&vsms_cd, 0);
	int x, y;

	if (data & VS_START_FRAME)
		sc->sc_nbyte = 0;

	sc->sc_report.raw[sc->sc_nbyte++] = data;

	if (sc->sc_nbyte < VS_MOUSE_REPSZ)
		return;
	sc->sc_nbyte = 0;

	x = sc->sc_report.ms.xpos;
	y = sc->sc_report.ms.ypos;
	if ((sc->sc_report.raw[0] & VS_X_SIGN) == 0)
		x = -x;
	if ((sc->sc_report.raw[0] & VS_Y_SIGN) != 0)
		y = -y;					/* Eeeh? */
	wsmouse_input(sc->sc_wsmousedev,
			sc->sc_report.raw[0] & 07,
			x, y, 0, 0,
			WSMOUSE_INPUT_DELTA);
}