[PATCH 10/13] staging: dwc2: properly mask the GRXFSIZ register

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bits 16-31 are reserved, so the old code just reads the whole register to
get bits 0-15, assuming the reserved bits would be 0 (which seems true
on current hardware, but who knows...).

This commit properly masks out the reserved bits when reading and
doesn't touch the reserved bits while writing.

Signed-off-by: Matthijs Kooijman <matthijs@xxxxxxxx>
---
 drivers/staging/dwc2/core.c | 23 ++++++++++++++++-------
 drivers/staging/dwc2/hw.h   |  2 ++
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/dwc2/core.c b/drivers/staging/dwc2/core.c
index 5c80b21..025760e 100644
--- a/drivers/staging/dwc2/core.c
+++ b/drivers/staging/dwc2/core.c
@@ -405,7 +405,9 @@ int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq)
 
 	hsotg->total_fifo_size = hsotg->hwcfg3 >> GHWCFG3_DFIFO_DEPTH_SHIFT &
 			GHWCFG3_DFIFO_DEPTH_MASK >> GHWCFG3_DFIFO_DEPTH_SHIFT;
-	hsotg->rx_fifo_size = readl(hsotg->regs + GRXFSIZ);
+	hsotg->rx_fifo_size = (readl(hsotg->regs + GRXFSIZ) &
+			       GRXFSIZ_RXF_DEP_MASK) >>
+			      GRXFSIZ_RXF_DEP_SHIFT;
 	hsotg->nperio_tx_fifo_size =
 			readl(hsotg->regs + GNPTXFSIZ) >> 16 & 0xffff;
 
@@ -510,7 +512,7 @@ void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg)
 static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
 {
 	struct dwc2_core_params *params = hsotg->core_params;
-	u32 nptxfsiz, hptxfsiz, dfifocfg;
+	u32 nptxfsiz, hptxfsiz, dfifocfg, grxfsiz;
 
 	if (!params->enable_dynamic_fifo)
 		return;
@@ -523,9 +525,12 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
 		params->host_perio_tx_fifo_size);
 
 	/* Rx FIFO */
-	dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n",
-		readl(hsotg->regs + GRXFSIZ));
-	writel(params->host_rx_fifo_size, hsotg->regs + GRXFSIZ);
+	grxfsiz = readl(hsotg->regs + GRXFSIZ);
+	dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz);
+	grxfsiz &= ~GRXFSIZ_RXF_DEP_MASK;
+	grxfsiz |= params->host_rx_fifo_size <<
+		   GRXFSIZ_RXF_DEP_SHIFT & GRXFSIZ_RXF_DEP_MASK;
+	writel(grxfsiz, hsotg->regs + GRXFSIZ);
 	dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", readl(hsotg->regs + GRXFSIZ));
 
 	/* Non-periodic Tx FIFO */
@@ -2120,7 +2125,9 @@ int dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val)
 	int valid = 1;
 	int retval = 0;
 
-	if (val < 16 || val > readl(hsotg->regs + GRXFSIZ))
+	if (val < 16 || val > (readl(hsotg->regs + GRXFSIZ) &
+			       GRXFSIZ_RXF_DEP_MASK) >>
+			      GRXFSIZ_RXF_DEP_SHIFT)
 		valid = 0;
 
 	if (!valid) {
@@ -2128,7 +2135,9 @@ int dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val)
 			dev_err(hsotg->dev,
 				"%d invalid for host_rx_fifo_size. Check HW configuration.\n",
 				val);
-		val = readl(hsotg->regs + GRXFSIZ);
+		val = (readl(hsotg->regs + GRXFSIZ) &
+		       GRXFSIZ_RXF_DEP_MASK) >>
+		      GRXFSIZ_RXF_DEP_SHIFT;
 		dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val);
 		retval = -EINVAL;
 	}
diff --git a/drivers/staging/dwc2/hw.h b/drivers/staging/dwc2/hw.h
index b5268882..4f813b8 100644
--- a/drivers/staging/dwc2/hw.h
+++ b/drivers/staging/dwc2/hw.h
@@ -184,6 +184,8 @@
 #define GRXSTS_EPNUM_SHIFT		0
 
 #define GRXFSIZ				HSOTG_REG(0x024)
+#define GRXFSIZ_RXF_DEP_MASK		(0xffff << 0)
+#define GRXFSIZ_RXF_DEP_SHIFT		0
 
 #define GNPTXFSIZ			HSOTG_REG(0x028)
 #define GNPTXFSIZ_NP_TXF_DEP_MASK	(0xffff << 16)
-- 
1.8.3.rc1

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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux