From 2e5c19bb2218893be9411414bbb51fb976231046 Mon Sep 17 00:00:00 2001 From: mengguanjun Date: Mon, 21 Oct 2024 16:40:51 +0800 Subject: [PATCH] usb gadget add/remove event Signed-off-by: mengguanjun --- drivers/usb/core/notify.c | 9 +++++++++ drivers/usb/dwc3/gadget.c | 2 ++ include/linux/usb.h | 3 +++ 3 files changed, 14 insertions(+) diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c index e6143663778f..8256d576c762 100644 --- a/drivers/usb/core/notify.c +++ b/drivers/usb/core/notify.c @@ -66,3 +66,12 @@ void usb_notify_remove_bus(struct usb_bus *ubus) { blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus); } + +void usb_notify_online_status(bool online) +{ + if (online) { + blocking_notifier_call_chain(&usb_notifier_list, USB_GADGET_ADD, NULL); + } else { + blocking_notifier_call_chain(&usb_notifier_list, USB_GADGET_REMOVE, NULL); + } +} diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 28f49400f3e8..abcc53a0779c 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -4360,6 +4360,7 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, { switch (event->type) { case DWC3_DEVICE_EVENT_DISCONNECT: + usb_notify_online_status(false); dwc3_gadget_disconnect_interrupt(dwc); break; case DWC3_DEVICE_EVENT_RESET: @@ -4367,6 +4368,7 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, break; case DWC3_DEVICE_EVENT_CONNECT_DONE: dwc3_gadget_conndone_interrupt(dwc); + usb_notify_online_status(true); break; case DWC3_DEVICE_EVENT_WAKEUP: dwc3_gadget_wakeup_interrupt(dwc, event->event_info); diff --git a/include/linux/usb.h b/include/linux/usb.h index a21074861f91..9e75513e4f7e 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -2056,8 +2056,11 @@ static inline int usb_translate_errors(int error_code) #define USB_DEVICE_REMOVE 0x0002 #define USB_BUS_ADD 0x0003 #define USB_BUS_REMOVE 0x0004 +#define USB_GADGET_ADD 0x0005 +#define USB_GADGET_REMOVE 0x0006 extern void usb_register_notify(struct notifier_block *nb); extern void usb_unregister_notify(struct notifier_block *nb); +extern void usb_notify_online_status(bool online); /* debugfs stuff */ extern struct dentry *usb_debug_root; -- Gitee