UPSTREAM: usb: dwc2: gadget: Add dwc2_gadget_read_ep_interrupts function
authorVardan Mikayelyan <mvardan@synopsys.com>
Thu, 26 May 2016 01:07:10 +0000 (18:07 -0700)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 3 Jan 2017 10:48:45 +0000 (18:48 +0800)
Reads and returns interrupts for given endpoint, by masking epint_reg
with corresponding mask.

Change-Id: I8f5af249b8569a19435665bef2c2a841672f1c03
Tested-by: John Keeping <john@metanate.com>
Signed-off-by: Vardan Mikayelyan <mvardan@synopsys.com>
Signed-off-by: John Youn <johnyoun@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Huang, Tao <huangtao@rock-chips.com>
(cherry picked from commit 326015887b6a1321fd61f7a16816241ad841a03c)

drivers/usb/dwc2/gadget.c

index 2cef7a9cb527300478dadc5fbb02d7f46d4ef02e..8139efdf00fb571d6c8dcf3230752a28d9f23132 100644 (file)
@@ -1946,6 +1946,34 @@ static void dwc2_hsotg_complete_in(struct dwc2_hsotg *hsotg,
        dwc2_hsotg_complete_request(hsotg, hs_ep, hs_req, 0);
 }
 
+/**
+ * dwc2_gadget_read_ep_interrupts - reads interrupts for given ep
+ * @hsotg: The device state.
+ * @idx: Index of ep.
+ * @dir_in: Endpoint direction 1-in 0-out.
+ *
+ * Reads for endpoint with given index and direction, by masking
+ * epint_reg with coresponding mask.
+ */
+static u32 dwc2_gadget_read_ep_interrupts(struct dwc2_hsotg *hsotg,
+                                         unsigned int idx, int dir_in)
+{
+       u32 epmsk_reg = dir_in ? DIEPMSK : DOEPMSK;
+       u32 epint_reg = dir_in ? DIEPINT(idx) : DOEPINT(idx);
+       u32 ints;
+       u32 mask;
+       u32 diepempmsk;
+
+       mask = dwc2_readl(hsotg->regs + epmsk_reg);
+       diepempmsk = dwc2_readl(hsotg->regs + DIEPEMPMSK);
+       mask |= ((diepempmsk >> idx) & 0x1) ? DIEPMSK_TXFIFOEMPTY : 0;
+       mask |= DXEPINT_SETUP_RCVD;
+
+       ints = dwc2_readl(hsotg->regs + epint_reg);
+       ints &= mask;
+       return ints;
+}
+
 /**
  * dwc2_hsotg_epint - handle an in/out endpoint interrupt
  * @hsotg: The driver state
@@ -1964,7 +1992,7 @@ static void dwc2_hsotg_epint(struct dwc2_hsotg *hsotg, unsigned int idx,
        u32 ints;
        u32 ctrl;
 
-       ints = dwc2_readl(hsotg->regs + epint_reg);
+       ints = dwc2_gadget_read_ep_interrupts(hsotg, idx, dir_in);
        ctrl = dwc2_readl(hsotg->regs + epctl_reg);
 
        /* Clear endpoint interrupts */