Module Name:    src
Committed By:   sborrill
Date:           Fri Sep 28 10:58:17 UTC 2012

Modified Files:
        src/distrib/sets/lists/man [netbsd-5]: mi
        src/lib/libusbhid [netbsd-5]: usb_hid_usages
        src/share/man/man4 [netbsd-5]: Makefile wsmouse.4
        src/sys/arch/amd64/conf [netbsd-5]: GENERIC
        src/sys/arch/i386/conf [netbsd-5]: GENERIC
        src/sys/dev/usb [netbsd-5]: FILES files.usb usbdevices.config usbhid.h
Added Files:
        src/share/man/man4 [netbsd-5]: uts.4
        src/sys/dev/usb [netbsd-5]: uts.c

Log Message:
Pull up the following revisions(s) (requested by liamjfoy in ticket #1797):
        lib/libusbhid/usb_hid_usages:   revision 1.5 via patch
        share/man/man4/Makefile:        revision 1.578 via patch
        share/man/man4/uts.4:           revision 1.1
        share/man/man4/wsmouse.4:       revision 1.19 via patch
        sys/arch/amd64/conf/GENERIC:    revision 1.346-1.347 via patch
        sys/arch/i386/conf/GENERIC:     revision 1.1078 via patch
        sys/dev/usb/FILES:              revision 1.12 via patch
        sys/dev/usb/usbdevices.config:  revision 1.12 via patch
        sys/dev/usb/files.usb:          revision 1.119-1.120 via patch
        sys/dev/usb/usbhid.h:           revision 1.14 via patch
        sys/dev/usb/uts.c:              revision 1.1
        distrib/sets/lists/man/mi:      revision 1.1370 via patch

Add uts(4) driver for USB touchscreens.


To generate a diff of this commit:
cvs rdiff -u -r1.1109.2.20 -r1.1109.2.21 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.3 -r1.3.18.1 src/lib/libusbhid/usb_hid_usages
cvs rdiff -u -r1.482.2.11 -r1.482.2.12 src/share/man/man4/Makefile
cvs rdiff -u -r0 -r1.1.10.2 src/share/man/man4/uts.4
cvs rdiff -u -r1.17 -r1.17.24.1 src/share/man/man4/wsmouse.4
cvs rdiff -u -r1.231.4.9 -r1.231.4.10 src/sys/arch/amd64/conf/GENERIC
cvs rdiff -u -r1.915.2.12 -r1.915.2.13 src/sys/arch/i386/conf/GENERIC
cvs rdiff -u -r1.10 -r1.10.70.1 src/sys/dev/usb/FILES
cvs rdiff -u -r1.90 -r1.90.4.1 src/sys/dev/usb/files.usb
cvs rdiff -u -r1.6 -r1.6.34.1 src/sys/dev/usb/usbdevices.config
cvs rdiff -u -r1.13 -r1.13.10.1 src/sys/dev/usb/usbhid.h
cvs rdiff -u -r0 -r1.1.12.2 src/sys/dev/usb/uts.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1109.2.20 src/distrib/sets/lists/man/mi:1.1109.2.21
--- src/distrib/sets/lists/man/mi:1.1109.2.20	Wed Jan 25 21:18:15 2012
+++ src/distrib/sets/lists/man/mi	Fri Sep 28 10:58:13 2012
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1109.2.20 2012/01/25 21:18:15 riz Exp $
+# $NetBSD: mi,v 1.1109.2.21 2012/09/28 10:58:13 sborrill Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1575,6 +1575,7 @@
 ./usr/share/man/cat4/usscanner.0		man-sys-catman		.cat
 ./usr/share/man/cat4/ustir.0			man-sys-catman		.cat
 ./usr/share/man/cat4/utoppy.0			man-sys-catman		.cat
+./usr/share/man/cat4/uts.0			man-sys-catman		.cat
 ./usr/share/man/cat4/uvideo.0			man-sys-catman		.cat
 ./usr/share/man/cat4/uvisor.0			man-sys-catman		.cat
 ./usr/share/man/cat4/uvscom.0			man-sys-catman		.cat
@@ -4057,6 +4058,7 @@
 ./usr/share/man/html4/usscanner.html		man-sys-htmlman		html
 ./usr/share/man/html4/ustir.html		man-sys-htmlman		html
 ./usr/share/man/html4/utoppy.html		man-sys-htmlman		html
+./usr/share/man/html4/uts.html			man-sys-htmlman		html
 ./usr/share/man/html4/uvideo.html		man-sys-htmlman		html
 ./usr/share/man/html4/uvisor.html		man-sys-htmlman		html
 ./usr/share/man/html4/uvscom.html		man-sys-htmlman		html
@@ -6469,6 +6471,7 @@
 ./usr/share/man/man4/usscanner.4		man-sys-man		.man
 ./usr/share/man/man4/ustir.4			man-sys-man		.man
 ./usr/share/man/man4/utoppy.4			man-sys-man		.man
+./usr/share/man/man4/uts.4			man-sys-man		.man
 ./usr/share/man/man4/uvideo.4			man-sys-man		.man
 ./usr/share/man/man4/uvisor.4			man-sys-man		.man
 ./usr/share/man/man4/uvscom.4			man-sys-man		.man

Index: src/lib/libusbhid/usb_hid_usages
diff -u src/lib/libusbhid/usb_hid_usages:1.3 src/lib/libusbhid/usb_hid_usages:1.3.18.1
--- src/lib/libusbhid/usb_hid_usages:1.3	Thu May 24 18:05:11 2007
+++ src/lib/libusbhid/usb_hid_usages	Fri Sep 28 10:58:15 2012
@@ -1,4 +1,4 @@
-# $NetBSD: usb_hid_usages,v 1.3 2007/05/24 18:05:11 plunky Exp $
+# $NetBSD: usb_hid_usages,v 1.3.18.1 2012/09/28 10:58:15 sborrill Exp $
 #
 # USB HID usage table
 # Syntax:
@@ -812,6 +812,10 @@
 	0x44	Barrel Switch
 	0x45	Eraser
 	0x46	Tablet Pick
+	0x51    Contact ID
+	0x53    Device Index
+	0x54    Contact Count
+	0x55    Contact Count Maximum
 
 15	Physical Interface Device
 

Index: src/share/man/man4/Makefile
diff -u src/share/man/man4/Makefile:1.482.2.11 src/share/man/man4/Makefile:1.482.2.12
--- src/share/man/man4/Makefile:1.482.2.11	Wed Jan 25 21:18:16 2012
+++ src/share/man/man4/Makefile	Fri Sep 28 10:58:15 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.482.2.11 2012/01/25 21:18:16 riz Exp $
+#	$NetBSD: Makefile,v 1.482.2.12 2012/09/28 10:58:15 sborrill Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/18/93
 
 MAN=	aac.4 ac97.4 acardide.4 aceride.4 acphy.4 acpidalb.4 \
@@ -72,7 +72,7 @@ MAN+=	stuirda.4 u3g.4 uaudio.4 uberry.4 
 	udsbr.4 uftdi.4 ugen.4 ugensa.4 uhid.4 \
 	uhidev.4 uhmodem.4 uipaq.4 uirda.4 ukbd.4 ukyopon.4 ulpt.4 \
 	umass.4 umct.4 umidi.4 umodem.4 ums.4 uplcom.4 urio.4 usb.4 \
-	uscanner.4 uslsa.4 usscanner.4 ustir.4 uvisor.4 uvscom.4 uyap.4 \
+	uscanner.4 uslsa.4 usscanner.4 ustir.4 uts.4 uvisor.4 uvscom.4 uyap.4 \
 	aue.4 atu.4 axe.4 cdce.4 cue.4 kue.4 upl.4 url.4 udav.4 \
 	ehci.4 ohci.4 slhci.4 uhci.4 utoppy.4 uvideo.4
 

Index: src/share/man/man4/wsmouse.4
diff -u src/share/man/man4/wsmouse.4:1.17 src/share/man/man4/wsmouse.4:1.17.24.1
--- src/share/man/man4/wsmouse.4:1.17	Tue Oct 31 22:01:09 2006
+++ src/share/man/man4/wsmouse.4	Fri Sep 28 10:58:15 2012
@@ -1,4 +1,4 @@
-.\" $NetBSD: wsmouse.4,v 1.17 2006/10/31 22:01:09 wiz Exp $
+.\" $NetBSD: wsmouse.4,v 1.17.24.1 2012/09/28 10:58:15 sborrill Exp $
 .\"
 .\" Copyright (c) 1999
 .\" 	Matthias Drochner.  All rights reserved.
@@ -27,7 +27,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd October 31, 2006
+.Dd January 17, 2012
 .Os
 .Dt WSMOUSE 4
 .Sh NAME
@@ -38,6 +38,8 @@
 (PS/2 mouse, including ``IntelliMouse''-compatible wheel mice)
 .Cd "wsmouse*   at ums? mux 0"
 (USB mouse)
+.Cd "wsmouse*   at uts? mux 0"
+(USB touchscreen)
 .Cd "wsmouse*   at lms? mux 0"
 (Logitech bus mouse, i386 only)
 .Cd "wsmouse*   at mms? mux 0"
@@ -124,6 +126,7 @@ above for more details.
 .Xr pms 4 ,
 .Xr uep 4 ,
 .Xr ums 4 ,
+.Xr uts 4 ,
 .Xr wscons 4 ,
 .Xr wsmux 4 ,
 .Xr moused 8 ,

Index: src/sys/arch/amd64/conf/GENERIC
diff -u src/sys/arch/amd64/conf/GENERIC:1.231.4.9 src/sys/arch/amd64/conf/GENERIC:1.231.4.10
--- src/sys/arch/amd64/conf/GENERIC:1.231.4.9	Wed Jan 25 21:18:13 2012
+++ src/sys/arch/amd64/conf/GENERIC	Fri Sep 28 10:58:15 2012
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.231.4.9 2012/01/25 21:18:13 riz Exp $
+# $NetBSD: GENERIC,v 1.231.4.10 2012/09/28 10:58:15 sborrill Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include	"arch/amd64/conf/std.amd64"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.231.4.9 $"
+#ident 		"GENERIC-$Revision: 1.231.4.10 $"
 
 maxusers	64		# estimated number of users
 
@@ -761,6 +761,10 @@ uhidev*	at uhub? port ? configuration ? 
 ums*	at uhidev? reportid ?
 wsmouse* at ums? mux 0
 
+# USB Touchscreens
+uts* 	at uhidev? reportid ?
+wsmouse* at uts? mux 0
+
 # USB eGalax touch-panel
 uep*	at uhub? port ?
 wsmouse* at uep? mux 0

Index: src/sys/arch/i386/conf/GENERIC
diff -u src/sys/arch/i386/conf/GENERIC:1.915.2.12 src/sys/arch/i386/conf/GENERIC:1.915.2.13
--- src/sys/arch/i386/conf/GENERIC:1.915.2.12	Wed Jan 25 21:18:14 2012
+++ src/sys/arch/i386/conf/GENERIC	Fri Sep 28 10:58:15 2012
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.915.2.12 2012/01/25 21:18:14 riz Exp $
+# $NetBSD: GENERIC,v 1.915.2.13 2012/09/28 10:58:15 sborrill Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include 	"arch/i386/conf/std.i386"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.915.2.12 $"
+#ident 		"GENERIC-$Revision: 1.915.2.13 $"
 
 maxusers	64		# estimated number of users
 
@@ -1103,6 +1103,10 @@ uhidev*	at uhub? port ? configuration ? 
 ums*	at uhidev? reportid ?
 wsmouse* at ums? mux 0
 
+# USB generic touchscreen
+uts*    at uhidev? reportid ?
+wsmouse* at uts? mux 0
+
 # USB eGalax touch-panel
 uep*	at uhub? port ?
 wsmouse* at uep? mux 0

Index: src/sys/dev/usb/FILES
diff -u src/sys/dev/usb/FILES:1.10 src/sys/dev/usb/FILES:1.10.70.1
--- src/sys/dev/usb/FILES:1.10	Sat Aug 19 16:35:03 2006
+++ src/sys/dev/usb/FILES	Fri Sep 28 10:58:16 2012
@@ -37,6 +37,7 @@ uhcireg.h		Hardware definitions for UHCI
 uhcivar.h		API for uhci.c
 uhid.c			USB generic HID driver
 uhidev.c		USB HID class driver
+uts.can 		USB touchscreen driver
 uhidev.h		  and definitions for it
 uhub.c			USB hub driver
 uipaq.c			HP ipaq22xx driver

Index: src/sys/dev/usb/files.usb
diff -u src/sys/dev/usb/files.usb:1.90 src/sys/dev/usb/files.usb:1.90.4.1
--- src/sys/dev/usb/files.usb:1.90	Fri Oct 10 16:37:16 2008
+++ src/sys/dev/usb/files.usb	Fri Sep 28 10:58:16 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: files.usb,v 1.90 2008/10/10 16:37:16 joerg Exp $
+#	$NetBSD: files.usb,v 1.90.4.1 2012/09/28 10:58:16 sborrill Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -86,6 +86,11 @@ device	ums: hid, wsmousedev
 attach	ums at uhidbus
 file	dev/usb/ums.c			ums
 
+# Touchscreens
+device 	uts: hid, wsmousedev, tpcalib
+attach 	uts at uhidbus
+file 	dev/usb/uts.c	 		uts
+
 # eGalax USB Touch Panel
 device	uep: wsmousedev, tpcalib
 attach	uep at usbdevif

Index: src/sys/dev/usb/usbdevices.config
diff -u src/sys/dev/usb/usbdevices.config:1.6 src/sys/dev/usb/usbdevices.config:1.6.34.1
--- src/sys/dev/usb/usbdevices.config:1.6	Sat Sep 22 07:40:19 2007
+++ src/sys/dev/usb/usbdevices.config	Fri Sep 28 10:58:16 2012
@@ -39,6 +39,10 @@ wsmouse* at ums? mux 0
 uep*	at uhub? port ?
 wsmouse* at uep? mux 0
 
+# USB Touchscreens
+uts* 	utsat uhidev? reportid ?
+wsmouse* at uts? mux 0
+
 # USB Keyboards
 ukbd*	at uhidev? reportid ?
 wskbd*	at ukbd? console ? mux 1

Index: src/sys/dev/usb/usbhid.h
diff -u src/sys/dev/usb/usbhid.h:1.13 src/sys/dev/usb/usbhid.h:1.13.10.1
--- src/sys/dev/usb/usbhid.h:1.13	Mon Apr 28 20:24:01 2008
+++ src/sys/dev/usb/usbhid.h	Fri Sep 28 10:58:16 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: usbhid.h,v 1.13 2008/04/28 20:24:01 martin Exp $	*/
+/*	$NetBSD: usbhid.h,v 1.13.10.1 2012/09/28 10:58:16 sborrill Exp $	*/
 /*	$FreeBSD: src/sys/dev/usb/usbhid.h,v 1.7 1999/11/17 22:33:51 n_hibma Exp $ */
 
 /*
@@ -133,6 +133,8 @@ typedef struct usb_hid_descriptor {
 
 /* Usages Digitizers */
 #define HUD_UNDEFINED		0x0000
+#define HUD_TOUCH_SCREEN 	0x0004
+#define HUD_FINGER 		0x0022
 #define HUD_TIP_PRESSURE	0x0030
 #define HUD_BARREL_PRESSURE	0x0031
 #define HUD_IN_RANGE		0x0032

Added files:

Index: src/share/man/man4/uts.4
diff -u /dev/null src/share/man/man4/uts.4:1.1.10.2
--- /dev/null	Fri Sep 28 10:58:17 2012
+++ src/share/man/man4/uts.4	Fri Sep 28 10:58:15 2012
@@ -0,0 +1,64 @@
+.\" $NetBSD: uts.4,v 1.1.10.2 2012/09/28 10:58:15 sborrill Exp $
+.\"
+.\" Copyright (c) 2012 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Pierre Pronchery.
+.\"
+.\" 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.
+.\"
+.Dd January 16, 2012
+.Dt UTS 4
+.Os
+.Sh NAME
+.Nm uts
+.Nd USB generic touchscreens
+.Sh SYNOPSIS
+.Cd "uts*     at uhidev? reportid ?"
+.Cd "wsmouse* at uts?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for USB touchscreens, otherwise known as Touch
+Digitizer devices.
+Access to panel events is through the
+.Xr wsmouse 4
+driver.
+.Sh SEE ALSO
+.Xr uhidev 4 ,
+.Xr wsmouse 4
+.Sh HISTORY
+The
+.Nm
+driver was written by Pierre Pronchery for
+.Nx .
+The
+.Nm
+driver appeared in
+.Nx 6.0 .
+.Sh BUGS
+.Nm
+currently does not support calibration.
+Also, not all
+.Nx Ns -supplied
+X servers support the absolute position events it generates.

Index: src/sys/dev/usb/uts.c
diff -u /dev/null src/sys/dev/usb/uts.c:1.1.12.2
--- /dev/null	Fri Sep 28 10:58:17 2012
+++ src/sys/dev/usb/uts.c	Fri Sep 28 10:58:17 2012
@@ -0,0 +1,385 @@
+/*
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Pierre Pronchery (khor...@defora.org).
+ *
+ * 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.
+ */
+
+/*
+ *  USB generic Touch Screen driver.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: uts.c,v 1.1.12.2 2012/09/28 10:58:17 sborrill Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <sys/ioctl.h>
+#include <sys/vnode.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbhid.h>
+
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/usbdevs.h>
+#include <dev/usb/usb_quirks.h>
+#include <dev/usb/uhidev.h>
+#include <dev/usb/hid.h>
+
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsmousevar.h>
+#include <dev/wscons/tpcalibvar.h>
+
+#ifdef USB_DEBUG
+#define DPRINTF(x)	if (utsdebug) printf x
+#define DPRINTFN(n,x)	if (utsdebug>(n)) printf x
+int	utsdebug = 0;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+
+struct uts_softc {
+	struct uhidev sc_hdev;
+
+	struct hid_location sc_loc_x, sc_loc_y, sc_loc_z;
+	struct hid_location sc_loc_btn;
+
+	int sc_enabled;
+
+	int flags;		/* device configuration */
+#define UTS_ABS		0x1	/* absolute position */
+
+	u_int32_t		sc_buttons;	/* touchscreen button status */
+	device_t		sc_wsmousedev;
+	struct tpcalib_softc	sc_tpcalib;	/* calibration */
+	struct wsmouse_calibcoords sc_calibcoords;
+
+	char sc_dying;
+};
+
+#define TSCREEN_FLAGS_MASK (HIO_CONST|HIO_RELATIVE)
+
+Static void	uts_intr(struct uhidev *addr, void *ibuf, u_int len);
+
+Static int	uts_enable(void *);
+Static void	uts_disable(void *);
+Static int	uts_ioctl(void *, u_long, void *, int, struct lwp *);
+
+Static const struct wsmouse_accessops uts_accessops = {
+	uts_enable,
+	uts_ioctl,
+	uts_disable,
+};
+
+Static int	uts_match(device_t, cfdata_t, void *);
+Static void	uts_attach(device_t, device_t, void *);
+Static void	uts_childdet(device_t, device_t);
+Static int	uts_detach(device_t, int);
+Static int	uts_activate(device_t, enum devact);
+
+extern struct cfdriver uts_cd;
+
+CFATTACH_DECL2_NEW(uts, sizeof(struct uts_softc), uts_match, uts_attach,
+    uts_detach, uts_activate, NULL, uts_childdet);
+
+Static int
+uts_match(device_t parent, cfdata_t match, void *aux)
+{
+	struct uhidev_attach_arg *uha = aux;
+	int size;
+	void *desc;
+
+	uhidev_get_report_desc(uha->parent, &desc, &size);
+	if (!hid_is_collection(desc, size, uha->reportid,
+	    HID_USAGE2(HUP_DIGITIZERS, HUD_TOUCH_SCREEN)) &&
+	    !hid_is_collection(desc, size, uha->reportid,
+	    HID_USAGE2(HUP_DIGITIZERS, HUD_FINGER)))
+		return UMATCH_NONE;
+
+	return UMATCH_IFACECLASS;
+}
+
+Static void
+uts_attach(device_t parent, device_t self, void *aux)
+{
+	struct uts_softc *sc = device_private(self);
+	struct uhidev_attach_arg *uha = aux;
+	struct wsmousedev_attach_args a;
+	int size;
+	void *desc;
+	u_int32_t flags;
+	struct hid_data * d;
+	struct hid_item item;
+
+	aprint_naive("\n");
+
+	sc->sc_hdev.sc_dev = self;
+	sc->sc_hdev.sc_intr = uts_intr;
+	sc->sc_hdev.sc_parent = uha->parent;
+	sc->sc_hdev.sc_report_id = uha->reportid;
+
+	uhidev_get_report_desc(uha->parent, &desc, &size);
+
+	if (!pmf_device_register(self, NULL, NULL))
+		aprint_error_dev(self, "couldn't establish power handler\n");
+
+	/* requires HID usage Generic_Desktop:X */
+	if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X),
+		uha->reportid, hid_input, &sc->sc_loc_x, &flags)) {
+		aprint_error_dev(sc->sc_hdev.sc_dev,
+		    "touchscreen has no X report\n");
+		return;
+	}
+	switch (flags & TSCREEN_FLAGS_MASK) {
+	case 0:
+		sc->flags |= UTS_ABS;
+		break;
+	case HIO_RELATIVE:
+		break;
+	default:
+		aprint_error_dev(sc->sc_hdev.sc_dev,
+		    "X report 0x%04x not supported\n", flags);
+		return;
+	}
+
+	/* requires HID usage Generic_Desktop:Y */
+	if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y),
+		uha->reportid, hid_input, &sc->sc_loc_y, &flags)) {
+		aprint_error_dev(sc->sc_hdev.sc_dev,
+		    "touchscreen has no Y report\n");
+		return;
+	}
+	switch (flags & TSCREEN_FLAGS_MASK) {
+	case 0:
+		sc->flags |= UTS_ABS;
+		break;
+	case HIO_RELATIVE:
+		break;
+	default:
+		aprint_error_dev(sc->sc_hdev.sc_dev,
+		    "Y report 0x%04x not supported\n", flags);
+		return;
+	}
+
+	/* requires HID usage Digitizer:Tip_Switch */
+	if (!hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, HUD_TIP_SWITCH),
+	    uha->reportid, hid_input, &sc->sc_loc_btn, 0)) {
+		aprint_error_dev(sc->sc_hdev.sc_dev,
+		    "touchscreen has no tip switch report\n");
+		return;
+	}
+
+	/* requires HID usage Digitizer:In_Range */
+	if (!hid_locate(desc, size, HID_USAGE2(HUP_DIGITIZERS, HUD_IN_RANGE),
+		uha->reportid, hid_input, &sc->sc_loc_z, &flags)) {
+		aprint_error_dev(sc->sc_hdev.sc_dev,
+		    "touchscreen has no range report\n");
+		return;
+	}
+
+	/* multi-touch support would need HUD_CONTACTID and HUD_CONTACTMAX */
+
+#ifdef USB_DEBUG
+	DPRINTF(("uts_attach: sc=%p\n", sc));
+	DPRINTF(("uts_attach: X\t%d/%d\n",
+		sc->sc_loc_x.pos, sc->sc_loc_x.size));
+	DPRINTF(("uts_attach: Y\t%d/%d\n",
+		sc->sc_loc_y.pos, sc->sc_loc_y.size));
+	DPRINTF(("uts_attach: Z\t%d/%d\n",
+		sc->sc_loc_z.pos, sc->sc_loc_z.size));
+#endif
+
+	a.accessops = &uts_accessops;
+	a.accesscookie = sc;
+
+	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
+
+	/* calibrate the touchscreen */
+	memset(&sc->sc_calibcoords, 0, sizeof(sc->sc_calibcoords));
+	sc->sc_calibcoords.maxx = 4095;
+	sc->sc_calibcoords.maxy = 4095;
+	sc->sc_calibcoords.samplelen = WSMOUSE_CALIBCOORDS_RESET;
+	d = hid_start_parse(desc, size, hid_input);
+	while (hid_get_item(d, &item)) {
+		if (item.kind != hid_input
+		    || HID_GET_USAGE_PAGE(item.usage) != HUP_GENERIC_DESKTOP
+		    || item.report_ID != sc->sc_hdev.sc_report_id)
+			continue;
+		if (HID_GET_USAGE(item.usage) == HUG_X) {
+			sc->sc_calibcoords.minx = item.logical_minimum;
+			sc->sc_calibcoords.maxx = item.logical_maximum;
+		}
+		if (HID_GET_USAGE(item.usage) == HUG_Y) {
+			sc->sc_calibcoords.miny = item.logical_minimum;
+			sc->sc_calibcoords.maxy = item.logical_maximum;
+		}
+	}
+	hid_end_parse(d);
+
+	tpcalib_init(&sc->sc_tpcalib);
+	tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
+	    (void *)&sc->sc_calibcoords, 0, 0);
+
+	return;
+}
+
+Static int
+uts_detach(device_t self, int flags)
+{
+	struct uts_softc *sc = device_private(self);
+	int rv = 0;
+
+	DPRINTF(("uts_detach: sc=%p flags=%d\n", sc, flags));
+
+	if (sc->sc_wsmousedev != NULL)
+		rv = config_detach(sc->sc_wsmousedev, flags);
+
+	pmf_device_deregister(self);
+
+	return rv;
+}
+
+Static void
+uts_childdet(device_t self, device_t child)
+{
+	struct uts_softc *sc = device_private(self);
+
+	KASSERT(sc->sc_wsmousedev == child);
+	sc->sc_wsmousedev = NULL;
+}
+
+Static int
+uts_activate(device_t self, enum devact act)
+{
+	struct uts_softc *sc = device_private(self);
+
+	switch (act) {
+	case DVACT_DEACTIVATE:
+		sc->sc_dying = 1;
+		return 0;
+	default:
+		return EOPNOTSUPP;
+	}
+}
+
+Static int
+uts_enable(void *v)
+{
+	struct uts_softc *sc = v;
+
+	DPRINTFN(1,("uts_enable: sc=%p\n", sc));
+
+	if (sc->sc_dying)
+		return EIO;
+
+	if (sc->sc_enabled)
+		return EBUSY;
+
+	sc->sc_enabled = 1;
+	sc->sc_buttons = 0;
+
+	return uhidev_open(&sc->sc_hdev);
+}
+
+Static void
+uts_disable(void *v)
+{
+	struct uts_softc *sc = v;
+
+	DPRINTFN(1,("uts_disable: sc=%p\n", sc));
+#ifdef DIAGNOSTIC
+	if (!sc->sc_enabled) {
+		printf("uts_disable: not enabled\n");
+		return;
+	}
+#endif
+
+	sc->sc_enabled = 0;
+	uhidev_close(&sc->sc_hdev);
+}
+
+Static int
+uts_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
+{
+	struct uts_softc *sc = v;
+
+	switch (cmd) {
+	case WSMOUSEIO_GTYPE:
+		if (sc->flags & UTS_ABS)
+			*(u_int *)data = WSMOUSE_TYPE_TPANEL;
+		else
+			*(u_int *)data = WSMOUSE_TYPE_USB;
+		return 0;
+	case WSMOUSEIO_SCALIBCOORDS:
+	case WSMOUSEIO_GCALIBCOORDS:
+		return tpcalib_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
+	}
+
+	return EPASSTHROUGH;
+}
+
+Static void
+uts_intr(struct uhidev *addr, void *ibuf, u_int len)
+{
+	struct uts_softc *sc = (struct uts_softc *)addr;
+	int dx, dy, dz;
+	u_int32_t buttons = 0;
+	int flags, s;
+
+	DPRINTFN(5,("uts_intr: len=%d\n", len));
+
+	flags = WSMOUSE_INPUT_DELTA | WSMOUSE_INPUT_ABSOLUTE_Z;
+
+	dx = hid_get_data(ibuf, &sc->sc_loc_x);
+	if (sc->flags & UTS_ABS) {
+		flags |= (WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
+		dy = hid_get_data(ibuf, &sc->sc_loc_y);
+		tpcalib_trans(&sc->sc_tpcalib, dx, dy, &dx, &dy);
+	} else
+		dy = -hid_get_data(ibuf, &sc->sc_loc_y);
+
+	dz = hid_get_data(ibuf, &sc->sc_loc_z);
+
+	if (hid_get_data(ibuf, &sc->sc_loc_btn))
+		buttons |= 1;
+
+	if (dx != 0 || dy != 0 || dz != 0 || buttons != sc->sc_buttons) {
+		DPRINTFN(10,("uts_intr: x:%d y:%d z:%d buttons:0x%x\n",
+		    dx, dy, dz, buttons));
+		sc->sc_buttons = buttons;
+		if (sc->sc_wsmousedev != NULL) {
+			s = spltty();
+			wsmouse_input(sc->sc_wsmousedev, buttons, dx, dy, dz, 0,
+			    flags);
+			splx(s);
+		}
+	}
+}

Reply via email to