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

Commit 24c7dad1 authored by Kyle Yan's avatar Kyle Yan Committed by Gerrit - the friendly Code Review server
Browse files

Merge "usb: dwc3: Adjust TX FIFO allocation" into msm-4.8

parents cbb20132 db943d68
Loading
Loading
Loading
Loading
+31 −7
Original line number Diff line number Diff line
@@ -202,32 +202,44 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
	int		fifo_size;
	int		mdwidth;
	int		num;
	int		num_eps;
	struct usb_composite_dev *cdev = get_gadget_data(&dwc->gadget);

	if (!dwc->needs_fifo_resize)
		return 0;

	/* gadget.num_eps never be greater than dwc->num_in_eps */
	num_eps = min_t(int, dwc->num_in_eps,
			cdev->config->num_ineps_used + 1);
	ram1_depth = DWC3_RAM1_DEPTH(dwc->hwparams.hwparams7);
	mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);

	/* MDWIDTH is represented in bits, we need it in bytes */
	mdwidth >>= 3;

	dev_dbg(dwc->dev, "%s: num eps: %d\n", __func__, num_eps);

	/*
	 * FIXME For now we will only allocate 1 wMaxPacketSize space
	 * for each enabled endpoint, later patches will come to
	 * improve this algorithm so that we better use the internal
	 * FIFO space
	 */
	for (num = 0; num < dwc->num_in_eps; num++) {
	for (num = 0; num < num_eps; num++) {
		/* bit0 indicates direction; 1 means IN ep */
		struct dwc3_ep	*dep = dwc->eps[(num << 1) | 1];
		int		mult = 1;
		int		tmp;
		int		max_packet = 1024;

		if (!(dep->flags & DWC3_EP_ENABLED))
			continue;
		if (!(dep->flags & DWC3_EP_ENABLED)) {
			dev_warn(dwc->dev, "ep%dIn not enabled", num);
			tmp = max_packet + mdwidth;
			goto resize_fifo;
		}

		if (usb_endpoint_xfer_bulk(dep->endpoint.desc)
		if (((dep->endpoint.maxburst > 1) &&
				usb_endpoint_xfer_bulk(dep->endpoint.desc))
				|| usb_endpoint_xfer_isoc(dep->endpoint.desc))
			mult = 3;

@@ -237,12 +249,13 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
		 * Make sure that's true somehow and change FIFO allocation
		 * accordingly.
		 *
		 * If we have Bulk or Isochronous endpoints, we want
		 * them to be able to be very, very fast. So we're giving
		 * If we have Bulk (burst only) or Isochronous endpoints, we
		 * want them to be able to be very, very fast. So we're giving
		 * those endpoints a fifo_size which is enough for 3 full
		 * packets
		 */
		tmp = mult * (dep->endpoint.maxpacket + mdwidth);
resize_fifo:
		tmp += mdwidth;

		fifo_size = DIV_ROUND_UP(tmp, mdwidth);
@@ -252,9 +265,20 @@ int dwc3_gadget_resize_tx_fifos(struct dwc3 *dwc)
		dwc3_trace(trace_dwc3_gadget, "%s: Fifo Addr %04x Size %d",
				dep->name, last_fifo_depth, fifo_size & 0xffff);

		last_fifo_depth += (fifo_size & 0xffff);
		if (dwc->tx_fifo_size &&
				(last_fifo_depth >= dwc->tx_fifo_size)) {
			/*
			 * Fifo size allocated exceeded available RAM size.
			 * Hence return error.
			 */
			dev_err(dwc->dev, "Fifosize(%d) > available RAM(%d)\n",
					last_fifo_depth, dwc->tx_fifo_size);
			return -ENOMEM;
		}

		dwc3_writel(dwc->regs, DWC3_GTXFIFOSIZ(num), fifo_size);

		last_fifo_depth += (fifo_size & 0xffff);
	}

	return 0;
+6 −0
Original line number Diff line number Diff line
@@ -888,6 +888,8 @@ static int set_config(struct usb_composite_dev *cdev,

	usb_gadget_set_state(gadget, USB_STATE_CONFIGURED);
	cdev->config = c;
	c->num_ineps_used = 0;
	c->num_outeps_used = 0;

	/* Initialize all interfaces by setting them to altsetting zero. */
	for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) {
@@ -916,6 +918,10 @@ static int set_config(struct usb_composite_dev *cdev,
			addr = ((ep->bEndpointAddress & 0x80) >> 3)
			     |  (ep->bEndpointAddress & 0x0f);
			set_bit(addr, f->endpoints);
			if (usb_endpoint_dir_in(ep))
				c->num_ineps_used++;
			else
				c->num_outeps_used++;
		}

		result = f->set_alt(f, tmp, 0);
+4 −0
Original line number Diff line number Diff line
@@ -338,6 +338,10 @@ struct usb_configuration {
	unsigned		fullspeed:1;
	unsigned		superspeed_plus:1;
	struct usb_function	*interface[MAX_CONFIG_INTERFACES];

	/* number of in and out eps used in this configuration */
	int			num_ineps_used;
	int			num_outeps_used;
};

int usb_add_config(struct usb_composite_dev *,