@@ -37,10 +37,6 @@ static const struct bus_type gadget_bus_type;
37
37
* @vbus: for udcs who care about vbus status, this value is real vbus status;
38
38
* for udcs who do not care about vbus status, this value is always true
39
39
* @started: the UDC's started state. True if the UDC had started.
40
- * @connect_lock: protects udc->vbus, udc->started, gadget->connect, gadget->deactivate related
41
- * functions. usb_gadget_connect_locked, usb_gadget_disconnect_locked,
42
- * usb_udc_connect_control_locked, usb_gadget_udc_start_locked, usb_gadget_udc_stop_locked are
43
- * called with this lock held.
44
40
*
45
41
* This represents the internal data structure which is used by the UDC-class
46
42
* to hold information about udc driver and gadget together.
@@ -52,7 +48,6 @@ struct usb_udc {
52
48
struct list_head list ;
53
49
bool vbus ;
54
50
bool started ;
55
- struct mutex connect_lock ;
56
51
};
57
52
58
53
static struct class * udc_class ;
@@ -692,9 +687,17 @@ int usb_gadget_vbus_disconnect(struct usb_gadget *gadget)
692
687
}
693
688
EXPORT_SYMBOL_GPL (usb_gadget_vbus_disconnect );
694
689
695
- /* Internal version of usb_gadget_connect needs to be called with connect_lock held. */
696
- static int usb_gadget_connect_locked (struct usb_gadget * gadget )
697
- __must_hold (& gadget - > udc - > connect_lock )
690
+ /**
691
+ * usb_gadget_connect - software-controlled connect to USB host
692
+ * @gadget:the peripheral being connected
693
+ *
694
+ * Enables the D+ (or potentially D-) pullup. The host will start
695
+ * enumerating this gadget when the pullup is active and a VBUS session
696
+ * is active (the link is powered).
697
+ *
698
+ * Returns zero on success, else negative errno.
699
+ */
700
+ int usb_gadget_connect (struct usb_gadget * gadget )
698
701
{
699
702
int ret = 0 ;
700
703
@@ -703,12 +706,10 @@ static int usb_gadget_connect_locked(struct usb_gadget *gadget)
703
706
goto out ;
704
707
}
705
708
706
- if (gadget -> deactivated || ! gadget -> udc -> started ) {
709
+ if (gadget -> deactivated ) {
707
710
/*
708
711
* If gadget is deactivated we only save new state.
709
712
* Gadget will be connected automatically after activation.
710
- *
711
- * udc first needs to be started before gadget can be pulled up.
712
713
*/
713
714
gadget -> connected = true;
714
715
goto out ;
@@ -723,32 +724,22 @@ static int usb_gadget_connect_locked(struct usb_gadget *gadget)
723
724
724
725
return ret ;
725
726
}
727
+ EXPORT_SYMBOL_GPL (usb_gadget_connect );
726
728
727
729
/**
728
- * usb_gadget_connect - software-controlled connect to USB host
729
- * @gadget:the peripheral being connected
730
+ * usb_gadget_disconnect - software-controlled disconnect from USB host
731
+ * @gadget:the peripheral being disconnected
730
732
*
731
- * Enables the D+ (or potentially D-) pullup. The host will start
732
- * enumerating this gadget when the pullup is active and a VBUS session
733
- * is active (the link is powered).
733
+ * Disables the D+ (or potentially D-) pullup, which the host may see
734
+ * as a disconnect (when a VBUS session is active). Not all systems
735
+ * support software pullup controls.
736
+ *
737
+ * Following a successful disconnect, invoke the ->disconnect() callback
738
+ * for the current gadget driver so that UDC drivers don't need to.
734
739
*
735
740
* Returns zero on success, else negative errno.
736
741
*/
737
- int usb_gadget_connect (struct usb_gadget * gadget )
738
- {
739
- int ret ;
740
-
741
- mutex_lock (& gadget -> udc -> connect_lock );
742
- ret = usb_gadget_connect_locked (gadget );
743
- mutex_unlock (& gadget -> udc -> connect_lock );
744
-
745
- return ret ;
746
- }
747
- EXPORT_SYMBOL_GPL (usb_gadget_connect );
748
-
749
- /* Internal version of usb_gadget_disconnect needs to be called with connect_lock held. */
750
- static int usb_gadget_disconnect_locked (struct usb_gadget * gadget )
751
- __must_hold (& gadget - > udc - > connect_lock )
742
+ int usb_gadget_disconnect (struct usb_gadget * gadget )
752
743
{
753
744
int ret = 0 ;
754
745
@@ -760,12 +751,10 @@ static int usb_gadget_disconnect_locked(struct usb_gadget *gadget)
760
751
if (!gadget -> connected )
761
752
goto out ;
762
753
763
- if (gadget -> deactivated || ! gadget -> udc -> started ) {
754
+ if (gadget -> deactivated ) {
764
755
/*
765
756
* If gadget is deactivated we only save new state.
766
757
* Gadget will stay disconnected after activation.
767
- *
768
- * udc should have been started before gadget being pulled down.
769
758
*/
770
759
gadget -> connected = false;
771
760
goto out ;
@@ -785,30 +774,6 @@ static int usb_gadget_disconnect_locked(struct usb_gadget *gadget)
785
774
786
775
return ret ;
787
776
}
788
-
789
- /**
790
- * usb_gadget_disconnect - software-controlled disconnect from USB host
791
- * @gadget:the peripheral being disconnected
792
- *
793
- * Disables the D+ (or potentially D-) pullup, which the host may see
794
- * as a disconnect (when a VBUS session is active). Not all systems
795
- * support software pullup controls.
796
- *
797
- * Following a successful disconnect, invoke the ->disconnect() callback
798
- * for the current gadget driver so that UDC drivers don't need to.
799
- *
800
- * Returns zero on success, else negative errno.
801
- */
802
- int usb_gadget_disconnect (struct usb_gadget * gadget )
803
- {
804
- int ret ;
805
-
806
- mutex_lock (& gadget -> udc -> connect_lock );
807
- ret = usb_gadget_disconnect_locked (gadget );
808
- mutex_unlock (& gadget -> udc -> connect_lock );
809
-
810
- return ret ;
811
- }
812
777
EXPORT_SYMBOL_GPL (usb_gadget_disconnect );
813
778
814
779
/**
@@ -829,11 +794,10 @@ int usb_gadget_deactivate(struct usb_gadget *gadget)
829
794
if (gadget -> deactivated )
830
795
goto out ;
831
796
832
- mutex_lock (& gadget -> udc -> connect_lock );
833
797
if (gadget -> connected ) {
834
- ret = usb_gadget_disconnect_locked (gadget );
798
+ ret = usb_gadget_disconnect (gadget );
835
799
if (ret )
836
- goto unlock ;
800
+ goto out ;
837
801
838
802
/*
839
803
* If gadget was being connected before deactivation, we want
@@ -843,8 +807,6 @@ int usb_gadget_deactivate(struct usb_gadget *gadget)
843
807
}
844
808
gadget -> deactivated = true;
845
809
846
- unlock :
847
- mutex_unlock (& gadget -> udc -> connect_lock );
848
810
out :
849
811
trace_usb_gadget_deactivate (gadget , ret );
850
812
@@ -868,16 +830,14 @@ int usb_gadget_activate(struct usb_gadget *gadget)
868
830
if (!gadget -> deactivated )
869
831
goto out ;
870
832
871
- mutex_lock (& gadget -> udc -> connect_lock );
872
833
gadget -> deactivated = false;
873
834
874
835
/*
875
836
* If gadget has been connected before deactivation, or became connected
876
837
* while it was being deactivated, we call usb_gadget_connect().
877
838
*/
878
839
if (gadget -> connected )
879
- ret = usb_gadget_connect_locked (gadget );
880
- mutex_unlock (& gadget -> udc -> connect_lock );
840
+ ret = usb_gadget_connect (gadget );
881
841
882
842
out :
883
843
trace_usb_gadget_activate (gadget , ret );
@@ -1118,13 +1078,12 @@ EXPORT_SYMBOL_GPL(usb_gadget_set_state);
1118
1078
1119
1079
/* ------------------------------------------------------------------------- */
1120
1080
1121
- /* Acquire connect_lock before calling this function. */
1122
- static void usb_udc_connect_control_locked (struct usb_udc * udc ) __must_hold (& udc - > connect_lock )
1081
+ static void usb_udc_connect_control (struct usb_udc * udc )
1123
1082
{
1124
- if (udc -> vbus && udc -> started )
1125
- usb_gadget_connect_locked (udc -> gadget );
1083
+ if (udc -> vbus )
1084
+ usb_gadget_connect (udc -> gadget );
1126
1085
else
1127
- usb_gadget_disconnect_locked (udc -> gadget );
1086
+ usb_gadget_disconnect (udc -> gadget );
1128
1087
}
1129
1088
1130
1089
/**
@@ -1140,12 +1099,10 @@ void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status)
1140
1099
{
1141
1100
struct usb_udc * udc = gadget -> udc ;
1142
1101
1143
- mutex_lock (& udc -> connect_lock );
1144
1102
if (udc ) {
1145
1103
udc -> vbus = status ;
1146
- usb_udc_connect_control_locked (udc );
1104
+ usb_udc_connect_control (udc );
1147
1105
}
1148
- mutex_unlock (& udc -> connect_lock );
1149
1106
}
1150
1107
EXPORT_SYMBOL_GPL (usb_udc_vbus_handler );
1151
1108
@@ -1167,7 +1124,7 @@ void usb_gadget_udc_reset(struct usb_gadget *gadget,
1167
1124
EXPORT_SYMBOL_GPL (usb_gadget_udc_reset );
1168
1125
1169
1126
/**
1170
- * usb_gadget_udc_start_locked - tells usb device controller to start up
1127
+ * usb_gadget_udc_start - tells usb device controller to start up
1171
1128
* @udc: The UDC to be started
1172
1129
*
1173
1130
* This call is issued by the UDC Class driver when it's about
@@ -1178,11 +1135,8 @@ EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
1178
1135
* necessary to have it powered on.
1179
1136
*
1180
1137
* Returns zero on success, else negative errno.
1181
- *
1182
- * Caller should acquire connect_lock before invoking this function.
1183
1138
*/
1184
- static inline int usb_gadget_udc_start_locked (struct usb_udc * udc )
1185
- __must_hold (& udc - > connect_lock )
1139
+ static inline int usb_gadget_udc_start (struct usb_udc * udc )
1186
1140
{
1187
1141
int ret ;
1188
1142
@@ -1199,7 +1153,7 @@ static inline int usb_gadget_udc_start_locked(struct usb_udc *udc)
1199
1153
}
1200
1154
1201
1155
/**
1202
- * usb_gadget_udc_stop_locked - tells usb device controller we don't need it anymore
1156
+ * usb_gadget_udc_stop - tells usb device controller we don't need it anymore
1203
1157
* @udc: The UDC to be stopped
1204
1158
*
1205
1159
* This call is issued by the UDC Class driver after calling
@@ -1208,11 +1162,8 @@ static inline int usb_gadget_udc_start_locked(struct usb_udc *udc)
1208
1162
* The details are implementation specific, but it can go as
1209
1163
* far as powering off UDC completely and disable its data
1210
1164
* line pullups.
1211
- *
1212
- * Caller should acquire connect lock before invoking this function.
1213
1165
*/
1214
- static inline void usb_gadget_udc_stop_locked (struct usb_udc * udc )
1215
- __must_hold (& udc - > connect_lock )
1166
+ static inline void usb_gadget_udc_stop (struct usb_udc * udc )
1216
1167
{
1217
1168
if (!udc -> started ) {
1218
1169
dev_err (& udc -> dev , "UDC had already stopped\n" );
@@ -1371,7 +1322,6 @@ int usb_add_gadget(struct usb_gadget *gadget)
1371
1322
1372
1323
udc -> gadget = gadget ;
1373
1324
gadget -> udc = udc ;
1374
- mutex_init (& udc -> connect_lock );
1375
1325
1376
1326
udc -> started = false;
1377
1327
@@ -1573,15 +1523,11 @@ static int gadget_bind_driver(struct device *dev)
1573
1523
if (ret )
1574
1524
goto err_bind ;
1575
1525
1576
- mutex_lock (& udc -> connect_lock );
1577
- ret = usb_gadget_udc_start_locked (udc );
1578
- if (ret ) {
1579
- mutex_unlock (& udc -> connect_lock );
1526
+ ret = usb_gadget_udc_start (udc );
1527
+ if (ret )
1580
1528
goto err_start ;
1581
- }
1582
1529
usb_gadget_enable_async_callbacks (udc );
1583
- usb_udc_connect_control_locked (udc );
1584
- mutex_unlock (& udc -> connect_lock );
1530
+ usb_udc_connect_control (udc );
1585
1531
1586
1532
kobject_uevent (& udc -> dev .kobj , KOBJ_CHANGE );
1587
1533
return 0 ;
@@ -1612,14 +1558,12 @@ static void gadget_unbind_driver(struct device *dev)
1612
1558
1613
1559
kobject_uevent (& udc -> dev .kobj , KOBJ_CHANGE );
1614
1560
1615
- mutex_lock (& udc -> connect_lock );
1616
- usb_gadget_disconnect_locked (gadget );
1561
+ usb_gadget_disconnect (gadget );
1617
1562
usb_gadget_disable_async_callbacks (udc );
1618
1563
if (gadget -> irq )
1619
1564
synchronize_irq (gadget -> irq );
1620
1565
udc -> driver -> unbind (gadget );
1621
- usb_gadget_udc_stop_locked (udc );
1622
- mutex_unlock (& udc -> connect_lock );
1566
+ usb_gadget_udc_stop (udc );
1623
1567
1624
1568
mutex_lock (& udc_lock );
1625
1569
driver -> is_bound = false;
@@ -1705,15 +1649,11 @@ static ssize_t soft_connect_store(struct device *dev,
1705
1649
}
1706
1650
1707
1651
if (sysfs_streq (buf , "connect" )) {
1708
- mutex_lock (& udc -> connect_lock );
1709
- usb_gadget_udc_start_locked (udc );
1710
- usb_gadget_connect_locked (udc -> gadget );
1711
- mutex_unlock (& udc -> connect_lock );
1652
+ usb_gadget_udc_start (udc );
1653
+ usb_gadget_connect (udc -> gadget );
1712
1654
} else if (sysfs_streq (buf , "disconnect" )) {
1713
- mutex_lock (& udc -> connect_lock );
1714
- usb_gadget_disconnect_locked (udc -> gadget );
1715
- usb_gadget_udc_stop_locked (udc );
1716
- mutex_unlock (& udc -> connect_lock );
1655
+ usb_gadget_disconnect (udc -> gadget );
1656
+ usb_gadget_udc_stop (udc );
1717
1657
} else {
1718
1658
dev_err (dev , "unsupported command '%s'\n" , buf );
1719
1659
ret = - EINVAL ;
0 commit comments