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

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

diff -u --recursive --new-file v2.3.12/linux/drivers/char/amigamouse.c linux/drivers/char/amigamouse.c
@@ -30,6 +30,9 @@
  * Moved the isr-allocation to the mouse_{open,close} calls, as there
  *   is no reason to service the mouse in the vertical blank isr if
  *   the mouse is not in use.             Jes Sorensen
+ *
+ * Converted to use new generic busmouse code.  5 Apr 1998
+ *   Russell King <rmk@arm.uk.linux.org>
  */
 
 #include <linux/module.h>
@@ -44,7 +47,7 @@
 #include <linux/random.h>
 #include <linux/poll.h>
 #include <linux/init.h>
-#include <linux/busmouse.h>
+#include <linux/logibusmouse.h>
 
 #include <asm/setup.h>
 #include <asm/system.h>
@@ -53,13 +56,15 @@
 #include <asm/amigahw.h>
 #include <asm/amigaints.h>
 
+#include "busmouse.h"
+
+#if 0
 #define AMI_MSE_INT_ON()	mouseint_allowed = 1
 #define AMI_MSE_INT_OFF()	mouseint_allowed = 0
-
-
-static struct mouse_status mouse;
-
 static int mouseint_allowed;
+#endif
+
+static int msedev;
 
 static void mouse_interrupt(int irq, void *dummy, struct pt_regs *fp)
 {
@@ -70,9 +75,11 @@
 
 	unsigned short joy0dat, potgor;
 
+#if 0
 	if(!mouseint_allowed)
 		return;
 	AMI_MSE_INT_OFF();
+#endif
 
 	/*
 	 *  This routine assumes, just like Kickstart, that the mouse
@@ -128,44 +135,10 @@
 		  (potgor & 0x0400 ? 1 : 0);	/* right button */
 
 
-	if (dx != 0 || dy != 0 || buttons != mouse.buttons) {
-	  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);
-
-	  /*
-	   * keep dx/dy reasonable, but still able to track when X (or
-	   * whatever) must page or is busy (i.e. long waits between
-	   * reads)
-	   */
-	  if (mouse.dx < -2048)
-	      mouse.dx = -2048;
-	  else
-	  if (mouse.dx >  2048)
-	      mouse.dx =  2048;
-
-	  if (mouse.dy < -2048)
-	      mouse.dy = -2048;
-	  else
-	  if (mouse.dy >  2048)
-	      mouse.dy =  2048;
-
-	  if (mouse.fasyncptr)
-	      kill_fasync(mouse.fasyncptr, SIGIO);
-	}
+	busmouse_add_movementbuttons(msedev, dx, -dy, buttons);
+#if 0
 	AMI_MSE_INT_ON();
-}
-
-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;
+#endif
 }
 
 /*
@@ -174,11 +147,10 @@
 
 static int release_mouse(struct inode * inode, struct file * file)
 {
-	fasync_mouse(-1, file, 0);
-	if (--mouse.active)
-		return 0;
 	free_irq(IRQ_AMIGA_VERTB, mouse_interrupt);
+#if 0
 	AMI_MSE_INT_OFF();
+#endif
 	MOD_DEC_USE_COUNT;
 	return 0;
 }
@@ -190,123 +162,25 @@
 
 static int open_mouse(struct inode * inode, struct file * file)
 {
-	if (!mouse.present)
-		return -EINVAL;
-	if (mouse.active++)
-		return 0;
 	/*
 	 *  use VBL to poll mouse deltas
 	 */
 
 	if(request_irq(IRQ_AMIGA_VERTB, mouse_interrupt, 0,
 	               "Amiga mouse", mouse_interrupt)) {
-		mouse.present = 0;
 		printk(KERN_INFO "Installing Amiga mouse failed.\n");
 		return -EIO;
 	}
 
-	mouse.ready = 0;
-	mouse.dx = 0;
-	mouse.dy = 0;
-	mouse.buttons = 0x87;
-	mouse.active = 1;
 	MOD_INC_USE_COUNT;
+#if 0
 	AMI_MSE_INT_ON();
+#endif
 	return 0;
 }
 
-/*
- * writes are disallowed
- */
-
-static ssize_t write_mouse(struct file * file, const char * buffer,
-			   size_t count, loff_t *ppos)
-{
-	return -EINVAL;
-}
-
-/*
- * read mouse data.  Currently never blocks.
- */
-
-static ssize_t read_mouse(struct file * file, char * buffer,
-			  size_t count, loff_t *ppos)
-{
-	int dx;
-	int dy;
-	unsigned char buttons; 
-
-	if (count < 3)
-		return -EINVAL;
-	if (!mouse.ready)
-		return -EAGAIN;
-
-	/*
-	 * Obtain the current mouse parameters and limit as appropriate for
-	 * the return data format.  Interrupts are only disabled while 
-	 * obtaining the parameters, NOT during the puts_user() calls,
-	 * so paging in put_user() does not effect mouse tracking.
-	 */
-
-	AMI_MSE_INT_OFF();
-	dx = mouse.dx;
-	dy = mouse.dy;
-	if (dx < -127)
-	    dx = -127;
-	else
-	if (dx > 127)
-	    dx = 127;
-	if (dy < -127)
-	    dy = -127;
-	else
-	if (dy > 127)
-	    dy = 127;
-	buttons = mouse.buttons;
-	mouse.dx -= dx;
-	mouse.dy -= dy;
-	mouse.ready = 0;
-	AMI_MSE_INT_ON();
-
-	if (put_user(buttons | 0x80, buffer++) ||
-	    put_user((char)dx, buffer++) ||
-	    put_user((char)dy, buffer++))
-		return -EINVAL;
-
-	if (count > 3)
-		if (clear_user(buffer, count - 3))
-			return -EFAULT;
-	return count;
-}
-
-/*
- * poll for mouse input
- */
-
-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 amiga_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 amiga_mouse = {
-	AMIGAMOUSE_MINOR, "amigamouse", &amiga_mouse_fops
+static struct busmouse amigamouse = {
+	AMIGAMOUSE_MINOR, "amigamouse", open_mouse, release_mouse, 7
 };
 
 int __init amiga_mouse_init(void)
@@ -315,21 +189,15 @@
 		return -ENODEV;
 
 	custom.joytest = 0;	/* reset counters */
-
+#if 0
 	AMI_MSE_INT_OFF();
-
-	mouse.active = 0;
-	mouse.ready = 0;
-	mouse.buttons = 0x87;
-	mouse.dx = 0;
-	mouse.dy = 0;
-	mouse.wait = NULL;
-
-	mouse.present = 1;
-
-	printk(KERN_INFO "Amiga mouse installed.\n");
-	misc_register(&amiga_mouse);
-	return 0;
+#endif
+	msedev = register_busmouse(&amigamouse);
+	if (msedev < 0)
+		printk(KERN_WARNING "Unable to install Amiga mouse driver.\n");
+	else
+		printk(KERN_INFO "Amiga mouse installed.\n");
+	return msedev < 0 ? msedev : 0;
 }
 
 #ifdef MODULE
@@ -341,6 +209,6 @@
 
 void cleanup_module(void)
 {
-	misc_deregister(&amiga_mouse);
+	unregsiter_busmouse(msedev);
 }
 #endif

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