Skip to content

Commit 7b8c9e6

Browse files
Peter Chengregkh
authored andcommitted
usb: chipidea: vbus event may exist before starting gadget
[ Upstream commit c3b674a04b8ab62a1d35e86714d466af0a0ecc18 ] 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 <peter.chen@nxp.com> Tested-by: Stephen Boyd <stephen.boyd@linaro.org> Reported-by: Stephen Boyd <stephen.boyd@linaro.org> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 093fe10 commit 7b8c9e6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

  • drivers/usb/chipidea

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)