dtms.c revision 1.10
11.10Stsutsui/*	$NetBSD: dtms.c,v 1.10 2011/06/04 01:37:36 tsutsui Exp $	*/
21.2Sad
31.2Sad/*-
41.2Sad * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
51.2Sad * All rights reserved.
61.2Sad *
71.2Sad * This code is derived from software contributed to The NetBSD Foundation
81.2Sad * by Andrew Doran.
91.2Sad *
101.2Sad * Redistribution and use in source and binary forms, with or without
111.2Sad * modification, are permitted provided that the following conditions
121.2Sad * are met:
131.2Sad * 1. Redistributions of source code must retain the above copyright
141.2Sad *    notice, this list of conditions and the following disclaimer.
151.2Sad * 2. Redistributions in binary form must reproduce the above copyright
161.2Sad *    notice, this list of conditions and the following disclaimer in the
171.2Sad *    documentation and/or other materials provided with the distribution.
181.2Sad *
191.2Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.2Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.2Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.2Sad * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.2Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.2Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.2Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.2Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.2Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.2Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.2Sad * POSSIBILITY OF SUCH DAMAGE.
301.2Sad */
311.2Sad
321.2Sad#include <sys/cdefs.h>
331.10Stsutsui__KERNEL_RCSID(0, "$NetBSD: dtms.c,v 1.10 2011/06/04 01:37:36 tsutsui Exp $");
341.2Sad
351.2Sad#include "locators.h"
361.2Sad
371.2Sad#include <sys/param.h>
381.2Sad#include <sys/systm.h>
391.2Sad#include <sys/device.h>
401.2Sad#include <sys/ioctl.h>
411.2Sad#include <sys/syslog.h>
421.2Sad
431.2Sad#include <machine/bus.h>
441.2Sad
451.2Sad#include <arch/pmax/tc/dtreg.h>
461.2Sad#include <arch/pmax/tc/dtvar.h>
471.2Sad
481.2Sad#include <dev/wscons/wsconsio.h>
491.2Sad#include <dev/wscons/wsmousevar.h>
501.2Sad
511.2Sadstruct dtms_softc {
521.10Stsutsui	device_t	sc_dev;
531.10Stsutsui	device_t	sc_wsmousedev;
541.2Sad	int		sc_enabled;
551.2Sad};
561.2Sad
571.10Stsutsuiint	dtms_match(device_t, cfdata_t, void *);
581.10Stsutsuivoid	dtms_attach(device_t, device_t, void *);
591.2Sadint	dtms_input(void *, int);
601.2Sadint	dtms_enable(void *);
611.8Schristosint	dtms_ioctl(void *, u_long, void *, int, struct lwp *);
621.2Sadvoid	dtms_disable(void *);
631.3Sadvoid	dtms_handler(void *, struct dt_msg *);
641.2Sad
651.10StsutsuiCFATTACH_DECL_NEW(dtms, sizeof(struct dtms_softc),
661.2Sad    dtms_match, dtms_attach, NULL, NULL);
671.2Sad
681.2Sadconst struct wsmouse_accessops dtms_accessops = {
691.2Sad	dtms_enable,
701.2Sad	dtms_ioctl,
711.2Sad	dtms_disable,
721.2Sad};
731.2Sad
741.2Sadint
751.10Stsutsuidtms_match(device_t parent, cfdata_t cf, void *aux)
761.2Sad{
771.2Sad	struct dt_attach_args *dta;
781.2Sad
791.2Sad	dta = aux;
801.3Sad	return (dta->dta_addr == DT_ADDR_MOUSE);
811.2Sad}
821.2Sad
831.2Sadvoid
841.10Stsutsuidtms_attach(device_t parent, device_t self, void *aux)
851.2Sad{
861.2Sad	struct wsmousedev_attach_args a;
871.2Sad	struct dtms_softc *sc;
881.2Sad	struct dt_softc *dt;
891.2Sad
901.10Stsutsui	dt = device_private(parent);
911.10Stsutsui	sc = device_private(self);
921.10Stsutsui	sc->sc_dev = self;
931.2Sad
941.2Sad	printf("\n");
951.2Sad
961.10Stsutsui	if (dt_establish_handler(dt, &dt_ms_dv, sc, dtms_handler)) {
971.10Stsutsui		printf("%s: unable to establish handler\n", device_xname(self));
981.2Sad		return;
991.2Sad	}
1001.2Sad
1011.2Sad	a.accessops = &dtms_accessops;
1021.2Sad	a.accesscookie = sc;
1031.2Sad	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
1041.2Sad}
1051.2Sad
1061.2Sadint
1071.2Saddtms_enable(void *cookie)
1081.2Sad{
1091.2Sad	struct dtms_softc *sc;
1101.2Sad
1111.2Sad	sc = cookie;
1121.2Sad	if (sc->sc_enabled)
1131.2Sad		return (EBUSY);
1141.2Sad	sc->sc_enabled = 1;
1151.2Sad
1161.2Sad	return (0);
1171.2Sad}
1181.2Sad
1191.2Sadvoid
1201.2Saddtms_disable(void *cookie)
1211.2Sad{
1221.2Sad	struct dtms_softc *sc;
1231.2Sad
1241.2Sad	sc = cookie;
1251.2Sad	sc->sc_enabled = 0;
1261.2Sad}
1271.2Sad
1281.2Sadint
1291.8Schristosdtms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l)
1301.2Sad{
1311.2Sad
1321.2Sad	if (cmd == WSMOUSEIO_GTYPE) {
1331.2Sad		*(u_int *)data = WSMOUSE_TYPE_VSXXX;
1341.2Sad		return (0);
1351.2Sad	}
1361.2Sad
1371.5Smhitch	return (EPASSTHROUGH);
1381.2Sad}
1391.2Sad
1401.2Sadvoid
1411.3Saddtms_handler(void *cookie, struct dt_msg *msg)
1421.2Sad{
1431.2Sad	struct dtms_softc *sc;
1441.4Smhitch	int buttons, dx, dy;
1451.4Smhitch	short tmp;
1461.2Sad
1471.3Sad	sc = cookie;
1481.3Sad
1491.3Sad	if (!sc->sc_enabled)
1501.3Sad		return;
1511.2Sad
1521.3Sad	tmp = DT_GET_SHORT(msg->body[0], msg->body[1]);
1531.4Smhitch	buttons = tmp & 1;
1541.4Smhitch	if (tmp & 2)
1551.4Smhitch		buttons |= 4;
1561.4Smhitch	if (tmp & 4)
1571.4Smhitch		buttons |= 2;
1581.3Sad
1591.3Sad	tmp = DT_GET_SHORT(msg->body[2], msg->body[3]);
1601.3Sad	if (tmp < 0)
1611.3Sad		dx = -(-tmp & 0x1f);
1621.3Sad	else
1631.3Sad		dx = tmp & 0x1f;
1641.3Sad
1651.3Sad	tmp = DT_GET_SHORT(msg->body[4], msg->body[5]);
1661.3Sad	if (tmp < 0)
1671.3Sad		dy = -(-tmp & 0x1f);
1681.3Sad	else
1691.3Sad		dy = tmp & 0x1f;
1701.3Sad
1711.7Splunky	wsmouse_input(sc->sc_wsmousedev,
1721.7Splunky			buttons,
1731.7Splunky			dx, dy, 0, 0,
1741.7Splunky			WSMOUSE_INPUT_DELTA);
1751.2Sad}
176