Skip to content

Commit 5bcb291

Browse files
Sevak Arakelyanwuliangfeng
authored andcommitted
UPSTREAM: usb: dwc2: gadget: Set TX FIFO depths to calculated defaults
Remove legacy DWC2_G_P_LEGACY_TX_FIFO_SIZE array for TX FIFOs. Update dwc2_set_param_tx_fifo_sizes function to calculate and assign default average FIFO depth to each member of g_tx_fifo_size array. Total FIFO size, EP Info block's size, FIFO operation mode and device operation mode are taken into consideration during the calculation. Change-Id: Iaf2c87b16e70b4d5cfefa24c7e4dcaa1a440b6bf Cc: Stefan Wahren <stefan.wahren@i2se.com> Signed-off-by: Sevak Arakelyan <sevaka@synopsys.com> Signed-off-by: John Youn <johnyoun@synopsys.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com> Signed-off-by: William Wu <william.wu@rock-chips.com> (cherry picked from commit c138ecfa6108edee17fabfa56285b00f66641659)
1 parent d87ffe3 commit 5bcb291

2 files changed

Lines changed: 108 additions & 9 deletions

File tree

drivers/usb/dwc2/core.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,6 @@ enum dwc2_lx_state {
262262
DWC2_L3, /* Off state */
263263
};
264264

265-
/*
266-
* Gadget periodic tx fifo sizes as used by legacy driver
267-
* EP0 is not included
268-
*/
269-
#define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
270-
768, 0, 0, 0, 0, 0, 0, 0}
271-
272265
/* Gadget ep0 states */
273266
enum dwc2_ep0_state {
274267
DWC2_EP0_SETUP,
@@ -1327,6 +1320,9 @@ extern int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
13271320
#define dwc2_is_device_connected(hsotg) (hsotg->connected)
13281321
int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg);
13291322
int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg);
1323+
int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg);
1324+
int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg);
1325+
int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg);
13301326
#else
13311327
static inline int dwc2_hsotg_remove(struct dwc2_hsotg *dwc2)
13321328
{ return 0; }
@@ -1348,6 +1344,12 @@ static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
13481344
{ return 0; }
13491345
static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
13501346
{ return 0; }
1347+
static inline int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
1348+
{ return 0; }
1349+
static inline int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
1350+
{ return 0; }
1351+
static inline int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg)
1352+
{ return 0; }
13511353
#endif
13521354

13531355
#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)

drivers/usb/dwc2/gadget.c

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,98 @@ static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg,
201201
local_irq_restore(flags);
202202
}
203203

204+
/**
205+
* dwc2_hsotg_tx_fifo_count - return count of TX FIFOs in device mode
206+
*/
207+
int dwc2_hsotg_tx_fifo_count(struct dwc2_hsotg *hsotg)
208+
{
209+
if (hsotg->hw_params.en_multiple_tx_fifo)
210+
/* In dedicated FIFO mode we need count of IN EPs */
211+
return (dwc2_readl(hsotg->regs + GHWCFG4) &
212+
GHWCFG4_NUM_IN_EPS_MASK) >> GHWCFG4_NUM_IN_EPS_SHIFT;
213+
else
214+
/* In shared FIFO mode we need count of Periodic IN EPs */
215+
return hsotg->hw_params.num_dev_perio_in_ep;
216+
}
217+
218+
/**
219+
* dwc2_hsotg_ep_info_size - return Endpoint Info Control block size in DWORDs
220+
*/
221+
static int dwc2_hsotg_ep_info_size(struct dwc2_hsotg *hsotg)
222+
{
223+
int val = 0;
224+
int i;
225+
u32 ep_dirs;
226+
227+
/*
228+
* Don't need additional space for ep info control registers in
229+
* slave mode.
230+
*/
231+
if (!using_dma(hsotg)) {
232+
dev_dbg(hsotg->dev, "Buffer DMA ep info size 0\n");
233+
return 0;
234+
}
235+
236+
/*
237+
* Buffer DMA mode - 1 location per endpoit
238+
* Descriptor DMA mode - 4 locations per endpoint
239+
*/
240+
ep_dirs = hsotg->hw_params.dev_ep_dirs;
241+
242+
for (i = 0; i <= hsotg->hw_params.num_dev_ep; i++) {
243+
val += ep_dirs & 3 ? 1 : 2;
244+
ep_dirs >>= 2;
245+
}
246+
247+
/* TODO set 4 locations per endpoint for Descriptor DMA mode */
248+
249+
return val;
250+
}
251+
252+
/**
253+
* dwc2_hsotg_tx_fifo_total_depth - return total FIFO depth available for
254+
* device mode TX FIFOs
255+
*/
256+
int dwc2_hsotg_tx_fifo_total_depth(struct dwc2_hsotg *hsotg)
257+
{
258+
int ep_info_size;
259+
int addr;
260+
int tx_addr_max;
261+
u32 np_tx_fifo_size;
262+
263+
np_tx_fifo_size = min_t(u32, hsotg->hw_params.dev_nperio_tx_fifo_size,
264+
hsotg->g_np_g_tx_fifo_sz);
265+
266+
/* Get Endpoint Info Control block size in DWORDs. */
267+
ep_info_size = dwc2_hsotg_ep_info_size(hsotg);
268+
tx_addr_max = hsotg->hw_params.total_fifo_size - ep_info_size;
269+
270+
addr = hsotg->g_rx_fifo_sz + np_tx_fifo_size;
271+
if (tx_addr_max <= addr)
272+
return 0;
273+
274+
return tx_addr_max - addr;
275+
}
276+
277+
/**
278+
* dwc2_hsotg_tx_fifo_average_depth - returns average depth of device mode
279+
* TX FIFOs
280+
*/
281+
int dwc2_hsotg_tx_fifo_average_depth(struct dwc2_hsotg *hsotg)
282+
{
283+
int tx_fifo_count;
284+
int tx_fifo_depth;
285+
286+
tx_fifo_depth = dwc2_hsotg_tx_fifo_total_depth(hsotg);
287+
288+
tx_fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
289+
290+
if (!tx_fifo_count)
291+
return tx_fifo_depth;
292+
else
293+
return tx_fifo_depth / tx_fifo_count;
294+
}
295+
204296
/**
205297
* dwc2_hsotg_init_fifo - initialise non-periodic FIFOs
206298
* @hsotg: The device instance.
@@ -3956,15 +4048,20 @@ static inline void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg) { }
39564048
int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
39574049
{
39584050
struct device *dev = hsotg->dev;
4051+
int depth_average;
4052+
int fifo_count;
39594053
int epnum;
39604054
int ret;
39614055
int i;
3962-
u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE;
39634056

39644057
/* Initialize to legacy fifo configuration values */
39654058
hsotg->g_rx_fifo_sz = 2048;
39664059
hsotg->g_np_g_tx_fifo_sz = 1024;
3967-
memcpy(&hsotg->g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo));
4060+
fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
4061+
depth_average = dwc2_hsotg_tx_fifo_average_depth(hsotg);
4062+
for (i = 1; i <= fifo_count; i++)
4063+
hsotg->g_tx_fifo_sz[i] = depth_average;
4064+
39684065
/* Device tree specific probe */
39694066
dwc2_hsotg_of_probe(hsotg);
39704067

0 commit comments

Comments
 (0)