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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/ptrace.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/input.h> |
| 25 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/hardware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/irq.h> |
| 28 | #include <asm/io.h> |
| 29 | #include <asm/hardware/iomd.h> |
| 30 | |
| 31 | MODULE_AUTHOR("Vojtech Pavlik, Russell King"); |
| 32 | MODULE_DESCRIPTION("Acorn RiscPC mouse driver"); |
| 33 | MODULE_LICENSE("GPL"); |
| 34 | |
| 35 | static short rpcmouse_lastx, rpcmouse_lasty; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 36 | static struct input_dev *rpcmouse_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 38 | static irqreturn_t rpcmouse_irq(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
| 40 | struct input_dev *dev = dev_id; |
| 41 | short x, y, dx, dy, b; |
| 42 | |
| 43 | x = (short) iomd_readl(IOMD_MOUSEX); |
| 44 | y = (short) iomd_readl(IOMD_MOUSEY); |
| 45 | b = (short) (__raw_readl(0xe0310000) ^ 0x70); |
| 46 | |
| 47 | dx = x - rpcmouse_lastx; |
Dmitry Torokhov | 968ac84 | 2005-05-29 02:28:29 -0500 | [diff] [blame] | 48 | dy = y - rpcmouse_lasty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | rpcmouse_lastx = x; |
| 51 | rpcmouse_lasty = y; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | input_report_rel(dev, REL_X, dx); |
| 54 | input_report_rel(dev, REL_Y, -dy); |
| 55 | |
| 56 | input_report_key(dev, BTN_LEFT, b & 0x40); |
| 57 | input_report_key(dev, BTN_MIDDLE, b & 0x20); |
| 58 | input_report_key(dev, BTN_RIGHT, b & 0x10); |
| 59 | |
| 60 | input_sync(dev); |
| 61 | |
| 62 | return IRQ_HANDLED; |
| 63 | } |
| 64 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static int __init rpcmouse_init(void) |
| 67 | { |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 68 | int err; |
| 69 | |
| 70 | rpcmouse_dev = input_allocate_device(); |
| 71 | if (!rpcmouse_dev) |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 72 | return -ENOMEM; |
| 73 | |
| 74 | rpcmouse_dev->name = "Acorn RiscPC Mouse"; |
| 75 | rpcmouse_dev->phys = "rpcmouse/input0"; |
| 76 | rpcmouse_dev->id.bustype = BUS_HOST; |
| 77 | rpcmouse_dev->id.vendor = 0x0005; |
| 78 | rpcmouse_dev->id.product = 0x0001; |
| 79 | rpcmouse_dev->id.version = 0x0100; |
| 80 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 81 | rpcmouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 82 | rpcmouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | |
| 83 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
| 84 | rpcmouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX); |
| 87 | rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY); |
| 88 | |
Thomas Gleixner | dace145 | 2006-07-01 19:29:38 -0700 | [diff] [blame] | 89 | if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n"); |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 91 | err = -EBUSY; |
| 92 | goto err_free_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 95 | err = input_register_device(rpcmouse_dev); |
| 96 | if (err) |
| 97 | goto err_free_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | return 0; |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 100 | |
| 101 | err_free_irq: |
| 102 | free_irq(IRQ_VSYNCPULSE, rpcmouse_dev); |
| 103 | err_free_dev: |
| 104 | input_free_device(rpcmouse_dev); |
| 105 | |
| 106 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | static void __exit rpcmouse_exit(void) |
| 110 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 111 | free_irq(IRQ_VSYNCPULSE, rpcmouse_dev); |
| 112 | input_unregister_device(rpcmouse_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | module_init(rpcmouse_init); |
| 116 | module_exit(rpcmouse_exit); |