From patchwork Fri Aug 4 03:15:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 109363 Delivered-To: patches@linaro.org Received: by 10.140.101.6 with SMTP id t6csp1605626qge; Thu, 3 Aug 2017 20:15:52 -0700 (PDT) X-Received: by 10.98.8.93 with SMTP id c90mr900754pfd.237.1501816552168; Thu, 03 Aug 2017 20:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501816552; cv=none; d=google.com; s=arc-20160816; b=bcfVGgXRBXkBkntTt3qAZFO/p5ZcUA/aHrqRoLihzJgqwkYLuiwVTEUorkDHv0NOrQ z+ew25GiBiG4/ie+GdJxK/Ukjxh8cVXIw/bZUMNrrsdy0FHUuAU3UEAfdz5PxApwWtv4 fJ/oAYox1mnJvtWrEg2cNlJQdZKhXnMBYDJjVLuprMFWBPHnrLt2AVcJFFmhZM3s71jJ anrtZoh87Sq0AA4oAHHaLf+MDZb7EKFaxz3p/92ukO/F6WnuRhHCRY0Rb7BkLm3gCVxF gGCM3UOj3Rtg1FpW8UaZAxp7/Z71vC6VQ3gJ4Utc5VH2yQaHYd65j2PQMo9xS857gpjK 02FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=q+51OvkhpFwdCYu8GFFbFPc86pPhtWjQcPllLTqO3cw=; b=X9+ES2YUVQctmN+sIhI+Aw68vGbmVneAwHch9u5gSvbSiFY3k48wBT/z0alXeRYODF v+XGlyEqMXBqwUkIgY53aKNA4lj1oHQmZcScvHauqOW0myC6eLGeRrklb1ae02LWLNir aaDCf/V9AgMXkR6AYFCt835HOGwBHhToVCOPuDCOjIkFNjuNGN29keKrzu1y+gkFU10Z LEkxGlNh7O+DhBrBzkR/RDnzCxvAblDkrjJWqi06Ew4yKmsmNlyFOnlEPRoA4MEMf2dm uDyVQOpxtxg2qjFMBRkuLekYZT7k2AZnQ2eRmKEhaiTPk2XDEoTk540WnDCDAi9kwhPC Kz+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=J/59rHO0; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22e as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-pg0-x22e.google.com (mail-pg0-x22e.google.com. [2607:f8b0:400e:c05::22e]) by mx.google.com with ESMTPS id v12si352414plk.748.2017.08.03.20.15.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Aug 2017 20:15:52 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22e as permitted sender) client-ip=2607:f8b0:400e:c05::22e; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=J/59rHO0; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22e as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x22e.google.com with SMTP id u5so2541714pgn.0 for ; Thu, 03 Aug 2017 20:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=q+51OvkhpFwdCYu8GFFbFPc86pPhtWjQcPllLTqO3cw=; b=J/59rHO0s86nga3W1Tyw1YjA0ZcJvll2zOuWarvG3wEXWp9Y/z+xsxj5BXHbIibzfY gU1AjqsQMOh6Q+mz52QjFg990s0tnXMtCvNihKVRfScY7uD+iHbU/OVrwW9xDJipUYsQ iZLWFxJ333HaTX49yqHCBrd8OMe1hnQ+2YnkI= 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; bh=q+51OvkhpFwdCYu8GFFbFPc86pPhtWjQcPllLTqO3cw=; b=Lr6+hxvzAFnwSTJEbfpLABOSGkR6Rg4wxN/7P2gtGX+v9Nrrnv+D2hlU/E8TzrjkPo eu5DOplXjq2l1CohswL9oNPqa4hZc96KCi5mqM/gI8Gu8p4HSoJf+W39c/N1hxXTZ2VC Dk7CKXX2qfmfDaubT0pQIFdkOGxsSFDRkx3cAc5o0rUlxUPIxRZgI/eRt0NeYXIusNgd h2lqiyov9VyLyf+KRldRiE3mKAy6Fsm7UWREdkz4BPlPvnAypC9AaIIFCv4+yb31/HQN OP2jaJ92DRYzGZBP3m9vvR+xGeHNEbLq64o/DvlRcBNzpOY1Fn1/tvhvzEZeQdN6R/IR m+yg== X-Gm-Message-State: AIVw111L2KWU5EPlpJ77EJ1WuqrJ+le/ED3fm8UfwQJfpz0/79drZ3o1 PTD6AE0HOrNUacy/klo= X-Received: by 10.99.36.5 with SMTP id k5mr842074pgk.328.1501816551788; Thu, 03 Aug 2017 20:15:51 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id x5sm450262pgq.18.2017.08.03.20.15.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Aug 2017 20:15:51 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Wei Xu , Guodong Xu , Amit Pundir , Rob Herring , John Youn , Minas Harutyunyan , Douglas Anderson , Chen Yu , Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Subject: [RFC][PATCH 1/2] usb: dwc2: Improve gadget state disconnection handling Date: Thu, 3 Aug 2017 20:15:46 -0700 Message-Id: <1501816547-23684-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In the earlier commit dad3f793f20f ("usb: dwc2: Make sure we disconnect the gadget state"), I was trying to fix up the fact that we somehow weren't disconnecting the gadget state, so that when the OTG port was plugged in the second time we would get warnings about the state tracking being wrong. The fix there was somewhat simple, as it just made sure to call dwc2_hsotg_disconnect() before we connected things up in OTG mode. But in looking at a different issue I was seeing with UDC state handling, I realized that it would be much better to call dwc2_hsotg_disconnect when we get the state change signal moving to host mode. Thus, this patch removes the earlier disconnect call I added and moves it (and the needed locking) to the host mode transition. Suggestions or feedback would be grealy appreciated! Cc: Wei Xu Cc: Guodong Xu Cc: Amit Pundir Cc: Rob Herring Cc: John Youn Cc: Minas Harutyunyan Cc: Douglas Anderson Cc: Chen Yu Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Signed-off-by: John Stultz --- drivers/usb/dwc2/hcd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 740c7e8..9fd84a9 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -3277,7 +3277,6 @@ static void dwc2_conn_id_status_change(struct work_struct *work) dwc2_core_init(hsotg, false); dwc2_enable_global_interrupts(hsotg); spin_lock_irqsave(&hsotg->lock, flags); - dwc2_hsotg_disconnect(hsotg); dwc2_hsotg_core_init_disconnected(hsotg, false); spin_unlock_irqrestore(&hsotg->lock, flags); dwc2_hsotg_core_connect(hsotg); @@ -3296,8 +3295,13 @@ static void dwc2_conn_id_status_change(struct work_struct *work) if (count > 250) dev_err(hsotg->dev, "Connection id status change timed out\n"); - hsotg->op_state = OTG_STATE_A_HOST; + spin_lock_irqsave(&hsotg->lock, flags); + dwc2_hsotg_disconnect(hsotg); + dwc2_hsotg_core_init_disconnected(hsotg, false); + spin_unlock_irqrestore(&hsotg->lock, flags); + + hsotg->op_state = OTG_STATE_A_HOST; /* Initialize the Core for Host mode */ dwc2_core_init(hsotg, false); dwc2_enable_global_interrupts(hsotg);