From 7021b60073f8059e1ec8aa140eb5fdfc017d0041 Mon Sep 17 00:00:00 2001 From: Grant Grundler Date: Thu, 5 Jan 2017 11:07:04 -0800 Subject: HID: remove use of DRIVER_LICENSE Local "#define DRIVER_LICENSE" obfuscates which license is used in MODULE_LICENSE(). "fgrep -R MODULE_LICENSE" is more informative when the string is hard coded in MODULE_LICENSE. Signed-off-by: Grant Grundler Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index b9779bcbd140..57a9faf56830 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -2540,4 +2540,4 @@ module_hid_driver(wacom_driver); MODULE_VERSION(DRIVER_VERSION); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_LICENSE(DRIVER_LICENSE); +MODULE_LICENSE("GPL"); -- cgit v1.2.3 From 5b779fc52020ac6f5beea31c5eafc3d25cf70dc1 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 20 Jan 2017 16:20:11 +0100 Subject: HID: wacom: release the resources before leaving despite devm In the general case, the resources are properly released by devm without needing to do anything. However, when unplugging the wireless receiver, the kernel segfaults from time to time while calling devres_release_all(). I think in that case the resources attempt to access hid_get_drvdata(hdev) which has been set to null while leaving wacom_remove(). Signed-off-by: Benjamin Tissoires Acked-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 8aeca038cc73..0a817e69e029 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -2497,6 +2497,8 @@ static void wacom_remove(struct hid_device *hdev) if (hdev->bus == BUS_BLUETOOTH) device_remove_file(&hdev->dev, &dev_attr_speed); + wacom_release_resources(wacom); + hid_set_drvdata(hdev, NULL); } -- cgit v1.2.3 From c0265a9488c2a3aea315b61a9239d5494997fa71 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 20 Jan 2017 16:20:12 +0100 Subject: HID: wacom: remove warning while disconnecting devices When the LED class gets removed, it actually tries to reset the LED. However, the device being disconnected, the set_report fails. Previously, the attempt to cut lose this last event was through unsetting the HID drvdata, but it was not working properly. Simply reset the LED groups to NULL makes a more efficient solution. Signed-off-by: Benjamin Tissoires Acked-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 0a817e69e029..4c0fa3e7ea00 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -757,9 +757,6 @@ static int wacom_led_control(struct wacom *wacom) unsigned char report_id = WAC_CMD_LED_CONTROL; int buf_size = 9; - if (!hid_get_drvdata(wacom->hdev)) - return -ENODEV; - if (!wacom->led.groups) return -ENOTSUPP; @@ -2497,6 +2494,8 @@ static void wacom_remove(struct hid_device *hdev) if (hdev->bus == BUS_BLUETOOTH) device_remove_file(&hdev->dev, &dev_attr_speed); + /* make sure we don't trigger the LEDs */ + wacom_led_groups_release(wacom); wacom_release_resources(wacom); hid_set_drvdata(hdev, NULL); -- cgit v1.2.3 From a544c619a54bd5e552b1c8c308e77f37f1e3ad7c Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Fri, 20 Jan 2017 16:20:13 +0100 Subject: HID: wacom: do not attempt to switch mode while in probe The Intuos Pro seems to not like when we set the features right after being powered up. Instead of waiting during probe, we can schedule the switch mode and LED control in a deferred worker so that we don't have the 5 secs of delay from USB when the device is not accessible. The USB timeout delays were really a pain because if you happen to unplug the tablet while it is still waiting, you are just adding 5 second timeouts to the USB stack. Which means that a new plug of the same tablet will also gets delayed, and will also attempt to access the hardware while in .probe(). So the tablet doesn't appear in the dmesg, the user unplug/replug it to make it appearing... and so on so forth. Really, this is for the best :) Signed-off-by: Benjamin Tissoires Acked-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 4c0fa3e7ea00..e1aa51abac30 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -497,11 +497,11 @@ static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed, * from the tablet, it is necessary to switch the tablet out of this * mode and into one which sends the full range of tablet data. */ -static int wacom_query_tablet_data(struct hid_device *hdev, - struct wacom_features *features) +static int _wacom_query_tablet_data(struct wacom *wacom) { - struct wacom *wacom = hid_get_drvdata(hdev); + struct hid_device *hdev = wacom->hdev; struct wacom_wac *wacom_wac = &wacom->wacom_wac; + struct wacom_features *features = &wacom_wac->features; if (hdev->bus == BUS_BLUETOOTH) return wacom_bt_query_tablet_data(hdev, 1, features); @@ -1437,11 +1437,23 @@ static int wacom_initialize_leds(struct wacom *wacom) "cannot create sysfs group err: %d\n", error); return error; } - wacom_led_control(wacom); return 0; } +static void wacom_init_work(struct work_struct *work) +{ + struct wacom *wacom = container_of(work, struct wacom, init_work.work); + + _wacom_query_tablet_data(wacom); + wacom_led_control(wacom); +} + +static void wacom_query_tablet_data(struct wacom *wacom) +{ + schedule_delayed_work(&wacom->init_work, msecs_to_jiffies(1000)); +} + static enum power_supply_property wacom_battery_props[] = { POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_PRESENT, @@ -2115,7 +2127,7 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless) if (!wireless) { /* Note that if query fails it is not a hard failure */ - wacom_query_tablet_data(hdev, features); + wacom_query_tablet_data(wacom); } /* touch only Bamboo doesn't support pen */ @@ -2447,6 +2459,7 @@ static int wacom_probe(struct hid_device *hdev, wacom->usbdev = dev; wacom->intf = intf; mutex_init(&wacom->lock); + INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work); INIT_WORK(&wacom->wireless_work, wacom_wireless_work); INIT_WORK(&wacom->battery_work, wacom_battery_work); INIT_WORK(&wacom->remote_work, wacom_remote_work); @@ -2488,6 +2501,7 @@ static void wacom_remove(struct hid_device *hdev) hid_hw_stop(hdev); + cancel_delayed_work_sync(&wacom->init_work); cancel_work_sync(&wacom->wireless_work); cancel_work_sync(&wacom->battery_work); cancel_work_sync(&wacom->remote_work); @@ -2505,12 +2519,11 @@ static void wacom_remove(struct hid_device *hdev) static int wacom_resume(struct hid_device *hdev) { struct wacom *wacom = hid_get_drvdata(hdev); - struct wacom_features *features = &wacom->wacom_wac.features; mutex_lock(&wacom->lock); /* switch to wacom mode first */ - wacom_query_tablet_data(hdev, features); + _wacom_query_tablet_data(wacom); wacom_led_control(wacom); mutex_unlock(&wacom->lock); -- cgit v1.2.3 From 5ba13c6495010cd39e0ecb89ce1e546189bd6006 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 25 Jan 2017 12:08:36 -0800 Subject: HID: wacom: Move WAC_CMD_* into wacom_wac.h Centralize our definition of report IDs by moving those for device commands into wacom_wac.h alongside those for input reports. Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index e1aa51abac30..4dd7b80ffca4 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -16,15 +16,7 @@ #include #define WAC_MSG_RETRIES 5 - -#define WAC_CMD_WL_LED_CONTROL 0x03 -#define WAC_CMD_LED_CONTROL 0x20 -#define WAC_CMD_ICON_START 0x21 -#define WAC_CMD_ICON_XFER 0x23 -#define WAC_CMD_ICON_BT_XFER 0x26 #define WAC_CMD_RETRIES 10 -#define WAC_CMD_DELETE_PAIRING 0x20 -#define WAC_CMD_UNPAIR_ALL 0xFF #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP) #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP) -- cgit v1.2.3 From 4922cd26f03c1c71bf7dd6cbdb638e7e36a4a50b Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 25 Jan 2017 12:08:37 -0800 Subject: HID: wacom: Support 2nd-gen Intuos Pro's Bluetooth classic interface In addition to its USB interface, the second-generation Intuos Pro includes a Bluetooth radio that offers two pairing interfaces: classic and low-energy. The classic interface functions just like the earlier Bluetooth-enabled Intuos4 and Graphire4 tablets, appearing as a HID device that our driver can work with. The low-energy interface is intented to be used by userspace applications that make use of its paper-to-digital capabilities. Despite the USB interface using Wacom's new vendor-defined HID usages, the Bluetooth interface provides us with useless black-box "blob" report descriptors like past devices. We thus have to explicitly add support for the PIDs and reports used. These devices pack a /lot/ of information into a single Bluetooth input report. Each report contains up to seven snapshots of the pen state, four snapshots of the touch state (of five touches each), pad state, and battery data. Thankfully this isn't too hard for the driver to report -- it just takes a fair amount of code to extract! Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 4dd7b80ffca4..4a70783e64e1 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -756,6 +756,10 @@ static int wacom_led_control(struct wacom *wacom) report_id = WAC_CMD_WL_LED_CONTROL; buf_size = 13; } + else if (wacom->wacom_wac.features.type == INTUOSP2_BT) { + report_id = WAC_CMD_WL_INTUOSP2; + buf_size = 51; + } buf = kzalloc(buf_size, GFP_KERNEL); if (!buf) return -ENOMEM; @@ -781,6 +785,16 @@ static int wacom_led_control(struct wacom *wacom) } else buf[1] = led_bits; } + else if (wacom->wacom_wac.features.type == INTUOSP2_BT) { + buf[0] = report_id; + buf[4] = 100; // Power Connection LED (ORANGE) + buf[5] = 100; // BT Connection LED (BLUE) + buf[6] = 100; // Paper Mode (RED?) + buf[7] = 100; // Paper Mode (GREEN?) + buf[8] = 100; // Paper Mode (BLUE?) + buf[9] = wacom->led.llv; + buf[10] = wacom->led.groups[0].select & 0x03; + } else { int led = wacom->led.groups[0].select | 0x4; @@ -1409,6 +1423,17 @@ static int wacom_initialize_leds(struct wacom *wacom) &intuos5_led_attr_group); break; + case INTUOSP2_BT: + wacom->led.llv = 50; + wacom->led.max_llv = 100; + error = wacom_leds_alloc_and_register(wacom, 1, 4, false); + if (error) { + hid_err(wacom->hdev, + "cannot create leds err: %d\n", error); + return error; + } + return 0; + case REMOTE: wacom->led.llv = 255; wacom->led.max_llv = 255; -- cgit v1.2.3 From ac2423c975dbd3e8c2afc6dec53ee25be38f723b Mon Sep 17 00:00:00 2001 From: Aaron Armstrong Skomra Date: Wed, 25 Jan 2017 12:08:40 -0800 Subject: HID: wacom: generic: add vendor defined touch Add vendor defined touch to support the second generation Intuos Pro. Previously all generic Wacom devices used true HID to report their touch. Signed-off-by: Aaron Skomra Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 4a70783e64e1..a4884e78b3f8 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -112,11 +112,12 @@ static void wacom_feature_mapping(struct hid_device *hdev, struct wacom *wacom = hid_get_drvdata(hdev); struct wacom_features *features = &wacom->wacom_wac.features; struct hid_data *hid_data = &wacom->wacom_wac.hid_data; + unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid); u8 *data; int ret; int n; - switch (usage->hid) { + switch (equivalent_usage) { case HID_DG_CONTACTMAX: /* leave touch_max as is if predefined */ if (!features->touch_max) { @@ -325,8 +326,14 @@ static void wacom_post_parse_hid(struct hid_device *hdev, if (features->type == HID_GENERIC) { /* Any last-minute generic device setup */ if (features->touch_max > 1) { - input_mt_init_slots(wacom_wac->touch_input, wacom_wac->features.touch_max, - INPUT_MT_DIRECT); + if (features->device_type & WACOM_DEVICETYPE_DIRECT) + input_mt_init_slots(wacom_wac->touch_input, + wacom_wac->features.touch_max, + INPUT_MT_DIRECT); + else + input_mt_init_slots(wacom_wac->touch_input, + wacom_wac->features.touch_max, + INPUT_MT_POINTER); } } } -- cgit v1.2.3 From d2ec58aee8b1d68d309656a0561c81c12197a987 Mon Sep 17 00:00:00 2001 From: Aaron Armstrong Skomra Date: Wed, 25 Jan 2017 12:08:41 -0800 Subject: HID: wacom: generic: support generic touch switch The second generation Intuos Pro is the first device in the generic codepath which has a touchswitch. We utilize a flag in wacom_shared in order to report this switch event received from the pad on the touch input. Signed-off-by: Aaron Skomra Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index a4884e78b3f8..a8e68dc2ca99 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -2053,6 +2053,24 @@ static void wacom_release_resources(struct wacom *wacom) wacom->wacom_wac.pad_input = NULL; } +static void wacom_set_shared_values(struct wacom_wac *wacom_wac) +{ + if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) { + wacom_wac->shared->type = wacom_wac->features.type; + wacom_wac->shared->touch_input = wacom_wac->touch_input; + } + + if (wacom_wac->has_mute_touch_switch) + wacom_wac->shared->has_mute_touch_switch = true; + + if (wacom_wac->shared->has_mute_touch_switch && + wacom_wac->shared->touch_input) { + set_bit(EV_SW, wacom_wac->shared->touch_input->evbit); + input_set_capability(wacom_wac->shared->touch_input, EV_SW, + SW_MUTE_DEVICE); + } +} + static int wacom_parse_and_register(struct wacom *wacom, bool wireless) { struct wacom_wac *wacom_wac = &wacom->wacom_wac; @@ -2172,13 +2190,7 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless) if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) error = hid_hw_open(hdev); - if ((wacom_wac->features.type == INTUOSHT || - wacom_wac->features.type == INTUOSHT2) && - (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)) { - wacom_wac->shared->type = wacom_wac->features.type; - wacom_wac->shared->touch_input = wacom_wac->touch_input; - } - + wacom_set_shared_values(wacom_wac); devres_close_group(&hdev->dev, wacom); return 0; -- cgit v1.2.3 From 10c55cacb8b20518fddf92de43fbfb198f288eb2 Mon Sep 17 00:00:00 2001 From: Aaron Armstrong Skomra Date: Wed, 25 Jan 2017 12:08:42 -0800 Subject: HID: wacom: generic: support LEDs Add support for the LEDs around the mode switch to the generic code path in support of the second generation Intuos Pro. Signed-off-by: Aaron Skomra Reviewed-by: Ping Cheng Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'drivers/hid/wacom_sys.c') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index a8e68dc2ca99..3586acbdb467 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -771,8 +771,13 @@ static int wacom_led_control(struct wacom *wacom) if (!buf) return -ENOMEM; - if (wacom->wacom_wac.features.type >= INTUOS5S && - wacom->wacom_wac.features.type <= INTUOSPL) { + if (wacom->wacom_wac.features.type == HID_GENERIC) { + buf[0] = WAC_CMD_LED_CONTROL_GENERIC; + buf[1] = wacom->led.llv; + buf[2] = wacom->led.groups[0].select & 0x03; + + } else if ((wacom->wacom_wac.features.type >= INTUOS5S && + wacom->wacom_wac.features.type <= INTUOSPL)) { /* * Touch Ring and crop mark LED luminance may take on * one of four values: @@ -1042,6 +1047,17 @@ static struct attribute_group intuos5_led_attr_group = { .attrs = intuos5_led_attrs, }; +static struct attribute *generic_led_attrs[] = { + &dev_attr_status0_luminance.attr, + &dev_attr_status_led0_select.attr, + NULL +}; + +static struct attribute_group generic_led_attr_group = { + .name = "wacom_led", + .attrs = generic_led_attrs, +}; + struct wacom_sysfs_group_devres { struct attribute_group *group; struct kobject *root; @@ -1363,7 +1379,7 @@ static int wacom_leds_alloc_and_register(struct wacom *wacom, int group_count, return 0; } -static int wacom_initialize_leds(struct wacom *wacom) +int wacom_initialize_leds(struct wacom *wacom) { int error; @@ -1372,6 +1388,23 @@ static int wacom_initialize_leds(struct wacom *wacom) /* Initialize default values */ switch (wacom->wacom_wac.features.type) { + case HID_GENERIC: + if (!wacom->generic_has_leds) + return 0; + wacom->led.llv = 100; + wacom->led.max_llv = 100; + + error = wacom_leds_alloc_and_register(wacom, 1, 4, false); + if (error) { + hid_err(wacom->hdev, + "cannot create leds err: %d\n", error); + return error; + } + + error = wacom_devm_sysfs_create_group(wacom, + &generic_led_attr_group); + break; + case INTUOS4S: case INTUOS4: case INTUOS4WL: -- cgit v1.2.3