From nobody Thu Sep 18 00:01:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2BC4C4167B for ; Wed, 14 Dec 2022 07:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237516AbiLNHHq (ORCPT ); Wed, 14 Dec 2022 02:07:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237201AbiLNHHg (ORCPT ); Wed, 14 Dec 2022 02:07:36 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5366B6570 for ; Tue, 13 Dec 2022 23:07:26 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3b0af5bcbd3so196520377b3.0 for ; Tue, 13 Dec 2022 23:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=N1ar1dADbdU6DENQz+1O8bfsS7Rj7vcSTdNKfRYLHK4=; b=Y0BnuVQuCo6vSf8eHHnJ/qgMABwFE1KDrHYvbMKq59Qi7/2tfcLob/qtmQg0ble+kM +B5jGvL/4ZcC/N1TEHOEjfIzUEcxavRVb4coNc0sVe/ia0lz1lp5MgYmHwaYoGoRhWCC yXfwxeC8nLVZHghItn7IhxQtyOqhcb5Ze1tEjEBnbt7qlGWUrRqqZS+3BPMnGPIBazf9 7Zk4y4JpQ4d/HS5Gi8/2tWOVQ9FlysDDESiH8XxUA5MsiJSloMSX8lEVVkgLWebC5GFl AkF/WVJzD4QY5fycLmTDd0cekmAT232RQs11zitmIFaGryuFMozYq/drxC2gd0641jlS G49A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=N1ar1dADbdU6DENQz+1O8bfsS7Rj7vcSTdNKfRYLHK4=; b=oe6LaJlnTUSVAoV65aVLAkeuDI3/IWEKpCBFBLyV+dvVHYMj0LTxayacOdV4EWJpKc HKJn+TSW3f4XKeDQgUAwgFA8GeEa53KjENtK2/zZ7esYXWHqY1e/FdghfTAbAtgTDNbY CQYJCu9apn3LqOBu4sBLjwagiitZ7XUoXTGZVN79EA4KF7T7iwalPQ79FT7lNGrXWr5r hkAWNRnGdg/YDY2pDfr0KzoSNjSWKfAsp+n+e6fO2fTfqjUr00TmG/zacKvpngB89qhE tACIXfRiPzO6bZY6s/6BQcs7OvsHG2+txEowVzeXUQHT4kcCSHy1FDI5xUwvn9Jndy+7 SpbQ== X-Gm-Message-State: ANoB5plDOXVGiQzdWErhDBWacCvdUaHTEEbJ/FLi/IfZmBMSn/bYJf45 L8EmCww30mswVKBqLutH+wMaLuwzxli4 X-Google-Smtp-Source: AA0mqf6EKelmu9XOooSmJS/Moj+JzDWjsUGWhdROmBGqXOy5TIevw9k2GKGyMbX2jZXqPUJWagflCR/9hM8u X-Received: from pumahsu.ntc.corp.google.com ([2401:fa00:fc:202:cb1:cbe3:3a49:1751]) (user=pumahsu job=sendgmr) by 2002:a25:74c7:0:b0:6fb:67c7:33e1 with SMTP id p190-20020a2574c7000000b006fb67c733e1mr35977414ybc.255.1671001645440; Tue, 13 Dec 2022 23:07:25 -0800 (PST) Date: Wed, 14 Dec 2022 15:06:49 +0800 In-Reply-To: <20221214070650.703793-1-pumahsu@google.com> Message-Id: <20221214070650.703793-2-pumahsu@google.com> Mime-Version: 1.0 References: <20221214070650.703793-1-pumahsu@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog Subject: [PATCH 1/2] usb: core: add vendor hook for usb suspend and resume From: Puma Hsu To: gregkh@linuxfoundation.org, mka@chromium.org, dianders@chromium.org Cc: albertccwang@google.com, raychi@google.com, howardyen@google.com, leejj@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Puma Hsu Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the hooks that vendor can design and bypass the suspend/resume. When the handled is set, skip the original suspend/resume process. In mobile, a co-processor can be used for USB audio. When the co-processor is working for USB audio, the co-processor is the user/owner of the USB driver, and the ACPU is able to sleep in such condition to improve power consumption. In original process, the ACPU will suspend/resume until the USB suspend/resume. We add the hooks, so we can control USB suspend/resume without affecting the ACPU. Signed-off-by: Puma Hsu --- drivers/usb/core/Makefile | 2 +- drivers/usb/core/driver.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.h | 5 +++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index 7d338e9c0657..f48f646cd874 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile @@ -3,7 +3,7 @@ # Makefile for USB Core files and filesystem # =20 -usbcore-y :=3D usb.o hub.o hcd.o urb.o message.o driver.o +usbcore-y :=3D usb.o hub.o hcd.o urb.o message.o driver.o usb-hooks-impl-g= oog.o usbcore-y +=3D config.o file.o buffer.o sysfs.o endpoint.o usbcore-y +=3D devio.o notify.o generic.o quirks.o devices.o usbcore-y +=3D phy.o port.o diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 7e7e119c253f..3d2cfb6c2277 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -35,6 +35,25 @@ #include "usb.h" =20 =20 +static struct usb_device_vendor_ops *usb_dev_vendor_ops; + +int usb_dev_register_vendor_ops(struct usb_device_vendor_ops *vendor_ops) +{ + if (vendor_ops =3D=3D NULL) + return -EINVAL; + + usb_dev_vendor_ops =3D vendor_ops; + return 0; +} +EXPORT_SYMBOL_GPL(usb_dev_register_vendor_ops); + +struct usb_device_vendor_ops *usb_vendor_get_ops(void) +{ + return usb_dev_vendor_ops; +} +EXPORT_SYMBOL_GPL(usb_vendor_get_ops); + + /* * Adds a new dynamic USBdevice ID to this driver, * and cause the driver to probe for all devices again. @@ -1400,11 +1419,19 @@ static int usb_suspend_both(struct usb_device *udev= , pm_message_t msg) int status =3D 0; int i =3D 0, n =3D 0; struct usb_interface *intf; + bool handled; + struct usb_device_vendor_ops *ops =3D usb_vendor_get_ops(); =20 if (udev->state =3D=3D USB_STATE_NOTATTACHED || udev->state =3D=3D USB_STATE_SUSPENDED) goto done; =20 + if (ops && ops->usb_dev_suspend) { + handled =3D ops->usb_dev_suspend(udev, msg); + if (handled) + goto done; + } + /* Suspend all the interfaces and then udev itself */ if (udev->actconfig) { n =3D udev->actconfig->desc.bNumInterfaces; @@ -1501,11 +1528,20 @@ static int usb_resume_both(struct usb_device *udev,= pm_message_t msg) int status =3D 0; int i; struct usb_interface *intf; + bool handled; + struct usb_device_vendor_ops *ops =3D usb_vendor_get_ops(); =20 if (udev->state =3D=3D USB_STATE_NOTATTACHED) { status =3D -ENODEV; goto done; } + + if (ops && ops->usb_dev_resume) { + handled =3D ops->usb_dev_resume(udev, msg); + if (handled) + goto done; + } + udev->can_submit =3D 1; =20 /* Resume the device */ diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h index 82538daac8b8..9ccb8683071d 100644 --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h @@ -220,3 +220,8 @@ extern acpi_handle usb_get_hub_port_acpi_handle(struct = usb_device *hdev, static inline int usb_acpi_register(void) { return 0; }; static inline void usb_acpi_unregister(void) { }; #endif + +struct usb_device_vendor_ops { + bool (*usb_dev_suspend)(struct usb_device *udev, pm_message_t msg); + bool (*usb_dev_resume)(struct usb_device *udev, pm_message_t msg); +}; --=20 2.39.0.rc1.256.g54fd8350bd-goog From nobody Thu Sep 18 00:01:03 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14420C4332F for ; Wed, 14 Dec 2022 07:08:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237535AbiLNHIF (ORCPT ); Wed, 14 Dec 2022 02:08:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237499AbiLNHHl (ORCPT ); Wed, 14 Dec 2022 02:07:41 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12EEFB1D0 for ; Tue, 13 Dec 2022 23:07:32 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-348608c1cd3so198713077b3.10 for ; Tue, 13 Dec 2022 23:07:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xwk10ScpIHN3TWeoCLrvB+vfcB+zS8T8ixzqnuDxGoQ=; b=S+ZBF0aetxStcQmCeGXzwYt5EYr7NqwSqJG8AaIaHEbqVpEpSuzSjYiSUhXEiNbImV Ea2GwSaPoQtaG8OF5d5huZF63W3lOkhWYFBhUN4HaXVfI5kKpUCHmE56fYPUv4HE3TRZ AJGNUmrvAUpDemnzYe+M/w6HXUE6IyRoOn00f/cCeosedEWCZ7NRvAQBBQzInBW+LvqH RMOyqbRFhjmyfTvTiUzIdN02SO9Q24DA+MljcTeC7wSNU9/sYR4oFxxCQxXgiJqW6kPo Fa0u60FF0bOFRWFEHRXhwPiB9SWZ8B1p3GspHFf5Ehg484k4HqLEH+gP3sh1YIarVrMD 8S7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xwk10ScpIHN3TWeoCLrvB+vfcB+zS8T8ixzqnuDxGoQ=; b=yxhkPFaAm6sblGgBqRdfAZ5zMccYA+znTMXUQlsE39sEJlB9/3EV9q1Rad5syiWVbS wA/k4ZVrbaeUgVeOZS/++ttoMi2UbZTw16kqBNZLwA9wbMtA3UEctkY/qg/6XQppFhA0 mkuKHLjPwqihpgW1/a+ZKCearFhzK4RosbKqRvFwS4GQ5nHlL8pBgCL1wq/wYTb0UCG/ YTNsZkQn92Kt8tg495FMZAuA6pTRJW8rbaCz+xTHXNdr/OzgjCfEovTir4X+uU6LFT0q Al0xxffqLAbbBMAm+SEGTHFMOKDwn4tdfXhqFXtTGRTSIGt8E7vEIZSfc80HkmAXMKah /3ig== X-Gm-Message-State: ANoB5pkZxSHQsSnqMvLwOo1lCKnx0FNba9mAz0FgbKJ8ADPTHLAvmf1q L7TYuDePAs+BAb3F/xrQWWB/Gg5AhLrr X-Google-Smtp-Source: AA0mqf7avn4Qaej3IKAY16Oodzg8JnzSJ4uRyWnL1FJxff/YhffcMhV0BRcdqYY6ra/CH47c9Wb2HHr+juUv X-Received: from pumahsu.ntc.corp.google.com ([2401:fa00:fc:202:cb1:cbe3:3a49:1751]) (user=pumahsu job=sendgmr) by 2002:a5b:d0d:0:b0:6fe:bdb1:1529 with SMTP id y13-20020a5b0d0d000000b006febdb11529mr22480701ybp.628.1671001651345; Tue, 13 Dec 2022 23:07:31 -0800 (PST) Date: Wed, 14 Dec 2022 15:06:50 +0800 In-Reply-To: <20221214070650.703793-1-pumahsu@google.com> Message-Id: <20221214070650.703793-3-pumahsu@google.com> Mime-Version: 1.0 References: <20221214070650.703793-1-pumahsu@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog Subject: [PATCH 2/2] usb: core: add implementations for usb suspend/resume hooks From: Puma Hsu To: gregkh@linuxfoundation.org, mka@chromium.org, dianders@chromium.org Cc: albertccwang@google.com, raychi@google.com, howardyen@google.com, leejj@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Puma Hsu Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In mobile, a co-processor can be used for USB audio. When the co-processor is working for USB audio, the co-processor is the user/owner of the USB driver, and the ACPU is able to sleep in such condition to improve power consumption. In order to support this, we implement the hooks to handle USB suspend/resume requests. This commit introduces two hook implementations: - usb_device_vendor_suspend() Determine whether we should skip suspend request according to the status of USB audio playback/capture. Return: - true: let driver.c know that we "handled" and it can just return succeeded to ACPU to continue system suspend process. - false: let driver.c know that it still run original suspend process. - usb_device_vendor_resume() Determine whether we should skip resume request according to the USB device's suspend state. Return: - true: let driver.c know that it doesn't need to run resume process. - false: let driver.c know that it still run original resume process. Signed-off-by: Puma Hsu --- drivers/usb/core/usb-hooks-impl-goog.c | 72 ++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 drivers/usb/core/usb-hooks-impl-goog.c diff --git a/drivers/usb/core/usb-hooks-impl-goog.c b/drivers/usb/core/usb-= hooks-impl-goog.c new file mode 100644 index 000000000000..89dc360babed --- /dev/null +++ b/drivers/usb/core/usb-hooks-impl-goog.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Google Corp. + * + * Author: + * Puma Hsu + */ + +#include +#include "usb.h" + +extern int usb_dev_register_vendor_ops(struct usb_device_vendor_ops *vendo= r_ops); + +static bool usb_device_vendor_suspend(struct usb_device *udev, pm_message_= t msg) +{ + bool usb_playback =3D false; + bool usb_capture =3D false; + bool handled =3D false; + + if (!udev) + return handled; + + /* + * Note: Our private driver provides APIs to know the device is in audio = playback + * or capture. + * + * usb_playback =3D usb_audio_playback_enabled(); + * usb_capture =3D usb_audio_capture_enabled(); + */ + + /* + * Note: When the USB audio is working, we will not let the usb device su= spend. + * Return handled =3D true so that the System core can it's suspend proce= ss. + */ + if (usb_playback || usb_capture) { + dev_info(&udev->dev, "%s: skip suspend process (playback:%d,capture:%d)\= n", + __func__, usb_playback, usb_capture); + handled =3D true; + } + + return handled; +} + +static bool usb_device_vendor_resume(struct usb_device *udev, pm_message_t= msg) +{ + bool handled =3D false; + + if (!udev) + return handled; + + /* + * Note: If the udev didn't suspend actually, we don't need to do resume. + */ + if (udev->port_is_suspended || udev->state =3D=3D USB_STATE_SUSPENDED) { + handled =3D false; + } else { + dev_info(&udev->dev, "%s: skip resume process\n", __func__); + handled =3D true; + } + + return handled; +} + +static struct usb_device_vendor_ops usb_dev_vendor_ops =3D { + .usb_dev_suspend =3D usb_device_vendor_suspend, + .usb_dev_resume =3D usb_device_vendor_resume, +}; + +int usb_vendor_helper_init(void) +{ + return usb_dev_register_vendor_ops(&usb_dev_vendor_ops); +} --=20 2.39.0.rc1.256.g54fd8350bd-goog