From patchwork Thu Jun 8 21:58:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yueyao Zhu X-Patchwork-Id: 9776613 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 034CC603B4 for ; Thu, 8 Jun 2017 21:59:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E82AB28599 for ; Thu, 8 Jun 2017 21:59:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD29C285AB; Thu, 8 Jun 2017 21:59:02 +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 7374828599 for ; Thu, 8 Jun 2017 21:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751940AbdFHV6m (ORCPT ); Thu, 8 Jun 2017 17:58:42 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35105 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751843AbdFHV6k (ORCPT ); Thu, 8 Jun 2017 17:58:40 -0400 Received: by mail-pf0-f194.google.com with SMTP id u26so6494836pfd.2; Thu, 08 Jun 2017 14:58:40 -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=KICcNKIc7YUYU+j6MtxIpPtaYey7eI9gZOtbCV2/Fno=; b=mskZUmPQhnRcvqh9oVQ6gUbyJULKvnjdjboup/1yY7DfWeTx5fY1t3kY8JDwLzPW0o F69Gxzlb+N3jTO24yOa8gM8RRRTUi5K/xYnH4ouj5I2SMRWa/w5GRFirDfUfuNlWq51K ST0FwS9nlGPQfBIG2qRfQKQRz4l8eP2UGgeT4pYdpxhIFUXkSep3Fyk6VsOwj/VSNPyH JHSs7b/XO6C0DRKd2qXf7yZpZoYFB6nGNervZ9LQyK0MCHmqTQx1zW4kXgx6k62YH9ZJ x4Yziu3jnxB4mpbMRgrKluWQq2wFiz4QPMMFjpM5IPvau6ZqGF8GDE/Ap2FzltX7+ux5 HO4w== 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=KICcNKIc7YUYU+j6MtxIpPtaYey7eI9gZOtbCV2/Fno=; b=nFnS3niiMnwRA6JLn1x4Vaqj1NzS1eHBYkKy2HMYRmgsSh5CLHRAJOyJrJ9mrcmiE2 C6PCCzl2Phq09U4bcOdQ46VTx13eqY9d2DOcLI7qBTA/knWGqqL88RwnNLUN/JRR3NnO SwsaGw1O36Q3+Y13I5KS8o/Ozcs6M23vyfnhxxSmTlvnoy9K2sqERCG9LUSMJx95wgix vzN5R2D3knxjdC/sSRIKM0bBfLR7nEfUmylLBBGuNbOBaRBFz3cyLRMpLnrYBsTXQv06 +vwI3l1n77lMDIm8dkp+xFhRQFKzMwdBbZT7s+J9+WCSacsw9uV68g/VSVci7FjRNjjK B4hA== X-Gm-Message-State: AODbwcAoHqTa2Zg+bnxBLHx4fZhJmZAePuL4AWHzvJaE9Gu0BPxIZxCe EEqfJMF71j7rgQ== X-Received: by 10.101.86.11 with SMTP id l11mr6932133pgs.202.1496959119881; Thu, 08 Jun 2017 14:58:39 -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.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jun 2017 14:58:39 -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 1/3] USB: add API for interface driver to vote for autosuspend Date: Thu, 8 Jun 2017 14:58:26 -0700 Message-Id: <20170608215828.130455-2-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 An interface driver can allow/disallow autosuspend power control for an interface, and if all the interfaces of the active configuration are allowed for autosuspend, autosuspend should be enabled on the usb device. Signed-off-by: Yueyao Zhu --- drivers/usb/core/driver.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb.h | 10 +++++++++ 2 files changed, 65 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index eb87a259d55c..c0a20f03ad01 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1545,6 +1545,61 @@ void usb_disable_autosuspend(struct usb_device *udev) } EXPORT_SYMBOL_GPL(usb_disable_autosuspend); +/** + * usb_allow_interface_autosuspend - allow autosuspend for the interface + * @intf: the USB interface which may be autosuspended + * + * This routine votes the interface to allow autosuspend. If all interfaces + * of the active configuration of the usb device allow autosuspend, autosuspend + * is enabled on the usb device through usb_enable_autosuspend(). + * + * The only interface driver that will enable autosuspend on the + * USB device is the last in loop during interface driver probe, or midway + * through life if an interface changes its autosuspend status, and all other + * interfaces have already said yes. + * + * The caller must hold @udev's device lock. + */ +void usb_allow_interface_autosuspend(struct usb_interface *intf) +{ + struct usb_device *udev = interface_to_usbdev(intf); + struct usb_host_config *actconfig = udev->actconfig; + int i; + bool udev_autosuspend = true; + + intf->autosuspend = 1; + + for (i = 0; i < actconfig->desc.bNumInterfaces; ++i) { + if (!actconfig->interface[i]->autosuspend) { + udev_autosuspend = false; + break; + } + } + + if (udev_autosuspend) + usb_enable_autosuspend(udev); +} +EXPORT_SYMBOL_GPL(usb_allow_interface_autosuspend); + +/** + * usb_disallow_interface_autosuspend - disallow autosuspend for the interface + * @intf: the USB interface which may not be autosuspended + * + * This routine votes the interface to disallow autosuspend. This immediately + * disables autosuspend on the usb device through usb_enable_autosuspend(). + * + * The caller must hold @udev's device lock. + */ +void usb_disallow_interface_autosuspend(struct usb_interface *intf) +{ + struct usb_device *udev = interface_to_usbdev(intf); + + intf->autosuspend = 0; + + usb_disable_autosuspend(udev); +} +EXPORT_SYMBOL_GPL(usb_disallow_interface_autosuspend); + /** * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces * @udev: the usb_device to autosuspend diff --git a/include/linux/usb.h b/include/linux/usb.h index cb9fbd54386e..723ab9130637 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -253,6 +253,7 @@ struct usb_interface { unsigned needs_binding:1; /* needs delayed unbind/rebind */ unsigned resetting_device:1; /* true: bandwidth alloc after reset */ unsigned authorized:1; /* used for interface authorization */ + unsigned autosuspend:1; /* interface allows autosuspend */ struct device dev; /* interface specific device info */ struct device *usb_dev; @@ -741,6 +742,9 @@ static inline bool usb_acpi_power_manageable(struct usb_device *hdev, int index) extern void usb_enable_autosuspend(struct usb_device *udev); extern void usb_disable_autosuspend(struct usb_device *udev); +extern void usb_allow_interface_autosuspend(struct usb_interface *intf); +extern void usb_disallow_interface_autosuspend(struct usb_interface *intf); + extern int usb_autopm_get_interface(struct usb_interface *intf); extern void usb_autopm_put_interface(struct usb_interface *intf); extern int usb_autopm_get_interface_async(struct usb_interface *intf); @@ -760,6 +764,12 @@ static inline int usb_enable_autosuspend(struct usb_device *udev) static inline int usb_disable_autosuspend(struct usb_device *udev) { return 0; } +static inline void usb_allow_interface_autosuspend(struct usb_interface *intf) +{ } +static inline void usb_disallow_interface_autosuspend( + struct usb_interface *intf) +{ } + static inline int usb_autopm_get_interface(struct usb_interface *intf) { return 0; } static inline int usb_autopm_get_interface_async(struct usb_interface *intf)