Re: [PATCH 3/4] usb: Introduce DesignWare USB3 DRD Driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Felipe Balbi <balbi@...> writes:

< snip > 

> +int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
> +		unsigned cmd, struct dwc3_gadget_ep_cmd_params *params)
> +{
> +	struct dwc3_ep		*dep = dwc->eps[ep];
> +	unsigned long		timeout = 500;
> +	u32			reg;
> +
> +	dev_vdbg(dwc->dev, "%s: cmd '%s' params %08x %08x %08x\n",
> +			dep->name,
> +			dwc3_gadget_ep_cmd_string(cmd), params->param0.raw,
> +			params->param1.raw, params->param2.raw);
> +
> +	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0.raw);
> +	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1.raw);
> +	dwc3_writel(dwc->regs, DWC3_DEPCMDPAR2(ep), params->param2.raw);
> +
> +	dwc3_writel(dwc->regs, DWC3_DEPCMD(ep), cmd | DWC3_DEPCMD_CMDACT);
> +	do {
> +		reg = dwc3_readl(dwc->regs, DWC3_DEPCMD(ep));
> +		if (!(reg & DWC3_DEPCMD_CMDACT)) {
> +			dev_vdbg(dwc->dev, "CMD Compl Status %d DEPCMD %04x\n",
> +					((reg & 0xf000) >> 12), reg);
> +			return 0;
> +		}
> +
> +		/*
> +		 * XXX Figure out a sane timeout here. 500ms is way too much.
> +		 * We can't sleep here, because it is also called from
> +		 * interrupt context.
> +		 */
> +		timeout--;
> +		if (!timeout)
> +			return -ETIMEDOUT;
> +
> +		mdelay(1);

You really don't want to use mdelay here. After writing the command, on the
first read back it will likely have not completed yet, which means you will
take at least a 1ms delay for every command issued. Not to mention you are
potentially causing a 1ms interrupt latency. I suggest you use udelay(1)
instead, and bump up the timeout value to 10,000 or so. That's what I do in
my driver, and I haven't seen any bogus timeouts.

> +	} while (1);
> +}

-- 
Paul


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux