Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cc5f7bf authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "usb: dwc3: gadget: Ensure minimum delay between run/stop"

parents c9cd7422 2e6a2a5f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1149,6 +1149,7 @@ struct dwc3_scratchpad_array {
 * @bh_completion_time: time taken for taklet completion
 * @bh_handled_evt_cnt: no. of events handled by tasklet per interrupt
 * @bh_dbg_index: index for capturing bh_completion_time and bh_handled_evt_cnt
 * @last_run_stop: timestamp denoting the last run_stop update
 */
struct dwc3 {
	struct work_struct	drd_work;
@@ -1393,6 +1394,7 @@ struct dwc3 {
	u32			gen2_tx_de_emph1;
	u32			gen2_tx_de_emph2;
	u32			gen2_tx_de_emph3;
	ktime_t			last_run_stop;
};

#define INCRX_BURST_MODE 0
+12 −0
Original line number Diff line number Diff line
@@ -2058,6 +2058,8 @@ static int dwc3_device_core_soft_reset(struct dwc3 *dwc)
	return 0;
}

#define MIN_RUN_STOP_DELAY_MS 50

static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
{
	u32			reg, reg1;
@@ -2167,6 +2169,7 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
	struct dwc3		*dwc = gadget_to_dwc(g);
	unsigned long		flags;
	int			ret;
	ktime_t			diff;

	is_on = !!is_on;
	dwc->softconnect = is_on;
@@ -2185,6 +2188,15 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
	dbg_event(0xFF, "Pullup gsync",
		atomic_read(&dwc->dev->power.usage_count));

	diff = ktime_sub(ktime_get(), dwc->last_run_stop);
	if (ktime_to_ms(diff) < MIN_RUN_STOP_DELAY_MS) {
		dbg_event(0xFF, "waitBefRun_Stop",
			  MIN_RUN_STOP_DELAY_MS - ktime_to_ms(diff));
		msleep(MIN_RUN_STOP_DELAY_MS - ktime_to_ms(diff));
	}

	dwc->last_run_stop = ktime_get();

	/*
	 * Per databook, when we want to stop the gadget, if a control transfer
	 * is still in process, complete it and get the core into setup phase.