From: Sevak Arakelyan <sev...@synopsys.com>

Add dwc2_check_param_tx_fifo_sizes function which validates
the members of g_tx_fifo_size array and sets to average or
default values if it is needed.

Cc: Stefan Wahren <stefan.wah...@i2se.com>
Signed-off-by: Sevak Arakelyan <sev...@synopsys.com>
Signed-off-by: John Youn <johny...@synopsys.com>
---
 drivers/usb/dwc2/params.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index 016fff0cb887..2990c347289f 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -427,6 +427,40 @@ static void dwc2_check_param_phy_utmi_width(struct 
dwc2_hsotg *hsotg)
                dwc2_set_param_phy_utmi_width(hsotg);
 }
 
+static void dwc2_check_param_tx_fifo_sizes(struct dwc2_hsotg *hsotg)
+{
+       int fifo_count;
+       int fifo;
+       int min;
+       u32 total = 0;
+       u32 dptxfszn;
+
+       fifo_count = dwc2_hsotg_tx_fifo_count(hsotg);
+       min = hsotg->hw_params.en_multiple_tx_fifo ? 16 : 4;
+
+       for (fifo = 1; fifo <= fifo_count; fifo++)
+               total += hsotg->params.g_tx_fifo_size[fifo];
+
+       if (total > dwc2_hsotg_tx_fifo_total_depth(hsotg) || !total) {
+               dev_warn(hsotg->dev, "%s: Invalid parameter g-tx-fifo-size, 
setting to default average\n",
+                        __func__);
+               dwc2_set_param_tx_fifo_sizes(hsotg);
+       }
+
+       for (fifo = 1; fifo <= fifo_count; fifo++) {
+               dptxfszn = (dwc2_readl(hsotg->regs + DPTXFSIZN(fifo)) &
+                       FIFOSIZE_DEPTH_MASK) >> FIFOSIZE_DEPTH_SHIFT;
+
+               if (hsotg->params.g_tx_fifo_size[fifo] < min ||
+                   hsotg->params.g_tx_fifo_size[fifo] >  dptxfszn) {
+                       dev_warn(hsotg->dev, "%s: Invalid parameter 
g_tx_fifo_size[%d]=%d\n",
+                                __func__, fifo,
+                                hsotg->params.g_tx_fifo_size[fifo]);
+                       hsotg->params.g_tx_fifo_size[fifo] = dptxfszn;
+               }
+       }
+}
+
 #define CHECK_RANGE(_param, _min, _max, _def) do {                     \
                if ((hsotg->params._param) < (_min) ||                  \
                    (hsotg->params._param) > (_max)) {                  \
@@ -496,6 +530,7 @@ static void dwc2_check_params(struct dwc2_hsotg *hsotg)
                CHECK_RANGE(g_np_tx_fifo_size,
                            16, hw->dev_nperio_tx_fifo_size,
                            hw->dev_nperio_tx_fifo_size);
+               dwc2_check_param_tx_fifo_sizes(hsotg);
        }
 }
 
-- 
2.11.0

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

Reply via email to