From 0e10f65fa989fb9251df8dc0e85bb401c6a030b0 Mon Sep 17 00:00:00 2001 From: Yunxian He Date: Fri, 8 Apr 2022 17:57:01 +0800 Subject: [PATCH] ANDROID: usb: Add vendor hook when core detect a new device Add vendor hook when core detect a new device. Vendor side can use this hook to do several things. Our Unisoc ASIC had some drawback. most scene, we use DWC3 controller and associated PHY, when digital headset plug in, we need end the enumeration and switch to another controller and phy. Using this hook, we can do the switch easily and efficiently. Bug: 229330749 Change-Id: I1cba28b43ff1b1f5ac0138c0bb743f3d8e9f1e4b Signed-off-by: Yunxian He --- drivers/android/vendor_hooks.c | 2 ++ drivers/usb/core/hub.c | 6 ++++++ include/trace/hooks/usb.h | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 include/trace/hooks/usb.h diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index f284701fb4a4..1c4639a347ea 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -58,6 +58,7 @@ #include #include #include +#include /* * Export tracepoints that act as a bare tracehook (ie: have no trace event @@ -280,3 +281,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_audio_usb_offload_disconnect); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_atomic_remove_fb); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_drm_atomic_check_modeset); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_get_thermal_zone_device); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_usb_new_device_added); diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index ac6c5ccfe1cb..bac8eab7ed0b 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "hub.h" #include "otg_productlist.h" @@ -2539,6 +2540,11 @@ int usb_new_device(struct usb_device *udev) dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", udev->devnum, udev->bus->busnum, (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); + + trace_android_vh_usb_new_device_added(udev, &err); + if (err) + goto fail; + /* export the usbdev device-node for libusb */ udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); diff --git a/include/trace/hooks/usb.h b/include/trace/hooks/usb.h new file mode 100644 index 000000000000..5f5dd68d981d --- /dev/null +++ b/include/trace/hooks/usb.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM usb +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH trace/hooks +#if !defined(_TRACE_HOOK_USB_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_USB_H +#include +/* + * Following tracepoints are not exported in tracefs and provide a + * mechanism for vendor modules to hook and extend functionality + */ +struct usb_device; +DECLARE_HOOK(android_vh_usb_new_device_added, + TP_PROTO(struct usb_device *udev, int *err), + TP_ARGS(udev, err)); +#endif /* _TRACE_HOOK_USB_H */ +/* This part must be outside protection */ +#include