From patchwork Tue Mar 22 13:13:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Henrik Rydberg X-Patchwork-Id: 87942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 975D9B6F75 for ; Wed, 23 Mar 2011 03:24:01 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Q24N7-00077v-Ag; Tue, 22 Mar 2011 16:23:53 +0000 Received: from ch-smtp04.sth.basefarm.net ([80.76.153.5]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Q21Lt-0004JJ-Io for kernel-team@lists.ubuntu.com; Tue, 22 Mar 2011 13:10:25 +0000 Received: from c83-254-52-20.bredband.comhem.se ([83.254.52.20]:47675 helo=polaris) by ch-smtp04.sth.basefarm.net with smtp (Exim 4.73) (envelope-from ) id 1Q21Lo-0000ar-EL for kernel-team@lists.ubuntu.com; Tue, 22 Mar 2011 14:10:24 +0100 Received: by polaris (sSMTP sendmail emulation); Tue, 22 Mar 2011 14:14:14 +0100 From: "Henrik Rydberg" To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/4] HID: hid-ntrig: init settle and mode check Date: Tue, 22 Mar 2011 14:13:59 +0100 Message-Id: <1300799640-5131-4-git-send-email-rydberg@euromail.se> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1300799640-5131-1-git-send-email-rydberg@euromail.se> References: <1300799640-5131-1-git-send-email-rydberg@euromail.se> X-Originating-IP: 83.254.52.20 X-Scan-Result: No virus found in message 1Q21Lo-0000ar-EL. X-Scan-Signature: ch-smtp04.sth.basefarm.net 1Q21Lo-0000ar-EL 1e8d72966eeecf90ee845443c76f437e X-Mailman-Approved-At: Tue, 22 Mar 2011 16:23:51 +0000 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com From: Rafi Rubin Adding a wait before the wakeup signal. As a precautionary measure sanity check the current sensor mode. If needed reset it to "dual". When the device is responding poorly and needs the wakeup call, it was missing it. Giving it a chance to settle first improves the chances that signal gets through. Signed-off-by: Rafi Rubin Tested-by: Peter Hutterer Signed-off-by: Jiri Kosina Signed-off-by: Henrik Rydberg --- drivers/hid/hid-ntrig.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c index 6de7f95..a8aef90 100644 --- a/drivers/hid/hid-ntrig.c +++ b/drivers/hid/hid-ntrig.c @@ -75,6 +75,36 @@ static int ntrig_version_string(unsigned char *raw, char *buf) return sprintf(buf, "%u.%u.%u.%u.%u", a, b, c, d, e); } +static inline int ntrig_get_mode(struct hid_device *hdev) +{ + struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT]. + report_id_hash[0x0d]; + + if (!report) + return -EINVAL; + + usbhid_submit_report(hdev, report, USB_DIR_IN); + usbhid_wait_io(hdev); + return (int)report->field[0]->value[0]; +} + +static inline void ntrig_set_mode(struct hid_device *hdev, const int mode) +{ + struct hid_report *report; + __u8 mode_commands[4] = { 0xe, 0xf, 0x1b, 0x10 }; + + if (mode < 0 || mode > 3) + return; + + report = hdev->report_enum[HID_FEATURE_REPORT]. + report_id_hash[mode_commands[mode]]; + + if (!report) + return; + + usbhid_submit_report(hdev, report, USB_DIR_IN); +} + static void ntrig_report_version(struct hid_device *hdev) { int ret; @@ -452,8 +482,19 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id) /* This is needed for devices with more recent firmware versions */ report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0x0a]; - if (report) - usbhid_submit_report(hdev, report, USB_DIR_OUT); + if (report) { + /* Let the device settle to ensure the wakeup message gets + * through */ + usbhid_wait_io(hdev); + usbhid_submit_report(hdev, report, USB_DIR_IN); + + /* + * Sanity check: if the current mode is invalid reset it to + * something reasonable. + */ + if (ntrig_get_mode(hdev) >= 4) + ntrig_set_mode(hdev, 3); + } ntrig_report_version(hdev);