forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/usb/chipidea/otg.c
....@@ -23,6 +23,7 @@
2323
2424 /**
2525 * hw_read_otgsc returns otgsc register bits value.
26
+ * @ci: the controller
2627 * @mask: bitfield mask
2728 */
2829 u32 hw_read_otgsc(struct ci_hdrc *ci, u32 mask)
....@@ -35,7 +36,7 @@
3536 * detection overwrite OTGSC register value
3637 */
3738 cable = &ci->platdata->vbus_extcon;
38
- if (!IS_ERR(cable->edev)) {
39
+ if (!IS_ERR(cable->edev) || ci->role_switch) {
3940 if (cable->changed)
4041 val |= OTGSC_BSVIS;
4142 else
....@@ -53,7 +54,7 @@
5354 }
5455
5556 cable = &ci->platdata->id_extcon;
56
- if (!IS_ERR(cable->edev)) {
57
+ if (!IS_ERR(cable->edev) || ci->role_switch) {
5758 if (cable->changed)
5859 val |= OTGSC_IDIS;
5960 else
....@@ -75,6 +76,7 @@
7576
7677 /**
7778 * hw_write_otgsc updates target bits of OTGSC register.
79
+ * @ci: the controller
7880 * @mask: bitfield mask
7981 * @data: to be written
8082 */
....@@ -83,7 +85,7 @@
8385 struct ci_hdrc_cable *cable;
8486
8587 cable = &ci->platdata->vbus_extcon;
86
- if (!IS_ERR(cable->edev)) {
88
+ if (!IS_ERR(cable->edev) || ci->role_switch) {
8789 if (data & mask & OTGSC_BSVIS)
8890 cable->changed = false;
8991
....@@ -97,7 +99,7 @@
9799 }
98100
99101 cable = &ci->platdata->id_extcon;
100
- if (!IS_ERR(cable->edev)) {
102
+ if (!IS_ERR(cable->edev) || ci->role_switch) {
101103 if (data & mask & OTGSC_IDIS)
102104 cable->changed = false;
103105
....@@ -164,11 +166,20 @@
164166
165167 static void ci_handle_id_switch(struct ci_hdrc *ci)
166168 {
167
- enum ci_role role = ci_otg_role(ci);
169
+ enum ci_role role;
168170
171
+ mutex_lock(&ci->mutex);
172
+ role = ci_otg_role(ci);
169173 if (role != ci->role) {
170174 dev_dbg(ci->dev, "switching from %s to %s\n",
171175 ci_role(ci)->name, ci->roles[role]->name);
176
+
177
+ if (ci->vbus_active && ci->role == CI_ROLE_GADGET)
178
+ /*
179
+ * vbus disconnect event is lost due to role
180
+ * switch occurs during system suspend.
181
+ */
182
+ usb_gadget_vbus_disconnect(&ci->gadget);
172183
173184 ci_role_stop(ci);
174185
....@@ -188,6 +199,7 @@
188199 if (role == CI_ROLE_GADGET)
189200 ci_handle_vbus_change(ci);
190201 }
202
+ mutex_unlock(&ci->mutex);
191203 }
192204 /**
193205 * ci_otg_work - perform otg (vbus/id) event handle
....@@ -222,7 +234,7 @@
222234
223235 /**
224236 * ci_hdrc_otg_init - initialize otg struct
225
- * ci: the controller
237
+ * @ci: the controller
226238 */
227239 int ci_hdrc_otg_init(struct ci_hdrc *ci)
228240 {
....@@ -241,7 +253,7 @@
241253
242254 /**
243255 * ci_hdrc_otg_destroy - destroy otg struct
244
- * ci: the controller
256
+ * @ci: the controller
245257 */
246258 void ci_hdrc_otg_destroy(struct ci_hdrc *ci)
247259 {