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

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

diff -u --recursive --new-file v2.3.12/linux/drivers/char/atixlmouse.c linux/drivers/char/atixlmouse.c
@@ -7,6 +7,9 @@
  * Modified by Chris Colohan (colohan@eecg.toronto.edu)
  * 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.3a
  */
 
@@ -26,6 +29,8 @@
 #include <asm/system.h>
 #include <asm/irq.h>
 
+#include "busmouse.h"
+
 #define ATIXL_MOUSE_IRQ		5 /* H/W interrupt # set up on ATIXL board */
 #define ATIXL_BUSMOUSE		3 /* Minor device # (mknod c 10 3 /dev/bm) */
 
@@ -59,17 +64,7 @@
 
 /* Same general mouse structure */
 
-static struct mouse_status {
-	char buttons;
-	char latch_buttons;
-	int dx;
-	int dy;
-	int present;
-	int ready;
-	int active;
-	wait_queue_head_t wait;
-	struct fasync_struct *fasync;
-} mouse;
+static int msedev;
 
 void mouse_interrupt(int irq, void *dev_id, struct pt_regs * regs)
 {
@@ -82,35 +77,13 @@
 	dy = inb( ATIXL_MSE_DATA_PORT);
 	outb(ATIXL_MSE_READ_BUTTONS, ATIXL_MSE_CONTROL_PORT); /* Select IR0 - Button Status */
 	buttons = inb( ATIXL_MSE_DATA_PORT);
-	if (dx != 0 || dy != 0 || buttons != mouse.latch_buttons) {
-		add_mouse_randomness((buttons << 16) + (dy << 8) + dx);
-		mouse.latch_buttons |= buttons;
-		mouse.dx += dx;
-		mouse.dy += dy;
-		mouse.ready = 1;
-		wake_up_interruptible(&mouse.wait);
-		if (mouse.fasync)
-			kill_fasync(mouse.fasync, SIGIO);
-	}
+	busmouse_add_movementbuttons(msedev, dx, -dy, buttons);
 	ATIXL_MSE_ENABLE_UPDATE();
 }
 
-static int fasync_mouse(int fd, struct file *filp, int on)
-{
-	int retval;
-	retval = fasync_helper(fd, filp, on, &mouse.fasync);
-	if (retval < 0)
-		return retval;
-	return 0;
-}
-
 static int release_mouse(struct inode * inode, struct file * file)
 {
-	fasync_mouse(-1, file, 0);
-	if (--mouse.active)
-		return 0;
 	ATIXL_MSE_INT_OFF(); /* Interrupts are really shut down here */
-	mouse.ready = 0;
 	free_irq(ATIXL_MOUSE_IRQ, NULL);
 	MOD_DEC_USE_COUNT;
 	return 0;
@@ -118,90 +91,17 @@
 
 static int open_mouse(struct inode * inode, struct file * file)
 {
-	if (!mouse.present)
-		return -EINVAL;
-	if (mouse.active++)
-		return 0;
-	if (request_irq(ATIXL_MOUSE_IRQ, mouse_interrupt, 0, "ATIXL mouse", NULL)) {
-		mouse.active--;
+	if (request_irq(ATIXL_MOUSE_IRQ, mouse_interrupt, 0, "ATIXL mouse", NULL))
 		return -EBUSY;
-	}
-	mouse.ready = 0;
-	mouse.dx = 0;
-	mouse.dy = 0;
-	mouse.buttons = mouse.latch_buttons = 0;
 	ATIXL_MSE_INT_ON(); /* Interrupts are really enabled here */
 	MOD_INC_USE_COUNT;
 	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)
-{
-       ssize_t i;
-
-	if (count < 3)
-		return -EINVAL;
-	if (!mouse.ready)
-		return -EAGAIN;
-	ATIXL_MSE_DISABLE_UPDATE();
-	/* Allowed interrupts to occur during data gathering - shouldn't hurt */
-	put_user((char)(~mouse.latch_buttons&7) | 0x80 , buffer);
-	if (mouse.dx < -127)
-		mouse.dx = -127;
-	if (mouse.dx > 127)
-		mouse.dx =  127;
-	put_user((char)mouse.dx, buffer + 1);
-	if (mouse.dy < -127)
-		mouse.dy = -127;
-	if (mouse.dy > 127)
-		mouse.dy =  127;
-	put_user((char)-mouse.dy, buffer + 2);
-	for(i = 3; i < count; i++)
-		put_user(0x00, buffer + i);
-	mouse.dx = 0;
-	mouse.dy = 0;
-	mouse.latch_buttons = mouse.buttons;
-	mouse.ready = 0;
-	ATIXL_MSE_ENABLE_UPDATE();
-	return i; /* i data bytes returned */
-}
-
-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 atixl_busmouse_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 busmouse atixlmouse = {
+	ATIXL_BUSMOUSE, "atixl", open_mouse, release_mouse, 0
 };
 
-static struct miscdevice atixl_mouse = { 
-	ATIXL_BUSMOUSE, "atixl", &atixl_busmouse_fops
-};
-
-
 int __init atixl_busmouse_init(void)
 {
 	unsigned char a,b,c;
@@ -211,22 +111,18 @@
 	c = inb( ATIXL_MSE_SIGNATURE_PORT );
 	if (( a != b ) && ( a == c ))
 		printk(KERN_INFO "\nATI Inport ");
-	else{
-		mouse.present = 0;
+	else
 		return -EIO;
-	}
 	outb(0x80, ATIXL_MSE_CONTROL_PORT);	/* Reset the Inport device */
 	outb(0x07, ATIXL_MSE_CONTROL_PORT);	/* Select Internal Register 7 */
 	outb(0x0a, ATIXL_MSE_DATA_PORT);	/* Data Interrupts 8+, 1=30hz, 2=50hz, 3=100hz, 4=200hz rate */
-	mouse.present = 1;
-	mouse.active = 0;
-	mouse.ready = 0;
-	mouse.buttons = mouse.latch_buttons = 0;
-	mouse.dx = mouse.dy = 0;
-	init_waitqueue_head(&mouse.wait);
-	printk("Bus mouse detected and installed.\n");
-	misc_register(&atixl_mouse);
-	return 0;
+
+	msedev = register_busmouse(&atixlmouse);
+	if (msedev < 0)
+		printk("Bus mouse initialisation error.\n");
+	else
+		printk("Bus mouse detected and installed.\n");
+	return msedev < 0 ? msedev : 0;
 }
 
 #ifdef MODULE
@@ -238,6 +134,6 @@
 
 void cleanup_module(void)
 {
-	misc_deregister(&atixl_mouse);
+	unregister_busmouse(msedev);
 }
 #endif

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