diff options
author | Stephen Evanchik <evanchsa@gmail.com> | 2005-08-08 02:26:18 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-08-08 02:26:18 -0400 |
commit | 541e316aed6f7d6efeb427a88645c2a8f61418d6 (patch) | |
tree | 2283bae66058470f24f47240e342a032d939ff89 /drivers/input/mouse/trackpoint.c | |
parent | 6fc32179de9e14c542e0b1760e412bc670611c53 (diff) |
Input: psmouse - add support for IBM TrackPoint devices.
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/mouse/trackpoint.c')
-rw-r--r-- | drivers/input/mouse/trackpoint.c | 297 |
1 files changed, 297 insertions, 0 deletions
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c new file mode 100644 index 000000000000..aee3b24a9102 --- /dev/null +++ b/drivers/input/mouse/trackpoint.c | |||
@@ -0,0 +1,297 @@ | |||
1 | /* | ||
2 | * Stephen Evanchik <evanchsa@gmail.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License version 2 as published by | ||
6 | * the Free Software Foundation. | ||
7 | * | ||
8 | * Trademarks are the property of their respective owners. | ||
9 | */ | ||
10 | |||
11 | #include <linux/delay.h> | ||
12 | #include <linux/serio.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/moduleparam.h> | ||
15 | #include <linux/input.h> | ||
16 | #include <linux/libps2.h> | ||
17 | #include <linux/proc_fs.h> | ||
18 | #include <asm/uaccess.h> | ||
19 | #include "psmouse.h" | ||
20 | #include "trackpoint.h" | ||
21 | |||
22 | PSMOUSE_DEFINE_ATTR(sensitivity); | ||
23 | PSMOUSE_DEFINE_ATTR(speed); | ||
24 | PSMOUSE_DEFINE_ATTR(inertia); | ||
25 | PSMOUSE_DEFINE_ATTR(reach); | ||
26 | PSMOUSE_DEFINE_ATTR(draghys); | ||
27 | PSMOUSE_DEFINE_ATTR(mindrag); | ||
28 | PSMOUSE_DEFINE_ATTR(thresh); | ||
29 | PSMOUSE_DEFINE_ATTR(upthresh); | ||
30 | PSMOUSE_DEFINE_ATTR(ztime); | ||
31 | PSMOUSE_DEFINE_ATTR(jenks); | ||
32 | PSMOUSE_DEFINE_ATTR(press_to_select); | ||
33 | PSMOUSE_DEFINE_ATTR(skipback); | ||
34 | PSMOUSE_DEFINE_ATTR(ext_dev); | ||
35 | |||
36 | #define MAKE_ATTR_READ(_item) \ | ||
37 | static ssize_t psmouse_attr_show_##_item(struct psmouse *psmouse, char *buf) \ | ||
38 | { \ | ||
39 | struct trackpoint_data *tp = psmouse->private; \ | ||
40 | return sprintf(buf, "%lu\n", (unsigned long)tp->_item); \ | ||
41 | } | ||
42 | |||
43 | #define MAKE_ATTR_WRITE(_item, command) \ | ||
44 | static ssize_t psmouse_attr_set_##_item(struct psmouse *psmouse, const char *buf, size_t count) \ | ||
45 | { \ | ||
46 | char *rest; \ | ||
47 | unsigned long value; \ | ||
48 | struct trackpoint_data *tp = psmouse->private; \ | ||
49 | value = simple_strtoul(buf, &rest, 10); \ | ||
50 | if (*rest) \ | ||
51 | return -EINVAL; \ | ||
52 | tp->_item = value; \ | ||
53 | trackpoint_write(&psmouse->ps2dev, command, tp->_item); \ | ||
54 | return count; \ | ||
55 | } | ||
56 | |||
57 | #define MAKE_ATTR_TOGGLE(_item, command, mask) \ | ||
58 | static ssize_t psmouse_attr_set_##_item(struct psmouse *psmouse, const char *buf, size_t count) \ | ||
59 | { \ | ||
60 | unsigned char toggle; \ | ||
61 | struct trackpoint_data *tp = psmouse->private; \ | ||
62 | toggle = (buf[0] == '1') ? 1 : 0; \ | ||
63 | if (toggle != tp->_item) { \ | ||
64 | tp->_item = toggle; \ | ||
65 | trackpoint_toggle_bit(&psmouse->ps2dev, command, mask); \ | ||
66 | } \ | ||
67 | return count; \ | ||
68 | } | ||
69 | |||
70 | /* | ||
71 | * Device IO: read, write and toggle bit | ||
72 | */ | ||
73 | static int trackpoint_read(struct ps2dev *ps2dev, unsigned char loc, unsigned char *results) | ||
74 | { | ||
75 | if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || | ||
76 | ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc))) { | ||
77 | return -1; | ||
78 | } | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | static int trackpoint_write(struct ps2dev *ps2dev, unsigned char loc, unsigned char val) | ||
84 | { | ||
85 | if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || | ||
86 | ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM)) || | ||
87 | ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) || | ||
88 | ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, val))) { | ||
89 | return -1; | ||
90 | } | ||
91 | |||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | static int trackpoint_toggle_bit(struct ps2dev *ps2dev, unsigned char loc, unsigned char mask) | ||
96 | { | ||
97 | /* Bad things will happen if the loc param isn't in this range */ | ||
98 | if (loc < 0x20 || loc >= 0x2F) | ||
99 | return -1; | ||
100 | |||
101 | if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || | ||
102 | ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_TOGGLE)) || | ||
103 | ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) || | ||
104 | ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, mask))) { | ||
105 | return -1; | ||
106 | } | ||
107 | |||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | MAKE_ATTR_WRITE(sensitivity, TP_SENS); | ||
112 | MAKE_ATTR_READ(sensitivity); | ||
113 | |||
114 | MAKE_ATTR_WRITE(speed, TP_SPEED); | ||
115 | MAKE_ATTR_READ(speed); | ||
116 | |||
117 | MAKE_ATTR_WRITE(inertia, TP_INERTIA); | ||
118 | MAKE_ATTR_READ(inertia); | ||
119 | |||
120 | MAKE_ATTR_WRITE(reach, TP_REACH); | ||
121 | MAKE_ATTR_READ(reach); | ||
122 | |||
123 | MAKE_ATTR_WRITE(draghys, TP_DRAGHYS); | ||
124 | MAKE_ATTR_READ(draghys); | ||
125 | |||
126 | MAKE_ATTR_WRITE(mindrag, TP_MINDRAG); | ||
127 | MAKE_ATTR_READ(mindrag); | ||
128 | |||
129 | MAKE_ATTR_WRITE(thresh, TP_THRESH); | ||
130 | MAKE_ATTR_READ(thresh); | ||
131 | |||
132 | MAKE_ATTR_WRITE(upthresh, TP_UP_THRESH); | ||
133 | MAKE_ATTR_READ(upthresh); | ||
134 | |||
135 | MAKE_ATTR_WRITE(ztime, TP_Z_TIME); | ||
136 | MAKE_ATTR_READ(ztime); | ||
137 | |||
138 | MAKE_ATTR_WRITE(jenks, TP_JENKS_CURV); | ||
139 | MAKE_ATTR_READ(jenks); | ||
140 | |||
141 | MAKE_ATTR_TOGGLE(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON); | ||
142 | MAKE_ATTR_READ(press_to_select); | ||
143 | |||
144 | MAKE_ATTR_TOGGLE(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK); | ||
145 | MAKE_ATTR_READ(skipback); | ||
146 | |||
147 | MAKE_ATTR_TOGGLE(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV); | ||
148 | MAKE_ATTR_READ(ext_dev); | ||
149 | |||
150 | static struct attribute *trackpoint_attrs[] = { | ||
151 | &psmouse_attr_sensitivity.attr, | ||
152 | &psmouse_attr_speed.attr, | ||
153 | &psmouse_attr_inertia.attr, | ||
154 | &psmouse_attr_reach.attr, | ||
155 | &psmouse_attr_draghys.attr, | ||
156 | &psmouse_attr_mindrag.attr, | ||
157 | &psmouse_attr_thresh.attr, | ||
158 | &psmouse_attr_upthresh.attr, | ||
159 | &psmouse_attr_ztime.attr, | ||
160 | &psmouse_attr_jenks.attr, | ||
161 | &psmouse_attr_press_to_select.attr, | ||
162 | &psmouse_attr_skipback.attr, | ||
163 | &psmouse_attr_ext_dev.attr, | ||
164 | NULL | ||
165 | }; | ||
166 | |||
167 | static struct attribute_group trackpoint_attr_group = { | ||
168 | .attrs = trackpoint_attrs, | ||
169 | }; | ||
170 | |||
171 | static void trackpoint_disconnect(struct psmouse *psmouse) | ||
172 | { | ||
173 | sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj, &trackpoint_attr_group); | ||
174 | |||
175 | kfree(psmouse->private); | ||
176 | psmouse->private = NULL; | ||
177 | } | ||
178 | |||
179 | static int trackpoint_sync(struct psmouse *psmouse) | ||
180 | { | ||
181 | unsigned char toggle; | ||
182 | struct trackpoint_data *tp = psmouse->private; | ||
183 | |||
184 | if (!tp) | ||
185 | return -1; | ||
186 | |||
187 | /* Disable features that may make device unusable with this driver */ | ||
188 | trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, &toggle); | ||
189 | if (toggle & TP_MASK_TWOHAND) | ||
190 | trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, TP_MASK_TWOHAND); | ||
191 | |||
192 | trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, &toggle); | ||
193 | if (toggle & TP_MASK_SOURCE_TAG) | ||
194 | trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, TP_MASK_SOURCE_TAG); | ||
195 | |||
196 | trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_MB, &toggle); | ||
197 | if (toggle & TP_MASK_MB) | ||
198 | trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_MB, TP_MASK_MB); | ||
199 | |||
200 | /* Push the config to the device */ | ||
201 | trackpoint_write(&psmouse->ps2dev, TP_SENS, tp->sensitivity); | ||
202 | trackpoint_write(&psmouse->ps2dev, TP_INERTIA, tp->inertia); | ||
203 | trackpoint_write(&psmouse->ps2dev, TP_SPEED, tp->speed); | ||
204 | |||
205 | trackpoint_write(&psmouse->ps2dev, TP_REACH, tp->reach); | ||
206 | trackpoint_write(&psmouse->ps2dev, TP_DRAGHYS, tp->draghys); | ||
207 | trackpoint_write(&psmouse->ps2dev, TP_MINDRAG, tp->mindrag); | ||
208 | |||
209 | trackpoint_write(&psmouse->ps2dev, TP_THRESH, tp->thresh); | ||
210 | trackpoint_write(&psmouse->ps2dev, TP_UP_THRESH, tp->upthresh); | ||
211 | |||
212 | trackpoint_write(&psmouse->ps2dev, TP_Z_TIME, tp->ztime); | ||
213 | trackpoint_write(&psmouse->ps2dev, TP_JENKS_CURV, tp->jenks); | ||
214 | |||
215 | trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_PTSON, &toggle); | ||
216 | if (((toggle & TP_MASK_PTSON) == TP_MASK_PTSON) != tp->press_to_select) | ||
217 | trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_PTSON, TP_MASK_PTSON); | ||
218 | |||
219 | trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, &toggle); | ||
220 | if (((toggle & TP_MASK_SKIPBACK) == TP_MASK_SKIPBACK) != tp->skipback) | ||
221 | trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK); | ||
222 | |||
223 | trackpoint_read(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, &toggle); | ||
224 | if (((toggle & TP_MASK_EXT_DEV) == TP_MASK_EXT_DEV) != tp->ext_dev) | ||
225 | trackpoint_toggle_bit(&psmouse->ps2dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV); | ||
226 | |||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | static void trackpoint_defaults(struct trackpoint_data *tp) | ||
231 | { | ||
232 | tp->press_to_select = TP_DEF_PTSON; | ||
233 | tp->sensitivity = TP_DEF_SENS; | ||
234 | tp->speed = TP_DEF_SPEED; | ||
235 | tp->reach = TP_DEF_REACH; | ||
236 | |||
237 | tp->draghys = TP_DEF_DRAGHYS; | ||
238 | tp->mindrag = TP_DEF_MINDRAG; | ||
239 | |||
240 | tp->thresh = TP_DEF_THRESH; | ||
241 | tp->upthresh = TP_DEF_UP_THRESH; | ||
242 | |||
243 | tp->ztime = TP_DEF_Z_TIME; | ||
244 | tp->jenks = TP_DEF_JENKS_CURV; | ||
245 | |||
246 | tp->inertia = TP_DEF_INERTIA; | ||
247 | tp->skipback = TP_DEF_SKIPBACK; | ||
248 | tp->ext_dev = TP_DEF_EXT_DEV; | ||
249 | } | ||
250 | |||
251 | int trackpoint_detect(struct psmouse *psmouse, int set_properties) | ||
252 | { | ||
253 | struct trackpoint_data *priv; | ||
254 | struct ps2dev *ps2dev = &psmouse->ps2dev; | ||
255 | unsigned char firmware_id; | ||
256 | unsigned char button_info; | ||
257 | unsigned char param[2]; | ||
258 | |||
259 | param[0] = param[1] = 0; | ||
260 | |||
261 | if (ps2_command(ps2dev, param, MAKE_PS2_CMD(0, 2, TP_READ_ID))) | ||
262 | return -1; | ||
263 | |||
264 | if (param[0] != TP_MAGIC_IDENT) | ||
265 | return -1; | ||
266 | |||
267 | if (!set_properties) | ||
268 | return 0; | ||
269 | |||
270 | firmware_id = param[1]; | ||
271 | |||
272 | if (trackpoint_read(&psmouse->ps2dev, TP_EXT_BTN, &button_info)) { | ||
273 | printk(KERN_WARNING "trackpoint.c: failed to get extended button data\n"); | ||
274 | button_info = 0; | ||
275 | } | ||
276 | |||
277 | psmouse->private = priv = kcalloc(1, sizeof(struct trackpoint_data), GFP_KERNEL); | ||
278 | if (!priv) | ||
279 | return -1; | ||
280 | |||
281 | psmouse->vendor = "IBM"; | ||
282 | psmouse->name = "TrackPoint"; | ||
283 | |||
284 | psmouse->reconnect = trackpoint_sync; | ||
285 | psmouse->disconnect = trackpoint_disconnect; | ||
286 | |||
287 | trackpoint_defaults(priv); | ||
288 | trackpoint_sync(psmouse); | ||
289 | |||
290 | sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group); | ||
291 | |||
292 | printk(KERN_INFO "IBM TrackPoint firmware: 0x%02x, buttons: %d/%d\n", | ||
293 | firmware_id, (button_info & 0xf0) >> 4, button_info & 0x0f); | ||
294 | |||
295 | return 0; | ||
296 | } | ||
297 | |||