16 #include <linux/device.h>
17 #include <linux/hid.h>
20 #include <linux/module.h>
21 #include <linux/slab.h>
25 #define NTRIG_DUPLICATE_USAGES 0x001
35 static unsigned int activate_slack = 1;
38 "the start of touch input.");
40 static unsigned int deactivate_slack = 4;
42 MODULE_PARM_DESC(deactivate_slack,
"Number of empty frames to ignore before "
43 "deactivating touch.");
45 static unsigned int activation_width = 64;
48 "processing touch events.");
50 static unsigned int activation_height = 32;
53 "processing touch events.");
97 static int ntrig_version_string(
unsigned char *
raw,
char *
buf)
99 __u8 a = (raw[1] & 0x0e) >> 1;
100 __u8 b = (raw[0] & 0x3c) >> 2;
101 __u8 c = ((raw[0] & 0x03) << 3) | ((raw[3] & 0xe0) >> 5);
102 __u8 d = ((raw[3] & 0x07) << 3) | ((raw[2] & 0xe0) >> 5);
103 __u8 e = raw[2] & 0x07;
110 return sprintf(buf,
"%u.%u.%u.%u.%u", a, b, c, d, e);
113 static inline int ntrig_get_mode(
struct hid_device *hdev)
116 report_id_hash[0x0d];
123 return (
int)report->
field[0]->value[0];
126 static inline void ntrig_set_mode(
struct hid_device *hdev,
const int mode)
129 __u8 mode_commands[4] = { 0xe, 0xf, 0x1b, 0x10 };
131 if (mode < 0 || mode > 3)
135 report_id_hash[mode_commands[
mode]];
143 static void ntrig_report_version(
struct hid_device *hdev)
158 USB_CTRL_SET_TIMEOUT);
161 ret = ntrig_version_string(&data[2], buf);
163 hid_info(hdev,
"Firmware version: %s (%02x%02x %02x%02x)\n",
164 buf, data[2], data[3], data[4], data[5]);
176 struct ntrig_data *nd = hid_get_drvdata(hdev);
188 struct ntrig_data *nd = hid_get_drvdata(hdev);
200 struct ntrig_data *nd = hid_get_drvdata(hdev);
212 struct ntrig_data *nd = hid_get_drvdata(hdev);
224 struct ntrig_data *nd = hid_get_drvdata(hdev);
233 const char *buf,
size_t count)
236 struct ntrig_data *nd = hid_get_drvdata(hdev);
259 struct ntrig_data *nd = hid_get_drvdata(hdev);
268 const char *buf,
size_t count)
271 struct ntrig_data *nd = hid_get_drvdata(hdev);
295 struct ntrig_data *nd = hid_get_drvdata(hdev);
302 const char *buf,
size_t count)
305 struct ntrig_data *nd = hid_get_drvdata(hdev);
328 struct ntrig_data *nd = hid_get_drvdata(hdev);
337 const char *buf,
size_t count)
340 struct ntrig_data *nd = hid_get_drvdata(hdev);
357 set_activation_width);
364 struct ntrig_data *nd = hid_get_drvdata(hdev);
373 const char *buf,
size_t count)
376 struct ntrig_data *nd = hid_get_drvdata(hdev);
393 show_activation_height, set_activation_height);
400 struct ntrig_data *nd = hid_get_drvdata(hdev);
407 const char *buf,
size_t count)
410 struct ntrig_data *nd = hid_get_drvdata(hdev);
431 set_deactivate_slack);
433 static struct attribute *sysfs_attrs[] = {
434 &dev_attr_sensor_physical_width.attr,
435 &dev_attr_sensor_physical_height.attr,
436 &dev_attr_sensor_logical_width.attr,
437 &dev_attr_sensor_logical_height.attr,
438 &dev_attr_min_height.attr,
439 &dev_attr_min_width.attr,
440 &dev_attr_activate_slack.attr,
441 &dev_attr_activation_width.attr,
442 &dev_attr_activation_height.attr,
443 &dev_attr_deactivate_slack.attr,
459 unsigned long **
bit,
int *
max)
461 struct ntrig_data *nd = hid_get_drvdata(hdev);
469 switch (usage->
hid) {
471 hid_map_usage(hi, usage, bit, max,
493 hid_map_usage(hi, usage, bit, max,
518 switch (usage->
hid) {
528 hid_map_usage(hi, usage, bit, max,
532 hid_map_usage(hi, usage, bit, max,
550 unsigned long **bit,
int *max)
573 struct input_dev *
input;
577 goto not_claimed_input;
590 switch (usage->
hid) {
753 input_mt_sync(field->
hidinput->input);
866 struct input_dev *
input;
875 hid_err(hdev,
"cannot allocate N-Trig data\n");
890 hid_set_drvdata(hdev, nd);
892 ret = hid_parse(hdev);
894 hid_err(hdev,
"parse failed\n");
900 hid_err(hdev,
"hw start failed\n");
906 if (hidinput->
report->maxfield < 1)
909 input = hidinput->
input;
910 switch (hidinput->
report->field[0]->application) {
912 input->name =
"N-Trig Pen";
928 (hidinput->
report->field[0]
930 "N-Trig Touchscreen" :
948 if (ntrig_get_mode(hdev) >= 4)
949 ntrig_set_mode(hdev, 3);
952 ntrig_report_version(hdev);
955 &ntrig_attribute_group);
963 static void ntrig_remove(
struct hid_device *hdev)
966 &ntrig_attribute_group);
968 kfree(hid_get_drvdata(hdev));
1014 static const struct hid_usage_id ntrig_grabbed_usages[] = {
1021 .id_table = ntrig_devices,
1022 .probe = ntrig_probe,
1023 .remove = ntrig_remove,
1024 .input_mapping = ntrig_input_mapping,
1025 .input_mapped = ntrig_input_mapped,
1026 .usage_table = ntrig_grabbed_usages,
1027 .event = ntrig_event,
1030 static int __init ntrig_init(
void)
1035 static void __exit ntrig_exit(
void)