| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *  Acorn RiscPC mouse driver for Linux/ARM | 
 | 3 |  * | 
 | 4 |  *  Copyright (c) 2000-2002 Vojtech Pavlik | 
 | 5 |  *  Copyright (C) 1996-2002 Russell King | 
 | 6 |  * | 
 | 7 |  */ | 
 | 8 |  | 
 | 9 | /* | 
 | 10 |  * This program is free software; you can redistribute it and/or modify it | 
 | 11 |  * under the terms of the GNU General Public License version 2 as published by | 
 | 12 |  * the Free Software Foundation. | 
 | 13 |  * | 
 | 14 |  * This handles the Acorn RiscPCs mouse.  We basically have a couple of | 
 | 15 |  * hardware registers that track the sensor count for the X-Y movement and | 
 | 16 |  * another register holding the button state.  On every VSYNC interrupt we read | 
 | 17 |  * the complete state and then work out if something has changed. | 
 | 18 |  */ | 
 | 19 |  | 
 | 20 | #include <linux/module.h> | 
 | 21 | #include <linux/sched.h> | 
 | 22 | #include <linux/ptrace.h> | 
 | 23 | #include <linux/interrupt.h> | 
 | 24 | #include <linux/init.h> | 
 | 25 | #include <linux/input.h> | 
 | 26 |  | 
 | 27 | #include <asm/hardware.h> | 
 | 28 | #include <asm/irq.h> | 
 | 29 | #include <asm/io.h> | 
 | 30 | #include <asm/hardware/iomd.h> | 
 | 31 |  | 
 | 32 | MODULE_AUTHOR("Vojtech Pavlik, Russell King"); | 
 | 33 | MODULE_DESCRIPTION("Acorn RiscPC mouse driver"); | 
 | 34 | MODULE_LICENSE("GPL"); | 
 | 35 |  | 
 | 36 | static short rpcmouse_lastx, rpcmouse_lasty; | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 37 | static struct input_dev *rpcmouse_dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 39 | static irqreturn_t rpcmouse_irq(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { | 
 | 41 | 	struct input_dev *dev = dev_id; | 
 | 42 | 	short x, y, dx, dy, b; | 
 | 43 |  | 
 | 44 | 	x = (short) iomd_readl(IOMD_MOUSEX); | 
 | 45 | 	y = (short) iomd_readl(IOMD_MOUSEY); | 
 | 46 | 	b = (short) (__raw_readl(0xe0310000) ^ 0x70); | 
 | 47 |  | 
 | 48 | 	dx = x - rpcmouse_lastx; | 
| Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 49 | 	dy = y - rpcmouse_lasty; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 |  | 
 | 51 | 	rpcmouse_lastx = x; | 
 | 52 | 	rpcmouse_lasty = y; | 
 | 53 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | 	input_report_rel(dev, REL_X, dx); | 
 | 55 | 	input_report_rel(dev, REL_Y, -dy); | 
 | 56 |  | 
 | 57 | 	input_report_key(dev, BTN_LEFT,   b & 0x40); | 
 | 58 | 	input_report_key(dev, BTN_MIDDLE, b & 0x20); | 
 | 59 | 	input_report_key(dev, BTN_RIGHT,  b & 0x10); | 
 | 60 |  | 
 | 61 | 	input_sync(dev); | 
 | 62 |  | 
 | 63 | 	return IRQ_HANDLED; | 
 | 64 | } | 
 | 65 |  | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 66 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static int __init rpcmouse_init(void) | 
 | 68 | { | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 69 | 	if (!(rpcmouse_dev = input_allocate_device())) | 
 | 70 | 		return -ENOMEM; | 
 | 71 |  | 
 | 72 | 	rpcmouse_dev->name = "Acorn RiscPC Mouse"; | 
 | 73 | 	rpcmouse_dev->phys = "rpcmouse/input0"; | 
 | 74 | 	rpcmouse_dev->id.bustype = BUS_HOST; | 
 | 75 | 	rpcmouse_dev->id.vendor  = 0x0005; | 
 | 76 | 	rpcmouse_dev->id.product = 0x0001; | 
 | 77 | 	rpcmouse_dev->id.version = 0x0100; | 
 | 78 |  | 
 | 79 | 	rpcmouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); | 
 | 80 | 	rpcmouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); | 
 | 81 | 	rpcmouse_dev->relbit[0]	= BIT(REL_X) | BIT(REL_Y); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 |  | 
 | 83 | 	rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX); | 
 | 84 | 	rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY); | 
 | 85 |  | 
| Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 86 | 	if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | 		printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n"); | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 88 | 		input_free_device(rpcmouse_dev); | 
 | 89 | 		return -EBUSY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | 	} | 
 | 91 |  | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 92 | 	input_register_device(rpcmouse_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 |  | 
 | 94 | 	return 0; | 
 | 95 | } | 
 | 96 |  | 
 | 97 | static void __exit rpcmouse_exit(void) | 
 | 98 | { | 
| Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 99 | 	free_irq(IRQ_VSYNCPULSE, rpcmouse_dev); | 
 | 100 | 	input_unregister_device(rpcmouse_dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } | 
 | 102 |  | 
 | 103 | module_init(rpcmouse_init); | 
 | 104 | module_exit(rpcmouse_exit); |