diff mbox series

usb: chipidea: otg: handle vbus change for udc iff it's in device mode

Message ID 20221207031448.336080-1-xu.yang_2@nxp.com
State New
Headers show
Series usb: chipidea: otg: handle vbus change for udc iff it's in device mode | expand

Commit Message

Xu Yang Dec. 7, 2022, 3:14 a.m. UTC
When in device mode at first (BSVIE is set),  OTGSC will assert both
BSVIS and IDIS bit if changed to host mode. ID event will be handled
in the first interrupt. Depends on whether BSVIE is cleared when call
ci_role_stop() for udc, the 2rd interrupt may be asserted after a
specific interrupt period (BSVIE and BSVIS is still 1). If it is, the
driver will continue to handle VBUS change for udc. We should avoid
this manner since the controller is not in device mode and the worser
is gadget related code may be executed if a gadget driver is attached.

Fixes: a107f8c505cd ("usb: chipidea: add vbus interrupt handler")
cc: <stable@vger.kernel.org>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/chipidea/otg.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Xu Yang Dec. 8, 2022, 3:27 a.m. UTC | #1
Hi,

After double check for this issue, the logic seems wrong.
Please ignore this patch and sorry for inconvenience in advance.

Best Regard,
Xu Yang

> -----Original Message-----
> From: Xu Yang
> Sent: Wednesday, December 7, 2022 11:14 AM
> To: peter.chen@kernel.org
> Cc: gregkh@linuxfoundation.org; linux-usb@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>; Jun Li <jun.li@nxp.com>;
> Xu Yang <xu.yang_2@nxp.com>
> Subject: [PATCH] usb: chipidea: otg: handle vbus change for udc iff it's in device mode
> 
> When in device mode at first (BSVIE is set),  OTGSC will assert both
> BSVIS and IDIS bit if changed to host mode. ID event will be handled
> in the first interrupt. Depends on whether BSVIE is cleared when call
> ci_role_stop() for udc, the 2rd interrupt may be asserted after a
> specific interrupt period (BSVIE and BSVIS is still 1). If it is, the
> driver will continue to handle VBUS change for udc. We should avoid
> this manner since the controller is not in device mode and the worser
> is gadget related code may be executed if a gadget driver is attached.
> 
> Fixes: a107f8c505cd ("usb: chipidea: add vbus interrupt handler")
> cc: <stable@vger.kernel.org>
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  drivers/usb/chipidea/otg.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
> index f5490f2a5b6b..31c38a3ab990 100644
> --- a/drivers/usb/chipidea/otg.c
> +++ b/drivers/usb/chipidea/otg.c
> @@ -133,6 +133,9 @@ void ci_handle_vbus_change(struct ci_hdrc *ci)
>  	if (!ci->is_otg)
>  		return;
> 
> +	if (ci_otg_role(ci) != CI_ROLE_GADGET)
> +		return;
> +
>  	if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active)
>  		usb_gadget_vbus_connect(&ci->gadget);
>  	else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)
> --
> 2.34.1
diff mbox series

Patch

diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
index f5490f2a5b6b..31c38a3ab990 100644
--- a/drivers/usb/chipidea/otg.c
+++ b/drivers/usb/chipidea/otg.c
@@ -133,6 +133,9 @@  void ci_handle_vbus_change(struct ci_hdrc *ci)
 	if (!ci->is_otg)
 		return;
 
+	if (ci_otg_role(ci) != CI_ROLE_GADGET)
+		return;
+
 	if (hw_read_otgsc(ci, OTGSC_BSV) && !ci->vbus_active)
 		usb_gadget_vbus_connect(&ci->gadget);
 	else if (!hw_read_otgsc(ci, OTGSC_BSV) && ci->vbus_active)