Subject: wsmouse for sun mouse
To: None <port-sparc@netbsd.org, port-sparc64@netbsd.org>
From: Andrey Petrov <petrov@netbsd.org>
List: port-sparc
Date: 05/20/2003 23:51:41
Hi,

This patch implements wsmouse fro sun's mouse. I tested it on sparc64,
and am going to do test build for sparc. As usually I appreciate comments.

Thanks,
	Andrey

Index: ms.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sun/ms.c,v
retrieving revision 1.23
diff -u -p -r1.23 ms.c
--- ms.c	2002/10/23 09:13:56	1.23
+++ ms.c	2003/05/20 23:46:01
@@ -79,7 +79,11 @@ __KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.23 
 #include <dev/sun/event_var.h>
 #include <dev/sun/msvar.h>
 
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsmousevar.h>
+
 #include "locators.h"
+#include "wsmouse.h"
 
 extern struct cfdriver ms_cd;
 
@@ -315,6 +319,19 @@ ms_input(ms, c)
 		/* NOTREACHED */
 	}
 
+#if NWSMOUSE > 0
+	if (ms->ms_wsmousedev != NULL && ms->ms_ready == 2) {
+		mb = ((ms->ms_mb & 4) >> 2) |
+			(ms->ms_mb & 2) |
+			((ms->ms_mb & 1) << 2);
+		wsmouse_input(ms->ms_wsmousedev,
+			      mb, ms->ms_dx, ms->ms_dy, 0,
+			      WSMOUSE_INPUT_DELTA);
+		ms->ms_dx = 0;
+		ms->ms_dy = 0;
+		return;
+	}
+#endif
 	/*
 	 * We have at least one event (mouse button, delta-X, or
 	 * delta-Y; possibly all three, and possibly three separate
Index: msvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/sun/msvar.h,v
retrieving revision 1.3
diff -u -p -r1.3 msvar.h
--- msvar.h	2001/12/09 12:02:06	1.3
+++ msvar.h	2003/05/20 23:46:01
@@ -111,6 +111,8 @@ struct ms_softc {
 	 */
 	volatile int ms_ready;		/* event queue is ready */
 	struct	evvar ms_events;	/* event queue state */
+
+	struct device *ms_wsmousedev;
 };
 
 /* front-end call back for mouse input */
Index: sunms.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sun/sunms.c,v
retrieving revision 1.13
diff -u -p -r1.13 sunms.c
--- sunms.c	2003/01/19 16:53:53	1.13
+++ sunms.c	2003/05/20 23:46:01
@@ -80,7 +80,11 @@ __KERNEL_RCSID(0, "$NetBSD: sunms.c,v 1.
 #include <dev/sun/msvar.h>
 #include <dev/sun/kbd_ms_ttyvar.h>
 
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wsmousevar.h>
+
 #include "ms.h"
+#include "wsmouse.h"
 #if NMS > 0
 
 #ifdef SUN_MS_BPS
@@ -101,6 +105,16 @@ struct  linesw sunms_disc =
 	{ "sunms", 8, ttylopen, ttylclose, ttyerrio, ttyerrio, ttynullioctl,
 	  sunmsinput, ttstart, nullmodem, ttpoll };	/* 8- SUNMOUSEDISC */
 
+int	sunms_enable(void *);
+int	sunms_ioctl(void *, u_long, caddr_t, int, struct proc *);
+void	sunms_disable(void *);
+
+const struct wsmouse_accessops	sunms_accessops = {
+	sunms_enable,
+	sunms_ioctl,
+	sunms_disable,
+};
+
 /*
  * ms_match: how is this zs channel configured?
  */
@@ -132,6 +146,9 @@ sunms_attach(parent, self, aux)
 	struct cfdata *cf;
 	struct tty *tp = args->kmta_tp;
 	int ms_unit;
+#if NWSMOUSE > 0
+	struct wsmousedev_attach_args a;
+#endif
 
 	cf = ms->ms_dev.dv_cfdata;
 	ms_unit = ms->ms_dev.dv_unit;
@@ -151,6 +168,16 @@ sunms_attach(parent, self, aux)
 
 	/* Initialize translator. */
 	ms->ms_byteno = -1;
+
+#if NWSMOUSE > 0
+	/*
+	 * attach wsmouse
+	 */
+	a.accessops = &sunms_accessops;
+	a.accesscookie = ms;
+
+	ms->ms_wsmousedev = config_found(self, &a, wsmousedevprint);
+#endif
 }
 
 /*
@@ -202,5 +229,60 @@ sunmsinput(c, tp)
 	/* Pass this up to the "middle" layer. */
 	ms_input(ms, c);
 	return (0);
+}
+
+int
+sunms_ioctl(v, cmd, data, flag, p)
+	void *v;
+	u_long cmd;
+	caddr_t data;
+	int flag;
+	struct proc *p;
+{
+/*	struct ms_softc *sc = v; */
+
+	switch (cmd) {
+	case WSMOUSEIO_GTYPE:
+		*(u_int *)data = WSMOUSE_TYPE_PS2; /* XXX  */
+		break;
+		
+	default:
+		return (EPASSTHROUGH);
+	}
+	return (0);
+}
+
+int
+sunms_enable(v)
+	void *v;
+{
+	struct ms_softc *ms = v;
+	int err;
+	int s;
+
+	if (ms->ms_ready)
+		return EBUSY;
+
+	err = sunmsiopen(v, 0);
+	if (err)
+		return err;
+
+	s = spltty();
+	ms->ms_ready = 2;
+	splx(s);
+
+	return 0;
+}
+
+void
+sunms_disable(v)
+	void *v;
+{
+	struct ms_softc *ms = v;
+	int s;
+
+	s = spltty();
+	ms->ms_ready = 0;
+	splx(s);
 }
 #endif
Index: files.sun
===================================================================
RCS file: /cvsroot/src/sys/dev/sun/files.sun,v
retrieving revision 1.7
diff -u -p -r1.7 files.sun
--- files.sun	2003/01/24 16:54:35	1.7
+++ files.sun	2003/05/20 23:46:01
@@ -35,7 +35,7 @@ file	dev/sun/wskbdmap_sun.c		kbd & wskbd
 
 # upper layer of sun ms driver
 # XXX: middle layer for sun serial mice (split out?)
-device ms: firm_events
+device ms: firm_events, wsmousedev
 file	dev/sun/ms.c			ms needs-flag
 
 # e.g. - lower layer: sun (mouse systems) mouse at zs