dtms.c revision 1.7
11.7Splunky/*	$NetBSD: dtms.c,v 1.7 2006/11/12 19:00:43 plunky 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 * 3. All advertising materials mentioning features or use of this software
191.2Sad *    must display the following acknowledgement:
201.2Sad *        This product includes software developed by the NetBSD
211.2Sad *        Foundation, Inc. and its contributors.
221.2Sad * 4. Neither the name of The NetBSD Foundation nor the names of its
231.2Sad *    contributors may be used to endorse or promote products derived
241.2Sad *    from this software without specific prior written permission.
251.2Sad *
261.2Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.2Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.2Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.2Sad * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.2Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.2Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.2Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.2Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.2Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.2Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.2Sad * POSSIBILITY OF SUCH DAMAGE.
371.2Sad */
381.2Sad
391.2Sad#include <sys/cdefs.h>
401.7Splunky__KERNEL_RCSID(0, "$NetBSD: dtms.c,v 1.7 2006/11/12 19:00:43 plunky Exp $");
411.2Sad
421.2Sad#include "locators.h"
431.2Sad
441.2Sad#include <sys/param.h>
451.2Sad#include <sys/systm.h>
461.2Sad#include <sys/device.h>
471.2Sad#include <sys/ioctl.h>
481.2Sad#include <sys/syslog.h>
491.2Sad
501.2Sad#include <machine/bus.h>
511.2Sad
521.2Sad#include <arch/pmax/tc/dtreg.h>
531.2Sad#include <arch/pmax/tc/dtvar.h>
541.2Sad
551.2Sad#include <dev/wscons/wsconsio.h>
561.2Sad#include <dev/wscons/wsmousevar.h>
571.2Sad
581.2Sadstruct dtms_softc {
591.2Sad	struct device	sc_dv;
601.2Sad	struct device	*sc_wsmousedev;
611.2Sad	int		sc_enabled;
621.2Sad};
631.2Sad
641.2Sadint	dtms_match(struct device *, struct cfdata *, void *);
651.2Sadvoid	dtms_attach(struct device *, struct device *, void *);
661.2Sadint	dtms_input(void *, int);
671.2Sadint	dtms_enable(void *);
681.6Schristosint	dtms_ioctl(void *, u_long, caddr_t, int, struct lwp *);
691.2Sadvoid	dtms_disable(void *);
701.3Sadvoid	dtms_handler(void *, struct dt_msg *);
711.2Sad
721.2SadCFATTACH_DECL(dtms, sizeof(struct dtms_softc),
731.2Sad    dtms_match, dtms_attach, NULL, NULL);
741.2Sad
751.2Sadconst struct wsmouse_accessops dtms_accessops = {
761.2Sad	dtms_enable,
771.2Sad	dtms_ioctl,
781.2Sad	dtms_disable,
791.2Sad};
801.2Sad
811.2Sadint
821.2Saddtms_match(struct device *parent, struct cfdata *cf, void *aux)
831.2Sad{
841.2Sad	struct dt_attach_args *dta;
851.2Sad
861.2Sad	dta = aux;
871.3Sad	return (dta->dta_addr == DT_ADDR_MOUSE);
881.2Sad}
891.2Sad
901.2Sadvoid
911.2Saddtms_attach(struct device *parent, struct device *self, void *aux)
921.2Sad{
931.2Sad	struct wsmousedev_attach_args a;
941.2Sad	struct dtms_softc *sc;
951.2Sad	struct dt_softc *dt;
961.2Sad
971.2Sad	dt = (struct dt_softc *)parent;
981.2Sad	sc = (struct dtms_softc *)self;
991.2Sad
1001.2Sad	printf("\n");
1011.2Sad
1021.3Sad	if (dt_establish_handler(dt, &dt_ms_dv, self, dtms_handler)) {
1031.2Sad		printf("%s: unable to establish handler\n", self->dv_xname);
1041.2Sad		return;
1051.2Sad	}
1061.2Sad
1071.2Sad	a.accessops = &dtms_accessops;
1081.2Sad	a.accesscookie = sc;
1091.2Sad	sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint);
1101.2Sad}
1111.2Sad
1121.2Sadint
1131.2Saddtms_enable(void *cookie)
1141.2Sad{
1151.2Sad	struct dtms_softc *sc;
1161.2Sad
1171.2Sad	sc = cookie;
1181.2Sad	if (sc->sc_enabled)
1191.2Sad		return (EBUSY);
1201.2Sad	sc->sc_enabled = 1;
1211.2Sad
1221.2Sad	return (0);
1231.2Sad}
1241.2Sad
1251.2Sadvoid
1261.2Saddtms_disable(void *cookie)
1271.2Sad{
1281.2Sad	struct dtms_softc *sc;
1291.2Sad
1301.2Sad	sc = cookie;
1311.2Sad	sc->sc_enabled = 0;
1321.2Sad}
1331.2Sad
1341.2Sadint
1351.6Schristosdtms_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
1361.2Sad{
1371.2Sad
1381.2Sad	if (cmd == WSMOUSEIO_GTYPE) {
1391.2Sad		*(u_int *)data = WSMOUSE_TYPE_VSXXX;
1401.2Sad		return (0);
1411.2Sad	}
1421.2Sad
1431.5Smhitch	return (EPASSTHROUGH);
1441.2Sad}
1451.2Sad
1461.2Sadvoid
1471.3Saddtms_handler(void *cookie, struct dt_msg *msg)
1481.2Sad{
1491.2Sad	struct dtms_softc *sc;
1501.4Smhitch	int buttons, dx, dy;
1511.4Smhitch	short tmp;
1521.2Sad
1531.3Sad	sc = cookie;
1541.3Sad
1551.3Sad	if (!sc->sc_enabled)
1561.3Sad		return;
1571.2Sad
1581.3Sad	tmp = DT_GET_SHORT(msg->body[0], msg->body[1]);
1591.4Smhitch	buttons = tmp & 1;
1601.4Smhitch	if (tmp & 2)
1611.4Smhitch		buttons |= 4;
1621.4Smhitch	if (tmp & 4)
1631.4Smhitch		buttons |= 2;
1641.3Sad
1651.3Sad	tmp = DT_GET_SHORT(msg->body[2], msg->body[3]);
1661.3Sad	if (tmp < 0)
1671.3Sad		dx = -(-tmp & 0x1f);
1681.3Sad	else
1691.3Sad		dx = tmp & 0x1f;
1701.3Sad
1711.3Sad	tmp = DT_GET_SHORT(msg->body[4], msg->body[5]);
1721.3Sad	if (tmp < 0)
1731.3Sad		dy = -(-tmp & 0x1f);
1741.3Sad	else
1751.3Sad		dy = tmp & 0x1f;
1761.3Sad
1771.7Splunky	wsmouse_input(sc->sc_wsmousedev,
1781.7Splunky			buttons,
1791.7Splunky			dx, dy, 0, 0,
1801.7Splunky			WSMOUSE_INPUT_DELTA);
1811.2Sad}
182