From: Dinh Nguyen <dingu...@altera.com>

Remove reading the fifo sizes from dts in platform.c

Add dwc2_calculate_dynamic_fifo

Conflicts:

        arch/arm/boot/dts/socfpga.dtsi
        drivers/staging/dwc2/core.c
---
 arch/arm/boot/dts/socfpga.dtsi |    8 -------
 drivers/usb/dwc2/core.c        |   49 ++++++++++++++++++++++++++++++++++++----
 drivers/usb/dwc2/platform.c    |   20 ----------------
 3 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/arch/arm/boot/dts/socfpga.dtsi b/arch/arm/boot/dts/socfpga.dtsi
index 03e7a6d..e4c0f72 100644
--- a/arch/arm/boot/dts/socfpga.dtsi
+++ b/arch/arm/boot/dts/socfpga.dtsi
@@ -860,10 +860,6 @@
                        clock-names = "otg";
                        phys = <&usbphy0>;
                        phy-names = "usb2-phy";
-                       enable-dynamic-fifo = <1>;
-                       host-rx-fifo-size = <0xa00>;
-                       host-perio-tx-fifo-size = <0xa00>;
-                       host-nperio-tx-fifo-size = <0xa00>;
                        dma-desc-enable = <0>;
                        status = "disabled";
                };
@@ -876,10 +872,6 @@
                        clock-names = "otg";
                        phys = <&usbphy0>;
                        phy-names = "usb2-phy";
-                       enable-dynamic-fifo = <1>;
-                       host-rx-fifo-size = <0xa00>;
-                       host-perio-tx-fifo-size = <0xa00>;
-                       host-nperio-tx-fifo-size = <0xa00>;
                        dma-desc-enable = <0>;
                        status = "disabled";
                };
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 6d001b5..3acb7ee 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -478,6 +478,38 @@ void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg)
        writel(intmsk, hsotg->regs + GINTMSK);
 }
 
+static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg)
+{
+       struct dwc2_core_params *params = hsotg->core_params;
+       struct dwc2_hw_params *hw = &hsotg->hw_params;
+       u32 rxfsiz, nptxfsiz, ptxfsiz, total_fifo_size;
+
+       total_fifo_size = hw->total_fifo_size;
+       rxfsiz = params->host_rx_fifo_size;
+       nptxfsiz = params->host_nperio_tx_fifo_size;
+       ptxfsiz = params->host_perio_tx_fifo_size;
+
+       if (total_fifo_size >= (rxfsiz + nptxfsiz + ptxfsiz))
+               /* Params are valid, nothing to do */
+               return;
+       else {
+               /* min rx fifo size = ((largest packet/4)*2)+2 */
+               rxfsiz = (((1024/4) + 1 + 1) * 3) + 1;
+               /* min non-periodic tx fifo depth */
+               nptxfsiz = 3 * (1024/4);
+               /* min periodic tx fifo depth */
+               ptxfsiz = ((1024*3)/4) * 3;
+       }
+
+       if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz))
+               dev_err(hsotg->dev, "invalid fifo sizes\n");
+
+       params->host_rx_fifo_size = rxfsiz;
+       params->host_nperio_tx_fifo_size = nptxfsiz;
+       params->host_perio_tx_fifo_size = ptxfsiz;
+}
+       
+
 static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
 {
        struct dwc2_core_params *params = hsotg->core_params;
@@ -495,19 +527,28 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
        writel(grxfsiz, hsotg->regs + GRXFSIZ);
        dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", readl(hsotg->regs + GRXFSIZ));
 
+       /* Calculate the correct FIFO sizes */
+       dwc2_calculate_dynamic_fifo(hsotg);
+
+       /* Rx FIFO */
+       printk("initial grxfsiz=%08x\n",
+               readl(hsotg->regs + GRXFSIZ));
+       writel(params->host_rx_fifo_size, hsotg->regs + GRXFSIZ);
+       printk("new grxfsiz=%08x\n", readl(hsotg->regs + GRXFSIZ));
+
        /* Non-periodic Tx FIFO */
-       dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n",
+       printk("initial gnptxfsiz=%08x\n",
                readl(hsotg->regs + GNPTXFSIZ));
        nptxfsiz = params->host_nperio_tx_fifo_size <<
                   FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
        nptxfsiz |= params->host_rx_fifo_size <<
                    FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
        writel(nptxfsiz, hsotg->regs + GNPTXFSIZ);
-       dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n",
+       printk("new gnptxfsiz=%08x\n",
                readl(hsotg->regs + GNPTXFSIZ));
 
        /* Periodic Tx FIFO */
-       dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n",
+       printk("initial hptxfsiz=%08x\n",
                readl(hsotg->regs + HPTXFSIZ));
        hptxfsiz = params->host_perio_tx_fifo_size <<
                   FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
@@ -515,7 +556,7 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
                     params->host_nperio_tx_fifo_size) <<
                    FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
        writel(hptxfsiz, hsotg->regs + HPTXFSIZ);
-       dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n",
+       printk("new hptxfsiz=%08x\n",
                readl(hsotg->regs + HPTXFSIZ));
 
        if (hsotg->core_params->en_multiple_tx_fifo > 0 &&
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index b8d4193..afbe1a4 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -133,26 +133,6 @@ static int dwc2_driver_probe(struct platform_device *dev)
                (unsigned long)res->start, hsotg->regs);
 
        if (!of_property_read_u32(dev->dev.of_node,
-               "enable-dynamic-fifo", &prop)) {
-               params.enable_dynamic_fifo = prop;
-
-               if (!of_property_read_u32(dev->dev.of_node,
-                       "host-rx-fifo-size", &prop)) {
-                       params.host_rx_fifo_size = prop;
-               }
-
-               if (!of_property_read_u32(dev->dev.of_node,
-                       "host-perio-tx-fifo-size", &prop)) {
-                       params.host_perio_tx_fifo_size = prop;
-               }
-
-               if (!of_property_read_u32(dev->dev.of_node,
-                       "host-nperio-tx-fifo-size", &prop)) {
-                       params.host_nperio_tx_fifo_size = prop;
-               }
-       }
-
-       if (!of_property_read_u32(dev->dev.of_node,
                "dma-desc-enable", &prop)) {
                params.dma_desc_enable = prop;
        }
-- 
1.7.9.5

--
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