Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pckbport PR/52483: Ryo ONODERA: Add support for ALPS...
details: https://anonhg.NetBSD.org/src/rev/0c570c7edeff
branches: trunk
changeset: 826066:0c570c7edeff
user: christos <christos%NetBSD.org@localhost>
date: Sun Aug 13 08:49:27 2017 +0000
description:
PR/52483: Ryo ONODERA: Add support for ALPS PS/2 pointing devices
diffstat:
sys/dev/pckbport/alps.c | 1091 +++++++++++++++++++++++++++++++++++++++
sys/dev/pckbport/alpsreg.h | 70 ++
sys/dev/pckbport/alpsvar.h | 50 +
sys/dev/pckbport/files.pckbport | 4 +-
sys/dev/pckbport/pms.c | 27 +-
sys/dev/pckbport/pmsvar.h | 12 +-
6 files changed, 1247 insertions(+), 7 deletions(-)
diffs (truncated from 1366 to 300 lines):
diff -r c70363580dcf -r 0c570c7edeff sys/dev/pckbport/alps.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pckbport/alps.c Sun Aug 13 08:49:27 2017 +0000
@@ -0,0 +1,1091 @@
+/* $NetBSD: alps.c,v 1.1 2017/08/13 08:49:27 christos Exp $ */
+
+/*-
+ * Copyright (c) 2017 Ryo ONODERA <ryo%tetera.org@localhost>
+ * Copyright (c) 2008 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * 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 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 "opt_pms.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: alps.c,v 1.1 2017/08/13 08:49:27 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/bus.h>
+#include <sys/bitops.h>
+
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsmousevar.h>
+
+#include <dev/pckbport/pckbportvar.h>
+#include <dev/pckbport/pmsreg.h>
+#include <dev/pckbport/pmsvar.h>
+#include <dev/pckbport/alpsreg.h>
+#include <dev/pckbport/alpsvar.h>
+
+/* #define ALPS_DEBUG */
+
+static int alps_touchpad_xy_unprecision_nodenum;
+static int alps_trackstick_xy_precision_nodenum;
+
+static int alps_touchpad_xy_unprecision = 2;
+static int alps_trackstick_xy_precision = 1;
+
+static void pms_alps_input_v7(void *, int);
+static void pms_alps_input_v2(void *, int);
+
+static int
+pms_sysctl_alps_verify(SYSCTLFN_ARGS)
+{
+ int error, t;
+ struct sysctlnode node;
+
+ node = *rnode;
+ t = *(int *)rnode->sysctl_data;
+ node.sysctl_data = &t;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (node.sysctl_num == alps_touchpad_xy_unprecision_nodenum ||
+ node.sysctl_num == alps_trackstick_xy_precision_nodenum) {
+ if (t < 0 || t > 7)
+ return EINVAL;
+ } else
+ return EINVAL;
+
+ *(int *)rnode->sysctl_data = t;
+
+ return 0;
+
+}
+
+static void
+pms_sysctl_alps(struct sysctllog **clog)
+{
+ const struct sysctlnode *node;
+ int rc, root_num;
+
+ if ((rc = sysctl_createv(clog, 0, NULL, &node,
+ CTLFLAG_PERMANENT, CTLTYPE_NODE, "alps",
+ SYSCTL_DESCR("ALPS touchpad controls"),
+ NULL, 0, NULL, 0, CTL_HW, CTL_CREATE, CTL_EOL)) != 0)
+ goto err;
+
+ root_num = node->sysctl_num;
+
+ if ((rc = sysctl_createv(clog, 0, NULL, &node,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "touchpad_xy_precision_shift",
+ SYSCTL_DESCR("Touchpad X/Y-axis precision shift value"),
+ pms_sysctl_alps_verify, 0,
+ &alps_touchpad_xy_unprecision,
+ 0, CTL_HW, root_num, CTL_CREATE,
+ CTL_EOL)) != 0)
+ goto err;
+ alps_touchpad_xy_unprecision_nodenum = node->sysctl_num;
+
+ if ((rc = sysctl_createv(clog, 0, NULL, &node,
+ CTLFLAG_PERMANENT | CTLFLAG_READWRITE,
+ CTLTYPE_INT, "tackstick_xy_precision_shift",
+ SYSCTL_DESCR("Trackstick X/Y-axis precision value"),
+ pms_sysctl_alps_verify, 0,
+ &alps_trackstick_xy_precision,
+ 0, CTL_HW, root_num, CTL_CREATE,
+ CTL_EOL)) != 0)
+ goto err;
+ alps_trackstick_xy_precision_nodenum = node->sysctl_num;
+
+ return;
+
+err:
+ aprint_error("%s: sysctl_createv failed (rc = %d)\n",
+ __func__, rc);
+}
+
+/*
+ * Publish E6 report command and get E6 signature,
+ * then check the signature
+ */
+static int
+pms_alps_e6sig(struct pms_softc *psc, uint8_t *e6sig)
+{
+ uint8_t cmd[2];
+ int res;
+
+ e6sig[0] = 0;
+ cmd[0] = PMS_SET_RES; /* E8 */
+ cmd[1] = 0;
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 2, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_SET_SCALE11; /* E6 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_SET_SCALE11; /* E6 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_SET_SCALE11; /* E6 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ e6sig[0] = e6sig[1] = e6sig[2] = 0;
+ /* Get E6 signature */
+ cmd[0] = PMS_GET_SCALE; /* E9 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 3, e6sig, 0)) != 0)
+ goto err;
+
+ /* ALPS input device returns 00-00-64 as E6 signature */
+ if (e6sig[0] != 0x00 || e6sig[1] != 0x00 ||
+ e6sig[2] != 0x64) {
+ return EINVAL;
+ }
+
+ aprint_debug_dev(psc->sc_dev,
+ "ALPS PS/2 E6 signature: 0x%X 0x%X 0x%X\n",
+ e6sig[0], e6sig[1], e6sig[2]);
+
+ return 0;
+err:
+ aprint_error_dev(psc->sc_dev, "Failed to get E6 signature.\n");
+ return res;
+}
+
+/*
+ * Publish E7 report command and get E7 signature
+ */
+static int
+pms_alps_e7sig(struct pms_softc *psc, uint8_t *e7sig)
+{
+ uint8_t cmd[2];
+ int res;
+
+ cmd[0] = PMS_SET_RES; /* E8 */
+ cmd[1] = 0;
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 2, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_SET_SCALE21; /* E7 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_SET_SCALE21; /* E7 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_SET_SCALE21; /* E7 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ e7sig[0] = e7sig[1] = e7sig[2] = 0;
+ cmd[0] = PMS_GET_SCALE; /* E9 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 3, e7sig, 0)) != 0)
+ goto err;
+
+ aprint_debug_dev(psc->sc_dev,
+ "ALPS PS/2 E7 signature: 0x%X 0x%X 0x%X\n",
+ e7sig[0], e7sig[1], e7sig[2]);
+
+ return 0;
+err:
+ aprint_error_dev(psc->sc_dev, "Failed to get E7 signature.\n");
+ return res;
+}
+
+/*
+ * Publish EC command and get EC signature
+ */
+static int
+pms_alps_ecsig(struct pms_softc *psc, uint8_t *ecsig)
+{
+ uint8_t cmd[2];
+ int res;
+
+ cmd[0] = PMS_SET_RES; /* E8 */
+ cmd[1] = 0;
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 2, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_RESET_WRAP_MODE; /* EC */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_RESET_WRAP_MODE; /* EC */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_RESET_WRAP_MODE; /* EC */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ ecsig[0] = ecsig[1] = ecsig[2] = 0;
+ cmd[0] = PMS_GET_SCALE; /* E9 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 3, ecsig, 0)) != 0)
+ goto err;
+
+ aprint_debug_dev(psc->sc_dev,
+ "ALPS PS/2 EC signature: 0x%X 0x%X 0x%X\n",
+ ecsig[0], ecsig[1], ecsig[2]);
+
+ return 0;
+
+err:
+ aprint_error_dev(psc->sc_dev, "Failed to get EC signature.\n");
+ return res;
+}
+
+/*
+ * Enter to command mode
+ */
+static int
+pms_alps_start_command_mode(struct pms_softc *psc)
+{
+ uint8_t cmd[1];
+ uint8_t resp[3];
+ int res;
+
+ cmd[0] = PMS_RESET_WRAP_MODE; /* EC */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_RESET_WRAP_MODE; /* EC */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ cmd[0] = PMS_RESET_WRAP_MODE; /* EC */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 0, NULL, 0)) != 0)
+ goto err;
+ resp[0] = resp[1] = resp[2] = 0;
+ cmd[0] = PMS_GET_SCALE; /* E9 */
+ if ((res = pckbport_poll_cmd(psc->sc_kbctag, psc->sc_kbcslot,
+ cmd, 1, 3, resp, 0)) != 0)
+ goto err;
+
+ aprint_debug_dev(psc->sc_dev, "ALPS Firmware ID: 0x%x 0x%X 0x%X\n",
Home |
Main Index |
Thread Index |
Old Index