aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/dwc3')
-rw-r--r--drivers/usb/dwc3/Kconfig17
-rw-r--r--drivers/usb/dwc3/Makefile7
-rw-r--r--drivers/usb/dwc3/core.c9
-rw-r--r--drivers/usb/dwc3/core.h4
-rw-r--r--drivers/usb/dwc3/debug.c32
-rw-r--r--drivers/usb/dwc3/debug.h200
-rw-r--r--drivers/usb/dwc3/dwc3-exynos.c4
-rw-r--r--drivers/usb/dwc3/dwc3-keystone.c1
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c4
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c4
-rw-r--r--drivers/usb/dwc3/dwc3-qcom.c130
-rw-r--r--drivers/usb/dwc3/dwc3-st.c367
-rw-r--r--drivers/usb/dwc3/ep0.c65
-rw-r--r--drivers/usb/dwc3/gadget.c140
-rw-r--r--drivers/usb/dwc3/gadget.h56
-rw-r--r--drivers/usb/dwc3/io.h30
-rw-r--r--drivers/usb/dwc3/trace.c19
-rw-r--r--drivers/usb/dwc3/trace.h220
18 files changed, 1083 insertions, 226 deletions
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 785510a0a0c3..f4e5cc60db0b 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -80,6 +80,23 @@ config USB_DWC3_KEYSTONE
80 Support of USB2/3 functionality in TI Keystone2 platforms. 80 Support of USB2/3 functionality in TI Keystone2 platforms.
81 Say 'Y' or 'M' here if you have one such device 81 Say 'Y' or 'M' here if you have one such device
82 82
83config USB_DWC3_ST
84 tristate "STMicroelectronics Platforms"
85 depends on ARCH_STI && OF
86 default USB_DWC3
87 help
88 STMicroelectronics SoCs with one DesignWare Core USB3 IP
89 inside (i.e. STiH407).
90 Say 'Y' or 'M' if you have one such device.
91
92config USB_DWC3_QCOM
93 tristate "Qualcomm Platforms"
94 depends on ARCH_QCOM || COMPILE_TEST
95 default USB_DWC3
96 help
97 Recent Qualcomm SoCs ship with one DesignWare Core USB3 IP inside,
98 say 'Y' or 'M' if you have one such device.
99
83comment "Debugging features" 100comment "Debugging features"
84 101
85config USB_DWC3_DEBUG 102config USB_DWC3_DEBUG
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 10ac3e72482e..bb34fbcfeab3 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -1,9 +1,12 @@
1# define_trace.h needs to know how to find our header
2CFLAGS_trace.o := -I$(src)
3
1ccflags-$(CONFIG_USB_DWC3_DEBUG) := -DDEBUG 4ccflags-$(CONFIG_USB_DWC3_DEBUG) := -DDEBUG
2ccflags-$(CONFIG_USB_DWC3_VERBOSE) += -DVERBOSE_DEBUG 5ccflags-$(CONFIG_USB_DWC3_VERBOSE) += -DVERBOSE_DEBUG
3 6
4obj-$(CONFIG_USB_DWC3) += dwc3.o 7obj-$(CONFIG_USB_DWC3) += dwc3.o
5 8
6dwc3-y := core.o 9dwc3-y := core.o debug.o trace.o
7 10
8ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),) 11ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
9 dwc3-y += host.o 12 dwc3-y += host.o
@@ -33,3 +36,5 @@ obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o
33obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o 36obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o
34obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o 37obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o
35obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o 38obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o
39obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o
40obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 9069984fe5cf..b0f4d52b7f04 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -186,10 +186,8 @@ static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
186 186
187 dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num, 187 dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
188 GFP_KERNEL); 188 GFP_KERNEL);
189 if (!dwc->ev_buffs) { 189 if (!dwc->ev_buffs)
190 dev_err(dwc->dev, "can't allocate event buffers array\n");
191 return -ENOMEM; 190 return -ENOMEM;
192 }
193 191
194 for (i = 0; i < num; i++) { 192 for (i = 0; i < num; i++) {
195 struct dwc3_event_buffer *evt; 193 struct dwc3_event_buffer *evt;
@@ -639,10 +637,9 @@ static int dwc3_probe(struct platform_device *pdev)
639 void *mem; 637 void *mem;
640 638
641 mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); 639 mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
642 if (!mem) { 640 if (!mem)
643 dev_err(dev, "not enough memory\n");
644 return -ENOMEM; 641 return -ENOMEM;
645 } 642
646 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); 643 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
647 dwc->mem = mem; 644 dwc->mem = mem;
648 dwc->dev = dev; 645 dwc->dev = dev;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 48fb264065db..66f62563bcf9 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -33,6 +33,8 @@
33 33
34#include <linux/phy/phy.h> 34#include <linux/phy/phy.h>
35 35
36#define DWC3_MSG_MAX 500
37
36/* Global constants */ 38/* Global constants */
37#define DWC3_EP0_BOUNCE_SIZE 512 39#define DWC3_EP0_BOUNCE_SIZE 512
38#define DWC3_ENDPOINTS_NUM 32 40#define DWC3_ENDPOINTS_NUM 32
@@ -938,7 +940,7 @@ int dwc3_gadget_get_link_state(struct dwc3 *dwc);
938int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); 940int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state);
939int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep, 941int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
940 unsigned cmd, struct dwc3_gadget_ep_cmd_params *params); 942 unsigned cmd, struct dwc3_gadget_ep_cmd_params *params);
941int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param); 943int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param);
942#else 944#else
943static inline int dwc3_gadget_init(struct dwc3 *dwc) 945static inline int dwc3_gadget_init(struct dwc3 *dwc)
944{ return 0; } 946{ return 0; }
diff --git a/drivers/usb/dwc3/debug.c b/drivers/usb/dwc3/debug.c
new file mode 100644
index 000000000000..0be6885bc370
--- /dev/null
+++ b/drivers/usb/dwc3/debug.c
@@ -0,0 +1,32 @@
1/**
2 * debug.c - DesignWare USB3 DRD Controller Debug/Trace Support
3 *
4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Felipe Balbi <balbi@ti.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include "debug.h"
19
20void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...)
21{
22 struct va_format vaf;
23 va_list args;
24
25 va_start(args, fmt);
26 vaf.fmt = fmt;
27 vaf.va = &args;
28
29 trace(&vaf);
30
31 va_end(args);
32}
diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index fceb39dc4bba..07fbc2d94fd4 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -16,8 +16,206 @@
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 */ 17 */
18 18
19#ifndef __DWC3_DEBUG_H
20#define __DWC3_DEBUG_H
21
19#include "core.h" 22#include "core.h"
20 23
24/**
25 * dwc3_gadget_ep_cmd_string - returns endpoint command string
26 * @cmd: command code
27 */
28static inline const char *
29dwc3_gadget_ep_cmd_string(u8 cmd)
30{
31 switch (cmd) {
32 case DWC3_DEPCMD_DEPSTARTCFG:
33 return "Start New Configuration";
34 case DWC3_DEPCMD_ENDTRANSFER:
35 return "End Transfer";
36 case DWC3_DEPCMD_UPDATETRANSFER:
37 return "Update Transfer";
38 case DWC3_DEPCMD_STARTTRANSFER:
39 return "Start Transfer";
40 case DWC3_DEPCMD_CLEARSTALL:
41 return "Clear Stall";
42 case DWC3_DEPCMD_SETSTALL:
43 return "Set Stall";
44 case DWC3_DEPCMD_GETEPSTATE:
45 return "Get Endpoint State";
46 case DWC3_DEPCMD_SETTRANSFRESOURCE:
47 return "Set Endpoint Transfer Resource";
48 case DWC3_DEPCMD_SETEPCONFIG:
49 return "Set Endpoint Configuration";
50 default:
51 return "UNKNOWN command";
52 }
53}
54
55/**
56 * dwc3_gadget_generic_cmd_string - returns generic command string
57 * @cmd: command code
58 */
59static inline const char *
60dwc3_gadget_generic_cmd_string(u8 cmd)
61{
62 switch (cmd) {
63 case DWC3_DGCMD_SET_LMP:
64 return "Set LMP";
65 case DWC3_DGCMD_SET_PERIODIC_PAR:
66 return "Set Periodic Parameters";
67 case DWC3_DGCMD_XMIT_FUNCTION:
68 return "Transmit Function Wake Device Notification";
69 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
70 return "Set Scratchpad Buffer Array Address Lo";
71 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
72 return "Set Scratchpad Buffer Array Address Hi";
73 case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
74 return "Selected FIFO Flush";
75 case DWC3_DGCMD_ALL_FIFO_FLUSH:
76 return "All FIFO Flush";
77 case DWC3_DGCMD_SET_ENDPOINT_NRDY:
78 return "Set Endpoint NRDY";
79 case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
80 return "Run SoC Bus Loopback Test";
81 default:
82 return "UNKNOWN";
83 }
84}
85
86/**
87 * dwc3_gadget_link_string - returns link name
88 * @link_state: link state code
89 */
90static inline const char *
91dwc3_gadget_link_string(enum dwc3_link_state link_state)
92{
93 switch (link_state) {
94 case DWC3_LINK_STATE_U0:
95 return "U0";
96 case DWC3_LINK_STATE_U1:
97 return "U1";
98 case DWC3_LINK_STATE_U2:
99 return "U2";
100 case DWC3_LINK_STATE_U3:
101 return "U3";
102 case DWC3_LINK_STATE_SS_DIS:
103 return "SS.Disabled";
104 case DWC3_LINK_STATE_RX_DET:
105 return "RX.Detect";
106 case DWC3_LINK_STATE_SS_INACT:
107 return "SS.Inactive";
108 case DWC3_LINK_STATE_POLL:
109 return "Polling";
110 case DWC3_LINK_STATE_RECOV:
111 return "Recovery";
112 case DWC3_LINK_STATE_HRESET:
113 return "Hot Reset";
114 case DWC3_LINK_STATE_CMPLY:
115 return "Compliance";
116 case DWC3_LINK_STATE_LPBK:
117 return "Loopback";
118 case DWC3_LINK_STATE_RESET:
119 return "Reset";
120 case DWC3_LINK_STATE_RESUME:
121 return "Resume";
122 default:
123 return "UNKNOWN link state\n";
124 }
125}
126
127/**
128 * dwc3_gadget_event_string - returns event name
129 * @event: the event code
130 */
131static inline const char *dwc3_gadget_event_string(u8 event)
132{
133 switch (event) {
134 case DWC3_DEVICE_EVENT_DISCONNECT:
135 return "Disconnect";
136 case DWC3_DEVICE_EVENT_RESET:
137 return "Reset";
138 case DWC3_DEVICE_EVENT_CONNECT_DONE:
139 return "Connection Done";
140 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
141 return "Link Status Change";
142 case DWC3_DEVICE_EVENT_WAKEUP:
143 return "WakeUp";
144 case DWC3_DEVICE_EVENT_EOPF:
145 return "End-Of-Frame";
146 case DWC3_DEVICE_EVENT_SOF:
147 return "Start-Of-Frame";
148 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
149 return "Erratic Error";
150 case DWC3_DEVICE_EVENT_CMD_CMPL:
151 return "Command Complete";
152 case DWC3_DEVICE_EVENT_OVERFLOW:
153 return "Overflow";
154 }
155
156 return "UNKNOWN";
157}
158
159/**
160 * dwc3_ep_event_string - returns event name
161 * @event: then event code
162 */
163static inline const char *dwc3_ep_event_string(u8 event)
164{
165 switch (event) {
166 case DWC3_DEPEVT_XFERCOMPLETE:
167 return "Transfer Complete";
168 case DWC3_DEPEVT_XFERINPROGRESS:
169 return "Transfer In-Progress";
170 case DWC3_DEPEVT_XFERNOTREADY:
171 return "Transfer Not Ready";
172 case DWC3_DEPEVT_RXTXFIFOEVT:
173 return "FIFO";
174 case DWC3_DEPEVT_STREAMEVT:
175 return "Stream";
176 case DWC3_DEPEVT_EPCMDCMPLT:
177 return "Endpoint Command Complete";
178 }
179
180 return "UNKNOWN";
181}
182
183/**
184 * dwc3_gadget_event_type_string - return event name
185 * @event: the event code
186 */
187static inline const char *dwc3_gadget_event_type_string(u8 event)
188{
189 switch (event) {
190 case DWC3_DEVICE_EVENT_DISCONNECT:
191 return "Disconnect";
192 case DWC3_DEVICE_EVENT_RESET:
193 return "Reset";
194 case DWC3_DEVICE_EVENT_CONNECT_DONE:
195 return "Connect Done";
196 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
197 return "Link Status Change";
198 case DWC3_DEVICE_EVENT_WAKEUP:
199 return "Wake-Up";
200 case DWC3_DEVICE_EVENT_HIBER_REQ:
201 return "Hibernation";
202 case DWC3_DEVICE_EVENT_EOPF:
203 return "End of Periodic Frame";
204 case DWC3_DEVICE_EVENT_SOF:
205 return "Start of Frame";
206 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
207 return "Erratic Error";
208 case DWC3_DEVICE_EVENT_CMD_CMPL:
209 return "Command Complete";
210 case DWC3_DEVICE_EVENT_OVERFLOW:
211 return "Overflow";
212 default:
213 return "UNKNOWN";
214 }
215}
216
217void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
218
21#ifdef CONFIG_DEBUG_FS 219#ifdef CONFIG_DEBUG_FS
22extern int dwc3_debugfs_init(struct dwc3 *); 220extern int dwc3_debugfs_init(struct dwc3 *);
23extern void dwc3_debugfs_exit(struct dwc3 *); 221extern void dwc3_debugfs_exit(struct dwc3 *);
@@ -27,4 +225,4 @@ static inline int dwc3_debugfs_init(struct dwc3 *d)
27static inline void dwc3_debugfs_exit(struct dwc3 *d) 225static inline void dwc3_debugfs_exit(struct dwc3 *d)
28{ } 226{ }
29#endif 227#endif
30 228#endif /* __DWC3_DEBUG_H */
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index f9fb8adb785b..3951a65fea04 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -113,10 +113,8 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
113 int ret; 113 int ret;
114 114
115 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); 115 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
116 if (!exynos) { 116 if (!exynos)
117 dev_err(dev, "not enough memory\n");
118 return -ENOMEM; 117 return -ENOMEM;
119 }
120 118
121 /* 119 /*
122 * Right now device-tree probed devices don't get dma_mask set. 120 * Right now device-tree probed devices don't get dma_mask set.
diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
index 1fad1618df6e..7ec8495f4523 100644
--- a/drivers/usb/dwc3/dwc3-keystone.c
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -189,7 +189,6 @@ static struct platform_driver kdwc3_driver = {
189 .remove = kdwc3_remove, 189 .remove = kdwc3_remove,
190 .driver = { 190 .driver = {
191 .name = "keystone-dwc3", 191 .name = "keystone-dwc3",
192 .owner = THIS_MODULE,
193 .of_match_table = kdwc3_of_match, 192 .of_match_table = kdwc3_of_match,
194 }, 193 },
195}; 194};
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index fc0de3753648..2f537d588225 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -481,10 +481,8 @@ static int dwc3_omap_probe(struct platform_device *pdev)
481 } 481 }
482 482
483 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); 483 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
484 if (!omap) { 484 if (!omap)
485 dev_err(dev, "not enough memory\n");
486 return -ENOMEM; 485 return -ENOMEM;
487 }
488 486
489 platform_set_drvdata(pdev, omap); 487 platform_set_drvdata(pdev, omap);
490 488
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index a60bab7dfa0a..436fb08c40b8 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -103,10 +103,8 @@ static int dwc3_pci_probe(struct pci_dev *pci,
103 struct device *dev = &pci->dev; 103 struct device *dev = &pci->dev;
104 104
105 glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL); 105 glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
106 if (!glue) { 106 if (!glue)
107 dev_err(dev, "not enough memory\n");
108 return -ENOMEM; 107 return -ENOMEM;
109 }
110 108
111 glue->dev = dev; 109 glue->dev = dev;
112 110
diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
new file mode 100644
index 000000000000..8c2e8eec80c2
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -0,0 +1,130 @@
1/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/clk.h>
14#include <linux/err.h>
15#include <linux/io.h>
16#include <linux/module.h>
17#include <linux/of.h>
18#include <linux/of_platform.h>
19#include <linux/platform_device.h>
20
21struct dwc3_qcom {
22 struct device *dev;
23
24 struct clk *core_clk;
25 struct clk *iface_clk;
26 struct clk *sleep_clk;
27};
28
29static int dwc3_qcom_probe(struct platform_device *pdev)
30{
31 struct device_node *node = pdev->dev.of_node;
32 struct dwc3_qcom *qdwc;
33 int ret;
34
35 qdwc = devm_kzalloc(&pdev->dev, sizeof(*qdwc), GFP_KERNEL);
36 if (!qdwc)
37 return -ENOMEM;
38
39 platform_set_drvdata(pdev, qdwc);
40
41 qdwc->dev = &pdev->dev;
42
43 qdwc->core_clk = devm_clk_get(qdwc->dev, "core");
44 if (IS_ERR(qdwc->core_clk)) {
45 dev_err(qdwc->dev, "failed to get core clock\n");
46 return PTR_ERR(qdwc->core_clk);
47 }
48
49 qdwc->iface_clk = devm_clk_get(qdwc->dev, "iface");
50 if (IS_ERR(qdwc->iface_clk)) {
51 dev_dbg(qdwc->dev, "failed to get optional iface clock\n");
52 qdwc->iface_clk = NULL;
53 }
54
55 qdwc->sleep_clk = devm_clk_get(qdwc->dev, "sleep");
56 if (IS_ERR(qdwc->sleep_clk)) {
57 dev_dbg(qdwc->dev, "failed to get optional sleep clock\n");
58 qdwc->sleep_clk = NULL;
59 }
60
61 ret = clk_prepare_enable(qdwc->core_clk);
62 if (ret) {
63 dev_err(qdwc->dev, "failed to enable core clock\n");
64 goto err_core;
65 }
66
67 ret = clk_prepare_enable(qdwc->iface_clk);
68 if (ret) {
69 dev_err(qdwc->dev, "failed to enable optional iface clock\n");
70 goto err_iface;
71 }
72
73 ret = clk_prepare_enable(qdwc->sleep_clk);
74 if (ret) {
75 dev_err(qdwc->dev, "failed to enable optional sleep clock\n");
76 goto err_sleep;
77 }
78
79 ret = of_platform_populate(node, NULL, NULL, qdwc->dev);
80 if (ret) {
81 dev_err(qdwc->dev, "failed to register core - %d\n", ret);
82 goto err_clks;
83 }
84
85 return 0;
86
87err_clks:
88 clk_disable_unprepare(qdwc->sleep_clk);
89err_sleep:
90 clk_disable_unprepare(qdwc->iface_clk);
91err_iface:
92 clk_disable_unprepare(qdwc->core_clk);
93err_core:
94 return ret;
95}
96
97static int dwc3_qcom_remove(struct platform_device *pdev)
98{
99 struct dwc3_qcom *qdwc = platform_get_drvdata(pdev);
100
101 of_platform_depopulate(&pdev->dev);
102
103 clk_disable_unprepare(qdwc->sleep_clk);
104 clk_disable_unprepare(qdwc->iface_clk);
105 clk_disable_unprepare(qdwc->core_clk);
106
107 return 0;
108}
109
110static const struct of_device_id of_dwc3_match[] = {
111 { .compatible = "qcom,dwc3" },
112 { /* Sentinel */ }
113};
114MODULE_DEVICE_TABLE(of, of_dwc3_match);
115
116static struct platform_driver dwc3_qcom_driver = {
117 .probe = dwc3_qcom_probe,
118 .remove = dwc3_qcom_remove,
119 .driver = {
120 .name = "qcom-dwc3",
121 .of_match_table = of_dwc3_match,
122 },
123};
124
125module_platform_driver(dwc3_qcom_driver);
126
127MODULE_ALIAS("platform:qcom-dwc3");
128MODULE_LICENSE("GPL v2");
129MODULE_DESCRIPTION("DesignWare USB3 QCOM Glue Layer");
130MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
new file mode 100644
index 000000000000..c7602b5362ad
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-st.c
@@ -0,0 +1,367 @@
1/**
2 * dwc3-st.c Support for dwc3 platform devices on ST Microelectronics platforms
3 *
4 * This is a small driver for the dwc3 to provide the glue logic
5 * to configure the controller. Tested on STi platforms.
6 *
7 * Copyright (C) 2014 Stmicroelectronics
8 *
9 * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
10 * Contributors: Aymen Bouattay <aymen.bouattay@st.com>
11 * Peter Griffin <peter.griffin@linaro.org>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * Inspired by dwc3-omap.c and dwc3-exynos.c.
19 */
20
21#include <linux/delay.h>
22#include <linux/interrupt.h>
23#include <linux/io.h>
24#include <linux/ioport.h>
25#include <linux/kernel.h>
26#include <linux/mfd/syscon.h>
27#include <linux/module.h>
28#include <linux/of.h>
29#include <linux/of_platform.h>
30#include <linux/platform_device.h>
31#include <linux/slab.h>
32#include <linux/regmap.h>
33#include <linux/reset.h>
34#include <linux/usb/of.h>
35
36#include "core.h"
37#include "io.h"
38
39/* glue registers */
40#define CLKRST_CTRL 0x00
41#define AUX_CLK_EN BIT(0)
42#define SW_PIPEW_RESET_N BIT(4)
43#define EXT_CFG_RESET_N BIT(8)
44/*
45 * 1'b0 : The host controller complies with the xHCI revision 0.96
46 * 1'b1 : The host controller complies with the xHCI revision 1.0
47 */
48#define XHCI_REVISION BIT(12)
49
50#define USB2_VBUS_MNGMNT_SEL1 0x2C
51/*
52 * For all fields in USB2_VBUS_MNGMNT_SEL1
53 * 2’b00 : Override value from Reg 0x30 is selected
54 * 2’b01 : utmiotg_<signal_name> from usb3_top is selected
55 * 2’b10 : pipew_<signal_name> from PIPEW instance is selected
56 * 2’b11 : value is 1'b0
57 */
58#define USB2_VBUS_REG30 0x0
59#define USB2_VBUS_UTMIOTG 0x1
60#define USB2_VBUS_PIPEW 0x2
61#define USB2_VBUS_ZERO 0x3
62
63#define SEL_OVERRIDE_VBUSVALID(n) (n << 0)
64#define SEL_OVERRIDE_POWERPRESENT(n) (n << 4)
65#define SEL_OVERRIDE_BVALID(n) (n << 8)
66
67/* Static DRD configuration */
68#define USB3_CONTROL_MASK 0xf77
69
70#define USB3_DEVICE_NOT_HOST BIT(0)
71#define USB3_FORCE_VBUSVALID BIT(1)
72#define USB3_DELAY_VBUSVALID BIT(2)
73#define USB3_SEL_FORCE_OPMODE BIT(4)
74#define USB3_FORCE_OPMODE(n) (n << 5)
75#define USB3_SEL_FORCE_DPPULLDOWN2 BIT(8)
76#define USB3_FORCE_DPPULLDOWN2 BIT(9)
77#define USB3_SEL_FORCE_DMPULLDOWN2 BIT(10)
78#define USB3_FORCE_DMPULLDOWN2 BIT(11)
79
80/**
81 * struct st_dwc3 - dwc3-st driver private structure
82 * @dev: device pointer
83 * @glue_base: ioaddr for the glue registers
84 * @regmap: regmap pointer for getting syscfg
85 * @syscfg_reg_off: usb syscfg control offset
86 * @dr_mode: drd static host/device config
87 * @rstc_pwrdn: rest controller for powerdown signal
88 * @rstc_rst: reset controller for softreset signal
89 */
90
91struct st_dwc3 {
92 struct device *dev;
93 void __iomem *glue_base;
94 struct regmap *regmap;
95 int syscfg_reg_off;
96 enum usb_dr_mode dr_mode;
97 struct reset_control *rstc_pwrdn;
98 struct reset_control *rstc_rst;
99};
100
101static inline u32 st_dwc3_readl(void __iomem *base, u32 offset)
102{
103 return readl_relaxed(base + offset);
104}
105
106static inline void st_dwc3_writel(void __iomem *base, u32 offset, u32 value)
107{
108 writel_relaxed(value, base + offset);
109}
110
111/**
112 * st_dwc3_drd_init: program the port
113 * @dwc3_data: driver private structure
114 * Description: this function is to program the port as either host or device
115 * according to the static configuration passed from devicetree.
116 * OTG and dual role are not yet supported!
117 */
118static int st_dwc3_drd_init(struct st_dwc3 *dwc3_data)
119{
120 u32 val;
121 int err;
122
123 err = regmap_read(dwc3_data->regmap, dwc3_data->syscfg_reg_off, &val);
124 if (err)
125 return err;
126
127 val &= USB3_CONTROL_MASK;
128
129 switch (dwc3_data->dr_mode) {
130 case USB_DR_MODE_PERIPHERAL:
131
132 val &= ~(USB3_FORCE_VBUSVALID | USB3_DELAY_VBUSVALID
133 | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3)
134 | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2
135 | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
136
137 val |= USB3_DEVICE_NOT_HOST;
138
139 dev_dbg(dwc3_data->dev, "Configuring as Device\n");
140 break;
141
142 case USB_DR_MODE_HOST:
143
144 val &= ~(USB3_DEVICE_NOT_HOST | USB3_FORCE_VBUSVALID
145 | USB3_SEL_FORCE_OPMODE | USB3_FORCE_OPMODE(0x3)
146 | USB3_SEL_FORCE_DPPULLDOWN2 | USB3_FORCE_DPPULLDOWN2
147 | USB3_SEL_FORCE_DMPULLDOWN2 | USB3_FORCE_DMPULLDOWN2);
148
149 /*
150 * USB3_DELAY_VBUSVALID is ANDed with USB_C_VBUSVALID. Thus,
151 * when set to ‘0‘, it can delay the arrival of VBUSVALID
152 * information to VBUSVLDEXT2 input of the pico PHY.
153 * We don't want to do that so we set the bit to '1'.
154 */
155
156 val |= USB3_DELAY_VBUSVALID;
157
158 dev_dbg(dwc3_data->dev, "Configuring as Host\n");
159 break;
160
161 default:
162 dev_err(dwc3_data->dev, "Unsupported mode of operation %d\n",
163 dwc3_data->dr_mode);
164 return -EINVAL;
165 }
166
167 return regmap_write(dwc3_data->regmap, dwc3_data->syscfg_reg_off, val);
168}
169
170/**
171 * st_dwc3_init: init the controller via glue logic
172 * @dwc3_data: driver private structure
173 */
174static void st_dwc3_init(struct st_dwc3 *dwc3_data)
175{
176 u32 reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL);
177
178 reg |= AUX_CLK_EN | EXT_CFG_RESET_N | XHCI_REVISION;
179 reg &= ~SW_PIPEW_RESET_N;
180 st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg);
181
182 /* configure mux for vbus, powerpresent and bvalid signals */
183 reg = st_dwc3_readl(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1);
184
185 reg |= SEL_OVERRIDE_VBUSVALID(USB2_VBUS_UTMIOTG) |
186 SEL_OVERRIDE_POWERPRESENT(USB2_VBUS_UTMIOTG) |
187 SEL_OVERRIDE_BVALID(USB2_VBUS_UTMIOTG);
188
189 st_dwc3_writel(dwc3_data->glue_base, USB2_VBUS_MNGMNT_SEL1, reg);
190
191 reg = st_dwc3_readl(dwc3_data->glue_base, CLKRST_CTRL);
192 reg |= SW_PIPEW_RESET_N;
193 st_dwc3_writel(dwc3_data->glue_base, CLKRST_CTRL, reg);
194}
195
196static int st_dwc3_probe(struct platform_device *pdev)
197{
198 struct st_dwc3 *dwc3_data;
199 struct resource *res;
200 struct device *dev = &pdev->dev;
201 struct device_node *node = dev->of_node, *child;
202 struct regmap *regmap;
203 int ret;
204
205 dwc3_data = devm_kzalloc(dev, sizeof(*dwc3_data), GFP_KERNEL);
206 if (!dwc3_data)
207 return -ENOMEM;
208
209 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "reg-glue");
210 dwc3_data->glue_base = devm_ioremap_resource(dev, res);
211 if (IS_ERR(dwc3_data->glue_base))
212 return PTR_ERR(dwc3_data->glue_base);
213
214 regmap = syscon_regmap_lookup_by_phandle(node, "st,syscfg");
215 if (IS_ERR(regmap))
216 return PTR_ERR(regmap);
217
218 dma_set_coherent_mask(dev, dev->coherent_dma_mask);
219 dwc3_data->dev = dev;
220 dwc3_data->regmap = regmap;
221
222 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-reg");
223 if (!res) {
224 ret = -ENXIO;
225 goto undo_platform_dev_alloc;
226 }
227
228 dwc3_data->syscfg_reg_off = res->start;
229
230 dev_vdbg(&pdev->dev, "glue-logic addr 0x%p, syscfg-reg offset 0x%x\n",
231 dwc3_data->glue_base, dwc3_data->syscfg_reg_off);
232
233 dwc3_data->rstc_pwrdn = devm_reset_control_get(dev, "powerdown");
234 if (IS_ERR(dwc3_data->rstc_pwrdn)) {
235 dev_err(&pdev->dev, "could not get power controller\n");
236 ret = PTR_ERR(dwc3_data->rstc_pwrdn);
237 goto undo_platform_dev_alloc;
238 }
239
240 /* Manage PowerDown */
241 reset_control_deassert(dwc3_data->rstc_pwrdn);
242
243 dwc3_data->rstc_rst = devm_reset_control_get(dev, "softreset");
244 if (IS_ERR(dwc3_data->rstc_rst)) {
245 dev_err(&pdev->dev, "could not get reset controller\n");
246 ret = PTR_ERR(dwc3_data->rstc_pwrdn);
247 goto undo_powerdown;
248 }
249
250 /* Manage SoftReset */
251 reset_control_deassert(dwc3_data->rstc_rst);
252
253 child = of_get_child_by_name(node, "dwc3");
254 if (!child) {
255 dev_err(&pdev->dev, "failed to find dwc3 core node\n");
256 ret = -ENODEV;
257 goto undo_softreset;
258 }
259
260 dwc3_data->dr_mode = of_usb_get_dr_mode(child);
261
262 /* Allocate and initialize the core */
263 ret = of_platform_populate(node, NULL, NULL, dev);
264 if (ret) {
265 dev_err(dev, "failed to add dwc3 core\n");
266 goto undo_softreset;
267 }
268
269 /*
270 * Configure the USB port as device or host according to the static
271 * configuration passed from DT.
272 * DRD is the only mode currently supported so this will be enhanced
273 * as soon as OTG is available.
274 */
275 ret = st_dwc3_drd_init(dwc3_data);
276 if (ret) {
277 dev_err(dev, "drd initialisation failed\n");
278 goto undo_softreset;
279 }
280
281 /* ST glue logic init */
282 st_dwc3_init(dwc3_data);
283
284 platform_set_drvdata(pdev, dwc3_data);
285 return 0;
286
287undo_softreset:
288 reset_control_assert(dwc3_data->rstc_rst);
289undo_powerdown:
290 reset_control_assert(dwc3_data->rstc_pwrdn);
291undo_platform_dev_alloc:
292 platform_device_put(pdev);
293 return ret;
294}
295
296static int st_dwc3_remove(struct platform_device *pdev)
297{
298 struct st_dwc3 *dwc3_data = platform_get_drvdata(pdev);
299
300 of_platform_depopulate(&pdev->dev);
301
302 reset_control_assert(dwc3_data->rstc_pwrdn);
303 reset_control_assert(dwc3_data->rstc_rst);
304
305 return 0;
306}
307
308#ifdef CONFIG_PM_SLEEP
309static int st_dwc3_suspend(struct device *dev)
310{
311 struct st_dwc3 *dwc3_data = dev_get_drvdata(dev);
312
313 reset_control_assert(dwc3_data->rstc_pwrdn);
314 reset_control_assert(dwc3_data->rstc_rst);
315
316 pinctrl_pm_select_sleep_state(dev);
317
318 return 0;
319}
320
321static int st_dwc3_resume(struct device *dev)
322{
323 struct st_dwc3 *dwc3_data = dev_get_drvdata(dev);
324 int ret;
325
326 pinctrl_pm_select_default_state(dev);
327
328 reset_control_deassert(dwc3_data->rstc_pwrdn);
329 reset_control_deassert(dwc3_data->rstc_rst);
330
331 ret = st_dwc3_drd_init(dwc3_data);
332 if (ret) {
333 dev_err(dev, "drd initialisation failed\n");
334 return ret;
335 }
336
337 /* ST glue logic init */
338 st_dwc3_init(dwc3_data);
339
340 return 0;
341}
342#endif /* CONFIG_PM_SLEEP */
343
344static SIMPLE_DEV_PM_OPS(st_dwc3_dev_pm_ops, st_dwc3_suspend, st_dwc3_resume);
345
346static const struct of_device_id st_dwc3_match[] = {
347 { .compatible = "st,stih407-dwc3" },
348 { /* sentinel */ },
349};
350
351MODULE_DEVICE_TABLE(of, st_dwc3_match);
352
353static struct platform_driver st_dwc3_driver = {
354 .probe = st_dwc3_probe,
355 .remove = st_dwc3_remove,
356 .driver = {
357 .name = "usb-st-dwc3",
358 .of_match_table = st_dwc3_match,
359 .pm = &st_dwc3_dev_pm_ops,
360 },
361};
362
363module_platform_driver(st_dwc3_driver);
364
365MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
366MODULE_DESCRIPTION("DesignWare USB3 STi Glue Layer");
367MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 21a352079bc2..b35938777dde 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -31,6 +31,7 @@
31#include <linux/usb/composite.h> 31#include <linux/usb/composite.h>
32 32
33#include "core.h" 33#include "core.h"
34#include "debug.h"
34#include "gadget.h" 35#include "gadget.h"
35#include "io.h" 36#include "io.h"
36 37
@@ -65,7 +66,7 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
65 66
66 dep = dwc->eps[epnum]; 67 dep = dwc->eps[epnum];
67 if (dep->flags & DWC3_EP_BUSY) { 68 if (dep->flags & DWC3_EP_BUSY) {
68 dev_vdbg(dwc->dev, "%s: still busy\n", dep->name); 69 dwc3_trace(trace_dwc3_ep0, "%s still busy", dep->name);
69 return 0; 70 return 0;
70 } 71 }
71 72
@@ -88,7 +89,8 @@ static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
88 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number, 89 ret = dwc3_send_gadget_ep_cmd(dwc, dep->number,
89 DWC3_DEPCMD_STARTTRANSFER, &params); 90 DWC3_DEPCMD_STARTTRANSFER, &params);
90 if (ret < 0) { 91 if (ret < 0) {
91 dev_dbg(dwc->dev, "failed to send STARTTRANSFER command\n"); 92 dwc3_trace(trace_dwc3_ep0, "%s STARTTRANSFER failed",
93 dep->name);
92 return ret; 94 return ret;
93 } 95 }
94 96
@@ -153,7 +155,8 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep,
153 if (dwc->ep0state == EP0_STATUS_PHASE) 155 if (dwc->ep0state == EP0_STATUS_PHASE)
154 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]); 156 __dwc3_ep0_do_control_status(dwc, dwc->eps[direction]);
155 else 157 else
156 dev_dbg(dwc->dev, "too early for delayed status\n"); 158 dwc3_trace(trace_dwc3_ep0,
159 "too early for delayed status");
157 160
158 return 0; 161 return 0;
159 } 162 }
@@ -217,7 +220,8 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
217 220
218 spin_lock_irqsave(&dwc->lock, flags); 221 spin_lock_irqsave(&dwc->lock, flags);
219 if (!dep->endpoint.desc) { 222 if (!dep->endpoint.desc) {
220 dev_dbg(dwc->dev, "trying to queue request %p to disabled %s\n", 223 dwc3_trace(trace_dwc3_ep0,
224 "trying to queue request %p to disabled %s",
221 request, dep->name); 225 request, dep->name);
222 ret = -ESHUTDOWN; 226 ret = -ESHUTDOWN;
223 goto out; 227 goto out;
@@ -229,7 +233,8 @@ int dwc3_gadget_ep0_queue(struct usb_ep *ep, struct usb_request *request,
229 goto out; 233 goto out;
230 } 234 }
231 235
232 dev_vdbg(dwc->dev, "queueing request %p to %s length %d, state '%s'\n", 236 dwc3_trace(trace_dwc3_ep0,
237 "queueing request %p to %s length %d state '%s'",
233 request, dep->name, request->length, 238 request, dep->name, request->length,
234 dwc3_ep0_state_string(dwc->ep0state)); 239 dwc3_ep0_state_string(dwc->ep0state));
235 240
@@ -485,12 +490,13 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
485 490
486 addr = le16_to_cpu(ctrl->wValue); 491 addr = le16_to_cpu(ctrl->wValue);
487 if (addr > 127) { 492 if (addr > 127) {
488 dev_dbg(dwc->dev, "invalid device address %d\n", addr); 493 dwc3_trace(trace_dwc3_ep0, "invalid device address %d", addr);
489 return -EINVAL; 494 return -EINVAL;
490 } 495 }
491 496
492 if (state == USB_STATE_CONFIGURED) { 497 if (state == USB_STATE_CONFIGURED) {
493 dev_dbg(dwc->dev, "trying to set address when configured\n"); 498 dwc3_trace(trace_dwc3_ep0,
499 "trying to set address when configured");
494 return -EINVAL; 500 return -EINVAL;
495 } 501 }
496 502
@@ -556,7 +562,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
556 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 562 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
557 563
558 dwc->resize_fifos = true; 564 dwc->resize_fifos = true;
559 dev_dbg(dwc->dev, "resize fifos flag SET\n"); 565 dwc3_trace(trace_dwc3_ep0, "resize FIFOs flag SET");
560 } 566 }
561 break; 567 break;
562 568
@@ -680,35 +686,35 @@ static int dwc3_ep0_std_request(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
680 686
681 switch (ctrl->bRequest) { 687 switch (ctrl->bRequest) {
682 case USB_REQ_GET_STATUS: 688 case USB_REQ_GET_STATUS:
683 dev_vdbg(dwc->dev, "USB_REQ_GET_STATUS\n"); 689 dwc3_trace(trace_dwc3_ep0, "USB_REQ_GET_STATUS\n");
684 ret = dwc3_ep0_handle_status(dwc, ctrl); 690 ret = dwc3_ep0_handle_status(dwc, ctrl);
685 break; 691 break;
686 case USB_REQ_CLEAR_FEATURE: 692 case USB_REQ_CLEAR_FEATURE:
687 dev_vdbg(dwc->dev, "USB_REQ_CLEAR_FEATURE\n"); 693 dwc3_trace(trace_dwc3_ep0, "USB_REQ_CLEAR_FEATURE\n");
688 ret = dwc3_ep0_handle_feature(dwc, ctrl, 0); 694 ret = dwc3_ep0_handle_feature(dwc, ctrl, 0);
689 break; 695 break;
690 case USB_REQ_SET_FEATURE: 696 case USB_REQ_SET_FEATURE:
691 dev_vdbg(dwc->dev, "USB_REQ_SET_FEATURE\n"); 697 dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_FEATURE\n");
692 ret = dwc3_ep0_handle_feature(dwc, ctrl, 1); 698 ret = dwc3_ep0_handle_feature(dwc, ctrl, 1);
693 break; 699 break;
694 case USB_REQ_SET_ADDRESS: 700 case USB_REQ_SET_ADDRESS:
695 dev_vdbg(dwc->dev, "USB_REQ_SET_ADDRESS\n"); 701 dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ADDRESS\n");
696 ret = dwc3_ep0_set_address(dwc, ctrl); 702 ret = dwc3_ep0_set_address(dwc, ctrl);
697 break; 703 break;
698 case USB_REQ_SET_CONFIGURATION: 704 case USB_REQ_SET_CONFIGURATION:
699 dev_vdbg(dwc->dev, "USB_REQ_SET_CONFIGURATION\n"); 705 dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_CONFIGURATION\n");
700 ret = dwc3_ep0_set_config(dwc, ctrl); 706 ret = dwc3_ep0_set_config(dwc, ctrl);
701 break; 707 break;
702 case USB_REQ_SET_SEL: 708 case USB_REQ_SET_SEL:
703 dev_vdbg(dwc->dev, "USB_REQ_SET_SEL\n"); 709 dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_SEL\n");
704 ret = dwc3_ep0_set_sel(dwc, ctrl); 710 ret = dwc3_ep0_set_sel(dwc, ctrl);
705 break; 711 break;
706 case USB_REQ_SET_ISOCH_DELAY: 712 case USB_REQ_SET_ISOCH_DELAY:
707 dev_vdbg(dwc->dev, "USB_REQ_SET_ISOCH_DELAY\n"); 713 dwc3_trace(trace_dwc3_ep0, "USB_REQ_SET_ISOCH_DELAY\n");
708 ret = dwc3_ep0_set_isoch_delay(dwc, ctrl); 714 ret = dwc3_ep0_set_isoch_delay(dwc, ctrl);
709 break; 715 break;
710 default: 716 default:
711 dev_vdbg(dwc->dev, "Forwarding to gadget driver\n"); 717 dwc3_trace(trace_dwc3_ep0, "Forwarding to gadget driver\n");
712 ret = dwc3_ep0_delegate_req(dwc, ctrl); 718 ret = dwc3_ep0_delegate_req(dwc, ctrl);
713 break; 719 break;
714 } 720 }
@@ -726,6 +732,8 @@ static void dwc3_ep0_inspect_setup(struct dwc3 *dwc,
726 if (!dwc->gadget_driver) 732 if (!dwc->gadget_driver)
727 goto out; 733 goto out;
728 734
735 trace_dwc3_ctrl_req(ctrl);
736
729 len = le16_to_cpu(ctrl->wLength); 737 len = le16_to_cpu(ctrl->wLength);
730 if (!len) { 738 if (!len) {
731 dwc->three_stage_setup = false; 739 dwc->three_stage_setup = false;
@@ -774,7 +782,7 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
774 782
775 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 783 status = DWC3_TRB_SIZE_TRBSTS(trb->size);
776 if (status == DWC3_TRBSTS_SETUP_PENDING) { 784 if (status == DWC3_TRBSTS_SETUP_PENDING) {
777 dev_dbg(dwc->dev, "Setup Pending received\n"); 785 dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
778 786
779 if (r) 787 if (r)
780 dwc3_gadget_giveback(ep0, r, -ECONNRESET); 788 dwc3_gadget_giveback(ep0, r, -ECONNRESET);
@@ -834,7 +842,7 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc,
834 842
835 ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr); 843 ret = dwc3_gadget_set_test_mode(dwc, dwc->test_mode_nr);
836 if (ret < 0) { 844 if (ret < 0) {
837 dev_dbg(dwc->dev, "Invalid Test #%d\n", 845 dwc3_trace(trace_dwc3_ep0, "Invalid Test #%d",
838 dwc->test_mode_nr); 846 dwc->test_mode_nr);
839 dwc3_ep0_stall_and_restart(dwc); 847 dwc3_ep0_stall_and_restart(dwc);
840 return; 848 return;
@@ -843,7 +851,7 @@ static void dwc3_ep0_complete_status(struct dwc3 *dwc,
843 851
844 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 852 status = DWC3_TRB_SIZE_TRBSTS(trb->size);
845 if (status == DWC3_TRBSTS_SETUP_PENDING) 853 if (status == DWC3_TRBSTS_SETUP_PENDING)
846 dev_dbg(dwc->dev, "Setup Pending received\n"); 854 dwc3_trace(trace_dwc3_ep0, "Setup Pending received\n");
847 855
848 dwc->ep0state = EP0_SETUP_PHASE; 856 dwc->ep0state = EP0_SETUP_PHASE;
849 dwc3_ep0_out_start(dwc); 857 dwc3_ep0_out_start(dwc);
@@ -860,17 +868,17 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
860 868
861 switch (dwc->ep0state) { 869 switch (dwc->ep0state) {
862 case EP0_SETUP_PHASE: 870 case EP0_SETUP_PHASE:
863 dev_vdbg(dwc->dev, "Inspecting Setup Bytes\n"); 871 dwc3_trace(trace_dwc3_ep0, "Setup Phase");
864 dwc3_ep0_inspect_setup(dwc, event); 872 dwc3_ep0_inspect_setup(dwc, event);
865 break; 873 break;
866 874
867 case EP0_DATA_PHASE: 875 case EP0_DATA_PHASE:
868 dev_vdbg(dwc->dev, "Data Phase\n"); 876 dwc3_trace(trace_dwc3_ep0, "Data Phase");
869 dwc3_ep0_complete_data(dwc, event); 877 dwc3_ep0_complete_data(dwc, event);
870 break; 878 break;
871 879
872 case EP0_STATUS_PHASE: 880 case EP0_STATUS_PHASE:
873 dev_vdbg(dwc->dev, "Status Phase\n"); 881 dwc3_trace(trace_dwc3_ep0, "Status Phase");
874 dwc3_ep0_complete_status(dwc, event); 882 dwc3_ep0_complete_status(dwc, event);
875 break; 883 break;
876 default: 884 default:
@@ -946,7 +954,7 @@ static int dwc3_ep0_start_control_status(struct dwc3_ep *dep)
946static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep) 954static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, struct dwc3_ep *dep)
947{ 955{
948 if (dwc->resize_fifos) { 956 if (dwc->resize_fifos) {
949 dev_dbg(dwc->dev, "starting to resize fifos\n"); 957 dwc3_trace(trace_dwc3_ep0, "Resizing FIFOs");
950 dwc3_gadget_resize_tx_fifos(dwc); 958 dwc3_gadget_resize_tx_fifos(dwc);
951 dwc->resize_fifos = 0; 959 dwc->resize_fifos = 0;
952 } 960 }
@@ -987,7 +995,7 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
987 995
988 switch (event->status) { 996 switch (event->status) {
989 case DEPEVT_STATUS_CONTROL_DATA: 997 case DEPEVT_STATUS_CONTROL_DATA:
990 dev_vdbg(dwc->dev, "Control Data\n"); 998 dwc3_trace(trace_dwc3_ep0, "Control Data");
991 999
992 /* 1000 /*
993 * We already have a DATA transfer in the controller's cache, 1001 * We already have a DATA transfer in the controller's cache,
@@ -1001,7 +1009,8 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
1001 if (dwc->ep0_expect_in != event->endpoint_number) { 1009 if (dwc->ep0_expect_in != event->endpoint_number) {
1002 struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in]; 1010 struct dwc3_ep *dep = dwc->eps[dwc->ep0_expect_in];
1003 1011
1004 dev_vdbg(dwc->dev, "Wrong direction for Data phase\n"); 1012 dwc3_trace(trace_dwc3_ep0,
1013 "Wrong direction for Data phase");
1005 dwc3_ep0_end_control_data(dwc, dep); 1014 dwc3_ep0_end_control_data(dwc, dep);
1006 dwc3_ep0_stall_and_restart(dwc); 1015 dwc3_ep0_stall_and_restart(dwc);
1007 return; 1016 return;
@@ -1013,13 +1022,13 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
1013 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS) 1022 if (dwc->ep0_next_event != DWC3_EP0_NRDY_STATUS)
1014 return; 1023 return;
1015 1024
1016 dev_vdbg(dwc->dev, "Control Status\n"); 1025 dwc3_trace(trace_dwc3_ep0, "Control Status");
1017 1026
1018 dwc->ep0state = EP0_STATUS_PHASE; 1027 dwc->ep0state = EP0_STATUS_PHASE;
1019 1028
1020 if (dwc->delayed_status) { 1029 if (dwc->delayed_status) {
1021 WARN_ON_ONCE(event->endpoint_number != 1); 1030 WARN_ON_ONCE(event->endpoint_number != 1);
1022 dev_vdbg(dwc->dev, "Mass Storage delayed status\n"); 1031 dwc3_trace(trace_dwc3_ep0, "Delayed Status");
1023 return; 1032 return;
1024 } 1033 }
1025 1034
@@ -1032,7 +1041,7 @@ void dwc3_ep0_interrupt(struct dwc3 *dwc,
1032{ 1041{
1033 u8 epnum = event->endpoint_number; 1042 u8 epnum = event->endpoint_number;
1034 1043
1035 dev_dbg(dwc->dev, "%s while ep%d%s in state '%s'\n", 1044 dwc3_trace(trace_dwc3_ep0, "%s while ep%d%s in state '%s'",
1036 dwc3_ep_event_string(event->endpoint_event), 1045 dwc3_ep_event_string(event->endpoint_event),
1037 epnum >> 1, (epnum & 1) ? "in" : "out", 1046 epnum >> 1, (epnum & 1) ? "in" : "out",
1038 dwc3_ep0_state_string(dwc->ep0state)); 1047 dwc3_ep0_state_string(dwc->ep0state));
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 490a6ca00733..3818b26bfc05 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -30,6 +30,7 @@
30#include <linux/usb/ch9.h> 30#include <linux/usb/ch9.h>
31#include <linux/usb/gadget.h> 31#include <linux/usb/gadget.h>
32 32
33#include "debug.h"
33#include "core.h" 34#include "core.h"
34#include "gadget.h" 35#include "gadget.h"
35#include "io.h" 36#include "io.h"
@@ -266,107 +267,19 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
266 dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n", 267 dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n",
267 req, dep->name, req->request.actual, 268 req, dep->name, req->request.actual,
268 req->request.length, status); 269 req->request.length, status);
270 trace_dwc3_gadget_giveback(req);
269 271
270 spin_unlock(&dwc->lock); 272 spin_unlock(&dwc->lock);
271 req->request.complete(&dep->endpoint, &req->request); 273 usb_gadget_giveback_request(&dep->endpoint, &req->request);
272 spin_lock(&dwc->lock); 274 spin_lock(&dwc->lock);
273} 275}
274 276
275static const char *dwc3_gadget_ep_cmd_string(u8 cmd) 277int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param)
276{
277 switch (cmd) {
278 case DWC3_DEPCMD_DEPSTARTCFG:
279 return "Start New Configuration";
280 case DWC3_DEPCMD_ENDTRANSFER:
281 return "End Transfer";
282 case DWC3_DEPCMD_UPDATETRANSFER:
283 return "Update Transfer";
284 case DWC3_DEPCMD_STARTTRANSFER:
285 return "Start Transfer";
286 case DWC3_DEPCMD_CLEARSTALL:
287 return "Clear Stall";
288 case DWC3_DEPCMD_SETSTALL:
289 return "Set Stall";
290 case DWC3_DEPCMD_GETEPSTATE:
291 return "Get Endpoint State";
292 case DWC3_DEPCMD_SETTRANSFRESOURCE:
293 return "Set Endpoint Transfer Resource";
294 case DWC3_DEPCMD_SETEPCONFIG:
295 return "Set Endpoint Configuration";
296 default:
297 return "UNKNOWN command";
298 }
299}
300
301static const char *dwc3_gadget_generic_cmd_string(u8 cmd)
302{
303 switch (cmd) {
304 case DWC3_DGCMD_SET_LMP:
305 return "Set LMP";
306 case DWC3_DGCMD_SET_PERIODIC_PAR:
307 return "Set Periodic Parameters";
308 case DWC3_DGCMD_XMIT_FUNCTION:
309 return "Transmit Function Wake Device Notification";
310 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO:
311 return "Set Scratchpad Buffer Array Address Lo";
312 case DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI:
313 return "Set Scratchpad Buffer Array Address Hi";
314 case DWC3_DGCMD_SELECTED_FIFO_FLUSH:
315 return "Selected FIFO Flush";
316 case DWC3_DGCMD_ALL_FIFO_FLUSH:
317 return "All FIFO Flush";
318 case DWC3_DGCMD_SET_ENDPOINT_NRDY:
319 return "Set Endpoint NRDY";
320 case DWC3_DGCMD_RUN_SOC_BUS_LOOPBACK:
321 return "Run SoC Bus Loopback Test";
322 default:
323 return "UNKNOWN";
324 }
325}
326
327static const char *dwc3_gadget_link_string(enum dwc3_link_state link_state)
328{
329 switch (link_state) {
330 case DWC3_LINK_STATE_U0:
331 return "U0";
332 case DWC3_LINK_STATE_U1:
333 return "U1";
334 case DWC3_LINK_STATE_U2:
335 return "U2";
336 case DWC3_LINK_STATE_U3:
337 return "U3";
338 case DWC3_LINK_STATE_SS_DIS:
339 return "SS.Disabled";
340 case DWC3_LINK_STATE_RX_DET:
341 return "RX.Detect";
342 case DWC3_LINK_STATE_SS_INACT:
343 return "SS.Inactive";
344 case DWC3_LINK_STATE_POLL:
345 return "Polling";
346 case DWC3_LINK_STATE_RECOV:
347 return "Recovery";
348 case DWC3_LINK_STATE_HRESET:
349 return "Hot Reset";
350 case DWC3_LINK_STATE_CMPLY:
351 return "Compliance";
352 case DWC3_LINK_STATE_LPBK:
353 return "Loopback";
354 case DWC3_LINK_STATE_RESET:
355 return "Reset";
356 case DWC3_LINK_STATE_RESUME:
357 return "Resume";
358 default:
359 return "UNKNOWN link state\n";
360 }
361}
362
363int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param)
364{ 278{
365 u32 timeout = 500; 279 u32 timeout = 500;
366 u32 reg; 280 u32 reg;
367 281
368 dev_vdbg(dwc->dev, "generic cmd '%s' [%d] param %08x\n", 282 trace_dwc3_gadget_generic_cmd(cmd, param);
369 dwc3_gadget_generic_cmd_string(cmd), cmd, param);
370 283
371 dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param); 284 dwc3_writel(dwc->regs, DWC3_DGCMDPAR, param);
372 dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT); 285 dwc3_writel(dwc->regs, DWC3_DGCMD, cmd | DWC3_DGCMD_CMDACT);
@@ -397,10 +310,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3 *dwc, unsigned ep,
397 u32 timeout = 500; 310 u32 timeout = 500;
398 u32 reg; 311 u32 reg;
399 312
400 dev_vdbg(dwc->dev, "%s: cmd '%s' [%d] params %08x %08x %08x\n", 313 trace_dwc3_gadget_ep_cmd(dep, cmd, params);
401 dep->name,
402 dwc3_gadget_ep_cmd_string(cmd), cmd, params->param0,
403 params->param1, params->param2);
404 314
405 dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0); 315 dwc3_writel(dwc->regs, DWC3_DEPCMDPAR0(ep), params->param0);
406 dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1); 316 dwc3_writel(dwc->regs, DWC3_DEPCMDPAR1(ep), params->param1);
@@ -789,17 +699,16 @@ static struct usb_request *dwc3_gadget_ep_alloc_request(struct usb_ep *ep,
789{ 699{
790 struct dwc3_request *req; 700 struct dwc3_request *req;
791 struct dwc3_ep *dep = to_dwc3_ep(ep); 701 struct dwc3_ep *dep = to_dwc3_ep(ep);
792 struct dwc3 *dwc = dep->dwc;
793 702
794 req = kzalloc(sizeof(*req), gfp_flags); 703 req = kzalloc(sizeof(*req), gfp_flags);
795 if (!req) { 704 if (!req)
796 dev_err(dwc->dev, "not enough memory\n");
797 return NULL; 705 return NULL;
798 }
799 706
800 req->epnum = dep->number; 707 req->epnum = dep->number;
801 req->dep = dep; 708 req->dep = dep;
802 709
710 trace_dwc3_alloc_request(req);
711
803 return &req->request; 712 return &req->request;
804} 713}
805 714
@@ -808,6 +717,7 @@ static void dwc3_gadget_ep_free_request(struct usb_ep *ep,
808{ 717{
809 struct dwc3_request *req = to_dwc3_request(request); 718 struct dwc3_request *req = to_dwc3_request(request);
810 719
720 trace_dwc3_free_request(req);
811 kfree(req); 721 kfree(req);
812} 722}
813 723
@@ -889,6 +799,8 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
889 trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id); 799 trb->ctrl |= DWC3_TRB_CTRL_SID_SOFN(req->request.stream_id);
890 800
891 trb->ctrl |= DWC3_TRB_CTRL_HWO; 801 trb->ctrl |= DWC3_TRB_CTRL_HWO;
802
803 trace_dwc3_prepare_trb(dep, trb);
892} 804}
893 805
894/* 806/*
@@ -1235,6 +1147,7 @@ static int dwc3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request,
1235 1147
1236 dev_vdbg(dwc->dev, "queing request %p to %s length %d\n", 1148 dev_vdbg(dwc->dev, "queing request %p to %s length %d\n",
1237 request, ep->name, request->length); 1149 request, ep->name, request->length);
1150 trace_dwc3_ep_queue(req);
1238 1151
1239 ret = __dwc3_gadget_ep_queue(dep, req); 1152 ret = __dwc3_gadget_ep_queue(dep, req);
1240 spin_unlock_irqrestore(&dwc->lock, flags); 1153 spin_unlock_irqrestore(&dwc->lock, flags);
@@ -1254,6 +1167,8 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
1254 unsigned long flags; 1167 unsigned long flags;
1255 int ret = 0; 1168 int ret = 0;
1256 1169
1170 trace_dwc3_ep_dequeue(req);
1171
1257 spin_lock_irqsave(&dwc->lock, flags); 1172 spin_lock_irqsave(&dwc->lock, flags);
1258 1173
1259 list_for_each_entry(r, &dep->request_list, list) { 1174 list_for_each_entry(r, &dep->request_list, list) {
@@ -1744,11 +1659,8 @@ static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc,
1744 u8 epnum = (i << 1) | (!!direction); 1659 u8 epnum = (i << 1) | (!!direction);
1745 1660
1746 dep = kzalloc(sizeof(*dep), GFP_KERNEL); 1661 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
1747 if (!dep) { 1662 if (!dep)
1748 dev_err(dwc->dev, "can't allocate endpoint %d\n",
1749 epnum);
1750 return -ENOMEM; 1663 return -ENOMEM;
1751 }
1752 1664
1753 dep->dwc = dwc; 1665 dep->dwc = dwc;
1754 dep->number = epnum; 1666 dep->number = epnum;
@@ -1847,6 +1759,8 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
1847 unsigned int s_pkt = 0; 1759 unsigned int s_pkt = 0;
1848 unsigned int trb_status; 1760 unsigned int trb_status;
1849 1761
1762 trace_dwc3_complete_trb(dep, trb);
1763
1850 if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) 1764 if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN)
1851 /* 1765 /*
1852 * We continue despite the error. There is not much we 1766 * We continue despite the error. There is not much we
@@ -2021,9 +1935,6 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
2021 if (!(dep->flags & DWC3_EP_ENABLED)) 1935 if (!(dep->flags & DWC3_EP_ENABLED))
2022 return; 1936 return;
2023 1937
2024 dev_vdbg(dwc->dev, "%s: %s\n", dep->name,
2025 dwc3_ep_event_string(event->endpoint_event));
2026
2027 if (epnum == 0 || epnum == 1) { 1938 if (epnum == 0 || epnum == 1) {
2028 dwc3_ep0_interrupt(dwc, event); 1939 dwc3_ep0_interrupt(dwc, event);
2029 return; 1940 return;
@@ -2210,8 +2121,6 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
2210{ 2121{
2211 int reg; 2122 int reg;
2212 2123
2213 dev_vdbg(dwc->dev, "%s\n", __func__);
2214
2215 reg = dwc3_readl(dwc->regs, DWC3_DCTL); 2124 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
2216 reg &= ~DWC3_DCTL_INITU1ENA; 2125 reg &= ~DWC3_DCTL_INITU1ENA;
2217 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 2126 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
@@ -2230,8 +2139,6 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
2230{ 2139{
2231 u32 reg; 2140 u32 reg;
2232 2141
2233 dev_vdbg(dwc->dev, "%s\n", __func__);
2234
2235 /* 2142 /*
2236 * WORKAROUND: DWC3 revisions <1.88a have an issue which 2143 * WORKAROUND: DWC3 revisions <1.88a have an issue which
2237 * would cause a missing Disconnect Event if there's a 2144 * would cause a missing Disconnect Event if there's a
@@ -2316,8 +2223,6 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
2316 u32 reg; 2223 u32 reg;
2317 u8 speed; 2224 u8 speed;
2318 2225
2319 dev_vdbg(dwc->dev, "%s\n", __func__);
2320
2321 reg = dwc3_readl(dwc->regs, DWC3_DSTS); 2226 reg = dwc3_readl(dwc->regs, DWC3_DSTS);
2322 speed = reg & DWC3_DSTS_CONNECTSPD; 2227 speed = reg & DWC3_DSTS_CONNECTSPD;
2323 dwc->speed = speed; 2228 dwc->speed = speed;
@@ -2415,8 +2320,6 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
2415 2320
2416static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc) 2321static void dwc3_gadget_wakeup_interrupt(struct dwc3 *dwc)
2417{ 2322{
2418 dev_vdbg(dwc->dev, "%s\n", __func__);
2419
2420 /* 2323 /*
2421 * TODO take core out of low power mode when that's 2324 * TODO take core out of low power mode when that's
2422 * implemented. 2325 * implemented.
@@ -2521,10 +2424,6 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
2521 break; 2424 break;
2522 } 2425 }
2523 2426
2524 dev_vdbg(dwc->dev, "link change: %s [%d] -> %s [%d]\n",
2525 dwc3_gadget_link_string(dwc->link_state),
2526 dwc->link_state, dwc3_gadget_link_string(next), next);
2527
2528 dwc->link_state = next; 2427 dwc->link_state = next;
2529} 2428}
2530 2429
@@ -2601,6 +2500,8 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc,
2601static void dwc3_process_event_entry(struct dwc3 *dwc, 2500static void dwc3_process_event_entry(struct dwc3 *dwc,
2602 const union dwc3_event *event) 2501 const union dwc3_event *event)
2603{ 2502{
2503 trace_dwc3_event(event->raw);
2504
2604 /* Endpoint IRQ, handle it and return early */ 2505 /* Endpoint IRQ, handle it and return early */
2605 if (event->type.is_devspec == 0) { 2506 if (event->type.is_devspec == 0) {
2606 /* depevt */ 2507 /* depevt */
@@ -2754,7 +2655,6 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2754 2655
2755 dwc->setup_buf = kzalloc(DWC3_EP0_BOUNCE_SIZE, GFP_KERNEL); 2656 dwc->setup_buf = kzalloc(DWC3_EP0_BOUNCE_SIZE, GFP_KERNEL);
2756 if (!dwc->setup_buf) { 2657 if (!dwc->setup_buf) {
2757 dev_err(dwc->dev, "failed to allocate setup buffer\n");
2758 ret = -ENOMEM; 2658 ret = -ENOMEM;
2759 goto err2; 2659 goto err2;
2760 } 2660 }
diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
index a0ee75b68a80..178ad8982206 100644
--- a/drivers/usb/dwc3/gadget.h
+++ b/drivers/usb/dwc3/gadget.h
@@ -103,60 +103,4 @@ static inline u32 dwc3_gadget_ep_get_transfer_index(struct dwc3 *dwc, u8 number)
103 return DWC3_DEPCMD_GET_RSC_IDX(res_id); 103 return DWC3_DEPCMD_GET_RSC_IDX(res_id);
104} 104}
105 105
106/**
107 * dwc3_gadget_event_string - returns event name
108 * @event: the event code
109 */
110static inline const char *dwc3_gadget_event_string(u8 event)
111{
112 switch (event) {
113 case DWC3_DEVICE_EVENT_DISCONNECT:
114 return "Disconnect";
115 case DWC3_DEVICE_EVENT_RESET:
116 return "Reset";
117 case DWC3_DEVICE_EVENT_CONNECT_DONE:
118 return "Connection Done";
119 case DWC3_DEVICE_EVENT_LINK_STATUS_CHANGE:
120 return "Link Status Change";
121 case DWC3_DEVICE_EVENT_WAKEUP:
122 return "WakeUp";
123 case DWC3_DEVICE_EVENT_EOPF:
124 return "End-Of-Frame";
125 case DWC3_DEVICE_EVENT_SOF:
126 return "Start-Of-Frame";
127 case DWC3_DEVICE_EVENT_ERRATIC_ERROR:
128 return "Erratic Error";
129 case DWC3_DEVICE_EVENT_CMD_CMPL:
130 return "Command Complete";
131 case DWC3_DEVICE_EVENT_OVERFLOW:
132 return "Overflow";
133 }
134
135 return "UNKNOWN";
136}
137
138/**
139 * dwc3_ep_event_string - returns event name
140 * @event: then event code
141 */
142static inline const char *dwc3_ep_event_string(u8 event)
143{
144 switch (event) {
145 case DWC3_DEPEVT_XFERCOMPLETE:
146 return "Transfer Complete";
147 case DWC3_DEPEVT_XFERINPROGRESS:
148 return "Transfer In-Progress";
149 case DWC3_DEPEVT_XFERNOTREADY:
150 return "Transfer Not Ready";
151 case DWC3_DEPEVT_RXTXFIFOEVT:
152 return "FIFO";
153 case DWC3_DEPEVT_STREAMEVT:
154 return "Stream";
155 case DWC3_DEPEVT_EPCMDCMPLT:
156 return "Endpoint Command Complete";
157 }
158
159 return "UNKNOWN";
160}
161
162#endif /* __DRIVERS_USB_DWC3_GADGET_H */ 106#endif /* __DRIVERS_USB_DWC3_GADGET_H */
diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index d94441c14d8c..6a79c8e66bbc 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -20,27 +20,51 @@
20#define __DRIVERS_USB_DWC3_IO_H 20#define __DRIVERS_USB_DWC3_IO_H
21 21
22#include <linux/io.h> 22#include <linux/io.h>
23 23#include "trace.h"
24#include "debug.h"
24#include "core.h" 25#include "core.h"
25 26
26static inline u32 dwc3_readl(void __iomem *base, u32 offset) 27static inline u32 dwc3_readl(void __iomem *base, u32 offset)
27{ 28{
29 u32 offs = offset - DWC3_GLOBALS_REGS_START;
30 u32 value;
31
28 /* 32 /*
29 * We requested the mem region starting from the Globals address 33 * We requested the mem region starting from the Globals address
30 * space, see dwc3_probe in core.c. 34 * space, see dwc3_probe in core.c.
31 * However, the offsets are given starting from xHCI address space. 35 * However, the offsets are given starting from xHCI address space.
32 */ 36 */
33 return readl(base + (offset - DWC3_GLOBALS_REGS_START)); 37 value = readl(base + offs);
38
39 /*
40 * When tracing we want to make it easy to find the correct address on
41 * documentation, so we revert it back to the proper addresses, the
42 * same way they are described on SNPS documentation
43 */
44 dwc3_trace(trace_dwc3_readl, "addr %p value %08x",
45 base - DWC3_GLOBALS_REGS_START + offset, value);
46
47 return value;
34} 48}
35 49
36static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value) 50static inline void dwc3_writel(void __iomem *base, u32 offset, u32 value)
37{ 51{
52 u32 offs = offset - DWC3_GLOBALS_REGS_START;
53
38 /* 54 /*
39 * We requested the mem region starting from the Globals address 55 * We requested the mem region starting from the Globals address
40 * space, see dwc3_probe in core.c. 56 * space, see dwc3_probe in core.c.
41 * However, the offsets are given starting from xHCI address space. 57 * However, the offsets are given starting from xHCI address space.
42 */ 58 */
43 writel(value, base + (offset - DWC3_GLOBALS_REGS_START)); 59 writel(value, base + offs);
60
61 /*
62 * When tracing we want to make it easy to find the correct address on
63 * documentation, so we revert it back to the proper addresses, the
64 * same way they are described on SNPS documentation
65 */
66 dwc3_trace(trace_dwc3_writel, "addr %p value %08x",
67 base - DWC3_GLOBALS_REGS_START + offset, value);
44} 68}
45 69
46#endif /* __DRIVERS_USB_DWC3_IO_H */ 70#endif /* __DRIVERS_USB_DWC3_IO_H */
diff --git a/drivers/usb/dwc3/trace.c b/drivers/usb/dwc3/trace.c
new file mode 100644
index 000000000000..6cd166412ad0
--- /dev/null
+++ b/drivers/usb/dwc3/trace.c
@@ -0,0 +1,19 @@
1/**
2 * trace.c - DesignWare USB3 DRD Controller Trace Support
3 *
4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Felipe Balbi <balbi@ti.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#define CREATE_TRACE_POINTS
19#include "trace.h"
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
new file mode 100644
index 000000000000..78aff1da089a
--- /dev/null
+++ b/drivers/usb/dwc3/trace.h
@@ -0,0 +1,220 @@
1/**
2 * trace.h - DesignWare USB3 DRD Controller Trace Support
3 *
4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Felipe Balbi <balbi@ti.com>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 of
10 * the License as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#undef TRACE_SYSTEM
19#define TRACE_SYSTEM dwc3
20
21#if !defined(__DWC3_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
22#define __DWC3_TRACE_H
23
24#include <linux/types.h>
25#include <linux/tracepoint.h>
26#include <asm/byteorder.h>
27#include "core.h"
28#include "debug.h"
29
30DECLARE_EVENT_CLASS(dwc3_log_msg,
31 TP_PROTO(struct va_format *vaf),
32 TP_ARGS(vaf),
33 TP_STRUCT__entry(__dynamic_array(char, msg, DWC3_MSG_MAX)),
34 TP_fast_assign(
35 vsnprintf(__get_str(msg), DWC3_MSG_MAX, vaf->fmt, *vaf->va);
36 ),
37 TP_printk("%s", __get_str(msg))
38);
39
40DEFINE_EVENT(dwc3_log_msg, dwc3_readl,
41 TP_PROTO(struct va_format *vaf),
42 TP_ARGS(vaf)
43);
44
45DEFINE_EVENT(dwc3_log_msg, dwc3_writel,
46 TP_PROTO(struct va_format *vaf),
47 TP_ARGS(vaf)
48);
49
50DEFINE_EVENT(dwc3_log_msg, dwc3_ep0,
51 TP_PROTO(struct va_format *vaf),
52 TP_ARGS(vaf)
53);
54
55DECLARE_EVENT_CLASS(dwc3_log_event,
56 TP_PROTO(u32 event),
57 TP_ARGS(event),
58 TP_STRUCT__entry(
59 __field(u32, event)
60 ),
61 TP_fast_assign(
62 __entry->event = event;
63 ),
64 TP_printk("event %08x\n", __entry->event)
65);
66
67DEFINE_EVENT(dwc3_log_event, dwc3_event,
68 TP_PROTO(u32 event),
69 TP_ARGS(event)
70);
71
72DECLARE_EVENT_CLASS(dwc3_log_ctrl,
73 TP_PROTO(struct usb_ctrlrequest *ctrl),
74 TP_ARGS(ctrl),
75 TP_STRUCT__entry(
76 __field(struct usb_ctrlrequest *, ctrl)
77 ),
78 TP_fast_assign(
79 __entry->ctrl = ctrl;
80 ),
81 TP_printk("bRequestType %02x bRequest %02x wValue %04x wIndex %04x wLength %d",
82 __entry->ctrl->bRequestType, __entry->ctrl->bRequest,
83 le16_to_cpu(__entry->ctrl->wValue), le16_to_cpu(__entry->ctrl->wIndex),
84 le16_to_cpu(__entry->ctrl->wLength)
85 )
86);
87
88DEFINE_EVENT(dwc3_log_ctrl, dwc3_ctrl_req,
89 TP_PROTO(struct usb_ctrlrequest *ctrl),
90 TP_ARGS(ctrl)
91);
92
93DECLARE_EVENT_CLASS(dwc3_log_request,
94 TP_PROTO(struct dwc3_request *req),
95 TP_ARGS(req),
96 TP_STRUCT__entry(
97 __field(struct dwc3_request *, req)
98 ),
99 TP_fast_assign(
100 __entry->req = req;
101 ),
102 TP_printk("%s: req %p length %u/%u ==> %d",
103 __entry->req->dep->name, __entry->req,
104 __entry->req->request.actual, __entry->req->request.length,
105 __entry->req->request.status
106 )
107);
108
109DEFINE_EVENT(dwc3_log_request, dwc3_alloc_request,
110 TP_PROTO(struct dwc3_request *req),
111 TP_ARGS(req)
112);
113
114DEFINE_EVENT(dwc3_log_request, dwc3_free_request,
115 TP_PROTO(struct dwc3_request *req),
116 TP_ARGS(req)
117);
118
119DEFINE_EVENT(dwc3_log_request, dwc3_ep_queue,
120 TP_PROTO(struct dwc3_request *req),
121 TP_ARGS(req)
122);
123
124DEFINE_EVENT(dwc3_log_request, dwc3_ep_dequeue,
125 TP_PROTO(struct dwc3_request *req),
126 TP_ARGS(req)
127);
128
129DEFINE_EVENT(dwc3_log_request, dwc3_gadget_giveback,
130 TP_PROTO(struct dwc3_request *req),
131 TP_ARGS(req)
132);
133
134DECLARE_EVENT_CLASS(dwc3_log_generic_cmd,
135 TP_PROTO(unsigned int cmd, u32 param),
136 TP_ARGS(cmd, param),
137 TP_STRUCT__entry(
138 __field(unsigned int, cmd)
139 __field(u32, param)
140 ),
141 TP_fast_assign(
142 __entry->cmd = cmd;
143 __entry->param = param;
144 ),
145 TP_printk("cmd '%s' [%d] param %08x\n",
146 dwc3_gadget_generic_cmd_string(__entry->cmd),
147 __entry->cmd, __entry->param
148 )
149);
150
151DEFINE_EVENT(dwc3_log_generic_cmd, dwc3_gadget_generic_cmd,
152 TP_PROTO(unsigned int cmd, u32 param),
153 TP_ARGS(cmd, param)
154);
155
156DECLARE_EVENT_CLASS(dwc3_log_gadget_ep_cmd,
157 TP_PROTO(struct dwc3_ep *dep, unsigned int cmd,
158 struct dwc3_gadget_ep_cmd_params *params),
159 TP_ARGS(dep, cmd, params),
160 TP_STRUCT__entry(
161 __field(struct dwc3_ep *, dep)
162 __field(unsigned int, cmd)
163 __field(struct dwc3_gadget_ep_cmd_params *, params)
164 ),
165 TP_fast_assign(
166 __entry->dep = dep;
167 __entry->cmd = cmd;
168 __entry->params = params;
169 ),
170 TP_printk("%s: cmd '%s' [%d] params %08x %08x %08x\n",
171 __entry->dep->name, dwc3_gadget_ep_cmd_string(__entry->cmd),
172 __entry->cmd, __entry->params->param0,
173 __entry->params->param1, __entry->params->param2
174 )
175);
176
177DEFINE_EVENT(dwc3_log_gadget_ep_cmd, dwc3_gadget_ep_cmd,
178 TP_PROTO(struct dwc3_ep *dep, unsigned int cmd,
179 struct dwc3_gadget_ep_cmd_params *params),
180 TP_ARGS(dep, cmd, params)
181);
182
183DECLARE_EVENT_CLASS(dwc3_log_trb,
184 TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
185 TP_ARGS(dep, trb),
186 TP_STRUCT__entry(
187 __field(struct dwc3_ep *, dep)
188 __field(struct dwc3_trb *, trb)
189 ),
190 TP_fast_assign(
191 __entry->dep = dep;
192 __entry->trb = trb;
193 ),
194 TP_printk("%s: trb %p bph %08x bpl %08x size %08x ctrl %08x\n",
195 __entry->dep->name, __entry->trb, __entry->trb->bph,
196 __entry->trb->bpl, __entry->trb->size, __entry->trb->ctrl
197 )
198);
199
200DEFINE_EVENT(dwc3_log_trb, dwc3_prepare_trb,
201 TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
202 TP_ARGS(dep, trb)
203);
204
205DEFINE_EVENT(dwc3_log_trb, dwc3_complete_trb,
206 TP_PROTO(struct dwc3_ep *dep, struct dwc3_trb *trb),
207 TP_ARGS(dep, trb)
208);
209
210#endif /* __DWC3_TRACE_H */
211
212/* this part has to be here */
213
214#undef TRACE_INCLUDE_PATH
215#define TRACE_INCLUDE_PATH .
216
217#undef TRACE_INCLUDE_FILE
218#define TRACE_INCLUDE_FILE trace
219
220#include <trace/define_trace.h>