]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/input/mouse/rpcmouse.c
define first set of BIT* macros
[mirror_ubuntu-artful-kernel.git] / drivers / input / mouse / rpcmouse.c
CommitLineData
1da177e4
LT
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>
1da177e4
LT
21#include <linux/ptrace.h>
22#include <linux/interrupt.h>
23#include <linux/init.h>
24#include <linux/input.h>
25
26#include <asm/hardware.h>
27#include <asm/irq.h>
28#include <asm/io.h>
29#include <asm/hardware/iomd.h>
30
31MODULE_AUTHOR("Vojtech Pavlik, Russell King");
32MODULE_DESCRIPTION("Acorn RiscPC mouse driver");
33MODULE_LICENSE("GPL");
34
35static short rpcmouse_lastx, rpcmouse_lasty;
2e5b636b 36static struct input_dev *rpcmouse_dev;
1da177e4 37
7d12e780 38static irqreturn_t rpcmouse_irq(int irq, void *dev_id)
1da177e4
LT
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;
968ac842 48 dy = y - rpcmouse_lasty;
1da177e4
LT
49
50 rpcmouse_lastx = x;
51 rpcmouse_lasty = y;
52
1da177e4
LT
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
2e5b636b 65
1da177e4
LT
66static int __init rpcmouse_init(void)
67{
72155615
DT
68 int err;
69
70 rpcmouse_dev = input_allocate_device();
71 if (!rpcmouse_dev)
2e5b636b
DT
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
81 rpcmouse_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
82 rpcmouse_dev->keybit[LONG(BTN_LEFT)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
83 rpcmouse_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y);
1da177e4
LT
84
85 rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX);
86 rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY);
87
dace1453 88 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) {
1da177e4 89 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
72155615
DT
90 err = -EBUSY;
91 goto err_free_dev;
1da177e4
LT
92 }
93
72155615
DT
94 err = input_register_device(rpcmouse_dev);
95 if (err)
96 goto err_free_irq;
1da177e4
LT
97
98 return 0;
72155615
DT
99
100 err_free_irq:
101 free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
102 err_free_dev:
103 input_free_device(rpcmouse_dev);
104
105 return err;
1da177e4
LT
106}
107
108static void __exit rpcmouse_exit(void)
109{
2e5b636b
DT
110 free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
111 input_unregister_device(rpcmouse_dev);
1da177e4
LT
112}
113
114module_init(rpcmouse_init);
115module_exit(rpcmouse_exit);