UPSTREAM: usb: dwc3: gadget: add a pointer to endpoint registers
authorFelipe Balbi <felipe.balbi@linux.intel.com>
Tue, 12 Apr 2016 13:53:39 +0000 (16:53 +0300)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 16 Aug 2016 12:48:19 +0000 (20:48 +0800)
By adding a pointer to endpoint registers' base
address, we can avoid using our controller-wide
struct dwc3 pointer for everything. At some point
this will allow us to have per-endpoint locks which
will, in turn, let us queue requests to separate
endpoints in parallel.

Because of this change our debugfs interface and io
accessors need to be changed accordingly.

Change-Id: I51229661378e4756f89770e9a813a132b822631c
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Wu Liang feng <wulf@rock-chips.com>
(cherry picked from commit 2eb8801650b315394ca376a56be2971c867aa9ec)

drivers/usb/dwc3/core.h
drivers/usb/dwc3/debugfs.c
drivers/usb/dwc3/ep0.c
drivers/usb/dwc3/gadget.c
drivers/usb/dwc3/gadget.h
drivers/usb/dwc3/io.h

index 17058f7efdd9550f7e63db10de913e36defc460b..1fb960c1c17b40121a7dd36b678872e9df2eed1a 100644 (file)
 #define DWC3_DGCMDPAR          0xc710
 #define DWC3_DGCMD             0xc714
 #define DWC3_DALEPENA          0xc720
-#define DWC3_DEPCMDPAR2(n)     (0xc800 + (n * 0x10))
-#define DWC3_DEPCMDPAR1(n)     (0xc804 + (n * 0x10))
-#define DWC3_DEPCMDPAR0(n)     (0xc808 + (n * 0x10))
-#define DWC3_DEPCMD(n)         (0xc80c + (n * 0x10))
+
+#define DWC3_DEP_BASE(n)       (0xc800 + (n * 0x10))
+#define DWC3_DEPCMDPAR2                0x00
+#define DWC3_DEPCMDPAR1                0x04
+#define DWC3_DEPCMDPAR0                0x08
+#define DWC3_DEPCMD            0x0c
 
 /* OTG Registers */
 #define DWC3_OCFG              0xcc00
@@ -478,6 +480,7 @@ struct dwc3_event_buffer {
  * @endpoint: usb endpoint
  * @pending_list: list of pending requests for this endpoint
  * @started_list: list of started requests on this endpoint
+ * @regs: pointer to first endpoint register
  * @trb_pool: array of transaction buffers
  * @trb_pool_dma: dma address of @trb_pool
  * @trb_enqueue: enqueue 'pointer' into TRB array
@@ -499,6 +502,8 @@ struct dwc3_ep {
        struct list_head        pending_list;
        struct list_head        started_list;
 
+       void __iomem            *regs;
+
        struct dwc3_trb         *trb_pool;
        dma_addr_t              trb_pool_dma;
        const struct usb_ss_ep_comp_descriptor *comp_desc;
index f3c9f445682a120ce6074a7284757478ee7ecacd..31926dda43c9638f96a3fa6a51a2f5ef6a6d2359 100644 (file)
 #define dump_register(nm)                              \
 {                                                      \
        .name   = __stringify(nm),                      \
-       .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \
+       .offset = DWC3_ ##nm,                           \
 }
 
+#define dump_ep_register_set(n)                        \
+       {                                       \
+               .name = "DEPCMDPAR2("__stringify(n)")", \
+               .offset = DWC3_DEP_BASE(n) +    \
+                       DWC3_DEPCMDPAR2,        \
+       },                                      \
+       {                                       \
+               .name = "DEPCMDPAR1("__stringify(n)")", \
+               .offset = DWC3_DEP_BASE(n) +    \
+                       DWC3_DEPCMDPAR1,        \
+       },                                      \
+       {                                       \
+               .name = "DEPCMDPAR0("__stringify(n)")", \
+               .offset = DWC3_DEP_BASE(n) +    \
+                       DWC3_DEPCMDPAR0,        \
+       },                                      \
+       {                                       \
+               .name = "DEPCMD("__stringify(n)")",     \
+               .offset = DWC3_DEP_BASE(n) +    \
+                       DWC3_DEPCMD,            \
+       }
+
+
 static const struct debugfs_reg32 dwc3_regs[] = {
        dump_register(GSBUSCFG0),
        dump_register(GSBUSCFG1),
@@ -219,137 +242,38 @@ static const struct debugfs_reg32 dwc3_regs[] = {
        dump_register(DGCMD),
        dump_register(DALEPENA),
 
-       dump_register(DEPCMDPAR2(0)),
-       dump_register(DEPCMDPAR2(1)),
-       dump_register(DEPCMDPAR2(2)),
-       dump_register(DEPCMDPAR2(3)),
-       dump_register(DEPCMDPAR2(4)),
-       dump_register(DEPCMDPAR2(5)),
-       dump_register(DEPCMDPAR2(6)),
-       dump_register(DEPCMDPAR2(7)),
-       dump_register(DEPCMDPAR2(8)),
-       dump_register(DEPCMDPAR2(9)),
-       dump_register(DEPCMDPAR2(10)),
-       dump_register(DEPCMDPAR2(11)),
-       dump_register(DEPCMDPAR2(12)),
-       dump_register(DEPCMDPAR2(13)),
-       dump_register(DEPCMDPAR2(14)),
-       dump_register(DEPCMDPAR2(15)),
-       dump_register(DEPCMDPAR2(16)),
-       dump_register(DEPCMDPAR2(17)),
-       dump_register(DEPCMDPAR2(18)),
-       dump_register(DEPCMDPAR2(19)),
-       dump_register(DEPCMDPAR2(20)),
-       dump_register(DEPCMDPAR2(21)),
-       dump_register(DEPCMDPAR2(22)),
-       dump_register(DEPCMDPAR2(23)),
-       dump_register(DEPCMDPAR2(24)),
-       dump_register(DEPCMDPAR2(25)),
-       dump_register(DEPCMDPAR2(26)),
-       dump_register(DEPCMDPAR2(27)),
-       dump_register(DEPCMDPAR2(28)),
-       dump_register(DEPCMDPAR2(29)),
-       dump_register(DEPCMDPAR2(30)),
-       dump_register(DEPCMDPAR2(31)),
-
-       dump_register(DEPCMDPAR1(0)),
-       dump_register(DEPCMDPAR1(1)),
-       dump_register(DEPCMDPAR1(2)),
-       dump_register(DEPCMDPAR1(3)),
-       dump_register(DEPCMDPAR1(4)),
-       dump_register(DEPCMDPAR1(5)),
-       dump_register(DEPCMDPAR1(6)),
-       dump_register(DEPCMDPAR1(7)),
-       dump_register(DEPCMDPAR1(8)),
-       dump_register(DEPCMDPAR1(9)),
-       dump_register(DEPCMDPAR1(10)),
-       dump_register(DEPCMDPAR1(11)),
-       dump_register(DEPCMDPAR1(12)),
-       dump_register(DEPCMDPAR1(13)),
-       dump_register(DEPCMDPAR1(14)),
-       dump_register(DEPCMDPAR1(15)),
-       dump_register(DEPCMDPAR1(16)),
-       dump_register(DEPCMDPAR1(17)),
-       dump_register(DEPCMDPAR1(18)),
-       dump_register(DEPCMDPAR1(19)),
-       dump_register(DEPCMDPAR1(20)),
-       dump_register(DEPCMDPAR1(21)),
-       dump_register(DEPCMDPAR1(22)),
-       dump_register(DEPCMDPAR1(23)),
-       dump_register(DEPCMDPAR1(24)),
-       dump_register(DEPCMDPAR1(25)),
-       dump_register(DEPCMDPAR1(26)),
-       dump_register(DEPCMDPAR1(27)),
-       dump_register(DEPCMDPAR1(28)),
-       dump_register(DEPCMDPAR1(29)),
-       dump_register(DEPCMDPAR1(30)),
-       dump_register(DEPCMDPAR1(31)),
-
-       dump_register(DEPCMDPAR0(0)),
-       dump_register(DEPCMDPAR0(1)),
-       dump_register(DEPCMDPAR0(2)),
-       dump_register(DEPCMDPAR0(3)),
-       dump_register(DEPCMDPAR0(4)),
-       dump_register(DEPCMDPAR0(5)),
-       dump_register(DEPCMDPAR0(6)),
-       dump_register(DEPCMDPAR0(7)),
-       dump_register(DEPCMDPAR0(8)),
-       dump_register(DEPCMDPAR0(9)),
-       dump_register(DEPCMDPAR0(10)),
-       dump_register(DEPCMDPAR0(11)),
-       dump_register(DEPCMDPAR0(12)),
-       dump_register(DEPCMDPAR0(13)),
-       dump_register(DEPCMDPAR0(14)),
-       dump_register(DEPCMDPAR0(15)),
-       dump_register(DEPCMDPAR0(16)),
-       dump_register(DEPCMDPAR0(17)),
-       dump_register(DEPCMDPAR0(18)),
-       dump_register(DEPCMDPAR0(19)),
-       dump_register(DEPCMDPAR0(20)),
-       dump_register(DEPCMDPAR0(21)),
-       dump_register(DEPCMDPAR0(22)),
-       dump_register(DEPCMDPAR0(23)),
-       dump_register(DEPCMDPAR0(24)),
-       dump_register(DEPCMDPAR0(25)),
-       dump_register(DEPCMDPAR0(26)),
-       dump_register(DEPCMDPAR0(27)),
-       dump_register(DEPCMDPAR0(28)),
-       dump_register(DEPCMDPAR0(29)),
-       dump_register(DEPCMDPAR0(30)),
-       dump_register(DEPCMDPAR0(31)),
-
-       dump_register(DEPCMD(0)),
-       dump_register(DEPCMD(1)),
-       dump_register(DEPCMD(2)),
-       dump_register(DEPCMD(3)),
-       dump_register(DEPCMD(4)),
-       dump_register(DEPCMD(5)),
-       dump_register(DEPCMD(6)),
-       dump_register(DEPCMD(7)),
-       dump_register(DEPCMD(8)),
-       dump_register(DEPCMD(9)),
-       dump_register(DEPCMD(10)),
-       dump_register(DEPCMD(11)),
-       dump_register(DEPCMD(12)),
-       dump_register(DEPCMD(13)),
-       dump_register(DEPCMD(14)),
-       dump_register(DEPCMD(15)),
-       dump_register(DEPCMD(16)),
-       dump_register(DEPCMD(17)),
-       dump_register(DEPCMD(18)),
-       dump_register(DEPCMD(19)),
-       dump_register(DEPCMD(20)),
-       dump_register(DEPCMD(21)),
-       dump_register(DEPCMD(22)),
-       dump_register(DEPCMD(23)),
-       dump_register(DEPCMD(24)),
-       dump_register(DEPCMD(25)),
-       dump_register(DEPCMD(26)),
-       dump_register(DEPCMD(27)),
-       dump_register(DEPCMD(28)),
-       dump_register(DEPCMD(29)),
-       dump_register(DEPCMD(30)),
-       dump_register(DEPCMD(31)),
+       dump_ep_register_set(0),
+       dump_ep_register_set(1),
+       dump_ep_register_set(2),
+       dump_ep_register_set(3),
+       dump_ep_register_set(4),
+       dump_ep_register_set(5),
+       dump_ep_register_set(6),
+       dump_ep_register_set(7),
+       dump_ep_register_set(8),
+       dump_ep_register_set(9),
+       dump_ep_register_set(10),
+       dump_ep_register_set(11),
+       dump_ep_register_set(12),
+       dump_ep_register_set(13),
+       dump_ep_register_set(14),
+       dump_ep_register_set(15),
+       dump_ep_register_set(16),
+       dump_ep_register_set(17),
+       dump_ep_register_set(18),
+       dump_ep_register_set(19),
+       dump_ep_register_set(20),
+       dump_ep_register_set(21),
+       dump_ep_register_set(22),
+       dump_ep_register_set(23),
+       dump_ep_register_set(24),
+       dump_ep_register_set(25),
+       dump_ep_register_set(26),
+       dump_ep_register_set(27),
+       dump_ep_register_set(28),
+       dump_ep_register_set(29),
+       dump_ep_register_set(30),
+       dump_ep_register_set(31),
 
        dump_register(OCFG),
        dump_register(OCTL),
@@ -940,7 +864,7 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
 
        dwc->regset->regs = dwc3_regs;
        dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
-       dwc->regset->base = dwc->regs;
+       dwc->regset->base = dwc->regs - DWC3_GLOBALS_REGS_START;
 
        file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
        if (!file)
index 9ab98ea612dbc60bda25836777ab00174e7e87ab..6cb03977cad84e4d3744bafa2648df2629affbeb 100644 (file)
@@ -106,9 +106,7 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
        }
 
        dep->flags |= DWC3_EP_BUSY;
-       dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc,
-                       dep->number);
-
+       dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep);
        dwc->ep0_next_event = DWC3_EP0_COMPLETE;
 
        return 0;
index 457dc32437a46a9641d546853e5cd5e0bf5aa156..f24746b476dcb82611294c341cb524f46e534d85 100644 (file)
@@ -248,8 +248,6 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
        int                     susphy = false;
        int                     ret = -EINVAL;
 
-       unsigned                ep = dep->number;
-
        trace_dwc3_gadget_ep_cmd(dep, cmd, params);
 
        /*
@@ -281,13 +279,13 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
                }
        }
 
-       dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0);
-       dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1);
-       dwc3_writel(dwc->regs, DWC3_DEPCMDPAR2(ep), params->param2);
+       dwc3_writel(dep->regs, DWC3_DEPCMDPAR0, params->param0);
+       dwc3_writel(dep->regs, DWC3_DEPCMDPAR1, params->param1);
+       dwc3_writel(dep->regs, DWC3_DEPCMDPAR2, params->param2);
 
-       dwc3_writel(dwc->regs, DWC3_DEPCMD(ep), cmd | DWC3_DEPCMD_CMDACT);
+       dwc3_writel(dep->regs, DWC3_DEPCMD, cmd | DWC3_DEPCMD_CMDACT);
        do {
-               reg = dwc3_readl(dwc->regs, DWC3_DEPCMD(ep));
+               reg = dwc3_readl(dep->regs, DWC3_DEPCMD);
                if (!(reg & DWC3_DEPCMD_CMDACT)) {
                        int cmd_status = DWC3_DEPCMD_STATUS(reg);
 
@@ -1025,8 +1023,7 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep *dep, u16 cmd_param)
        dep->flags |= DWC3_EP_BUSY;
 
        if (starting) {
-               dep->resource_index = dwc3_gadget_ep_get_transfer_index(dwc,
-                               dep->number);
+               dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep);
                WARN_ON_ONCE(!dep->resource_index);
        }
 
@@ -1834,6 +1831,7 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc,
                dep->dwc = dwc;
                dep->number = epnum;
                dep->direction = !!direction;
+               dep->regs = dwc->regs + DWC3_DEP_BASE(epnum);
                dwc->eps[epnum] = dep;
 
                snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1,
index f21c0fccbebdf92545c9f1ff7b8ae6415acc130b..e4a1d974a5aea209fbea745280bb70cada700883 100644 (file)
@@ -95,11 +95,11 @@ int __dwc3_gadget_ep_set_halt(struct dwc3_ep *dep, int value, int protocol);
  *
  * Caller should take care of locking
  */
-static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3 *dwc, u8 number)
+static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3_ep *dep)
 {
        u32                     res_id;
 
-       res_id = dwc3_readl(dwc->regs, DWC3_DEPCMD(number));
+       res_id = dwc3_readl(dep->regs, DWC3_DEPCMD);
 
        return DWC3_DEPCMD_GET_RSC_IDX(res_id);
 }
index 6a79c8e66bbcce87ae1b0d7f38bd345687504894..a06f9a8fecc701c99c370150416bdf5351b4d3d8 100644 (file)
@@ -26,7 +26,6 @@
 
 static inline u32 dwc3_readl(void __iomem *base, u32 offset)
 {
-       u32 offs = offset - DWC3_GLOBALS_REGS_START;
        u32 value;
 
        /*
@@ -34,7 +33,7 @@ static inline u32 dwc3_readl(void __iomem *base, u32 offset)
         * space, see dwc3_probe in core.c.
         * However, the offsets are given starting from xHCI address space.
         */
-       value = readl(base + offs);
+       value = readl(base + offset - DWC3_GLOBALS_REGS_START);
 
        /*
         * When tracing we want to make it easy to find the correct address on
@@ -49,14 +48,12 @@ static inline u32 dwc3_readl(void __iomem *base, u32 offset)
 
 static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value)
 {
-       u32 offs = offset - DWC3_GLOBALS_REGS_START;
-
        /*
         * We requested the mem region starting from the Globals address
         * space, see dwc3_probe in core.c.
         * However, the offsets are given starting from xHCI address space.
         */
-       writel(value, base + offs);
+       writel(value, base + offset - DWC3_GLOBALS_REGS_START);
 
        /*
         * When tracing we want to make it easy to find the correct address on