]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usb: dwc3: Create helper function getting MDWIDTH
authorThinh Nguyen <Thinh.Nguyen@synopsys.com>
Sun, 28 Mar 2021 00:54:01 +0000 (17:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 28 Mar 2021 12:07:18 +0000 (14:07 +0200)
Different controller IPs check different HW parameters for MDWIDTH.
To help with maintainability, create a helper function to consolidate
the logic in a single place.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/456329d36e8c188df5c234f3282595b630bf1470.1616892233.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/core.h
drivers/usb/dwc3/debugfs.c
drivers/usb/dwc3/gadget.c

index 4ca4b4be85e47447f90783b0dcf808ef07586434..265190b7074ae6e2a6461f511e2ba77c0b9b8425 100644 (file)
@@ -860,8 +860,6 @@ struct dwc3_hwparams {
 /* HWPARAMS0 */
 #define DWC3_MODE(n)           ((n) & 0x7)
 
-#define DWC3_MDWIDTH(n)                (((n) & 0xff00) >> 8)
-
 /* HWPARAMS1 */
 #define DWC3_NUM_INT(n)                (((n) & (0x3f << 15)) >> 15)
 
@@ -1458,6 +1456,23 @@ u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
         (!(_ip##_VERSIONTYPE_##_to) ||                                 \
          dwc->version_type <= _ip##_VERSIONTYPE_##_to))
 
+/**
+ * dwc3_mdwidth - get MDWIDTH value in bits
+ * @dwc: pointer to our context structure
+ *
+ * Return MDWIDTH configuration value in bits.
+ */
+static inline u32 dwc3_mdwidth(struct dwc3 *dwc)
+{
+       u32 mdwidth;
+
+       mdwidth = DWC3_GHWPARAMS0_MDWIDTH(dwc->hwparams.hwparams0);
+       if (DWC3_IP_IS(DWC32))
+               mdwidth += DWC3_GHWPARAMS6_MDWIDTH(dwc->hwparams.hwparams6);
+
+       return mdwidth;
+}
+
 bool dwc3_has_imod(struct dwc3 *dwc);
 
 int dwc3_event_buffers_setup(struct dwc3 *dwc);
index 5da4f6082d930486bb9fa30a1f1bc47128c1a794..c85852d98b4b5db0379defd44baf3ad052dfb933 100644 (file)
@@ -638,16 +638,14 @@ static int dwc3_tx_fifo_size_show(struct seq_file *s, void *unused)
        struct dwc3_ep          *dep = s->private;
        struct dwc3             *dwc = dep->dwc;
        unsigned long           flags;
-       int                     mdwidth;
+       u32                     mdwidth;
        u32                     val;
 
        spin_lock_irqsave(&dwc->lock, flags);
        val = dwc3_core_fifo_space(dep, DWC3_TXFIFO);
 
        /* Convert to bytes */
-       mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
-       if (DWC3_IP_IS(DWC32))
-               mdwidth += DWC3_GHWPARAMS6_MDWIDTH(dwc->hwparams.hwparams6);
+       mdwidth = dwc3_mdwidth(dwc);
 
        val *= mdwidth;
        val >>= 3;
@@ -662,16 +660,14 @@ static int dwc3_rx_fifo_size_show(struct seq_file *s, void *unused)
        struct dwc3_ep          *dep = s->private;
        struct dwc3             *dwc = dep->dwc;
        unsigned long           flags;
-       int                     mdwidth;
+       u32                     mdwidth;
        u32                     val;
 
        spin_lock_irqsave(&dwc->lock, flags);
        val = dwc3_core_fifo_space(dep, DWC3_RXFIFO);
 
        /* Convert to bytes */
-       mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
-       if (DWC3_IP_IS(DWC32))
-               mdwidth += DWC3_GHWPARAMS6_MDWIDTH(dwc->hwparams.hwparams6);
+       mdwidth = dwc3_mdwidth(dwc);
 
        val *= mdwidth;
        val >>= 3;
index 8a361f07e0453fb904780c877f6f5bd144e2c667..1a0d53e245f0b42ea976de6f2930d825d203e27e 100644 (file)
@@ -2337,9 +2337,7 @@ static void dwc3_gadget_setup_nump(struct dwc3 *dwc)
        u32 reg;
 
        ram2_depth = DWC3_GHWPARAMS7_RAM2_DEPTH(dwc->hwparams.hwparams7);
-       mdwidth = DWC3_GHWPARAMS0_MDWIDTH(dwc->hwparams.hwparams0);
-       if (DWC3_IP_IS(DWC32))
-               mdwidth += DWC3_GHWPARAMS6_MDWIDTH(dwc->hwparams.hwparams6);
+       mdwidth = dwc3_mdwidth(dwc);
 
        nump = ((ram2_depth * mdwidth / 8) - 24 - 16) / 1024;
        nump = min_t(u32, nump, 16);
@@ -2575,12 +2573,10 @@ static int dwc3_gadget_init_control_endpoint(struct dwc3_ep *dep)
 static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep)
 {
        struct dwc3 *dwc = dep->dwc;
-       int mdwidth;
+       u32 mdwidth;
        int size;
 
-       mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
-       if (DWC3_IP_IS(DWC32))
-               mdwidth += DWC3_GHWPARAMS6_MDWIDTH(dwc->hwparams.hwparams6);
+       mdwidth = dwc3_mdwidth(dwc);
 
        /* MDWIDTH is represented in bits, we need it in bytes */
        mdwidth /= 8;
@@ -2622,12 +2618,10 @@ static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep)
 static int dwc3_gadget_init_out_endpoint(struct dwc3_ep *dep)
 {
        struct dwc3 *dwc = dep->dwc;
-       int mdwidth;
+       u32 mdwidth;
        int size;
 
-       mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
-       if (DWC3_IP_IS(DWC32))
-               mdwidth += DWC3_GHWPARAMS6_MDWIDTH(dwc->hwparams.hwparams6);
+       mdwidth = dwc3_mdwidth(dwc);
 
        /* MDWIDTH is represented in bits, convert to bytes */
        mdwidth /= 8;