forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/usb/dwc3/core.c
....@@ -1,14 +1,13 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/**
2
+/*
33 * core.c - DesignWare USB3 DRD Controller Core file
44 *
5
- * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
5
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
66 *
77 * Authors: Felipe Balbi <balbi@ti.com>,
88 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
99 */
1010
11
-#include <linux/async.h>
1211 #include <linux/clk.h>
1312 #include <linux/version.h>
1413 #include <linux/module.h>
....@@ -86,7 +85,9 @@
8685 * specified or set to OTG, then set the mode to peripheral.
8786 */
8887 if (mode == USB_DR_MODE_OTG &&
89
- dwc->revision >= DWC3_REVISION_330A)
88
+ (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
89
+ !device_property_read_bool(dwc->dev, "usb-role-switch")) &&
90
+ !DWC3_VER_IS_PRIOR(DWC3, 330A))
9091 mode = USB_DR_MODE_PERIPHERAL;
9192 }
9293
....@@ -118,24 +119,36 @@
118119 struct dwc3 *dwc = work_to_dwc(work);
119120 unsigned long flags;
120121 int ret;
122
+ int retries = 1000;
123
+ u32 reg;
121124
122
- if (dwc->dr_mode != USB_DR_MODE_OTG)
123
- return;
125
+ mutex_lock(&dwc->mutex);
126
+
127
+ pm_runtime_get_sync(dwc->dev);
128
+
129
+#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_NO_GKI)
130
+ if (dwc->desired_role_sw_mode == USB_DR_MODE_PERIPHERAL &&
131
+ dwc->desired_role_sw_mode != dwc->current_role_sw_mode)
132
+ pm_runtime_get(dwc->dev);
133
+ else if ((dwc->desired_role_sw_mode == USB_DR_MODE_UNKNOWN ||
134
+ dwc->desired_role_sw_mode == USB_DR_MODE_HOST) &&
135
+ dwc->current_role_sw_mode == USB_DR_MODE_PERIPHERAL)
136
+ pm_runtime_put(dwc->dev);
137
+
138
+ dwc->current_role_sw_mode = dwc->desired_role_sw_mode;
139
+#endif
124140
125141 if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
126142 dwc3_otg_update(dwc, 0);
127143
128144 if (!dwc->desired_dr_role)
129
- return;
130
-
131
- if (dwc->en_runtime)
132
- goto runtime;
145
+ goto out;
133146
134147 if (dwc->desired_dr_role == dwc->current_dr_role)
135
- return;
148
+ goto out;
136149
137150 if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
138
- return;
151
+ goto out;
139152
140153 switch (dwc->current_dr_role) {
141154 case DWC3_GCTL_PRTCAP_HOST:
....@@ -156,6 +169,30 @@
156169 break;
157170 }
158171
172
+ /*
173
+ * When current_dr_role is not set, there's no role switching.
174
+ * Only perform GCTL.CoreSoftReset when there's DRD role switching.
175
+ */
176
+ if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) ||
177
+ DWC3_VER_IS_PRIOR(DWC31, 190A)) &&
178
+ dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {
179
+ reg = dwc3_readl(dwc->regs, DWC3_GCTL);
180
+ reg |= DWC3_GCTL_CORESOFTRESET;
181
+ dwc3_writel(dwc->regs, DWC3_GCTL, reg);
182
+
183
+ /*
184
+ * Wait for internal clocks to synchronized. DWC_usb31 and
185
+ * DWC_usb32 may need at least 50ms (less for DWC_usb3). To
186
+ * keep it consistent across different IPs, let's wait up to
187
+ * 100ms before clearing GCTL.CORESOFTRESET.
188
+ */
189
+ msleep(100);
190
+
191
+ reg = dwc3_readl(dwc->regs, DWC3_GCTL);
192
+ reg &= ~DWC3_GCTL_CORESOFTRESET;
193
+ dwc3_writel(dwc->regs, DWC3_GCTL, reg);
194
+ }
195
+
159196 spin_lock_irqsave(&dwc->lock, flags);
160197
161198 dwc3_set_prtcap(dwc, dwc->desired_dr_role);
....@@ -172,12 +209,35 @@
172209 otg_set_vbus(dwc->usb2_phy->otg, true);
173210 phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
174211 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
175
- if (!of_device_is_compatible(dwc->dev->parent->of_node,
176
- "rockchip,rk3399-dwc3"))
177
- phy_calibrate(dwc->usb2_generic_phy);
212
+ if (dwc->dis_split_quirk) {
213
+ reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
214
+ reg |= DWC3_GUCTL3_SPLITDISABLE;
215
+ dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
216
+ }
178217 }
179218 break;
180219 case DWC3_GCTL_PRTCAP_DEVICE:
220
+ reg = dwc3_readl(dwc->regs, DWC3_DCTL);
221
+ reg |= DWC3_DCTL_CSFTRST;
222
+ dwc3_writel(dwc->regs, DWC3_DCTL, reg);
223
+
224
+ if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
225
+ retries = 10;
226
+
227
+ do {
228
+ reg = dwc3_readl(dwc->regs, DWC3_DCTL);
229
+ if (!(reg & DWC3_DCTL_CSFTRST))
230
+ goto done;
231
+
232
+ if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
233
+ msleep(20);
234
+ else
235
+ udelay(1);
236
+ } while (--retries);
237
+done:
238
+ if (DWC3_VER_IS_WITHIN(DWC31, ANY, 180A))
239
+ msleep(50);
240
+
181241 dwc3_event_buffers_setup(dwc);
182242
183243 if (dwc->usb2_phy)
....@@ -197,123 +257,18 @@
197257 break;
198258 }
199259
200
- return;
201
-
202
-runtime:
203
- if (extcon_get_state(dwc->edev, EXTCON_USB) ||
204
- extcon_get_state(dwc->edev, EXTCON_USB_HOST)) {
205
- if (dwc->drd_connected) {
206
- /*
207
- * If the connected flag is true, and the DWC3 is
208
- * in device mode, it means that the Type-C cable
209
- * is doing data role swap (UFP -> DFP), so we need
210
- * to disconnect UFP first, and then switch DWC3 to
211
- * DFP depends on the next extcon notifier.
212
- */
213
- if (extcon_get_state(dwc->edev, EXTCON_USB_HOST) &&
214
- dwc->current_dr_role == DWC3_GCTL_PRTCAP_DEVICE)
215
- goto disconnect;
216
- else
217
- return;
218
- }
219
-
220
- dwc->current_dr_role = dwc->desired_dr_role;
221
- pm_runtime_get_sync(dwc->dev);
222
- /*
223
- * We should set drd_connected true after runtime_resume to
224
- * enable reset deassert.
225
- */
226
- dwc->drd_connected = true;
227
-
228
- spin_lock_irqsave(&dwc->lock, flags);
229
-
230
- dwc3_set_prtcap(dwc, dwc->desired_dr_role);
231
-
232
- spin_unlock_irqrestore(&dwc->lock, flags);
233
-
234
- switch (dwc->current_dr_role) {
235
- case DWC3_GCTL_PRTCAP_HOST:
236
- phy_power_on(dwc->usb3_generic_phy);
237
- ret = dwc3_host_init(dwc);
238
- if (ret) {
239
- dev_err(dwc->dev,
240
- "failed to initialize host\n");
241
- } else {
242
- if (dwc->usb2_phy)
243
- otg_set_vbus(dwc->usb2_phy->otg, true);
244
- phy_set_mode(dwc->usb2_generic_phy,
245
- PHY_MODE_USB_HOST);
246
- phy_set_mode(dwc->usb3_generic_phy,
247
- PHY_MODE_USB_HOST);
248
- if (!of_device_is_compatible(
249
- dwc->dev->parent->of_node,
250
- "rockchip,rk3399-dwc3"))
251
- phy_calibrate(dwc->usb2_generic_phy);
252
- }
253
- break;
254
- case DWC3_GCTL_PRTCAP_DEVICE:
255
- if (dwc->usb2_phy)
256
- otg_set_vbus(dwc->usb2_phy->otg, false);
257
- phy_set_mode(dwc->usb2_generic_phy,
258
- PHY_MODE_USB_DEVICE);
259
- phy_set_mode(dwc->usb3_generic_phy,
260
- PHY_MODE_USB_DEVICE);
261
- dwc->gadget.ops->udc_set_speed(&dwc->gadget,
262
- dwc->maximum_speed);
263
- break;
264
- case DWC3_GCTL_PRTCAP_OTG:
265
- break;
266
- default:
267
- break;
268
- }
269
- } else {
270
-disconnect:
271
- switch (dwc->current_dr_role) {
272
- case DWC3_GCTL_PRTCAP_HOST:
273
- if (dwc->drd_connected) {
274
- /*
275
- * Set device mode to disable otg-vbus supply
276
- * and enable vbus detect for inno USB2PHY.
277
- */
278
- phy_set_mode(dwc->usb2_generic_phy,
279
- PHY_MODE_USB_DEVICE);
280
- phy_set_mode(dwc->usb3_generic_phy,
281
- PHY_MODE_USB_DEVICE);
282
- phy_power_off(dwc->usb3_generic_phy);
283
- dwc3_host_exit(dwc);
284
- }
285
- break;
286
- case DWC3_GCTL_PRTCAP_DEVICE:
287
- if (dwc->connected) {
288
- ret = wait_for_completion_timeout(&dwc->discon_done,
289
- msecs_to_jiffies(DWC3_DISCON_TIMEOUT));
290
- if (!ret)
291
- dev_warn(dwc->dev,
292
- "timed out waiting for disconnect\n");
293
- }
294
-
295
- break;
296
- case DWC3_GCTL_PRTCAP_OTG:
297
- break;
298
- default:
299
- dwc->current_dr_role = dwc->desired_dr_role;
300
- return;
301
- }
302
-
303
- /*
304
- * We should set drd_connected to false before
305
- * runtime_suspend to enable reset assert.
306
- */
307
- if (dwc->drd_connected) {
308
- dwc->drd_connected = false;
309
- pm_runtime_put_sync_suspend(dwc->dev);
310
- }
311
- }
260
+out:
261
+ pm_runtime_mark_last_busy(dwc->dev);
262
+ pm_runtime_put_autosuspend(dwc->dev);
263
+ mutex_unlock(&dwc->mutex);
312264 }
313265
314266 void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
315267 {
316268 unsigned long flags;
269
+
270
+ if (dwc->dr_mode != USB_DR_MODE_OTG)
271
+ return;
317272
318273 spin_lock_irqsave(&dwc->lock, flags);
319274 dwc->desired_dr_role = mode;
....@@ -340,23 +295,10 @@
340295 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
341296 * @dwc: pointer to our context structure
342297 */
343
-static int dwc3_core_soft_reset(struct dwc3 *dwc)
298
+int dwc3_core_soft_reset(struct dwc3 *dwc)
344299 {
345300 u32 reg;
346301 int retries = 1000;
347
- int ret;
348
-
349
- usb_phy_init(dwc->usb2_phy);
350
- usb_phy_init(dwc->usb3_phy);
351
- ret = phy_init(dwc->usb2_generic_phy);
352
- if (ret < 0)
353
- return ret;
354
-
355
- ret = phy_init(dwc->usb3_generic_phy);
356
- if (ret < 0) {
357
- phy_exit(dwc->usb2_generic_phy);
358
- return ret;
359
- }
360302
361303 /*
362304 * We're resetting only the device side because, if we're in host mode,
....@@ -368,38 +310,43 @@
368310
369311 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
370312 reg |= DWC3_DCTL_CSFTRST;
371
- dwc3_writel(dwc->regs, DWC3_DCTL, reg);
313
+ reg &= ~DWC3_DCTL_RUN_STOP;
314
+ dwc3_gadget_dctl_write_safe(dwc, reg);
315
+
316
+ /*
317
+ * For DWC_usb31 controller 1.90a and later, the DCTL.CSFRST bit
318
+ * is cleared only after all the clocks are synchronized. This can
319
+ * take a little more than 50ms. Set the polling rate at 20ms
320
+ * for 10 times instead.
321
+ */
322
+ if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
323
+ retries = 10;
372324
373325 do {
374326 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
375327 if (!(reg & DWC3_DCTL_CSFTRST))
376328 goto done;
377329
378
- udelay(1);
330
+ if (DWC3_VER_IS_WITHIN(DWC31, 190A, ANY) || DWC3_IP_IS(DWC32))
331
+ msleep(20);
332
+ else
333
+ udelay(1);
379334 } while (--retries);
380335
381
- phy_exit(dwc->usb3_generic_phy);
382
- phy_exit(dwc->usb2_generic_phy);
383
-
336
+ dev_warn(dwc->dev, "DWC3 controller soft reset failed.\n");
384337 return -ETIMEDOUT;
385338
386339 done:
387340 /*
388
- * For DWC_usb31 controller, once DWC3_DCTL_CSFTRST bit is cleared,
389
- * we must wait at least 50ms before accessing the PHY domain
390
- * (synchronization delay). DWC_usb31 programming guide section 1.3.2.
341
+ * For DWC_usb31 controller 1.80a and prior, once DCTL.CSFRST bit
342
+ * is cleared, we must wait at least 50ms before accessing the PHY
343
+ * domain (synchronization delay).
391344 */
392
- if (dwc3_is_usb31(dwc))
345
+ if (DWC3_VER_IS_WITHIN(DWC31, ANY, 180A))
393346 msleep(50);
394347
395348 return 0;
396349 }
397
-
398
-static const struct clk_bulk_data dwc3_core_clks[] = {
399
- { .id = "ref" },
400
- { .id = "bus_early" },
401
- { .id = "suspend" },
402
-};
403350
404351 /*
405352 * dwc3_frame_length_adjustment - Adjusts frame length if required
....@@ -410,7 +357,7 @@
410357 u32 reg;
411358 u32 dft;
412359
413
- if (dwc->revision < DWC3_REVISION_250A)
360
+ if (DWC3_VER_IS_PRIOR(DWC3, 250A))
414361 return;
415362
416363 if (dwc->fladj == 0)
....@@ -445,7 +392,7 @@
445392 * otherwise ERR_PTR(errno).
446393 */
447394 static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
448
- unsigned length)
395
+ unsigned int length)
449396 {
450397 struct dwc3_event_buffer *evt;
451398
....@@ -488,7 +435,7 @@
488435 * Returns 0 on success otherwise negative errno. In the error case, dwc
489436 * may contain some buffers allocated but not all which were requested.
490437 */
491
-static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
438
+static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned int length)
492439 {
493440 struct dwc3_event_buffer *evt;
494441
....@@ -644,6 +591,9 @@
644591 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
645592 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
646593 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
594
+
595
+ if (DWC3_IP_IS(DWC32))
596
+ parms->hwparams9 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS9);
647597 }
648598
649599 static int dwc3_core_ulpi_init(struct dwc3 *dwc)
....@@ -672,7 +622,10 @@
672622 */
673623 static int dwc3_phy_setup(struct dwc3 *dwc)
674624 {
625
+ unsigned int hw_mode;
675626 u32 reg;
627
+
628
+ hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
676629
677630 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
678631
....@@ -688,8 +641,16 @@
688641 * will be '0' when the core is reset. Application needs to set it
689642 * to '1' after the core initialization is completed.
690643 */
691
- if (dwc->revision > DWC3_REVISION_194A)
644
+ if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A))
692645 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
646
+
647
+ /*
648
+ * For DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be cleared after
649
+ * power-on reset, and it can be set after core initialization, which is
650
+ * after device soft-reset during initialization.
651
+ */
652
+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD)
653
+ reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
693654
694655 if (dwc->u2ss_inp3_quirk)
695656 reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK;
....@@ -741,9 +702,8 @@
741702 if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI))
742703 break;
743704 }
744
- /* FALLTHROUGH */
705
+ fallthrough;
745706 case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
746
- /* FALLTHROUGH */
747707 default:
748708 break;
749709 }
....@@ -771,8 +731,16 @@
771731 * be '0' when the core is reset. Application needs to set it to
772732 * '1' after the core initialization is completed.
773733 */
774
- if (dwc->revision > DWC3_REVISION_194A)
734
+ if (!DWC3_VER_IS_WITHIN(DWC3, ANY, 194A))
775735 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
736
+
737
+ /*
738
+ * For DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared after
739
+ * power-on reset, and it can be set after core initialization, which is
740
+ * after device soft-reset during initialization.
741
+ */
742
+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD)
743
+ reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
776744
777745 if (dwc->dis_u2_susphy_quirk)
778746 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
....@@ -794,20 +762,18 @@
794762 {
795763 dwc3_event_buffers_cleanup(dwc);
796764
765
+ usb_phy_set_suspend(dwc->usb2_phy, 1);
766
+ usb_phy_set_suspend(dwc->usb3_phy, 1);
767
+ phy_power_off(dwc->usb2_generic_phy);
768
+ phy_power_off(dwc->usb3_generic_phy);
769
+
797770 usb_phy_shutdown(dwc->usb2_phy);
798771 usb_phy_shutdown(dwc->usb3_phy);
799772 phy_exit(dwc->usb2_generic_phy);
800773 phy_exit(dwc->usb3_generic_phy);
801774
802
- usb_phy_set_suspend(dwc->usb2_phy, 1);
803
- usb_phy_set_suspend(dwc->usb3_phy, 1);
804
- phy_power_off(dwc->usb2_generic_phy);
805
- phy_power_off(dwc->usb3_generic_phy);
806
- clk_bulk_disable(dwc->num_clks, dwc->clks);
807
- clk_bulk_unprepare(dwc->num_clks, dwc->clks);
808
-
809
- if (!dwc->drd_connected && dwc->dr_mode == USB_DR_MODE_OTG)
810
- reset_control_assert(dwc->reset);
775
+ clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks);
776
+ reset_control_assert(dwc->reset);
811777 }
812778
813779 static bool dwc3_core_is_valid(struct dwc3 *dwc)
....@@ -815,15 +781,13 @@
815781 u32 reg;
816782
817783 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
784
+ dwc->ip = DWC3_GSNPS_ID(reg);
818785
819786 /* This should read as U3 followed by revision number */
820
- if ((reg & DWC3_GSNPSID_MASK) == 0x55330000) {
821
- /* Detected DWC_usb3 IP */
787
+ if (DWC3_IP_IS(DWC3)) {
822788 dwc->revision = reg;
823
- } else if ((reg & DWC3_GSNPSID_MASK) == 0x33310000) {
824
- /* Detected DWC_usb31 IP */
789
+ } else if (DWC3_IP_IS(DWC31) || DWC3_IP_IS(DWC32)) {
825790 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER);
826
- dwc->revision |= DWC3_REVISION_IS_DWC31;
827791 dwc->version_type = dwc3_readl(dwc->regs, DWC3_VER_TYPE);
828792 } else {
829793 return false;
....@@ -856,8 +820,7 @@
856820 */
857821 if ((dwc->dr_mode == USB_DR_MODE_HOST ||
858822 dwc->dr_mode == USB_DR_MODE_OTG) &&
859
- (dwc->revision >= DWC3_REVISION_210A &&
860
- dwc->revision <= DWC3_REVISION_250A))
823
+ DWC3_VER_IS_WITHIN(DWC3, 210A, 250A))
861824 reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
862825 else
863826 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
....@@ -879,7 +842,7 @@
879842
880843 /* check if current dwc3 is on simulation board */
881844 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) {
882
- dev_info(dwc->dev, "Running with FPGA optmizations\n");
845
+ dev_info(dwc->dev, "Running with FPGA optimizations\n");
883846 dwc->is_fpga = true;
884847 }
885848
....@@ -900,7 +863,7 @@
900863 * and falls back to high-speed mode which causes
901864 * the device to enter a Connect/Disconnect loop
902865 */
903
- if (dwc->revision < DWC3_REVISION_190A)
866
+ if (DWC3_VER_IS_PRIOR(DWC3, 190A))
904867 reg |= DWC3_GCTL_U2RSTECN;
905868
906869 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
....@@ -932,8 +895,7 @@
932895 * result = 1, means INCRx burst mode supported.
933896 * result > 1, means undefined length burst mode supported.
934897 */
935
- ntype = device_property_read_u32_array(dev,
936
- "snps,incr-burst-type-adjustment", NULL, 0);
898
+ ntype = device_property_count_u32(dev, "snps,incr-burst-type-adjustment");
937899 if (ntype <= 0)
938900 return;
939901
....@@ -1012,21 +974,17 @@
1012974 */
1013975 static int dwc3_core_init(struct dwc3 *dwc)
1014976 {
977
+ unsigned int hw_mode;
1015978 u32 reg;
1016979 int ret;
980
+
981
+ hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
1017982
1018983 /*
1019984 * Write Linux Version Code to our GUID register so it's easy to figure
1020985 * out which kernel version a bug was found.
1021986 */
1022987 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
1023
-
1024
- /* Handle USB2.0-only core configuration */
1025
- if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
1026
- DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
1027
- if (dwc->maximum_speed == USB_SPEED_SUPER)
1028
- dwc->maximum_speed = USB_SPEED_HIGH;
1029
- }
1030988
1031989 ret = dwc3_phy_setup(dwc);
1032990 if (ret)
....@@ -1046,9 +1004,36 @@
10461004 dwc->phys_ready = true;
10471005 }
10481006
1007
+ usb_phy_init(dwc->usb2_phy);
1008
+ usb_phy_init(dwc->usb3_phy);
1009
+ ret = phy_init(dwc->usb2_generic_phy);
1010
+ if (ret < 0)
1011
+ goto err0a;
1012
+
1013
+ ret = phy_init(dwc->usb3_generic_phy);
1014
+ if (ret < 0) {
1015
+ phy_exit(dwc->usb2_generic_phy);
1016
+ goto err0a;
1017
+ }
1018
+
10491019 ret = dwc3_core_soft_reset(dwc);
10501020 if (ret)
1051
- goto err0a;
1021
+ goto err1;
1022
+
1023
+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD &&
1024
+ !DWC3_VER_IS_WITHIN(DWC3, ANY, 194A)) {
1025
+ if (!dwc->dis_u3_susphy_quirk) {
1026
+ reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
1027
+ reg |= DWC3_GUSB3PIPECTL_SUSPHY;
1028
+ dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
1029
+ }
1030
+
1031
+ if (!dwc->dis_u2_susphy_quirk) {
1032
+ reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
1033
+ reg |= DWC3_GUSB2PHYCFG_SUSPHY;
1034
+ dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
1035
+ }
1036
+ }
10521037
10531038 dwc3_core_setup_global_control(dwc);
10541039 dwc3_core_num_eps(dwc);
....@@ -1083,27 +1068,41 @@
10831068 * the DWC_usb3 controller. It is NOT available in the
10841069 * DWC_usb31 controller.
10851070 */
1086
- if (!dwc3_is_usb31(dwc) && dwc->revision >= DWC3_REVISION_310A) {
1071
+ if (DWC3_VER_IS_WITHIN(DWC3, 310A, ANY)) {
10871072 reg = dwc3_readl(dwc->regs, DWC3_GUCTL2);
10881073 reg |= DWC3_GUCTL2_RST_ACTBITLATER;
10891074 dwc3_writel(dwc->regs, DWC3_GUCTL2, reg);
10901075 }
10911076
1092
- if (dwc->revision >= DWC3_REVISION_250A) {
1077
+ if (!DWC3_VER_IS_PRIOR(DWC3, 250A)) {
10931078 reg = dwc3_readl(dwc->regs, DWC3_GUCTL1);
10941079
10951080 /*
10961081 * Enable hardware control of sending remote wakeup
10971082 * in HS when the device is in the L1 state.
10981083 */
1099
- if (dwc->revision >= DWC3_REVISION_290A)
1084
+ if (!DWC3_VER_IS_PRIOR(DWC3, 290A))
11001085 reg |= DWC3_GUCTL1_DEV_L1_EXIT_BY_HW;
1086
+
1087
+ /*
1088
+ * Decouple USB 2.0 L1 & L2 events which will allow for
1089
+ * gadget driver to only receive U3/L2 suspend & wakeup
1090
+ * events and prevent the more frequent L1 LPM transitions
1091
+ * from interrupting the driver.
1092
+ */
1093
+ if (!DWC3_VER_IS_PRIOR(DWC3, 300A))
1094
+ reg |= DWC3_GUCTL1_DEV_DECOUPLE_L1L2_EVT;
11011095
11021096 if (dwc->dis_tx_ipgap_linecheck_quirk)
11031097 reg |= DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS;
11041098
11051099 if (dwc->parkmode_disable_ss_quirk)
11061100 reg |= DWC3_GUCTL1_PARKMODE_DISABLE_SS;
1101
+
1102
+#ifdef CONFIG_NO_GKI
1103
+ if (dwc->parkmode_disable_hs_quirk)
1104
+ reg |= DWC3_GUCTL1_PARKMODE_DISABLE_HS;
1105
+#endif
11071106
11081107 if (dwc->maximum_speed == USB_SPEED_HIGH ||
11091108 dwc->maximum_speed == USB_SPEED_FULL)
....@@ -1132,7 +1131,7 @@
11321131 * Must config both number of packets and max burst settings to enable
11331132 * RX and/or TX threshold.
11341133 */
1135
- if (dwc3_is_usb31(dwc) && dwc->dr_mode == USB_DR_MODE_HOST) {
1134
+ if (!DWC3_IP_IS(DWC3) && dwc->dr_mode == USB_DR_MODE_HOST) {
11361135 u8 rx_thr_num = dwc->rx_thr_num_pkt_prd;
11371136 u8 rx_maxburst = dwc->rx_max_burst_prd;
11381137 u8 tx_thr_num = dwc->tx_thr_num_pkt_prd;
....@@ -1206,52 +1205,36 @@
12061205
12071206 if (IS_ERR(dwc->usb2_phy)) {
12081207 ret = PTR_ERR(dwc->usb2_phy);
1209
- if (ret == -ENXIO || ret == -ENODEV) {
1208
+ if (ret == -ENXIO || ret == -ENODEV)
12101209 dwc->usb2_phy = NULL;
1211
- } else if (ret == -EPROBE_DEFER) {
1212
- return ret;
1213
- } else {
1214
- dev_err(dev, "no usb2 phy configured\n");
1215
- return ret;
1216
- }
1210
+ else
1211
+ return dev_err_probe(dev, ret, "no usb2 phy configured\n");
12171212 }
12181213
12191214 if (IS_ERR(dwc->usb3_phy)) {
12201215 ret = PTR_ERR(dwc->usb3_phy);
1221
- if (ret == -ENXIO || ret == -ENODEV) {
1216
+ if (ret == -ENXIO || ret == -ENODEV)
12221217 dwc->usb3_phy = NULL;
1223
- } else if (ret == -EPROBE_DEFER) {
1224
- return ret;
1225
- } else {
1226
- dev_err(dev, "no usb3 phy configured\n");
1227
- return ret;
1228
- }
1218
+ else
1219
+ return dev_err_probe(dev, ret, "no usb3 phy configured\n");
12291220 }
12301221
12311222 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
12321223 if (IS_ERR(dwc->usb2_generic_phy)) {
12331224 ret = PTR_ERR(dwc->usb2_generic_phy);
1234
- if (ret == -ENOSYS || ret == -ENODEV) {
1225
+ if (ret == -ENOSYS || ret == -ENODEV)
12351226 dwc->usb2_generic_phy = NULL;
1236
- } else if (ret == -EPROBE_DEFER) {
1237
- return ret;
1238
- } else {
1239
- dev_err(dev, "no usb2 phy configured\n");
1240
- return ret;
1241
- }
1227
+ else
1228
+ return dev_err_probe(dev, ret, "no usb2 phy configured\n");
12421229 }
12431230
12441231 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
12451232 if (IS_ERR(dwc->usb3_generic_phy)) {
12461233 ret = PTR_ERR(dwc->usb3_generic_phy);
1247
- if (ret == -ENOSYS || ret == -ENODEV) {
1234
+ if (ret == -ENOSYS || ret == -ENODEV)
12481235 dwc->usb3_generic_phy = NULL;
1249
- } else if (ret == -EPROBE_DEFER) {
1250
- return ret;
1251
- } else {
1252
- dev_err(dev, "no usb3 phy configured\n");
1253
- return ret;
1254
- }
1236
+ else
1237
+ return dev_err_probe(dev, ret, "no usb3 phy configured\n");
12551238 }
12561239
12571240 return 0;
....@@ -1272,28 +1255,10 @@
12721255 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_DEVICE);
12731256
12741257 ret = dwc3_gadget_init(dwc);
1275
- if (ret) {
1276
- if (ret != -EPROBE_DEFER)
1277
- dev_err(dev, "failed to initialize gadget\n");
1278
- return ret;
1279
- }
1280
-
1281
- if (dwc->uwk_en)
1282
- device_init_wakeup(dev, true);
1258
+ if (ret)
1259
+ return dev_err_probe(dev, ret, "failed to initialize gadget\n");
12831260 break;
12841261 case USB_DR_MODE_HOST:
1285
- /*
1286
- * To prevent usb device be reenumerated when resume from PM
1287
- * suspend, we set the flag dwc->power.can_wakeup which can
1288
- * keep PD on and run phy_power_on again to avoid
1289
- * phy_power_on failed (error -110) in Rockchip platform.
1290
- */
1291
- if (!of_machine_is_compatible("rockchip,rk3568") &&
1292
- !of_machine_is_compatible("rockchip,rk3566"))
1293
- device_init_wakeup(dev, true);
1294
-
1295
- phy_power_on(dwc->usb3_generic_phy);
1296
-
12971262 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_HOST);
12981263
12991264 if (dwc->usb2_phy)
....@@ -1302,37 +1267,14 @@
13021267 phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
13031268
13041269 ret = dwc3_host_init(dwc);
1305
- if (ret) {
1306
- if (ret != -EPROBE_DEFER)
1307
- dev_err(dev, "failed to initialize host\n");
1308
- return ret;
1309
- }
1310
- if (!of_device_is_compatible(dwc->dev->parent->of_node,
1311
- "rockchip,rk3399-dwc3"))
1312
- phy_calibrate(dwc->usb2_generic_phy);
1270
+ if (ret)
1271
+ return dev_err_probe(dev, ret, "failed to initialize host\n");
13131272 break;
13141273 case USB_DR_MODE_OTG:
13151274 INIT_WORK(&dwc->drd_work, __dwc3_set_mode);
1316
- if (dwc->en_runtime) {
1317
- ret = dwc3_gadget_init(dwc);
1318
- if (ret) {
1319
- if (ret != -EPROBE_DEFER)
1320
- dev_err(dev, "failed to initialize gadget\n");
1321
- return ret;
1322
- }
1323
- }
13241275 ret = dwc3_drd_init(dwc);
1325
- if (ret) {
1326
- if (dwc->en_runtime)
1327
- dwc3_gadget_exit(dwc);
1328
-
1329
- if (ret != -EPROBE_DEFER)
1330
- dev_err(dev, "failed to initialize dual-role\n");
1331
- return ret;
1332
- }
1333
-
1334
- if (dwc->uwk_en)
1335
- device_init_wakeup(dev, true);
1276
+ if (ret)
1277
+ return dev_err_probe(dev, ret, "failed to initialize dual-role\n");
13361278 break;
13371279 default:
13381280 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
....@@ -1369,10 +1311,13 @@
13691311 u8 lpm_nyet_threshold;
13701312 u8 tx_de_emphasis;
13711313 u8 hird_threshold;
1372
- u8 rx_thr_num_pkt_prd;
1373
- u8 rx_max_burst_prd;
1374
- u8 tx_thr_num_pkt_prd;
1375
- u8 tx_max_burst_prd;
1314
+ u8 rx_thr_num_pkt_prd = 0;
1315
+ u8 rx_max_burst_prd = 0;
1316
+ u8 tx_thr_num_pkt_prd = 0;
1317
+ u8 tx_max_burst_prd = 0;
1318
+ u8 tx_fifo_resize_max_num;
1319
+ const char *usb_psy_name;
1320
+ int ret;
13761321
13771322 /* default to highest possible threshold */
13781323 lpm_nyet_threshold = 0xf;
....@@ -1386,7 +1331,15 @@
13861331 */
13871332 hird_threshold = 12;
13881333
1334
+ /*
1335
+ * default to a TXFIFO size large enough to fit 6 max packets. This
1336
+ * allows for systems with larger bus latencies to have some headroom
1337
+ * for endpoints that have a large bMaxBurst value.
1338
+ */
1339
+ tx_fifo_resize_max_num = 6;
1340
+
13891341 dwc->maximum_speed = usb_get_maximum_speed(dev);
1342
+ dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev);
13901343 dwc->dr_mode = usb_get_dr_mode(dev);
13911344 dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
13921345
....@@ -1396,6 +1349,13 @@
13961349 dwc->sysdev = dwc->dev->parent;
13971350 else
13981351 dwc->sysdev = dwc->dev;
1352
+
1353
+ ret = device_property_read_string(dev, "usb-psy-name", &usb_psy_name);
1354
+ if (ret >= 0) {
1355
+ dwc->usb_psy = power_supply_get_by_name(usb_psy_name);
1356
+ if (!dwc->usb_psy)
1357
+ dev_err(dev, "couldn't get usb power supply\n");
1358
+ }
13991359
14001360 dwc->has_lpm_erratum = device_property_read_bool(dev,
14011361 "snps,has-lpm-erratum");
....@@ -1411,6 +1371,8 @@
14111371 "snps,usb3_lpm_capable");
14121372 dwc->usb2_lpm_disable = device_property_read_bool(dev,
14131373 "snps,usb2-lpm-disable");
1374
+ dwc->usb2_gadget_lpm_disable = device_property_read_bool(dev,
1375
+ "snps,usb2-gadget-lpm-disable");
14141376 device_property_read_u8(dev, "snps,rx-thr-num-pkt-prd",
14151377 &rx_thr_num_pkt_prd);
14161378 device_property_read_u8(dev, "snps,rx-max-burst-prd",
....@@ -1419,6 +1381,11 @@
14191381 &tx_thr_num_pkt_prd);
14201382 device_property_read_u8(dev, "snps,tx-max-burst-prd",
14211383 &tx_max_burst_prd);
1384
+ dwc->do_fifo_resize = device_property_read_bool(dev,
1385
+ "tx-fifo-resize");
1386
+ if (dwc->do_fifo_resize)
1387
+ device_property_read_u8(dev, "tx-fifo-max-num",
1388
+ &tx_fifo_resize_max_num);
14221389
14231390 dwc->disable_scramble_quirk = device_property_read_bool(dev,
14241391 "snps,disable_scramble_quirk");
....@@ -1440,10 +1407,12 @@
14401407 "snps,dis_u3_susphy_quirk");
14411408 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev,
14421409 "snps,dis_u2_susphy_quirk");
1443
- dwc->dis_u1u2_quirk = device_property_read_bool(dev,
1444
- "snps,dis-u1u2-quirk");
14451410 dwc->dis_enblslpm_quirk = device_property_read_bool(dev,
14461411 "snps,dis_enblslpm_quirk");
1412
+ dwc->dis_u1_entry_quirk = device_property_read_bool(dev,
1413
+ "snps,dis-u1-entry-quirk");
1414
+ dwc->dis_u2_entry_quirk = device_property_read_bool(dev,
1415
+ "snps,dis-u2-entry-quirk");
14471416 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
14481417 "snps,dis_rxdet_inp3_quirk");
14491418 dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
....@@ -1454,12 +1423,10 @@
14541423 "snps,dis-tx-ipgap-linecheck-quirk");
14551424 dwc->parkmode_disable_ss_quirk = device_property_read_bool(dev,
14561425 "snps,parkmode-disable-ss-quirk");
1457
- dwc->xhci_slow_suspend_quirk = device_property_read_bool(dev,
1458
- "snps,xhci-slow-suspend-quirk");
1459
- dwc->xhci_trb_ent_quirk = device_property_read_bool(dev,
1460
- "snps,xhci-trb-ent-quirk");
1461
- dwc->dis_u3_autosuspend_quirk = device_property_read_bool(dev,
1462
- "snps,dis-u3-autosuspend-quirk");
1426
+#ifdef CONFIG_NO_GKI
1427
+ dwc->parkmode_disable_hs_quirk = device_property_read_bool(dev,
1428
+ "snps,parkmode-disable-hs-quirk");
1429
+#endif
14631430
14641431 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
14651432 "snps,tx_de_emphasis_quirk");
....@@ -1472,18 +1439,14 @@
14721439
14731440 dwc->dis_metastability_quirk = device_property_read_bool(dev,
14741441 "snps,dis_metastability_quirk");
1475
- dwc->needs_fifo_resize = device_property_read_bool(dev,
1476
- "snps,tx-fifo-resize");
1477
- dwc->xhci_warm_reset_on_suspend_quirk = device_property_read_bool(dev,
1478
- "snps,xhci-warm-reset-on-suspend-quirk");
1479
- dwc->uwk_en = device_property_read_bool(dev,
1480
- "wakeup-source");
1442
+
1443
+ dwc->dis_split_quirk = device_property_read_bool(dev,
1444
+ "snps,dis-split-quirk");
14811445
14821446 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
14831447 dwc->tx_de_emphasis = tx_de_emphasis;
14841448
1485
- dwc->hird_threshold = hird_threshold
1486
- | (dwc->is_utmi_l1_suspend << 4);
1449
+ dwc->hird_threshold = hird_threshold;
14871450
14881451 dwc->rx_thr_num_pkt_prd = rx_thr_num_pkt_prd;
14891452 dwc->rx_max_burst_prd = rx_max_burst_prd;
....@@ -1492,20 +1455,23 @@
14921455 dwc->tx_max_burst_prd = tx_max_burst_prd;
14931456
14941457 dwc->imod_interval = 0;
1458
+
1459
+ dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num;
14951460 }
14961461
14971462 /* check whether the core supports IMOD */
14981463 bool dwc3_has_imod(struct dwc3 *dwc)
14991464 {
1500
- return ((dwc3_is_usb3(dwc) &&
1501
- dwc->revision >= DWC3_REVISION_300A) ||
1502
- (dwc3_is_usb31(dwc) &&
1503
- dwc->revision >= DWC3_USB31_REVISION_120A));
1465
+ return DWC3_VER_IS_WITHIN(DWC3, 300A, ANY) ||
1466
+ DWC3_VER_IS_WITHIN(DWC31, 120A, ANY) ||
1467
+ DWC3_IP_IS(DWC32);
15041468 }
15051469
15061470 static void dwc3_check_params(struct dwc3 *dwc)
15071471 {
15081472 struct device *dev = dwc->dev;
1473
+ unsigned int hwparam_gen =
1474
+ DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3);
15091475
15101476 /* Check for proper value of imod_interval */
15111477 if (dwc->imod_interval && !dwc3_has_imod(dwc)) {
....@@ -1521,7 +1487,7 @@
15211487 * affected version.
15221488 */
15231489 if (!dwc->imod_interval &&
1524
- (dwc->revision == DWC3_REVISION_300A))
1490
+ DWC3_VER_IS(DWC3, 300A))
15251491 dwc->imod_interval = 1;
15261492
15271493 /* Check the maximum_speed parameter */
....@@ -1529,64 +1495,95 @@
15291495 case USB_SPEED_LOW:
15301496 case USB_SPEED_FULL:
15311497 case USB_SPEED_HIGH:
1498
+ break;
15321499 case USB_SPEED_SUPER:
1500
+ if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS)
1501
+ dev_warn(dev, "UDC doesn't support Gen 1\n");
1502
+ break;
15331503 case USB_SPEED_SUPER_PLUS:
1504
+ if ((DWC3_IP_IS(DWC32) &&
1505
+ hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_DIS) ||
1506
+ (!DWC3_IP_IS(DWC32) &&
1507
+ hwparam_gen != DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
1508
+ dev_warn(dev, "UDC doesn't support SSP\n");
15341509 break;
15351510 default:
15361511 dev_err(dev, "invalid maximum_speed parameter %d\n",
15371512 dwc->maximum_speed);
1538
- /* fall through */
1513
+ fallthrough;
15391514 case USB_SPEED_UNKNOWN:
1540
- /* default to superspeed */
1541
- dwc->maximum_speed = USB_SPEED_SUPER;
1542
-
1543
- /*
1544
- * default to superspeed plus if we are capable.
1545
- */
1546
- if (dwc3_is_usb31(dwc) &&
1547
- (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
1548
- DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
1515
+ switch (hwparam_gen) {
1516
+ case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2:
15491517 dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
1550
-
1518
+ break;
1519
+ case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1:
1520
+ if (DWC3_IP_IS(DWC32))
1521
+ dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
1522
+ else
1523
+ dwc->maximum_speed = USB_SPEED_SUPER;
1524
+ break;
1525
+ case DWC3_GHWPARAMS3_SSPHY_IFC_DIS:
1526
+ dwc->maximum_speed = USB_SPEED_HIGH;
1527
+ break;
1528
+ default:
1529
+ dwc->maximum_speed = USB_SPEED_SUPER;
1530
+ break;
1531
+ }
15511532 break;
15521533 }
1553
-}
15541534
1555
-static void dwc3_rockchip_async_probe(void *data, async_cookie_t cookie)
1556
-{
1557
- struct dwc3 *dwc = data;
1558
- struct device *dev = dwc->dev;
1559
- int id;
1560
-
1561
- if (dwc->edev && !dwc->drd_connected) {
1562
- id = extcon_get_state(dwc->edev, EXTCON_USB_HOST);
1563
- if (id < 0)
1564
- id = 0;
1565
- dwc->current_dr_role = id ? DWC3_GCTL_PRTCAP_HOST :
1566
- DWC3_GCTL_PRTCAP_DEVICE;
1535
+ /*
1536
+ * Currently the controller does not have visibility into the HW
1537
+ * parameter to determine the maximum number of lanes the HW supports.
1538
+ * If the number of lanes is not specified in the device property, then
1539
+ * set the default to support dual-lane for DWC_usb32 and single-lane
1540
+ * for DWC_usb31 for super-speed-plus.
1541
+ */
1542
+ if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) {
1543
+ switch (dwc->max_ssp_rate) {
1544
+ case USB_SSP_GEN_2x1:
1545
+ if (hwparam_gen == DWC3_GHWPARAMS3_SSPHY_IFC_GEN1)
1546
+ dev_warn(dev, "UDC only supports Gen 1\n");
1547
+ break;
1548
+ case USB_SSP_GEN_1x2:
1549
+ case USB_SSP_GEN_2x2:
1550
+ if (DWC3_IP_IS(DWC31))
1551
+ dev_warn(dev, "UDC only supports single lane\n");
1552
+ break;
1553
+ case USB_SSP_GEN_UNKNOWN:
1554
+ default:
1555
+ switch (hwparam_gen) {
1556
+ case DWC3_GHWPARAMS3_SSPHY_IFC_GEN2:
1557
+ if (DWC3_IP_IS(DWC32))
1558
+ dwc->max_ssp_rate = USB_SSP_GEN_2x2;
1559
+ else
1560
+ dwc->max_ssp_rate = USB_SSP_GEN_2x1;
1561
+ break;
1562
+ case DWC3_GHWPARAMS3_SSPHY_IFC_GEN1:
1563
+ if (DWC3_IP_IS(DWC32))
1564
+ dwc->max_ssp_rate = USB_SSP_GEN_1x2;
1565
+ break;
1566
+ }
1567
+ break;
1568
+ }
15671569 }
1568
-
1569
- pm_runtime_put_sync_suspend(dev);
15701570 }
15711571
15721572 static int dwc3_probe(struct platform_device *pdev)
15731573 {
15741574 struct device *dev = &pdev->dev;
15751575 struct resource *res, dwc_res;
1576
+ struct dwc3_vendor *vdwc;
15761577 struct dwc3 *dwc;
15771578
15781579 int ret;
15791580
15801581 void __iomem *regs;
15811582
1582
- dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
1583
- if (!dwc)
1583
+ vdwc = devm_kzalloc(dev, sizeof(*vdwc), GFP_KERNEL);
1584
+ if (!vdwc)
15841585 return -ENOMEM;
1585
-
1586
- dwc->clks = devm_kmemdup(dev, dwc3_core_clks, sizeof(dwc3_core_clks),
1587
- GFP_KERNEL);
1588
- if (!dwc->clks)
1589
- return -ENOMEM;
1586
+ dwc = &vdwc->dwc;
15901587
15911588 dwc->dev = dev;
15921589
....@@ -1616,58 +1613,46 @@
16161613 dwc->regs = regs;
16171614 dwc->regs_size = resource_size(&dwc_res);
16181615
1619
- dwc->reset = devm_reset_control_get_optional_shared(dev, NULL);
1616
+ dwc3_get_properties(dwc);
1617
+
1618
+ dwc->reset = devm_reset_control_array_get_optional_shared(dev);
16201619 if (IS_ERR(dwc->reset))
16211620 return PTR_ERR(dwc->reset);
16221621
1623
- ret = reset_control_deassert(dwc->reset);
1624
- if (ret)
1625
- return ret;
1626
-
1627
- /* Reset the whole dwc3 controller */
1628
- ret = reset_control_assert(dwc->reset);
1629
- if (ret)
1630
- return ret;
1631
-
1632
- udelay(1);
1633
-
1634
- ret = reset_control_deassert(dwc->reset);
1635
- if (ret)
1636
- return ret;
1637
-
1638
- if (!dwc3_core_is_valid(dwc)) {
1639
- dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
1640
- return -ENODEV;
1641
- }
1642
-
1643
- dwc3_get_properties(dwc);
1644
-
16451622 if (dev->of_node) {
1646
- dwc->num_clks = ARRAY_SIZE(dwc3_core_clks);
1647
-
1648
- ret = clk_bulk_get(dev, dwc->num_clks, dwc->clks);
1623
+ ret = devm_clk_bulk_get_all(dev, &dwc->clks);
16491624 if (ret == -EPROBE_DEFER)
1650
- goto assert_reset;
1625
+ return ret;
16511626 /*
16521627 * Clocks are optional, but new DT platforms should support all
16531628 * clocks as required by the DT-binding.
16541629 */
1655
- if (ret)
1630
+ if (ret < 0)
16561631 dwc->num_clks = 0;
1632
+ else
1633
+ dwc->num_clks = ret;
1634
+
16571635 }
16581636
1659
- ret = clk_bulk_prepare(dwc->num_clks, dwc->clks);
1637
+ ret = reset_control_deassert(dwc->reset);
16601638 if (ret)
1661
- goto put_clks;
1639
+ return ret;
16621640
1663
- ret = clk_bulk_enable(dwc->num_clks, dwc->clks);
1641
+ ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks);
16641642 if (ret)
1665
- goto unprepare_clks;
1643
+ goto assert_reset;
1644
+
1645
+ if (!dwc3_core_is_valid(dwc)) {
1646
+ dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
1647
+ ret = -ENODEV;
1648
+ goto disable_clks;
1649
+ }
16661650
16671651 platform_set_drvdata(pdev, dwc);
16681652 dwc3_cache_hwparams(dwc);
16691653
16701654 spin_lock_init(&dwc->lock);
1655
+ mutex_init(&dwc->mutex);
16711656
16721657 pm_runtime_set_active(dev);
16731658 pm_runtime_use_autosuspend(dev);
....@@ -1690,21 +1675,13 @@
16901675 if (ret)
16911676 goto err3;
16921677
1693
- if (dwc->dr_mode == USB_DR_MODE_OTG &&
1694
- of_device_is_compatible(dev->parent->of_node,
1695
- "rockchip,rk3399-dwc3")) {
1696
- pm_runtime_allow(dev);
1697
- dwc->en_runtime = true;
1698
- }
1699
-
17001678 ret = dwc3_alloc_scratch_buffers(dwc);
17011679 if (ret)
17021680 goto err3;
17031681
17041682 ret = dwc3_core_init(dwc);
17051683 if (ret) {
1706
- if (ret != -EPROBE_DEFER)
1707
- dev_err(dev, "failed to initialize core: %d\n", ret);
1684
+ dev_err_probe(dev, ret, "failed to initialize core\n");
17081685 goto err4;
17091686 }
17101687
....@@ -1715,10 +1692,17 @@
17151692 if (ret)
17161693 goto err5;
17171694
1718
- if (dwc->en_runtime)
1719
- async_schedule(dwc3_rockchip_async_probe, dwc);
1720
- else
1695
+ if (dwc->dr_mode == USB_DR_MODE_OTG &&
1696
+ of_device_is_compatible(dev->parent->of_node,
1697
+ "rockchip,rk3399-dwc3")) {
1698
+#if defined(CONFIG_ARCH_ROCKCHIP) && defined(CONFIG_NO_GKI)
1699
+ pm_runtime_set_autosuspend_delay(dev, 100);
1700
+#endif
1701
+ pm_runtime_allow(dev);
1702
+ pm_runtime_put_sync_suspend(dev);
1703
+ } else {
17211704 pm_runtime_put(dev);
1705
+ }
17221706
17231707 return 0;
17241708
....@@ -1726,15 +1710,15 @@
17261710 dwc3_debugfs_exit(dwc);
17271711 dwc3_event_buffers_cleanup(dwc);
17281712
1729
- usb_phy_shutdown(dwc->usb2_phy);
1730
- usb_phy_shutdown(dwc->usb3_phy);
1731
- phy_exit(dwc->usb2_generic_phy);
1732
- phy_exit(dwc->usb3_generic_phy);
1733
-
17341713 usb_phy_set_suspend(dwc->usb2_phy, 1);
17351714 usb_phy_set_suspend(dwc->usb3_phy, 1);
17361715 phy_power_off(dwc->usb2_generic_phy);
17371716 phy_power_off(dwc->usb3_generic_phy);
1717
+
1718
+ usb_phy_shutdown(dwc->usb2_phy);
1719
+ usb_phy_shutdown(dwc->usb3_phy);
1720
+ phy_exit(dwc->usb2_generic_phy);
1721
+ phy_exit(dwc->usb3_generic_phy);
17381722
17391723 dwc3_ulpi_exit(dwc);
17401724
....@@ -1751,13 +1735,13 @@
17511735 pm_runtime_put_sync(&pdev->dev);
17521736 pm_runtime_disable(&pdev->dev);
17531737
1754
- clk_bulk_disable(dwc->num_clks, dwc->clks);
1755
-unprepare_clks:
1756
- clk_bulk_unprepare(dwc->num_clks, dwc->clks);
1757
-put_clks:
1758
- clk_bulk_put(dwc->num_clks, dwc->clks);
1738
+disable_clks:
1739
+ clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks);
17591740 assert_reset:
17601741 reset_control_assert(dwc->reset);
1742
+
1743
+ if (dwc->usb_psy)
1744
+ power_supply_put(dwc->usb_psy);
17611745
17621746 return ret;
17631747 }
....@@ -1780,7 +1764,9 @@
17801764
17811765 dwc3_free_event_buffers(dwc);
17821766 dwc3_free_scratch_buffers(dwc);
1783
- clk_bulk_put(dwc->num_clks, dwc->clks);
1767
+
1768
+ if (dwc->usb_psy)
1769
+ power_supply_put(dwc->usb_psy);
17841770
17851771 return 0;
17861772 }
....@@ -1790,19 +1776,13 @@
17901776 {
17911777 int ret;
17921778
1793
- if (!dwc->drd_connected && dwc->dr_mode == USB_DR_MODE_OTG) {
1794
- ret = reset_control_deassert(dwc->reset);
1795
- if (ret)
1796
- return ret;
1797
- }
1779
+ ret = reset_control_deassert(dwc->reset);
1780
+ if (ret)
1781
+ return ret;
17981782
1799
- ret = clk_bulk_prepare(dwc->num_clks, dwc->clks);
1783
+ ret = clk_bulk_prepare_enable(dwc->num_clks, dwc->clks);
18001784 if (ret)
18011785 goto assert_reset;
1802
-
1803
- ret = clk_bulk_enable(dwc->num_clks, dwc->clks);
1804
- if (ret)
1805
- goto unprepare_clks;
18061786
18071787 ret = dwc3_core_init(dwc);
18081788 if (ret)
....@@ -1811,12 +1791,9 @@
18111791 return 0;
18121792
18131793 disable_clks:
1814
- clk_bulk_disable(dwc->num_clks, dwc->clks);
1815
-unprepare_clks:
1816
- clk_bulk_unprepare(dwc->num_clks, dwc->clks);
1794
+ clk_bulk_disable_unprepare(dwc->num_clks, dwc->clks);
18171795 assert_reset:
1818
- if (!dwc->drd_connected && dwc->dr_mode == USB_DR_MODE_OTG)
1819
- reset_control_assert(dwc->reset);
1796
+ reset_control_assert(dwc->reset);
18201797
18211798 return ret;
18221799 }
....@@ -1828,14 +1805,14 @@
18281805
18291806 switch (dwc->current_dr_role) {
18301807 case DWC3_GCTL_PRTCAP_DEVICE:
1831
- spin_lock_irqsave(&dwc->lock, flags);
1808
+ if (pm_runtime_suspended(dwc->dev))
1809
+ break;
18321810 dwc3_gadget_suspend(dwc);
1833
- spin_unlock_irqrestore(&dwc->lock, flags);
18341811 synchronize_irq(dwc->irq_gadget);
18351812 dwc3_core_exit(dwc);
18361813 break;
18371814 case DWC3_GCTL_PRTCAP_HOST:
1838
- if (!PMSG_IS_AUTO(msg) || dwc->en_runtime) {
1815
+ if (!PMSG_IS_AUTO(msg)) {
18391816 dwc3_core_exit(dwc);
18401817 break;
18411818 }
....@@ -1871,7 +1848,8 @@
18711848 dwc3_core_exit(dwc);
18721849 break;
18731850 default:
1874
- /* do nothing */
1851
+ if (!pm_runtime_suspended(dwc->dev))
1852
+ dwc3_core_exit(dwc);
18751853 break;
18761854 }
18771855
....@@ -1891,12 +1869,10 @@
18911869 return ret;
18921870
18931871 dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE);
1894
- spin_lock_irqsave(&dwc->lock, flags);
18951872 dwc3_gadget_resume(dwc);
1896
- spin_unlock_irqrestore(&dwc->lock, flags);
18971873 break;
18981874 case DWC3_GCTL_PRTCAP_HOST:
1899
- if (!PMSG_IS_AUTO(msg) || dwc->en_runtime) {
1875
+ if (!PMSG_IS_AUTO(msg)) {
19001876 ret = dwc3_core_init_for_resume(dwc);
19011877 if (ret)
19021878 return ret;
....@@ -1938,7 +1914,9 @@
19381914
19391915 break;
19401916 default:
1941
- /* do nothing */
1917
+ ret = dwc3_core_init_for_resume(dwc);
1918
+ if (ret)
1919
+ return ret;
19421920 break;
19431921 }
19441922
....@@ -2032,40 +2010,12 @@
20322010 struct dwc3 *dwc = dev_get_drvdata(dev);
20332011 int ret;
20342012
2035
- if (dwc->uwk_en) {
2036
- dwc3_gadget_disable_irq(dwc);
2037
- synchronize_irq(dwc->irq_gadget);
2038
- return 0;
2039
- }
2040
-
20412013 if (pm_runtime_suspended(dwc->dev))
20422014 return 0;
20432015
20442016 ret = dwc3_suspend_common(dwc, PMSG_SUSPEND);
20452017 if (ret)
20462018 return ret;
2047
-
2048
- /*
2049
- * If link state is Rx.Detect, it means that
2050
- * no usb device is connecting with the DWC3
2051
- * Host, and need to power off the USB3 PHY.
2052
- *
2053
- * If link state is in other state, like U0
2054
- * or U3 state, it means that at least one
2055
- * USB3 device is connecting with the Host
2056
- * port, in this case, we don't power off
2057
- * the USB3 PHY because some USB3 PHYs (like
2058
- * RK3399 Type-C USB3 PHY) require that the
2059
- * power on operation must be done while the
2060
- * DWC3 controller is in P2 state, but the
2061
- * state is in P0 after resume with a USB3
2062
- * device connected. So we set the USB3 PHY
2063
- * in power on state in this case.
2064
- */
2065
- dwc->link_state = dwc3_gadget_get_link_state(dwc);
2066
- if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
2067
- dwc->link_state == DWC3_LINK_STATE_RX_DET)
2068
- phy_power_off(dwc->usb3_generic_phy);
20692019
20702020 pinctrl_pm_select_sleep_state(dev);
20712021
....@@ -2077,19 +2027,10 @@
20772027 struct dwc3 *dwc = dev_get_drvdata(dev);
20782028 int ret;
20792029
2080
- if (dwc->uwk_en) {
2081
- dwc3_gadget_enable_irq(dwc);
2082
- return 0;
2083
- }
2084
-
20852030 if (pm_runtime_suspended(dwc->dev))
20862031 return 0;
20872032
20882033 pinctrl_pm_select_default_state(dev);
2089
-
2090
- if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
2091
- dwc->link_state == DWC3_LINK_STATE_RX_DET)
2092
- phy_power_on(dwc->usb3_generic_phy);
20932034
20942035 ret = dwc3_resume_common(dwc, PMSG_RESUME);
20952036 if (ret)
....@@ -2101,10 +2042,26 @@
21012042
21022043 return 0;
21032044 }
2045
+
2046
+static void dwc3_complete(struct device *dev)
2047
+{
2048
+ struct dwc3 *dwc = dev_get_drvdata(dev);
2049
+ u32 reg;
2050
+
2051
+ if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
2052
+ dwc->dis_split_quirk) {
2053
+ reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
2054
+ reg |= DWC3_GUCTL3_SPLITDISABLE;
2055
+ dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
2056
+ }
2057
+}
2058
+#else
2059
+#define dwc3_complete NULL
21042060 #endif /* CONFIG_PM_SLEEP */
21052061
21062062 static const struct dev_pm_ops dwc3_dev_pm_ops = {
21072063 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
2064
+ .complete = dwc3_complete,
21082065 SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume,
21092066 dwc3_runtime_idle)
21102067 };