From f20bc63b4f836134bf9694f66532e84b3afed09f Mon Sep 17 00:00:00 2001 From: Terry_Xia Date: Fri, 3 Dec 2021 11:39:35 +0800 Subject: [PATCH 1/2] feat: modify usb device gadget and device attach notify Signed-off-by: wu-chengwen --- drivers/usb/core/notify.c | 9 +++++++++ drivers/usb/dwc3/Kconfig | 1 - drivers/usb/dwc3/gadget.c | 8 +++++--- 3 files changed, 14 insertions(+), 4 deletions(-) mode change 100644 => 100755 drivers/usb/core/notify.c mode change 100644 => 100755 drivers/usb/dwc3/Kconfig mode change 100644 => 100755 drivers/usb/dwc3/gadget.c diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c old mode 100644 new mode 100755 index e6143663778f..f362e814e945 --- 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); + } +} \ No newline at end of file diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig old mode 100644 new mode 100755 index 7a2304565a73..3b198085af8b --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -44,7 +44,6 @@ config USB_DWC3_GADGET config USB_DWC3_DUAL_ROLE bool "Dual Role mode" depends on ((USB=y || USB=USB_DWC3) && (USB_GADGET=y || USB_GADGET=USB_DWC3)) - depends on (EXTCON=y || EXTCON=USB_DWC3) help This is the default mode of working of DWC3 controller where both host and gadget features are enabled. diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c old mode 100644 new mode 100755 index b75fe568096f..7d1bb2677fea --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3640,6 +3640,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); @@ -3661,9 +3662,10 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc, * Ignore suspend event until the gadget enters into * USB_STATE_CONFIGURED state. */ - if (dwc->gadget->state >= USB_STATE_CONFIGURED) - dwc3_gadget_suspend_interrupt(dwc, - event->event_info); + if (dwc->gadget->state >= USB_STATE_CONFIGURED){ + dwc3_gadget_suspend_interrupt(dwc, event->event_info); + usb_notify_online_status(false); + } } break; case DWC3_DEVICE_EVENT_SOF: -- Gitee From 20a473c544d93489fe9bed64b7fd0903e06bc85f Mon Sep 17 00:00:00 2001 From: wu-chengwen Date: Fri, 3 Dec 2021 15:22:45 +0800 Subject: [PATCH 2/2] feat: modify usb device gadget and device attach notify Signed-off-by: wu-chengwen --- include/linux/usb.h | 5 +++++ 1 file changed, 5 insertions(+) mode change 100644 => 100755 include/linux/usb.h diff --git a/include/linux/usb.h b/include/linux/usb.h old mode 100644 new mode 100755 index d6a41841b93e..27db1a969865 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -2019,9 +2019,14 @@ 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