From patchwork Thu Jun 8 21:58:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yueyao Zhu X-Patchwork-Id: 9776685 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 4856C60393 for ; Thu, 8 Jun 2017 22:04:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36EBB285B5 for ; Thu, 8 Jun 2017 22:04:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29C0F285C7; Thu, 8 Jun 2017 22:04:15 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 D264A285B5 for ; Thu, 8 Jun 2017 22:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751753AbdFHWEA (ORCPT ); Thu, 8 Jun 2017 18:04:00 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36244 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751919AbdFHV6l (ORCPT ); Thu, 8 Jun 2017 17:58:41 -0400 Received: by mail-pg0-f67.google.com with SMTP id v18so5812890pgb.3; Thu, 08 Jun 2017 14:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IMiPmMXQFbxPSbkLqGL33jCat3iQUn8oqftcmcwHSW0=; b=eODBJ69P4ZgCodU/aWHaO86R7//I6lPLtVTLZrJvKqy5Ht/O7A/nxRseiyaaS1UvK/ ti+/xClw8G6IA69CwzJcHIGjmUUe6WEk6Hf6Tc6YUwm7xhqOAtLC7aihpARDXp94tTmz 3qoFRH8lBg3JEx7Z+fWAQbZzIkv4+EW6B+y0fmvNBafCpK49o4vlRVEPB58bYsLdmoG5 8jLrrZq2V529cIvqiQJ6tfE6mH13UJls/XVYLFi0ogtSq9QaNVpTZHyBbxA9RjhWhcVL W/qPeAI5BSW60zBjDzRoxLYpb+/3MepSUn39vo49Paa29Y7z0ay03KOwoRsl5gNLGn1N o+/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IMiPmMXQFbxPSbkLqGL33jCat3iQUn8oqftcmcwHSW0=; b=pUdaOrJLYM1qcogZdkY3HshcRttTm1x4iXcOG41NOL9ROUYr3H9FQnAKBMKItMqS9m F2U989yvuHAg3XtkFGg2jTtv666lR7z4jEh4TuF/OFy8NRB1VOkel06xZnHf1g479S1+ EN3vtV1B1aZIw9YTTc96wWT6fLQD4MZDi8QiBxfkWyr6Z2wYo8JAANTziHqCWbGjwU36 37WLCdAIVIetFcOqvHOtvEocdKCS4B/M5mCV1LOpE8tOZiPeZM0ZYjMIanZEu+qw9KDX WUv09izZMVsS7Js4+fgtx4AaYC2cx6DjnfBzxIVtfr1frnMKEocVETjDUZ6IHA+tshC5 iMKw== X-Gm-Message-State: AODbwcBtafUIp6DfQeh639RLIB8UtuuNIGh1rCEE51zcAclsJE4ewtOJ XOLveh9G4edKNQ== X-Received: by 10.99.63.5 with SMTP id m5mr36134956pga.68.1496959120742; Thu, 08 Jun 2017 14:58:40 -0700 (PDT) Received: from yueyao0.mtv.corp.google.com ([100.98.126.197]) by smtp.gmail.com with ESMTPSA id u73sm10826385pgb.24.2017.06.08.14.58.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jun 2017 14:58:40 -0700 (PDT) From: Yueyao Zhu To: Jiri Kosina , Benjamin Tissoires , Greg Kroah-Hartman , Jaroslav Kysela , Takashi Iwai Cc: linux-usb@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Chant , Badhri Jagan Sridharan , Dmitry Torokhov , Yueyao Zhu Subject: [PATCH 2/3] HID: usbhid: enable autosuspend for devices whose ... Date: Thu, 8 Jun 2017 14:58:27 -0700 Message-Id: <20170608215828.130455-3-yueyao.zhu@gmail.com> X-Mailer: git-send-email 2.13.0.506.g27d5fe0cd-goog In-Reply-To: <20170608215828.130455-1-yueyao.zhu@gmail.com> References: <20170608215828.130455-1-yueyao.zhu@gmail.com> 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 From: Yueyao Zhu usage pages only points to CONSUMER. This allows autosuspend to be enabled and thus power saved on CONSUMER hid devices. Yet hid devices use other usage pages are not affected, e.g. keyboard, mouse. Signed-off-by: Yueyao Zhu --- drivers/hid/usbhid/hid-core.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 83772fa7d92a..f2696b4098b5 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -1270,6 +1270,31 @@ static struct hid_ll_driver usb_hid_driver = { .idle = usbhid_idle, }; +static bool usbhid_usage_is_consumer(struct hid_device *hid) +{ + int i; + struct hid_report_enum *input_report_enum = + hid->report_enum + HID_INPUT_REPORT; + struct list_head *report_list = &input_report_enum->report_list; + struct hid_report *report; + unsigned int usage_page; + + if (list_empty(report_list)) + return false; + + list_for_each_entry(report, report_list, list) { + for (i = 0; i < report->maxfield; i++) { + /* only checks Application field */ + usage_page = + report->field[i]->application & HID_USAGE_PAGE; + if (usage_page != HID_UP_CONSUMER) + return false; + } + } + + return true; +} + static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id *id) { struct usb_host_interface *interface = intf->cur_altsetting; @@ -1363,6 +1388,18 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id * goto err_free; } + /* + * Autosuspend interfaces which have only consumer usage page inputs. + * This allows autosuspending devices which adhere to the Android USB + * headset spec while not autosuspending general keyboards, mice, and + * joysticks which may misbehave. + */ + if (usbhid_usage_is_consumer(hid)) { + intf->needs_remote_wakeup = true; + usb_allow_interface_autosuspend(intf); + hid_info(hid, "autosuspend enabled on the hid interface\n"); + } + return 0; err_free: kfree(usbhid);