From 358b59f1bce213fe1d83e09ae2e1fba718682e4a Mon Sep 17 00:00:00 2001 From: Puma Hsu Date: Sat, 10 Jul 2021 16:11:10 +0800 Subject: [PATCH] ANDROID: usb: Add vendor hook for usb suspend and resume Add the hook that vendor can design and bypass the suspend/resume. When the bypass is set, skip the orignal suspend/resume methods. In mobile, a co-processor can be used with USB audio, and ACPU may be able to sleep in such condition to improve power consumption. We will need vendor hook to support this. Bug: 192774581 Signed-off-by: Puma Hsu Change-Id: Ic62a8a1e662bbe3fb0aa17af7491daace0b9f18a (cherry picked from commit 98085b5dd8afd1ec65500eb091d061a3fee21b84) --- drivers/android/vendor_hooks.c | 2 ++ drivers/usb/core/driver.c | 12 ++++++++++++ include/trace/hooks/usb.h | 9 +++++++++ 3 files changed, 23 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 660cefd48bd2..e2dbf71dccd3 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -312,3 +312,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_get_timer); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_modify_src_caps); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_log); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sound_usb_support_cpu_suspend); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_usb_dev_suspend); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_usb_dev_resume); diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 072968c40ade..1f0b98e164aa 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -34,6 +34,7 @@ #include "usb.h" +#include /* * Adds a new dynamic USBdevice ID to this driver, @@ -1399,11 +1400,16 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) int status = 0; int i = 0, n = 0; struct usb_interface *intf; + int bypass = 0; if (udev->state == USB_STATE_NOTATTACHED || udev->state == USB_STATE_SUSPENDED) goto done; + trace_android_rvh_usb_dev_suspend(udev, msg, &bypass); + if (bypass) + goto done; + /* Suspend all the interfaces and then udev itself */ if (udev->actconfig) { n = udev->actconfig->desc.bNumInterfaces; @@ -1500,11 +1506,17 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg) int status = 0; int i; struct usb_interface *intf; + int bypass = 0; if (udev->state == USB_STATE_NOTATTACHED) { status = -ENODEV; goto done; } + + trace_android_vh_usb_dev_resume(udev, msg, &bypass); + if (bypass) + goto done; + udev->can_submit = 1; /* Resume the device */ diff --git a/include/trace/hooks/usb.h b/include/trace/hooks/usb.h index fe379b174289..a5d7440a60a9 100644 --- a/include/trace/hooks/usb.h +++ b/include/trace/hooks/usb.h @@ -15,6 +15,15 @@ struct usb_device; DECLARE_HOOK(android_vh_usb_new_device_added, TP_PROTO(struct usb_device *udev, int *err), TP_ARGS(udev, err)); + +DECLARE_RESTRICTED_HOOK(android_rvh_usb_dev_suspend, + TP_PROTO(struct usb_device *udev, pm_message_t msg, int *bypass), + TP_ARGS(udev, msg, bypass), 1); + +DECLARE_HOOK(android_vh_usb_dev_resume, + TP_PROTO(struct usb_device *udev, pm_message_t msg, int *bypass), + TP_ARGS(udev, msg, bypass)); + #endif /* _TRACE_HOOK_USB_H */ /* This part must be outside protection */ #include