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

Commit 1fbcd4d0 authored by Mayank Rana's avatar Mayank Rana Committed by Hemant Kumar
Browse files

dwc3: gadget: Use TXFIFO register based on used dwc3 version



TXFIFO register's bit(15) is reserved on usb31 version. Hence this
change starts using dwc3 version based TXFIFO size related macro
to update TXFIFO register while resizing TXFIFO of USB endpoint.

Change-Id: I1b9fb9d109f1ad8e1fd4bc23c75341bdec912c10
Signed-off-by: default avatarMayank Rana <mrana@codeaurora.org>
Signed-off-by: default avatarHemant Kumar <hemantk@codeaurora.org>
parent 72f784ce
Loading
Loading
Loading
Loading
+16 −4
Original line number Original line Diff line number Diff line
@@ -633,6 +633,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
	int ret, num;
	int ret, num;
	u32 reg;
	u32 reg;
	struct dwc3_ep	*dep;
	struct dwc3_ep	*dep;
	int size;


	cfg = le16_to_cpu(ctrl->wValue);
	cfg = le16_to_cpu(ctrl->wValue);


@@ -649,15 +650,26 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
		if (dwc->needs_fifo_resize && dwc->tx_fifo_size) {
		if (dwc->needs_fifo_resize && dwc->tx_fifo_size) {
			/* Read ep0IN related TXFIFO size */
			/* Read ep0IN related TXFIFO size */
			dep = dwc->eps[1];
			dep = dwc->eps[1];
			dwc->last_fifo_depth = dep->fifo_depth =
			size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0));
					(dwc3_readl(dwc->regs,
			if (dwc3_is_usb31(dwc))
					    DWC3_GTXFIFOSIZ(0)) & 0xFFFF);
				dep->fifo_depth = DWC31_GTXFIFOSIZ_TXFDEF(size);
			else
				dep->fifo_depth = DWC3_GTXFIFOSIZ_TXFDEF(size);

			dwc->last_fifo_depth = dep->fifo_depth;
			/* Clear existing TXFIFO for all IN eps except ep0 */
			/* Clear existing TXFIFO for all IN eps except ep0 */
			for (num = 3; num < min_t(int, dwc->num_eps,
			for (num = 3; num < min_t(int, dwc->num_eps,
						DWC3_ENDPOINTS_NUM); num += 2) {
						DWC3_ENDPOINTS_NUM); num += 2) {
				dep = dwc->eps[num];
				dep = dwc->eps[num];
				size = 0;
				/* Don't change TXFRAMNUM on usb31 version */
				if (dwc3_is_usb31(dwc))
					size = dwc3_readl(dwc->regs,
						DWC3_GTXFIFOSIZ(num >> 1)) &
						DWC31_GTXFIFOSIZ_TXFRAMNUM;

				dwc3_writel(dwc->regs,
				dwc3_writel(dwc->regs,
						DWC3_GTXFIFOSIZ(num >> 1), 0);
					DWC3_GTXFIFOSIZ(num >> 1), size);
				dep->fifo_depth = 0;
				dep->fifo_depth = 0;


				dev_dbg(dwc->dev, "%s(): %s fifo_depth:%x\n",
				dev_dbg(dwc->dev, "%s(): %s fifo_depth:%x\n",
+18 −5
Original line number Original line Diff line number Diff line
@@ -199,7 +199,7 @@ void dwc3_ep_inc_deq(struct dwc3_ep *dep)
int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc, struct dwc3_ep *dep)
int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc, struct dwc3_ep *dep)
{
{
	int		fifo_size, mdwidth, max_packet = 1024;
	int		fifo_size, mdwidth, max_packet = 1024;
	int		tmp, mult = 1;
	int		tmp, mult = 1, size;


	if (!dwc->needs_fifo_resize || !dwc->tx_fifo_size)
	if (!dwc->needs_fifo_resize || !dwc->tx_fifo_size)
		return 0;
		return 0;
@@ -231,9 +231,18 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc, struct dwc3_ep *dep)
	tmp = ((max_packet + mdwidth) * mult) + mdwidth;
	tmp = ((max_packet + mdwidth) * mult) + mdwidth;
	fifo_size = DIV_ROUND_UP(tmp, mdwidth);
	fifo_size = DIV_ROUND_UP(tmp, mdwidth);
	dep->fifo_depth = fifo_size;
	dep->fifo_depth = fifo_size;
	fifo_size |= (dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0)) & 0xffff0000)

						+ (dwc->last_fifo_depth << 16);
	size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(0));
	dwc->last_fifo_depth += (fifo_size & 0xffff);
	if (dwc3_is_usb31(dwc))
		size = DWC31_GTXFIFOSIZ_TXFDEF(size);
	else
		size = DWC3_GTXFIFOSIZ_TXFDEF(size);

	fifo_size |= (size + (dwc->last_fifo_depth << 16));
	if (dwc3_is_usb31(dwc))
		dwc->last_fifo_depth += DWC31_GTXFIFOSIZ_TXFDEF(fifo_size);
	else
		dwc->last_fifo_depth += DWC3_GTXFIFOSIZ_TXFDEF(fifo_size);


	dev_dbg(dwc->dev, "%s ep_num:%d last_fifo_depth:%04x fifo_depth:%d\n",
	dev_dbg(dwc->dev, "%s ep_num:%d last_fifo_depth:%04x fifo_depth:%d\n",
		dep->endpoint.name, dep->endpoint.ep_num, dwc->last_fifo_depth,
		dep->endpoint.name, dep->endpoint.ep_num, dwc->last_fifo_depth,
@@ -246,7 +255,11 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc, struct dwc3_ep *dep)
		dev_err(dwc->dev, "Fifosize(%d) > RAM size(%d) %s depth:%d\n",
		dev_err(dwc->dev, "Fifosize(%d) > RAM size(%d) %s depth:%d\n",
			(dwc->last_fifo_depth * mdwidth), dwc->tx_fifo_size,
			(dwc->last_fifo_depth * mdwidth), dwc->tx_fifo_size,
			dep->endpoint.name, fifo_size);
			dep->endpoint.name, fifo_size);
		dwc->last_fifo_depth -= (fifo_size & 0xffff);
		if (dwc3_is_usb31(dwc))
			fifo_size = DWC31_GTXFIFOSIZ_TXFDEF(fifo_size);
		else
			fifo_size = DWC3_GTXFIFOSIZ_TXFDEF(fifo_size);
		dwc->last_fifo_depth -= fifo_size;
		dep->fifo_depth = 0;
		dep->fifo_depth = 0;
		WARN_ON(1);
		WARN_ON(1);
		return -ENOMEM;
		return -ENOMEM;