From patchwork Fri Jan 20 15:20:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 9528757 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E91A960459 for ; Fri, 20 Jan 2017 15:21:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9FDC2656B for ; Fri, 20 Jan 2017 15:21:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE873286A9; Fri, 20 Jan 2017 15:21:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A2CE286A2 for ; Fri, 20 Jan 2017 15:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752494AbdATPU3 (ORCPT ); Fri, 20 Jan 2017 10:20:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57044 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752541AbdATPU2 (ORCPT ); Fri, 20 Jan 2017 10:20:28 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB56E3DBC3; Fri, 20 Jan 2017 15:20:28 +0000 (UTC) Received: from plouf.banquise.eu.com (ovpn-116-46.ams2.redhat.com [10.36.116.46]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0KFKLip004876; Fri, 20 Jan 2017 10:20:27 -0500 From: Benjamin Tissoires To: Jiri Kosina , Ping Cheng , Jason Gerecke , Aaron Skomra Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 3/4] HID: wacom: do not attempt to switch mode while in probe Date: Fri, 20 Jan 2017 16:20:13 +0100 Message-Id: <20170120152014.19775-4-benjamin.tissoires@redhat.com> In-Reply-To: <20170120152014.19775-1-benjamin.tissoires@redhat.com> References: <20170120152014.19775-1-benjamin.tissoires@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 20 Jan 2017 15:20:29 +0000 (UTC) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The Intuos Pro seems to not like when we set the features right after being powered up. Instead of waiting during probe, we can schedule the switch mode and LED control in a deferred worker so that we don't have the 5 secs of delay from USB when the device is not accessible. The USB timeout delays were really a pain because if you happen to unplug the tablet while it is still waiting, you are just adding 5 second timeouts to the USB stack. Which means that a new plug of the same tablet will also gets delayed, and will also attempt to access the hardware while in .probe(). So the tablet doesn't appear in the dmesg, the user unplug/replug it to make it appearing... and so on so forth. Really, this is for the best :) Signed-off-by: Benjamin Tissoires --- drivers/hid/wacom.h | 1 + drivers/hid/wacom_sys.c | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/hid/wacom.h b/drivers/hid/wacom.h index 020956c..3f650ce6 100644 --- a/drivers/hid/wacom.h +++ b/drivers/hid/wacom.h @@ -165,6 +165,7 @@ struct wacom { struct work_struct wireless_work; struct work_struct battery_work; struct work_struct remote_work; + struct delayed_work init_work; struct wacom_remote *remote; struct wacom_leds { struct wacom_group_leds *groups; diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c index 4a2c88d..6acb422 100644 --- a/drivers/hid/wacom_sys.c +++ b/drivers/hid/wacom_sys.c @@ -497,11 +497,11 @@ static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed, * from the tablet, it is necessary to switch the tablet out of this * mode and into one which sends the full range of tablet data. */ -static int wacom_query_tablet_data(struct hid_device *hdev, - struct wacom_features *features) +static int _wacom_query_tablet_data(struct wacom *wacom) { - struct wacom *wacom = hid_get_drvdata(hdev); + struct hid_device *hdev = wacom->hdev; struct wacom_wac *wacom_wac = &wacom->wacom_wac; + struct wacom_features *features = &wacom_wac->features; if (hdev->bus == BUS_BLUETOOTH) return wacom_bt_query_tablet_data(hdev, 1, features); @@ -1437,11 +1437,23 @@ static int wacom_initialize_leds(struct wacom *wacom) "cannot create sysfs group err: %d\n", error); return error; } - wacom_led_control(wacom); return 0; } +static void wacom_init_work(struct work_struct *work) +{ + struct wacom *wacom = container_of(work, struct wacom, init_work.work); + + _wacom_query_tablet_data(wacom); + wacom_led_control(wacom); +} + +static void wacom_query_tablet_data(struct wacom *wacom) +{ + schedule_delayed_work(&wacom->init_work, msecs_to_jiffies(1000)); +} + static enum power_supply_property wacom_battery_props[] = { POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_PRESENT, @@ -2115,7 +2127,7 @@ static int wacom_parse_and_register(struct wacom *wacom, bool wireless) if (!wireless) { /* Note that if query fails it is not a hard failure */ - wacom_query_tablet_data(hdev, features); + wacom_query_tablet_data(wacom); } /* touch only Bamboo doesn't support pen */ @@ -2445,6 +2457,7 @@ static int wacom_probe(struct hid_device *hdev, wacom->usbdev = dev; wacom->intf = intf; mutex_init(&wacom->lock); + INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work); INIT_WORK(&wacom->wireless_work, wacom_wireless_work); INIT_WORK(&wacom->battery_work, wacom_battery_work); INIT_WORK(&wacom->remote_work, wacom_remote_work); @@ -2486,6 +2499,7 @@ static void wacom_remove(struct hid_device *hdev) hid_hw_stop(hdev); + cancel_delayed_work_sync(&wacom->init_work); cancel_work_sync(&wacom->wireless_work); cancel_work_sync(&wacom->battery_work); cancel_work_sync(&wacom->remote_work); @@ -2503,12 +2517,11 @@ static void wacom_remove(struct hid_device *hdev) static int wacom_resume(struct hid_device *hdev) { struct wacom *wacom = hid_get_drvdata(hdev); - struct wacom_features *features = &wacom->wacom_wac.features; mutex_lock(&wacom->lock); /* switch to wacom mode first */ - wacom_query_tablet_data(hdev, features); + _wacom_query_tablet_data(wacom); wacom_led_control(wacom); mutex_unlock(&wacom->lock);