2010-02-25 01:37:54 +03:00
|
|
|
/* $NetBSD: pms.c,v 1.30 2010/02/24 22:38:08 dyoung Exp $ */
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
/*-
|
2004-12-24 21:33:06 +03:00
|
|
|
* Copyright (c) 2004 Kentaro Kurahone.
|
|
|
|
* Copyright (c) 2004 Ales Krenek.
|
1998-08-15 07:02:31 +04:00
|
|
|
* Copyright (c) 1994 Charles M. Hannum.
|
1998-03-22 18:41:27 +03:00
|
|
|
* Copyright (c) 1992, 1993 Erik Forsberg.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY ``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 I 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:24:43 +03:00
|
|
|
#include <sys/cdefs.h>
|
2010-02-25 01:37:54 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: pms.c,v 1.30 2010/02/24 22:38:08 dyoung Exp $");
|
2007-07-20 02:18:54 +04:00
|
|
|
|
|
|
|
#include "opt_pms.h"
|
2001-11-13 10:24:43 +03:00
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/ioctl.h>
|
2002-07-08 11:43:31 +04:00
|
|
|
#include <sys/kernel.h>
|
2002-05-18 02:49:48 +04:00
|
|
|
#include <sys/kthread.h>
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
1999-12-04 01:48:22 +03:00
|
|
|
|
2004-03-13 20:31:33 +03:00
|
|
|
#include <dev/pckbport/pckbportvar.h>
|
2005-01-18 13:22:51 +03:00
|
|
|
#ifdef PMS_SYNAPTICS_TOUCHPAD
|
2004-12-24 21:33:06 +03:00
|
|
|
#include <dev/pckbport/synapticsvar.h>
|
2005-01-18 13:22:51 +03:00
|
|
|
#endif
|
2008-12-14 03:42:33 +03:00
|
|
|
#ifdef PMS_ELANTECH_TOUCHPAD
|
|
|
|
#include <dev/pckbport/elantechvar.h>
|
|
|
|
#endif
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2004-03-13 20:31:33 +03:00
|
|
|
#include <dev/pckbport/pmsreg.h>
|
2004-12-24 21:33:06 +03:00
|
|
|
#include <dev/pckbport/pmsvar.h>
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/wscons/wsmousevar.h>
|
|
|
|
|
2002-03-20 20:06:51 +03:00
|
|
|
#ifdef PMSDEBUG
|
|
|
|
int pmsdebug = 1;
|
|
|
|
#define DPRINTF(x) if (pmsdebug) printf x
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
|
|
|
|
2005-10-24 20:31:54 +04:00
|
|
|
const enum pms_type tries[] = {
|
2004-12-24 21:33:06 +03:00
|
|
|
PMS_SCROLL5, PMS_SCROLL3, PMS_STANDARD, PMS_UNKNOWN
|
|
|
|
};
|
2002-03-20 20:06:51 +03:00
|
|
|
|
2005-10-24 20:31:54 +04:00
|
|
|
const struct pms_protocol pms_protocols[] = {
|
2002-03-20 20:06:51 +03:00
|
|
|
{ { 0, 0, 0 }, 0, "unknown protocol" },
|
|
|
|
{ { 0, 0, 0 }, 0, "no scroll wheel (3 buttons)" },
|
|
|
|
{ { 200, 100, 80 }, 3, "scroll wheel (3 buttons)" },
|
2005-11-09 01:12:16 +03:00
|
|
|
{ { 200, 200, 80 }, 4, "scroll wheel (5 buttons)" },
|
2008-12-14 03:42:33 +03:00
|
|
|
{ { 0, 0, 0 }, 0, "synaptics" },
|
|
|
|
{ { 0, 0, 0 }, 0, "elantech" }
|
2002-03-20 20:06:51 +03:00
|
|
|
};
|
2002-03-11 01:21:21 +03:00
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2008-03-15 21:59:07 +03:00
|
|
|
int pmsprobe(device_t, cfdata_t, void *);
|
|
|
|
void pmsattach(device_t, device_t, void *);
|
2004-03-19 00:05:19 +03:00
|
|
|
void pmsinput(void *, int);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2008-03-15 21:46:22 +03:00
|
|
|
CFATTACH_DECL_NEW(pms, sizeof(struct pms_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
pmsprobe, pmsattach, NULL, NULL);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2004-03-19 00:05:19 +03:00
|
|
|
static int pms_protocol(pckbport_tag_t, pckbport_slot_t);
|
|
|
|
static void do_enable(struct pms_softc *);
|
|
|
|
static void do_disable(struct pms_softc *);
|
|
|
|
static void pms_reset_thread(void*);
|
|
|
|
int pms_enable(void *);
|
2007-03-04 08:59:00 +03:00
|
|
|
int pms_ioctl(void *, u_long, void *, int, struct lwp *);
|
2004-03-19 00:05:19 +03:00
|
|
|
void pms_disable(void *);
|
2007-12-09 23:27:42 +03:00
|
|
|
|
2010-02-25 01:37:54 +03:00
|
|
|
static bool pms_suspend(device_t, const pmf_qual_t *);
|
|
|
|
static bool pms_resume(device_t, const pmf_qual_t *);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
1999-01-23 19:05:56 +03:00
|
|
|
const struct wsmouse_accessops pms_accessops = {
|
|
|
|
pms_enable,
|
|
|
|
pms_ioctl,
|
|
|
|
pms_disable,
|
1998-03-22 18:41:27 +03:00
|
|
|
};
|
|
|
|
|
2002-03-11 01:21:21 +03:00
|
|
|
static int
|
2004-03-19 00:05:19 +03:00
|
|
|
pms_protocol(pckbport_tag_t tag, pckbport_slot_t slot)
|
2002-03-11 01:21:21 +03:00
|
|
|
{
|
|
|
|
u_char cmd[2], resp[1];
|
|
|
|
int i, j, res;
|
2005-10-24 20:31:54 +04:00
|
|
|
const struct pms_protocol *p;
|
2002-03-20 20:06:51 +03:00
|
|
|
|
|
|
|
for (j = 0; j < sizeof(tries) / sizeof(tries[0]); ++j) {
|
|
|
|
p = &pms_protocols[tries[j]];
|
|
|
|
if (!p->rates[0])
|
|
|
|
break;
|
2002-03-11 01:21:21 +03:00
|
|
|
cmd[0] = PMS_SET_SAMPLE;
|
|
|
|
for (i = 0; i < 3; i++) {
|
2002-03-20 20:06:51 +03:00
|
|
|
cmd[1] = p->rates[i];
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_enqueue_cmd(tag, slot, cmd, 2, 0, 1, 0);
|
2002-03-11 01:21:21 +03:00
|
|
|
if (res)
|
2002-03-20 20:06:51 +03:00
|
|
|
return PMS_STANDARD;
|
2002-03-11 01:21:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd[0] = PMS_SEND_DEV_ID;
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_enqueue_cmd(tag, slot, cmd, 1, 1, 1, resp);
|
2002-03-11 01:21:21 +03:00
|
|
|
if (res)
|
2004-02-27 20:56:01 +03:00
|
|
|
return PMS_UNKNOWN;
|
2002-03-20 20:06:51 +03:00
|
|
|
if (resp[0] == p->response) {
|
|
|
|
DPRINTF(("pms_protocol: found mouse protocol %d\n",
|
|
|
|
tries[j]));
|
|
|
|
return tries[j];
|
2002-03-11 01:21:21 +03:00
|
|
|
}
|
|
|
|
}
|
2002-03-20 20:06:51 +03:00
|
|
|
DPRINTF(("pms_protocol: standard PS/2 protocol (no scroll wheel)\n"));
|
2002-03-11 01:21:21 +03:00
|
|
|
return PMS_STANDARD;
|
|
|
|
}
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
int
|
2008-03-15 21:59:07 +03:00
|
|
|
pmsprobe(device_t parent, cfdata_t match, void *aux)
|
1998-03-22 18:41:27 +03:00
|
|
|
{
|
2004-03-13 20:31:33 +03:00
|
|
|
struct pckbport_attach_args *pa = aux;
|
1998-03-22 18:41:27 +03:00
|
|
|
u_char cmd[1], resp[2];
|
|
|
|
int res;
|
|
|
|
|
2004-03-13 20:31:33 +03:00
|
|
|
if (pa->pa_slot != PCKBPORT_AUX_SLOT)
|
2004-03-19 00:05:19 +03:00
|
|
|
return 0;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
/* Flush any garbage. */
|
2004-03-13 20:31:33 +03:00
|
|
|
pckbport_flush(pa->pa_tag, pa->pa_slot);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
/* reset the device */
|
|
|
|
cmd[0] = PMS_RESET;
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_poll_cmd(pa->pa_tag, pa->pa_slot, cmd, 1, 2, resp, 1);
|
1998-03-22 18:41:27 +03:00
|
|
|
if (res) {
|
2009-03-08 18:06:56 +03:00
|
|
|
aprint_debug("pmsprobe: reset error %d\n", res);
|
2004-03-19 00:05:19 +03:00
|
|
|
return 0;
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
if (resp[0] != PMS_RSTDONE) {
|
1999-01-23 19:05:56 +03:00
|
|
|
printf("pmsprobe: reset response 0x%x\n", resp[0]);
|
2004-03-19 00:05:19 +03:00
|
|
|
return 0;
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get type number (0 = mouse) */
|
|
|
|
if (resp[1] != 0) {
|
2009-03-08 18:06:56 +03:00
|
|
|
aprint_debug("pmsprobe: type 0x%x\n", resp[1]);
|
2004-03-19 00:05:19 +03:00
|
|
|
return 0;
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
2004-03-19 00:05:19 +03:00
|
|
|
return 10;
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-03-15 21:59:07 +03:00
|
|
|
pmsattach(device_t parent, device_t self, void *aux)
|
1998-03-22 18:41:27 +03:00
|
|
|
{
|
2006-03-29 10:51:47 +04:00
|
|
|
struct pms_softc *sc = device_private(self);
|
2004-03-13 20:31:33 +03:00
|
|
|
struct pckbport_attach_args *pa = aux;
|
1998-03-22 18:41:27 +03:00
|
|
|
struct wsmousedev_attach_args a;
|
2004-12-24 21:33:06 +03:00
|
|
|
u_char cmd[2], resp[2];
|
1998-03-22 18:41:27 +03:00
|
|
|
int res;
|
|
|
|
|
2008-03-15 21:46:22 +03:00
|
|
|
sc->sc_dev = self;
|
1998-03-22 18:41:27 +03:00
|
|
|
sc->sc_kbctag = pa->pa_tag;
|
|
|
|
sc->sc_kbcslot = pa->pa_slot;
|
|
|
|
|
2007-12-01 17:35:51 +03:00
|
|
|
aprint_naive("\n");
|
|
|
|
aprint_normal("\n");
|
1998-03-22 18:41:27 +03:00
|
|
|
|
1998-07-29 00:18:36 +04:00
|
|
|
/* Flush any garbage. */
|
2004-03-13 20:31:33 +03:00
|
|
|
pckbport_flush(pa->pa_tag, pa->pa_slot);
|
1998-07-29 00:18:36 +04:00
|
|
|
|
|
|
|
/* reset the device */
|
|
|
|
cmd[0] = PMS_RESET;
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_poll_cmd(pa->pa_tag, pa->pa_slot, cmd, 1, 2, resp, 1);
|
1998-07-29 00:18:36 +04:00
|
|
|
if (res || resp[0] != PMS_RSTDONE || resp[1] != 0) {
|
2009-03-08 18:06:56 +03:00
|
|
|
aprint_debug("pmsattach: reset error\n");
|
1998-07-29 00:18:36 +04:00
|
|
|
return;
|
|
|
|
}
|
1998-03-22 18:41:27 +03:00
|
|
|
sc->inputstate = 0;
|
2002-03-20 20:06:51 +03:00
|
|
|
sc->buttons = 0;
|
2002-05-29 13:30:35 +04:00
|
|
|
sc->protocol = PMS_UNKNOWN;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2005-01-18 13:22:51 +03:00
|
|
|
#ifdef PMS_SYNAPTICS_TOUCHPAD
|
2004-12-24 21:33:06 +03:00
|
|
|
/* Probe for synaptics touchpad. */
|
|
|
|
if (pms_synaptics_probe_init(sc) == 0) {
|
|
|
|
sc->protocol = PMS_SYNAPTICS;
|
2005-01-18 13:22:51 +03:00
|
|
|
} else
|
2008-12-14 03:42:33 +03:00
|
|
|
#endif
|
|
|
|
#ifdef PMS_ELANTECH_TOUCHPAD
|
|
|
|
if (pms_elantech_probe_init(sc) == 0) {
|
|
|
|
sc->protocol = PMS_ELANTECH;
|
|
|
|
} else
|
2005-01-18 13:22:51 +03:00
|
|
|
#endif
|
2004-12-24 21:33:06 +03:00
|
|
|
/* Install generic handler. */
|
|
|
|
pckbport_set_inputhandler(sc->sc_kbctag, sc->sc_kbcslot,
|
2008-03-15 21:46:22 +03:00
|
|
|
pmsinput, sc, device_xname(sc->sc_dev));
|
2005-01-18 13:22:51 +03:00
|
|
|
|
1999-01-23 19:05:56 +03:00
|
|
|
a.accessops = &pms_accessops;
|
1998-03-22 18:41:27 +03:00
|
|
|
a.accesscookie = sc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the wsmouse, saving a handle to it.
|
|
|
|
* Note that we don't need to check this pointer against NULL
|
1999-01-23 19:05:56 +03:00
|
|
|
* here or in pmsintr, because if this fails pms_enable() will
|
|
|
|
* never be called, so pmsinput() will never be called.
|
1998-03-22 18:41:27 +03:00
|
|
|
*/
|
2008-03-15 21:46:22 +03:00
|
|
|
sc->sc_wsmousedev = config_found_ia(self, "wsmousedev", &a, wsmousedevprint);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
/* no interrupts until enabled */
|
|
|
|
cmd[0] = PMS_DEV_DISABLE;
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_poll_cmd(pa->pa_tag, pa->pa_slot, cmd, 1, 0, 0, 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
if (res)
|
2007-12-01 17:35:51 +03:00
|
|
|
aprint_error("pmsattach: disable error\n");
|
2004-03-13 20:31:33 +03:00
|
|
|
pckbport_slot_enable(sc->sc_kbctag, sc->sc_kbcslot, 0);
|
2001-09-13 18:16:12 +04:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
kthread_create(PRI_NONE, 0, NULL, pms_reset_thread, sc,
|
2008-03-15 21:46:22 +03:00
|
|
|
&sc->sc_event_thread, device_xname(sc->sc_dev));
|
2002-05-18 02:49:48 +04:00
|
|
|
|
2002-02-27 03:30:07 +03:00
|
|
|
#ifndef PMS_DISABLE_POWERHOOK
|
2002-07-10 06:05:25 +04:00
|
|
|
sc->sc_suspended = 0;
|
2007-12-09 23:27:42 +03:00
|
|
|
#endif
|
|
|
|
if (!pmf_device_register(self, pms_suspend, pms_resume))
|
|
|
|
aprint_error_dev(self, "couldn't establish power handler\n");
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
2001-09-13 18:16:12 +04:00
|
|
|
static void
|
2004-03-19 00:05:19 +03:00
|
|
|
do_enable(struct pms_softc *sc)
|
1998-03-22 18:41:27 +03:00
|
|
|
{
|
2004-12-24 21:33:06 +03:00
|
|
|
u_char cmd[2];
|
1998-03-22 18:41:27 +03:00
|
|
|
int res;
|
|
|
|
|
|
|
|
sc->inputstate = 0;
|
2002-03-20 20:06:51 +03:00
|
|
|
sc->buttons = 0;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2004-03-13 20:31:33 +03:00
|
|
|
pckbport_slot_enable(sc->sc_kbctag, sc->sc_kbcslot, 1);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2005-01-18 13:22:51 +03:00
|
|
|
#ifdef PMS_SYNAPTICS_TOUCHPAD
|
2004-12-24 21:33:06 +03:00
|
|
|
if (sc->protocol == PMS_SYNAPTICS)
|
|
|
|
pms_synaptics_enable(sc);
|
2005-01-18 13:22:51 +03:00
|
|
|
#endif
|
2008-12-14 03:42:33 +03:00
|
|
|
#ifdef PMS_ELANTECH_TOUCHPAD
|
|
|
|
if (sc->protocol == PMS_ELANTECH)
|
|
|
|
pms_elantech_enable(sc);
|
|
|
|
#endif
|
2004-12-24 21:33:06 +03:00
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
cmd[0] = PMS_DEV_ENABLE;
|
2004-12-24 21:33:06 +03:00
|
|
|
res = pckbport_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, cmd,
|
|
|
|
1, 0, 1, 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
if (res)
|
2007-12-01 17:35:51 +03:00
|
|
|
aprint_error("pms_enable: command error %d\n", res);
|
2002-03-11 01:21:21 +03:00
|
|
|
|
2002-05-29 13:30:35 +04:00
|
|
|
if (sc->protocol == PMS_UNKNOWN)
|
|
|
|
sc->protocol = pms_protocol(sc->sc_kbctag, sc->sc_kbcslot);
|
2002-03-20 20:06:51 +03:00
|
|
|
DPRINTF(("pms_enable: using %s protocol\n",
|
|
|
|
pms_protocols[sc->protocol].name));
|
1998-03-22 18:41:27 +03:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
u_char scmd[2];
|
|
|
|
|
|
|
|
scmd[0] = PMS_SET_RES;
|
|
|
|
scmd[1] = 3; /* 8 counts/mm */
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, scmd,
|
2002-03-11 01:21:21 +03:00
|
|
|
2, 0, 1, 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
if (res)
|
1999-01-23 19:05:56 +03:00
|
|
|
printf("pms_enable: setup error1 (%d)\n", res);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
scmd[0] = PMS_SET_SCALE21;
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, scmd,
|
2002-03-11 01:21:21 +03:00
|
|
|
1, 0, 1, 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
if (res)
|
1999-01-23 19:05:56 +03:00
|
|
|
printf("pms_enable: setup error2 (%d)\n", res);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
scmd[0] = PMS_SET_SAMPLE;
|
|
|
|
scmd[1] = 100; /* 100 samples/sec */
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, scmd,
|
2002-03-11 01:21:21 +03:00
|
|
|
2, 0, 1, 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
if (res)
|
1999-01-23 19:05:56 +03:00
|
|
|
printf("pms_enable: setup error3 (%d)\n", res);
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-09-13 18:16:12 +04:00
|
|
|
static void
|
2004-03-19 00:05:19 +03:00
|
|
|
do_disable(struct pms_softc *sc)
|
1998-03-22 18:41:27 +03:00
|
|
|
{
|
|
|
|
u_char cmd[1];
|
|
|
|
int res;
|
|
|
|
|
|
|
|
cmd[0] = PMS_DEV_DISABLE;
|
2004-12-24 21:33:06 +03:00
|
|
|
res = pckbport_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, cmd,
|
|
|
|
1, 0, 1, 0);
|
1998-03-22 18:41:27 +03:00
|
|
|
if (res)
|
2007-12-01 17:35:51 +03:00
|
|
|
aprint_error("pms_disable: command error\n");
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2004-03-13 20:31:33 +03:00
|
|
|
pckbport_slot_enable(sc->sc_kbctag, sc->sc_kbcslot, 0);
|
2001-09-13 18:16:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-03-19 00:05:19 +03:00
|
|
|
pms_enable(void *v)
|
2001-09-13 18:16:12 +04:00
|
|
|
{
|
|
|
|
struct pms_softc *sc = v;
|
2002-05-18 02:49:48 +04:00
|
|
|
int s;
|
2001-09-13 18:16:12 +04:00
|
|
|
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
return EBUSY;
|
|
|
|
|
2002-05-18 02:49:48 +04:00
|
|
|
do_enable(sc);
|
2001-09-13 18:16:12 +04:00
|
|
|
|
2002-05-18 02:49:48 +04:00
|
|
|
s = spltty();
|
|
|
|
sc->sc_enabled = 1;
|
|
|
|
splx(s);
|
2001-09-13 18:16:12 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-19 00:05:19 +03:00
|
|
|
pms_disable(void *v)
|
2001-09-13 18:16:12 +04:00
|
|
|
{
|
|
|
|
struct pms_softc *sc = v;
|
2002-05-29 13:30:35 +04:00
|
|
|
int s;
|
2001-09-13 18:16:12 +04:00
|
|
|
|
2002-05-18 02:49:48 +04:00
|
|
|
do_disable(sc);
|
1998-03-22 18:41:27 +03:00
|
|
|
|
2002-05-29 13:30:35 +04:00
|
|
|
s = spltty();
|
1998-03-22 18:41:27 +03:00
|
|
|
sc->sc_enabled = 0;
|
2002-05-29 13:30:35 +04:00
|
|
|
splx(s);
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
2007-12-09 23:27:42 +03:00
|
|
|
static bool
|
2010-02-25 01:37:54 +03:00
|
|
|
pms_suspend(device_t dv, const pmf_qual_t *qual)
|
2001-09-13 18:16:12 +04:00
|
|
|
{
|
2007-12-09 23:27:42 +03:00
|
|
|
struct pms_softc *sc = device_private(dv);
|
|
|
|
|
|
|
|
if (sc->sc_enabled)
|
|
|
|
do_disable(sc);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2010-02-25 01:37:54 +03:00
|
|
|
pms_resume(device_t dv, const pmf_qual_t *qual)
|
2007-12-09 23:27:42 +03:00
|
|
|
{
|
|
|
|
struct pms_softc *sc = device_private(dv);
|
2001-09-13 18:16:12 +04:00
|
|
|
|
2005-01-18 13:22:51 +03:00
|
|
|
#ifdef PMS_SYNAPTICS_TOUCHPAD
|
2007-12-09 23:27:42 +03:00
|
|
|
if (sc->protocol == PMS_SYNAPTICS) {
|
|
|
|
pms_synaptics_resume(sc);
|
2008-01-29 01:29:00 +03:00
|
|
|
if (sc->sc_enabled) {
|
|
|
|
do_enable(sc);
|
|
|
|
}
|
2007-12-09 23:27:42 +03:00
|
|
|
} else
|
2008-12-14 03:42:33 +03:00
|
|
|
#endif
|
|
|
|
#ifdef PMS_ELANTECH_TOUCHPAD
|
|
|
|
if (sc->protocol == PMS_ELANTECH) {
|
|
|
|
pms_elantech_resume(sc);
|
|
|
|
if (sc->sc_enabled) {
|
|
|
|
do_enable(sc);
|
|
|
|
}
|
|
|
|
} else
|
2005-01-18 13:22:51 +03:00
|
|
|
#endif
|
2007-12-09 23:27:42 +03:00
|
|
|
if (sc->sc_enabled) {
|
|
|
|
/* recheck protocol & init mouse */
|
|
|
|
sc->protocol = PMS_UNKNOWN;
|
|
|
|
do_enable(sc); /* only if we were suspended */
|
2001-09-13 18:16:12 +04:00
|
|
|
}
|
2007-12-09 23:27:42 +03:00
|
|
|
|
|
|
|
return true;
|
2001-09-13 18:16:12 +04:00
|
|
|
}
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
int
|
2007-03-04 08:59:00 +03:00
|
|
|
pms_ioctl(void *v, u_long cmd, void *data, int flag,
|
2006-11-16 04:32:37 +03:00
|
|
|
struct lwp *l)
|
1998-03-22 18:41:27 +03:00
|
|
|
{
|
1999-01-23 19:05:56 +03:00
|
|
|
struct pms_softc *sc = v;
|
1999-05-03 19:45:16 +04:00
|
|
|
u_char kbcmd[2];
|
|
|
|
int i;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case WSMOUSEIO_GTYPE:
|
|
|
|
*(u_int *)data = WSMOUSE_TYPE_PS2;
|
1999-05-03 19:45:16 +04:00
|
|
|
break;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1999-05-03 19:45:16 +04:00
|
|
|
case WSMOUSEIO_SRES:
|
|
|
|
i = (*(u_int *)data - 12) / 25;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1999-05-03 19:45:16 +04:00
|
|
|
if (i < 0)
|
|
|
|
i = 0;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1999-05-03 19:45:16 +04:00
|
|
|
if (i > 3)
|
|
|
|
i = 3;
|
|
|
|
|
|
|
|
kbcmd[0] = PMS_SET_RES;
|
2005-02-27 03:26:58 +03:00
|
|
|
kbcmd[1] = i;
|
|
|
|
i = pckbport_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, kbcmd,
|
1999-05-03 19:45:16 +04:00
|
|
|
2, 0, 1, 0);
|
2005-02-27 03:26:58 +03:00
|
|
|
|
1999-05-03 19:45:16 +04:00
|
|
|
if (i)
|
|
|
|
printf("pms_ioctl: SET_RES command error\n");
|
|
|
|
break;
|
2004-12-24 21:33:06 +03:00
|
|
|
|
1999-05-03 19:45:16 +04:00
|
|
|
default:
|
2004-03-19 00:05:19 +03:00
|
|
|
return EPASSTHROUGH;
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
2004-03-19 00:05:19 +03:00
|
|
|
return 0;
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
|
2002-05-18 02:49:48 +04:00
|
|
|
static void
|
2004-03-19 00:05:19 +03:00
|
|
|
pms_reset_thread(void *arg)
|
2002-05-18 02:49:48 +04:00
|
|
|
{
|
|
|
|
struct pms_softc *sc = arg;
|
|
|
|
u_char cmd[1], resp[2];
|
|
|
|
int res;
|
2002-07-08 11:43:31 +04:00
|
|
|
int save_protocol;
|
2002-05-18 02:49:48 +04:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
tsleep(&sc->sc_enabled, PWAIT, "pmsreset", 0);
|
2002-05-14 01:18:51 +04:00
|
|
|
#ifdef PMSDEBUG
|
2002-05-18 02:49:48 +04:00
|
|
|
if (pmsdebug)
|
2002-05-14 01:18:51 +04:00
|
|
|
#endif
|
|
|
|
#if defined(PMSDEBUG) || defined(DIAGNOSTIC)
|
2008-03-15 21:46:22 +03:00
|
|
|
aprint_debug_dev(sc->sc_dev,
|
|
|
|
"resetting mouse interface\n");
|
2002-05-14 01:18:51 +04:00
|
|
|
#endif
|
2002-07-08 11:43:31 +04:00
|
|
|
save_protocol = sc->protocol;
|
2002-05-18 02:49:48 +04:00
|
|
|
pms_disable(sc);
|
|
|
|
cmd[0] = PMS_RESET;
|
2004-12-24 21:33:06 +03:00
|
|
|
res = pckbport_enqueue_cmd(sc->sc_kbctag, sc->sc_kbcslot, cmd,
|
|
|
|
1, 2, 1, resp);
|
2006-09-13 04:55:57 +04:00
|
|
|
if (res) {
|
2008-03-15 21:46:22 +03:00
|
|
|
DPRINTF(("%s: reset error %d\n",
|
|
|
|
device_xname(sc->sc_dev), res));
|
2006-09-13 04:55:57 +04:00
|
|
|
}
|
2004-12-24 21:33:06 +03:00
|
|
|
|
2008-12-14 03:42:33 +03:00
|
|
|
/* For the synaptics and elantech case, leave the protocol alone. */
|
|
|
|
if (sc->protocol != PMS_SYNAPTICS && sc->protocol != PMS_ELANTECH)
|
2004-12-24 21:33:06 +03:00
|
|
|
sc->protocol = PMS_UNKNOWN;
|
2005-01-18 13:22:51 +03:00
|
|
|
|
2002-05-18 02:49:48 +04:00
|
|
|
pms_enable(sc);
|
2002-07-08 11:43:31 +04:00
|
|
|
if (sc->protocol != save_protocol) {
|
|
|
|
#if defined(PMSDEBUG) || defined(DIAGNOSTIC)
|
2008-03-15 21:46:22 +03:00
|
|
|
aprint_verbose_dev(sc->sc_dev,
|
|
|
|
"protocol change, sleeping and retrying\n");
|
2002-07-08 11:43:31 +04:00
|
|
|
#endif
|
|
|
|
pms_disable(sc);
|
|
|
|
cmd[0] = PMS_RESET;
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_enqueue_cmd(sc->sc_kbctag,
|
2002-07-08 11:43:31 +04:00
|
|
|
sc->sc_kbcslot, cmd, 1, 2, 1, resp);
|
2006-09-13 04:55:57 +04:00
|
|
|
if (res) {
|
2002-07-08 11:43:31 +04:00
|
|
|
DPRINTF(("%s: reset error %d\n",
|
2008-03-15 21:46:22 +03:00
|
|
|
device_xname(sc->sc_dev), res));
|
2006-09-13 04:55:57 +04:00
|
|
|
}
|
2002-07-08 11:43:31 +04:00
|
|
|
tsleep(pms_reset_thread, PWAIT, "pmsreset", hz);
|
|
|
|
cmd[0] = PMS_RESET;
|
2004-03-13 20:31:33 +03:00
|
|
|
res = pckbport_enqueue_cmd(sc->sc_kbctag,
|
2002-07-08 11:43:31 +04:00
|
|
|
sc->sc_kbcslot, cmd, 1, 2, 1, resp);
|
2006-09-13 04:55:57 +04:00
|
|
|
if (res) {
|
2002-07-08 11:43:31 +04:00
|
|
|
DPRINTF(("%s: reset error %d\n",
|
2008-03-15 21:46:22 +03:00
|
|
|
device_xname(sc->sc_dev), res));
|
2006-09-13 04:55:57 +04:00
|
|
|
}
|
2002-07-08 11:43:31 +04:00
|
|
|
sc->protocol = PMS_UNKNOWN; /* reprobe protocol */
|
|
|
|
pms_enable(sc);
|
|
|
|
#if defined(PMSDEBUG) || defined(DIAGNOSTIC)
|
|
|
|
if (sc->protocol != save_protocol) {
|
|
|
|
printf("%s: protocol changed.\n",
|
2008-03-15 21:46:22 +03:00
|
|
|
device_xname(sc->sc_dev));
|
2002-07-08 11:43:31 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2002-05-18 02:49:48 +04:00
|
|
|
}
|
2002-03-11 01:21:21 +03:00
|
|
|
}
|
|
|
|
|
1998-03-22 18:41:27 +03:00
|
|
|
/* Masks for the first byte of a packet */
|
2002-03-20 20:06:51 +03:00
|
|
|
#define PMS_LBUTMASK 0x01
|
|
|
|
#define PMS_RBUTMASK 0x02
|
|
|
|
#define PMS_MBUTMASK 0x04
|
|
|
|
#define PMS_4BUTMASK 0x10
|
|
|
|
#define PMS_5BUTMASK 0x20
|
|
|
|
|
|
|
|
void
|
2004-03-19 00:05:19 +03:00
|
|
|
pmsinput(void *vsc, int data)
|
1998-03-22 18:41:27 +03:00
|
|
|
{
|
1999-01-23 19:05:56 +03:00
|
|
|
struct pms_softc *sc = vsc;
|
1998-03-22 18:41:27 +03:00
|
|
|
u_int changed;
|
2002-03-20 20:06:51 +03:00
|
|
|
int dx, dy, dz = 0;
|
|
|
|
int newbuttons = 0;
|
1998-03-22 18:41:27 +03:00
|
|
|
|
|
|
|
if (!sc->sc_enabled) {
|
2002-03-11 01:21:21 +03:00
|
|
|
/* Interrupts are not expected. Discard the byte. */
|
1998-03-22 18:41:27 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-06-08 02:33:33 +04:00
|
|
|
getmicrouptime(&sc->current);
|
2002-09-14 03:39:05 +04:00
|
|
|
|
2002-05-23 23:00:28 +04:00
|
|
|
if (sc->inputstate > 0) {
|
2002-03-13 07:36:49 +03:00
|
|
|
struct timeval diff;
|
|
|
|
|
|
|
|
timersub(&sc->current, &sc->last, &diff);
|
2002-03-20 20:06:51 +03:00
|
|
|
/*
|
|
|
|
* Empirically, the delay should be about 1700us on a standard
|
|
|
|
* PS/2 port. I have seen delays as large as 4500us (rarely)
|
|
|
|
* in regular use. When using a confused mouse, I generally
|
2002-09-14 03:39:05 +04:00
|
|
|
* see delays at least as large as 30,000us. -seebs
|
2002-03-29 00:54:27 +03:00
|
|
|
*
|
|
|
|
* The thinkpad trackball returns at 22-23ms. So we use
|
2002-09-14 03:39:05 +04:00
|
|
|
* >= 40ms. In the future, I'll implement adaptable timeout
|
2002-03-29 00:54:27 +03:00
|
|
|
* by increasing the timeout if the mouse reset happens
|
|
|
|
* too frequently -christos
|
2002-03-20 20:06:51 +03:00
|
|
|
*/
|
2002-09-14 03:39:05 +04:00
|
|
|
if (diff.tv_sec > 0 || diff.tv_usec >= 40000) {
|
2002-05-14 01:18:51 +04:00
|
|
|
DPRINTF(("pms_input: unusual delay (%ld.%06ld s), "
|
|
|
|
"scheduling reset\n",
|
|
|
|
(long)diff.tv_sec, (long)diff.tv_usec));
|
2002-03-13 07:36:49 +03:00
|
|
|
sc->inputstate = 0;
|
2002-03-20 20:06:51 +03:00
|
|
|
sc->sc_enabled = 0;
|
2002-05-18 02:49:48 +04:00
|
|
|
wakeup(&sc->sc_enabled);
|
2002-03-13 07:36:49 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-03-11 01:21:21 +03:00
|
|
|
}
|
|
|
|
sc->last = sc->current;
|
2002-05-23 23:00:28 +04:00
|
|
|
|
2002-05-29 13:30:35 +04:00
|
|
|
if (sc->inputstate == 0) {
|
|
|
|
/*
|
2004-03-19 00:05:19 +03:00
|
|
|
* Some devices (seen on trackballs anytime, and on
|
|
|
|
* some mice shortly after reset) output garbage bytes
|
|
|
|
* between packets. Just ignore them.
|
2002-05-29 13:30:35 +04:00
|
|
|
*/
|
2002-05-23 23:00:28 +04:00
|
|
|
if ((data & 0xc0) != 0)
|
|
|
|
return; /* not in sync yet, discard input */
|
|
|
|
}
|
|
|
|
|
2002-03-20 20:06:51 +03:00
|
|
|
sc->packet[sc->inputstate++] = data & 0xff;
|
1998-03-22 18:41:27 +03:00
|
|
|
switch (sc->inputstate) {
|
|
|
|
case 0:
|
2002-03-20 20:06:51 +03:00
|
|
|
/* no useful processing can be done yet */
|
1998-03-22 18:41:27 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2002-05-29 13:30:35 +04:00
|
|
|
/*
|
|
|
|
* Why should we test for bit 0x8 and insist on it here?
|
|
|
|
* The old (psm.c and psm_intelli.c) drivers didn't do
|
|
|
|
* it, and there are devices where it does harm (that's
|
|
|
|
* why it is not used if using PMS_STANDARD protocol).
|
|
|
|
* Anyway, it does not to cause any harm to accept packets
|
|
|
|
* without this bit.
|
|
|
|
*/
|
|
|
|
#if 0
|
2002-05-23 23:00:28 +04:00
|
|
|
if (sc->protocol == PMS_STANDARD)
|
|
|
|
break;
|
2002-03-20 20:06:51 +03:00
|
|
|
if (!(sc->packet[0] & 0x8)) {
|
|
|
|
DPRINTF(("pmsinput: 0x8 not set in first byte "
|
|
|
|
"[0x%02x], resetting\n", sc->packet[0]));
|
|
|
|
sc->inputstate = 0;
|
|
|
|
sc->sc_enabled = 0;
|
2002-05-18 02:49:48 +04:00
|
|
|
wakeup(&sc->sc_enabled);
|
2002-03-20 20:06:51 +03:00
|
|
|
return;
|
|
|
|
}
|
2002-05-29 13:30:35 +04:00
|
|
|
#endif
|
1998-03-22 18:41:27 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2002-03-11 01:21:21 +03:00
|
|
|
break;
|
|
|
|
|
2002-03-20 20:06:51 +03:00
|
|
|
case 4:
|
|
|
|
/* Case 4 is a superset of case 3. This is *not* an accident. */
|
|
|
|
if (sc->protocol == PMS_SCROLL3) {
|
|
|
|
dz = sc->packet[3];
|
|
|
|
if (dz >= 128)
|
|
|
|
dz -= 256;
|
|
|
|
if (dz == -128)
|
|
|
|
dz = -127;
|
|
|
|
} else if (sc->protocol == PMS_SCROLL5) {
|
|
|
|
dz = sc->packet[3] & 0xf;
|
|
|
|
if (dz >= 8)
|
|
|
|
dz -= 16;
|
|
|
|
if (sc->packet[3] & PMS_4BUTMASK)
|
|
|
|
newbuttons |= 0x8;
|
|
|
|
if (sc->packet[3] & PMS_5BUTMASK)
|
|
|
|
newbuttons |= 0x10;
|
|
|
|
} else {
|
|
|
|
DPRINTF(("pmsinput: why am I looking at this byte?\n"));
|
|
|
|
dz = 0;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
2002-03-11 01:21:21 +03:00
|
|
|
case 3:
|
2002-03-20 20:06:51 +03:00
|
|
|
/*
|
|
|
|
* This is only an endpoint for scroll protocols with 4
|
|
|
|
* bytes, or the standard protocol with 3.
|
|
|
|
*/
|
|
|
|
if (sc->protocol != PMS_STANDARD && sc->inputstate == 3)
|
|
|
|
break;
|
|
|
|
|
|
|
|
newbuttons |= ((sc->packet[0] & PMS_LBUTMASK) ? 0x1 : 0) |
|
|
|
|
((sc->packet[0] & PMS_MBUTMASK) ? 0x2 : 0) |
|
|
|
|
((sc->packet[0] & PMS_RBUTMASK) ? 0x4 : 0);
|
|
|
|
|
|
|
|
dx = sc->packet[1];
|
|
|
|
if (dx >= 128)
|
|
|
|
dx -= 256;
|
|
|
|
if (dx == -128)
|
|
|
|
dx = -127;
|
|
|
|
|
|
|
|
dy = sc->packet[2];
|
|
|
|
if (dy >= 128)
|
|
|
|
dy -= 256;
|
|
|
|
if (dy == -128)
|
|
|
|
dy = -127;
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2002-05-29 13:30:35 +04:00
|
|
|
sc->inputstate = 0;
|
2002-03-20 20:06:51 +03:00
|
|
|
changed = (sc->buttons ^ newbuttons);
|
|
|
|
sc->buttons = newbuttons;
|
|
|
|
|
|
|
|
#ifdef PMSDEBUG
|
|
|
|
if (sc->protocol == PMS_STANDARD) {
|
|
|
|
DPRINTF(("pms: packet: 0x%02x%02x%02x\n",
|
|
|
|
sc->packet[0], sc->packet[1], sc->packet[2]));
|
2002-03-11 01:21:21 +03:00
|
|
|
} else {
|
2002-03-28 18:21:50 +03:00
|
|
|
DPRINTF(("pms: packet: 0x%02x%02x%02x%02x\n",
|
2002-03-20 20:06:51 +03:00
|
|
|
sc->packet[0], sc->packet[1], sc->packet[2],
|
|
|
|
sc->packet[3]));
|
2002-03-11 01:21:21 +03:00
|
|
|
}
|
|
|
|
#endif
|
2002-03-20 20:06:51 +03:00
|
|
|
if (dx || dy || dz || changed) {
|
|
|
|
#ifdef PMSDEBUG
|
2002-03-28 18:21:50 +03:00
|
|
|
DPRINTF(("pms: x %+03d y %+03d z %+03d "
|
2002-03-20 20:06:51 +03:00
|
|
|
"buttons 0x%02x\n", dx, dy, dz, sc->buttons));
|
|
|
|
#endif
|
1998-03-22 18:41:27 +03:00
|
|
|
wsmouse_input(sc->sc_wsmousedev,
|
2006-11-12 22:00:42 +03:00
|
|
|
sc->buttons, dx, dy, dz, 0,
|
2002-03-11 01:21:21 +03:00
|
|
|
WSMOUSE_INPUT_DELTA);
|
|
|
|
}
|
2002-03-20 20:06:51 +03:00
|
|
|
memset(sc->packet, 0, 4);
|
1998-03-22 18:41:27 +03:00
|
|
|
break;
|
2002-03-20 20:06:51 +03:00
|
|
|
|
|
|
|
/* If we get here, we have problems. */
|
|
|
|
default:
|
|
|
|
printf("pmsinput: very confused. resetting.\n");
|
|
|
|
sc->inputstate = 0;
|
|
|
|
sc->sc_enabled = 0;
|
2002-05-18 02:49:48 +04:00
|
|
|
wakeup(&sc->sc_enabled);
|
2002-03-20 20:06:51 +03:00
|
|
|
return;
|
1998-03-22 18:41:27 +03:00
|
|
|
}
|
|
|
|
}
|