11.13Sthorpej/* $NetBSD: dtms.c,v 1.13 2021/08/07 16:19:02 thorpej 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.13Sthorpej__KERNEL_RCSID(0, "$NetBSD: dtms.c,v 1.13 2021/08/07 16:19:02 thorpej Exp $"); 341.2Sad 351.2Sad#include "locators.h" 361.2Sad 371.2Sad#include <sys/param.h> 381.11Smatt#include <sys/bus.h> 391.2Sad#include <sys/device.h> 401.2Sad#include <sys/ioctl.h> 411.2Sad#include <sys/syslog.h> 421.11Smatt#include <sys/systm.h> 431.2Sad 441.11Smatt#include <pmax/tc/dtreg.h> 451.11Smatt#include <pmax/tc/dtvar.h> 461.2Sad 471.2Sad#include <dev/wscons/wsconsio.h> 481.2Sad#include <dev/wscons/wsmousevar.h> 491.2Sad 501.2Sadstruct dtms_softc { 511.10Stsutsui device_t sc_dev; 521.10Stsutsui device_t sc_wsmousedev; 531.2Sad int sc_enabled; 541.2Sad}; 551.2Sad 561.10Stsutsuiint dtms_match(device_t, cfdata_t, void *); 571.10Stsutsuivoid dtms_attach(device_t, device_t, void *); 581.2Sadint dtms_input(void *, int); 591.2Sadint dtms_enable(void *); 601.8Schristosint dtms_ioctl(void *, u_long, void *, int, struct lwp *); 611.2Sadvoid dtms_disable(void *); 621.3Sadvoid dtms_handler(void *, struct dt_msg *); 631.2Sad 641.10StsutsuiCFATTACH_DECL_NEW(dtms, sizeof(struct dtms_softc), 651.2Sad dtms_match, dtms_attach, NULL, NULL); 661.2Sad 671.2Sadconst struct wsmouse_accessops dtms_accessops = { 681.2Sad dtms_enable, 691.2Sad dtms_ioctl, 701.2Sad dtms_disable, 711.2Sad}; 721.2Sad 731.2Sadint 741.10Stsutsuidtms_match(device_t parent, cfdata_t cf, void *aux) 751.2Sad{ 761.2Sad struct dt_attach_args *dta; 771.2Sad 781.2Sad dta = aux; 791.3Sad return (dta->dta_addr == DT_ADDR_MOUSE); 801.2Sad} 811.2Sad 821.2Sadvoid 831.10Stsutsuidtms_attach(device_t parent, device_t self, void *aux) 841.2Sad{ 851.2Sad struct wsmousedev_attach_args a; 861.2Sad struct dtms_softc *sc; 871.2Sad struct dt_softc *dt; 881.2Sad 891.10Stsutsui dt = device_private(parent); 901.10Stsutsui sc = device_private(self); 911.10Stsutsui sc->sc_dev = self; 921.2Sad 931.2Sad printf("\n"); 941.2Sad 951.10Stsutsui if (dt_establish_handler(dt, &dt_ms_dv, sc, dtms_handler)) { 961.10Stsutsui printf("%s: unable to establish handler\n", device_xname(self)); 971.2Sad return; 981.2Sad } 991.2Sad 1001.2Sad a.accessops = &dtms_accessops; 1011.2Sad a.accesscookie = sc; 1021.13Sthorpej sc->sc_wsmousedev = config_found(self, &a, wsmousedevprint, CFARGS_NONE); 1031.2Sad} 1041.2Sad 1051.2Sadint 1061.2Saddtms_enable(void *cookie) 1071.2Sad{ 1081.2Sad struct dtms_softc *sc; 1091.2Sad 1101.2Sad sc = cookie; 1111.2Sad if (sc->sc_enabled) 1121.2Sad return (EBUSY); 1131.2Sad sc->sc_enabled = 1; 1141.2Sad 1151.2Sad return (0); 1161.2Sad} 1171.2Sad 1181.2Sadvoid 1191.2Saddtms_disable(void *cookie) 1201.2Sad{ 1211.2Sad struct dtms_softc *sc; 1221.2Sad 1231.2Sad sc = cookie; 1241.2Sad sc->sc_enabled = 0; 1251.2Sad} 1261.2Sad 1271.2Sadint 1281.8Schristosdtms_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l) 1291.2Sad{ 1301.2Sad 1311.2Sad if (cmd == WSMOUSEIO_GTYPE) { 1321.2Sad *(u_int *)data = WSMOUSE_TYPE_VSXXX; 1331.2Sad return (0); 1341.2Sad } 1351.2Sad 1361.5Smhitch return (EPASSTHROUGH); 1371.2Sad} 1381.2Sad 1391.2Sadvoid 1401.3Saddtms_handler(void *cookie, struct dt_msg *msg) 1411.2Sad{ 1421.2Sad struct dtms_softc *sc; 1431.4Smhitch int buttons, dx, dy; 1441.4Smhitch short tmp; 1451.2Sad 1461.3Sad sc = cookie; 1471.3Sad 1481.3Sad if (!sc->sc_enabled) 1491.3Sad return; 1501.2Sad 1511.3Sad tmp = DT_GET_SHORT(msg->body[0], msg->body[1]); 1521.4Smhitch buttons = tmp & 1; 1531.4Smhitch if (tmp & 2) 1541.4Smhitch buttons |= 4; 1551.4Smhitch if (tmp & 4) 1561.4Smhitch buttons |= 2; 1571.3Sad 1581.3Sad tmp = DT_GET_SHORT(msg->body[2], msg->body[3]); 1591.3Sad if (tmp < 0) 1601.3Sad dx = -(-tmp & 0x1f); 1611.3Sad else 1621.3Sad dx = tmp & 0x1f; 1631.3Sad 1641.3Sad tmp = DT_GET_SHORT(msg->body[4], msg->body[5]); 1651.3Sad if (tmp < 0) 1661.3Sad dy = -(-tmp & 0x1f); 1671.3Sad else 1681.3Sad dy = tmp & 0x1f; 1691.3Sad 1701.7Splunky wsmouse_input(sc->sc_wsmousedev, 1711.7Splunky buttons, 1721.7Splunky dx, dy, 0, 0, 1731.7Splunky WSMOUSE_INPUT_DELTA); 1741.2Sad} 175