hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/usb/host/ehci-platform.c
....@@ -43,6 +43,9 @@
4343 #define EHCI_MAX_CLKS 4
4444 #define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv)
4545
46
+#define BCM_USB_FIFO_THRESHOLD 0x00800040
47
+#define bcm_iproc_insnreg01 hostpc[0]
48
+
4649 struct ehci_platform_priv {
4750 struct clk *clks[EHCI_MAX_CLKS];
4851 struct reset_control *rsts;
....@@ -66,7 +69,14 @@
6669 ehci_writel(ehci, portsc, status_reg);
6770 }
6871
69
-static void ehci_rockchip_usic_init(struct usb_hcd *hcd)
72
+#define USIC_MICROFRAME_OFFSET 0x90
73
+#define USIC_SCALE_DOWN_OFFSET 0xa0
74
+#define USIC_ENABLE_OFFSET 0xb0
75
+#define USIC_ENABLE BIT(0)
76
+#define USIC_SCALE_DOWN BIT(2)
77
+#define USIC_MICROFRAME_COUNT 0x1d4d
78
+
79
+static void ehci_usic_init(struct usb_hcd *hcd)
7080 {
7181 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
7282
....@@ -100,6 +110,11 @@
100110
101111 if (pdata->no_io_watchdog)
102112 ehci->need_io_watchdog = 0;
113
+
114
+ if (of_device_is_compatible(pdev->dev.of_node, "brcm,xgs-iproc-ehci"))
115
+ ehci_writel(ehci, BCM_USB_FIFO_THRESHOLD,
116
+ &ehci->regs->bcm_iproc_insnreg01);
117
+
103118 return 0;
104119 }
105120
....@@ -261,6 +276,8 @@
261276 struct ehci_platform_priv *priv;
262277 struct ehci_hcd *ehci;
263278 int err, irq, clk = 0;
279
+ struct device *companion_dev;
280
+ struct device_link *link;
264281
265282 if (usb_disabled())
266283 return -ENODEV;
....@@ -280,10 +297,8 @@
280297 }
281298
282299 irq = platform_get_irq(dev, 0);
283
- if (irq < 0) {
284
- dev_err(&dev->dev, "no irq provided");
300
+ if (irq < 0)
285301 return irq;
286
- }
287302
288303 hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
289304 dev_name(&dev->dev));
....@@ -324,15 +339,9 @@
324339
325340 if (of_machine_is_compatible("rockchip,rk3288") &&
326341 of_property_read_bool(dev->dev.of_node,
327
- "rockchip-relinquish-port")) {
342
+ "rockchip-relinquish-port"))
328343 ehci_platform_hc_driver.relinquish_port =
329344 ehci_rockchip_relinquish_port;
330
- hcd->rk3288_relinquish_port_quirk = 1;
331
- }
332
-
333
- if (of_property_read_bool(dev->dev.of_node,
334
- "rockchip-has-usic"))
335
- ehci->has_usic = 1;
336345
337346 for (clk = 0; clk < EHCI_MAX_CLKS; clk++) {
338347 priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
....@@ -404,8 +413,24 @@
404413 if (err)
405414 goto err_power;
406415
407
- if (ehci->has_usic)
408
- ehci_rockchip_usic_init(hcd);
416
+ if (of_usb_get_phy_mode(dev->dev.of_node) == USBPHY_INTERFACE_MODE_HSIC)
417
+ ehci_usic_init(hcd);
418
+
419
+ if (of_device_is_compatible(dev->dev.of_node,
420
+ "rockchip,rk3588-ehci")) {
421
+ companion_dev = usb_of_get_companion_dev(hcd->self.controller);
422
+ if (companion_dev) {
423
+ link = device_link_add(companion_dev, hcd->self.controller,
424
+ DL_FLAG_STATELESS);
425
+ put_device(companion_dev);
426
+ if (!link) {
427
+ dev_err(&dev->dev, "Unable to link %s\n",
428
+ dev_name(companion_dev));
429
+ err = -EINVAL;
430
+ goto err_power;
431
+ }
432
+ }
433
+ }
409434
410435 device_wakeup_enable(hcd->self.controller);
411436 device_enable_async_suspend(hcd->self.controller);
....@@ -440,10 +465,20 @@
440465 struct usb_hcd *hcd = platform_get_drvdata(dev);
441466 struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
442467 struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
468
+ struct device *companion_dev;
443469 int clk;
444470
445471 if (priv->quirk_poll)
446472 quirk_poll_end(priv);
473
+
474
+ if (of_device_is_compatible(dev->dev.of_node,
475
+ "rockchip,rk3588-ehci")) {
476
+ companion_dev = usb_of_get_companion_dev(hcd->self.controller);
477
+ if (companion_dev) {
478
+ device_link_remove(companion_dev, hcd->self.controller);
479
+ put_device(companion_dev);
480
+ }
481
+ }
447482
448483 usb_remove_hcd(hcd);
449484
....@@ -466,8 +501,7 @@
466501 return 0;
467502 }
468503
469
-#ifdef CONFIG_PM_SLEEP
470
-static int ehci_platform_suspend(struct device *dev)
504
+static int __maybe_unused ehci_platform_suspend(struct device *dev)
471505 {
472506 struct usb_hcd *hcd = dev_get_drvdata(dev);
473507 struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
....@@ -489,7 +523,7 @@
489523 return ret;
490524 }
491525
492
-static int ehci_platform_resume(struct device *dev)
526
+static int __maybe_unused ehci_platform_resume(struct device *dev)
493527 {
494528 struct usb_hcd *hcd = dev_get_drvdata(dev);
495529 struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
....@@ -505,18 +539,22 @@
505539
506540 companion_dev = usb_of_get_companion_dev(hcd->self.controller);
507541 if (companion_dev) {
508
- device_pm_wait_for_dev(hcd->self.controller, companion_dev);
542
+ if (!device_is_dependent(hcd->self.controller, companion_dev))
543
+ device_pm_wait_for_dev(hcd->self.controller, companion_dev);
509544 put_device(companion_dev);
510545 }
511546
512547 ehci_resume(hcd, priv->reset_on_resume);
548
+
549
+ pm_runtime_disable(dev);
550
+ pm_runtime_set_active(dev);
551
+ pm_runtime_enable(dev);
513552
514553 if (priv->quirk_poll)
515554 quirk_poll_init(priv);
516555
517556 return 0;
518557 }
519
-#endif /* CONFIG_PM_SLEEP */
520558
521559 static const struct of_device_id vt8500_ehci_ids[] = {
522560 { .compatible = "via,vt8500-ehci", },
....@@ -527,11 +565,13 @@
527565 };
528566 MODULE_DEVICE_TABLE(of, vt8500_ehci_ids);
529567
568
+#ifdef CONFIG_ACPI
530569 static const struct acpi_device_id ehci_acpi_match[] = {
531570 { "PNP0D20", 0 }, /* EHCI controller without debug */
532571 { }
533572 };
534573 MODULE_DEVICE_TABLE(acpi, ehci_acpi_match);
574
+#endif
535575
536576 static const struct platform_device_id ehci_platform_table[] = {
537577 { "ehci-platform", 0 },
....@@ -549,7 +589,7 @@
549589 .shutdown = usb_hcd_platform_shutdown,
550590 .driver = {
551591 .name = "ehci-platform",
552
- .pm = &ehci_platform_pm_ops,
592
+ .pm = pm_ptr(&ehci_platform_pm_ops),
553593 .of_match_table = vt8500_ehci_ids,
554594 .acpi_match_table = ACPI_PTR(ehci_acpi_match),
555595 }