From patchwork Thu Oct 24 02:15:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11208153 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B02E913 for ; Thu, 24 Oct 2019 02:15:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 25D592086D for ; Thu, 24 Oct 2019 02:15:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Q/buGT4K" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436740AbfJXCPp (ORCPT ); Wed, 23 Oct 2019 22:15:45 -0400 Received: from us03-smtprelay2.synopsys.com ([149.117.87.133]:58622 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436605AbfJXCPp (ORCPT ); Wed, 23 Oct 2019 22:15:45 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id A9543C0239; Thu, 24 Oct 2019 02:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1571883344; bh=N6N+xiy43WEoIJ73vc6RQdArovxlIQFDlOKfTocuX8Q=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Q/buGT4KrEDGvcy2AsZMdJ4pqhIyTg+Vf+SbHJIe8n5RE/7+NGqN3Kd4yk7XUSt6B 40wJ/CT7snCvpdLAuVNCe5fP7/JhfEUvH5Hb9kKZhQd6U0gx40xWJjOIXoE0Ercpq7 AJvUpn0DP7K3piyAq5z7ufSecer6vqdTzGZiUioUp+5oJFqu5X1Bb2/EaA14r7LNW7 fPNzM52BZieCWvzfRA7XgGWGq5kX+1q1S/r9TZP1f3k6gCQg1+SQ7VAv+kcagJTrjH evl7DmQ2klm1It+mz2I+YrArK+vGRM8Fq8pvS3LMzh3EEfzlY4jYhk5zRMNr07W2ML 3s0hEWeRk/puA== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 744A3A005A; Thu, 24 Oct 2019 02:15:43 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 23 Oct 2019 19:15:43 -0700 Date: Wed, 23 Oct 2019 19:15:43 -0700 Message-Id: <3abc68f12aa32abf41b61a668f1e5b136d2acfc4.1571882179.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 1/4] usb: dwc3: gadget: Don't send unintended link state change To: Felipe Balbi , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org DCTL.ULSTCHNGREQ is a write-only field. When doing a read-modify-write to DCTL, the driver must make sure that there's no unintended link state change request from whatever is read from DCTL.ULSTCHNGREQ. Set link state change to no-action when the driver writes to DCTL. Signed-off-by: Thinh Nguyen --- Changes in v2: - Create inline function to do safe write to DCTL drivers/usb/dwc3/gadget.c | 16 +++++++--------- drivers/usb/dwc3/gadget.h | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 86dc1db788a9..85adc718808a 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -57,7 +57,7 @@ int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode) return -EINVAL; } - dwc3_writel(dwc->regs, DWC3_DCTL, reg); + dwc3_gadget_dctl_write_safe(dwc, reg); return 0; } @@ -1822,7 +1822,7 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend) dwc->pullups_connected = false; } - dwc3_writel(dwc->regs, DWC3_DCTL, reg); + dwc3_gadget_dctl_write_safe(dwc, reg); do { reg = dwc3_readl(dwc->regs, DWC3_DSTS); @@ -2745,10 +2745,8 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg &= ~DWC3_DCTL_INITU1ENA; - dwc3_writel(dwc->regs, DWC3_DCTL, reg); - reg &= ~DWC3_DCTL_INITU2ENA; - dwc3_writel(dwc->regs, DWC3_DCTL, reg); + dwc3_gadget_dctl_write_safe(dwc, reg); dwc3_disconnect_gadget(dwc); @@ -2800,7 +2798,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg &= ~DWC3_DCTL_TSTCTRL_MASK; - dwc3_writel(dwc->regs, DWC3_DCTL, reg); + dwc3_gadget_dctl_write_safe(dwc, reg); dwc->test_mode = false; dwc3_clear_stall_all_ep(dwc); @@ -2904,11 +2902,11 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) if (dwc->has_lpm_erratum && dwc->revision >= DWC3_REVISION_240A) reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold); - dwc3_writel(dwc->regs, DWC3_DCTL, reg); + dwc3_gadget_dctl_write_safe(dwc, reg); } else { reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg &= ~DWC3_DCTL_HIRD_THRES_MASK; - dwc3_writel(dwc->regs, DWC3_DCTL, reg); + dwc3_gadget_dctl_write_safe(dwc, reg); } dep = dwc->eps[0]; @@ -3017,7 +3015,7 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, reg &= ~u1u2; - dwc3_writel(dwc->regs, DWC3_DCTL, reg); + dwc3_gadget_dctl_write_safe(dwc, reg); break; default: /* do nothing */ diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index 5faf4d1249e0..fbc7d8013f0b 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h @@ -127,4 +127,18 @@ static inline void dwc3_gadget_ep_get_transfer_index(struct dwc3_ep *dep) dep->resource_index = DWC3_DEPCMD_GET_RSC_IDX(res_id); } +/** + * dwc3_gadget_dctl_write_safe - write to DCTL safe from link state change + * @dwc: pointer to our context structure + * @value: value to write to DCTL + * + * Use this function when doing read-modify-write to DCTL. It will not + * send link state change request. + */ +static inline void dwc3_gadget_dctl_write_safe(struct dwc3 *dwc, u32 value) +{ + value &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; + dwc3_writel(dwc->regs, DWC3_DCTL, value); +} + #endif /* __DRIVERS_USB_DWC3_GADGET_H */ From patchwork Thu Oct 24 02:15:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11208155 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D777E112C for ; Thu, 24 Oct 2019 02:15:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE9622086D for ; Thu, 24 Oct 2019 02:15:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="Lxxsf6iX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436769AbfJXCPv (ORCPT ); Wed, 23 Oct 2019 22:15:51 -0400 Received: from dc8-smtprelay2.synopsys.com ([198.182.47.102]:42370 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436605AbfJXCPu (ORCPT ); Wed, 23 Oct 2019 22:15:50 -0400 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id A2F0AC0B5E; Thu, 24 Oct 2019 02:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1571883350; bh=7xLxcdEgHbiLNDQ1pFvSRTSIsYs+h4+L9ave6PTVtXg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Lxxsf6iXmQPbtRU3Mbi6UI3GYreTDWlHc8NkEY6MDHj3hoT/EJjEoNX+AtfoJGZrg hPdN6wX0cBaCOey5WE22U0jSQ4iUDLSTa5SgzevOmcJojXAyTnQRZ3oiaD4X6EMElR uve1EZ1jAtui7nyCXPk0xfcmftPV1+VaUyCR+3oWdFnhW3BGvS7IW4jtTDsCk/iEHr Fb7BYXqkEdu9++sFad2X1VWggUp0PIwDthyhThgP1/jl5s7fil6filS5oLiVMMSZof Y4OfeujZlw2HzSYtGPMwgUvLTjYqRJNLoM7TOAJ0ILsNsawLubFGB+s3y4M43L1ULm w5F+r/TCoE37g== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 8B9CBA0064; Thu, 24 Oct 2019 02:15:49 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 23 Oct 2019 19:15:49 -0700 Date: Wed, 23 Oct 2019 19:15:49 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 2/4] usb: dwc3: gadget: Set link state to RX_Detect on disconnect To: Felipe Balbi , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When DWC3 receives disconnect event, it needs to set the link state to RX_Detect. DWC_usb3 3.30a programming guide 4.1.7 Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 85adc718808a..5856c8c96418 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2743,6 +2743,8 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) { int reg; + dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); + reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg &= ~DWC3_DCTL_INITU1ENA; reg &= ~DWC3_DCTL_INITU2ENA; From patchwork Thu Oct 24 02:15:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11208157 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32EE2112C for ; Thu, 24 Oct 2019 02:15:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08E702086D for ; Thu, 24 Oct 2019 02:15:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="DlqzONlF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436786AbfJXCP5 (ORCPT ); Wed, 23 Oct 2019 22:15:57 -0400 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]:58626 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436605AbfJXCP5 (ORCPT ); Wed, 23 Oct 2019 22:15:57 -0400 Received: from mailhost.synopsys.com (sv2-mailhost1.synopsys.com [10.205.2.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id CB69EC0239; Thu, 24 Oct 2019 02:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1571883356; bh=Qj7MaDOXqFXYmlayYiTBixG3sFATVpQdY6vxqDaCJsk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=DlqzONlFsAj34HfpUSLwLGNiwFdfoZ1KkW/hiJg6Z/eu/djBPNzeaDlTiyeaCqxfB LdrpYcBYrwrk4pob3y3EgQ61SOaSspcqNF55jbqCiDNMqs0pHnh3qKRk6QIEnOWfYM Eqrcy5+X1rba7MenOZ9xL/VXtzCLywZZI4abpAxZ9QWXdTbgflqXX1k+NErJy9q5p+ LG/G/cLh6DWCKTG6lW2FWneI/ayGyRueRpnmqapecLOcHmSyM4LSXBVqHDqlZXEjAJ ZoOMfTEMoXe5VaZe/o5kPhbfrtLT1P1vHkeVEAvVVRCrMsUg7L5FTAyAM3i3HBusO0 xIwXnNN2zkpWQ== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 9C0F5A005A; Thu, 24 Oct 2019 02:15:55 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 23 Oct 2019 19:15:55 -0700 Date: Wed, 23 Oct 2019 19:15:55 -0700 Message-Id: <11954a39aa8a2ee06c561ffad60932f50366af59.1571882179.git.thinhn@synopsys.com> In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 3/4] usb: dwc3: gadget: Clear DCTL.ULSTCHNGREQ before set To: Felipe Balbi , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Send a no-action link state change request before the actual request so DWC3 can send the same request whenever we call dwc3_gadget_set_link_state(). Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 5856c8c96418..7f97856e6b20 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -111,6 +111,9 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state) reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; + /* set no action before sending new link state change */ + dwc3_writel(dwc->regs, DWC3_DCTL, reg); + /* set requested state */ reg |= DWC3_DCTL_ULSTCHNGREQ(state); dwc3_writel(dwc->regs, DWC3_DCTL, reg); From patchwork Thu Oct 24 02:16:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 11208159 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 999ED913 for ; Thu, 24 Oct 2019 02:16:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F4972086D for ; Thu, 24 Oct 2019 02:16:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="H3FrKHiM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436810AbfJXCQE (ORCPT ); Wed, 23 Oct 2019 22:16:04 -0400 Received: from us03-smtprelay2.synopsys.com ([149.117.87.133]:58630 "EHLO smtprelay-out1.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436605AbfJXCQD (ORCPT ); Wed, 23 Oct 2019 22:16:03 -0400 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 41AD9C0239; Thu, 24 Oct 2019 02:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1571883363; bh=Ot6jUybTLjzITL1McgAzEtE8wQEtYOI7xyxGMxD6Oug=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=H3FrKHiMGVE8ZRF88hZwOt3UE2UAH8nHsKDhuw1h9NnNTkoeEL6k1rAbzXSxc6CuU tRqD9ipf8dULTej9HDNrad8ScMpzzXEMPTe395KdusGj/Pq+kQtvZge2tn8GD8xHaH KT6Z0+7e4NVljNWJL/LBB1q1KtwbHipTDtRvpllEk9zm9wli10/GReN1Bf6UeIJD6m QxvgQLJQ6nuNwfSZwwqmV03tTYiVB8kHBoFMDdB4gz2EZrRfZ1qES/Me9yPt4Ctf0u 4fzic6PqUgVtyqgLosB8J/2ZTNqofOL5/UBzbI23NQEDxVhQMYJbBscI4J7TGyTKlU Glruct7RwbOTQ== Received: from te-lab16 (nanobot.internal.synopsys.com [10.10.186.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mailhost.synopsys.com (Postfix) with ESMTPSA id 0CC8DA005A; Thu, 24 Oct 2019 02:16:01 +0000 (UTC) Received: by te-lab16 (sSMTP sendmail emulation); Wed, 23 Oct 2019 19:16:01 -0700 Date: Wed, 23 Oct 2019 19:16:01 -0700 Message-Id: In-Reply-To: References: From: Thinh Nguyen Subject: [PATCH v2 4/4] usb: dwc3: debug: Remove newline printout To: Felipe Balbi , Thinh Nguyen , linux-usb@vger.kernel.org Cc: John Youn Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The newline from the unknown link state tracepoint doesn't follow the other tracepoints, and it looks unsightly. Let's remove it. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/debug.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h index 9baabed87d61..e56beb9d1e36 100644 --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h @@ -112,7 +112,7 @@ dwc3_gadget_link_string(enum dwc3_link_state link_state) case DWC3_LINK_STATE_RESUME: return "Resume"; default: - return "UNKNOWN link state\n"; + return "UNKNOWN link state"; } } @@ -141,7 +141,7 @@ dwc3_gadget_hs_link_string(enum dwc3_link_state link_state) case DWC3_LINK_STATE_RESUME: return "Resume"; default: - return "UNKNOWN link state\n"; + return "UNKNOWN link state"; } }