From patchwork Tue Feb 14 14:08:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rick Wertenbroek X-Patchwork-Id: 13140369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A0606C61DA4 for ; Tue, 14 Feb 2023 14:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CRHE5dOTKAy5Yo4pMHanYwDakJZOrKOT7So3yrYAVvU=; b=M8fFUeGHMWTYad bq+H+KaO1sueDclGvYnuRDLrgqIMDZlPgYz8j1/ZbHj8I2O2Y8Ymdm3Xvj5vUhq+xbE0wJSSNxHfD s7mwFO37T45SSuEXurGAXPnq92IgDufL9tosWl9EKhhld6AhMYU6uKs/tQtj0pPDeqC+/I+jHXweG 18uZBMf+CK0O85lhZHFvZL3QofFtPEGT5vTbMhomS8MU8vs2EpbWP704pcxK0lRl2N0xBqv+X+V/5 VUTXxYCddTdTuMOU+lHbA+nASIfdccE8wlz3GQuURMA1Sdlku9fJq9LMNijDX7c4OVUlCU0TCCz1z MLjvrvxeNuyZPTgKarvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRwXs-002GSw-QJ; Tue, 14 Feb 2023 14:44:36 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRw0U-0021KF-SK; Tue, 14 Feb 2023 14:10:08 +0000 Received: by mail-ej1-x633.google.com with SMTP id jg8so40399902ejc.6; Tue, 14 Feb 2023 06:10:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wlhNVngokcMAaPIU9YsiNMvp+CICZXJFUIQaHO3ObSo=; b=HS6vt8v8FJ4bXQy/YZe5flTG49HKxTKB1pLjucGq+lUFeWZcdClLvjWzIVJvSplQVI 7PA2I2gzFZ4I0F6hJT27YGypLzagHMBp6I7feTyiKmoeUhRjWEL4VRBZeKUce/SwMUle 4D7qF0ZesQzsGxkkgbZQ1ta1kNx2nrkHfDwy7I9+F0ofKMaqK16t+3LoUNBrde/NjyQs az5U6ZZE8zHE8HizqQGScI2J+SMjKIiZTGtRITqAPDzyv3N7ZtU5S0+MLaHQpDz8FZYZ LF4qHa6oV1SUR/cJmfSs6pQergQrwvDGFJ4hT4mzztx43dwNnHH25Piw+wMcBWyYpzez wxow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wlhNVngokcMAaPIU9YsiNMvp+CICZXJFUIQaHO3ObSo=; b=G/5WQvfV13JJSHEcCxSkU2caMqZd9t2ih/21OFJIppBzsjWwgv7qOqh0tJ6IsbloB2 K+dRNfY7FpL72nT1nQVCknKjEBl/U2V1J4wL8GbOEkeMrEEr1/vLwmYvrom82+Q41Hdy 5ALnSP/R7Grl3RNSgpSoF+/77XLQSpkY1Uzo6Z66fAjZLy5i55wnpiE/Kp1twgrb4z4v m4eLvWURba8wKCO/j4jlTjFiB/GiSjIG7xZZ8Y/aDbmZ55kliJuGDW7Vm4+bCHCa4Hmd PdmK3e3CDI05tA3ddhQNtD/hAUJuJDoMScerQZ/FSV7/ieTXM7W4AEKDSKpYf/BNvb4R cmuA== X-Gm-Message-State: AO0yUKWeBht8vXbL5tWlNgrI4M5OGY4kSxvsImSzWKYeDjWIyhU8pxrS fs51Pl/idenpFVJ79KARRbY= X-Google-Smtp-Source: AK7set8O61hFgKTFZuDfgH32RN6jBC0eEFWlPfzOZWQPCNksB1GIDJF//jlppO0Izpan8+U5ZnXmQw== X-Received: by 2002:a17:906:5512:b0:8aa:c0d6:2dc6 with SMTP id r18-20020a170906551200b008aac0d62dc6mr3098791ejp.29.1676383803683; Tue, 14 Feb 2023 06:10:03 -0800 (PST) Received: from A13PC04R.einet.ad.eivd.ch ([193.134.219.72]) by smtp.googlemail.com with ESMTPSA id n11-20020a1709065e0b00b008b13814f804sm332241eju.186.2023.02.14.06.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 06:10:03 -0800 (PST) From: Rick Wertenbroek To: alberto.dassatti@heig-vd.ch Cc: xxm@rock-chips.com, rick.wertenbroek@heig-vd.ch, Rick Wertenbroek , stable@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Heiko Stuebner , Shawn Lin , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Bjorn Helgaas , Jani Nikula , Greg Kroah-Hartman , Rodrigo Vivi , Mikko Kovanen , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v2 4/9] PCI: rockchip: Add poll and timeout to wait for PHY PLLs to be locked Date: Tue, 14 Feb 2023 15:08:52 +0100 Message-Id: <20230214140858.1133292-5-rick.wertenbroek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230214140858.1133292-1-rick.wertenbroek@gmail.com> References: <20230214140858.1133292-1-rick.wertenbroek@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230214_061006_990009_CB529B5E X-CRM114-Status: GOOD ( 15.93 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org The RK3399 PCIe controller should wait until the PHY PLLs are locked. Add poll and timeout to wait for PHY PLLs to be locked. If they cannot be locked generate error message and jump to error handler. Accessing registers in the PHY clock domain when PLLs are not locked causes hang The PHY PLLs status is checked through a side channel register. This is documented in the TRM section 17.5.8.1 "PCIe Initialization Sequence". Fixes: cf590b078391 ("PCI: rockchip: Add EP driver for Rockchip PCIe controller") Cc: stable@vger.kernel.org Signed-off-by: Rick Wertenbroek Reviewed-by: Damien Le Moal Tested-by: Damien Le Moal --- drivers/pci/controller/pcie-rockchip.c | 16 ++++++++++++++++ drivers/pci/controller/pcie-rockchip.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/drivers/pci/controller/pcie-rockchip.c b/drivers/pci/controller/pcie-rockchip.c index 990a00e08..5f2e2dd5d 100644 --- a/drivers/pci/controller/pcie-rockchip.c +++ b/drivers/pci/controller/pcie-rockchip.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -153,6 +154,12 @@ int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip) } EXPORT_SYMBOL_GPL(rockchip_pcie_parse_dt); +#define rockchip_pcie_read_addr(addr) rockchip_pcie_read(rockchip, addr) +/* 100 ms max wait time for PHY PLLs to lock */ +#define RK_PHY_PLL_LOCK_TIMEOUT_US 100000 +/* Sleep should be less than 20ms */ +#define RK_PHY_PLL_LOCK_SLEEP_US 1000 + int rockchip_pcie_init_port(struct rockchip_pcie *rockchip) { struct device *dev = rockchip->dev; @@ -254,6 +261,15 @@ int rockchip_pcie_init_port(struct rockchip_pcie *rockchip) } } + err = readx_poll_timeout(rockchip_pcie_read_addr, PCIE_CLIENT_SIDE_BAND_STATUS, + regs, !(regs & PCIE_CLIENT_PHY_ST), RK_PHY_PLL_LOCK_SLEEP_US, + RK_PHY_PLL_LOCK_TIMEOUT_US); + + if (err) { + dev_err(dev, "PHY PLLs could not lock, %d\n", err); + goto err_power_off_phy; + } + /* * Please don't reorder the deassert sequence of the following * four reset pins. diff --git a/drivers/pci/controller/pcie-rockchip.h b/drivers/pci/controller/pcie-rockchip.h index 51a123e5c..f3a5ff1cf 100644 --- a/drivers/pci/controller/pcie-rockchip.h +++ b/drivers/pci/controller/pcie-rockchip.h @@ -38,6 +38,8 @@ #define PCIE_CLIENT_MODE_EP HIWORD_UPDATE(0x0040, 0) #define PCIE_CLIENT_GEN_SEL_1 HIWORD_UPDATE(0x0080, 0) #define PCIE_CLIENT_GEN_SEL_2 HIWORD_UPDATE_BIT(0x0080) +#define PCIE_CLIENT_SIDE_BAND_STATUS (PCIE_CLIENT_BASE + 0x20) +#define PCIE_CLIENT_PHY_ST BIT(12) #define PCIE_CLIENT_DEBUG_OUT_0 (PCIE_CLIENT_BASE + 0x3c) #define PCIE_CLIENT_DEBUG_LTSSM_MASK GENMASK(5, 0) #define PCIE_CLIENT_DEBUG_LTSSM_L1 0x18