To modify Ixia port numbers and IP in pod.yaml
[kvmfornfv.git] / kernel / drivers / hid / hid-multitouch.c
index 6a9b05b..f62a9d6 100644 (file)
@@ -61,6 +61,7 @@ MODULE_LICENSE("GPL");
 #define MT_QUIRK_ALWAYS_VALID          (1 << 4)
 #define MT_QUIRK_VALID_IS_INRANGE      (1 << 5)
 #define MT_QUIRK_VALID_IS_CONFIDENCE   (1 << 6)
+#define MT_QUIRK_CONFIDENCE            (1 << 7)
 #define MT_QUIRK_SLOT_IS_CONTACTID_MINUS_ONE   (1 << 8)
 #define MT_QUIRK_NO_AREA               (1 << 9)
 #define MT_QUIRK_IGNORE_DUPLICATES     (1 << 10)
@@ -78,6 +79,7 @@ struct mt_slot {
        __s32 contactid;        /* the device ContactID assigned to this slot */
        bool touch_state;       /* is the touch valid? */
        bool inrange_state;     /* is the finger in proximity of the sensor? */
+       bool confidence_state;  /* is the touch made by a finger? */
 };
 
 struct mt_class {
@@ -309,6 +311,41 @@ static struct attribute_group mt_attribute_group = {
        .attrs = sysfs_attrs
 };
 
+static void mt_get_feature(struct hid_device *hdev, struct hid_report *report)
+{
+       struct mt_device *td = hid_get_drvdata(hdev);
+       int ret, size = hid_report_len(report);
+       u8 *buf;
+
+       /*
+        * Only fetch the feature report if initial reports are not already
+        * been retrieved. Currently this is only done for Windows 8 touch
+        * devices.
+        */
+       if (!(hdev->quirks & HID_QUIRK_NO_INIT_REPORTS))
+               return;
+       if (td->mtclass.name != MT_CLS_WIN_8)
+               return;
+
+       buf = hid_alloc_report_buf(report, GFP_KERNEL);
+       if (!buf)
+               return;
+
+       ret = hid_hw_raw_request(hdev, report->id, buf, size,
+                                HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+       if (ret < 0) {
+               dev_warn(&hdev->dev, "failed to fetch feature %d\n",
+                        report->id);
+       } else {
+               ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, buf,
+                                          size, 0);
+               if (ret)
+                       dev_warn(&hdev->dev, "failed to report feature\n");
+       }
+
+       kfree(buf);
+}
+
 static void mt_feature_mapping(struct hid_device *hdev,
                struct hid_field *field, struct hid_usage *usage)
 {
@@ -322,11 +359,24 @@ static void mt_feature_mapping(struct hid_device *hdev,
                        break;
                }
 
-               td->inputmode = field->report->id;
-               td->inputmode_index = usage->usage_index;
+               if (td->inputmode < 0) {
+                       td->inputmode = field->report->id;
+                       td->inputmode_index = usage->usage_index;
+               } else {
+                       /*
+                        * Some elan panels wrongly declare 2 input mode
+                        * features, and silently ignore when we set the
+                        * value in the second field. Skip the second feature
+                        * and hope for the best.
+                        */
+                       dev_info(&hdev->dev,
+                                "Ignoring the extra HID_DG_INPUTMODE\n");
+               }
 
                break;
        case HID_DG_CONTACTMAX:
+               mt_get_feature(hdev, field->report);
+
                td->maxcontact_report_id = field->report->id;
                td->maxcontacts = field->value[0];
                if (!td->maxcontacts &&
@@ -343,10 +393,16 @@ static void mt_feature_mapping(struct hid_device *hdev,
                        break;
                }
 
+               mt_get_feature(hdev, field->report);
                if (field->value[usage->usage_index] == MT_BUTTONTYPE_CLICKPAD)
                        td->is_buttonpad = true;
 
                break;
+       case 0xff0000c5:
+               /* Retrieve the Win8 blob once to enable some devices */
+               if (usage->usage_index == 0)
+                       mt_get_feature(hdev, field->report);
+               break;
        }
 }
 
@@ -448,6 +504,9 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
                        mt_store_field(usage, td, hi);
                        return 1;
                case HID_DG_CONFIDENCE:
+                       if (cls->name == MT_CLS_WIN_8 &&
+                               field->application == HID_DG_TOUCHPAD)
+                               cls->quirks |= MT_QUIRK_CONFIDENCE;
                        mt_store_field(usage, td, hi);
                        return 1;
                case HID_DG_TIPSWITCH:
@@ -560,6 +619,7 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
                return;
 
        if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) {
+               int active;
                int slotnum = mt_compute_slot(td, input);
                struct mt_slot *s = &td->curdata;
                struct input_mt *mt = input->mt;
@@ -574,10 +634,14 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
                                return;
                }
 
+               if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE))
+                       s->confidence_state = 1;
+               active = (s->touch_state || s->inrange_state) &&
+                                                       s->confidence_state;
+
                input_mt_slot(input, slotnum);
-               input_mt_report_slot_state(input, MT_TOOL_FINGER,
-                       s->touch_state || s->inrange_state);
-               if (s->touch_state || s->inrange_state) {
+               input_mt_report_slot_state(input, MT_TOOL_FINGER, active);
+               if (active) {
                        /* this finger is in proximity of the sensor */
                        int wide = (s->w > s->h);
                        /* divided by two to match visual scale of touch */
@@ -642,6 +706,8 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
                        td->curdata.touch_state = value;
                        break;
                case HID_DG_CONFIDENCE:
+                       if (quirks & MT_QUIRK_CONFIDENCE)
+                               td->curdata.confidence_state = value;
                        if (quirks & MT_QUIRK_VALID_IS_CONFIDENCE)
                                td->curvalid = value;
                        break;
@@ -725,12 +791,13 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
                mt_sync_frame(td, report->field[0]->hidinput->input);
 }
 
-static void mt_touch_input_configured(struct hid_device *hdev,
+static int mt_touch_input_configured(struct hid_device *hdev,
                                        struct hid_input *hi)
 {
        struct mt_device *td = hid_get_drvdata(hdev);
        struct mt_class *cls = &td->mtclass;
        struct input_dev *input = hi->input;
+       int ret;
 
        if (!td->maxcontacts)
                td->maxcontacts = MT_DEFAULT_MAXCONTACT;
@@ -752,9 +819,12 @@ static void mt_touch_input_configured(struct hid_device *hdev,
        if (td->is_buttonpad)
                __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
 
-       input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
+       ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags);
+       if (ret)
+               return ret;
 
        td->mt_flags = 0;
+       return 0;
 }
 
 static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
@@ -778,9 +848,16 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
        /*
         * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
         * for the stylus.
+        * The check for mt_report_id ensures we don't process
+        * HID_DG_CONTACTCOUNT from the pen report as it is outside the physical
+        * collection, but within the report ID.
         */
        if (field->physical == HID_DG_STYLUS)
                return 0;
+       else if ((field->physical == 0) &&
+                (field->report->id != td->mt_report_id) &&
+                (td->mt_report_id != -1))
+               return 0;
 
        if (field->application == HID_DG_TOUCHSCREEN ||
            field->application == HID_DG_TOUCHPAD)
@@ -923,15 +1000,19 @@ static void mt_post_parse(struct mt_device *td)
                cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE;
 }
 
-static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
+static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
 {
        struct mt_device *td = hid_get_drvdata(hdev);
        char *name;
        const char *suffix = NULL;
        struct hid_field *field = hi->report->field[0];
+       int ret;
 
-       if (hi->report->id == td->mt_report_id)
-               mt_touch_input_configured(hdev, hi);
+       if (hi->report->id == td->mt_report_id) {
+               ret = mt_touch_input_configured(hdev, hi);
+               if (ret)
+                       return ret;
+       }
 
        /*
         * some egalax touchscreens have "application == HID_DG_TOUCHSCREEN"
@@ -961,6 +1042,9 @@ static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
                case HID_DG_TOUCHSCREEN:
                        /* we do not set suffix = "Touchscreen" */
                        break;
+               case HID_DG_TOUCHPAD:
+                       suffix = "Touchpad";
+                       break;
                case HID_GD_SYSTEM_CONTROL:
                        suffix = "System Control";
                        break;
@@ -982,6 +1066,8 @@ static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
                        hi->input->name = name;
                }
        }
+
+       return 0;
 }
 
 static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
@@ -1019,8 +1105,13 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
                 * reports. Fortunately, the Win8 spec says that all touches
                 * should be sent during each report, making the initialization
                 * of input reports unnecessary.
+                *
+                * In addition some touchpads do not behave well if we read
+                * all feature reports from them. Instead we prevent
+                * initial report fetching and then selectively fetch each
+                * report we are interested in.
                 */
-               hdev->quirks |= HID_QUIRK_NO_INIT_INPUT_REPORTS;
+               hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
 
        td = devm_kzalloc(&hdev->dev, sizeof(struct mt_device), GFP_KERNEL);
        if (!td) {
@@ -1138,6 +1229,14 @@ static const struct hid_device_id mt_devices[] = {
                MT_USB_DEVICE(USB_VENDOR_ID_CHUNGHWAT,
                        USB_DEVICE_ID_CHUNGHWAT_MULTITOUCH) },
 
+       /* CJTouch panels */
+       { .driver_data = MT_CLS_NSMU,
+               MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
+                       USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0020) },
+       { .driver_data = MT_CLS_NSMU,
+               MT_USB_DEVICE(USB_VENDOR_ID_CJTOUCH,
+                       USB_DEVICE_ID_CJTOUCH_MULTI_TOUCH_0040) },
+
        /* CVTouch panels */
        { .driver_data = MT_CLS_NSMU,
                MT_USB_DEVICE(USB_VENDOR_ID_CVTOUCH,