1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43#include <linux/module.h>
44#include <linux/init.h>
45#include <linux/input.h>
46#include <linux/interrupt.h>
47
48#include <asm/irq.h>
49#include <asm/setup.h>
50#include <linux/uaccess.h>
51#include <asm/atarihw.h>
52#include <asm/atarikb.h>
53#include <asm/atariints.h>
54
55MODULE_AUTHOR("Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>");
56MODULE_DESCRIPTION("Atari mouse driver");
57MODULE_LICENSE("GPL");
58
59static int mouse_threshold[2] = {2, 2};
60module_param_array(mouse_threshold, int, NULL, 0);
61
62#ifdef FIXED_ATARI_JOYSTICK
63extern int atari_mouse_buttons;
64#endif
65
66static struct input_dev *atamouse_dev;
67
68static void atamouse_interrupt(char *buf)
69{
70 int buttons, dx, dy;
71
72 buttons = (buf[0] & 1) | ((buf[0] & 2) << 1);
73#ifdef FIXED_ATARI_JOYSTICK
74 buttons |= atari_mouse_buttons & 2;
75 atari_mouse_buttons = buttons;
76#endif
77
78
79 dx = buf[1];
80 dy = buf[2];
81
82 input_report_rel(atamouse_dev, REL_X, dx);
83 input_report_rel(atamouse_dev, REL_Y, dy);
84
85 input_report_key(atamouse_dev, BTN_LEFT, buttons & 0x4);
86 input_report_key(atamouse_dev, BTN_MIDDLE, buttons & 0x2);
87 input_report_key(atamouse_dev, BTN_RIGHT, buttons & 0x1);
88
89 input_sync(atamouse_dev);
90
91 return;
92}
93
94static int atamouse_open(struct input_dev *dev)
95{
96#ifdef FIXED_ATARI_JOYSTICK
97 atari_mouse_buttons = 0;
98#endif
99 ikbd_mouse_y0_top();
100 ikbd_mouse_thresh(mouse_threshold[0], mouse_threshold[1]);
101 ikbd_mouse_rel_pos();
102 atari_input_mouse_interrupt_hook = atamouse_interrupt;
103
104 return 0;
105}
106
107static void atamouse_close(struct input_dev *dev)
108{
109 ikbd_mouse_disable();
110 atari_input_mouse_interrupt_hook = NULL;
111}
112
113static int __init atamouse_init(void)
114{
115 int error;
116
117 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP))
118 return -ENODEV;
119
120 error = atari_keyb_init();
121 if (error)
122 return error;
123
124 atamouse_dev = input_allocate_device();
125 if (!atamouse_dev)
126 return -ENOMEM;
127
128 atamouse_dev->name = "Atari mouse";
129 atamouse_dev->phys = "atamouse/input0";
130 atamouse_dev->id.bustype = BUS_HOST;
131 atamouse_dev->id.vendor = 0x0001;
132 atamouse_dev->id.product = 0x0002;
133 atamouse_dev->id.version = 0x0100;
134
135 atamouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
136 atamouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
137 atamouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
138 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
139
140 atamouse_dev->open = atamouse_open;
141 atamouse_dev->close = atamouse_close;
142
143 error = input_register_device(atamouse_dev);
144 if (error) {
145 input_free_device(atamouse_dev);
146 return error;
147 }
148
149 return 0;
150}
151
152static void __exit atamouse_exit(void)
153{
154 input_unregister_device(atamouse_dev);
155}
156
157module_init(atamouse_init);
158module_exit(atamouse_exit);
159