All of lore.kernel.org
 help / color / mirror / Atom feed
From: Puma Hsu <pumahsu@google.com>
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 <pumahsu@google.com>
Subject: [PATCH 2/2] usb: core: add implementations for usb suspend/resume hooks
Date: Wed, 14 Dec 2022 15:06:50 +0800	[thread overview]
Message-ID: <20221214070650.703793-3-pumahsu@google.com> (raw)
In-Reply-To: <20221214070650.703793-1-pumahsu@google.com>

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 <pumahsu@google.com>
---
 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 <pumahsu@google.com>
+ */
+
+#include <linux/usb.h>
+#include "usb.h"
+
+extern int usb_dev_register_vendor_ops(struct usb_device_vendor_ops *vendor_ops);
+
+static bool usb_device_vendor_suspend(struct usb_device *udev, pm_message_t msg)
+{
+	bool usb_playback = false;
+	bool usb_capture = false;
+	bool handled = false;
+
+	if (!udev)
+		return handled;
+
+	/*
+	 * Note: Our private driver provides APIs to know the device is in audio playback
+	 * or capture.
+	 *
+	 * usb_playback = usb_audio_playback_enabled();
+	 * usb_capture = usb_audio_capture_enabled();
+	 */
+
+	/*
+	 * Note: When the USB audio is working, we will not let the usb device suspend.
+	 * Return handled = true so that the System core can it's suspend process.
+	 */
+	if (usb_playback || usb_capture) {
+		dev_info(&udev->dev, "%s: skip suspend process (playback:%d,capture:%d)\n",
+			 __func__, usb_playback, usb_capture);
+		handled = true;
+	}
+
+	return handled;
+}
+
+static bool usb_device_vendor_resume(struct usb_device *udev, pm_message_t msg)
+{
+	bool handled = 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 == USB_STATE_SUSPENDED) {
+		handled = false;
+	} else {
+		dev_info(&udev->dev, "%s: skip resume process\n", __func__);
+		handled = true;
+	}
+
+	return handled;
+}
+
+static struct usb_device_vendor_ops usb_dev_vendor_ops = {
+	.usb_dev_suspend = usb_device_vendor_suspend,
+	.usb_dev_resume = usb_device_vendor_resume,
+};
+
+int usb_vendor_helper_init(void)
+{
+	return usb_dev_register_vendor_ops(&usb_dev_vendor_ops);
+}
-- 
2.39.0.rc1.256.g54fd8350bd-goog


  parent reply	other threads:[~2022-12-14  7:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14  7:06 [PATCH 0/2] add vendor hooks for usb suspend and resume Puma Hsu
2022-12-14  7:06 ` [PATCH 1/2] usb: core: add vendor hook " Puma Hsu
2022-12-14  7:20   ` Puma Hsu
2022-12-14  7:36   ` Christoph Hellwig
2022-12-14  8:20   ` Greg KH
2022-12-14  9:38   ` kernel test robot
2022-12-14  9:38   ` kernel test robot
2022-12-14 10:59   ` kernel test robot
2022-12-14  7:06 ` Puma Hsu [this message]
2022-12-14  8:21   ` [PATCH 2/2] usb: core: add implementations for usb suspend/resume hooks Greg KH
2022-12-14  9:48   ` kernel test robot
2022-12-19 12:32   ` kernel test robot
2022-12-14  8:17 ` [PATCH 0/2] add vendor hooks for usb suspend and resume Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221214070650.703793-3-pumahsu@google.com \
    --to=pumahsu@google.com \
    --cc=albertccwang@google.com \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=howardyen@google.com \
    --cc=leejj@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=raychi@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.