From patchwork Tue Jan 3 19:52:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 89730 Delivered-To: patches@linaro.org Received: by 10.140.20.101 with SMTP id 92csp8169808qgi; Tue, 3 Jan 2017 11:52:44 -0800 (PST) X-Received: by 10.84.195.228 with SMTP id j91mr136388494pld.88.1483473164380; Tue, 03 Jan 2017 11:52:44 -0800 (PST) Return-Path: Received: from mail-pg0-x22a.google.com (mail-pg0-x22a.google.com. [2607:f8b0:400e:c05::22a]) by mx.google.com with ESMTPS id w33si37678192plb.261.2017.01.03.11.52.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jan 2017 11:52:44 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22a as permitted sender) client-ip=2607:f8b0:400e:c05::22a; 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::22a as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x22a.google.com with SMTP id g1so178867933pgn.0 for ; Tue, 03 Jan 2017 11:52:44 -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:in-reply-to:references; bh=bIrU0siLkPAJKs7KNFDapwhe2dRntfcehyHA/G3/rCI=; b=VjQhFpfTWjJQq6TL/f66RccaQcu4RFtnLjvstsGeBaZkCfuJyZe8NUpz9kIcfelT4s F5UT1XWb8pz5lG3Hx+podl9dVkzNLUqSQ8rYaleyM/4UBWHQr0aKKSYVobFTMflcDLm/ GdP/V9IuONS9H8CqagMYjzpkd2SmxNUI0+vx8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bIrU0siLkPAJKs7KNFDapwhe2dRntfcehyHA/G3/rCI=; b=lnvA2FSVfmMZyIax/dsVc0yt7KkEZ3nFucGRg+DCqpVNN2Y9TEP31pH5LcrT5YRL4F T4D3mxrXGceyhqBstznjzMvQUQ9YydF3d0jWVvgGgYh5oftuJ1a4YbI9SifSO+BLhRGe 4AGCsvwPrnm75FJGz1/99SoZmH9MZ9E+18eUqX7lhHNLo7+PKMAnf2mcevCTjc5jPSft khtyjbicLkEMXEI8VvT1eXjMrUDLDY7U45gDDfRttyi56hqteb0FzdR9aTKedr5hzbgq FXr7PLvQuPTgIsNkRBLDz+D6aMUm5rou6/hOzvGwg6sA94SyzlWFkYhavLYTVhTzqcpr EoyA== X-Gm-Message-State: AIkVDXJawrQxBGXJXs3AjkU8rAfA4SCbOW2wbzkWZuH/fSQBSzPhWdVYGTkgRfSW61STO6/IJhQ= X-Received: by 10.98.198.85 with SMTP id m82mr58907950pfg.69.1483473164052; Tue, 03 Jan 2017 11:52:44 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id r1sm93771794pgn.48.2017.01.03.11.52.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Jan 2017 11:52:43 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Wei Xu , Guodong Xu , Amit Pundir , Rob Herring , John Youn , Douglas Anderson , Chen Yu , Vardan Mikayelyan , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Subject: [PATCH 2/5 v2] usb: dwc2: Workaround case where GOTGCTL state is wrong Date: Tue, 3 Jan 2017 11:52:34 -0800 Message-Id: <1483473157-16678-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1483473157-16678-1-git-send-email-john.stultz@linaro.org> References: <1483473157-16678-1-git-send-email-john.stultz@linaro.org> 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: Vardan Mikayelyan Cc: Kishon Vijay Abraham I Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Acked-by: John Youn Reviewed-by: Vardan Mikayelyan Signed-off-by: John Stultz --- v2: Rework goto logic suggested by Vardan, and add a comment drivers/usb/dwc2/hcd.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.7.4 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 911c3b3..b60307a 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -3241,6 +3241,14 @@ static void dwc2_conn_id_status_change(struct work_struct *work) dwc2_is_host_mode(hsotg) ? "Host" : "Peripheral"); usleep_range(20000, 40000); + /* + * Sometimes the initial GOTGCTRL read is wrong, so + * check it again and jump to host mode if that was + * the case. + */ + gotgctl = dwc2_readl(hsotg->regs + GOTGCTL); + if (!(gotgctl & GOTGCTL_CONID_B)) + goto host; if (++count > 250) break; } @@ -3255,6 +3263,7 @@ static void dwc2_conn_id_status_change(struct work_struct *work) spin_unlock_irqrestore(&hsotg->lock, flags); dwc2_hsotg_core_connect(hsotg); } else { +host: /* A-Device connector (Host Mode) */ dev_dbg(hsotg->dev, "connId A\n"); while (!dwc2_is_host_mode(hsotg)) {