From f03b0f0b8fe247fd41572789609237a1cbd2c1e3 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Tue, 31 Dec 2013 01:36:50 +0100
Subject: [PATCH] WIP spic(4) driver

---
 Makefile_upgrade.inc              |  4 +--
 share/man/man4/Makefile           |  1 +
 share/man/man4/man4.i386/Makefile |  1 -
 share/man/man4/man4.i386/spic.4   | 60 --------------------------------------
 share/man/man4/spic.4             | 61 +++++++++++++++++++++++++++++++++++++++
 sys/conf/files                    |  1 +
 sys/config/LINT64                 |  2 ++
 sys/dev/misc/spic/spic.c          | 20 +++++++------
 sys/platform/pc32/conf/files      |  1 -
 9 files changed, 78 insertions(+), 73 deletions(-)
 delete mode 100644 share/man/man4/man4.i386/spic.4
 create mode 100644 share/man/man4/spic.4

diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc
index 11f6e93..5ff9062 100644
--- a/Makefile_upgrade.inc
+++ b/Makefile_upgrade.inc
@@ -2105,8 +2105,6 @@ TO_REMOVE+=/usr/share/man/man3/use_helpfile.3.gz
 TO_REMOVE+=/usr/share/man/cat3/use_helpline.3.gz
 TO_REMOVE+=/usr/share/man/man3/use_helpline.3.gz
 TO_REMOVE+=/usr/include/machine/apm_segments.h
-TO_REMOVE+=/usr/share/man/cat4/spic.4.gz
-TO_REMOVE+=/usr/share/man/man4/spic.4.gz
 TO_REMOVE+=/usr/include/machine/ioctl_ctx.h
 TO_REMOVE+=/usr/include/machine/wtio.h
 TO_REMOVE+=/usr/include/machine/if_wl_wavelan.h
@@ -2402,6 +2400,8 @@ TO_REMOVE+=/usr/share/man/cat3/strtouq_l.3.gz
 TO_REMOVE+=/usr/share/man/man3/strtouq_l.3.gz
 TO_REMOVE+=/usr/share/man/cat5/utf2.5.gz
 TO_REMOVE+=/usr/share/man/man5/utf2.5.gz
+TO_REMOVE+=/usr/share/man/cat4/i386/spic.4.gz
+TO_REMOVE+=/usr/share/man/man4/i386/spic.4.gz
 
 .if ${MACHINE_ARCH} == "x86_64"
 TO_REMOVE+=/usr/sbin/stlstats
diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
index 9c8654a..f7e5838 100644
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -294,6 +294,7 @@ MAN=	aac.4 \
 	snd_via82c686.4 \
 	snd_vibes.4 \
 	snp.4 \
+	spic.4 \
 	splash.4 \
 	sppp.4 \
 	st.4 \
diff --git a/share/man/man4/man4.i386/Makefile b/share/man/man4/man4.i386/Makefile
index 027118b..3ff0d2e 100644
--- a/share/man/man4/man4.i386/Makefile
+++ b/share/man/man4/man4.i386/Makefile
@@ -19,7 +19,6 @@ MAN=	ar.4 \
 	pnpbios.4 \
 	pst.4 \
 	sbni.4 \
-	spic.4 \
 	sr.4 \
 	stl.4 \
 	tx.4 \
diff --git a/share/man/man4/man4.i386/spic.4 b/share/man/man4/man4.i386/spic.4
deleted file mode 100644
index e609da4..0000000
--- a/share/man/man4/man4.i386/spic.4
+++ /dev/null
@@ -1,60 +0,0 @@
-.\"
-.\" Copyright (c) 2002 Will Andrews
-.\" All rights reserved.
-.\"
-.\" 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 AUTHOR 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 AUTHOR 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.
-.\"
-.\" $FreeBSD: src/share/man/man4/spic.4,v 1.1.2.1 2002/05/20 18:55:34 will Exp $
-.\"
-.Dd May 20, 2002
-.Dt SPIC 4 i386
-.Os
-.Sh NAME
-.Nm spic
-.Nd Sony Programmable I/O Controller device driver
-.Sh SYNOPSIS
-.Cd "device spic"
-.Sh DESCRIPTION
-The
-.Nm
-driver allows using
-.Xr moused 8
-to drive the Sony Vaio Jogdial device found on several Sony Vaio models.
-It works by mapping the forward, backwards, up, and down inputs to
-.Dq l ,
-.Dq r ,
-.Dq u ,
-.Dq d ,
-respectively.
-From that a program reading the Jogdial can decide what to do.
-Some actions might include scrolling, mimicking mouse buttons, launching
-applications, or other useful things.
-.Sh SEE ALSO
-.Xr moused 8
-.Sh HISTORY
-The
-.Nm
-device driver first appeared in
-.Fx 4.6 .
-.Sh AUTHORS
-.An Nick Sayer Aq Mt nsayer@FreeBSD.org
-.An Will Andrews Aq Mt will@FreeBSD.org
diff --git a/share/man/man4/spic.4 b/share/man/man4/spic.4
new file mode 100644
index 0000000..7083d59
--- /dev/null
+++ b/share/man/man4/spic.4
@@ -0,0 +1,61 @@
+.\"
+.\" Copyright (c) 2002 Will Andrews
+.\" All rights reserved.
+.\"
+.\" 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 AUTHOR 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 AUTHOR 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.
+.\"
+.\" $FreeBSD: src/share/man/man4/spic.4,v 1.1.2.1 2002/05/20 18:55:34 will Exp $
+.\"
+.Dd May 20, 2002
+.Dt SPIC 4
+.Os
+.Sh NAME
+.Nm spic
+.Nd Sony Programmable I/O Controller device driver
+.Sh SYNOPSIS
+.Cd "device spic"
+.Sh DESCRIPTION
+The
+.Nm
+driver allows using
+.Xr moused 8
+to drive the Sony Vaio Jogdial device found on several Sony Vaio models.
+It works by mapping the forward, backwards, up, and down inputs to
+.Dq l ,
+.Dq r ,
+.Dq u ,
+and
+.Dq d ,
+respectively.
+From that a program reading the Jogdial can decide what to do.
+Some actions might include scrolling, mimicking mouse buttons, launching
+applications, or other useful things.
+.Sh SEE ALSO
+.Xr moused 8
+.Sh HISTORY
+The
+.Nm
+device driver first appeared in
+.Fx 4.6 .
+.Sh AUTHORS
+.An Nick Sayer Aq Mt nsayer@FreeBSD.org
+.An Will Andrews Aq Mt will@FreeBSD.org
diff --git a/sys/conf/files b/sys/conf/files
index cf8c710..35613f4 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -739,6 +739,7 @@ dev/netif/sln/if_sln.c		optional sln pci
 dev/netif/sn/if_sn.c		optional sn
 dev/netif/sn/if_sn_pccard.c	optional sn pccard
 dev/misc/snp/snp.c		optional snp
+dev/misc/spic/spic.c		optional spic
 dev/netif/sr/if_sr.c		optional sr
 dev/netif/sr/if_sr_pci.c	optional sr pci
 dev/disk/stg/tmc18c30.c		optional stg
diff --git a/sys/config/LINT64 b/sys/config/LINT64
index 650f3f1..43c288c 100644
--- a/sys/config/LINT64
+++ b/sys/config/LINT64
@@ -1295,6 +1295,7 @@ device		"snd_uaudio"
 # joy: joystick
 # nrp: Comtrol Rocketport
 # si: Specialix SI/XIO 4-32 port terminal multiplexor
+# spic: Sony Programmable I/O controller (VAIO notebooks)
 # nmdm: nullmodem terminal driver (see nmdm(4))
 # tpm: Trusted Platform Module
 
@@ -1309,6 +1310,7 @@ device		ecc
 device		joy0	at isa? port IO_GAME
 device		nrp
 device		si
+device		spic0	at isa? irq 0 port 0x10a0
 # nullmodem terminal driver
 device		nmdm
 device		tpm
diff --git a/sys/dev/misc/spic/spic.c b/sys/dev/misc/spic/spic.c
index 142e563..55b709b 100644
--- a/sys/dev/misc/spic/spic.c
+++ b/sys/dev/misc/spic/spic.c
@@ -1,4 +1,4 @@
-/*
+/*-
  * Copyright (c) 2000  Nick Sayer
  * All rights reserved.
  *
@@ -22,8 +22,9 @@
  * 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.
- *
- * spic -- the Sony Programmable I/O Controller
+ */
+
+/* spic -- the Sony Programmable I/O Controller
  *
  * This device exists on most recent Sony laptops. It is the means by which
  * you can watch the Jog Dial and some other functions.
@@ -33,14 +34,14 @@
  * and mouse button out of the jog dial. I suspect that this device will
  * end up having to support at least 2 different minor devices: One to be
  * the jog wheel device for moused to camp out on and the other to perform
- * all of the other miscelaneous functions of this device. But for now,
+ * all of the other miscellaneous functions of this device. But for now,
  * the jog wheel is all you get.
  *
  * At the moment, the data sent back by the device is rather primitive.
  * It sends a single character per event:
  * u = up, d = down -- that's the jog button
  * l = left, r = right -- that's the dial.
- * "left" and "right" are rather caprecious. They actually represent
+ * "left" and "right" are rather capricious. They actually represent
  * ccw and cw, respectively
  *
  * What documentation exists is thanks to Andrew Tridge, and his page at
@@ -59,11 +60,9 @@
 #include <sys/tty.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
-#include <sys/dkstat.h>
 #include <sys/malloc.h>
 #include <sys/sysctl.h>
 #include <sys/uio.h>
-#include <sys/proc.h>
 #include <sys/thread2.h>
 
 #include <bus/isa/isavar.h>
@@ -299,10 +298,10 @@ spic_probe(device_t dev)
 	 *
 	 */
 
+#if 1 /* XXX */
 	/* Enable ACPI mode to get Fn key events */
-	/* XXX This may slow down your VAIO if ACPI is not supported in the kernel.
 	outb(0xb2, 0xf0);
-	 */
+#endif
 
 	device_printf(dev,"device model type = %d\n", sc->sc_model);
 	
@@ -420,6 +419,9 @@ spictimeout(void *arg)
 			case 0x30: /* Lid switch */
 				kprintf("Lid switch event: %x\n",param);
 				break;
+			case 0x0c: /* We must ignore these type of event for C1VP... */
+			case 0x70: /* Closing/Opening the lid on C1VP */
+				break;
 			default:
 				kprintf("Unknown event: event %02x param %02x\n", event, param);
 				break;
diff --git a/sys/platform/pc32/conf/files b/sys/platform/pc32/conf/files
index aeb3425..4387928 100644
--- a/sys/platform/pc32/conf/files
+++ b/sys/platform/pc32/conf/files
@@ -272,7 +272,6 @@ bus/pci/i386/mptable_pci.c		optional	pci
 platform/pc32/isa/pmtimer.c		optional	pmtimer acpi
 # XXX drhodus
 platform/pc32/isa/prof_machdep.c	optional	profiling-routine
-dev/misc/spic/spic.c			optional 	spic
 dev/serial/stl/stallion.c		optional	stl pci
 dev/video/i386/vesa/vesa.c		optional	vga vesa
 emulation/linux/i386/imgact_linux.c	optional	compat_linux
-- 
1.8.2.2

