Skip to content

Commit c3b674a

Browse files
author
Peter Chen
committed
usb: chipidea: vbus event may exist before starting gadget
At some situations, the vbus may already be there before starting gadget. So we need to check vbus event after switching to gadget in order to handle missing vbus event. The typical use cases are plugging vbus cable before driver load or the vbus has already been there after stopping host but before starting gadget. Signed-off-by: Peter Chen <[email protected]> Tested-by: Stephen Boyd <[email protected]> Reported-by: Stephen Boyd <[email protected]>
1 parent 5cc4926 commit c3b674a

File tree

1 file changed

+12
-5
lines changed
  • drivers/usb/chipidea

1 file changed

+12
-5
lines changed

drivers/usb/chipidea/otg.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ void ci_handle_vbus_change(struct ci_hdrc *ci)
134134
if (!ci->is_otg)
135135
return;
136136

137-
if (hw_read_otgsc(ci, OTGSC_BSV))
137+
if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active)
138138
usb_gadget_vbus_connect(&ci->gadget);
139-
else
139+
else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)
140140
usb_gadget_vbus_disconnect(&ci->gadget);
141141
}
142142

@@ -175,14 +175,21 @@ static void ci_handle_id_switch(struct ci_hdrc *ci)
175175

176176
ci_role_stop(ci);
177177

178-
if (role == CI_ROLE_GADGET)
178+
if (role == CI_ROLE_GADGET &&
179+
IS_ERR(ci->platdata->vbus_extcon.edev))
179180
/*
180-
* wait vbus lower than OTGSC_BSV before connecting
181-
* to host
181+
* Wait vbus lower than OTGSC_BSV before connecting
182+
* to host. If connecting status is from an external
183+
* connector instead of register, we don't need to
184+
* care vbus on the board, since it will not affect
185+
* external connector status.
182186
*/
183187
hw_wait_vbus_lower_bsv(ci);
184188

185189
ci_role_start(ci, role);
190+
/* vbus change may have already occurred */
191+
if (role == CI_ROLE_GADGET)
192+
ci_handle_vbus_change(ci);
186193
}
187194
}
188195
/**

0 commit comments

Comments
 (0)