hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/usb/musb/musb_core.c
....@@ -73,6 +73,7 @@
7373 #include <linux/prefetch.h>
7474 #include <linux/platform_device.h>
7575 #include <linux/io.h>
76
+#include <linux/iopoll.h>
7677 #include <linux/dma-mapping.h>
7778 #include <linux/usb.h>
7879 #include <linux/usb/of.h>
....@@ -452,6 +453,108 @@
452453 return hw_ep->musb->io.write_fifo(hw_ep, len, src);
453454 }
454455
456
+static u8 musb_read_devctl(struct musb *musb)
457
+{
458
+ return musb_readb(musb->mregs, MUSB_DEVCTL);
459
+}
460
+
461
+/**
462
+ * musb_set_host - set and initialize host mode
463
+ * @musb: musb controller driver data
464
+ *
465
+ * At least some musb revisions need to enable devctl session bit in
466
+ * peripheral mode to switch to host mode. Initializes things to host
467
+ * mode and sets A_IDLE. SoC glue needs to advance state further
468
+ * based on phy provided VBUS state.
469
+ *
470
+ * Note that the SoC glue code may need to wait for musb to settle
471
+ * on enable before calling this to avoid babble.
472
+ */
473
+int musb_set_host(struct musb *musb)
474
+{
475
+ int error = 0;
476
+ u8 devctl;
477
+
478
+ if (!musb)
479
+ return -EINVAL;
480
+
481
+ devctl = musb_read_devctl(musb);
482
+ if (!(devctl & MUSB_DEVCTL_BDEVICE)) {
483
+ dev_info(musb->controller,
484
+ "%s: already in host mode: %02x\n",
485
+ __func__, devctl);
486
+ goto init_data;
487
+ }
488
+
489
+ devctl |= MUSB_DEVCTL_SESSION;
490
+ musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
491
+
492
+ error = readx_poll_timeout(musb_read_devctl, musb, devctl,
493
+ !(devctl & MUSB_DEVCTL_BDEVICE), 5000,
494
+ 1000000);
495
+ if (error) {
496
+ dev_err(musb->controller, "%s: could not set host: %02x\n",
497
+ __func__, devctl);
498
+
499
+ return error;
500
+ }
501
+
502
+init_data:
503
+ musb->is_active = 1;
504
+ musb->xceiv->otg->state = OTG_STATE_A_IDLE;
505
+ MUSB_HST_MODE(musb);
506
+
507
+ return error;
508
+}
509
+EXPORT_SYMBOL_GPL(musb_set_host);
510
+
511
+/**
512
+ * musb_set_peripheral - set and initialize peripheral mode
513
+ * @musb: musb controller driver data
514
+ *
515
+ * Clears devctl session bit and initializes things for peripheral
516
+ * mode and sets B_IDLE. SoC glue needs to advance state further
517
+ * based on phy provided VBUS state.
518
+ */
519
+int musb_set_peripheral(struct musb *musb)
520
+{
521
+ int error = 0;
522
+ u8 devctl;
523
+
524
+ if (!musb)
525
+ return -EINVAL;
526
+
527
+ devctl = musb_read_devctl(musb);
528
+ if (devctl & MUSB_DEVCTL_BDEVICE) {
529
+ dev_info(musb->controller,
530
+ "%s: already in peripheral mode: %02x\n",
531
+ __func__, devctl);
532
+
533
+ goto init_data;
534
+ }
535
+
536
+ devctl &= ~MUSB_DEVCTL_SESSION;
537
+ musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
538
+
539
+ error = readx_poll_timeout(musb_read_devctl, musb, devctl,
540
+ devctl & MUSB_DEVCTL_BDEVICE, 5000,
541
+ 1000000);
542
+ if (error) {
543
+ dev_err(musb->controller, "%s: could not set peripheral: %02x\n",
544
+ __func__, devctl);
545
+
546
+ return error;
547
+ }
548
+
549
+init_data:
550
+ musb->is_active = 0;
551
+ musb->xceiv->otg->state = OTG_STATE_B_IDLE;
552
+ MUSB_DEV_MODE(musb);
553
+
554
+ return error;
555
+}
556
+EXPORT_SYMBOL_GPL(musb_set_peripheral);
557
+
455558 /*-------------------------------------------------------------------------*/
456559
457560 /* for high speed test mode; see USB 2.0 spec 7.1.20 */
....@@ -749,7 +852,7 @@
749852 case OTG_STATE_B_IDLE:
750853 if (!musb->is_active)
751854 break;
752
- /* fall through */
855
+ fallthrough;
753856 case OTG_STATE_B_PERIPHERAL:
754857 musb_g_suspend(musb);
755858 musb->is_active = musb->g.b_hnp_enable;
....@@ -869,9 +972,8 @@
869972 case OTG_STATE_A_PERIPHERAL:
870973 musb_hnp_stop(musb);
871974 musb_root_disconnect(musb);
872
- /* FALLTHROUGH */
975
+ fallthrough;
873976 case OTG_STATE_B_WAIT_ACON:
874
- /* FALLTHROUGH */
875977 case OTG_STATE_B_PERIPHERAL:
876978 case OTG_STATE_B_IDLE:
877979 musb_g_disconnect(musb);
....@@ -906,7 +1008,7 @@
9061008 switch (musb->xceiv->otg->state) {
9071009 case OTG_STATE_A_SUSPEND:
9081010 musb_g_reset(musb);
909
- /* FALLTHROUGH */
1011
+ fallthrough;
9101012 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
9111013 /* never use invalid T(a_wait_bcon) */
9121014 musb_dbg(musb, "HNP: in %s, %d msec timeout",
....@@ -927,7 +1029,7 @@
9271029 break;
9281030 case OTG_STATE_B_IDLE:
9291031 musb->xceiv->otg->state = OTG_STATE_B_PERIPHERAL;
930
- /* FALLTHROUGH */
1032
+ fallthrough;
9311033 case OTG_STATE_B_PERIPHERAL:
9321034 musb_g_reset(musb);
9331035 break;
....@@ -947,7 +1049,6 @@
9471049 * @param musb instance pointer
9481050 * @param int_usb register contents
9491051 * @param devctl
950
- * @param power
9511052 */
9521053
9531054 static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
....@@ -1369,7 +1470,7 @@
13691470 switch (fifo_mode) {
13701471 default:
13711472 fifo_mode = 0;
1372
- /* FALLTHROUGH */
1473
+ fallthrough;
13731474 case 0:
13741475 cfg = mode_0_cfg;
13751476 n = ARRAY_SIZE(mode_0_cfg);
....@@ -1534,10 +1635,11 @@
15341635 } else {
15351636 musb->is_multipoint = 0;
15361637 type = "";
1537
-#ifndef CONFIG_USB_OTG_BLACKLIST_HUB
1538
- pr_err("%s: kernel must blacklist external hubs\n",
1539
- musb_driver_name);
1540
-#endif
1638
+ if (IS_ENABLED(CONFIG_USB) &&
1639
+ !IS_ENABLED(CONFIG_USB_OTG_DISABLE_EXTERNAL_HUB)) {
1640
+ pr_err("%s: kernel must disable external hubs, please fix the configuration\n",
1641
+ musb_driver_name);
1642
+ }
15411643 }
15421644
15431645 /* log release info */
....@@ -1692,7 +1794,7 @@
16921794 EXPORT_SYMBOL_GPL(musb_interrupt);
16931795
16941796 #ifndef CONFIG_MUSB_PIO_ONLY
1695
-static bool use_dma = 1;
1797
+static bool use_dma = true;
16961798
16971799 /* "modprobe ... use_dma=0" etc */
16981800 module_param(use_dma, bool, 0644);
....@@ -1757,7 +1859,7 @@
17571859 {
17581860 struct musb *musb = dev_to_musb(dev);
17591861 unsigned long flags;
1760
- int ret = -EINVAL;
1862
+ int ret;
17611863
17621864 spin_lock_irqsave(&musb->lock, flags);
17631865 ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->otg->state));
....@@ -1865,16 +1967,13 @@
18651967 }
18661968 static DEVICE_ATTR_WO(srp);
18671969
1868
-static struct attribute *musb_attributes[] = {
1970
+static struct attribute *musb_attrs[] = {
18691971 &dev_attr_mode.attr,
18701972 &dev_attr_vbus.attr,
18711973 &dev_attr_srp.attr,
18721974 NULL
18731975 };
1874
-
1875
-static const struct attribute_group musb_attr_group = {
1876
- .attrs = musb_attributes,
1877
-};
1976
+ATTRIBUTE_GROUPS(musb);
18781977
18791978 #define MUSB_QUIRK_B_INVALID_VBUS_91 (MUSB_DEVCTL_BDEVICE | \
18801979 (2 << MUSB_DEVCTL_VBUS_SHIFT) | \
....@@ -1910,9 +2009,8 @@
19102009 schedule_delayed_work(&musb->irq_work,
19112010 msecs_to_jiffies(1000));
19122011 musb->quirk_retries--;
1913
- break;
19142012 }
1915
- /* fall through */
2013
+ break;
19162014 case MUSB_QUIRK_B_INVALID_VBUS_91:
19172015 if (musb->quirk_retries && !musb->flush_irq_work) {
19182016 musb_dbg(musb,
....@@ -1922,7 +2020,7 @@
19222020 musb->quirk_retries--;
19232021 return;
19242022 }
1925
- /* fall through */
2023
+ fallthrough;
19262024 case MUSB_QUIRK_A_DISCONNECT_19:
19272025 if (musb->quirk_retries && !musb->flush_irq_work) {
19282026 musb_dbg(musb,
....@@ -1971,7 +2069,7 @@
19712069 struct musb *musb = container_of(data, struct musb, irq_work.work);
19722070 int error;
19732071
1974
- error = pm_runtime_get_sync(musb->controller);
2072
+ error = pm_runtime_resume_and_get(musb->controller);
19752073 if (error < 0) {
19762074 dev_err(musb->controller, "Could not enable: %i\n", error);
19772075
....@@ -2085,10 +2183,6 @@
20852183 * probe(), where things may be partially set up, as well as rmmod
20862184 * cleanup after everything's been de-activated.
20872185 */
2088
-
2089
-#ifdef CONFIG_SYSFS
2090
- sysfs_remove_group(&musb->controller->kobj, &musb_attr_group);
2091
-#endif
20922186
20932187 if (musb->nIrq >= 0) {
20942188 if (musb->irq_wake)
....@@ -2463,21 +2557,11 @@
24632557
24642558 musb_init_debugfs(musb);
24652559
2466
- status = sysfs_create_group(&musb->controller->kobj, &musb_attr_group);
2467
- if (status)
2468
- goto fail5;
2469
-
24702560 musb->is_initialized = 1;
24712561 pm_runtime_mark_last_busy(musb->controller);
24722562 pm_runtime_put_autosuspend(musb->controller);
24732563
24742564 return 0;
2475
-
2476
-fail5:
2477
- musb_exit_debugfs(musb);
2478
-
2479
- musb_gadget_cleanup(musb);
2480
- musb_host_cleanup(musb);
24812565
24822566 fail3:
24832567 cancel_delayed_work_sync(&musb->irq_work);
....@@ -2521,14 +2605,12 @@
25212605 {
25222606 struct device *dev = &pdev->dev;
25232607 int irq = platform_get_irq_byname(pdev, "mc");
2524
- struct resource *iomem;
25252608 void __iomem *base;
25262609
25272610 if (irq <= 0)
25282611 return -ENODEV;
25292612
2530
- iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2531
- base = devm_ioremap_resource(dev, iomem);
2613
+ base = devm_platform_ioremap_resource(pdev, 0);
25322614 if (IS_ERR(base))
25332615 return PTR_ERR(base);
25342616
....@@ -2875,9 +2957,10 @@
28752957
28762958 static struct platform_driver musb_driver = {
28772959 .driver = {
2878
- .name = (char *)musb_driver_name,
2960
+ .name = musb_driver_name,
28792961 .bus = &platform_bus_type,
28802962 .pm = MUSB_DEV_PM_OPS,
2963
+ .dev_groups = musb_groups,
28812964 },
28822965 .probe = musb_probe,
28832966 .remove = musb_remove,