29 #include <linux/device.h>
30 #include <linux/hid.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
46 #define MT_QUIRK_NOT_SEEN_MEANS_UP (1 << 0)
47 #define MT_QUIRK_SLOT_IS_CONTACTID (1 << 1)
48 #define MT_QUIRK_CYPRESS (1 << 2)
49 #define MT_QUIRK_SLOT_IS_CONTACTNUMBER (1 << 3)
50 #define MT_QUIRK_ALWAYS_VALID (1 << 4)
51 #define MT_QUIRK_VALID_IS_INRANGE (1 << 5)
52 #define MT_QUIRK_VALID_IS_CONFIDENCE (1 << 6)
53 #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE (1 << 8)
54 #define MT_QUIRK_NO_AREA (1 << 9)
101 #define MT_CLS_DEFAULT 0x0001
103 #define MT_CLS_SERIAL 0x0002
104 #define MT_CLS_CONFIDENCE 0x0003
105 #define MT_CLS_CONFIDENCE_CONTACT_ID 0x0004
106 #define MT_CLS_CONFIDENCE_MINUS_ONE 0x0005
107 #define MT_CLS_DUAL_INRANGE_CONTACTID 0x0006
108 #define MT_CLS_DUAL_INRANGE_CONTACTNUMBER 0x0007
109 #define MT_CLS_DUAL_NSMU_CONTACTID 0x0008
110 #define MT_CLS_INRANGE_CONTACTNUMBER 0x0009
113 #define MT_CLS_3M 0x0101
114 #define MT_CLS_CYPRESS 0x0102
115 #define MT_CLS_EGALAX 0x0103
116 #define MT_CLS_EGALAX_SERIAL 0x0104
117 #define MT_CLS_TOPSEED 0x0105
118 #define MT_CLS_PANASONIC 0x0106
119 #define MT_CLS_FLATFROG 0x0107
120 #define MT_CLS_GENERALTOUCH_TWOFINGERS 0x0108
121 #define MT_CLS_GENERALTOUCH_PWT_TENFINGERS 0x0109
123 #define MT_DEFAULT_MAXCONTACT 10
125 #define MT_USB_DEVICE(v, p) HID_DEVICE(BUS_USB, HID_GROUP_MULTITOUCH, v, p)
126 #define MT_BT_DEVICE(v, p) HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_MULTITOUCH, v, p)
133 static int cypress_compute_slot(
struct mt_device *
td)
141 static struct mt_class mt_classes[] = {
244 if (kstrtoul(buf, 0, &val))
254 static struct attribute *sysfs_attrs[] = {
255 &dev_attr_quirks.attr,
263 static void mt_feature_mapping(
struct hid_device *hdev,
266 struct mt_device *td = hid_get_drvdata(hdev);
269 switch (usage->
hid) {
274 for (i=0; i < field->
maxusage; i++) {
275 if (field->
usage[i].hid == usage->
hid) {
293 static void set_abs(
struct input_dev *
input,
unsigned int code,
298 int fuzz = snratio ? (fmax - fmin) / snratio : 0;
299 input_set_abs_params(input, code, fmin, fmax, fuzz, 0);
315 unsigned long **
bit,
int *
max)
317 struct mt_device *td = hid_get_drvdata(hdev);
345 switch (usage->
hid) {
347 hid_map_usage(hi, usage, bit, max,
351 mt_store_field(usage, td, hi);
355 hid_map_usage(hi, usage, bit, max,
359 mt_store_field(usage, td, hi);
366 switch (usage->
hid) {
368 mt_store_field(usage, td, hi);
372 mt_store_field(usage, td, hi);
378 mt_store_field(usage, td, hi);
382 mt_store_field(usage, td, hi);
387 hid_map_usage(hi, usage, bit, max,
392 mt_store_field(usage, td, hi);
396 hid_map_usage(hi, usage, bit, max,
401 input_set_abs_params(hi->
input,
404 mt_store_field(usage, td, hi);
408 hid_map_usage(hi, usage, bit, max,
412 mt_store_field(usage, td, hi);
433 hid_map_usage(hi, usage, bit, max,
EV_KEY, code);
447 unsigned long **bit,
int *max)
455 static int mt_compute_slot(
struct mt_device *td,
struct input_dev *
input)
463 return cypress_compute_slot(td);
469 return td->
curdata.contactid - 1;
478 static void mt_complete_slot(
struct mt_device *td,
struct input_dev *input)
481 int slotnum = mt_compute_slot(td, input);
513 static void mt_sync_frame(
struct mt_device *td,
struct input_dev *input)
523 struct mt_device *td = hid_get_drvdata(hid);
527 switch (usage->
hid) {
579 mt_complete_slot(td, field->
hidinput->input);
583 mt_sync_frame(td, field->
hidinput->input);
594 static void mt_set_input_mode(
struct hid_device *hdev)
596 struct mt_device *td = hid_get_drvdata(hdev);
611 static void mt_set_maxcontacts(
struct hid_device *hdev)
613 struct mt_device *td = hid_get_drvdata(hdev);
628 fieldmax = r->
field[0]->logical_maximum;
629 max =
min(fieldmax, max);
630 if (r->
field[0]->value[0] != max) {
637 static void mt_post_parse_default_settings(
struct mt_device *td)
644 quirks &= ~MT_QUIRK_NOT_SEEN_MEANS_UP;
645 quirks &= ~MT_QUIRK_VALID_IS_INRANGE;
646 quirks &= ~MT_QUIRK_VALID_IS_CONFIDENCE;
652 static void mt_post_parse(
struct mt_device *td)
665 struct mt_device *td = hid_get_drvdata(hdev);
667 struct input_dev *input = hi->
input;
678 mt_post_parse_default_settings(td);
683 if (cls->
quirks & MT_QUIRK_NOT_SEEN_MEANS_UP)
695 struct mt_class *mtclass = mt_classes;
697 for (i = 0; mt_classes[
i].
name ; i++) {
698 if (id->driver_data == mt_classes[i].
name) {
699 mtclass = &(mt_classes[
i]);
711 dev_err(&hdev->
dev,
"cannot allocate multitouch data\n");
717 hid_set_drvdata(hdev, td);
721 dev_err(&hdev->
dev,
"cannot allocate multitouch fields data\n");
729 ret = hid_parse(hdev);
739 mt_set_maxcontacts(hdev);
740 mt_set_input_mode(hdev);
754 static int mt_reset_resume(
struct hid_device *hdev)
756 mt_set_maxcontacts(hdev);
757 mt_set_input_mode(hdev);
765 struct usb_device *
dev;
770 intf = to_usb_interface(hdev->
dev.parent);
771 interface = intf->cur_altsetting;
781 0, interface->desc.bInterfaceNumber,
782 NULL, 0, USB_CTRL_SET_TIMEOUT);
788 static void mt_remove(
struct hid_device *hdev)
790 struct mt_device *td = hid_get_drvdata(hdev);
794 hid_set_drvdata(hdev,
NULL);
1113 static const struct hid_usage_id mt_grabbed_usages[] = {
1119 .name =
"hid-multitouch",
1120 .id_table = mt_devices,
1122 .remove = mt_remove,
1123 .input_mapping = mt_input_mapping,
1124 .input_mapped = mt_input_mapped,
1125 .input_configured = mt_input_configured,
1126 .feature_mapping = mt_feature_mapping,
1127 .usage_table = mt_grabbed_usages,
1130 .reset_resume = mt_reset_resume,
1131 .resume = mt_resume,
1135 static int __init mt_init(
void)
1140 static void __exit mt_exit(
void)