Skip to content

add usb fifo config in dts for dwc2 USB driver #96206

@jean12332

Description

@jean12332

Is your feature request related to a problem? Please describe.

The current code defaults to assuming that endpoint number==txFifo number, which may cause issues with EP using TXFF.95500

95654In this PR, it is proposed to select the minimum available TXFF for EP, and then configure addr and depth. But when deciding new txffaddress, it always needs to look for current highest largest address.
if we can refer to the method of using DTS like Linux to configure the entire DFIFO area first, and users can make the optimal configuration according to their own usage scenarios. In this way, the IN EP only selects txff without rearranging the address and depth.

Describe the solution you'd like

linux config like this

  1. DTS property:
usb: usb{
		g-rx-fifo-size = <512>;
		g-np-tx-fifo-size = <256>;
		g-tx-fifo-size = <128 120>;
		status = "okay";
	};
  1. all fifo config
    in linux/v6.16.7/source/drivers/usb/dwc2/platform.c
* Detect config values from hardware */
retval = dwc2_get_hwparams(hsotg);

dwc2_init_params //linux/v6.16.7/source/drivers/usb/dwc2/params.c
->dwc2_get_device_properties() // Read in device properties.
-> dwc2_check_params //Check if the parameter complies with HW restrictions
Now we have a complete set of size configurations for rxff&txff

  1. when init the usb core
    dwc2_hsotg_init // linux/v6.16.7/source/drivers/usb/dwc2/gadget.c
    -> dwc2_hsotg_init_fifo //Configure addr and depth for entire DFIFO according to their respective size,and flush all fifo

4.dwc2_hsotg_ep_enable

for (i = 1; i <= fifo_count; ++i) {
	if (hsotg->fifo_map & (1 << i))
		continue;
	val = dwc2_readl(hsotg, DPTXFSIZN(i));
	val = (val >> FIFOSIZE_DEPTH_SHIFT) * 4;
	if (val < size)
		continue;
	/* Search for smallest acceptable fifo */
	if (val < fifo_size) {
		fifo_size = val;
		fifo_index = i;
	}
}
epctrl &= ~(DXEPCTL_TXFNUM_LIMIT << DXEPCTL_TXFNUM_SHIFT);
hsotg->fifo_map |= 1 << fifo_index;
epctrl |= DXEPCTL_TXFNUM(fifo_index);
hs_ep->fifo_index = fifo_index;
hs_ep->fifo_size = fifo_size;

5.dwc2_hsotg_ep_disable

hsotg->fifo_map &= ~(1 << hs_ep->fifo_index);
hs_ep->fifo_index = 0;
hs_ep->fifo_size = 0;

Describe alternatives you've considered

We can refer to

  1. Use DTS to determine the entire DFIFO partition, allowing users to determine the required configurations themselves
  2. EP only select TXFF through txffnum without modifying txffadd/depth.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions