]>
Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 LT |
2 | /* |
3 | * Acorn RiscPC mouse driver for Linux/ARM | |
4 | * | |
5 | * Copyright (c) 2000-2002 Vojtech Pavlik | |
6 | * Copyright (C) 1996-2002 Russell King | |
1da177e4 LT |
7 | */ |
8 | ||
9 | /* | |
1da177e4 LT |
10 | * |
11 | * This handles the Acorn RiscPCs mouse. We basically have a couple of | |
12 | * hardware registers that track the sensor count for the X-Y movement and | |
13 | * another register holding the button state. On every VSYNC interrupt we read | |
14 | * the complete state and then work out if something has changed. | |
15 | */ | |
16 | ||
17 | #include <linux/module.h> | |
1da177e4 LT |
18 | #include <linux/ptrace.h> |
19 | #include <linux/interrupt.h> | |
20 | #include <linux/init.h> | |
21 | #include <linux/input.h> | |
99730225 | 22 | #include <linux/io.h> |
1da177e4 | 23 | |
a09e64fb | 24 | #include <mach/hardware.h> |
1da177e4 | 25 | #include <asm/irq.h> |
1da177e4 LT |
26 | #include <asm/hardware/iomd.h> |
27 | ||
28 | MODULE_AUTHOR("Vojtech Pavlik, Russell King"); | |
29 | MODULE_DESCRIPTION("Acorn RiscPC mouse driver"); | |
30 | MODULE_LICENSE("GPL"); | |
31 | ||
32 | static short rpcmouse_lastx, rpcmouse_lasty; | |
2e5b636b | 33 | static struct input_dev *rpcmouse_dev; |
1da177e4 | 34 | |
7d12e780 | 35 | static irqreturn_t rpcmouse_irq(int irq, void *dev_id) |
1da177e4 LT |
36 | { |
37 | struct input_dev *dev = dev_id; | |
38 | short x, y, dx, dy, b; | |
39 | ||
40 | x = (short) iomd_readl(IOMD_MOUSEX); | |
41 | y = (short) iomd_readl(IOMD_MOUSEY); | |
fe73f035 | 42 | b = (short) (__raw_readl(IOMEM(0xe0310000)) ^ 0x70); |
1da177e4 LT |
43 | |
44 | dx = x - rpcmouse_lastx; | |
968ac842 | 45 | dy = y - rpcmouse_lasty; |
1da177e4 LT |
46 | |
47 | rpcmouse_lastx = x; | |
48 | rpcmouse_lasty = y; | |
49 | ||
1da177e4 LT |
50 | input_report_rel(dev, REL_X, dx); |
51 | input_report_rel(dev, REL_Y, -dy); | |
52 | ||
53 | input_report_key(dev, BTN_LEFT, b & 0x40); | |
54 | input_report_key(dev, BTN_MIDDLE, b & 0x20); | |
55 | input_report_key(dev, BTN_RIGHT, b & 0x10); | |
56 | ||
57 | input_sync(dev); | |
58 | ||
59 | return IRQ_HANDLED; | |
60 | } | |
61 | ||
2e5b636b | 62 | |
1da177e4 LT |
63 | static int __init rpcmouse_init(void) |
64 | { | |
72155615 DT |
65 | int err; |
66 | ||
67 | rpcmouse_dev = input_allocate_device(); | |
68 | if (!rpcmouse_dev) | |
2e5b636b DT |
69 | return -ENOMEM; |
70 | ||
71 | rpcmouse_dev->name = "Acorn RiscPC Mouse"; | |
72 | rpcmouse_dev->phys = "rpcmouse/input0"; | |
73 | rpcmouse_dev->id.bustype = BUS_HOST; | |
74 | rpcmouse_dev->id.vendor = 0x0005; | |
75 | rpcmouse_dev->id.product = 0x0001; | |
76 | rpcmouse_dev->id.version = 0x0100; | |
77 | ||
7b19ada2 JS |
78 | rpcmouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
79 | rpcmouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | | |
80 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); | |
81 | rpcmouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); | |
1da177e4 LT |
82 | |
83 | rpcmouse_lastx = (short) iomd_readl(IOMD_MOUSEX); | |
84 | rpcmouse_lasty = (short) iomd_readl(IOMD_MOUSEY); | |
85 | ||
dace1453 | 86 | if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) { |
1da177e4 | 87 | printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n"); |
72155615 DT |
88 | err = -EBUSY; |
89 | goto err_free_dev; | |
1da177e4 LT |
90 | } |
91 | ||
72155615 DT |
92 | err = input_register_device(rpcmouse_dev); |
93 | if (err) | |
94 | goto err_free_irq; | |
1da177e4 LT |
95 | |
96 | return 0; | |
72155615 DT |
97 | |
98 | err_free_irq: | |
99 | free_irq(IRQ_VSYNCPULSE, rpcmouse_dev); | |
100 | err_free_dev: | |
101 | input_free_device(rpcmouse_dev); | |
102 | ||
103 | return err; | |
1da177e4 LT |
104 | } |
105 | ||
106 | static void __exit rpcmouse_exit(void) | |
107 | { | |
2e5b636b DT |
108 | free_irq(IRQ_VSYNCPULSE, rpcmouse_dev); |
109 | input_unregister_device(rpcmouse_dev); | |
1da177e4 LT |
110 | } |
111 | ||
112 | module_init(rpcmouse_init); | |
113 | module_exit(rpcmouse_exit); |