hc
2024-05-10 748e4f3d702def1a4bff191e0cf93b6a05340f01
kernel/drivers/usb/dwc3/dwc3-qcom.c
....@@ -4,14 +4,16 @@
44 * Inspired by dwc3-of-simple.c
55 */
66
7
+#include <linux/acpi.h>
78 #include <linux/io.h>
89 #include <linux/of.h>
910 #include <linux/clk.h>
1011 #include <linux/irq.h>
11
-#include <linux/clk-provider.h>
12
+#include <linux/of_clk.h>
1213 #include <linux/module.h>
1314 #include <linux/kernel.h>
1415 #include <linux/extcon.h>
16
+#include <linux/interconnect.h>
1517 #include <linux/of_platform.h>
1618 #include <linux/platform_device.h>
1719 #include <linux/phy/phy.h>
....@@ -38,10 +40,34 @@
3840 #define PWR_EVNT_LPM_IN_L2_MASK BIT(4)
3941 #define PWR_EVNT_LPM_OUT_L2_MASK BIT(5)
4042
43
+#define SDM845_QSCRATCH_BASE_OFFSET 0xf8800
44
+#define SDM845_QSCRATCH_SIZE 0x400
45
+#define SDM845_DWC3_CORE_SIZE 0xcd00
46
+
47
+/* Interconnect path bandwidths in MBps */
48
+#define USB_MEMORY_AVG_HS_BW MBps_to_icc(240)
49
+#define USB_MEMORY_PEAK_HS_BW MBps_to_icc(700)
50
+#define USB_MEMORY_AVG_SS_BW MBps_to_icc(1000)
51
+#define USB_MEMORY_PEAK_SS_BW MBps_to_icc(2500)
52
+#define APPS_USB_AVG_BW 0
53
+#define APPS_USB_PEAK_BW MBps_to_icc(40)
54
+
55
+struct dwc3_acpi_pdata {
56
+ u32 qscratch_base_offset;
57
+ u32 qscratch_base_size;
58
+ u32 dwc3_core_base_size;
59
+ int hs_phy_irq_index;
60
+ int dp_hs_phy_irq_index;
61
+ int dm_hs_phy_irq_index;
62
+ int ss_phy_irq_index;
63
+ bool is_urs;
64
+};
65
+
4166 struct dwc3_qcom {
4267 struct device *dev;
4368 void __iomem *qscratch_base;
4469 struct platform_device *dwc3;
70
+ struct platform_device *urs_usb;
4571 struct clk **clks;
4672 int num_clocks;
4773 struct reset_control *resets;
....@@ -56,9 +82,13 @@
5682 struct notifier_block vbus_nb;
5783 struct notifier_block host_nb;
5884
85
+ const struct dwc3_acpi_pdata *acpi_pdata;
86
+
5987 enum usb_dr_mode mode;
6088 bool is_suspended;
6189 bool pm_suspended;
90
+ struct icc_path *icc_path_ddr;
91
+ struct icc_path *icc_path_apps;
6292 };
6393
6494 static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val)
....@@ -85,7 +115,7 @@
85115 readl(base + offset);
86116 }
87117
88
-static void dwc3_qcom_vbus_overrride_enable(struct dwc3_qcom *qcom, bool enable)
118
+static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool enable)
89119 {
90120 if (enable) {
91121 dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL,
....@@ -106,7 +136,7 @@
106136 struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, vbus_nb);
107137
108138 /* enable vbus override for device mode */
109
- dwc3_qcom_vbus_overrride_enable(qcom, event);
139
+ dwc3_qcom_vbus_override_enable(qcom, event);
110140 qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST;
111141
112142 return NOTIFY_DONE;
....@@ -118,7 +148,7 @@
118148 struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, host_nb);
119149
120150 /* disable vbus override in host mode */
121
- dwc3_qcom_vbus_overrride_enable(qcom, !event);
151
+ dwc3_qcom_vbus_override_enable(qcom, !event);
122152 qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL;
123153
124154 return NOTIFY_DONE;
....@@ -173,6 +203,123 @@
173203 return 0;
174204 }
175205
206
+static int dwc3_qcom_interconnect_enable(struct dwc3_qcom *qcom)
207
+{
208
+ int ret;
209
+
210
+ ret = icc_enable(qcom->icc_path_ddr);
211
+ if (ret)
212
+ return ret;
213
+
214
+ ret = icc_enable(qcom->icc_path_apps);
215
+ if (ret)
216
+ icc_disable(qcom->icc_path_ddr);
217
+
218
+ return ret;
219
+}
220
+
221
+static int dwc3_qcom_interconnect_disable(struct dwc3_qcom *qcom)
222
+{
223
+ int ret;
224
+
225
+ ret = icc_disable(qcom->icc_path_ddr);
226
+ if (ret)
227
+ return ret;
228
+
229
+ ret = icc_disable(qcom->icc_path_apps);
230
+ if (ret)
231
+ icc_enable(qcom->icc_path_ddr);
232
+
233
+ return ret;
234
+}
235
+
236
+/**
237
+ * dwc3_qcom_interconnect_init() - Get interconnect path handles
238
+ * and set bandwidhth.
239
+ * @qcom: Pointer to the concerned usb core.
240
+ *
241
+ */
242
+static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom)
243
+{
244
+ struct device *dev = qcom->dev;
245
+ int ret;
246
+
247
+ if (has_acpi_companion(dev))
248
+ return 0;
249
+
250
+ qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr");
251
+ if (IS_ERR(qcom->icc_path_ddr)) {
252
+ dev_err(dev, "failed to get usb-ddr path: %ld\n",
253
+ PTR_ERR(qcom->icc_path_ddr));
254
+ return PTR_ERR(qcom->icc_path_ddr);
255
+ }
256
+
257
+ qcom->icc_path_apps = of_icc_get(dev, "apps-usb");
258
+ if (IS_ERR(qcom->icc_path_apps)) {
259
+ dev_err(dev, "failed to get apps-usb path: %ld\n",
260
+ PTR_ERR(qcom->icc_path_apps));
261
+ ret = PTR_ERR(qcom->icc_path_apps);
262
+ goto put_path_ddr;
263
+ }
264
+
265
+ if (usb_get_maximum_speed(&qcom->dwc3->dev) >= USB_SPEED_SUPER ||
266
+ usb_get_maximum_speed(&qcom->dwc3->dev) == USB_SPEED_UNKNOWN)
267
+ ret = icc_set_bw(qcom->icc_path_ddr,
268
+ USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW);
269
+ else
270
+ ret = icc_set_bw(qcom->icc_path_ddr,
271
+ USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW);
272
+
273
+ if (ret) {
274
+ dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret);
275
+ goto put_path_apps;
276
+ }
277
+
278
+ ret = icc_set_bw(qcom->icc_path_apps,
279
+ APPS_USB_AVG_BW, APPS_USB_PEAK_BW);
280
+ if (ret) {
281
+ dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret);
282
+ goto put_path_apps;
283
+ }
284
+
285
+ return 0;
286
+
287
+put_path_apps:
288
+ icc_put(qcom->icc_path_apps);
289
+put_path_ddr:
290
+ icc_put(qcom->icc_path_ddr);
291
+ return ret;
292
+}
293
+
294
+/**
295
+ * dwc3_qcom_interconnect_exit() - Release interconnect path handles
296
+ * @qcom: Pointer to the concerned usb core.
297
+ *
298
+ * This function is used to release interconnect path handle.
299
+ */
300
+static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom)
301
+{
302
+ icc_put(qcom->icc_path_ddr);
303
+ icc_put(qcom->icc_path_apps);
304
+}
305
+
306
+/* Only usable in contexts where the role can not change. */
307
+static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom)
308
+{
309
+ struct dwc3 *dwc;
310
+
311
+ /*
312
+ * FIXME: Fix this layering violation.
313
+ */
314
+ dwc = platform_get_drvdata(qcom->dwc3);
315
+
316
+ /* Core driver may not have probed yet. */
317
+ if (!dwc)
318
+ return false;
319
+
320
+ return dwc->xhci;
321
+}
322
+
176323 static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom)
177324 {
178325 if (qcom->hs_phy_irq) {
....@@ -219,10 +366,10 @@
219366 }
220367 }
221368
222
-static int dwc3_qcom_suspend(struct dwc3_qcom *qcom)
369
+static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
223370 {
224371 u32 val;
225
- int i;
372
+ int i, ret;
226373
227374 if (qcom->is_suspended)
228375 return 0;
....@@ -234,7 +381,11 @@
234381 for (i = qcom->num_clocks - 1; i >= 0; i--)
235382 clk_disable_unprepare(qcom->clks[i]);
236383
237
- if (device_may_wakeup(qcom->dev))
384
+ ret = dwc3_qcom_interconnect_disable(qcom);
385
+ if (ret)
386
+ dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
387
+
388
+ if (wakeup)
238389 dwc3_qcom_enable_interrupts(qcom);
239390
240391 qcom->is_suspended = true;
....@@ -242,7 +393,7 @@
242393 return 0;
243394 }
244395
245
-static int dwc3_qcom_resume(struct dwc3_qcom *qcom)
396
+static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)
246397 {
247398 int ret;
248399 int i;
....@@ -250,7 +401,7 @@
250401 if (!qcom->is_suspended)
251402 return 0;
252403
253
- if (device_may_wakeup(qcom->dev))
404
+ if (wakeup)
254405 dwc3_qcom_disable_interrupts(qcom);
255406
256407 for (i = 0; i < qcom->num_clocks; i++) {
....@@ -261,6 +412,10 @@
261412 return ret;
262413 }
263414 }
415
+
416
+ ret = dwc3_qcom_interconnect_enable(qcom);
417
+ if (ret)
418
+ dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
264419
265420 /* Clear existing events from PHY related to L2 in/out */
266421 dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG,
....@@ -280,7 +435,11 @@
280435 if (qcom->pm_suspended)
281436 return IRQ_HANDLED;
282437
283
- if (dwc->xhci)
438
+ /*
439
+ * This is safe as role switching is done from a freezable workqueue
440
+ * and the wakeup interrupts are disabled as part of resume.
441
+ */
442
+ if (dwc3_qcom_is_host(qcom))
284443 pm_runtime_resume(&dwc->xhci->dev);
285444
286445 return IRQ_HANDLED;
....@@ -303,12 +462,31 @@
303462 PIPE_UTMI_CLK_DIS);
304463 }
305464
465
+static int dwc3_qcom_get_irq(struct platform_device *pdev,
466
+ const char *name, int num)
467
+{
468
+ struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
469
+ struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : pdev;
470
+ struct device_node *np = pdev->dev.of_node;
471
+ int ret;
472
+
473
+ if (np)
474
+ ret = platform_get_irq_byname_optional(pdev_irq, name);
475
+ else
476
+ ret = platform_get_irq_optional(pdev_irq, num);
477
+
478
+ return ret;
479
+}
480
+
306481 static int dwc3_qcom_setup_irq(struct platform_device *pdev)
307482 {
308483 struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
309
- int irq, ret;
484
+ const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata;
485
+ int irq;
486
+ int ret;
310487
311
- irq = platform_get_irq_byname(pdev, "hs_phy_irq");
488
+ irq = dwc3_qcom_get_irq(pdev, "hs_phy_irq",
489
+ pdata ? pdata->hs_phy_irq_index : -1);
312490 if (irq > 0) {
313491 /* Keep wakeup interrupts disabled until suspend */
314492 irq_set_status_flags(irq, IRQ_NOAUTOEN);
....@@ -323,7 +501,8 @@
323501 qcom->hs_phy_irq = irq;
324502 }
325503
326
- irq = platform_get_irq_byname(pdev, "dp_hs_phy_irq");
504
+ irq = dwc3_qcom_get_irq(pdev, "dp_hs_phy_irq",
505
+ pdata ? pdata->dp_hs_phy_irq_index : -1);
327506 if (irq > 0) {
328507 irq_set_status_flags(irq, IRQ_NOAUTOEN);
329508 ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
....@@ -337,7 +516,8 @@
337516 qcom->dp_hs_phy_irq = irq;
338517 }
339518
340
- irq = platform_get_irq_byname(pdev, "dm_hs_phy_irq");
519
+ irq = dwc3_qcom_get_irq(pdev, "dm_hs_phy_irq",
520
+ pdata ? pdata->dm_hs_phy_irq_index : -1);
341521 if (irq > 0) {
342522 irq_set_status_flags(irq, IRQ_NOAUTOEN);
343523 ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
....@@ -351,7 +531,8 @@
351531 qcom->dm_hs_phy_irq = irq;
352532 }
353533
354
- irq = platform_get_irq_byname(pdev, "ss_phy_irq");
534
+ irq = dwc3_qcom_get_irq(pdev, "ss_phy_irq",
535
+ pdata ? pdata->ss_phy_irq_index : -1);
355536 if (irq > 0) {
356537 irq_set_status_flags(irq, IRQ_NOAUTOEN);
357538 ret = devm_request_threaded_irq(qcom->dev, irq, NULL,
....@@ -374,10 +555,13 @@
374555 struct device_node *np = dev->of_node;
375556 int i;
376557
377
- qcom->num_clocks = count;
378
-
379
- if (!count)
558
+ if (!np || !count)
380559 return 0;
560
+
561
+ if (count < 0)
562
+ return count;
563
+
564
+ qcom->num_clocks = count;
381565
382566 qcom->clks = devm_kcalloc(dev, qcom->num_clocks,
383567 sizeof(struct clk *), GFP_KERNEL);
....@@ -412,12 +596,142 @@
412596 return 0;
413597 }
414598
415
-static int dwc3_qcom_probe(struct platform_device *pdev)
599
+static const struct property_entry dwc3_qcom_acpi_properties[] = {
600
+ PROPERTY_ENTRY_STRING("dr_mode", "host"),
601
+ {}
602
+};
603
+
604
+static int dwc3_qcom_acpi_register_core(struct platform_device *pdev)
416605 {
606
+ struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
607
+ struct device *dev = &pdev->dev;
608
+ struct resource *res, *child_res = NULL;
609
+ struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb :
610
+ pdev;
611
+ int irq;
612
+ int ret;
613
+
614
+ qcom->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
615
+ if (!qcom->dwc3)
616
+ return -ENOMEM;
617
+
618
+ qcom->dwc3->dev.parent = dev;
619
+ qcom->dwc3->dev.type = dev->type;
620
+ qcom->dwc3->dev.dma_mask = dev->dma_mask;
621
+ qcom->dwc3->dev.dma_parms = dev->dma_parms;
622
+ qcom->dwc3->dev.coherent_dma_mask = dev->coherent_dma_mask;
623
+
624
+ child_res = kcalloc(2, sizeof(*child_res), GFP_KERNEL);
625
+ if (!child_res)
626
+ return -ENOMEM;
627
+
628
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
629
+ if (!res) {
630
+ dev_err(&pdev->dev, "failed to get memory resource\n");
631
+ ret = -ENODEV;
632
+ goto out;
633
+ }
634
+
635
+ child_res[0].flags = res->flags;
636
+ child_res[0].start = res->start;
637
+ child_res[0].end = child_res[0].start +
638
+ qcom->acpi_pdata->dwc3_core_base_size;
639
+
640
+ irq = platform_get_irq(pdev_irq, 0);
641
+ if (irq < 0) {
642
+ ret = irq;
643
+ goto out;
644
+ }
645
+ child_res[1].flags = IORESOURCE_IRQ;
646
+ child_res[1].start = child_res[1].end = irq;
647
+
648
+ ret = platform_device_add_resources(qcom->dwc3, child_res, 2);
649
+ if (ret) {
650
+ dev_err(&pdev->dev, "failed to add resources\n");
651
+ goto out;
652
+ }
653
+
654
+ ret = platform_device_add_properties(qcom->dwc3,
655
+ dwc3_qcom_acpi_properties);
656
+ if (ret < 0) {
657
+ dev_err(&pdev->dev, "failed to add properties\n");
658
+ goto out;
659
+ }
660
+
661
+ ret = platform_device_add(qcom->dwc3);
662
+ if (ret)
663
+ dev_err(&pdev->dev, "failed to add device\n");
664
+
665
+out:
666
+ kfree(child_res);
667
+ return ret;
668
+}
669
+
670
+static int dwc3_qcom_of_register_core(struct platform_device *pdev)
671
+{
672
+ struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
417673 struct device_node *np = pdev->dev.of_node, *dwc3_np;
418674 struct device *dev = &pdev->dev;
675
+ int ret;
676
+
677
+ dwc3_np = of_get_child_by_name(np, "dwc3");
678
+ if (!dwc3_np) {
679
+ dev_err(dev, "failed to find dwc3 core child\n");
680
+ return -ENODEV;
681
+ }
682
+
683
+ ret = of_platform_populate(np, NULL, NULL, dev);
684
+ if (ret) {
685
+ dev_err(dev, "failed to register dwc3 core - %d\n", ret);
686
+ goto node_put;
687
+ }
688
+
689
+ qcom->dwc3 = of_find_device_by_node(dwc3_np);
690
+ if (!qcom->dwc3) {
691
+ ret = -ENODEV;
692
+ dev_err(dev, "failed to get dwc3 platform device\n");
693
+ }
694
+
695
+node_put:
696
+ of_node_put(dwc3_np);
697
+
698
+ return ret;
699
+}
700
+
701
+static struct platform_device *
702
+dwc3_qcom_create_urs_usb_platdev(struct device *dev)
703
+{
704
+ struct fwnode_handle *fwh;
705
+ struct acpi_device *adev;
706
+ char name[8];
707
+ int ret;
708
+ int id;
709
+
710
+ /* Figure out device id */
711
+ ret = sscanf(fwnode_get_name(dev->fwnode), "URS%d", &id);
712
+ if (!ret)
713
+ return NULL;
714
+
715
+ /* Find the child using name */
716
+ snprintf(name, sizeof(name), "USB%d", id);
717
+ fwh = fwnode_get_named_child_node(dev->fwnode, name);
718
+ if (!fwh)
719
+ return NULL;
720
+
721
+ adev = to_acpi_device_node(fwh);
722
+ if (!adev)
723
+ return NULL;
724
+
725
+ return acpi_create_platform_device(adev, NULL);
726
+}
727
+
728
+static int dwc3_qcom_probe(struct platform_device *pdev)
729
+{
730
+ struct device_node *np = pdev->dev.of_node;
731
+ struct device *dev = &pdev->dev;
419732 struct dwc3_qcom *qcom;
420
- struct resource *res;
733
+ struct resource *res, *parent_res = NULL;
734
+ struct resource local_res;
421735 int ret, i;
422736 bool ignore_pipe_clk;
423737
....@@ -427,6 +741,14 @@
427741
428742 platform_set_drvdata(pdev, qcom);
429743 qcom->dev = &pdev->dev;
744
+
745
+ if (has_acpi_companion(dev)) {
746
+ qcom->acpi_pdata = acpi_device_get_match_data(dev);
747
+ if (!qcom->acpi_pdata) {
748
+ dev_err(&pdev->dev, "no supporting ACPI device data\n");
749
+ return -EINVAL;
750
+ }
751
+ }
430752
431753 qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
432754 if (IS_ERR(qcom->resets)) {
....@@ -449,15 +771,39 @@
449771 goto reset_assert;
450772 }
451773
452
- ret = dwc3_qcom_clk_init(qcom, of_count_phandle_with_args(np,
453
- "clocks", "#clock-cells"));
774
+ ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np));
454775 if (ret) {
455776 dev_err(dev, "failed to get clocks\n");
456777 goto reset_assert;
457778 }
458779
459780 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
460
- qcom->qscratch_base = devm_ioremap_resource(dev, res);
781
+
782
+ if (np) {
783
+ parent_res = res;
784
+ } else {
785
+ memcpy(&local_res, res, sizeof(struct resource));
786
+ parent_res = &local_res;
787
+
788
+ parent_res->start = res->start +
789
+ qcom->acpi_pdata->qscratch_base_offset;
790
+ parent_res->end = parent_res->start +
791
+ qcom->acpi_pdata->qscratch_base_size;
792
+
793
+ if (qcom->acpi_pdata->is_urs) {
794
+ qcom->urs_usb = dwc3_qcom_create_urs_usb_platdev(dev);
795
+ if (IS_ERR_OR_NULL(qcom->urs_usb)) {
796
+ dev_err(dev, "failed to create URS USB platdev\n");
797
+ if (!qcom->urs_usb)
798
+ ret = -ENODEV;
799
+ else
800
+ ret = PTR_ERR(qcom->urs_usb);
801
+ goto clk_disable;
802
+ }
803
+ }
804
+ }
805
+
806
+ qcom->qscratch_base = devm_ioremap_resource(dev, parent_res);
461807 if (IS_ERR(qcom->qscratch_base)) {
462808 dev_err(dev, "failed to map qscratch, err=%d\n", ret);
463809 ret = PTR_ERR(qcom->qscratch_base);
....@@ -465,13 +811,8 @@
465811 }
466812
467813 ret = dwc3_qcom_setup_irq(pdev);
468
- if (ret)
469
- goto clk_disable;
470
-
471
- dwc3_np = of_get_child_by_name(np, "dwc3");
472
- if (!dwc3_np) {
473
- dev_err(dev, "failed to find dwc3 core child\n");
474
- ret = -ENODEV;
814
+ if (ret) {
815
+ dev_err(dev, "failed to setup IRQs, err=%d\n", ret);
475816 goto clk_disable;
476817 }
477818
....@@ -484,29 +825,30 @@
484825 if (ignore_pipe_clk)
485826 dwc3_qcom_select_utmi_clk(qcom);
486827
487
- ret = of_platform_populate(np, NULL, NULL, dev);
488
- if (ret) {
489
- dev_err(dev, "failed to register dwc3 core - %d\n", ret);
490
- goto clk_disable;
491
- }
828
+ if (np)
829
+ ret = dwc3_qcom_of_register_core(pdev);
830
+ else
831
+ ret = dwc3_qcom_acpi_register_core(pdev);
492832
493
- qcom->dwc3 = of_find_device_by_node(dwc3_np);
494
- if (!qcom->dwc3) {
495
- dev_err(&pdev->dev, "failed to get dwc3 platform device\n");
496
- ret = -ENODEV;
833
+ if (ret) {
834
+ dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret);
497835 goto depopulate;
498836 }
837
+
838
+ ret = dwc3_qcom_interconnect_init(qcom);
839
+ if (ret)
840
+ goto depopulate;
499841
500842 qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev);
501843
502844 /* enable vbus override for device mode */
503
- if (qcom->mode == USB_DR_MODE_PERIPHERAL)
504
- dwc3_qcom_vbus_overrride_enable(qcom, true);
845
+ if (qcom->mode != USB_DR_MODE_HOST)
846
+ dwc3_qcom_vbus_override_enable(qcom, true);
505847
506848 /* register extcon to override sw_vbus on Vbus change later */
507849 ret = dwc3_qcom_register_extcon(qcom);
508850 if (ret)
509
- goto depopulate;
851
+ goto interconnect_exit;
510852
511853 device_init_wakeup(&pdev->dev, 1);
512854 qcom->is_suspended = false;
....@@ -516,8 +858,13 @@
516858
517859 return 0;
518860
861
+interconnect_exit:
862
+ dwc3_qcom_interconnect_exit(qcom);
519863 depopulate:
520
- of_platform_depopulate(&pdev->dev);
864
+ if (np)
865
+ of_platform_depopulate(&pdev->dev);
866
+ else
867
+ platform_device_put(pdev);
521868 clk_disable:
522869 for (i = qcom->num_clocks - 1; i >= 0; i--) {
523870 clk_disable_unprepare(qcom->clks[i]);
....@@ -532,10 +879,14 @@
532879 static int dwc3_qcom_remove(struct platform_device *pdev)
533880 {
534881 struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
882
+ struct device_node *np = pdev->dev.of_node;
535883 struct device *dev = &pdev->dev;
536884 int i;
537885
538
- of_platform_depopulate(dev);
886
+ if (np)
887
+ of_platform_depopulate(&pdev->dev);
888
+ else
889
+ platform_device_put(pdev);
539890
540891 for (i = qcom->num_clocks - 1; i >= 0; i--) {
541892 clk_disable_unprepare(qcom->clks[i]);
....@@ -543,6 +894,7 @@
543894 }
544895 qcom->num_clocks = 0;
545896
897
+ dwc3_qcom_interconnect_exit(qcom);
546898 reset_control_assert(qcom->resets);
547899
548900 pm_runtime_allow(dev);
....@@ -554,9 +906,11 @@
554906 static int __maybe_unused dwc3_qcom_pm_suspend(struct device *dev)
555907 {
556908 struct dwc3_qcom *qcom = dev_get_drvdata(dev);
909
+ bool wakeup = device_may_wakeup(dev);
557910 int ret = 0;
558911
559
- ret = dwc3_qcom_suspend(qcom);
912
+
913
+ ret = dwc3_qcom_suspend(qcom, wakeup);
560914 if (!ret)
561915 qcom->pm_suspended = true;
562916
....@@ -566,9 +920,10 @@
566920 static int __maybe_unused dwc3_qcom_pm_resume(struct device *dev)
567921 {
568922 struct dwc3_qcom *qcom = dev_get_drvdata(dev);
923
+ bool wakeup = device_may_wakeup(dev);
569924 int ret;
570925
571
- ret = dwc3_qcom_resume(qcom);
926
+ ret = dwc3_qcom_resume(qcom, wakeup);
572927 if (!ret)
573928 qcom->pm_suspended = false;
574929
....@@ -579,14 +934,14 @@
579934 {
580935 struct dwc3_qcom *qcom = dev_get_drvdata(dev);
581936
582
- return dwc3_qcom_suspend(qcom);
937
+ return dwc3_qcom_suspend(qcom, true);
583938 }
584939
585940 static int __maybe_unused dwc3_qcom_runtime_resume(struct device *dev)
586941 {
587942 struct dwc3_qcom *qcom = dev_get_drvdata(dev);
588943
589
- return dwc3_qcom_resume(qcom);
944
+ return dwc3_qcom_resume(qcom, true);
590945 }
591946
592947 static const struct dev_pm_ops dwc3_qcom_dev_pm_ops = {
....@@ -598,10 +953,43 @@
598953 static const struct of_device_id dwc3_qcom_of_match[] = {
599954 { .compatible = "qcom,dwc3" },
600955 { .compatible = "qcom,msm8996-dwc3" },
956
+ { .compatible = "qcom,msm8998-dwc3" },
601957 { .compatible = "qcom,sdm845-dwc3" },
602958 { }
603959 };
604960 MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match);
961
+
962
+#ifdef CONFIG_ACPI
963
+static const struct dwc3_acpi_pdata sdm845_acpi_pdata = {
964
+ .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET,
965
+ .qscratch_base_size = SDM845_QSCRATCH_SIZE,
966
+ .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE,
967
+ .hs_phy_irq_index = 1,
968
+ .dp_hs_phy_irq_index = 4,
969
+ .dm_hs_phy_irq_index = 3,
970
+ .ss_phy_irq_index = 2
971
+};
972
+
973
+static const struct dwc3_acpi_pdata sdm845_acpi_urs_pdata = {
974
+ .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET,
975
+ .qscratch_base_size = SDM845_QSCRATCH_SIZE,
976
+ .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE,
977
+ .hs_phy_irq_index = 1,
978
+ .dp_hs_phy_irq_index = 4,
979
+ .dm_hs_phy_irq_index = 3,
980
+ .ss_phy_irq_index = 2,
981
+ .is_urs = true,
982
+};
983
+
984
+static const struct acpi_device_id dwc3_qcom_acpi_match[] = {
985
+ { "QCOM2430", (unsigned long)&sdm845_acpi_pdata },
986
+ { "QCOM0304", (unsigned long)&sdm845_acpi_urs_pdata },
987
+ { "QCOM0497", (unsigned long)&sdm845_acpi_urs_pdata },
988
+ { "QCOM04A6", (unsigned long)&sdm845_acpi_pdata },
989
+ { },
990
+};
991
+MODULE_DEVICE_TABLE(acpi, dwc3_qcom_acpi_match);
992
+#endif
605993
606994 static struct platform_driver dwc3_qcom_driver = {
607995 .probe = dwc3_qcom_probe,
....@@ -610,6 +998,7 @@
610998 .name = "dwc3-qcom",
611999 .pm = &dwc3_qcom_dev_pm_ops,
6121000 .of_match_table = dwc3_qcom_of_match,
1001
+ .acpi_match_table = ACPI_PTR(dwc3_qcom_acpi_match),
6131002 },
6141003 };
6151004