#if IS_ENABLED(CONFIG_USB_DWC2_EXTCON_NOTIFY)
struct extcon_dev *edev;
- struct work_struct extcon_work;
+ struct delayed_work extcon_work;
unsigned int extcon_state;
#endif /* CONFIG_DWC2_EXTCON_NOTIFY */
#endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
#include "core.h"
#include "hw.h"
+#define DWC2_EXTCON_NOTIFY_DELAY 10 /* msec */
+
static const unsigned int supported_cable[] = {
EXTCON_USB,
EXTCON_NONE,
return;
hsotg->extcon_state = on;
- queue_work(system_power_efficient_wq, &hsotg->extcon_work);
+
+ if (delayed_work_pending(&hsotg->extcon_work))
+ cancel_delayed_work(&hsotg->extcon_work);
+
+ queue_delayed_work(system_power_efficient_wq, &hsotg->extcon_work,
+ msecs_to_jiffies(DWC2_EXTCON_NOTIFY_DELAY));
}
void dwc2_gadget_cancel_extcon_work(struct dwc2_hsotg *hsotg)
if (!hsotg->params.g_extcon_notify)
return;
- cancel_work_sync(&hsotg->extcon_work);
+ cancel_delayed_work_sync(&hsotg->extcon_work);
}
static void dwc2_gadget_extcon_work(struct work_struct *work)
{
- struct dwc2_hsotg *hsotg = container_of(work, struct dwc2_hsotg,
+ struct dwc2_hsotg *hsotg = container_of(to_delayed_work(work),
+ struct dwc2_hsotg,
extcon_work);
extcon_set_state_sync(hsotg->edev, EXTCON_USB, hsotg->extcon_state);
hsotg->edev = edev;
- INIT_WORK(&hsotg->extcon_work, dwc2_gadget_extcon_work);
+ INIT_DELAYED_WORK(&hsotg->extcon_work, dwc2_gadget_extcon_work);
/*
* HACK: In order to give chance to setup gadget for user-space