From patchwork Thu Jan 11 10:38:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 124187 Delivered-To: patch@linaro.org Received: by 10.80.140.226 with SMTP id r31csp382189edr; Thu, 11 Jan 2018 02:38:26 -0800 (PST) X-Google-Smtp-Source: ACJfBosN7cmsm/5u+8YV77OBRnQosoYK0WUXtQBMuyd7dCMEUuNSsih0RHABsaE7leibYuMk7Q+b X-Received: by 10.84.253.131 with SMTP id a3mr22218356plm.281.1515667106311; Thu, 11 Jan 2018 02:38:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515667106; cv=none; d=google.com; s=arc-20160816; b=fcxNSzHbuyNyzPXnExguuqOlEuUTNvp2bRXSHrW3AKjnUbEhXvQggCklHqWTlgEh+H oXdu3kqPXAcGHuFkeeNrU3LyzL/VLzQYF7U8kd29CzivpAAQI4+sqdbBTMtVufy2IFVx nq22IgHpg33s+ngRIfmutElwZ1i/yw2nUioqfNlHDFMJGKtgq+wVPQ9o6DTJyzdEHtOB d7IyGW2jtWLzrVsh3RP4CwBEOj/mwe8BCwZOXdCiGS/VRwMq6oLMXaI/TQc3Y83oGBpf NGzsoIj7E4ukBLAWDhCTeU/9Z6Vb0k9R81SExaVucdPGK+qAuATq1pCepEMir+aapzSX qjTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature:arc-authentication-results; bh=CBjmgtcp65nrNA9eIXSROKXMKJ+gVe5VEBh4q5RSzsI=; b=xyy6y1u83UXOIol1vbCJuSc71KukzQkDcgYdBcfKun1aa5MU5mCdzdKjutICTT4/eq Q2bMh1JeaGI9rncqdDjedAzq2LzUg5mT4DBx6+SOZBJz2LQe5qvPFkF/rSEwx2XFelJX oItsDK6LziqcqAg0E0gh9o1yrVU0E8AHAkHi6Jx9MIqbgu//+oLNAl5CtNtqeewFBWtP kpsuHdIyeT1WxC+E82AXO5xMGVOexu+5ylC73TtiOJncMMj/K/Nt71uoa/8WSqky8DTp EhNwMeDGW7aTp+BVrVWQfc8Zyuy+RinzsO4VxYh+J8PI/y2AKqUDVqn1syX+KIbfQZJb kOnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=EkAnq8S2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y40si13599085pla.793.2018.01.11.02.38.26; Thu, 11 Jan 2018 02:38:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=EkAnq8S2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933473AbeAKKiW (ORCPT + 28 others); Thu, 11 Jan 2018 05:38:22 -0500 Received: from lelnx194.ext.ti.com ([198.47.27.80]:14179 "EHLO lelnx194.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933414AbeAKKiT (ORCPT ); Thu, 11 Jan 2018 05:38:19 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id w0BAcEF2007156; Thu, 11 Jan 2018 04:38:14 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1515667094; bh=LGOXZqTaRNlFleRHtysxbjwgb2BwHY8vqF4Mlo0q0Ds=; h=From:To:CC:Subject:Date; b=EkAnq8S2UyFiZaojziJpcv2+enPYqDTrniYH8s29QoRb+sK/HFNt9fJXjJdeqXIsL EdJeqQ2+ELVF3Y1LxMaKoPRYsW/d1/hqklcoyJRMZcgV5x2E09+sOi1+hL1+jUacrz J0C+BYQek9vhmTIimk07WINMmsQvTURKgvKJeZvQ= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0BAcExl003000; Thu, 11 Jan 2018 04:38:14 -0600 Received: from DLEE107.ent.ti.com (157.170.170.37) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1261.35; Thu, 11 Jan 2018 04:38:14 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1261.35 via Frontend Transport; Thu, 11 Jan 2018 04:38:14 -0600 Received: from dlelxv97.itg.ti.com (dlelxv97.itg.ti.com [172.17.2.193]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0BAcE2B022605; Thu, 11 Jan 2018 04:38:14 -0600 Received: from lta0400828d.ti.com (vboxa0400828d.emea.dhcp.ti.com [172.22.233.66]) by dlelxv97.itg.ti.com (8.14.3/8.13.8) with ESMTP id w0BAcBn6020881; Thu, 11 Jan 2018 04:38:12 -0600 From: Roger Quadros To: CC: , , , , Roger Quadros , "linux-stable # = v4 . 13" Subject: [PATCH v2] usb: dwc3: core: Fix ULPI PHYs and prevent phy_get/ulpi_init during suspend/resume Date: Thu, 11 Jan 2018 12:38:07 +0200 Message-ID: <1515667087-4110-1-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order for ULPI PHYs to work, dwc3_phy_setup() and dwc3_ulpi_init() must be doene before dwc3_core_get_phy(). commit 541768b08a40 ("usb: dwc3: core: Call dwc3_core_get_phy() before initializing phys") broke this. The other issue is that dwc3_core_get_phy() and dwc3_ulpi_init() should be called only once during the life cycle of the driver. However, as dwc3_core_init() is called during system suspend/resume it will result in multiple calls to dwc3_core_get_phy() and dwc3_ulpi_init() which is wrong. Fix this by moving dwc3_ulpi_init() out of dwc3_phy_setup() into dwc3_core_ulpi_init(). Use a flag 'ulpi_ready' to ensure that dwc3_core_ulpi_init() is called only once from dwc3_core_init(). Use another flag 'phys_ready' to call dwc3_core_get_phy() only once from dwc3_core_init(). Fixes: 541768b08a40 ("usb: dwc3: core: Call dwc3_core_get_phy() before initializing phys") Fixes: f54edb539c11 ("usb: dwc3: core: initialize ULPI before trying to get the PHY") Cc: linux-stable # >= v4.13 Signed-off-by: Roger Quadros --- Changelog: v2: - don't break ULPI case. Also take into consideration suspend/resume for ULPI case. drivers/usb/dwc3/core.c | 47 ++++++++++++++++++++++++++++++++++++----------- drivers/usb/dwc3/core.h | 5 +++++ 2 files changed, 41 insertions(+), 11 deletions(-) -- cheers, -roger Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 0783250..84382f6 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -482,6 +482,22 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc) parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); } +static int dwc3_core_ulpi_init(struct dwc3 *dwc) +{ + int intf; + int ret = 0; + + intf = DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3); + + if (intf == DWC3_GHWPARAMS3_HSPHY_IFC_ULPI || + (intf == DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI && + dwc->hsphy_interface && + !strncmp(dwc->hsphy_interface, "ulpi", 4))) + ret = dwc3_ulpi_init(dwc); + + return ret; +} + /** * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core * @dwc: Pointer to our controller context structure @@ -493,7 +509,6 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc) static int dwc3_phy_setup(struct dwc3 *dwc) { u32 reg; - int ret; reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); @@ -564,9 +579,6 @@ static int dwc3_phy_setup(struct dwc3 *dwc) } /* FALLTHROUGH */ case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI: - ret = dwc3_ulpi_init(dwc); - if (ret) - return ret; /* FALLTHROUGH */ default: break; @@ -723,6 +735,7 @@ static void dwc3_core_setup_global_control(struct dwc3 *dwc) } static int dwc3_core_get_phy(struct dwc3 *dwc); +static int dwc3_core_ulpi_init(struct dwc3 *dwc); /** * dwc3_core_init - Low-level initialization of DWC3 Core @@ -754,17 +767,27 @@ static int dwc3_core_init(struct dwc3 *dwc) dwc->maximum_speed = USB_SPEED_HIGH; } - ret = dwc3_core_get_phy(dwc); + ret = dwc3_phy_setup(dwc); if (ret) goto err0; - ret = dwc3_core_soft_reset(dwc); - if (ret) - goto err0; + if (!dwc->ulpi_ready) { + ret = dwc3_core_ulpi_init(dwc); + if (ret) + goto err0; + dwc->ulpi_ready = true; + } - ret = dwc3_phy_setup(dwc); + if (!dwc->phys_ready) { + ret = dwc3_core_get_phy(dwc); + if (ret) + goto err0a; + dwc->phys_ready = true; + } + + ret = dwc3_core_soft_reset(dwc); if (ret) - goto err0; + goto err0a; dwc3_core_setup_global_control(dwc); dwc3_core_num_eps(dwc); @@ -837,6 +860,9 @@ static int dwc3_core_init(struct dwc3 *dwc) phy_exit(dwc->usb2_generic_phy); phy_exit(dwc->usb3_generic_phy); +err0a: + dwc3_ulpi_exit(dwc); + err0: return ret; } @@ -1229,7 +1255,6 @@ static int dwc3_probe(struct platform_device *pdev) err3: dwc3_free_event_buffers(dwc); - dwc3_ulpi_exit(dwc); err2: pm_runtime_allow(&pdev->dev); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 4a4a4c9..6b202e3 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -795,7 +795,9 @@ struct dwc3_scratchpad_array { * @usb3_phy: pointer to USB3 PHY * @usb2_generic_phy: pointer to USB2 PHY * @usb3_generic_phy: pointer to USB3 PHY + * @phys_ready: flag to indicate that PHYs are ready * @ulpi: pointer to ulpi interface + * @ulpi_ready: flag to indicate that ULPI is initialized * @isoch_delay: wValue from Set Isochronous Delay request; * @u2sel: parameter from Set SEL request. * @u2pel: parameter from Set SEL request. @@ -893,7 +895,10 @@ struct dwc3 { struct phy *usb2_generic_phy; struct phy *usb3_generic_phy; + bool phys_ready; + struct ulpi *ulpi; + bool ulpi_ready; void __iomem *regs; size_t regs_size;