trackpoint.c (f5d07b9e98022d50720e38aa936fc11c67868ece) | trackpoint.c (2a924d71794c530e55e73d0ce2cc77233307eaa9) |
---|---|
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. --- 5 unchanged lines hidden (view full) --- 14#include <linux/module.h> 15#include <linux/input.h> 16#include <linux/libps2.h> 17#include <linux/proc_fs.h> 18#include <linux/uaccess.h> 19#include "psmouse.h" 20#include "trackpoint.h" 21 | 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. --- 5 unchanged lines hidden (view full) --- 14#include <linux/module.h> 15#include <linux/input.h> 16#include <linux/libps2.h> 17#include <linux/proc_fs.h> 18#include <linux/uaccess.h> 19#include "psmouse.h" 20#include "trackpoint.h" 21 |
22static const char * const trackpoint_variants[] = { 23 [TP_VARIANT_IBM] = "IBM", 24 [TP_VARIANT_ALPS] = "ALPS", 25 [TP_VARIANT_ELAN] = "Elan", 26 [TP_VARIANT_NXP] = "NXP", 27}; 28 |
|
22/* 23 * Power-on Reset: Resets all trackpoint parameters, including RAM values, 24 * to defaults. 25 * Returns zero on success, non-zero on failure. 26 */ 27static int trackpoint_power_on_reset(struct ps2dev *ps2dev) 28{ | 29/* 30 * Power-on Reset: Resets all trackpoint parameters, including RAM values, 31 * to defaults. 32 * Returns zero on success, non-zero on failure. 33 */ 34static int trackpoint_power_on_reset(struct ps2dev *ps2dev) 35{ |
29 unsigned char results[2]; | 36 u8 results[2]; |
30 int tries = 0; 31 32 /* Issue POR command, and repeat up to once if 0xFC00 received */ 33 do { 34 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 35 ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 2, TP_POR))) 36 return -1; 37 } while (results[0] == 0xFC && results[1] == 0x00 && ++tries < 2); 38 39 /* Check for success response -- 0xAA00 */ 40 if (results[0] != 0xAA || results[1] != 0x00) | 37 int tries = 0; 38 39 /* Issue POR command, and repeat up to once if 0xFC00 received */ 40 do { 41 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 42 ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 2, TP_POR))) 43 return -1; 44 } while (results[0] == 0xFC && results[1] == 0x00 && ++tries < 2); 45 46 /* Check for success response -- 0xAA00 */ 47 if (results[0] != 0xAA || results[1] != 0x00) |
41 return -1; | 48 return -ENODEV; |
42 43 return 0; 44} 45 46/* 47 * Device IO: read, write and toggle bit 48 */ | 49 50 return 0; 51} 52 53/* 54 * Device IO: read, write and toggle bit 55 */ |
49static int trackpoint_read(struct ps2dev *ps2dev, 50 unsigned char loc, unsigned char *results) | 56static int trackpoint_read(struct ps2dev *ps2dev, u8 loc, u8 *results) |
51{ 52 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 53 ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc))) { 54 return -1; 55 } 56 57 return 0; 58} 59 | 57{ 58 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 59 ps2_command(ps2dev, results, MAKE_PS2_CMD(0, 1, loc))) { 60 return -1; 61 } 62 63 return 0; 64} 65 |
60static int trackpoint_write(struct ps2dev *ps2dev, 61 unsigned char loc, unsigned char val) | 66static int trackpoint_write(struct ps2dev *ps2dev, u8 loc, u8 val) |
62{ 63 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 64 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM)) || 65 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) || 66 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, val))) { 67 return -1; 68 } 69 70 return 0; 71} 72 | 67{ 68 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 69 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_WRITE_MEM)) || 70 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) || 71 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, val))) { 72 return -1; 73 } 74 75 return 0; 76} 77 |
73static int trackpoint_toggle_bit(struct ps2dev *ps2dev, 74 unsigned char loc, unsigned char mask) | 78static int trackpoint_toggle_bit(struct ps2dev *ps2dev, u8 loc, u8 mask) |
75{ 76 /* Bad things will happen if the loc param isn't in this range */ 77 if (loc < 0x20 || loc >= 0x2F) 78 return -1; 79 80 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 81 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_TOGGLE)) || 82 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) || 83 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, mask))) { 84 return -1; 85 } 86 87 return 0; 88} 89 | 79{ 80 /* Bad things will happen if the loc param isn't in this range */ 81 if (loc < 0x20 || loc >= 0x2F) 82 return -1; 83 84 if (ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_COMMAND)) || 85 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, TP_TOGGLE)) || 86 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, loc)) || 87 ps2_command(ps2dev, NULL, MAKE_PS2_CMD(0, 0, mask))) { 88 return -1; 89 } 90 91 return 0; 92} 93 |
90static int trackpoint_update_bit(struct ps2dev *ps2dev, unsigned char loc, 91 unsigned char mask, unsigned char value) | 94static int trackpoint_update_bit(struct ps2dev *ps2dev, 95 u8 loc, u8 mask, u8 value) |
92{ 93 int retval = 0; | 96{ 97 int retval = 0; |
94 unsigned char data; | 98 u8 data; |
95 96 trackpoint_read(ps2dev, loc, &data); 97 if (((data & mask) == mask) != !!value) 98 retval = trackpoint_toggle_bit(ps2dev, loc, mask); 99 100 return retval; 101} 102 103/* 104 * Trackpoint-specific attributes 105 */ 106struct trackpoint_attr_data { 107 size_t field_offset; | 99 100 trackpoint_read(ps2dev, loc, &data); 101 if (((data & mask) == mask) != !!value) 102 retval = trackpoint_toggle_bit(ps2dev, loc, mask); 103 104 return retval; 105} 106 107/* 108 * Trackpoint-specific attributes 109 */ 110struct trackpoint_attr_data { 111 size_t field_offset; |
108 unsigned char command; 109 unsigned char mask; 110 unsigned char inverted; 111 unsigned char power_on_default; | 112 u8 command; 113 u8 mask; 114 bool inverted; 115 u8 power_on_default; |
112}; 113 | 116}; 117 |
114static ssize_t trackpoint_show_int_attr(struct psmouse *psmouse, void *data, char *buf) | 118static ssize_t trackpoint_show_int_attr(struct psmouse *psmouse, 119 void *data, char *buf) |
115{ 116 struct trackpoint_data *tp = psmouse->private; 117 struct trackpoint_attr_data *attr = data; | 120{ 121 struct trackpoint_data *tp = psmouse->private; 122 struct trackpoint_attr_data *attr = data; |
118 unsigned char value = *(unsigned char *)((char *)tp + attr->field_offset); | 123 u8 value = *(u8 *)((void *)tp + attr->field_offset); |
119 120 if (attr->inverted) 121 value = !value; 122 123 return sprintf(buf, "%u\n", value); 124} 125 126static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data, 127 const char *buf, size_t count) 128{ 129 struct trackpoint_data *tp = psmouse->private; 130 struct trackpoint_attr_data *attr = data; | 124 125 if (attr->inverted) 126 value = !value; 127 128 return sprintf(buf, "%u\n", value); 129} 130 131static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data, 132 const char *buf, size_t count) 133{ 134 struct trackpoint_data *tp = psmouse->private; 135 struct trackpoint_attr_data *attr = data; |
131 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset); 132 unsigned char value; | 136 u8 *field = (void *)tp + attr->field_offset; 137 u8 value; |
133 int err; 134 135 err = kstrtou8(buf, 10, &value); 136 if (err) 137 return err; 138 139 *field = value; 140 trackpoint_write(&psmouse->ps2dev, attr->command, value); --- 11 unchanged lines hidden (view full) --- 152 &trackpoint_attr_##_name, \ 153 trackpoint_show_int_attr, trackpoint_set_int_attr) 154 155static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data, 156 const char *buf, size_t count) 157{ 158 struct trackpoint_data *tp = psmouse->private; 159 struct trackpoint_attr_data *attr = data; | 138 int err; 139 140 err = kstrtou8(buf, 10, &value); 141 if (err) 142 return err; 143 144 *field = value; 145 trackpoint_write(&psmouse->ps2dev, attr->command, value); --- 11 unchanged lines hidden (view full) --- 157 &trackpoint_attr_##_name, \ 158 trackpoint_show_int_attr, trackpoint_set_int_attr) 159 160static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data, 161 const char *buf, size_t count) 162{ 163 struct trackpoint_data *tp = psmouse->private; 164 struct trackpoint_attr_data *attr = data; |
160 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset); 161 unsigned int value; | 165 bool *field = (void *)tp + attr->field_offset; 166 bool value; |
162 int err; 163 | 167 int err; 168 |
164 err = kstrtouint(buf, 10, &value); | 169 err = kstrtobool(buf, &value); |
165 if (err) 166 return err; 167 | 170 if (err) 171 return err; 172 |
168 if (value > 1) 169 return -EINVAL; 170 | |
171 if (attr->inverted) 172 value = !value; 173 174 if (*field != value) { 175 *field = value; 176 trackpoint_toggle_bit(&psmouse->ps2dev, attr->command, attr->mask); 177 } 178 --- 9 unchanged lines hidden (view full) --- 188 .mask = _mask, \ 189 .inverted = _inv, \ 190 .power_on_default = _default, \ 191 }; \ 192PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \ 193 &trackpoint_attr_##_name, \ 194 trackpoint_show_int_attr, trackpoint_set_bit_attr) 195 | 173 if (attr->inverted) 174 value = !value; 175 176 if (*field != value) { 177 *field = value; 178 trackpoint_toggle_bit(&psmouse->ps2dev, attr->command, attr->mask); 179 } 180 --- 9 unchanged lines hidden (view full) --- 190 .mask = _mask, \ 191 .inverted = _inv, \ 192 .power_on_default = _default, \ 193 }; \ 194PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO, \ 195 &trackpoint_attr_##_name, \ 196 trackpoint_show_int_attr, trackpoint_set_bit_attr) 197 |
196#define TRACKPOINT_UPDATE_BIT(_psmouse, _tp, _name) \ 197do { \ 198 struct trackpoint_attr_data *_attr = &trackpoint_attr_##_name; \ 199 \ 200 trackpoint_update_bit(&_psmouse->ps2dev, \ 201 _attr->command, _attr->mask, _tp->_name); \ 202} while (0) 203 204#define TRACKPOINT_UPDATE(_power_on, _psmouse, _tp, _name) \ 205do { \ 206 if (!_power_on || \ 207 _tp->_name != trackpoint_attr_##_name.power_on_default) { \ 208 if (!trackpoint_attr_##_name.mask) \ 209 trackpoint_write(&_psmouse->ps2dev, \ 210 trackpoint_attr_##_name.command, \ 211 _tp->_name); \ 212 else \ 213 TRACKPOINT_UPDATE_BIT(_psmouse, _tp, _name); \ 214 } \ 215} while (0) 216 217#define TRACKPOINT_SET_POWER_ON_DEFAULT(_tp, _name) \ 218 (_tp->_name = trackpoint_attr_##_name.power_on_default) 219 | |
220TRACKPOINT_INT_ATTR(sensitivity, TP_SENS, TP_DEF_SENS); 221TRACKPOINT_INT_ATTR(speed, TP_SPEED, TP_DEF_SPEED); 222TRACKPOINT_INT_ATTR(inertia, TP_INERTIA, TP_DEF_INERTIA); 223TRACKPOINT_INT_ATTR(reach, TP_REACH, TP_DEF_REACH); 224TRACKPOINT_INT_ATTR(draghys, TP_DRAGHYS, TP_DEF_DRAGHYS); 225TRACKPOINT_INT_ATTR(mindrag, TP_MINDRAG, TP_DEF_MINDRAG); 226TRACKPOINT_INT_ATTR(thresh, TP_THRESH, TP_DEF_THRESH); 227TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRESH, TP_DEF_UP_THRESH); 228TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME, TP_DEF_Z_TIME); 229TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV, TP_DEF_JENKS_CURV); 230TRACKPOINT_INT_ATTR(drift_time, TP_DRIFT_TIME, TP_DEF_DRIFT_TIME); 231 | 198TRACKPOINT_INT_ATTR(sensitivity, TP_SENS, TP_DEF_SENS); 199TRACKPOINT_INT_ATTR(speed, TP_SPEED, TP_DEF_SPEED); 200TRACKPOINT_INT_ATTR(inertia, TP_INERTIA, TP_DEF_INERTIA); 201TRACKPOINT_INT_ATTR(reach, TP_REACH, TP_DEF_REACH); 202TRACKPOINT_INT_ATTR(draghys, TP_DRAGHYS, TP_DEF_DRAGHYS); 203TRACKPOINT_INT_ATTR(mindrag, TP_MINDRAG, TP_DEF_MINDRAG); 204TRACKPOINT_INT_ATTR(thresh, TP_THRESH, TP_DEF_THRESH); 205TRACKPOINT_INT_ATTR(upthresh, TP_UP_THRESH, TP_DEF_UP_THRESH); 206TRACKPOINT_INT_ATTR(ztime, TP_Z_TIME, TP_DEF_Z_TIME); 207TRACKPOINT_INT_ATTR(jenks, TP_JENKS_CURV, TP_DEF_JENKS_CURV); 208TRACKPOINT_INT_ATTR(drift_time, TP_DRIFT_TIME, TP_DEF_DRIFT_TIME); 209 |
232TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON, 0, | 210TRACKPOINT_BIT_ATTR(press_to_select, TP_TOGGLE_PTSON, TP_MASK_PTSON, false, |
233 TP_DEF_PTSON); | 211 TP_DEF_PTSON); |
234TRACKPOINT_BIT_ATTR(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK, 0, | 212TRACKPOINT_BIT_ATTR(skipback, TP_TOGGLE_SKIPBACK, TP_MASK_SKIPBACK, false, |
235 TP_DEF_SKIPBACK); | 213 TP_DEF_SKIPBACK); |
236TRACKPOINT_BIT_ATTR(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV, 1, | 214TRACKPOINT_BIT_ATTR(ext_dev, TP_TOGGLE_EXT_DEV, TP_MASK_EXT_DEV, true, |
237 TP_DEF_EXT_DEV); 238 | 215 TP_DEF_EXT_DEV); 216 |
217static bool trackpoint_is_attr_available(struct psmouse *psmouse, 218 struct attribute *attr) 219{ 220 struct trackpoint_data *tp = psmouse->private; 221 222 return tp->variant_id == TP_VARIANT_IBM || 223 attr == &psmouse_attr_sensitivity.dattr.attr || 224 attr == &psmouse_attr_press_to_select.dattr.attr; 225} 226 227static umode_t trackpoint_is_attr_visible(struct kobject *kobj, 228 struct attribute *attr, int n) 229{ 230 struct device *dev = container_of(kobj, struct device, kobj); 231 struct serio *serio = to_serio_port(dev); 232 struct psmouse *psmouse = serio_get_drvdata(serio); 233 234 return trackpoint_is_attr_available(psmouse, attr) ? attr->mode : 0; 235} 236 |
|
239static struct attribute *trackpoint_attrs[] = { 240 &psmouse_attr_sensitivity.dattr.attr, 241 &psmouse_attr_speed.dattr.attr, 242 &psmouse_attr_inertia.dattr.attr, 243 &psmouse_attr_reach.dattr.attr, 244 &psmouse_attr_draghys.dattr.attr, 245 &psmouse_attr_mindrag.dattr.attr, 246 &psmouse_attr_thresh.dattr.attr, 247 &psmouse_attr_upthresh.dattr.attr, 248 &psmouse_attr_ztime.dattr.attr, 249 &psmouse_attr_jenks.dattr.attr, 250 &psmouse_attr_drift_time.dattr.attr, 251 &psmouse_attr_press_to_select.dattr.attr, 252 &psmouse_attr_skipback.dattr.attr, 253 &psmouse_attr_ext_dev.dattr.attr, 254 NULL 255}; 256 257static struct attribute_group trackpoint_attr_group = { | 237static struct attribute *trackpoint_attrs[] = { 238 &psmouse_attr_sensitivity.dattr.attr, 239 &psmouse_attr_speed.dattr.attr, 240 &psmouse_attr_inertia.dattr.attr, 241 &psmouse_attr_reach.dattr.attr, 242 &psmouse_attr_draghys.dattr.attr, 243 &psmouse_attr_mindrag.dattr.attr, 244 &psmouse_attr_thresh.dattr.attr, 245 &psmouse_attr_upthresh.dattr.attr, 246 &psmouse_attr_ztime.dattr.attr, 247 &psmouse_attr_jenks.dattr.attr, 248 &psmouse_attr_drift_time.dattr.attr, 249 &psmouse_attr_press_to_select.dattr.attr, 250 &psmouse_attr_skipback.dattr.attr, 251 &psmouse_attr_ext_dev.dattr.attr, 252 NULL 253}; 254 255static struct attribute_group trackpoint_attr_group = { |
258 .attrs = trackpoint_attrs, | 256 .is_visible = trackpoint_is_attr_visible, 257 .attrs = trackpoint_attrs, |
259}; 260 | 258}; 259 |
261static int trackpoint_start_protocol(struct psmouse *psmouse, unsigned char *firmware_id) 262{ 263 unsigned char param[2] = { 0 }; | 260#define TRACKPOINT_UPDATE(_power_on, _psmouse, _tp, _name) \ 261do { \ 262 struct trackpoint_attr_data *_attr = &trackpoint_attr_##_name; \ 263 \ 264 if ((!_power_on || _tp->_name != _attr->power_on_default) && \ 265 trackpoint_is_attr_available(_psmouse, \ 266 &psmouse_attr_##_name.dattr.attr)) { \ 267 if (!_attr->mask) \ 268 trackpoint_write(&_psmouse->ps2dev, \ 269 _attr->command, _tp->_name); \ 270 else \ 271 trackpoint_update_bit(&_psmouse->ps2dev, \ 272 _attr->command, _attr->mask, \ 273 _tp->_name); \ 274 } \ 275} while (0) |
264 | 276 |
265 if (ps2_command(&psmouse->ps2dev, param, MAKE_PS2_CMD(0, 2, TP_READ_ID))) 266 return -1; | 277#define TRACKPOINT_SET_POWER_ON_DEFAULT(_tp, _name) \ 278do { \ 279 _tp->_name = trackpoint_attr_##_name.power_on_default; \ 280} while (0) |
267 | 281 |
268 /* add new TP ID. */ 269 if (!(param[0] & TP_MAGIC_IDENT)) 270 return -1; | 282static int trackpoint_start_protocol(struct psmouse *psmouse, 283 u8 *variant_id, u8 *firmware_id) 284{ 285 u8 param[2] = { 0 }; 286 int error; |
271 | 287 |
272 if (firmware_id) 273 *firmware_id = param[1]; | 288 error = ps2_command(&psmouse->ps2dev, 289 param, MAKE_PS2_CMD(0, 2, TP_READ_ID)); 290 if (error) 291 return error; |
274 | 292 |
275 return 0; | 293 switch (param[0]) { 294 case TP_VARIANT_IBM: 295 case TP_VARIANT_ALPS: 296 case TP_VARIANT_ELAN: 297 case TP_VARIANT_NXP: 298 if (variant_id) 299 *variant_id = param[0]; 300 if (firmware_id) 301 *firmware_id = param[1]; 302 return 0; 303 } 304 305 return -ENODEV; |
276} 277 278/* 279 * Write parameters to trackpad. 280 * in_power_on_state: Set to true if TP is in default / power-on state (ex. if 281 * power-on reset was run). If so, values will only be 282 * written to TP if they differ from power-on default. 283 */ 284static int trackpoint_sync(struct psmouse *psmouse, bool in_power_on_state) 285{ 286 struct trackpoint_data *tp = psmouse->private; 287 | 306} 307 308/* 309 * Write parameters to trackpad. 310 * in_power_on_state: Set to true if TP is in default / power-on state (ex. if 311 * power-on reset was run). If so, values will only be 312 * written to TP if they differ from power-on default. 313 */ 314static int trackpoint_sync(struct psmouse *psmouse, bool in_power_on_state) 315{ 316 struct trackpoint_data *tp = psmouse->private; 317 |
288 if (!in_power_on_state) { | 318 if (!in_power_on_state && tp->variant_id == TP_VARIANT_IBM) { |
289 /* 290 * Disable features that may make device unusable 291 * with this driver. 292 */ 293 trackpoint_update_bit(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, 294 TP_MASK_TWOHAND, TP_DEF_TWOHAND); 295 296 trackpoint_update_bit(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, --- 45 unchanged lines hidden (view full) --- 342 /* toggles */ 343 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, press_to_select); 344 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, skipback); 345 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, ext_dev); 346} 347 348static void trackpoint_disconnect(struct psmouse *psmouse) 349{ | 319 /* 320 * Disable features that may make device unusable 321 * with this driver. 322 */ 323 trackpoint_update_bit(&psmouse->ps2dev, TP_TOGGLE_TWOHAND, 324 TP_MASK_TWOHAND, TP_DEF_TWOHAND); 325 326 trackpoint_update_bit(&psmouse->ps2dev, TP_TOGGLE_SOURCE_TAG, --- 45 unchanged lines hidden (view full) --- 372 /* toggles */ 373 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, press_to_select); 374 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, skipback); 375 TRACKPOINT_SET_POWER_ON_DEFAULT(tp, ext_dev); 376} 377 378static void trackpoint_disconnect(struct psmouse *psmouse) 379{ |
350 sysfs_remove_group(&psmouse->ps2dev.serio->dev.kobj, &trackpoint_attr_group); | 380 device_remove_group(&psmouse->ps2dev.serio->dev, 381 &trackpoint_attr_group); |
351 352 kfree(psmouse->private); 353 psmouse->private = NULL; 354} 355 356static int trackpoint_reconnect(struct psmouse *psmouse) 357{ | 382 383 kfree(psmouse->private); 384 psmouse->private = NULL; 385} 386 387static int trackpoint_reconnect(struct psmouse *psmouse) 388{ |
358 int reset_fail; | 389 struct trackpoint_data *tp = psmouse->private; 390 int error; 391 bool was_reset; |
359 | 392 |
360 if (trackpoint_start_protocol(psmouse, NULL)) 361 return -1; | 393 error = trackpoint_start_protocol(psmouse, NULL, NULL); 394 if (error) 395 return error; |
362 | 396 |
363 reset_fail = trackpoint_power_on_reset(&psmouse->ps2dev); 364 if (trackpoint_sync(psmouse, !reset_fail)) 365 return -1; | 397 was_reset = tp->variant_id == TP_VARIANT_IBM && 398 trackpoint_power_on_reset(&psmouse->ps2dev) == 0; |
366 | 399 |
400 error = trackpoint_sync(psmouse, was_reset); 401 if (error) 402 return error; 403 |
|
367 return 0; 368} 369 370int trackpoint_detect(struct psmouse *psmouse, bool set_properties) 371{ 372 struct ps2dev *ps2dev = &psmouse->ps2dev; | 404 return 0; 405} 406 407int trackpoint_detect(struct psmouse *psmouse, bool set_properties) 408{ 409 struct ps2dev *ps2dev = &psmouse->ps2dev; |
373 unsigned char firmware_id; 374 unsigned char button_info; | 410 struct trackpoint_data *tp; 411 u8 variant_id; 412 u8 firmware_id; 413 u8 button_info; |
375 int error; 376 | 414 int error; 415 |
377 if (trackpoint_start_protocol(psmouse, &firmware_id)) 378 return -1; | 416 error = trackpoint_start_protocol(psmouse, &variant_id, &firmware_id); 417 if (error) 418 return error; |
379 380 if (!set_properties) 381 return 0; 382 | 419 420 if (!set_properties) 421 return 0; 422 |
383 if (trackpoint_read(ps2dev, TP_EXT_BTN, &button_info)) { 384 psmouse_warn(psmouse, "failed to get extended button data, assuming 3 buttons\n"); 385 button_info = 0x33; 386 } else if (!button_info) { 387 psmouse_warn(psmouse, "got 0 in extended button data, assuming 3 buttons\n"); 388 button_info = 0x33; 389 } 390 391 psmouse->private = kzalloc(sizeof(struct trackpoint_data), GFP_KERNEL); 392 if (!psmouse->private) | 423 tp = kzalloc(sizeof(*tp), GFP_KERNEL); 424 if (!tp) |
393 return -ENOMEM; 394 | 425 return -ENOMEM; 426 |
395 psmouse->vendor = "IBM"; | 427 trackpoint_defaults(tp); 428 tp->variant_id = variant_id; 429 tp->firmware_id = firmware_id; 430 431 psmouse->private = tp; 432 433 psmouse->vendor = trackpoint_variants[variant_id]; |
396 psmouse->name = "TrackPoint"; 397 398 psmouse->reconnect = trackpoint_reconnect; 399 psmouse->disconnect = trackpoint_disconnect; 400 | 434 psmouse->name = "TrackPoint"; 435 436 psmouse->reconnect = trackpoint_reconnect; 437 psmouse->disconnect = trackpoint_disconnect; 438 |
439 if (variant_id != TP_VARIANT_IBM) { 440 /* Newer variants do not support extended button query. */ 441 button_info = 0x33; 442 } else { 443 error = trackpoint_read(ps2dev, TP_EXT_BTN, &button_info); 444 if (error) { 445 psmouse_warn(psmouse, 446 "failed to get extended button data, assuming 3 buttons\n"); 447 button_info = 0x33; 448 } else if (!button_info) { 449 psmouse_warn(psmouse, 450 "got 0 in extended button data, assuming 3 buttons\n"); 451 button_info = 0x33; 452 } 453 } 454 |
|
401 if ((button_info & 0x0f) >= 3) | 455 if ((button_info & 0x0f) >= 3) |
402 __set_bit(BTN_MIDDLE, psmouse->dev->keybit); | 456 input_set_capability(psmouse->dev, EV_KEY, BTN_MIDDLE); |
403 404 __set_bit(INPUT_PROP_POINTER, psmouse->dev->propbit); 405 __set_bit(INPUT_PROP_POINTING_STICK, psmouse->dev->propbit); 406 | 457 458 __set_bit(INPUT_PROP_POINTER, psmouse->dev->propbit); 459 __set_bit(INPUT_PROP_POINTING_STICK, psmouse->dev->propbit); 460 |
407 trackpoint_defaults(psmouse->private); 408 409 error = trackpoint_power_on_reset(ps2dev); 410 411 /* Write defaults to TP only if reset fails. */ 412 if (error) | 461 if (variant_id != TP_VARIANT_IBM || 462 trackpoint_power_on_reset(ps2dev) != 0) { 463 /* 464 * Write defaults to TP if we did not reset the trackpoint. 465 */ |
413 trackpoint_sync(psmouse, false); | 466 trackpoint_sync(psmouse, false); |
467 } |
|
414 | 468 |
415 error = sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group); | 469 error = device_add_group(&ps2dev->serio->dev, &trackpoint_attr_group); |
416 if (error) { 417 psmouse_err(psmouse, 418 "failed to create sysfs attributes, error: %d\n", 419 error); 420 kfree(psmouse->private); 421 psmouse->private = NULL; 422 return -1; 423 } 424 425 psmouse_info(psmouse, | 470 if (error) { 471 psmouse_err(psmouse, 472 "failed to create sysfs attributes, error: %d\n", 473 error); 474 kfree(psmouse->private); 475 psmouse->private = NULL; 476 return -1; 477 } 478 479 psmouse_info(psmouse, |
426 "IBM TrackPoint firmware: 0x%02x, buttons: %d/%d\n", 427 firmware_id, | 480 "%s TrackPoint firmware: 0x%02x, buttons: %d/%d\n", 481 psmouse->vendor, firmware_id, |
428 (button_info & 0xf0) >> 4, button_info & 0x0f); 429 430 return 0; 431} 432 | 482 (button_info & 0xf0) >> 4, button_info & 0x0f); 483 484 return 0; 485} 486 |