2 * Stephen Evanchik <evanchsa@gmail.com>
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.
8 * Trademarks are the property of their respective owners.
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>
20 #include "trackpoint.h"
23 * Device IO: read, write and toggle bit
25 static int trackpoint_read(struct ps2dev
*ps2dev
, unsigned char loc
, unsigned char *results
)
27 if (ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, TP_COMMAND
)) ||
28 ps2_command(ps2dev
, results
, MAKE_PS2_CMD(0, 1, loc
))) {
35 static int trackpoint_write(struct ps2dev
*ps2dev
, unsigned char loc
, unsigned char val
)
37 if (ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, TP_COMMAND
)) ||
38 ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM
)) ||
39 ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, loc
)) ||
40 ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, val
))) {
47 static int trackpoint_toggle_bit(struct ps2dev
*ps2dev
, unsigned char loc
, unsigned char mask
)
49 /* Bad things will happen if the loc param isn't in this range */
50 if (loc
< 0x20 || loc
>= 0x2F)
53 if (ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, TP_COMMAND
)) ||
54 ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, TP_TOGGLE
)) ||
55 ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, loc
)) ||
56 ps2_command(ps2dev
, NULL
, MAKE_PS2_CMD(0, 0, mask
))) {
65 * Trackpoint-specific attributes
67 struct trackpoint_attr_data
{
69 unsigned char command
;
73 static ssize_t
trackpoint_show_int_attr(struct psmouse
*psmouse
, void *data
, char *buf
)
75 struct trackpoint_data
*tp
= psmouse
->private;
76 struct trackpoint_attr_data
*attr
= data
;
77 unsigned char *field
= (unsigned char *)((char *)tp
+ attr
->field_offset
);
79 return sprintf(buf
, "%u\n", *field
);
82 static ssize_t
trackpoint_set_int_attr(struct psmouse
*psmouse
, void *data
,
83 const char *buf
, size_t count
)
85 struct trackpoint_data
*tp
= psmouse
->private;
86 struct trackpoint_attr_data
*attr
= data
;
87 unsigned char *field
= (unsigned char *)((char *)tp
+ attr
->field_offset
);
91 value
= simple_strtoul(buf
, &rest
, 10);
92 if (*rest
|| value
> 255)
96 trackpoint_write(&psmouse
->ps2dev
, attr
->command
, value
);
101 #define TRACKPOINT_INT_ATTR(_name, _command) \
102 static struct trackpoint_attr_data trackpoint_attr_##_name = { \
103 .field_offset = offsetof(struct trackpoint_data, _name), \
104 .command = _command, \
106 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
107 &trackpoint_attr_##_name, \
108 trackpoint_show_int_attr, trackpoint_set_int_attr)
110 static ssize_t
trackpoint_set_bit_attr(struct psmouse
*psmouse
, void *data
,
111 const char *buf
, size_t count
)
113 struct trackpoint_data
*tp
= psmouse
->private;
114 struct trackpoint_attr_data
*attr
= data
;
115 unsigned char *field
= (unsigned char *)((char *)tp
+ attr
->field_offset
);
119 value
= simple_strtoul(buf
, &rest
, 10);
120 if (*rest
|| value
> 1)
123 if (*field
!= value
) {
125 trackpoint_toggle_bit(&psmouse
->ps2dev
, attr
->command
, attr
->mask
);
132 #define TRACKPOINT_BIT_ATTR(_name, _command, _mask) \
133 static struct trackpoint_attr_data trackpoint_attr_##_name = { \
134 .field_offset = offsetof(struct trackpoint_data, _name), \
135 .command = _command, \
138 PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \
139 &trackpoint_attr_##_name, \
140 trackpoint_show_int_attr, trackpoint_set_bit_attr)
142 TRACKPOINT_INT_ATTR(sensitivity
, TP_SENS
);
143 TRACKPOINT_INT_ATTR(speed
, TP_SPEED
);
144 TRACKPOINT_INT_ATTR(inertia
, TP_INERTIA
);
145 TRACKPOINT_INT_ATTR(reach
, TP_REACH
);
146 TRACKPOINT_INT_ATTR(draghys
, TP_DRAGHYS
);
147 TRACKPOINT_INT_ATTR(mindrag
, TP_MINDRAG
);
148 TRACKPOINT_INT_ATTR(thresh
, TP_THRESH
);
149 TRACKPOINT_INT_ATTR(upthresh
, TP_UP_THRESH
);
150 TRACKPOINT_INT_ATTR(ztime
, TP_Z_TIME
);
151 TRACKPOINT_INT_ATTR(jenks
, TP_JENKS_CURV
);
153 TRACKPOINT_BIT_ATTR(press_to_select
, TP_TOGGLE_PTSON
, TP_MASK_PTSON
);
154 TRACKPOINT_BIT_ATTR(skipback
, TP_TOGGLE_SKIPBACK
, TP_MASK_SKIPBACK
);
155 TRACKPOINT_BIT_ATTR(ext_dev
, TP_TOGGLE_EXT_DEV
, TP_MASK_EXT_DEV
);
157 static struct attribute
*trackpoint_attrs
[] = {
158 &psmouse_attr_sensitivity
.dattr
.attr
,
159 &psmouse_attr_speed
.dattr
.attr
,
160 &psmouse_attr_inertia
.dattr
.attr
,
161 &psmouse_attr_reach
.dattr
.attr
,
162 &psmouse_attr_draghys
.dattr
.attr
,
163 &psmouse_attr_mindrag
.dattr
.attr
,
164 &psmouse_attr_thresh
.dattr
.attr
,
165 &psmouse_attr_upthresh
.dattr
.attr
,
166 &psmouse_attr_ztime
.dattr
.attr
,
167 &psmouse_attr_jenks
.dattr
.attr
,
168 &psmouse_attr_press_to_select
.dattr
.attr
,
169 &psmouse_attr_skipback
.dattr
.attr
,
170 &psmouse_attr_ext_dev
.dattr
.attr
,
174 static struct attribute_group trackpoint_attr_group
= {
175 .attrs
= trackpoint_attrs
,
178 static void trackpoint_disconnect(struct psmouse
*psmouse
)
180 sysfs_remove_group(&psmouse
->ps2dev
.serio
->dev
.kobj
, &trackpoint_attr_group
);
182 kfree(psmouse
->private);
183 psmouse
->private = NULL
;
186 static int trackpoint_sync(struct psmouse
*psmouse
)
188 unsigned char toggle
;
189 struct trackpoint_data
*tp
= psmouse
->private;
194 /* Disable features that may make device unusable with this driver */
195 trackpoint_read(&psmouse
->ps2dev
, TP_TOGGLE_TWOHAND
, &toggle
);
196 if (toggle
& TP_MASK_TWOHAND
)
197 trackpoint_toggle_bit(&psmouse
->ps2dev
, TP_TOGGLE_TWOHAND
, TP_MASK_TWOHAND
);
199 trackpoint_read(&psmouse
->ps2dev
, TP_TOGGLE_SOURCE_TAG
, &toggle
);
200 if (toggle
& TP_MASK_SOURCE_TAG
)
201 trackpoint_toggle_bit(&psmouse
->ps2dev
, TP_TOGGLE_SOURCE_TAG
, TP_MASK_SOURCE_TAG
);
203 trackpoint_read(&psmouse
->ps2dev
, TP_TOGGLE_MB
, &toggle
);
204 if (toggle
& TP_MASK_MB
)
205 trackpoint_toggle_bit(&psmouse
->ps2dev
, TP_TOGGLE_MB
, TP_MASK_MB
);
207 /* Push the config to the device */
208 trackpoint_write(&psmouse
->ps2dev
, TP_SENS
, tp
->sensitivity
);
209 trackpoint_write(&psmouse
->ps2dev
, TP_INERTIA
, tp
->inertia
);
210 trackpoint_write(&psmouse
->ps2dev
, TP_SPEED
, tp
->speed
);
212 trackpoint_write(&psmouse
->ps2dev
, TP_REACH
, tp
->reach
);
213 trackpoint_write(&psmouse
->ps2dev
, TP_DRAGHYS
, tp
->draghys
);
214 trackpoint_write(&psmouse
->ps2dev
, TP_MINDRAG
, tp
->mindrag
);
216 trackpoint_write(&psmouse
->ps2dev
, TP_THRESH
, tp
->thresh
);
217 trackpoint_write(&psmouse
->ps2dev
, TP_UP_THRESH
, tp
->upthresh
);
219 trackpoint_write(&psmouse
->ps2dev
, TP_Z_TIME
, tp
->ztime
);
220 trackpoint_write(&psmouse
->ps2dev
, TP_JENKS_CURV
, tp
->jenks
);
222 trackpoint_read(&psmouse
->ps2dev
, TP_TOGGLE_PTSON
, &toggle
);
223 if (((toggle
& TP_MASK_PTSON
) == TP_MASK_PTSON
) != tp
->press_to_select
)
224 trackpoint_toggle_bit(&psmouse
->ps2dev
, TP_TOGGLE_PTSON
, TP_MASK_PTSON
);
226 trackpoint_read(&psmouse
->ps2dev
, TP_TOGGLE_SKIPBACK
, &toggle
);
227 if (((toggle
& TP_MASK_SKIPBACK
) == TP_MASK_SKIPBACK
) != tp
->skipback
)
228 trackpoint_toggle_bit(&psmouse
->ps2dev
, TP_TOGGLE_SKIPBACK
, TP_MASK_SKIPBACK
);
230 trackpoint_read(&psmouse
->ps2dev
, TP_TOGGLE_EXT_DEV
, &toggle
);
231 if (((toggle
& TP_MASK_EXT_DEV
) == TP_MASK_EXT_DEV
) != tp
->ext_dev
)
232 trackpoint_toggle_bit(&psmouse
->ps2dev
, TP_TOGGLE_EXT_DEV
, TP_MASK_EXT_DEV
);
237 static void trackpoint_defaults(struct trackpoint_data
*tp
)
239 tp
->press_to_select
= TP_DEF_PTSON
;
240 tp
->sensitivity
= TP_DEF_SENS
;
241 tp
->speed
= TP_DEF_SPEED
;
242 tp
->reach
= TP_DEF_REACH
;
244 tp
->draghys
= TP_DEF_DRAGHYS
;
245 tp
->mindrag
= TP_DEF_MINDRAG
;
247 tp
->thresh
= TP_DEF_THRESH
;
248 tp
->upthresh
= TP_DEF_UP_THRESH
;
250 tp
->ztime
= TP_DEF_Z_TIME
;
251 tp
->jenks
= TP_DEF_JENKS_CURV
;
253 tp
->inertia
= TP_DEF_INERTIA
;
254 tp
->skipback
= TP_DEF_SKIPBACK
;
255 tp
->ext_dev
= TP_DEF_EXT_DEV
;
258 int trackpoint_detect(struct psmouse
*psmouse
, int set_properties
)
260 struct trackpoint_data
*priv
;
261 struct ps2dev
*ps2dev
= &psmouse
->ps2dev
;
262 unsigned char firmware_id
;
263 unsigned char button_info
;
264 unsigned char param
[2];
266 param
[0] = param
[1] = 0;
268 if (ps2_command(ps2dev
, param
, MAKE_PS2_CMD(0, 2, TP_READ_ID
)))
271 if (param
[0] != TP_MAGIC_IDENT
)
277 firmware_id
= param
[1];
279 if (trackpoint_read(&psmouse
->ps2dev
, TP_EXT_BTN
, &button_info
)) {
280 printk(KERN_WARNING
"trackpoint.c: failed to get extended button data\n");
284 psmouse
->private = priv
= kcalloc(1, sizeof(struct trackpoint_data
), GFP_KERNEL
);
288 psmouse
->vendor
= "IBM";
289 psmouse
->name
= "TrackPoint";
291 psmouse
->reconnect
= trackpoint_sync
;
292 psmouse
->disconnect
= trackpoint_disconnect
;
294 trackpoint_defaults(priv
);
295 trackpoint_sync(psmouse
);
297 sysfs_create_group(&ps2dev
->serio
->dev
.kobj
, &trackpoint_attr_group
);
299 printk(KERN_INFO
"IBM TrackPoint firmware: 0x%02x, buttons: %d/%d\n",
300 firmware_id
, (button_info
& 0xf0) >> 4, button_info
& 0x0f);