From patchwork Sat Dec 17 05:31:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 88355 Delivered-To: patches@linaro.org Received: by 10.140.20.101 with SMTP id 92csp180132qgi; Fri, 16 Dec 2016 21:32:00 -0800 (PST) X-Received: by 10.99.204.81 with SMTP id q17mr12119564pgi.168.1481952720727; Fri, 16 Dec 2016 21:32:00 -0800 (PST) Return-Path: Received: from mail-pg0-x233.google.com (mail-pg0-x233.google.com. [2607:f8b0:400e:c05::233]) by mx.google.com with ESMTPS id s11si10966053pgc.259.2016.12.16.21.32.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 21:32:00 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::233 as permitted sender) client-ip=2607:f8b0:400e:c05::233; 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::233 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x233.google.com with SMTP id f188so39549268pgc.3 for ; Fri, 16 Dec 2016 21:32:00 -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=dxDby3SmS4F54uAvxC68i0zKMTnDjsj0Gn2Haezi4lA=; b=CB9VYiAmeAbrQYIaClYZpxv9bKLusfKfqIMb0Z7g/tBGkns22IXUlINpL0JJhtUn/l wTAcL8yZi35oesC2agi8WaZrRcH+phibPmIGze0KJUQAYecu+QWAhNbe72PL7HDZjmMV owKZ716X353wa3OMYjYSD2dJXpJqj3hB/ozsM= 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=dxDby3SmS4F54uAvxC68i0zKMTnDjsj0Gn2Haezi4lA=; b=R0rFG0JvLhh2izmbJ5X6wkxOq4ob7+JghZdPxsDA+/zg9uOWkPS8cr9NHs3C7mKfil d1tyMkY/Zk4QTmGnntkXRzvL7tDIEk1K+ZDY/eQaw7TfT4HR5E3kiLPg9hDlYsTz/foc LBfkpnliJYEm2ZxYyOC0HL9IZeXqG1czGW2Wq8h4GXWfCQX4hK07V0CvfPoiLFhSwuNW hxxf7uGQ7ja+lUJjeI4+zYiE5JHNEj3OEKm6hHSyXHHTdkB9FFho5xGr7f8RXW+t/QcZ IIwDWGxJFmZQ8WBPdI0DBkpxe/mT05iKyzQ+2HrC3gSPcyIqacgDVgDxh2bf+B2/qhta PL8g== X-Gm-Message-State: AKaTC02ltQk00YBFa0ZEFL3VwEOQwYHvuE35l8PTgkbtUGF4/jvibkUAltt4VTKbMszlaRxEpjI= X-Received: by 10.84.173.195 with SMTP id p61mr14455626plb.158.1481952720448; Fri, 16 Dec 2016 21:32:00 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id 72sm15475350pfw.37.2016.12.16.21.31.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Dec 2016 21:31:59 -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: [RFC][PATCH 2/5 v2] usb: dwc2: Workaround case where GOTGCTL state is wrong Date: Fri, 16 Dec 2016 21:31:50 -0800 Message-Id: <1481952713-29829-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481952713-29829-1-git-send-email-john.stultz@linaro.org> References: <1481952713-29829-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)) {