HID: wacom: set initial hardware touch switch state to 'off'
authorPing Cheng <ping.cheng@wacom.com>
Mon, 19 Jul 2021 20:55:29 +0000 (13:55 -0700)
committerJiri Kosina <jkosina@suse.cz>
Wed, 28 Jul 2021 09:45:40 +0000 (11:45 +0200)
Wacom touch devices have two types of touch switches: softkey touch
toggle and hardware touch switch. For softkey toggle, we assume
touch is on by default in the driver. However the hardware touch
switch is controlled by end users. We don't know if it's on or off
before getting the status event.

This patch sets touch off for devices with a hardware switch until we
get the status. This is a bit safer for users who leave the switch "off"
and don't want any accidental touches. The tradeoff is a slight delay
between device connection and touch becoming enabled for users who
leave the switch "on".

Signed-off-by: Ping Cheng <ping.cheng@wacom.com>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
Tested-by: Jason Gerecke <jason.gerecke@wacom.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/wacom_sys.c
drivers/hid/wacom_wac.c
drivers/hid/wacom_wac.h

index 57bfa0ae98361e14fd14b57e9dc831597c91cfc4..713a2504092f396387c734b0d9c81f9d8ec550c8 100644 (file)
@@ -2287,7 +2287,13 @@ static void wacom_set_shared_values(struct wacom_wac *wacom_wac)
 
        if (wacom_wac->has_mute_touch_switch) {
                wacom_wac->shared->has_mute_touch_switch = true;
-               wacom_wac->shared->is_touch_on = true;
+               /* Hardware touch switch may be off. Wait until
+                * we know the switch state to decide is_touch_on.
+                * Softkey state should be initialized to "on" to
+                * match historic default.
+                */
+               if (wacom_wac->is_soft_touch_switch)
+                       wacom_wac->shared->is_touch_on = true;
        }
 
        if (wacom_wac->shared->has_mute_touch_switch &&
index 81ba642adcb74cbc351b0cbd3f95256c26ffe74c..fa2b4222bcad61d1285da78505bad463ff3b6bd2 100644 (file)
@@ -1987,14 +1987,17 @@ static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
                features->numbered_buttons++;
                features->device_type |= WACOM_DEVICETYPE_PAD;
                break;
-       case WACOM_HID_WD_TOUCHONOFF:
        case WACOM_HID_WD_MUTE_DEVICE:
+               /* softkey touch switch */
+               wacom_wac->is_soft_touch_switch = true;
+               fallthrough;
+       case WACOM_HID_WD_TOUCHONOFF:
                /*
-                * This usage, which is used to mute touch events, comes
-                * from the pad packet, but is reported on the touch
+                * These two usages, which are used to mute touch events, come
+                * from the pad packet, but are reported on the touch
                 * interface. Because the touch interface may not have
                 * been created yet, we cannot call wacom_map_usage(). In
-                * order to process this usage when we receive it, we set
+                * order to process the usages when we receive them, we set
                 * the usage type and code directly.
                 */
                wacom_wac->has_mute_touch_switch = true;
@@ -3835,6 +3838,7 @@ int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
                        input_dev->evbit[0] |= BIT_MASK(EV_SW);
                        __set_bit(SW_MUTE_DEVICE, input_dev->swbit);
                        wacom_wac->has_mute_touch_switch = true;
+                       wacom_wac->is_soft_touch_switch = true;
                }
                fallthrough;
 
index 8f16654eca098d39cbccd46bdfb0583d1fb2b6be..4e9eb0c1eff6315624417e468c01211a43b7243c 100644 (file)
@@ -352,6 +352,7 @@ struct wacom_wac {
        int mode_value;
        struct hid_data hid_data;
        bool has_mute_touch_switch;
+       bool is_soft_touch_switch;
        bool has_mode_change;
        bool is_direct_mode;
        bool is_invalid_bt_frame;