Path: csiph.com!aioe.org!bofh.it!news.nic.it!robomod From: John Stultz Newsgroups: linux.kernel Subject: Re: [RFC][PATCH 2/5] usb: dwc2: Workaround case where GOTGCTL state is wrong Date: Tue, 13 Dec 2016 22:20:01 +0100 Message-ID: References: Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=49tJ3HIcJd6mF7cikmq10EVtABGpCSxJAWzwZUhFua0=; b=exf8pPYurifDhmfRmsgxqZQop5qoKzRJ1CWI1lWW647EK3maDMvtU4MqYqtQUj0YcJ TyOgSJFFL26SC7KdzQoXMoc75Pi5hZQ2iPqsC3WSSY7ECyvoI3Y99BSp6ukNnL/dI7Pj DwRc8wutrgUEsWoW6ZRw+V0yCT2Qz0YUo8Qjs= X-Google-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=49tJ3HIcJd6mF7cikmq10EVtABGpCSxJAWzwZUhFua0=; b=hx/UzzPoQ2M5XuRsqAyeCSGaddJuBCvs7ME7P6jY9RC1yRDwXoZMNfC58qmPbgeIJA QNbd9FWg6klkJOja1ss2LKl09ypXiOniSCZtb0wilYIsrmPkznjVRhB7TZYGlhkgbIzs XDgmgyc3KbGOGzR0VsDHLEAyS7G9kL6df+Y4j6gvbnbLJTrdu0M9DNUSySe8eGSC5NWq UXRcxo9QXMYb9oH7MiJjEe743LjCz45c4ERpggoNoc8+sknUXL8qGUQR4zMW9gRkPcEB JyKM4dpnH9f7AlJRWsO5Zsv9td49T6iM3gRN1FS/8h+XHAfFE6X8oIH69Of/i8/Fnwnk bGug== X-Gm-Message-State: AKaTC00aT9iB4kQ+EHH9B7boYaVaPaYZ6/0S+UYGPjo6eRaXnCwcZ+ZrpbGsl2PB6v9omysgoZu1lJn4pXYjgKQJ X-Received: by 10.157.42.199 with SMTP id e65mr54535267otb.269.1481661615627; Tue, 13 Dec 2016 12:40:15 -0800 (PST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 71 Organization: linux.* mail to news gateway X-Original-Cc: lkml , Wei Xu , Guodong Xu , Amit Pundir , Rob Herring , John Youn , Douglas Anderson , Chen Yu , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" X-Original-Date: Tue, 13 Dec 2016 12:40:15 -0800 X-Original-Message-ID: X-Original-References: <1481612990-23409-1-git-send-email-john.stultz@linaro.org> <1481612990-23409-3-git-send-email-john.stultz@linaro.org> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1541531 On Tue, Dec 13, 2016 at 4:28 AM, Vardan Mikayelyan wrote: > On 12/13/2016 11:12 AM, John Stultz wrote: >> When removing a USB-A to USB-otg adapter cable, we get a change >> status irq, and then in dwc2_conn_id_status_change, we >> erroniously see the GOTGCTL_CONID_B flag set. This causes us to >> get stuck in the "while (!dwc2_is_device_mode(hsotg))" loop, >> spitting out "Waiting for Peripheral Mode, Mode=Host" warnings >> until it fails out many seconds later. >> >> This patch works around the issue by re-reading the GOTGCTL >> state to check if the GOTGCTL_CONID_B is still set and if not >> restarting the change status logic. >> >> I suspect this isn't the best solution, but it seems to work >> well for me. >> >> Feedback would be greatly appreciated! >> >> Cc: Wei Xu >> Cc: Guodong Xu >> Cc: Amit Pundir >> Cc: Rob Herring >> Cc: John Youn >> Cc: Douglas Anderson >> Cc: Chen Yu >> Cc: Kishon Vijay Abraham I >> Cc: Felipe Balbi >> Cc: Greg Kroah-Hartman >> Cc: linux-usb@vger.kernel.org >> Acked-by: John Youn >> Signed-off-by: John Stultz >> --- >> drivers/usb/dwc2/hcd.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c >> index df5a065..a3f34dd 100644 >> --- a/drivers/usb/dwc2/hcd.c >> +++ b/drivers/usb/dwc2/hcd.c >> @@ -3199,7 +3199,7 @@ static void dwc2_conn_id_status_change(struct work_struct *work) >> dev_dbg(hsotg->dev, "gotgctl=%0x\n", gotgctl); >> dev_dbg(hsotg->dev, "gotgctl.b.conidsts=%d\n", >> !!(gotgctl & GOTGCTL_CONID_B)); >> - >> +again: >> /* B-Device connector (Device Mode) */ >> if (gotgctl & GOTGCTL_CONID_B) { >> /* Wait for switch to device mode */ >> @@ -3210,6 +3210,9 @@ static void dwc2_conn_id_status_change(struct work_struct *work) >> dwc2_is_host_mode(hsotg) ? "Host" : >> "Peripheral"); >> usleep_range(20000, 40000); >> + gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); >> + if (!(gotgctl & GOTGCTL_CONID_B)) >> + goto again; >> if (++count > 250) >> break; >> } >> > Hi John Stultz, > > When it goes to ":again", it will go to else anyways. I'll suggest > alternative way to do this. Please see below. Sounds good. I've made the change. > Also you can add "Reviewed-by: Vardan Mikayelyan " Thanks so much for your review! -john