0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/module.h>
0018 #include <linux/ptrace.h>
0019 #include <linux/interrupt.h>
0020 #include <linux/init.h>
0021 #include <linux/input.h>
0022 #include <linux/io.h>
0023
0024 #include <mach/hardware.h>
0025 #include <asm/irq.h>
0026 #include <asm/hardware/iomd.h>
0027
0028 MODULE_AUTHOR("Vojtech Pavlik, Russell King");
0029 MODULE_DESCRIPTION("Acorn RiscPC mouse driver");
0030 MODULE_LICENSE("GPL");
0031
0032 static short rpcmouse_lastx, rpcmouse_lasty;
0033 static struct input_dev *rpcmouse_dev;
0034
0035 static irqreturn_t rpcmouse_irq(int irq, void *dev_id)
0036 {
0037 struct input_dev *dev = dev_id;
0038 short x, y, dx, dy, b;
0039
0040 x = (short) iomd_readl(IOMD_MOUSEX);
0041 y = (short) iomd_readl(IOMD_MOUSEY);
0042 b = (short) (__raw_readl(IOMEM(0xe0310000)) ^ 0x70);
0043
0044 dx = x - rpcmouse_lastx;
0045 dy = y - rpcmouse_lasty;
0046
0047 rpcmouse_lastx = x;
0048 rpcmouse_lasty = y;
0049
0050 input_report_rel(dev, REL_X, dx);
0051 input_report_rel(dev, REL_Y, -dy);
0052
0053 input_report_key(dev, BTN_LEFT, b & 0x40);
0054 input_report_key(dev, BTN_MIDDLE, b & 0x20);
0055 input_report_key(dev, BTN_RIGHT, b & 0x10);
0056
0057 input_sync(dev);
0058
0059 return IRQ_HANDLED;
0060 }
0061
0062
0063 static int __init rpcmouse_init(void)
0064 {
0065 int err;
0066
0067 rpcmouse_dev = input_allocate_device();
0068 if (!rpcmouse_dev)
0069 return -ENOMEM;
0070
0071 rpcmouse_dev->name = "Acorn RiscPC Mouse";
0072 rpcmouse_dev->phys = "rpcmouse/input0";
0073 rpcmouse_dev->id.bustype = BUS_HOST;
0074 rpcmouse_dev->id.vendor = 0x0005;
0075 rpcmouse_dev->id.product = 0x0001;
0076 rpcmouse_dev->id.version = 0x0100;
0077
0078 rpcmouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
0079 rpcmouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
0080 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
0081 rpcmouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
0082
0083 rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX);
0084 rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY);
0085
0086 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) {
0087 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
0088 err = -EBUSY;
0089 goto err_free_dev;
0090 }
0091
0092 err = input_register_device(rpcmouse_dev);
0093 if (err)
0094 goto err_free_irq;
0095
0096 return 0;
0097
0098 err_free_irq:
0099 free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
0100 err_free_dev:
0101 input_free_device(rpcmouse_dev);
0102
0103 return err;
0104 }
0105
0106 static void __exit rpcmouse_exit(void)
0107 {
0108 free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
0109 input_unregister_device(rpcmouse_dev);
0110 }
0111
0112 module_init(rpcmouse_init);
0113 module_exit(rpcmouse_exit);