patch-2.3.13 linux/drivers/char/msbusmouse.c

Next file: linux/drivers/char/nvram.c
Previous file: linux/drivers/char/misc.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.12/linux/drivers/char/msbusmouse.c linux/drivers/char/msbusmouse.c
@@ -27,6 +27,9 @@
  *
  * Modularised 8-Sep-95 Philip Blundell <pjb27@cam.ac.uk>
  *
+ * Converted to use new generic busmouse code.  5 Apr 1998
+ *   Russell King <rmk@arm.uk.linux.org>
+ *
  * version 0.3b
  */
 
@@ -35,7 +38,7 @@
 #include <linux/kernel.h>
 #include <linux/ioport.h>
 #include <linux/sched.h>
-#include <linux/busmouse.h>
+#include <linux/logibusmouse.h>
 #include <linux/signal.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
@@ -48,7 +51,9 @@
 #include <asm/system.h>
 #include <asm/irq.h>
 
-static struct mouse_status mouse;
+#include "busmouse.h"
+
+static int msedev;
 static int mouse_irq = MOUSE_IRQ;
 
 #ifdef MODULE
@@ -81,35 +86,17 @@
 	outb(MS_MSE_COMMAND_MODE, MS_MSE_CONTROL_PORT);
 	outb((inb(MS_MSE_DATA_PORT) & 0xdf), MS_MSE_DATA_PORT);
 
-	if (dx != 0 || dy != 0 || buttons != mouse.buttons || ((~buttons) & 0x07)) {
-		add_mouse_randomness((buttons << 16) + (dy << 8) + dx);
-		mouse.buttons = buttons;
-		mouse.dx += dx;
-		mouse.dy += dy;
-		mouse.ready = 1;
-		wake_up_interruptible(&mouse.wait);
-		if (mouse.fasyncptr)
-			kill_fasync(mouse.fasyncptr, SIGIO);
-	}
-}
-
-static int fasync_mouse(int fd, struct file *filp, int on)
-{
-	int retval;
-
-	retval = fasync_helper(fd, filp, on, &mouse.fasyncptr);
-	if (retval < 0)
-		return retval;
-	return 0;
+	/* why did the original have:
+	 * if (dx != 0 || dy != 0 || buttons != mouse.buttons ||
+	 *    ((~buttons) & 0x07))
+	 *    ^^^^^^^^^^^^^^^^^^^ this?
+	 */
+	busmouse_add_movementbuttons(msedev, dx, -dy, buttons);
 }
 
 static int release_mouse(struct inode * inode, struct file * file)
 {
-	fasync_mouse(-1, file, 0);
-	if (--mouse.active)
-		return 0;
 	MS_MSE_INT_OFF();
-	mouse.ready = 0; 
 	free_irq(mouse_irq, NULL);
 	MOD_DEC_USE_COUNT;
 	return 0;
@@ -117,86 +104,24 @@
 
 static int open_mouse(struct inode * inode, struct file * file)
 {
-	if (!mouse.present)
-		return -EINVAL;
-	if (mouse.active++)
-		return 0;
-	if (request_irq(mouse_irq, ms_mouse_interrupt, 0, "MS Busmouse", NULL)) {
-		mouse.active--;
+	if (request_irq(mouse_irq, ms_mouse_interrupt, 0, "MS Busmouse", NULL))
 		return -EBUSY;
-	}
-	mouse.ready = mouse.dx = mouse.dy = 0;	
-	mouse.buttons = 0x80;
+
 	outb(MS_MSE_START, MS_MSE_CONTROL_PORT);
 	MOD_INC_USE_COUNT;
 	MS_MSE_INT_ON();	
 	return 0;
 }
 
-static ssize_t write_mouse(struct file * file,
-       const char * buffer, size_t count, loff_t *ppos)
-{
-	return -EINVAL;
-}
-
-static ssize_t read_mouse(struct file * file,
-       char * buffer, size_t count, loff_t *ppos)
-{
-	int i, dx, dy;
-
-	if (count < 3)
-		return -EINVAL;
-	if (!mouse.ready)
-		return -EAGAIN;
-	put_user(mouse.buttons | 0x80, buffer);
-	dx = mouse.dx < -127 ? -127 : mouse.dx > 127 ?  127 :  mouse.dx;
-	dy = mouse.dy < -127 ?  127 : mouse.dy > 127 ? -127 : -mouse.dy;
-	put_user((char)dx, buffer + 1);
-	put_user((char)dy, buffer + 2);
-	for (i = 3; i < count; i++)
-		put_user(0x00, buffer + i);
-	mouse.dx -= dx;
-	mouse.dy += dy;
-	mouse.ready = 0;
-	return i;	
-}
-
-static unsigned int mouse_poll(struct file *file, poll_table * wait)
-{
-	poll_wait(file, &mouse.wait, wait);
-	if (mouse.ready) 
-		return POLLIN | POLLRDNORM;
-	return 0;
-}
-
-struct file_operations ms_bus_mouse_fops = {
-	NULL,		/* mouse_seek */
-	read_mouse,
-	write_mouse,
-	NULL, 		/* mouse_readdir */
-	mouse_poll, 	/* mouse_poll */
-	NULL, 		/* mouse_ioctl */
-	NULL,		/* mouse_mmap */
-	open_mouse,
-	NULL,		/* flush */
-	release_mouse,
-	NULL,
-	fasync_mouse,
-};
-
-static struct miscdevice ms_bus_mouse = {
-	MICROSOFT_BUSMOUSE, "msbusmouse", &ms_bus_mouse_fops
+static struct busmouse msbusmouse = {
+	MICROSOFT_BUSMOUSE, "msbusmouse", open_mouse, release_mouse, 0
 };
 
 __initfunc(int ms_bus_mouse_init(void))
 {
+	int present = 0;
 	int mse_byte, i;
 
-	mouse.present = mouse.active = mouse.ready = 0;
-	mouse.buttons = 0x80;
-	mouse.dx = mouse.dy = 0;
-	init_waitqueue_head(&mouse.wait);
-
 	if (check_region(MS_MSE_CONTROL_PORT, 0x04))
 		return -ENODEV;
 
@@ -207,32 +132,30 @@
 		for (i = 0; i < 4; i++) {
 			if (inb_p(MS_MSE_SIGNATURE_PORT) == 0xde) {
 				if (inb_p(MS_MSE_SIGNATURE_PORT) == mse_byte)
-					mouse.present = 1;
+					present = 1;
 				else
-					mouse.present = 0;
+					present = 0;
 			} else
-				mouse.present = 0;
+				present = 0;
 		}
 	}
-	if (mouse.present == 0)
+	if (present == 0)
 		return -EIO;
 	MS_MSE_INT_OFF();
 	request_region(MS_MSE_CONTROL_PORT, 0x04, "MS Busmouse");
-	printk(KERN_INFO "Microsoft BusMouse detected and installed.\n");
-	misc_register(&ms_bus_mouse);
-	return 0;
-}
-
-#ifdef MODULE
-int init_module(void)
-{
-	return ms_bus_mouse_init();
+	msedev = register_busmouse(&msbusmouse);
+	if (msedev < 0)
+		printk(KERN_WARNING "Unable to register msbusmouse driver.\n");
+	else
+		printk(KERN_INFO "Microsoft BusMouse detected and installed.\n");
+	return msedev < 0 ? msedev : 0;
 }
 
-void cleanup_module(void)
+void ms_bus_mouse_exit(void)
 {
-	misc_deregister(&ms_bus_mouse);
+	unregister_busmouse(msedev);
 	release_region(MS_MSE_CONTROL_PORT, 0x04);
 }
-#endif
 
+module_init(ms_bus_mouse_init)
+module_exit(ms_bus_mouse_exit)

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)