From d8aaccda7144df1c3d35251313197aed4cbea7bc Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Wed, 11 Nov 2015 09:49:37 -0500 Subject: HID: sony: Refactor the output report sending functions Refactor the output report sending functions to allow for the sending of output reports without enqueuing a work item. Output reports for any device can now be sent via the send_output_report function pointer in the sony_sc struct which points to the appropriate output function. The individual state worker functions have been replaced with a universal sony_state_worker function which uses this function pointer. Signed-off-by: Frank Praznik Signed-off-by: Jiri Kosina --- drivers/hid/hid-sony.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 774cd2210566..4ba904b02bc2 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1028,6 +1028,7 @@ struct sony_sc { struct led_classdev *leds[MAX_LEDS]; unsigned long quirks; struct work_struct state_worker; + void(*send_output_report)(struct sony_sc*); struct power_supply *battery; struct power_supply_desc battery_desc; int device_id; @@ -1789,7 +1790,7 @@ error_leds: return ret; } -static void sixaxis_state_worker(struct work_struct *work) +static void sixaxis_send_output_report(struct sony_sc *sc) { static const union sixaxis_output_report_01 default_report = { .buf = { @@ -1803,7 +1804,6 @@ static void sixaxis_state_worker(struct work_struct *work) 0x00, 0x00, 0x00, 0x00, 0x00 } }; - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); struct sixaxis_output_report *report = (struct sixaxis_output_report *)sc->output_report_dmabuf; int n; @@ -1846,9 +1846,8 @@ static void sixaxis_state_worker(struct work_struct *work) HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); } -static void dualshock4_state_worker(struct work_struct *work) +static void dualshock4_send_output_report(struct sony_sc *sc) { - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); struct hid_device *hdev = sc->hdev; __u8 *buf = sc->output_report_dmabuf; int offset; @@ -1893,9 +1892,8 @@ static void dualshock4_state_worker(struct work_struct *work) HID_OUTPUT_REPORT, HID_REQ_SET_REPORT); } -static void motion_state_worker(struct work_struct *work) +static void motion_send_output_report(struct sony_sc *sc) { - struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); struct hid_device *hdev = sc->hdev; struct motion_output_report_02 *report = (struct motion_output_report_02 *)sc->output_report_dmabuf; @@ -1914,6 +1912,12 @@ static void motion_state_worker(struct work_struct *work) hid_hw_output_report(hdev, (__u8 *)report, MOTION_REPORT_0x02_SIZE); } +static void sony_state_worker(struct work_struct *work) +{ + struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); + sc->send_output_report(sc); +} + static int sony_allocate_output_report(struct sony_sc *sc) { if ((sc->quirks & SIXAXIS_CONTROLLER) || @@ -2241,11 +2245,13 @@ static void sony_release_device_id(struct sony_sc *sc) } } -static inline void sony_init_work(struct sony_sc *sc, - void (*worker)(struct work_struct *)) +static inline void sony_init_output_report(struct sony_sc *sc, + void(*send_output_report)(struct sony_sc*)) { + sc->send_output_report = send_output_report; + if (!sc->worker_initialized) - INIT_WORK(&sc->state_worker, worker); + INIT_WORK(&sc->state_worker, sony_state_worker); sc->worker_initialized = 1; } @@ -2319,7 +2325,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; hdev->quirks |= HID_QUIRK_SKIP_OUTPUT_REPORT_ID; ret = sixaxis_set_operational_usb(hdev); - sony_init_work(sc, sixaxis_state_worker); + sony_init_output_report(sc, sixaxis_send_output_report); } else if ((sc->quirks & SIXAXIS_CONTROLLER_BT) || (sc->quirks & NAVIGATION_CONTROLLER_BT)) { /* @@ -2328,7 +2334,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) */ hdev->quirks |= HID_QUIRK_NO_OUTPUT_REPORTS_ON_INTR_EP; ret = sixaxis_set_operational_bt(hdev); - sony_init_work(sc, sixaxis_state_worker); + sony_init_output_report(sc, sixaxis_send_output_report); } else if (sc->quirks & DUALSHOCK4_CONTROLLER) { if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) { /* @@ -2343,9 +2349,9 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) } } - sony_init_work(sc, dualshock4_state_worker); + sony_init_output_report(sc, dualshock4_send_output_report); } else if (sc->quirks & MOTION_CONTROLLER) { - sony_init_work(sc, motion_state_worker); + sony_init_output_report(sc, motion_send_output_report); } else { ret = 0; } -- cgit 1.4.1 From decd946c99f6b3826bda0bfd5d1b2ddd56ef6b54 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Wed, 11 Nov 2015 09:49:38 -0500 Subject: HID: sony: Save and restore the controller state on suspend and resume On hardware which provides standby power for charging devices the state of the LEDs and force-feedback on controllers can persist even when the system is in standby. Additionally, the state of the controllers on resume may be different from the state they were in at the time when they were suspended (ie. LEDs are cleared on resume). This implements the suspend and resume callbacks which saves and clears the state of the LEDs on suspend and restores them on resume. Force-feedback is stopped on suspend but not automatically restored on resume until a new event is received to avoid potentially damaging hardware. USB Sixaxis and navigation controllers must be reinitialized when the hardware is reset on resume or they won't send any input reports. Signed-off-by: Frank Praznik Signed-off-by: Jiri Kosina --- drivers/hid/hid-sony.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 4ba904b02bc2..1041c44765e1 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1045,6 +1045,7 @@ struct sony_sc { __u8 battery_charging; __u8 battery_capacity; __u8 led_state[MAX_LEDS]; + __u8 resume_led_state[MAX_LEDS]; __u8 led_delay_on[MAX_LEDS]; __u8 led_delay_off[MAX_LEDS]; __u8 led_count; @@ -1912,6 +1913,12 @@ static void motion_send_output_report(struct sony_sc *sc) hid_hw_output_report(hdev, (__u8 *)report, MOTION_REPORT_0x02_SIZE); } +static inline void sony_send_output_report(struct sony_sc *sc) +{ + if (sc->send_output_report) + sc->send_output_report(sc); +} + static void sony_state_worker(struct work_struct *work) { struct sony_sc *sc = container_of(work, struct sony_sc, state_worker); @@ -2427,6 +2434,56 @@ static void sony_remove(struct hid_device *hdev) hid_hw_stop(hdev); } +#ifdef CONFIG_PM + +static int sony_suspend(struct hid_device *hdev, pm_message_t message) +{ + /* + * On suspend save the current LED state, + * stop running force-feedback and blank the LEDS. + */ + if (SONY_LED_SUPPORT || SONY_FF_SUPPORT) { + struct sony_sc *sc = hid_get_drvdata(hdev); + +#ifdef CONFIG_SONY_FF + sc->left = sc->right = 0; +#endif + + memcpy(sc->resume_led_state, sc->led_state, + sizeof(sc->resume_led_state)); + memset(sc->led_state, 0, sizeof(sc->led_state)); + + sony_send_output_report(sc); + } + + return 0; +} + +static int sony_resume(struct hid_device *hdev) +{ + /* Restore the state of controller LEDs on resume */ + if (SONY_LED_SUPPORT) { + struct sony_sc *sc = hid_get_drvdata(hdev); + + memcpy(sc->led_state, sc->resume_led_state, + sizeof(sc->led_state)); + + /* + * The Sixaxis and navigation controllers on USB need to be + * reinitialized on resume or they won't behave properly. + */ + if ((sc->quirks & SIXAXIS_CONTROLLER_USB) || + (sc->quirks & NAVIGATION_CONTROLLER_USB)) + sixaxis_set_operational_usb(sc->hdev); + + sony_set_leds(sc); + } + + return 0; +} + +#endif + static const struct hid_device_id sony_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER), .driver_data = SIXAXIS_CONTROLLER_USB }, @@ -2476,7 +2533,13 @@ static struct hid_driver sony_driver = { .probe = sony_probe, .remove = sony_remove, .report_fixup = sony_report_fixup, - .raw_event = sony_raw_event + .raw_event = sony_raw_event, + +#ifdef CONFIG_PM + .suspend = sony_suspend, + .resume = sony_resume, + .reset_resume = sony_resume, +#endif }; static int __init sony_init(void) -- cgit 1.4.1 From b71b5578a84d297954e4812ba0ca2d466e61cf42 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Fri, 6 Nov 2015 15:35:53 -0500 Subject: HID: sony: Remove the size check for the Dualshock 4 HID Descriptor Sony has modified the HID descriptor in new revisions of the Dualshock 4 which causes the size check in the descriptor replacement function to fail. Remove it so that new revisions of the controller will work correctly. The module is completely replacing the descriptor instead of patching it, so the size check isn't really necessary anyways. Signed-off-by: Frank Praznik Signed-off-by: Jiri Kosina --- drivers/hid/hid-sony.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 1041c44765e1..876ea2b85355 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1139,11 +1139,11 @@ static __u8 *sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, * the gyroscope values to corresponding axes so we need a * modified one. */ - if ((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && *rsize == 467) { + if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) { hid_info(hdev, "Using modified Dualshock 4 report descriptor with gyroscope axes\n"); rdesc = dualshock4_usb_rdesc; *rsize = sizeof(dualshock4_usb_rdesc); - } else if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && *rsize == 357) { + } else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) { hid_info(hdev, "Using modified Dualshock 4 Bluetooth report descriptor\n"); rdesc = dualshock4_bt_rdesc; *rsize = sizeof(dualshock4_bt_rdesc); -- cgit 1.4.1 From 6cf2e31bea1445ae50644d4d359786f43eb10afc Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Thu, 19 Nov 2015 12:58:14 +0900 Subject: HID: Drop owner assignment from i2c_driver i2c_driver does not need to set an owner because i2c_register_driver() will set it. Signed-off-by: Krzysztof Kozlowski Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/i2c-hid/i2c-hid.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 10bd8e6e4c9c..55d8f9d25696 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -1184,7 +1184,6 @@ MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table); static struct i2c_driver i2c_hid_driver = { .driver = { .name = "i2c_hid", - .owner = THIS_MODULE, .pm = &i2c_hid_pm, .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match), .of_match_table = of_match_ptr(i2c_hid_of_match), -- cgit 1.4.1 From 27ba1d56e1e150294802f0dca8368abc51a664fb Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Fri, 6 Nov 2015 18:00:30 +0100 Subject: HID: wacom: Delete an unnecessary check before kobject_put() The kobject_put() function tests whether its argument is NULL and then returns immediately. Thus the test around the call is not needed. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Jiri Kosina --- drivers/hid/wacom_sys.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index e06af5b9f59e..c7a3b79d563e 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1353,8 +1353,7 @@ static void wacom_clean_inputs(struct wacom *wacom) else input_free_device(wacom->wacom_wac.pad_input); } - if (wacom->remote_dir) - kobject_put(wacom->remote_dir); + kobject_put(wacom->remote_dir); wacom->wacom_wac.pen_input = NULL; wacom->wacom_wac.touch_input = NULL; wacom->wacom_wac.pad_input = NULL; -- cgit 1.4.1 From 54f32fd5dff96a903f838de1efcdfb9831c5b207 Mon Sep 17 00:00:00 2001 From: Andy Lutomirski Date: Thu, 19 Nov 2015 08:19:31 -0800 Subject: HID: Make report_descriptor available for all devices Currently the sysfs report_descriptor attribute is only available if the device is claimed. We have the descriptor before we even create the device node, so just instantiate report_descriptor statically. Signed-off-by: Andy Lutomirski Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index c6f7a694f67a..d5ddb7573691 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1691,11 +1691,6 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) hid_warn(hdev, "can't create sysfs country code attribute err: %d\n", ret); - ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc); - if (ret) - hid_warn(hdev, - "can't create sysfs report descriptor attribute err: %d\n", ret); - hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", buf, bus, hdev->version >> 8, hdev->version & 0xff, type, hdev->name, hdev->phys); @@ -1707,7 +1702,6 @@ EXPORT_SYMBOL_GPL(hid_connect); void hid_disconnect(struct hid_device *hdev) { device_remove_file(&hdev->dev, &dev_attr_country); - device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc); if (hdev->claimed & HID_CLAIMED_INPUT) hidinput_disconnect(hdev); if (hdev->claimed & HID_CLAIMED_HIDDEV) @@ -2236,7 +2230,15 @@ static struct attribute *hid_dev_attrs[] = { &dev_attr_modalias.attr, NULL, }; -ATTRIBUTE_GROUPS(hid_dev); +static struct bin_attribute *hid_dev_bin_attrs[] = { + &dev_bin_attr_report_desc, + NULL +}; +static const struct attribute_group hid_dev_group = { + .attrs = hid_dev_attrs, + .bin_attrs = hid_dev_bin_attrs, +}; +__ATTRIBUTE_GROUPS(hid_dev); static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) { -- cgit 1.4.1 From a5ce8f5b12966d34623d6c20278b5b4da7a53675 Mon Sep 17 00:00:00 2001 From: Simon Wood Date: Thu, 19 Nov 2015 16:42:11 -0700 Subject: HID: hid-logitech-hidpp: Add support for very long packets Patch add support for the 'very long' HID++ packets, which are 64 bytes in length. Signed-off-by: Simon Wood Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-logitech-hidpp.c | 59 ++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 11 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 5fd97860aec4..0f53dc8c79b1 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -40,9 +40,11 @@ MODULE_PARM_DESC(disable_tap_to_click, #define REPORT_ID_HIDPP_SHORT 0x10 #define REPORT_ID_HIDPP_LONG 0x11 +#define REPORT_ID_HIDPP_VERY_LONG 0x12 #define HIDPP_REPORT_SHORT_LENGTH 7 #define HIDPP_REPORT_LONG_LENGTH 20 +#define HIDPP_REPORT_VERY_LONG_LENGTH 64 #define HIDPP_QUIRK_CLASS_WTP BIT(0) #define HIDPP_QUIRK_CLASS_M560 BIT(1) @@ -81,13 +83,13 @@ MODULE_PARM_DESC(disable_tap_to_click, struct fap { u8 feature_index; u8 funcindex_clientid; - u8 params[HIDPP_REPORT_LONG_LENGTH - 4U]; + u8 params[HIDPP_REPORT_VERY_LONG_LENGTH - 4U]; }; struct rap { u8 sub_id; u8 reg_address; - u8 params[HIDPP_REPORT_LONG_LENGTH - 4U]; + u8 params[HIDPP_REPORT_VERY_LONG_LENGTH - 4U]; }; struct hidpp_report { @@ -153,6 +155,9 @@ static int __hidpp_send_report(struct hid_device *hdev, case REPORT_ID_HIDPP_LONG: fields_count = HIDPP_REPORT_LONG_LENGTH; break; + case REPORT_ID_HIDPP_VERY_LONG: + fields_count = HIDPP_REPORT_VERY_LONG_LENGTH; + break; default: return -ENODEV; } @@ -217,8 +222,9 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp, goto exit; } - if (response->report_id == REPORT_ID_HIDPP_LONG && - response->fap.feature_index == HIDPP20_ERROR) { + if ((response->report_id == REPORT_ID_HIDPP_LONG || + response->report_id == REPORT_ID_HIDPP_VERY_LONG) && + response->fap.feature_index == HIDPP20_ERROR) { ret = response->fap.params[1]; dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret); goto exit; @@ -243,7 +249,11 @@ static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp, message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL); if (!message) return -ENOMEM; - message->report_id = REPORT_ID_HIDPP_LONG; + + if (param_count > (HIDPP_REPORT_LONG_LENGTH - 4)) + message->report_id = REPORT_ID_HIDPP_VERY_LONG; + else + message->report_id = REPORT_ID_HIDPP_LONG; message->fap.feature_index = feat_index; message->fap.funcindex_clientid = funcindex_clientid; memcpy(&message->fap.params, params, param_count); @@ -258,13 +268,23 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev, struct hidpp_report *response) { struct hidpp_report *message; - int ret; + int ret, max_count; - if ((report_id != REPORT_ID_HIDPP_SHORT) && - (report_id != REPORT_ID_HIDPP_LONG)) + switch (report_id) { + case REPORT_ID_HIDPP_SHORT: + max_count = HIDPP_REPORT_SHORT_LENGTH - 4; + break; + case REPORT_ID_HIDPP_LONG: + max_count = HIDPP_REPORT_LONG_LENGTH - 4; + break; + case REPORT_ID_HIDPP_VERY_LONG: + max_count = HIDPP_REPORT_VERY_LONG_LENGTH - 4; + break; + default: return -EINVAL; + } - if (param_count > sizeof(message->rap.params)) + if (param_count > max_count) return -EINVAL; message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL); @@ -508,10 +528,19 @@ static int hidpp_devicenametype_get_device_name(struct hidpp_device *hidpp, if (ret) return ret; - if (response.report_id == REPORT_ID_HIDPP_LONG) + switch (response.report_id) { + case REPORT_ID_HIDPP_VERY_LONG: + count = HIDPP_REPORT_VERY_LONG_LENGTH - 4; + break; + case REPORT_ID_HIDPP_LONG: count = HIDPP_REPORT_LONG_LENGTH - 4; - else + break; + case REPORT_ID_HIDPP_SHORT: count = HIDPP_REPORT_SHORT_LENGTH - 4; + break; + default: + return -EPROTO; + } if (len_buf < count) count = len_buf; @@ -1347,6 +1376,14 @@ static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report, /* Generic HID++ processing. */ switch (data[0]) { + case REPORT_ID_HIDPP_VERY_LONG: + if (size != HIDPP_REPORT_VERY_LONG_LENGTH) { + hid_err(hdev, "received hid++ report of bad size (%d)", + size); + return 1; + } + ret = hidpp_raw_hidpp_event(hidpp, data, size); + break; case REPORT_ID_HIDPP_LONG: if (size != HIDPP_REPORT_LONG_LENGTH) { hid_err(hdev, "received hid++ report of bad size (%d)", -- cgit 1.4.1 From 7bfd2927adcacac2930a2709a9bcc1231e5bba1c Mon Sep 17 00:00:00 2001 From: Simon Wood Date: Thu, 19 Nov 2015 16:42:12 -0700 Subject: HID: hid-logitech-hidpp: Add basic support for Logitech G920 This patch adds basic support for the Logitech G920 wheel when in HID mode. This wheel 'speaks' the HID++ protocol, and therefor is driven with hid-logitech-hidpp. At this stage the driver only shows that it can communicate with the wheel by outputting the name discovered over HID++. The normal HID functions work to give input functionality using joystick/event interface. Note: in 'hidpp_probe()' we have to start the hardware to get packets flowing, the same might apply in future for other devices which don't use the unifying protocol. Signed-off-by: Simon Wood Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 1 + drivers/hid/hid-ids.h | 1 + drivers/hid/hid-logitech-hidpp.c | 71 +++++++++++++++++++++++++++++++--------- 3 files changed, 57 insertions(+), 16 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index c6f7a694f67a..190260c52adc 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1902,6 +1902,7 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G29_WHEEL) }, + { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL) }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_FFG ) }, { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) }, diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h index ac1feea51be3..269e758d450d 100644 --- a/drivers/hid/hid-ids.h +++ b/drivers/hid/hid-ids.h @@ -619,6 +619,7 @@ #define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2 0xc218 #define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2 0xc219 #define USB_DEVICE_ID_LOGITECH_G29_WHEEL 0xc24f +#define USB_DEVICE_ID_LOGITECH_G920_WHEEL 0xc262 #define USB_DEVICE_ID_LOGITECH_WINGMAN_F3D 0xc283 #define USB_DEVICE_ID_LOGITECH_FORCE3D_PRO 0xc286 #define USB_DEVICE_ID_LOGITECH_FLIGHT_SYSTEM_G940 0xc287 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 0f53dc8c79b1..98b8f096d7ee 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -49,11 +49,13 @@ MODULE_PARM_DESC(disable_tap_to_click, #define HIDPP_QUIRK_CLASS_WTP BIT(0) #define HIDPP_QUIRK_CLASS_M560 BIT(1) #define HIDPP_QUIRK_CLASS_K400 BIT(2) +#define HIDPP_QUIRK_CLASS_G920 BIT(3) /* bits 2..20 are reserved for classes */ #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22) #define HIDPP_QUIRK_NO_HIDINPUT BIT(23) +#define HIDPP_QUIRK_FORCE_OUTPUT_REPORTS BIT(24) #define HIDPP_QUIRK_DELAYED_INIT (HIDPP_QUIRK_NO_HIDINPUT | \ HIDPP_QUIRK_CONNECT_EVENTS) @@ -146,8 +148,11 @@ static void hidpp_connect_event(struct hidpp_device *hidpp_dev); static int __hidpp_send_report(struct hid_device *hdev, struct hidpp_report *hidpp_report) { + struct hidpp_device *hidpp = hid_get_drvdata(hdev); int fields_count, ret; + hidpp = hid_get_drvdata(hdev); + switch (hidpp_report->report_id) { case REPORT_ID_HIDPP_SHORT: fields_count = HIDPP_REPORT_SHORT_LENGTH; @@ -168,9 +173,13 @@ static int __hidpp_send_report(struct hid_device *hdev, */ hidpp_report->device_index = 0xff; - ret = hid_hw_raw_request(hdev, hidpp_report->report_id, - (u8 *)hidpp_report, fields_count, HID_OUTPUT_REPORT, - HID_REQ_SET_REPORT); + if (hidpp->quirks & HIDPP_QUIRK_FORCE_OUTPUT_REPORTS) { + ret = hid_hw_output_report(hdev, (u8 *)hidpp_report, fields_count); + } else { + ret = hid_hw_raw_request(hdev, hidpp_report->report_id, + (u8 *)hidpp_report, fields_count, HID_OUTPUT_REPORT, + HID_REQ_SET_REPORT); + } return ret == fields_count ? 0 : -1; } @@ -1430,10 +1439,12 @@ static void hidpp_overwrite_name(struct hid_device *hdev, bool use_unifying) else name = hidpp_get_device_name(hidpp); - if (!name) + if (!name) { hid_err(hdev, "unable to retrieve the name of the device"); - else + } else { + dbg_hid("HID++: Got name: %s\n", name); snprintf(hdev->name, sizeof(hdev->name), "%s", name); + } kfree(name); } @@ -1596,6 +1607,25 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) goto hid_parse_fail; } + if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) + connect_mask &= ~HID_CONNECT_HIDINPUT; + + if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + ret = hid_hw_start(hdev, connect_mask); + if (ret) { + hid_err(hdev, "hw start failed\n"); + goto hid_hw_start_fail; + } + ret = hid_hw_open(hdev); + if (ret < 0) { + dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n", + __func__, ret); + hid_hw_stop(hdev); + goto hid_hw_start_fail; + } + } + + /* Allow incoming packets */ hid_device_io_start(hdev); @@ -1604,8 +1634,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) if (!connected) { ret = -ENODEV; hid_err(hdev, "Device not connected"); - hid_device_io_stop(hdev); - goto hid_parse_fail; + goto hid_hw_open_failed; } hid_info(hdev, "HID++ %u.%u device connected.\n", @@ -1618,19 +1647,18 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { ret = wtp_get_config(hidpp); if (ret) - goto hid_parse_fail; + goto hid_hw_open_failed; } /* Block incoming packets */ hid_device_io_stop(hdev); - if (hidpp->quirks & HIDPP_QUIRK_NO_HIDINPUT) - connect_mask &= ~HID_CONNECT_HIDINPUT; - - ret = hid_hw_start(hdev, connect_mask); - if (ret) { - hid_err(hdev, "%s:hid_hw_start returned error\n", __func__); - goto hid_hw_start_fail; + if (!(hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { + ret = hid_hw_start(hdev, connect_mask); + if (ret) { + hid_err(hdev, "%s:hid_hw_start returned error\n", __func__); + goto hid_hw_start_fail; + } } if (hidpp->quirks & HIDPP_QUIRK_CONNECT_EVENTS) { @@ -1642,6 +1670,12 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; +hid_hw_open_failed: + hid_device_io_stop(hdev); + if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + hid_hw_close(hdev); + hid_hw_stop(hdev); + } hid_hw_start_fail: hid_parse_fail: cancel_work_sync(&hidpp->work); @@ -1655,9 +1689,11 @@ static void hidpp_remove(struct hid_device *hdev) { struct hidpp_device *hidpp = hid_get_drvdata(hdev); + if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) + hid_hw_close(hdev); + hid_hw_stop(hdev); cancel_work_sync(&hidpp->work); mutex_destroy(&hidpp->send_mutex); - hid_hw_stop(hdev); } static const struct hid_device_id hidpp_devices[] = { @@ -1685,6 +1721,9 @@ static const struct hid_device_id hidpp_devices[] = { { HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, USB_VENDOR_ID_LOGITECH, HID_ANY_ID)}, + + { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_G920_WHEEL), + .driver_data = HIDPP_QUIRK_CLASS_G920 | HIDPP_QUIRK_FORCE_OUTPUT_REPORTS}, {} }; -- cgit 1.4.1 From 7f4b49fef6ffb5021c01a915c21b3221fd521e81 Mon Sep 17 00:00:00 2001 From: Simon Wood Date: Thu, 19 Nov 2015 16:42:13 -0700 Subject: HID: hid-logitech-hidpp: Add range sysfs for Logitech G920 The G920 can adjust the amount of 'turn' it permits, this patch adds a sysfs file 'range' to control this. Signed-off-by: Simon Wood Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-logitech-hidpp.c | 140 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 98b8f096d7ee..fc553e3f948d 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1295,6 +1295,133 @@ static int k400_connect(struct hid_device *hdev, bool connected) return k400_disable_tap_to_click(hidpp); } +/* ------------------------------------------------------------------------- */ +/* Logitech G920 Driving Force Racing Wheel for Xbox One */ +/* ------------------------------------------------------------------------- */ + +#define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123 + +/* Using session ID = 1 */ +#define CMD_G920_FORCE_GET_APERTURE 0x51 +#define CMD_G920_FORCE_SET_APERTURE 0x61 + +struct g920_private_data { + u8 force_feature; + u16 range; +}; + +#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) + +static ssize_t g920_range_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct hid_device *hid = to_hid_device(dev); + struct hidpp_device *hidpp = hid_get_drvdata(hid); + struct g920_private_data *pdata; + + pdata = hidpp->private_data; + if (!pdata) { + hid_err(hid, "Private driver data not found!\n"); + return -EINVAL; + } + + return scnprintf(buf, PAGE_SIZE, "%u\n", pdata->range); +} + +static ssize_t g920_range_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hid = to_hid_device(dev); + struct hidpp_device *hidpp = hid_get_drvdata(hid); + struct g920_private_data *pdata; + struct hidpp_report response; + u8 params[2]; + int ret; + u16 range = simple_strtoul(buf, NULL, 10); + + pdata = hidpp->private_data; + if (!pdata) { + hid_err(hid, "Private driver data not found!\n"); + return -EINVAL; + } + + if (range < 180) + range = 180; + else if (range > 900) + range = 900; + + params[0] = range >> 8; + params[1] = range & 0x00FF; + + ret = hidpp_send_fap_command_sync(hidpp, pdata->force_feature, + CMD_G920_FORCE_SET_APERTURE, params, 2, &response); + if (ret) + return ret; + + pdata->range = range; + return count; +} + +static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, g920_range_show, g920_range_store); + +static int g920_allocate(struct hid_device *hdev) +{ + struct hidpp_device *hidpp = hid_get_drvdata(hdev); + struct g920_private_data *pdata; + + pdata = devm_kzalloc(&hdev->dev, sizeof(struct g920_private_data), + GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + hidpp->private_data = pdata; + + return 0; +} + +static int g920_get_config(struct hidpp_device *hidpp) +{ + struct g920_private_data *pdata = hidpp->private_data; + struct hidpp_report response; + u8 feature_type; + u8 feature_index; + int ret; + + pdata = hidpp->private_data; + if (!pdata) { + hid_err(hidpp->hid_dev, "Private driver data not found!\n"); + return -EINVAL; + } + + /* Find feature and store for later use */ + ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_G920_FORCE_FEEDBACK, + &feature_index, &feature_type); + if (ret) + return ret; + + pdata->force_feature = feature_index; + + /* Read current Range */ + ret = hidpp_send_fap_command_sync(hidpp, feature_index, + CMD_G920_FORCE_GET_APERTURE, NULL, 0, &response); + if (ret > 0) { + hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", + __func__, ret); + return -EPROTO; + } + if (ret) + return ret; + + pdata->range = get_unaligned_be16(&response.fap.params[0]); + + /* Create sysfs interface */ + ret = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range); + if (ret) + hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d\n", ret); + + return 0; +} + /* -------------------------------------------------------------------------- */ /* Generic HID++ devices */ /* -------------------------------------------------------------------------- */ @@ -1595,6 +1722,10 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) ret = k400_allocate(hdev); if (ret) goto allocate_fail; + } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + ret = g920_allocate(hdev); + if (ret) + goto allocate_fail; } INIT_WORK(&hidpp->work, delayed_work_cb); @@ -1648,6 +1779,10 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) ret = wtp_get_config(hidpp); if (ret) goto hid_hw_open_failed; + } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { + ret = g920_get_config(hidpp); + if (ret) + goto hid_hw_open_failed; } /* Block incoming packets */ @@ -1673,6 +1808,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hid_hw_open_failed: hid_device_io_stop(hdev); if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + device_remove_file(&hdev->dev, &dev_attr_range); hid_hw_close(hdev); hid_hw_stop(hdev); } @@ -1689,8 +1825,10 @@ static void hidpp_remove(struct hid_device *hdev) { struct hidpp_device *hidpp = hid_get_drvdata(hdev); - if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) + if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + device_remove_file(&hdev->dev, &dev_attr_range); hid_hw_close(hdev); + } hid_hw_stop(hdev); cancel_work_sync(&hidpp->work); mutex_destroy(&hidpp->send_mutex); -- cgit 1.4.1 From b466c1dd73d5303a313fb0c962e4eb5879bc1336 Mon Sep 17 00:00:00 2001 From: Simon Wood Date: Thu, 19 Nov 2015 16:42:14 -0700 Subject: HID: Add vendor specific usage pages for Logitech G920 The Logitech G920 uses a couple of vendor specific usage pages, which results in incorrect number of axis/buttons being detected. This patch adds these pages to the 'ignore' list. Reported-by: Elias Vanderstuyft Signed-off-by: Simon Wood Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-input.c | 4 ++++ include/linux/hid.h | 2 ++ 2 files changed, 6 insertions(+) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 2ba6bf69b7d0..f4eeb6bcb9ac 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -960,6 +960,10 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel goto ignore; case HID_UP_LOGIVENDOR: + /* intentional fallback */ + case HID_UP_LOGIVENDOR2: + /* intentional fallback */ + case HID_UP_LOGIVENDOR3: goto ignore; case HID_UP_PID: diff --git a/include/linux/hid.h b/include/linux/hid.h index 251a1d382e23..a6d7a3fc2cb3 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -168,6 +168,8 @@ struct hid_item { #define HID_UP_MSVENDOR 0xff000000 #define HID_UP_CUSTOM 0x00ff0000 #define HID_UP_LOGIVENDOR 0xffbc0000 +#define HID_UP_LOGIVENDOR2 0xff090000 +#define HID_UP_LOGIVENDOR3 0xff430000 #define HID_UP_LNVENDOR 0xffa00000 #define HID_UP_SENSOR 0x00200000 -- cgit 1.4.1 From 0b1804e3d6ee820303cd07fd5b9579db6110840b Mon Sep 17 00:00:00 2001 From: Simon Wood Date: Thu, 19 Nov 2015 16:42:15 -0700 Subject: HID: hid-logitech-hidpp: G920 remove deadzones Ensure that the G920 is not given the default deadzones. Signed-off-by: Simon Wood Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-logitech-hidpp.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index fc553e3f948d..f2a481125522 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1441,6 +1441,25 @@ static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi, return 0; } +static int hidpp_input_mapped(struct hid_device *hdev, struct hid_input *hi, + struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) +{ + struct hidpp_device *hidpp = hid_get_drvdata(hdev); + + /* Ensure that Logitech G920 is not given a default fuzz/flat value */ + if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + if (usage->type == EV_ABS && (usage->code == ABS_X || + usage->code == ABS_Y || usage->code == ABS_Z || + usage->code == ABS_RZ)) { + field->application = HID_GD_MULTIAXIS; + } + } + + return 0; +} + + static void hidpp_populate_input(struct hidpp_device *hidpp, struct input_dev *input, bool origin_is_hid_core) { @@ -1875,6 +1894,7 @@ static struct hid_driver hidpp_driver = { .raw_event = hidpp_raw_event, .input_configured = hidpp_input_configured, .input_mapping = hidpp_input_mapping, + .input_mapped = hidpp_input_mapped, }; module_hid_driver(hidpp_driver); -- cgit 1.4.1 From dfa0c5faf1b8964fa508373232b4cb597a5c226b Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Sat, 14 Nov 2015 22:08:08 +0100 Subject: HID: core: use scnprintf in modalias_show() scnprintf() exists to provide these semantics, so we might as well use it. Signed-off-by: Rasmus Villemoes Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index d5ddb7573691..3c1cfc6d9964 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2217,12 +2217,9 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a, char *buf) { struct hid_device *hdev = container_of(dev, struct hid_device, dev); - int len; - - len = snprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n", - hdev->bus, hdev->group, hdev->vendor, hdev->product); - return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; + return scnprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n", + hdev->bus, hdev->group, hdev->vendor, hdev->product); } static DEVICE_ATTR_RO(modalias); -- cgit 1.4.1 From cc8a9d79222c6b259ea9eceef21b94a5610616f0 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Thu, 5 Nov 2015 12:55:27 +0100 Subject: HID: usbhid: discarded events don't abort idleness If an event is discarded the device stays idle. Just reverse the order of check and marking busy. Found by code inspection. Signed-off-by: Oliver Neukum Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/hid-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 36712e9f56c2..19a4364c9085 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -274,10 +274,10 @@ static void hid_irq_in(struct urb *urb) switch (urb->status) { case 0: /* success */ - usbhid_mark_busy(usbhid); usbhid->retry_delay = 0; if ((hid->quirks & HID_QUIRK_ALWAYS_POLL) && !hid->open) break; + usbhid_mark_busy(usbhid); if (!test_bit(HID_RESUME_RUNNING, &usbhid->iofl)) { hid_input_report(urb->context, HID_INPUT_REPORT, urb->transfer_buffer, -- cgit 1.4.1 From 25a84db15b3f3a24d3ea7d2baf90693bcff34b0c Mon Sep 17 00:00:00 2001 From: Allen Hung Date: Fri, 20 Nov 2015 18:21:06 +0800 Subject: HID: multitouch: enable palm rejection if device implements confidence usage The usage Confidence is mandary to Windows Precision Touchpad devices. The appearance of this usage is checked in hidinput_connect but the quirk MT_QUIRK_VALID_IS_CONFIDENCE is not applied to device accordingly. Apply this quirk and also remove quirk MT_QUIRK_ALWAYS_VALID to enable palm rejection for the WIN 8 touchpad devices which have implemented usage Confidence in its input reports. Tested on Dell XPS 13 laptop. Signed-off-by: Allen Hung Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-multitouch.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 3d664d01305e..351ddd297792 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -486,6 +486,11 @@ 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_ALWAYS_VALID; + cls->quirks |= MT_QUIRK_VALID_IS_CONFIDENCE; + } mt_store_field(usage, td, hi); return 1; case HID_DG_TIPSWITCH: -- cgit 1.4.1 From 92529623d242cea4440958d7bcebdf291f4ab15e Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Tue, 24 Nov 2015 13:33:47 +0100 Subject: HID: debug: improve hid_debug_event() The code in hid_debug_event() causes horrible code generation. First, we do a strlen() call for every byte we copy (we're doing a store to global memory, so gcc has no way of proving that strlen(buf) doesn't change). Second, since both i, list->tail and HID_DEBUG_BUFSIZE have signed type, the modulo computation has to take into account the possibility that list->tail+i is negative, so it's not just a simple and. Fix the former by simply not doing strlen() at all (we have to load buf[i] anyway, so testing it is almost free) and the latter by changing i to unsigned. This cuts 29% (69 bytes) of the size of the function. Signed-off-by: Rasmus Villemoes Signed-off-by: Jiri Kosina --- drivers/hid/hid-debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c index 2886b645ced7..acfb522a432a 100644 --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -659,13 +659,13 @@ EXPORT_SYMBOL_GPL(hid_dump_device); /* enqueue string to 'events' ring buffer */ void hid_debug_event(struct hid_device *hdev, char *buf) { - int i; + unsigned i; struct hid_debug_list *list; unsigned long flags; spin_lock_irqsave(&hdev->debug_list_lock, flags); list_for_each_entry(list, &hdev->debug_list, node) { - for (i = 0; i < strlen(buf); i++) + for (i = 0; buf[i]; i++) list->hid_debug_buf[(list->tail + i) % HID_DEBUG_BUFSIZE] = buf[i]; list->tail = (list->tail + i) % HID_DEBUG_BUFSIZE; -- cgit 1.4.1 From e470127e9606b1fa151c4184243e61296d1e0c0f Mon Sep 17 00:00:00 2001 From: Ioan-Adrian Ratiu Date: Fri, 20 Nov 2015 22:19:02 +0200 Subject: HID: usbhid: fix recursive deadlock The critical section protected by usbhid->lock in hid_ctrl() is too big and because of this it causes a recursive deadlock. "Too big" means the case statement and the call to hid_input_report() do not need to be protected by the spinlock (no URB operations are done inside them). The deadlock happens because in certain rare cases drivers try to grab the lock while handling the ctrl irq which grabs the lock before them as described above. For example newer wacom tablets like 056a:033c try to reschedule proximity reads from wacom_intuos_schedule_prox_event() calling hid_hw_request() -> usbhid_request() -> usbhid_submit_report() which tries to grab the usbhid lock already held by hid_ctrl(). There are two ways to get out of this deadlock: 1. Make the drivers work "around" the ctrl critical region, in the wacom case for ex. by delaying the scheduling of the proximity read request itself to a workqueue. 2. Shrink the critical region so the usbhid lock protects only the instructions which modify usbhid state, calling hid_input_report() with the spinlock unlocked, allowing the device driver to grab the lock first, finish and then grab the lock afterwards in hid_ctrl(). This patch implements the 2nd solution. Signed-off-by: Ioan-Adrian Ratiu Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/hid-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 19a4364c9085..ad71160b9ea4 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -477,8 +477,6 @@ static void hid_ctrl(struct urb *urb) struct usbhid_device *usbhid = hid->driver_data; int unplug = 0, status = urb->status; - spin_lock(&usbhid->lock); - switch (status) { case 0: /* success */ if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN) @@ -498,6 +496,8 @@ static void hid_ctrl(struct urb *urb) hid_warn(urb->dev, "ctrl urb status %d received\n", status); } + spin_lock(&usbhid->lock); + if (unplug) { usbhid->ctrltail = usbhid->ctrlhead; } else { -- cgit 1.4.1 From 73e7d63efb4d774883a338997943bfa59e127085 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Tue, 1 Dec 2015 12:41:38 +0100 Subject: HID: multitouch: fix input mode switching on some Elan panels as reported by https://bugzilla.kernel.org/show_bug.cgi?id=108481 This bug reports mentions 6d4f5440 ("HID: multitouch: Fetch feature reports on demand for Win8 devices") as the origin of the problem but this commit actually masked 2 firmware bugs that are annihilating each other: The report descriptor declares two features in reports 3 and 5: 0x05, 0x0d, // Usage Page (Digitizers) 318 0x09, 0x0e, // Usage (Device Configuration) 320 0xa1, 0x01, // Collection (Application) 322 0x85, 0x03, // Report ID (3) 324 0x09, 0x22, // Usage (Finger) 326 0xa1, 0x00, // Collection (Physical) 328 0x09, 0x52, // Usage (Inputmode) 330 0x15, 0x00, // Logical Minimum (0) 332 0x25, 0x0a, // Logical Maximum (10) 334 0x75, 0x08, // Report Size (8) 336 0x95, 0x02, // Report Count (2) 338 0xb1, 0x02, // Feature (Data,Var,Abs) 340 0xc0, // End Collection 342 0x09, 0x22, // Usage (Finger) 343 0xa1, 0x00, // Collection (Physical) 345 0x85, 0x05, // Report ID (5) 347 0x09, 0x57, // Usage (Surface Switch) 349 0x09, 0x58, // Usage (Button Switch) 351 0x15, 0x00, // Logical Minimum (0) 353 0x75, 0x01, // Report Size (1) 355 0x95, 0x02, // Report Count (2) 357 0x25, 0x03, // Logical Maximum (3) 359 0xb1, 0x02, // Feature (Data,Var,Abs) 361 0x95, 0x0e, // Report Count (14) 363 0xb1, 0x03, // Feature (Cnst,Var,Abs) 365 0xc0, // End Collection 367 The report ID 3 presents 2 input mode features, while only the first one is handled by the device. Given that we did not checked if one was previously assigned, we were dealing with the ignored featured and we should never have been able to switch this panel into the multitouch mode. However, the firmware presents an other bugs which allowed 6d4f5440 to counteract the faulty report descriptor. When we request the values of the feature 5, the firmware answers "03 03 00". The fields are correct but the report id is wrong. Before 6d4f5440, we retrieved all the features and injected them in the system. So when we called report 5, we injected in the system the report 3 with the values "03 00". Setting the second input mode to 03 in this report changed it to "03 03" and the touchpad switched to the mt mode. We could have set anything in the second field because the actual value (the first 03 in this report) was given by the query of report ID 5. To sum up: 2 bugs in the firmware were hiding that we were accessing the wrong feature. Signed-off-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/hid-multitouch.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 351ddd297792..4ee771642090 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -357,8 +357,19 @@ 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: -- cgit 1.4.1 From fb013a01d48d71a68cd14ea30181754f93acae21 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 30 Nov 2015 17:13:46 -0800 Subject: HID: wacom: Move Intuos pad handling code into dedicated function Begin slimming down the body of 'wacom_intuos_irq' by moving out its largest block of code to a dedicated 'wacom_intuos_pad' function. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 482 +++++++++++++++++++++++++----------------------- 1 file changed, 247 insertions(+), 235 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 8b29949507d1..c611ea5b83c8 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -446,6 +446,249 @@ static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac) } } +static int wacom_intuos_pad(struct wacom_wac *wacom) +{ + struct wacom_features *features = &wacom->features; + unsigned char *data = wacom->data; + struct input_dev *input = wacom->pad_input; + + /* pad packets. Works as a second tool and is always in prox */ + if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD || + data[0] == WACOM_REPORT_CINTIQPAD)) + return 0; + + if (features->type >= INTUOS4S && features->type <= INTUOS4L) { + input_report_key(input, BTN_0, (data[2] & 0x01)); + input_report_key(input, BTN_1, (data[3] & 0x01)); + input_report_key(input, BTN_2, (data[3] & 0x02)); + input_report_key(input, BTN_3, (data[3] & 0x04)); + input_report_key(input, BTN_4, (data[3] & 0x08)); + input_report_key(input, BTN_5, (data[3] & 0x10)); + input_report_key(input, BTN_6, (data[3] & 0x20)); + if (data[1] & 0x80) { + input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f)); + } else { + /* Out of proximity, clear wheel value. */ + input_report_abs(input, ABS_WHEEL, 0); + } + if (features->type != INTUOS4S) { + input_report_key(input, BTN_7, (data[3] & 0x40)); + input_report_key(input, BTN_8, (data[3] & 0x80)); + } + if (data[1] | (data[2] & 0x01) | data[3]) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + } else if (features->type == DTK) { + input_report_key(input, BTN_0, (data[6] & 0x01)); + input_report_key(input, BTN_1, (data[6] & 0x02)); + input_report_key(input, BTN_2, (data[6] & 0x04)); + input_report_key(input, BTN_3, (data[6] & 0x08)); + input_report_key(input, BTN_4, (data[6] & 0x10)); + input_report_key(input, BTN_5, (data[6] & 0x20)); + if (data[6] & 0x3f) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + } else if (features->type == WACOM_13HD) { + input_report_key(input, BTN_0, (data[3] & 0x01)); + input_report_key(input, BTN_1, (data[4] & 0x01)); + input_report_key(input, BTN_2, (data[4] & 0x02)); + input_report_key(input, BTN_3, (data[4] & 0x04)); + input_report_key(input, BTN_4, (data[4] & 0x08)); + input_report_key(input, BTN_5, (data[4] & 0x10)); + input_report_key(input, BTN_6, (data[4] & 0x20)); + input_report_key(input, BTN_7, (data[4] & 0x40)); + input_report_key(input, BTN_8, (data[4] & 0x80)); + if ((data[3] & 0x01) | data[4]) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + } else if (features->type == WACOM_24HD) { + input_report_key(input, BTN_0, (data[6] & 0x01)); + input_report_key(input, BTN_1, (data[6] & 0x02)); + input_report_key(input, BTN_2, (data[6] & 0x04)); + input_report_key(input, BTN_3, (data[6] & 0x08)); + input_report_key(input, BTN_4, (data[6] & 0x10)); + input_report_key(input, BTN_5, (data[6] & 0x20)); + input_report_key(input, BTN_6, (data[6] & 0x40)); + input_report_key(input, BTN_7, (data[6] & 0x80)); + input_report_key(input, BTN_8, (data[8] & 0x01)); + input_report_key(input, BTN_9, (data[8] & 0x02)); + input_report_key(input, BTN_A, (data[8] & 0x04)); + input_report_key(input, BTN_B, (data[8] & 0x08)); + input_report_key(input, BTN_C, (data[8] & 0x10)); + input_report_key(input, BTN_X, (data[8] & 0x20)); + input_report_key(input, BTN_Y, (data[8] & 0x40)); + input_report_key(input, BTN_Z, (data[8] & 0x80)); + + /* + * Three "buttons" are available on the 24HD which are + * physically implemented as a touchstrip. Each button + * is approximately 3 bits wide with a 2 bit spacing. + * The raw touchstrip bits are stored at: + * ((data[3] & 0x1f) << 8) | data[4]) + */ + input_report_key(input, KEY_PROG1, data[4] & 0x07); + input_report_key(input, KEY_PROG2, data[4] & 0xE0); + input_report_key(input, KEY_PROG3, data[3] & 0x1C); + + if (data[1] & 0x80) { + input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f)); + } else { + /* Out of proximity, clear wheel value. */ + input_report_abs(input, ABS_WHEEL, 0); + } + + if (data[2] & 0x80) { + input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f)); + } else { + /* Out of proximity, clear second wheel value. */ + input_report_abs(input, ABS_THROTTLE, 0); + } + + if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + } else if (features->type == WACOM_27QHD) { + input_report_key(input, KEY_PROG1, data[2] & 0x01); + input_report_key(input, KEY_PROG2, data[2] & 0x02); + input_report_key(input, KEY_PROG3, data[2] & 0x04); + + input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4])); + input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6])); + input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8])); + if ((data[2] & 0x07) | data[4] | data[5] | data[6] | data[7] | data[8] | data[9]) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + } else if (features->type == CINTIQ_HYBRID) { + /* + * Do not send hardware buttons under Android. They + * are already sent to the system through GPIO (and + * have different meaning). + */ + input_report_key(input, BTN_1, (data[4] & 0x01)); + input_report_key(input, BTN_2, (data[4] & 0x02)); + input_report_key(input, BTN_3, (data[4] & 0x04)); + input_report_key(input, BTN_4, (data[4] & 0x08)); + + input_report_key(input, BTN_5, (data[4] & 0x10)); /* Right */ + input_report_key(input, BTN_6, (data[4] & 0x20)); /* Up */ + input_report_key(input, BTN_7, (data[4] & 0x40)); /* Left */ + input_report_key(input, BTN_8, (data[4] & 0x80)); /* Down */ + input_report_key(input, BTN_0, (data[3] & 0x01)); /* Center */ + + if (data[4] | (data[3] & 0x01)) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + + } else if (features->type == CINTIQ_COMPANION_2) { + input_report_key(input, BTN_1, (data[1] & 0x02)); + input_report_key(input, BTN_2, (data[2] & 0x01)); + input_report_key(input, BTN_3, (data[2] & 0x02)); + input_report_key(input, BTN_4, (data[2] & 0x04)); + input_report_key(input, BTN_5, (data[2] & 0x08)); + input_report_key(input, BTN_6, (data[1] & 0x04)); + + input_report_key(input, BTN_7, (data[2] & 0x10)); /* Right */ + input_report_key(input, BTN_8, (data[2] & 0x20)); /* Up */ + input_report_key(input, BTN_9, (data[2] & 0x40)); /* Left */ + input_report_key(input, BTN_A, (data[2] & 0x80)); /* Down */ + input_report_key(input, BTN_0, (data[1] & 0x01)); /* Center */ + + if (data[2] | (data[1] & 0x07)) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + + } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) { + int i; + + /* Touch ring mode switch has no capacitive sensor */ + input_report_key(input, BTN_0, (data[3] & 0x01)); + + /* + * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in + * addition to the mechanical switch. Switch data is + * stored in data[4], capacitive data in data[5]. + */ + for (i = 0; i < 8; i++) + input_report_key(input, BTN_1 + i, data[4] & (1 << i)); + + if (data[2] & 0x80) { + input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f)); + } else { + /* Out of proximity, clear wheel value. */ + input_report_abs(input, ABS_WHEEL, 0); + } + + if (data[2] | (data[3] & 0x01) | data[4] | data[5]) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + } else { + if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) { + input_report_key(input, BTN_0, (data[5] & 0x01)); + input_report_key(input, BTN_1, (data[6] & 0x01)); + input_report_key(input, BTN_2, (data[6] & 0x02)); + input_report_key(input, BTN_3, (data[6] & 0x04)); + input_report_key(input, BTN_4, (data[6] & 0x08)); + input_report_key(input, BTN_5, (data[6] & 0x10)); + input_report_key(input, BTN_6, (data[6] & 0x20)); + input_report_key(input, BTN_7, (data[6] & 0x40)); + input_report_key(input, BTN_8, (data[6] & 0x80)); + input_report_key(input, BTN_9, (data[7] & 0x01)); + input_report_key(input, BTN_A, (data[8] & 0x01)); + input_report_key(input, BTN_B, (data[8] & 0x02)); + input_report_key(input, BTN_C, (data[8] & 0x04)); + input_report_key(input, BTN_X, (data[8] & 0x08)); + input_report_key(input, BTN_Y, (data[8] & 0x10)); + input_report_key(input, BTN_Z, (data[8] & 0x20)); + input_report_key(input, BTN_BASE, (data[8] & 0x40)); + input_report_key(input, BTN_BASE2, (data[8] & 0x80)); + + if (features->type == WACOM_22HD) { + input_report_key(input, KEY_PROG1, data[9] & 0x01); + input_report_key(input, KEY_PROG2, data[9] & 0x02); + input_report_key(input, KEY_PROG3, data[9] & 0x04); + } + } else { + input_report_key(input, BTN_0, (data[5] & 0x01)); + input_report_key(input, BTN_1, (data[5] & 0x02)); + input_report_key(input, BTN_2, (data[5] & 0x04)); + input_report_key(input, BTN_3, (data[5] & 0x08)); + input_report_key(input, BTN_4, (data[6] & 0x01)); + input_report_key(input, BTN_5, (data[6] & 0x02)); + input_report_key(input, BTN_6, (data[6] & 0x04)); + input_report_key(input, BTN_7, (data[6] & 0x08)); + input_report_key(input, BTN_8, (data[5] & 0x10)); + input_report_key(input, BTN_9, (data[6] & 0x10)); + } + input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]); + input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]); + + if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) | + data[2] | (data[3] & 0x1f) | data[4] | data[8] | + (data[7] & 0x01)) { + input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); + } else { + input_report_abs(input, ABS_MISC, 0); + } + } + return 1; +} + static int wacom_intuos_inout(struct wacom_wac *wacom) { struct wacom_features *features = &wacom->features; @@ -814,241 +1057,10 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) if (features->type == INTUOS) idx = data[1] & 0x01; - /* pad packets. Works as a second tool and is always in prox */ - if (data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD || - data[0] == WACOM_REPORT_CINTIQPAD) { - input = wacom->pad_input; - if (features->type >= INTUOS4S && features->type <= INTUOS4L) { - input_report_key(input, BTN_0, (data[2] & 0x01)); - input_report_key(input, BTN_1, (data[3] & 0x01)); - input_report_key(input, BTN_2, (data[3] & 0x02)); - input_report_key(input, BTN_3, (data[3] & 0x04)); - input_report_key(input, BTN_4, (data[3] & 0x08)); - input_report_key(input, BTN_5, (data[3] & 0x10)); - input_report_key(input, BTN_6, (data[3] & 0x20)); - if (data[1] & 0x80) { - input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f)); - } else { - /* Out of proximity, clear wheel value. */ - input_report_abs(input, ABS_WHEEL, 0); - } - if (features->type != INTUOS4S) { - input_report_key(input, BTN_7, (data[3] & 0x40)); - input_report_key(input, BTN_8, (data[3] & 0x80)); - } - if (data[1] | (data[2] & 0x01) | data[3]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - } else if (features->type == DTK) { - input_report_key(input, BTN_0, (data[6] & 0x01)); - input_report_key(input, BTN_1, (data[6] & 0x02)); - input_report_key(input, BTN_2, (data[6] & 0x04)); - input_report_key(input, BTN_3, (data[6] & 0x08)); - input_report_key(input, BTN_4, (data[6] & 0x10)); - input_report_key(input, BTN_5, (data[6] & 0x20)); - if (data[6] & 0x3f) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - } else if (features->type == WACOM_13HD) { - input_report_key(input, BTN_0, (data[3] & 0x01)); - input_report_key(input, BTN_1, (data[4] & 0x01)); - input_report_key(input, BTN_2, (data[4] & 0x02)); - input_report_key(input, BTN_3, (data[4] & 0x04)); - input_report_key(input, BTN_4, (data[4] & 0x08)); - input_report_key(input, BTN_5, (data[4] & 0x10)); - input_report_key(input, BTN_6, (data[4] & 0x20)); - input_report_key(input, BTN_7, (data[4] & 0x40)); - input_report_key(input, BTN_8, (data[4] & 0x80)); - if ((data[3] & 0x01) | data[4]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - } else if (features->type == WACOM_24HD) { - input_report_key(input, BTN_0, (data[6] & 0x01)); - input_report_key(input, BTN_1, (data[6] & 0x02)); - input_report_key(input, BTN_2, (data[6] & 0x04)); - input_report_key(input, BTN_3, (data[6] & 0x08)); - input_report_key(input, BTN_4, (data[6] & 0x10)); - input_report_key(input, BTN_5, (data[6] & 0x20)); - input_report_key(input, BTN_6, (data[6] & 0x40)); - input_report_key(input, BTN_7, (data[6] & 0x80)); - input_report_key(input, BTN_8, (data[8] & 0x01)); - input_report_key(input, BTN_9, (data[8] & 0x02)); - input_report_key(input, BTN_A, (data[8] & 0x04)); - input_report_key(input, BTN_B, (data[8] & 0x08)); - input_report_key(input, BTN_C, (data[8] & 0x10)); - input_report_key(input, BTN_X, (data[8] & 0x20)); - input_report_key(input, BTN_Y, (data[8] & 0x40)); - input_report_key(input, BTN_Z, (data[8] & 0x80)); - - /* - * Three "buttons" are available on the 24HD which are - * physically implemented as a touchstrip. Each button - * is approximately 3 bits wide with a 2 bit spacing. - * The raw touchstrip bits are stored at: - * ((data[3] & 0x1f) << 8) | data[4]) - */ - input_report_key(input, KEY_PROG1, data[4] & 0x07); - input_report_key(input, KEY_PROG2, data[4] & 0xE0); - input_report_key(input, KEY_PROG3, data[3] & 0x1C); - - if (data[1] & 0x80) { - input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f)); - } else { - /* Out of proximity, clear wheel value. */ - input_report_abs(input, ABS_WHEEL, 0); - } - - if (data[2] & 0x80) { - input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f)); - } else { - /* Out of proximity, clear second wheel value. */ - input_report_abs(input, ABS_THROTTLE, 0); - } - - if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - } else if (features->type == WACOM_27QHD) { - input_report_key(input, KEY_PROG1, data[2] & 0x01); - input_report_key(input, KEY_PROG2, data[2] & 0x02); - input_report_key(input, KEY_PROG3, data[2] & 0x04); - - input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4])); - input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6])); - input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8])); - if ((data[2] & 0x07) | data[4] | data[5] | data[6] | data[7] | data[8] | data[9]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - } else if (features->type == CINTIQ_HYBRID) { - /* - * Do not send hardware buttons under Android. They - * are already sent to the system through GPIO (and - * have different meaning). - */ - input_report_key(input, BTN_1, (data[4] & 0x01)); - input_report_key(input, BTN_2, (data[4] & 0x02)); - input_report_key(input, BTN_3, (data[4] & 0x04)); - input_report_key(input, BTN_4, (data[4] & 0x08)); - - input_report_key(input, BTN_5, (data[4] & 0x10)); /* Right */ - input_report_key(input, BTN_6, (data[4] & 0x20)); /* Up */ - input_report_key(input, BTN_7, (data[4] & 0x40)); /* Left */ - input_report_key(input, BTN_8, (data[4] & 0x80)); /* Down */ - input_report_key(input, BTN_0, (data[3] & 0x01)); /* Center */ - - if (data[4] | (data[3] & 0x01)) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - - } else if (features->type == CINTIQ_COMPANION_2) { - input_report_key(input, BTN_1, (data[1] & 0x02)); - input_report_key(input, BTN_2, (data[2] & 0x01)); - input_report_key(input, BTN_3, (data[2] & 0x02)); - input_report_key(input, BTN_4, (data[2] & 0x04)); - input_report_key(input, BTN_5, (data[2] & 0x08)); - input_report_key(input, BTN_6, (data[1] & 0x04)); - - input_report_key(input, BTN_7, (data[2] & 0x10)); /* Right */ - input_report_key(input, BTN_8, (data[2] & 0x20)); /* Up */ - input_report_key(input, BTN_9, (data[2] & 0x40)); /* Left */ - input_report_key(input, BTN_A, (data[2] & 0x80)); /* Down */ - input_report_key(input, BTN_0, (data[1] & 0x01)); /* Center */ - - if (data[2] | (data[1] & 0x07)) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - - } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) { - int i; - - /* Touch ring mode switch has no capacitive sensor */ - input_report_key(input, BTN_0, (data[3] & 0x01)); - - /* - * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in - * addition to the mechanical switch. Switch data is - * stored in data[4], capacitive data in data[5]. - */ - for (i = 0; i < 8; i++) - input_report_key(input, BTN_1 + i, data[4] & (1 << i)); - - if (data[2] & 0x80) { - input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f)); - } else { - /* Out of proximity, clear wheel value. */ - input_report_abs(input, ABS_WHEEL, 0); - } - - if (data[2] | (data[3] & 0x01) | data[4] | data[5]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - } else { - if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) { - input_report_key(input, BTN_0, (data[5] & 0x01)); - input_report_key(input, BTN_1, (data[6] & 0x01)); - input_report_key(input, BTN_2, (data[6] & 0x02)); - input_report_key(input, BTN_3, (data[6] & 0x04)); - input_report_key(input, BTN_4, (data[6] & 0x08)); - input_report_key(input, BTN_5, (data[6] & 0x10)); - input_report_key(input, BTN_6, (data[6] & 0x20)); - input_report_key(input, BTN_7, (data[6] & 0x40)); - input_report_key(input, BTN_8, (data[6] & 0x80)); - input_report_key(input, BTN_9, (data[7] & 0x01)); - input_report_key(input, BTN_A, (data[8] & 0x01)); - input_report_key(input, BTN_B, (data[8] & 0x02)); - input_report_key(input, BTN_C, (data[8] & 0x04)); - input_report_key(input, BTN_X, (data[8] & 0x08)); - input_report_key(input, BTN_Y, (data[8] & 0x10)); - input_report_key(input, BTN_Z, (data[8] & 0x20)); - input_report_key(input, BTN_BASE, (data[8] & 0x40)); - input_report_key(input, BTN_BASE2, (data[8] & 0x80)); - - if (features->type == WACOM_22HD) { - input_report_key(input, KEY_PROG1, data[9] & 0x01); - input_report_key(input, KEY_PROG2, data[9] & 0x02); - input_report_key(input, KEY_PROG3, data[9] & 0x04); - } - } else { - input_report_key(input, BTN_0, (data[5] & 0x01)); - input_report_key(input, BTN_1, (data[5] & 0x02)); - input_report_key(input, BTN_2, (data[5] & 0x04)); - input_report_key(input, BTN_3, (data[5] & 0x08)); - input_report_key(input, BTN_4, (data[6] & 0x01)); - input_report_key(input, BTN_5, (data[6] & 0x02)); - input_report_key(input, BTN_6, (data[6] & 0x04)); - input_report_key(input, BTN_7, (data[6] & 0x08)); - input_report_key(input, BTN_8, (data[5] & 0x10)); - input_report_key(input, BTN_9, (data[6] & 0x10)); - } - input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]); - input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]); - - if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) | - data[2] | (data[3] & 0x1f) | data[4] | data[8] | - (data[7] & 0x01)) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - } - return 1; - } + /* process pad events */ + result = wacom_intuos_pad(wacom); + if (result) + return result; /* process in/out prox events */ result = wacom_intuos_inout(wacom); -- cgit 1.4.1 From c7f0522a1ad1c2a1a23872c96955d60890f453e4 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 30 Nov 2015 17:13:47 -0800 Subject: HID: wacom: Slim down wacom_intuos_pad processing Seperate the function into two halves: first gather data from the packet, next report all gathered data. The input subsystem should automatically mute any events that aren't actually declared for the tablet at hand. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 277 +++++++++++++++--------------------------------- 1 file changed, 86 insertions(+), 191 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index c611ea5b83c8..ec1e13e55ae9 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -34,6 +34,9 @@ */ #define WACOM_CONTACT_AREA_SCALE 2607 +static void wacom_report_numbered_buttons(struct input_dev *input_dev, + int button_count, int mask); + /* * Percent of battery capacity for Graphire. * 8th value means AC online and show 100% capacity. @@ -451,6 +454,12 @@ static int wacom_intuos_pad(struct wacom_wac *wacom) struct wacom_features *features = &wacom->features; unsigned char *data = wacom->data; struct input_dev *input = wacom->pad_input; + int i; + int buttons = 0, nbuttons = features->numbered_buttons; + int keys = 0, nkeys = 0; + int ring1 = 0, ring2 = 0; + int strip1 = 0, strip2 = 0; + bool prox = false; /* pad packets. Works as a second tool and is always in prox */ if (!(data[0] == WACOM_REPORT_INTUOSPAD || data[0] == WACOM_REPORT_INTUOS5PAD || @@ -458,72 +467,16 @@ static int wacom_intuos_pad(struct wacom_wac *wacom) return 0; if (features->type >= INTUOS4S && features->type <= INTUOS4L) { - input_report_key(input, BTN_0, (data[2] & 0x01)); - input_report_key(input, BTN_1, (data[3] & 0x01)); - input_report_key(input, BTN_2, (data[3] & 0x02)); - input_report_key(input, BTN_3, (data[3] & 0x04)); - input_report_key(input, BTN_4, (data[3] & 0x08)); - input_report_key(input, BTN_5, (data[3] & 0x10)); - input_report_key(input, BTN_6, (data[3] & 0x20)); - if (data[1] & 0x80) { - input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f)); - } else { - /* Out of proximity, clear wheel value. */ - input_report_abs(input, ABS_WHEEL, 0); - } - if (features->type != INTUOS4S) { - input_report_key(input, BTN_7, (data[3] & 0x40)); - input_report_key(input, BTN_8, (data[3] & 0x80)); - } - if (data[1] | (data[2] & 0x01) | data[3]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } + buttons = (data[3] << 1) | (data[2] & 0x01); + ring1 = data[1]; } else if (features->type == DTK) { - input_report_key(input, BTN_0, (data[6] & 0x01)); - input_report_key(input, BTN_1, (data[6] & 0x02)); - input_report_key(input, BTN_2, (data[6] & 0x04)); - input_report_key(input, BTN_3, (data[6] & 0x08)); - input_report_key(input, BTN_4, (data[6] & 0x10)); - input_report_key(input, BTN_5, (data[6] & 0x20)); - if (data[6] & 0x3f) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } + buttons = data[6]; } else if (features->type == WACOM_13HD) { - input_report_key(input, BTN_0, (data[3] & 0x01)); - input_report_key(input, BTN_1, (data[4] & 0x01)); - input_report_key(input, BTN_2, (data[4] & 0x02)); - input_report_key(input, BTN_3, (data[4] & 0x04)); - input_report_key(input, BTN_4, (data[4] & 0x08)); - input_report_key(input, BTN_5, (data[4] & 0x10)); - input_report_key(input, BTN_6, (data[4] & 0x20)); - input_report_key(input, BTN_7, (data[4] & 0x40)); - input_report_key(input, BTN_8, (data[4] & 0x80)); - if ((data[3] & 0x01) | data[4]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } + buttons = (data[4] << 1) | (data[3] & 0x01); } else if (features->type == WACOM_24HD) { - input_report_key(input, BTN_0, (data[6] & 0x01)); - input_report_key(input, BTN_1, (data[6] & 0x02)); - input_report_key(input, BTN_2, (data[6] & 0x04)); - input_report_key(input, BTN_3, (data[6] & 0x08)); - input_report_key(input, BTN_4, (data[6] & 0x10)); - input_report_key(input, BTN_5, (data[6] & 0x20)); - input_report_key(input, BTN_6, (data[6] & 0x40)); - input_report_key(input, BTN_7, (data[6] & 0x80)); - input_report_key(input, BTN_8, (data[8] & 0x01)); - input_report_key(input, BTN_9, (data[8] & 0x02)); - input_report_key(input, BTN_A, (data[8] & 0x04)); - input_report_key(input, BTN_B, (data[8] & 0x08)); - input_report_key(input, BTN_C, (data[8] & 0x10)); - input_report_key(input, BTN_X, (data[8] & 0x20)); - input_report_key(input, BTN_Y, (data[8] & 0x40)); - input_report_key(input, BTN_Z, (data[8] & 0x80)); + buttons = (data[8] << 8) | data[6]; + ring1 = data[1]; + ring2 = data[2]; /* * Three "buttons" are available on the 24HD which are @@ -532,160 +485,89 @@ static int wacom_intuos_pad(struct wacom_wac *wacom) * The raw touchstrip bits are stored at: * ((data[3] & 0x1f) << 8) | data[4]) */ - input_report_key(input, KEY_PROG1, data[4] & 0x07); - input_report_key(input, KEY_PROG2, data[4] & 0xE0); - input_report_key(input, KEY_PROG3, data[3] & 0x1C); - - if (data[1] & 0x80) { - input_report_abs(input, ABS_WHEEL, (data[1] & 0x7f)); - } else { - /* Out of proximity, clear wheel value. */ - input_report_abs(input, ABS_WHEEL, 0); - } - - if (data[2] & 0x80) { - input_report_abs(input, ABS_THROTTLE, (data[2] & 0x7f)); - } else { - /* Out of proximity, clear second wheel value. */ - input_report_abs(input, ABS_THROTTLE, 0); - } - - if (data[1] | data[2] | (data[3] & 0x1f) | data[4] | data[6] | data[8]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } + nkeys = 3; + keys = ((data[3] & 0x1C) ? 1<<2 : 0) | + ((data[4] & 0xE0) ? 1<<1 : 0) | + ((data[4] & 0x07) ? 1<<0 : 0); } else if (features->type == WACOM_27QHD) { - input_report_key(input, KEY_PROG1, data[2] & 0x01); - input_report_key(input, KEY_PROG2, data[2] & 0x02); - input_report_key(input, KEY_PROG3, data[2] & 0x04); + nkeys = 3; + keys = data[2] & 0x07; input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[4])); input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[6])); input_report_abs(input, ABS_Z, be16_to_cpup((__be16 *)&data[8])); - if ((data[2] & 0x07) | data[4] | data[5] | data[6] | data[7] | data[8] | data[9]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } } else if (features->type == CINTIQ_HYBRID) { /* * Do not send hardware buttons under Android. They * are already sent to the system through GPIO (and * have different meaning). + * + * d-pad right -> data[4] & 0x10 + * d-pad up -> data[4] & 0x20 + * d-pad left -> data[4] & 0x40 + * d-pad down -> data[4] & 0x80 + * d-pad center -> data[3] & 0x01 */ - input_report_key(input, BTN_1, (data[4] & 0x01)); - input_report_key(input, BTN_2, (data[4] & 0x02)); - input_report_key(input, BTN_3, (data[4] & 0x04)); - input_report_key(input, BTN_4, (data[4] & 0x08)); - - input_report_key(input, BTN_5, (data[4] & 0x10)); /* Right */ - input_report_key(input, BTN_6, (data[4] & 0x20)); /* Up */ - input_report_key(input, BTN_7, (data[4] & 0x40)); /* Left */ - input_report_key(input, BTN_8, (data[4] & 0x80)); /* Down */ - input_report_key(input, BTN_0, (data[3] & 0x01)); /* Center */ - - if (data[4] | (data[3] & 0x01)) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - + buttons = (data[4] << 1) | (data[3] & 0x01); } else if (features->type == CINTIQ_COMPANION_2) { - input_report_key(input, BTN_1, (data[1] & 0x02)); - input_report_key(input, BTN_2, (data[2] & 0x01)); - input_report_key(input, BTN_3, (data[2] & 0x02)); - input_report_key(input, BTN_4, (data[2] & 0x04)); - input_report_key(input, BTN_5, (data[2] & 0x08)); - input_report_key(input, BTN_6, (data[1] & 0x04)); - - input_report_key(input, BTN_7, (data[2] & 0x10)); /* Right */ - input_report_key(input, BTN_8, (data[2] & 0x20)); /* Up */ - input_report_key(input, BTN_9, (data[2] & 0x40)); /* Left */ - input_report_key(input, BTN_A, (data[2] & 0x80)); /* Down */ - input_report_key(input, BTN_0, (data[1] & 0x01)); /* Center */ - - if (data[2] | (data[1] & 0x07)) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } - + /* d-pad right -> data[4] & 0x10 + * d-pad up -> data[4] & 0x20 + * d-pad left -> data[4] & 0x40 + * d-pad down -> data[4] & 0x80 + * d-pad center -> data[3] & 0x01 + */ + buttons = ((data[2] & 0xF0) << 7) | + ((data[1] & 0x04) << 6) | + ((data[2] & 0x0F) << 2) | + (data[1] & 0x03); } else if (features->type >= INTUOS5S && features->type <= INTUOSPL) { - int i; - - /* Touch ring mode switch has no capacitive sensor */ - input_report_key(input, BTN_0, (data[3] & 0x01)); - /* * ExpressKeys on Intuos5/Intuos Pro have a capacitive sensor in * addition to the mechanical switch. Switch data is * stored in data[4], capacitive data in data[5]. + * + * Touch ring mode switch (data[3]) has no capacitive sensor */ - for (i = 0; i < 8; i++) - input_report_key(input, BTN_1 + i, data[4] & (1 << i)); - - if (data[2] & 0x80) { - input_report_abs(input, ABS_WHEEL, (data[2] & 0x7f)); - } else { - /* Out of proximity, clear wheel value. */ - input_report_abs(input, ABS_WHEEL, 0); - } - - if (data[2] | (data[3] & 0x01) | data[4] | data[5]) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); - } + buttons = (data[4] << 1) | (data[3] & 0x01); + ring1 = data[2]; } else { if (features->type == WACOM_21UX2 || features->type == WACOM_22HD) { - input_report_key(input, BTN_0, (data[5] & 0x01)); - input_report_key(input, BTN_1, (data[6] & 0x01)); - input_report_key(input, BTN_2, (data[6] & 0x02)); - input_report_key(input, BTN_3, (data[6] & 0x04)); - input_report_key(input, BTN_4, (data[6] & 0x08)); - input_report_key(input, BTN_5, (data[6] & 0x10)); - input_report_key(input, BTN_6, (data[6] & 0x20)); - input_report_key(input, BTN_7, (data[6] & 0x40)); - input_report_key(input, BTN_8, (data[6] & 0x80)); - input_report_key(input, BTN_9, (data[7] & 0x01)); - input_report_key(input, BTN_A, (data[8] & 0x01)); - input_report_key(input, BTN_B, (data[8] & 0x02)); - input_report_key(input, BTN_C, (data[8] & 0x04)); - input_report_key(input, BTN_X, (data[8] & 0x08)); - input_report_key(input, BTN_Y, (data[8] & 0x10)); - input_report_key(input, BTN_Z, (data[8] & 0x20)); - input_report_key(input, BTN_BASE, (data[8] & 0x40)); - input_report_key(input, BTN_BASE2, (data[8] & 0x80)); + buttons = (data[8] << 10) | ((data[7] & 0x01) << 9) | + (data[6] << 1) | (data[5] & 0x01); if (features->type == WACOM_22HD) { - input_report_key(input, KEY_PROG1, data[9] & 0x01); - input_report_key(input, KEY_PROG2, data[9] & 0x02); - input_report_key(input, KEY_PROG3, data[9] & 0x04); + nkeys = 3; + keys = data[9] & 0x07; } } else { - input_report_key(input, BTN_0, (data[5] & 0x01)); - input_report_key(input, BTN_1, (data[5] & 0x02)); - input_report_key(input, BTN_2, (data[5] & 0x04)); - input_report_key(input, BTN_3, (data[5] & 0x08)); - input_report_key(input, BTN_4, (data[6] & 0x01)); - input_report_key(input, BTN_5, (data[6] & 0x02)); - input_report_key(input, BTN_6, (data[6] & 0x04)); - input_report_key(input, BTN_7, (data[6] & 0x08)); - input_report_key(input, BTN_8, (data[5] & 0x10)); - input_report_key(input, BTN_9, (data[6] & 0x10)); - } - input_report_abs(input, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]); - input_report_abs(input, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]); - - if ((data[5] & 0x1f) | data[6] | (data[1] & 0x1f) | - data[2] | (data[3] & 0x1f) | data[4] | data[8] | - (data[7] & 0x01)) { - input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); - } else { - input_report_abs(input, ABS_MISC, 0); + buttons = ((data[6] & 0x10) << 10) | + ((data[5] & 0x10) << 9) | + ((data[6] & 0x0F) << 4) | + (data[5] & 0x0F); } + strip1 = (data[1] << 8) || data[2]; + strip2 = (data[3] << 8) || data[4]; } + + prox = (buttons & ~(~0 << nbuttons)) || (keys & ~(~0 << nkeys)) || + (ring1 & 0x80) || (ring2 & 0x80) || strip1 || strip2; + + wacom_report_numbered_buttons(input, nbuttons, buttons); + + for (i = 0; i < nkeys; i++) + input_report_key(input, KEY_PROG1 + i, keys & (1 << i)); + + input_report_abs(input, ABS_RX, strip1); + input_report_abs(input, ABS_RX, strip2); + + input_report_abs(input, ABS_WHEEL, ring1 & 0x7f ? ring1 : 0); + input_report_abs(input, ABS_THROTTLE, ring2 & 0x07 ? ring2 : 0); + + input_report_key(input, wacom->tool[1], prox ? 1 : 0); + input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0); + + input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff); + return 1; } @@ -2818,6 +2700,19 @@ static void wacom_setup_numbered_buttons(struct input_dev *input_dev, __set_bit(BTN_BASE + (i-16), input_dev->keybit); } +static void wacom_report_numbered_buttons(struct input_dev *input_dev, + int button_count, int mask) +{ + int i; + + for (i = 0; i < button_count && i < 10; i++) + input_report_key(input_dev, BTN_0 + i, mask & (1 << i)); + for (i = 10; i < button_count && i < 16; i++) + input_report_key(input_dev, BTN_A + (i-10), mask & (1 << i)); + for (i = 16; i < button_count && i < 18; i++) + input_report_key(input_dev, BTN_BASE + (i-16), mask & (1 << i)); +} + int wacom_setup_pad_input_capabilities(struct input_dev *input_dev, struct wacom_wac *wacom_wac) { -- cgit 1.4.1 From 16e0a6a0d27f01c47e3685a2a5e6dd2a5b0a525f Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 30 Nov 2015 17:13:48 -0800 Subject: HID: wacom: Centralize Intuos pen packet decoding Continue to slim down 'wacom_intuos_irq' by moving all decoding and reporting of pen packet data into the 'wacom_intuos_general' function. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 105 +++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 51 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index ec1e13e55ae9..e39568837b58 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -880,13 +880,28 @@ static int wacom_remote_status_irq(struct wacom_wac *wacom_wac, size_t len) return 0; } -static void wacom_intuos_general(struct wacom_wac *wacom) +static int wacom_intuos_general(struct wacom_wac *wacom) { struct wacom_features *features = &wacom->features; unsigned char *data = wacom->data; struct input_dev *input = wacom->pen_input; + int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0; unsigned int t; + if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ && + data[0] != WACOM_REPORT_INTUOS_PEN) + return 0; + + if (features->type >= INTUOS3S) { + input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); + input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); + input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); + } else { + input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2])); + input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4])); + input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); + } + /* general pen packet */ if ((data[1] & 0xb8) == 0xa0) { t = (data[6] << 2) | ((data[7] >> 6) & 3); @@ -912,55 +927,6 @@ static void wacom_intuos_general(struct wacom_wac *wacom) (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64); input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64); } -} - -static int wacom_intuos_irq(struct wacom_wac *wacom) -{ - struct wacom_features *features = &wacom->features; - unsigned char *data = wacom->data; - struct input_dev *input = wacom->pen_input; - unsigned int t; - int idx = 0, result; - - if (data[0] != WACOM_REPORT_PENABLED && - data[0] != WACOM_REPORT_INTUOSREAD && - data[0] != WACOM_REPORT_INTUOSWRITE && - data[0] != WACOM_REPORT_INTUOSPAD && - data[0] != WACOM_REPORT_INTUOS_PEN && - data[0] != WACOM_REPORT_CINTIQ && - data[0] != WACOM_REPORT_CINTIQPAD && - data[0] != WACOM_REPORT_INTUOS5PAD) { - dev_dbg(input->dev.parent, - "%s: received unknown report #%d\n", __func__, data[0]); - return 0; - } - - /* tool number */ - if (features->type == INTUOS) - idx = data[1] & 0x01; - - /* process pad events */ - result = wacom_intuos_pad(wacom); - if (result) - return result; - - /* process in/out prox events */ - result = wacom_intuos_inout(wacom); - if (result) - return result - 1; - - if (features->type >= INTUOS3S) { - input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); - input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); - input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); - } else { - input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2])); - input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4])); - input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); - } - - /* process general packets */ - wacom_intuos_general(wacom); /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */ if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) { @@ -1036,7 +1002,44 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) input_report_key(input, wacom->tool[idx], 1); input_event(input, EV_MSC, MSC_SERIAL, wacom->serial[idx]); wacom->reporting_data = true; - return 1; + return 2; +} + +static int wacom_intuos_irq(struct wacom_wac *wacom) +{ + unsigned char *data = wacom->data; + struct input_dev *input = wacom->pen_input; + int result; + + if (data[0] != WACOM_REPORT_PENABLED && + data[0] != WACOM_REPORT_INTUOSREAD && + data[0] != WACOM_REPORT_INTUOSWRITE && + data[0] != WACOM_REPORT_INTUOSPAD && + data[0] != WACOM_REPORT_INTUOS_PEN && + data[0] != WACOM_REPORT_CINTIQ && + data[0] != WACOM_REPORT_CINTIQPAD && + data[0] != WACOM_REPORT_INTUOS5PAD) { + dev_dbg(input->dev.parent, + "%s: received unknown report #%d\n", __func__, data[0]); + return 0; + } + + /* process pad events */ + result = wacom_intuos_pad(wacom); + if (result) + return result; + + /* process in/out prox events */ + result = wacom_intuos_inout(wacom); + if (result) + return result - 1; + + /* process general packets */ + result = wacom_intuos_general(wacom); + if (result) + return result - 1; + + return 0; } static int int_dist(int x1, int y1, int x2, int y2) -- cgit 1.4.1 From a8a09c8597bd301437c30ce0a4b2f511349a90aa Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 30 Nov 2015 17:13:49 -0800 Subject: HID: wacom: Replace magic masks and comparisons with switch cases Reasoning through the conditions under which a particular block of code in 'wacom_intuos_general' will be reached is not at all easy due to the sheer number of magic masks and comparisons. Remove these and replace them with a switch statement over the various 'types' of packets that will be encountered. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 79 ++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 30 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index e39568837b58..a426cb2a1834 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -886,6 +886,7 @@ static int wacom_intuos_general(struct wacom_wac *wacom) unsigned char *data = wacom->data; struct input_dev *input = wacom->pen_input; int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0; + unsigned char type = (data[1] >> 1) & 0x0F; unsigned int t; if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ && @@ -902,8 +903,12 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); } - /* general pen packet */ - if ((data[1] & 0xb8) == 0xa0) { + switch (type) { + case 0x00: + case 0x01: + case 0x02: + case 0x03: + /* general pen packet */ t = (data[6] << 2) | ((data[7] >> 6) & 3); if (features->pressure_max == 2047) { t = (t << 1) | (data[1] & 1); @@ -917,36 +922,40 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_key(input, BTN_STYLUS, data[1] & 2); input_report_key(input, BTN_STYLUS2, data[1] & 4); input_report_key(input, BTN_TOUCH, t > 10); - } + break; - /* airbrush second packet */ - if ((data[1] & 0xbc) == 0xb4) { + case 0x0a: + case 0x0b: + /* airbrush second packet */ input_report_abs(input, ABS_WHEEL, (data[6] << 2) | ((data[7] >> 6) & 3)); input_report_abs(input, ABS_TILT_X, (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64); input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64); - } + break; - /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */ - if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) { - - if (data[1] & 0x02) { - /* Rotation packet */ - if (features->type >= INTUOS3S) { - /* I3 marker pen rotation */ - t = (data[6] << 3) | ((data[7] >> 5) & 7); - t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : - ((t-1) / 2 + 450)) : (450 - t / 2) ; - input_report_abs(input, ABS_Z, t); - } else { - /* 4D mouse rotation packet */ - t = (data[6] << 3) | ((data[7] >> 5) & 7); - input_report_abs(input, ABS_RZ, (data[7] & 0x20) ? - ((t - 1) / 2) : -t / 2); - } + case 0x05: + case 0x07: + /* Rotation packet */ + if (features->type >= INTUOS3S) { + /* I3 marker pen rotation */ + t = (data[6] << 3) | ((data[7] >> 5) & 7); + t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : + ((t-1) / 2 + 450)) : (450 - t / 2) ; + input_report_abs(input, ABS_Z, t); + } else { + /* 4D mouse rotation packet */ + t = (data[6] << 3) | ((data[7] >> 5) & 7); + input_report_abs(input, ABS_RZ, (data[7] & 0x20) ? + ((t - 1) / 2) : -t / 2); + } + break; - } else if (!(data[1] & 0x10) && features->type < INTUOS3S) { + /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */ + case 0x04: + case 0x06: + case 0x08: + if (features->type < INTUOS3S && type != 0x08) { /* 4D mouse packet */ input_report_key(input, BTN_LEFT, data[8] & 0x01); input_report_key(input, BTN_MIDDLE, data[8] & 0x02); @@ -956,8 +965,8 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_key(input, BTN_EXTRA, data[8] & 0x10); t = (data[6] << 2) | ((data[7] >> 6) & 3); input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t); - - } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { + } + else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { /* I4 mouse */ if (features->type >= INTUOS4S && features->type <= INTUOSPL) { input_report_key(input, BTN_LEFT, data[6] & 0x01); @@ -985,10 +994,11 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_key(input, BTN_EXTRA, data[8] & 0x20); } } - } else if ((features->type < INTUOS3S || features->type == INTUOS3L || - features->type == INTUOS4L || features->type == INTUOS5L || - features->type == INTUOSPL) && - wacom->tool[idx] == BTN_TOOL_LENS) { + } + else if ((features->type < INTUOS3S || features->type == INTUOS3L || + features->type == INTUOS4L || features->type == INTUOS5L || + features->type == INTUOSPL) && + wacom->tool[idx] == BTN_TOOL_LENS) { /* Lens cursor packets */ input_report_key(input, BTN_LEFT, data[8] & 0x01); input_report_key(input, BTN_MIDDLE, data[8] & 0x02); @@ -996,6 +1006,15 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_key(input, BTN_SIDE, data[8] & 0x10); input_report_key(input, BTN_EXTRA, data[8] & 0x08); } + break; + + case 0x09: + case 0x0c: + case 0x0d: + case 0x0e: + case 0x0f: + /* unhandled */ + break; } input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */ -- cgit 1.4.1 From 571f572f9acf7e03fd0e8eb1449e75447295d457 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 30 Nov 2015 17:13:50 -0800 Subject: HID: wacom: Further clean up wacom_intuos_general packet decoder Continue re-organizing and trimming cases to make it easier to wrap the brain around. A number of changes were made after consulting the protocol spec and so don't necessarily follow from the code itself. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 87 +++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 46 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index a426cb2a1834..ce3afab806cc 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -925,7 +925,6 @@ static int wacom_intuos_general(struct wacom_wac *wacom) break; case 0x0a: - case 0x0b: /* airbrush second packet */ input_report_abs(input, ABS_WHEEL, (data[6] << 2) | ((data[7] >> 6) & 3)); @@ -935,7 +934,6 @@ static int wacom_intuos_general(struct wacom_wac *wacom) break; case 0x05: - case 0x07: /* Rotation packet */ if (features->type >= INTUOS3S) { /* I3 marker pen rotation */ @@ -944,61 +942,56 @@ static int wacom_intuos_general(struct wacom_wac *wacom) ((t-1) / 2 + 450)) : (450 - t / 2) ; input_report_abs(input, ABS_Z, t); } else { - /* 4D mouse rotation packet */ + /* 4D mouse 2nd packet */ t = (data[6] << 3) | ((data[7] >> 5) & 7); input_report_abs(input, ABS_RZ, (data[7] & 0x20) ? ((t - 1) / 2) : -t / 2); } break; - /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */ case 0x04: + /* 4D mouse 1st packet */ + input_report_key(input, BTN_LEFT, data[8] & 0x01); + input_report_key(input, BTN_MIDDLE, data[8] & 0x02); + input_report_key(input, BTN_RIGHT, data[8] & 0x04); + + input_report_key(input, BTN_SIDE, data[8] & 0x20); + input_report_key(input, BTN_EXTRA, data[8] & 0x10); + t = (data[6] << 2) | ((data[7] >> 6) & 3); + input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t); + break; + case 0x06: - case 0x08: - if (features->type < INTUOS3S && type != 0x08) { - /* 4D mouse packet */ - input_report_key(input, BTN_LEFT, data[8] & 0x01); - input_report_key(input, BTN_MIDDLE, data[8] & 0x02); - input_report_key(input, BTN_RIGHT, data[8] & 0x04); + /* I4 mouse */ + input_report_key(input, BTN_LEFT, data[6] & 0x01); + input_report_key(input, BTN_MIDDLE, data[6] & 0x02); + input_report_key(input, BTN_RIGHT, data[6] & 0x04); + input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7) + - ((data[7] & 0x40) >> 6)); + input_report_key(input, BTN_SIDE, data[6] & 0x08); + input_report_key(input, BTN_EXTRA, data[6] & 0x10); - input_report_key(input, BTN_SIDE, data[8] & 0x20); - input_report_key(input, BTN_EXTRA, data[8] & 0x10); - t = (data[6] << 2) | ((data[7] >> 6) & 3); - input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t); - } - else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { - /* I4 mouse */ - if (features->type >= INTUOS4S && features->type <= INTUOSPL) { - input_report_key(input, BTN_LEFT, data[6] & 0x01); - input_report_key(input, BTN_MIDDLE, data[6] & 0x02); - input_report_key(input, BTN_RIGHT, data[6] & 0x04); - input_report_rel(input, REL_WHEEL, ((data[7] & 0x80) >> 7) - - ((data[7] & 0x40) >> 6)); - input_report_key(input, BTN_SIDE, data[6] & 0x08); - input_report_key(input, BTN_EXTRA, data[6] & 0x10); - - input_report_abs(input, ABS_TILT_X, - (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64); - input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64); - } else { - /* 2D mouse packet */ - input_report_key(input, BTN_LEFT, data[8] & 0x04); - input_report_key(input, BTN_MIDDLE, data[8] & 0x08); - input_report_key(input, BTN_RIGHT, data[8] & 0x10); - input_report_rel(input, REL_WHEEL, (data[8] & 0x01) - - ((data[8] & 0x02) >> 1)); - - /* I3 2D mouse side buttons */ - if (features->type >= INTUOS3S && features->type <= INTUOS3L) { - input_report_key(input, BTN_SIDE, data[8] & 0x40); - input_report_key(input, BTN_EXTRA, data[8] & 0x20); - } + input_report_abs(input, ABS_TILT_X, + (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64); + input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64); + break; + + case 0x08: + if (wacom->tool[idx] == BTN_TOOL_MOUSE) { + /* 2D mouse packet */ + input_report_key(input, BTN_LEFT, data[8] & 0x04); + input_report_key(input, BTN_MIDDLE, data[8] & 0x08); + input_report_key(input, BTN_RIGHT, data[8] & 0x10); + input_report_rel(input, REL_WHEEL, (data[8] & 0x01) + - ((data[8] & 0x02) >> 1)); + + /* I3 2D mouse side buttons */ + if (features->type >= INTUOS3S && features->type <= INTUOS3L) { + input_report_key(input, BTN_SIDE, data[8] & 0x40); + input_report_key(input, BTN_EXTRA, data[8] & 0x20); } } - else if ((features->type < INTUOS3S || features->type == INTUOS3L || - features->type == INTUOS4L || features->type == INTUOS5L || - features->type == INTUOSPL) && - wacom->tool[idx] == BTN_TOOL_LENS) { + else if (wacom->tool[idx] == BTN_TOOL_LENS) { /* Lens cursor packets */ input_report_key(input, BTN_LEFT, data[8] & 0x01); input_report_key(input, BTN_MIDDLE, data[8] & 0x02); @@ -1008,7 +1001,9 @@ static int wacom_intuos_general(struct wacom_wac *wacom) } break; + case 0x07: case 0x09: + case 0x0b: case 0x0c: case 0x0d: case 0x0e: -- cgit 1.4.1 From 5f33f430efe3ce2dfe4e9c5eeabb89ea5df145b6 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 30 Nov 2015 17:13:51 -0800 Subject: HID: wacom: Clean up value reading Make the logic for reading X, Y, distance, and pressure a bit more clear. An additional bit was stuffed into the packet format many models back, and /most/ devices in use will use it. If we happen to be dealing with a particularly old tablet, just shift it off the end to pretend we never read it. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index ce3afab806cc..0008650e3bdb 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -887,21 +887,23 @@ static int wacom_intuos_general(struct wacom_wac *wacom) struct input_dev *input = wacom->pen_input; int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0; unsigned char type = (data[1] >> 1) & 0x0F; - unsigned int t; + unsigned int x, y, distance, t; if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ && data[0] != WACOM_REPORT_INTUOS_PEN) return 0; - if (features->type >= INTUOS3S) { - input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); - input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); - input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); - } else { - input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2])); - input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4])); - input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); + x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1); + y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1); + distance = data[9] >> 2; + if (features->type < INTUOS3S) { + x >>= 1; + y >>= 1; + distance >>= 1; } + input_report_abs(input, ABS_X, x); + input_report_abs(input, ABS_Y, y); + input_report_abs(input, ABS_DISTANCE, distance); switch (type) { case 0x00: @@ -909,10 +911,9 @@ static int wacom_intuos_general(struct wacom_wac *wacom) case 0x02: case 0x03: /* general pen packet */ - t = (data[6] << 2) | ((data[7] >> 6) & 3); - if (features->pressure_max == 2047) { - t = (t << 1) | (data[1] & 1); - } + t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1); + if (features->pressure_max < 2047) + t >>= 1; input_report_abs(input, ABS_PRESSURE, t); if (features->type != INTUOSHT2) { input_report_abs(input, ABS_TILT_X, -- cgit 1.4.1 From 061099936a724cdd8dd0d69deea5b064b4f7122b Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Mon, 30 Nov 2015 17:13:52 -0800 Subject: HID: wacom: Rename wacom ID report ID macros "INTUOSREAD" and "INTUOSWRITE" are poorly named. These are report IDs for pen ID (proximity) packets. It should be noted that the latter is only used on Intuos/Intuos2 for a second stylus when DualTrack is in use. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 6 +++--- drivers/hid/wacom_wac.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 0008650e3bdb..3953416ff753 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -443,7 +443,7 @@ static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac) struct hid_report_enum *re; re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]); - r = re->report_id_hash[WACOM_REPORT_INTUOSREAD]; + r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1]; if (r) { hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT); } @@ -1027,8 +1027,8 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) int result; if (data[0] != WACOM_REPORT_PENABLED && - data[0] != WACOM_REPORT_INTUOSREAD && - data[0] != WACOM_REPORT_INTUOSWRITE && + data[0] != WACOM_REPORT_INTUOS_ID1 && + data[0] != WACOM_REPORT_INTUOS_ID2 && data[0] != WACOM_REPORT_INTUOSPAD && data[0] != WACOM_REPORT_INTUOS_PEN && data[0] != WACOM_REPORT_CINTIQ && diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index 877c24a5df94..3f60192e9272 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -47,8 +47,8 @@ /* wacom data packet report IDs */ #define WACOM_REPORT_PENABLED 2 #define WACOM_REPORT_PENABLED_BT 3 -#define WACOM_REPORT_INTUOSREAD 5 -#define WACOM_REPORT_INTUOSWRITE 6 +#define WACOM_REPORT_INTUOS_ID1 5 +#define WACOM_REPORT_INTUOS_ID2 6 #define WACOM_REPORT_INTUOSPAD 12 #define WACOM_REPORT_INTUOS5PAD 3 #define WACOM_REPORT_DTUSPAD 21 -- cgit 1.4.1 From 64bebefcf3195baed3d15dc377e15d1e7121036a Mon Sep 17 00:00:00 2001 From: "Fu, Zhonghui" Date: Thu, 24 Sep 2015 14:06:31 +0800 Subject: HID: enable hid device to suspend/resume asynchronously Now, PM core supports asynchronous suspend/resume mode for devices during system suspend/resume, and the power state transition of one device may be completed in separate kernel thread. PM core ensures all power state transition timing dependency between devices. This patch enables hid devices to suspend/resume asynchronously. This will take advantage of multicore and improve system suspend/resume speed. Signed-off-by: Zhonghui Fu Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index c6f7a694f67a..e9ef0dd4fd89 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2660,6 +2660,7 @@ struct hid_device *hid_allocate_device(void) device_initialize(&hdev->dev); hdev->dev.release = hid_device_release; hdev->dev.bus = &hid_bus_type; + device_enable_async_suspend(&hdev->dev); hid_close_report(hdev); -- cgit 1.4.1 From be853fd1c6a5fe127af3392157dfe95e9712a575 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Fri, 4 Dec 2015 14:45:27 -0800 Subject: HID: wacom: Apply lowres quirk to BAMBOO_TOUCH devices When splitting the touch-only "BAMBOO_TOUCH" type out of the existing "BAMBOO_PT" type in 3b164a00, the lowres quirk was not updated so that it would continue to apply to these devices (effectively only the 0xD0). The absence of this quirk does not significantly impact usability, but is a correctness issue nonetheless. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 3953416ff753..bec23001c219 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2421,7 +2421,7 @@ void wacom_setup_device_quirks(struct wacom *wacom) features->quirks |= WACOM_QUIRK_BATTERY; /* quirk for bamboo touch with 2 low res touches */ - if (features->type == BAMBOO_PT && + if ((features->type == BAMBOO_PT || features->type == BAMBOO_TOUCH) && features->pktlen == WACOM_PKGLEN_BBTOUCH) { features->x_max <<= 5; features->y_max <<= 5; -- cgit 1.4.1 From 8f9cfdd359478ea70da0144b0cb407a4734f14cd Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 9 Dec 2015 13:22:05 +0300 Subject: HID: wacom: bitwise vs logical ORs Smatch complains that these should probably be bitwise ORs instead of logical. It doesn't matter for "prox" but it makes a difference for "strip1" and "strip2". Fixes: c7f0522a1ad1 ('HID: wacom: Slim down wacom_intuos_pad processing') Signed-off-by: Dan Carpenter Reviewed-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index bec23001c219..22d32259e1f1 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -545,12 +545,12 @@ static int wacom_intuos_pad(struct wacom_wac *wacom) ((data[6] & 0x0F) << 4) | (data[5] & 0x0F); } - strip1 = (data[1] << 8) || data[2]; - strip2 = (data[3] << 8) || data[4]; + strip1 = (data[1] << 8) | data[2]; + strip2 = (data[3] << 8) | data[4]; } - prox = (buttons & ~(~0 << nbuttons)) || (keys & ~(~0 << nkeys)) || - (ring1 & 0x80) || (ring2 & 0x80) || strip1 || strip2; + prox = (buttons & ~(~0 << nbuttons)) | (keys & ~(~0 << nkeys)) | + (ring1 & 0x80) | (ring2 & 0x80) | strip1 | strip2; wacom_report_numbered_buttons(input, nbuttons, buttons); -- cgit 1.4.1 From f73d08d073a4bcb8bb1bd88444f07f39c84400da Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 16 Dec 2015 13:37:33 -0800 Subject: HID: wacom: Limit touchstrip data to 13 bits Commit c7f0522 uses sixteen bits of data in the construction of 'strip1' and 'strip2'. This can cause problems in some cases, however, since some tablets store flags in the MSB of data[2] and data[4] that should not be included in these values. This restores the 0x1f mask that used prior to c7f0522. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 22d32259e1f1..cf878106f4ed 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -545,8 +545,8 @@ static int wacom_intuos_pad(struct wacom_wac *wacom) ((data[6] & 0x0F) << 4) | (data[5] & 0x0F); } - strip1 = (data[1] << 8) | data[2]; - strip2 = (data[3] << 8) | data[4]; + strip1 = ((data[1] & 0x1f) << 8) | data[2]; + strip2 = ((data[3] & 0x1f) << 8) | data[4]; } prox = (buttons & ~(~0 << nbuttons)) | (keys & ~(~0 << nkeys)) | -- cgit 1.4.1 From 03a0dc546be3fa6091214bd2c05d678d3e8d67df Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 16 Dec 2015 13:37:34 -0800 Subject: HID: wacom: Report 'strip2' values in ABS_RY Commit c7f0522 accidentally used ABS_RX for reporting both 'strip1' and 'strip2', when the latter should actually be reported through ABS_RY. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index cf878106f4ed..94dffde5f3d5 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -558,7 +558,7 @@ static int wacom_intuos_pad(struct wacom_wac *wacom) input_report_key(input, KEY_PROG1 + i, keys & (1 << i)); input_report_abs(input, ABS_RX, strip1); - input_report_abs(input, ABS_RX, strip2); + input_report_abs(input, ABS_RY, strip2); input_report_abs(input, ABS_WHEEL, ring1 & 0x7f ? ring1 : 0); input_report_abs(input, ABS_THROTTLE, ring2 & 0x07 ? ring2 : 0); -- cgit 1.4.1 From aaae03e4f7f0c641a258dde855ab677c9b58b155 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 16 Dec 2015 13:37:35 -0800 Subject: HID: wacom: Fix touchring value reporting Commit c7f0522 reports incorrect touchring values to userspace. This is due to its incorrect handling of the 'touched' bit present in the 'ring1' and 'ring2' variables. Instead of using this bit when determining if a value should be sent, the ABS_WHEEL and ABS_INPUT check (different?!) portions of the position bits. Furthermore, the full values of 'ring1' and 'ring2' are reported to userspace, despite the 'touched' flag needing to be trimmed beforehand. This commit addresses both issues. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 94dffde5f3d5..23212af7fa76 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -560,8 +560,8 @@ static int wacom_intuos_pad(struct wacom_wac *wacom) input_report_abs(input, ABS_RX, strip1); input_report_abs(input, ABS_RY, strip2); - input_report_abs(input, ABS_WHEEL, ring1 & 0x7f ? ring1 : 0); - input_report_abs(input, ABS_THROTTLE, ring2 & 0x07 ? ring2 : 0); + input_report_abs(input, ABS_WHEEL, (ring1 & 0x80) ? (ring1 & 0x7f) : 0); + input_report_abs(input, ABS_THROTTLE, (ring2 & 0x80) ? (ring2 & 0x7f) : 0); input_report_key(input, wacom->tool[1], prox ? 1 : 0); input_report_abs(input, ABS_MISC, prox ? PAD_DEVICE_ID : 0); -- cgit 1.4.1 From 0402b6b77a35205072087d7f774e4c2b2797f8c3 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 16 Dec 2015 13:37:36 -0800 Subject: HID: wacom: Fix pad button range for CINTIQ_COMPANION_2 Commit c7f0522 incorrectly constructs the 'buttons' variable for the CINTIQ_COMPANION_2 case. The high nybble of data[2] is shifted four bits too far, leaving the bits associated with BTN_7 through BTN_A unset. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 23212af7fa76..f70660465a54 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -516,7 +516,7 @@ static int wacom_intuos_pad(struct wacom_wac *wacom) * d-pad down -> data[4] & 0x80 * d-pad center -> data[3] & 0x01 */ - buttons = ((data[2] & 0xF0) << 7) | + buttons = ((data[2] >> 4) << 7) | ((data[1] & 0x04) << 6) | ((data[2] & 0x0F) << 2) | (data[1] & 0x03); -- cgit 1.4.1 From 5d9374cf5f66ebe38007bccf0b4adc14f0013663 Mon Sep 17 00:00:00 2001 From: "Alexander E. Patrakov" Date: Mon, 14 Dec 2015 17:42:26 +0500 Subject: HID: input: ignore the battery in OKLICK Laser BTmouse This mouse, when asked about the battery, ceases to report movements and clicks. So just don't ask. Signed-off-by: Alexander E. Patrakov Signed-off-by: Jiri Kosina --- drivers/hid/hid-input.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index 2ba6bf69b7d0..0869faef1308 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -303,6 +303,7 @@ static enum power_supply_property hidinput_battery_props[] = { #define HID_BATTERY_QUIRK_PERCENT (1 << 0) /* always reports percent */ #define HID_BATTERY_QUIRK_FEATURE (1 << 1) /* ask for feature report */ +#define HID_BATTERY_QUIRK_IGNORE (1 << 2) /* completely ignore the battery */ static const struct hid_device_id hid_battery_quirks[] = { { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, @@ -320,6 +321,9 @@ static const struct hid_device_id hid_battery_quirks[] = { { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI), HID_BATTERY_QUIRK_PERCENT | HID_BATTERY_QUIRK_FEATURE }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, + USB_DEVICE_ID_ELECOM_BM084), + HID_BATTERY_QUIRK_IGNORE }, {} }; @@ -408,6 +412,14 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, if (dev->battery != NULL) goto out; /* already initialized? */ + quirks = find_battery_quirk(dev); + + hid_dbg(dev, "device %x:%x:%x %d quirks %d\n", + dev->bus, dev->vendor, dev->product, dev->version, quirks); + + if (quirks & HID_BATTERY_QUIRK_IGNORE) + goto out; + psy_desc = kzalloc(sizeof(*psy_desc), GFP_KERNEL); if (psy_desc == NULL) goto out; @@ -424,11 +436,6 @@ static bool hidinput_setup_battery(struct hid_device *dev, unsigned report_type, psy_desc->use_for_apm = 0; psy_desc->get_property = hidinput_get_battery_property; - quirks = find_battery_quirk(dev); - - hid_dbg(dev, "device %x:%x:%x %d quirks %d\n", - dev->bus, dev->vendor, dev->product, dev->version, quirks); - min = field->logical_minimum; max = field->logical_maximum; -- cgit 1.4.1 From e3fed74894c725fb85d7315aa0c01df9b59b7a9d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 16 Dec 2015 16:56:39 +0800 Subject: HID: corsair: Convert to use module_hid_driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Axel Lin Acked-by: Clément Vuchener Signed-off-by: Jiri Kosina --- drivers/hid/hid-corsair.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-corsair.c b/drivers/hid/hid-corsair.c index bcefb9ebb026..58551964ce86 100644 --- a/drivers/hid/hid-corsair.c +++ b/drivers/hid/hid-corsair.c @@ -655,18 +655,7 @@ static struct hid_driver corsair_driver = { .input_mapping = corsair_input_mapping, }; -static int __init corsair_init(void) -{ - return hid_register_driver(&corsair_driver); -} - -static void corsair_exit(void) -{ - hid_unregister_driver(&corsair_driver); -} - -module_init(corsair_init); -module_exit(corsair_exit); +module_hid_driver(corsair_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Clement Vuchener"); -- cgit 1.4.1 From 7775fb929d959eade7c705e27a0a759997463da8 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Wed, 23 Dec 2015 21:26:53 +0800 Subject: HID: usbhid: use to_usb_device Use to_usb_device() instead of open-coding it. Signed-off-by: Geliang Tang Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/usbhid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h index 807922b49aa4..fa47d666cfcf 100644 --- a/drivers/hid/usbhid/usbhid.h +++ b/drivers/hid/usbhid/usbhid.h @@ -96,7 +96,7 @@ struct usbhid_device { }; #define hid_to_usb_dev(hid_dev) \ - container_of(hid_dev->dev.parent->parent, struct usb_device, dev) + to_usb_device(hid_dev->dev.parent->parent) #endif -- cgit 1.4.1 From d8ce9bf5551bfea431893bdd0a943f24a5170828 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Sun, 27 Dec 2015 17:25:20 +0800 Subject: HID: move to_hid_device() to hid.h to_hid_device() macro is defined in both hid-lg4ff.c and hid-logitech-hidpp.c. So I move it to include/linux/hid.h. Signed-off-by: Geliang Tang Signed-off-by: Jiri Kosina --- drivers/hid/hid-lg4ff.c | 2 -- drivers/hid/hid-logitech-hidpp.c | 2 -- include/linux/hid.h | 3 +++ 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index fbddcb37ae98..3e160ff5f218 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -33,8 +33,6 @@ #include "hid-lg4ff.h" #include "hid-ids.h" -#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) - #define LG4FF_MMODE_IS_MULTIMODE 0 #define LG4FF_MMODE_SWITCHED 1 #define LG4FF_MMODE_NOT_MULTIMODE 2 diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index f2a481125522..bd2ab476c65e 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1310,8 +1310,6 @@ struct g920_private_data { u16 range; }; -#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) - static ssize_t g920_range_show(struct device *dev, struct device_attribute *attr, char *buf) { diff --git a/include/linux/hid.h b/include/linux/hid.h index a6d7a3fc2cb3..1472026367ed 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -565,6 +565,9 @@ struct hid_device { /* device report descriptor */ wait_queue_head_t debug_wait; }; +#define to_hid_device(pdev) \ + container_of(pdev, struct hid_device, dev) + static inline void *hid_get_drvdata(struct hid_device *hdev) { return dev_get_drvdata(&hdev->dev); -- cgit 1.4.1 From ee79a8f840a45d331bc33e55cbcc89bba417671c Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Sun, 27 Dec 2015 17:25:21 +0800 Subject: HID: use to_hid_device() Use to_hid_device() instead of container_of(). Signed-off-by: Geliang Tang Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 14 +++++++------- drivers/hid/hid-cp2112.c | 8 ++++---- drivers/hid/hid-gt683r.c | 8 +++----- drivers/hid/hid-lenovo.c | 36 ++++++++++++++++++------------------ drivers/hid/hid-lg4ff.c | 4 ++-- drivers/hid/hid-multitouch.c | 4 ++-- drivers/hid/hid-ntrig.c | 32 ++++++++++++++++---------------- drivers/hid/hid-picolcd_leds.c | 4 ++-- drivers/hid/hid-prodikeys.c | 12 ++++++------ drivers/hid/hid-sony.c | 6 +++--- drivers/hid/hid-steelseries.c | 8 ++++---- drivers/hid/hid-wiimote.h | 3 +-- drivers/hid/wacom_sys.c | 16 ++++++++-------- 13 files changed, 76 insertions(+), 79 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 190260c52adc..a6e24e00a37b 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -625,7 +625,7 @@ static void hid_close_report(struct hid_device *device) static void hid_device_release(struct device *dev) { - struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct hid_device *hid = to_hid_device(dev); hid_close_report(hid); kfree(hid->dev_rdesc); @@ -1572,7 +1572,7 @@ read_report_descriptor(struct file *filp, struct kobject *kobj, char *buf, loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj); - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); if (off >= hdev->rsize) return 0; @@ -1589,7 +1589,7 @@ static ssize_t show_country(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); return sprintf(buf, "%02x\n", hdev->country & 0xff); } @@ -2140,7 +2140,7 @@ static const struct hid_device_id *hid_match_device(struct hid_device *hdev, static int hid_bus_match(struct device *dev, struct device_driver *drv) { struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); return hid_match_device(hdev, hdrv) != NULL; } @@ -2149,7 +2149,7 @@ static int hid_device_probe(struct device *dev) { struct hid_driver *hdrv = container_of(dev->driver, struct hid_driver, driver); - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); const struct hid_device_id *id; int ret = 0; @@ -2191,7 +2191,7 @@ unlock_driver_lock: static int hid_device_remove(struct device *dev) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct hid_driver *hdrv; int ret = 0; @@ -2241,7 +2241,7 @@ ATTRIBUTE_GROUPS(hid_dev); static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X", hdev->bus, hdev->vendor, hdev->product)) diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c index 7afc3fcc122c..7c38bfa05fac 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c @@ -807,7 +807,7 @@ static ssize_t name##_store(struct device *kdev, \ struct device_attribute *attr, const char *buf, \ size_t count) \ { \ - struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \ + struct hid_device *hdev = to_hid_device(kdev); \ struct cp2112_usb_config_report cfg; \ int ret = cp2112_get_usb_config(hdev, &cfg); \ if (ret) \ @@ -822,7 +822,7 @@ static ssize_t name##_store(struct device *kdev, \ static ssize_t name##_show(struct device *kdev, \ struct device_attribute *attr, char *buf) \ { \ - struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \ + struct hid_device *hdev = to_hid_device(kdev); \ struct cp2112_usb_config_report cfg; \ int ret = cp2112_get_usb_config(hdev, &cfg); \ if (ret) \ @@ -887,7 +887,7 @@ static ssize_t pstr_store(struct device *kdev, struct device_attribute *kattr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(kdev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(kdev); struct cp2112_pstring_attribute *attr = container_of(kattr, struct cp2112_pstring_attribute, attr); struct cp2112_string_report report; @@ -918,7 +918,7 @@ static ssize_t pstr_store(struct device *kdev, static ssize_t pstr_show(struct device *kdev, struct device_attribute *kattr, char *buf) { - struct hid_device *hdev = container_of(kdev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(kdev); struct cp2112_pstring_attribute *attr = container_of(kattr, struct cp2112_pstring_attribute, attr); struct cp2112_string_report report; diff --git a/drivers/hid/hid-gt683r.c b/drivers/hid/hid-gt683r.c index 0d6f135e266c..a298fbd8db6b 100644 --- a/drivers/hid/hid-gt683r.c +++ b/drivers/hid/hid-gt683r.c @@ -70,7 +70,7 @@ static void gt683r_brightness_set(struct led_classdev *led_cdev, { int i; struct device *dev = led_cdev->dev->parent; - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct gt683r_led *led = hid_get_drvdata(hdev); for (i = 0; i < GT683R_LED_COUNT; i++) { @@ -89,8 +89,7 @@ static ssize_t mode_show(struct device *dev, char *buf) { u8 sysfs_mode; - struct hid_device *hdev = container_of(dev->parent, - struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev->parent); struct gt683r_led *led = hid_get_drvdata(hdev); if (led->mode == GT683R_LED_NORMAL) @@ -108,8 +107,7 @@ static ssize_t mode_store(struct device *dev, const char *buf, size_t count) { u8 sysfs_mode; - struct hid_device *hdev = container_of(dev->parent, - struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev->parent); struct gt683r_led *led = hid_get_drvdata(hdev); diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index 8979f1fd5208..0125e356bd8d 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -220,7 +220,7 @@ static ssize_t attr_fn_lock_show_cptkbd(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%u\n", cptkbd_data->fn_lock); @@ -231,7 +231,7 @@ static ssize_t attr_fn_lock_store_cptkbd(struct device *dev, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); int value; @@ -250,7 +250,7 @@ static ssize_t attr_sensitivity_show_cptkbd(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%u\n", @@ -262,7 +262,7 @@ static ssize_t attr_sensitivity_store_cptkbd(struct device *dev, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_cptkbd *cptkbd_data = hid_get_drvdata(hdev); int value; @@ -387,7 +387,7 @@ static ssize_t attr_press_to_select_show_tpkbd(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select); @@ -398,7 +398,7 @@ static ssize_t attr_press_to_select_store_tpkbd(struct device *dev, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); int value; @@ -417,7 +417,7 @@ static ssize_t attr_dragging_show_tpkbd(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging); @@ -428,7 +428,7 @@ static ssize_t attr_dragging_store_tpkbd(struct device *dev, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); int value; @@ -447,7 +447,7 @@ static ssize_t attr_release_to_select_show_tpkbd(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select); @@ -458,7 +458,7 @@ static ssize_t attr_release_to_select_store_tpkbd(struct device *dev, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); int value; @@ -477,7 +477,7 @@ static ssize_t attr_select_right_show_tpkbd(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right); @@ -488,7 +488,7 @@ static ssize_t attr_select_right_store_tpkbd(struct device *dev, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); int value; @@ -507,7 +507,7 @@ static ssize_t attr_sensitivity_show_tpkbd(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%u\n", @@ -519,7 +519,7 @@ static ssize_t attr_sensitivity_store_tpkbd(struct device *dev, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); int value; @@ -536,7 +536,7 @@ static ssize_t attr_press_speed_show_tpkbd(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%u\n", @@ -548,7 +548,7 @@ static ssize_t attr_press_speed_store_tpkbd(struct device *dev, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); int value; @@ -609,7 +609,7 @@ static enum led_brightness lenovo_led_brightness_get_tpkbd( struct led_classdev *led_cdev) { struct device *dev = led_cdev->dev->parent; - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); int led_nr = 0; @@ -625,7 +625,7 @@ static void lenovo_led_brightness_set_tpkbd(struct led_classdev *led_cdev, enum led_brightness value) { struct device *dev = led_cdev->dev->parent; - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct lenovo_drvdata_tpkbd *data_pointer = hid_get_drvdata(hdev); struct hid_report *report; int led_nr = 0; diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c index 3e160ff5f218..af3a8ec8a746 100644 --- a/drivers/hid/hid-lg4ff.c +++ b/drivers/hid/hid-lg4ff.c @@ -1018,7 +1018,7 @@ static void lg4ff_led_set_brightness(struct led_classdev *led_cdev, enum led_brightness value) { struct device *dev = led_cdev->dev->parent; - struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct hid_device *hid = to_hid_device(dev); struct lg_drv_data *drv_data = hid_get_drvdata(hid); struct lg4ff_device_entry *entry; int i, state = 0; @@ -1053,7 +1053,7 @@ static void lg4ff_led_set_brightness(struct led_classdev *led_cdev, static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cdev) { struct device *dev = led_cdev->dev->parent; - struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct hid_device *hid = to_hid_device(dev); struct lg_drv_data *drv_data = hid_get_drvdata(hid); struct lg4ff_device_entry *entry; int i, value = 0; diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 3d664d01305e..96cf7512c338 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -272,7 +272,7 @@ static ssize_t mt_show_quirks(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct mt_device *td = hid_get_drvdata(hdev); return sprintf(buf, "%u\n", td->mtclass.quirks); @@ -282,7 +282,7 @@ static ssize_t mt_set_quirks(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct mt_device *td = hid_get_drvdata(hdev); unsigned long val; diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index 756d1ef9bd99..1b0084d4af2e 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c @@ -173,7 +173,7 @@ static ssize_t show_phys_width(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->sensor_physical_width); @@ -185,7 +185,7 @@ static ssize_t show_phys_height(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->sensor_physical_height); @@ -197,7 +197,7 @@ static ssize_t show_log_width(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->sensor_logical_width); @@ -209,7 +209,7 @@ static ssize_t show_log_height(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->sensor_logical_height); @@ -221,7 +221,7 @@ static ssize_t show_min_width(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->min_width * @@ -233,7 +233,7 @@ static ssize_t set_min_width(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); unsigned long val; @@ -256,7 +256,7 @@ static ssize_t show_min_height(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->min_height * @@ -268,7 +268,7 @@ static ssize_t set_min_height(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); unsigned long val; @@ -292,7 +292,7 @@ static ssize_t show_activate_slack(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->activate_slack); @@ -302,7 +302,7 @@ static ssize_t set_activate_slack(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); unsigned long val; @@ -325,7 +325,7 @@ static ssize_t show_activation_width(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->activation_width * @@ -337,7 +337,7 @@ static ssize_t set_activation_width(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); unsigned long val; @@ -361,7 +361,7 @@ static ssize_t show_activation_height(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", nd->activation_height * @@ -373,7 +373,7 @@ static ssize_t set_activation_height(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); unsigned long val; @@ -397,7 +397,7 @@ static ssize_t show_deactivate_slack(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); return sprintf(buf, "%d\n", -nd->deactivate_slack); @@ -407,7 +407,7 @@ static ssize_t set_deactivate_slack(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct ntrig_data *nd = hid_get_drvdata(hdev); unsigned long val; diff --git a/drivers/hid/hid-picolcd_leds.c b/drivers/hid/hid-picolcd_leds.c index e994f9c29012..a802b4f49c7b 100644 --- a/drivers/hid/hid-picolcd_leds.c +++ b/drivers/hid/hid-picolcd_leds.c @@ -66,7 +66,7 @@ static void picolcd_led_set_brightness(struct led_classdev *led_cdev, int i, state = 0; dev = led_cdev->dev->parent; - hdev = container_of(dev, struct hid_device, dev); + hdev = to_hid_device(dev); data = hid_get_drvdata(hdev); if (!data) return; @@ -93,7 +93,7 @@ static enum led_brightness picolcd_led_get_brightness(struct led_classdev *led_c int i, value = 0; dev = led_cdev->dev->parent; - hdev = container_of(dev, struct hid_device, dev); + hdev = to_hid_device(dev); data = hid_get_drvdata(hdev); for (i = 0; i < 8; i++) if (led_cdev == data->led[i]) { diff --git a/drivers/hid/hid-prodikeys.c b/drivers/hid/hid-prodikeys.c index 3a207c0ac0e3..f095bf8a3aa9 100644 --- a/drivers/hid/hid-prodikeys.c +++ b/drivers/hid/hid-prodikeys.c @@ -103,7 +103,7 @@ MODULE_PARM_DESC(enable, "Enable for the PC-MIDI virtual audio driver"); static ssize_t show_channel(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct pk_device *pk = hid_get_drvdata(hdev); dbg_hid("pcmidi sysfs read channel=%u\n", pk->pm->midi_channel); @@ -116,7 +116,7 @@ static ssize_t show_channel(struct device *dev, static ssize_t store_channel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct pk_device *pk = hid_get_drvdata(hdev); unsigned channel = 0; @@ -140,7 +140,7 @@ static struct device_attribute *sysfs_device_attr_channel = { static ssize_t show_sustain(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct pk_device *pk = hid_get_drvdata(hdev); dbg_hid("pcmidi sysfs read sustain=%u\n", pk->pm->midi_sustain); @@ -153,7 +153,7 @@ static ssize_t show_sustain(struct device *dev, static ssize_t store_sustain(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct pk_device *pk = hid_get_drvdata(hdev); unsigned sustain = 0; @@ -179,7 +179,7 @@ static struct device_attribute *sysfs_device_attr_sustain = { static ssize_t show_octave(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct pk_device *pk = hid_get_drvdata(hdev); dbg_hid("pcmidi sysfs read octave=%d\n", pk->pm->midi_octave); @@ -192,7 +192,7 @@ static ssize_t show_octave(struct device *dev, static ssize_t store_octave(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct pk_device *pk = hid_get_drvdata(hdev); int octave = 0; diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 774cd2210566..9bbf5a725139 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -1549,7 +1549,7 @@ static void sony_led_set_brightness(struct led_classdev *led, enum led_brightness value) { struct device *dev = led->dev->parent; - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct sony_sc *drv_data; int n; @@ -1591,7 +1591,7 @@ static void sony_led_set_brightness(struct led_classdev *led, static enum led_brightness sony_led_get_brightness(struct led_classdev *led) { struct device *dev = led->dev->parent; - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct sony_sc *drv_data; int n; @@ -1614,7 +1614,7 @@ static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on, unsigned long *delay_off) { struct device *dev = led->dev->parent; - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct sony_sc *drv_data = hid_get_drvdata(hdev); int n; __u8 new_on, new_off; diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c index 3edd4ac36494..ec18768b124a 100644 --- a/drivers/hid/hid-steelseries.c +++ b/drivers/hid/hid-steelseries.c @@ -141,7 +141,7 @@ static void steelseries_srws1_led_all_set_brightness(struct led_classdev *led_cd enum led_brightness value) { struct device *dev = led_cdev->dev->parent; - struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct hid_device *hid = to_hid_device(dev); struct steelseries_srws1_data *drv_data = hid_get_drvdata(hid); if (!drv_data) { @@ -160,7 +160,7 @@ static void steelseries_srws1_led_all_set_brightness(struct led_classdev *led_cd static enum led_brightness steelseries_srws1_led_all_get_brightness(struct led_classdev *led_cdev) { struct device *dev = led_cdev->dev->parent; - struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct hid_device *hid = to_hid_device(dev); struct steelseries_srws1_data *drv_data; drv_data = hid_get_drvdata(hid); @@ -177,7 +177,7 @@ static void steelseries_srws1_led_set_brightness(struct led_classdev *led_cdev, enum led_brightness value) { struct device *dev = led_cdev->dev->parent; - struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct hid_device *hid = to_hid_device(dev); struct steelseries_srws1_data *drv_data = hid_get_drvdata(hid); int i, state = 0; @@ -205,7 +205,7 @@ static void steelseries_srws1_led_set_brightness(struct led_classdev *led_cdev, static enum led_brightness steelseries_srws1_led_get_brightness(struct led_classdev *led_cdev) { struct device *dev = led_cdev->dev->parent; - struct hid_device *hid = container_of(dev, struct hid_device, dev); + struct hid_device *hid = to_hid_device(dev); struct steelseries_srws1_data *drv_data; int i, value = 0; diff --git a/drivers/hid/hid-wiimote.h b/drivers/hid/hid-wiimote.h index 875694d43e4d..510ca77fe14e 100644 --- a/drivers/hid/hid-wiimote.h +++ b/drivers/hid/hid-wiimote.h @@ -256,8 +256,7 @@ enum wiiproto_reqs { WIIPROTO_REQ_MAX }; -#define dev_to_wii(pdev) hid_get_drvdata(container_of(pdev, struct hid_device, \ - dev)) +#define dev_to_wii(pdev) hid_get_drvdata(to_hid_device(pdev)) void __wiimote_schedule(struct wiimote_data *wdata); diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index e06af5b9f59e..4b7feb3022c1 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -686,7 +686,7 @@ out: static ssize_t wacom_led_select_store(struct device *dev, int set_id, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct wacom *wacom = hid_get_drvdata(hdev); unsigned int id; int err; @@ -714,7 +714,7 @@ static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \ static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ - struct hid_device *hdev = container_of(dev, struct hid_device, dev);\ + struct hid_device *hdev = to_hid_device(dev);\ struct wacom *wacom = hid_get_drvdata(hdev); \ return scnprintf(buf, PAGE_SIZE, "%d\n", \ wacom->led.select[SET_ID]); \ @@ -750,7 +750,7 @@ static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, static ssize_t wacom_##name##_luminance_store(struct device *dev, \ struct device_attribute *attr, const char *buf, size_t count) \ { \ - struct hid_device *hdev = container_of(dev, struct hid_device, dev);\ + struct hid_device *hdev = to_hid_device(dev);\ struct wacom *wacom = hid_get_drvdata(hdev); \ \ return wacom_luminance_store(wacom, &wacom->led.field, \ @@ -773,7 +773,7 @@ DEVICE_LUMINANCE_ATTR(buttons, img_lum); static ssize_t wacom_button_image_store(struct device *dev, int button_id, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct wacom *wacom = hid_get_drvdata(hdev); int err; unsigned len; @@ -1097,7 +1097,7 @@ static ssize_t wacom_show_speed(struct device *dev, struct device_attribute *attr, char *buf) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct wacom *wacom = hid_get_drvdata(hdev); return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed); @@ -1107,7 +1107,7 @@ static ssize_t wacom_store_speed(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct wacom *wacom = hid_get_drvdata(hdev); u8 new_speed; @@ -1131,7 +1131,7 @@ static ssize_t wacom_show_remote_mode(struct kobject *kobj, char *buf, int index) { struct device *dev = container_of(kobj->parent, struct device, kobj); - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct wacom *wacom = hid_get_drvdata(hdev); u8 mode; @@ -1242,7 +1242,7 @@ static ssize_t wacom_store_unpair_remote(struct kobject *kobj, { unsigned char selector = 0; struct device *dev = container_of(kobj->parent, struct device, kobj); - struct hid_device *hdev = container_of(dev, struct hid_device, dev); + struct hid_device *hdev = to_hid_device(dev); struct wacom *wacom = hid_get_drvdata(hdev); int err; -- cgit 1.4.1 From ba91a96718d17160890e161f702db6e60747248a Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Sun, 27 Dec 2015 17:25:22 +0800 Subject: HID: add a new helper to_hid_driver() Add a new helper to_hid_driver() and use it in hid-core.c. Signed-off-by: Geliang Tang Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 7 +++---- include/linux/hid.h | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index a6e24e00a37b..9d75205a511e 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -2077,7 +2077,7 @@ struct hid_dynid { static ssize_t store_new_id(struct device_driver *drv, const char *buf, size_t count) { - struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); + struct hid_driver *hdrv = to_hid_driver(drv); struct hid_dynid *dynid; __u32 bus, vendor, product; unsigned long driver_data = 0; @@ -2139,7 +2139,7 @@ static const struct hid_device_id *hid_match_device(struct hid_device *hdev, static int hid_bus_match(struct device *dev, struct device_driver *drv) { - struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver); + struct hid_driver *hdrv = to_hid_driver(drv); struct hid_device *hdev = to_hid_device(dev); return hid_match_device(hdev, hdrv) != NULL; @@ -2147,8 +2147,7 @@ static int hid_bus_match(struct device *dev, struct device_driver *drv) static int hid_device_probe(struct device *dev) { - struct hid_driver *hdrv = container_of(dev->driver, - struct hid_driver, driver); + struct hid_driver *hdrv = to_hid_driver(dev->driver); struct hid_device *hdev = to_hid_device(dev); const struct hid_device_id *id; int ret = 0; diff --git a/include/linux/hid.h b/include/linux/hid.h index 1472026367ed..75b66eccc692 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -717,6 +717,9 @@ struct hid_driver { struct device_driver driver; }; +#define to_hid_driver(pdrv) \ + container_of(pdrv, struct hid_driver, driver) + /** * hid_ll_driver - low level driver callbacks * @start: called on probe to start the device -- cgit 1.4.1 From d98ba98c4fbff91abb37eef628ccce0c218b4185 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Sun, 27 Dec 2015 17:25:23 +0800 Subject: HID: wiimote: use dev_to_wii() Use dev_to_wii() instead of open-coding it. Signed-off-by: Geliang Tang Signed-off-by: Jiri Kosina --- drivers/hid/hid-wiimote-modules.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c index 05e23c417d50..4390eee2ce84 100644 --- a/drivers/hid/hid-wiimote-modules.c +++ b/drivers/hid/hid-wiimote-modules.c @@ -296,14 +296,12 @@ static const struct wiimod_ops wiimod_battery = { static enum led_brightness wiimod_led_get(struct led_classdev *led_dev) { - struct wiimote_data *wdata; struct device *dev = led_dev->dev->parent; + struct wiimote_data *wdata = dev_to_wii(dev); int i; unsigned long flags; bool value = false; - wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev)); - for (i = 0; i < 4; ++i) { if (wdata->leds[i] == led_dev) { spin_lock_irqsave(&wdata->state.lock, flags); @@ -319,14 +317,12 @@ static enum led_brightness wiimod_led_get(struct led_classdev *led_dev) static void wiimod_led_set(struct led_classdev *led_dev, enum led_brightness value) { - struct wiimote_data *wdata; struct device *dev = led_dev->dev->parent; + struct wiimote_data *wdata = dev_to_wii(dev); int i; unsigned long flags; __u8 state, flag; - wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev)); - for (i = 0; i < 4; ++i) { if (wdata->leds[i] == led_dev) { flag = WIIPROTO_FLAG_LED(i + 1); -- cgit 1.4.1 From 2cf83833fc9cff04c50e402260b724b3f001d737 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Sun, 27 Dec 2015 17:25:24 +0800 Subject: HID: use kobj_to_dev() Use kobj_to_dev() instead of open-coding it. Signed-off-by: Geliang Tang Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 2 +- drivers/hid/hid-roccat-arvo.c | 6 ++---- drivers/hid/hid-roccat-common.c | 6 ++---- drivers/hid/hid-roccat-isku.c | 6 ++---- drivers/hid/hid-roccat-kone.c | 12 ++++-------- drivers/hid/hid-roccat-koneplus.c | 12 ++++-------- drivers/hid/hid-roccat-kovaplus.c | 12 ++++-------- drivers/hid/hid-roccat-lua.c | 4 ++-- drivers/hid/hid-roccat-pyra.c | 15 +++++---------- drivers/hid/wacom_sys.c | 4 ++-- 10 files changed, 28 insertions(+), 51 deletions(-) (limited to 'drivers/hid') diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 9d75205a511e..e847fb7f5d5d 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1571,7 +1571,7 @@ read_report_descriptor(struct file *filp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = container_of(kobj, struct device, kobj); + struct device *dev = kobj_to_dev(kobj); struct hid_device *hdev = to_hid_device(dev); if (off >= hdev->rsize) diff --git a/drivers/hid/hid-roccat-arvo.c b/drivers/hid/hid-roccat-arvo.c index 1948208fe038..329c5d1270f9 100644 --- a/drivers/hid/hid-roccat-arvo.c +++ b/drivers/hid/hid-roccat-arvo.c @@ -191,8 +191,7 @@ static ssize_t arvo_sysfs_write(struct file *fp, struct kobject *kobj, void const *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct arvo_device *arvo = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -211,8 +210,7 @@ static ssize_t arvo_sysfs_read(struct file *fp, struct kobject *kobj, void *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct arvo_device *arvo = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; diff --git a/drivers/hid/hid-roccat-common.c b/drivers/hid/hid-roccat-common.c index 02e28e9f4ea7..8155ac5fede2 100644 --- a/drivers/hid/hid-roccat-common.c +++ b/drivers/hid/hid-roccat-common.c @@ -134,8 +134,7 @@ ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj, char *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -158,8 +157,7 @@ ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj, void const *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; diff --git a/drivers/hid/hid-roccat-isku.c b/drivers/hid/hid-roccat-isku.c index bc62ed91e451..02db537f8f3e 100644 --- a/drivers/hid/hid-roccat-isku.c +++ b/drivers/hid/hid-roccat-isku.c @@ -121,8 +121,7 @@ static ssize_t isku_sysfs_read(struct file *fp, struct kobject *kobj, char *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct isku_device *isku = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -144,8 +143,7 @@ static ssize_t isku_sysfs_write(struct file *fp, struct kobject *kobj, void const *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct isku_device *isku = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c index c29265055ac1..bf4675a27396 100644 --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c @@ -269,8 +269,7 @@ static int kone_get_firmware_version(struct usb_device *usb_dev, int *result) static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); if (off >= sizeof(struct kone_settings)) @@ -294,8 +293,7 @@ static ssize_t kone_sysfs_read_settings(struct file *fp, struct kobject *kobj, static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval = 0, difference, old_profile; @@ -332,8 +330,7 @@ static BIN_ATTR(settings, 0660, kone_sysfs_read_settings, static ssize_t kone_sysfs_read_profilex(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); if (off >= sizeof(struct kone_profile)) @@ -353,8 +350,7 @@ static ssize_t kone_sysfs_read_profilex(struct file *fp, static ssize_t kone_sysfs_write_profilex(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct kone_device *kone = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); struct kone_profile *profile; diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c index 5e99fcdc71b9..09e8fc72aa1d 100644 --- a/drivers/hid/hid-roccat-koneplus.c +++ b/drivers/hid/hid-roccat-koneplus.c @@ -87,8 +87,7 @@ static ssize_t koneplus_sysfs_read(struct file *fp, struct kobject *kobj, char *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -113,8 +112,7 @@ static ssize_t koneplus_sysfs_write(struct file *fp, struct kobject *kobj, void const *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct koneplus_device *koneplus = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -193,8 +191,7 @@ static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); ssize_t retval; @@ -212,8 +209,7 @@ static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); ssize_t retval; diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c index 966047711fbf..43617fb28b87 100644 --- a/drivers/hid/hid-roccat-kovaplus.c +++ b/drivers/hid/hid-roccat-kovaplus.c @@ -128,8 +128,7 @@ static ssize_t kovaplus_sysfs_read(struct file *fp, struct kobject *kobj, char *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -154,8 +153,7 @@ static ssize_t kovaplus_sysfs_write(struct file *fp, struct kobject *kobj, void const *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -221,8 +219,7 @@ static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); ssize_t retval; @@ -240,8 +237,7 @@ static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); ssize_t retval; diff --git a/drivers/hid/hid-roccat-lua.c b/drivers/hid/hid-roccat-lua.c index 65e2e76bf2fe..ac1a7313e259 100644 --- a/drivers/hid/hid-roccat-lua.c +++ b/drivers/hid/hid-roccat-lua.c @@ -30,7 +30,7 @@ static ssize_t lua_sysfs_read(struct file *fp, struct kobject *kobj, char *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = container_of(kobj, struct device, kobj); + struct device *dev = kobj_to_dev(kobj); struct lua_device *lua = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -52,7 +52,7 @@ static ssize_t lua_sysfs_write(struct file *fp, struct kobject *kobj, void const *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = container_of(kobj, struct device, kobj); + struct device *dev = kobj_to_dev(kobj); struct lua_device *lua = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index 47d7e74231e5..b30aa7b82bf8 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c @@ -90,8 +90,7 @@ static ssize_t pyra_sysfs_read(struct file *fp, struct kobject *kobj, char *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -116,8 +115,7 @@ static ssize_t pyra_sysfs_write(struct file *fp, struct kobject *kobj, void const *buf, loff_t off, size_t count, size_t real_size, uint command) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval; @@ -191,8 +189,7 @@ static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); ssize_t retval; @@ -210,8 +207,7 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); ssize_t retval; @@ -248,8 +244,7 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { - struct device *dev = - container_of(kobj, struct device, kobj)->parent->parent; + struct device *dev = kobj_to_dev(kobj)->parent->parent; struct pyra_device *pyra = hid_get_drvdata(dev_get_drvdata(dev)); struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev)); int retval = 0; diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 4b7feb3022c1..a90de9b5d489 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -1130,7 +1130,7 @@ static ssize_t wacom_show_remote_mode(struct kobject *kobj, struct kobj_attribute *kattr, char *buf, int index) { - struct device *dev = container_of(kobj->parent, struct device, kobj); + struct device *dev = kobj_to_dev(kobj->parent); struct hid_device *hdev = to_hid_device(dev); struct wacom *wacom = hid_get_drvdata(hdev); u8 mode; @@ -1241,7 +1241,7 @@ static ssize_t wacom_store_unpair_remote(struct kobject *kobj, const char *buf, size_t count) { unsigned char selector = 0; - struct device *dev = container_of(kobj->parent, struct device, kobj); + struct device *dev = kobj_to_dev(kobj->parent); struct hid_device *hdev = to_hid_device(dev); struct wacom *wacom = hid_get_drvdata(hdev); int err; -- cgit 1.4.1 From 0bbfe28ad0fdc11dddae5fe6f6e4e91b7be06395 Mon Sep 17 00:00:00 2001 From: Jason Gerecke Date: Wed, 6 Jan 2016 13:25:53 -0800 Subject: HID: wacom: Use correct report to query pen ID from INTUOSHT2 devices Unlike other tablets which are compatible with the wacom_intuos_irq handler, INTUOSHT2 devices provide pen ID with report ID 8 instead of 5. To ensure wacom_intuos_schedule_prox_event works as intended for these tablets, we must be sure it uses the correct report ID in this case. Signed-off-by: Jason Gerecke Signed-off-by: Jiri Kosina --- drivers/hid/wacom_wac.c | 6 +++++- drivers/hid/wacom_wac.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'drivers/hid') diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index f70660465a54..3aeddc297652 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -439,11 +439,15 @@ exit: static void wacom_intuos_schedule_prox_event(struct wacom_wac *wacom_wac) { struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac); + struct wacom_features *features = &wacom_wac->features; struct hid_report *r; struct hid_report_enum *re; re = &(wacom->hdev->report_enum[HID_FEATURE_REPORT]); - r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1]; + if (features->type == INTUOSHT2) + r = re->report_id_hash[WACOM_REPORT_INTUOSHT2_ID]; + else + r = re->report_id_hash[WACOM_REPORT_INTUOS_ID1]; if (r) { hid_hw_request(wacom->hdev, r, HID_REQ_GET_REPORT); } diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index 3f60192e9272..25baa7f29599 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -70,6 +70,7 @@ #define WACOM_REPORT_DEVICE_LIST 16 #define WACOM_REPORT_INTUOS_PEN 16 #define WACOM_REPORT_REMOTE 17 +#define WACOM_REPORT_INTUOSHT2_ID 8 /* device quirks */ #define WACOM_QUIRK_BBTOUCH_LOWRES 0x0001 -- cgit 1.4.1