From patchwork Wed Dec 7 01:47:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 86944 Delivered-To: patches@linaro.org Received: by 10.140.20.101 with SMTP id 92csp90350qgi; Tue, 6 Dec 2016 17:48:03 -0800 (PST) X-Received: by 10.98.23.88 with SMTP id 85mr66022081pfx.21.1481075283334; Tue, 06 Dec 2016 17:48:03 -0800 (PST) Return-Path: Received: from mail-pg0-x234.google.com (mail-pg0-x234.google.com. [2607:f8b0:400e:c05::234]) by mx.google.com with ESMTPS id 123si21696263pgb.134.2016.12.06.17.48.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Dec 2016 17:48:03 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::234 as permitted sender) client-ip=2607:f8b0:400e:c05::234; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::234 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x234.google.com with SMTP id x23so155596998pgx.1 for ; Tue, 06 Dec 2016 17:48:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=VovJhtsPhvzC/NUhE4F21wCMwv5QPPPZcOsO2JF1mm4=; b=D3eQcWlab2CI+3QMieuIc5kLs8a0y5eARehxdbRgcl1WJmN1GV6rTFKsX5BmYJnMqf YSdfryd7Sd56NzE4eukDltx8NDLs3rj615cV9L/gKx2Kf+F3HnIXo+ZsoGWZGzFa80ID neKIH9ksGhrsxRyWrfr18z1lztOOxkvZsEKAw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VovJhtsPhvzC/NUhE4F21wCMwv5QPPPZcOsO2JF1mm4=; b=jlctznJaN8KZftnbZwvAwPhGN8oQEVNwB0T7fgsnkY3L98KCiNNL5FjRhRJPWR+e8K H9GFXaN8DENZAmcw45lHXp+KPPdYCihFRThALUx7JbeS8c2u5wTsrfuJGpl/eTkgJY1U wSB8ZDR/6Wjm9MsmW/hyH3Fa6igJrm38u2CFlr5BoeCte/uwFLunl/BuNco7UDRlEf29 mzO0uxiVfnWsELf9rCXzLZZftizGakr60zEeG7KPcqrGKJAtn1l5OC3++Z3vcnPec2A1 slDNa5X3atYsCNWB5XSQVKCxQLhXQCOOFbkWPaaQCH2Xl9Cewg8/URGqLYJ1uTbXLDKx Z5bg== X-Gm-Message-State: AKaTC00jipb9fcjyBKrtxWIrYZAd44JP3O+BTl4yhnIpJuObLviS6nLS1v8fLkNNIV3WPM1nmOM= X-Received: by 10.99.133.200 with SMTP id u191mr116381953pgd.28.1481075282886; Tue, 06 Dec 2016 17:48:02 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id o29sm37752315pgn.28.2016.12.06.17.48.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 17:48:02 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , 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 Subject: [RFC][PATCH] HACK: usb: dwc2: Workaround case where GOTGCTL state is wrong Date: Tue, 6 Dec 2016 17:47:58 -0800 Message-Id: <1481075278-17600-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 Hey John, Just wanted to send this by you, as it seems something is slightly off with the GOTGCTL state when removing a otg adapter cable. The following seems to work around the issue I'm seeing. Let me know if you have any thoughts on this. thanks -john 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 Signed-off-by: John Stultz --- drivers/usb/dwc2/hcd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.7.4 Acked-by: John Youn diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 143da47..6d6802a 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -3203,7 +3203,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 */ @@ -3219,6 +3219,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; }