[v2,2/2] usb: core: add implementations for usb suspend/resume hooks
Commit Message
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
Comments
Again, this is never actually registered. It it not tied to an device.
What is the point of all this? Are you trying to fool us?
new file mode 100644
@@ -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);
+}