From patchwork Tue Dec 13 07:09:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 87795 Delivered-To: patches@linaro.org Received: by 10.140.20.101 with SMTP id 92csp2060678qgi; Mon, 12 Dec 2016 23:09:56 -0800 (PST) X-Received: by 10.84.129.111 with SMTP id 102mr196528532plb.103.1481612996101; Mon, 12 Dec 2016 23:09:56 -0800 (PST) Return-Path: Received: from mail-pf0-x22b.google.com (mail-pf0-x22b.google.com. [2607:f8b0:400e:c00::22b]) by mx.google.com with ESMTPS id o61si35676645pld.191.2016.12.12.23.09.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2016 23:09:56 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22b as permitted sender) client-ip=2607:f8b0:400e:c00::22b; 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:c00::22b as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x22b.google.com with SMTP id i88so17166282pfk.2 for ; Mon, 12 Dec 2016 23:09:55 -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=GRifGecagHauDERdNL/2nc7fNUa4Rlun8MxpJfrOJ1c=; b=VBTa79riNdHTu2N8ZkAaBLP7ZVxchBu2v9k4end7QU2mBSRN1PrnM4kqwfqlIaVWsQ +jktj1ZhiwuBlW3yjYs54/RYRy8x0renVAV/QefiIGrTmuYxNM2ttqubaZfbkF6VCCWl Qy8Qn6j//aJEI/WERqqNYlxfnmtcfgpdCpatg= 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:in-reply-to :references; bh=GRifGecagHauDERdNL/2nc7fNUa4Rlun8MxpJfrOJ1c=; b=QcI0VjcHVH+ek9R2gOy7soPeD1675qtLDibgu5p0w4Ld0eVoSxJEWQIk5vxA31QPTS Ijx28TyYoqwkT1Os/RYhhZxw2wHMb38KSeyW8nBAqZr4VHewWfiZrV3pezqccg/Gf4sN ILERmXcuijpyDMoiEDwOyz2ZiYoP2wn7XA0R2KxAEV9Ara4H2Dx/7vMp7kdABW/xqqB0 u4ofVm4ZYJJyMu9SzYHBkW0xBN3LKhE4TspGQNwlyg0KDJoVm59jS9wSdu6SiYRo/1Qi DcYwXcTipf7K6BYb92ytyRB3LZwff5w06P2+VUfkMtjW3nRtyF/seCg9QoMZ+xeZnpGZ iM/w== X-Gm-Message-State: AKaTC01FxHYAyN01IEW2vlje5jyi/hH0/YRLIJsiAG0TSIf5Ak988x6t8J7hACMwdVBMUJGZwL8= X-Received: by 10.84.137.1 with SMTP id 1mr190685020plm.8.1481612995793; Mon, 12 Dec 2016 23:09:55 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id 13sm79190204pfz.30.2016.12.12.23.09.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Dec 2016 23:09:55 -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 2/5] usb: dwc2: Workaround case where GOTGCTL state is wrong Date: Mon, 12 Dec 2016 23:09:47 -0800 Message-Id: <1481612990-23409-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481612990-23409-1-git-send-email-john.stultz@linaro.org> References: <1481612990-23409-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: 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(-) -- 2.7.4 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; }