/*
* Copyright (c) 2002 Valeriy E. Ushakov
* 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.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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: ms_pckbport.c,v 1.9 2012/10/27 17:18:11 chs Exp $");
/*
* Attach PS/2 mouse at pckbport aux port
* and convert PS/2 mouse protocol to Sun firm events.
*/
/*
* NB: we {re,ab}use ms_softc input translator state and ignore its
* zs-related members. Not quite clean, but what the heck.
*/
struct ms_pckbport_softc {
struct ms_softc sc_ms;
/* no interrupts until device is actually opened */
cmd[0] = PMS_DEV_DISABLE;
res = pckbport_poll_cmd(sc->sc_kbctag, sc->sc_kbcslot, cmd,
1, 0, 0, 0);
if (res)
aprint_error("%s: failed to disable interrupts\n", __func__);
pckbport_slot_enable(sc->sc_kbctag, sc->sc_kbcslot, 0);
}
static int
ms_pckbport_iopen(device_t self, int flags)
{
struct ms_pckbport_softc *sc = device_private(self);
struct ms_softc *ms = &sc->sc_ms;
u_char cmd[1];
int res;
case 1:
ms->ms_dx += (int8_t)data;
++ms->ms_byteno;
return;
case 2:
ms->ms_dy += (int8_t)data;
ms->ms_byteno = 0;
break; /* last byte processed, report changes */
}
any = 0;
get = ms->ms_events.ev_get;
put = ms->ms_events.ev_put;
fe = &ms->ms_events.ev_q[put];
/* NEXT prepares to put the next event, backing off if necessary */
#define NEXT do { \
if ((++put) % EV_QSIZE == get) { \
--put; \
goto out; \
} \
} while (0)
/* ADVANCE completes the `put' of the event */
#define ADVANCE do { \
++fe; \
if (put >= EV_QSIZE) { \
put = 0; \
fe = &ms->ms_events.ev_q[0]; \
} \
any = 1; \
} while (0)
ub = ms->ms_ub; /* old buttons state */
mb = ms->ms_mb; /* new buttons state */
while ((d = mb ^ ub) != 0) {
/*
* Mouse button change. Convert up to three state changes
* to the `first' change, and drop it into the event queue.
*/
NEXT;
d = to_one[d - 1]; /* from 1..7 to {1,2,4} */
fe->id = to_id[d - 1]; /* from {1,2,4} to ID */
fe->value = (mb & d) ? VKEY_DOWN : VKEY_UP;
firm_gettime(fe);
ADVANCE;
ub ^= d; /* reflect the button state change */
}