From patchwork Tue Apr 16 05:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 13631292 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 969F1C04FF6 for ; Tue, 16 Apr 2024 05:43:13 +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:Cc:To:Message-Id:MIME-Version:Subject: Date:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=0CSkr7Ez7bLCZlknW2q9zSQyVlAPErfWMV2OxKuvX6s=; b=vQ4GWQlcwDat3A GZcjR5Vw/p1imFvxf6B6TxAKTx1X8kYESfIzAjG0YCBsgd0PRnjS0EUgkZanYcKn6w++njbZflXpQ 5sKMRkwfJS+BJKTD3RSipjc14R9ytfDefJus52DI12rGFg7VDlXUmrUDZM0FpdW7mf5QL4q1+gHGf BSDrF7r3QQR0aporIQ8RhJJ7XEWNhsX143GZAoCHlryyaSlNfUAFTr2bitMPEGmvH4zW4YVbSvJPH XCD8yyrHbWZv1VBfioWykNQ0/hPz54moMrrVOnaXG96leT2BdLrKYtgf7RJF4VzgFJ99ETOUzkANv WB2CTD8AoYoFhBnDrSGg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwbay-0000000AxkR-1Sxx; Tue, 16 Apr 2024 05:43:04 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwbat-0000000Axhr-3SgG for linux-arm-kernel@lists.infradead.org; Tue, 16 Apr 2024 05:43:02 +0000 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6ece8991654so3616427b3a.3 for ; Mon, 15 Apr 2024 22:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713246177; x=1713850977; darn=lists.infradead.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=A3zTEkiG2nqHLpygf92sT5A2vKJ1K17V0uKLVPKWPqc=; b=FRqFL6LYllKh/doF+HC0VtaJGJW0rLLWwKi90vCSwr3pDtuQFyGQ1KMbooi9P7A+QM tvdbGl1z9Yh89AtLfZpVzqKbE0KXx0z33QQJG1cLto+zXAUW4qoJAKnn3cjOKmmD4XSe wTzR+63IEoGxbwIGXA1sMIyrbxGOxPp+sqaulme2qTj6UVLQMWC5mgvZafZ79lgymPtl a03X5g9Ra39c2ZXEbvBk9ctvGcQXGkHgTBbAWNVAv8mhzoIhPlVLx+24RSyGnGZPa/8M nY7ipnsiWXOPa5HDBdcF6Ip3H+efSRs78sLu6+BXmHxaKOvTh1YhDUbWW0irEuVtQcVH TG+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713246177; x=1713850977; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=A3zTEkiG2nqHLpygf92sT5A2vKJ1K17V0uKLVPKWPqc=; b=J6tSbMoD2bF+Ks3+CCA9JJ9wS3/uJHq4rkV9dVuA1zr9YQqBtVnC3zis7bDdMbhe+c 43UrG3hs8/J7C8CymvBCBwmCQzy6/dpADnNVjWdvmT6kQfnFYMu8H9EhwbbYKueyeab3 77Pqjr35bNLRICBH7tVSbUhSXEXkOE0TV+OTDIMMWRsgnUjcTZlMTsFnfIJSdlpa3QIR mLo6zAHUhJgNjOgwacWyLg/Q3DdT7KIL2btfWMllB94u8IC9oW5+NeiHN1ug+M1LqjOy wvqXYodXDYJz0EUl/zhZlzZB2uMsly1urE97/dWM6Yz4K1bWjHWn6u08+4aCJmCSHdIJ xLXw== X-Forwarded-Encrypted: i=1; AJvYcCUJk+TA4QByaepmBeobefz4Evkg0qgmfR3R4QCh+f2PfFhMKdoNnHH4+3LH7OIx32UKb2DkMjvwQHdewGP721ajHyaxLyEWdSYOie9oqQHlcxpT5t8= X-Gm-Message-State: AOJu0YxavqwI0BU6odU8RyFZJtr+IEdmBdSEXoP5LOYDQF566RD9O+Vr fTt2GYqPbanY7soTuHsvogVs+rlyXCBipmM8s8+QX66h986snHXXDB0IYLE90w== X-Google-Smtp-Source: AGHT+IHmL5CGk/C9YY3eQgCl7Y3aehKD10gTha3MpE92TAHps4Lx1+7Q4FtBizYCJM5LHup7vD1Aeg== X-Received: by 2002:a05:6a00:1945:b0:6ea:f4ad:7298 with SMTP id s5-20020a056a00194500b006eaf4ad7298mr16195085pfk.34.1713246177243; Mon, 15 Apr 2024 22:42:57 -0700 (PDT) Received: from [127.0.1.1] ([103.28.246.221]) by smtp.gmail.com with ESMTPSA id jw9-20020a056a00928900b006ece7862035sm8096651pfb.128.2024.04.15.22.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 22:42:56 -0700 (PDT) From: Manivannan Sadhasivam Date: Tue, 16 Apr 2024 11:12:35 +0530 Subject: [PATCH] PCI: rockchip: Use GPIOD_OUT_LOW flag while requesting ep_gpio MIME-Version: 1.0 Message-Id: <20240416-pci-rockchip-perst-fix-v1-1-4800b1d4d954@linaro.org> X-B4-Tracking: v=1; b=H4sIAMoPHmYC/x2MQQqAMAzAviI9W3BFxvQr4kFq1SLo6EQE2d8dH hNIXkhiKgn66gWTW5OeRwFXV8DbdKyCOhcGaqhtWucxsqKdvPOmEaNYunDRB0PgjsiTm7sJShx Niv7Hw5jzB1Ks2+JoAAAA To: Shawn Lin , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Rob Herring , Bjorn Helgaas , Heiko Stuebner , Brian Norris Cc: linux-pci@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mhi@lists.linux.dev, stable@vger.kernel.org, Slark Xiao , Manivannan Sadhasivam X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3420; i=manivannan.sadhasivam@linaro.org; h=from:subject:message-id; bh=YzcwzdZL4XKreo1CF3wbVR5j3L/jHhRL6gcOR16pIWc=; b=owEBbQGS/pANAwAKAVWfEeb+kc71AcsmYgBmHg/crzU1Kkb1i9AqXVJ3hRXBiUx9TkrzmPVOq mUTZO2izYWJATMEAAEKAB0WIQRnpUMqgUjL2KRYJ5dVnxHm/pHO9QUCZh4P3AAKCRBVnxHm/pHO 9fTRCACK8wHhlIy/kLvZHbQzhc/EFgpLhGxBwGkKpiC9xOYMycx6mQuk8X1lpK2goCoKljGgktY e/Ti3YO9R2ntH5ycJCk/FK/xMY1wZffrkZYUg6QKtEvZoa/kWnzAIk+Vt9bagTtP++dRzu4C7bq 0Zgccetk3ERl1hzVhTluvHGB1AEHOCgCIyQTOS31v3gy2QmRLo4zDLQULZvtm6X0fNDJNQ2qlsW ftcyIPvXBVxIDlkQsY8t5m23kXP/PeVhPhIn/bvbB2rJ5g4Tsr15A3RwqVuSKt9C6V89PogwlGn qFNOcL9t95ugWM11fE3JxyLL309ww7DJvfLnqgnK8zPZDpqZ X-Developer-Key: i=manivannan.sadhasivam@linaro.org; a=openpgp; fpr=C668AEC3C3188E4C611465E7488550E901166008 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240415_224300_015201_D9983CD3 X-CRM114-Status: GOOD ( 18.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rockchip platforms use 'GPIO_ACTIVE_HIGH' flag in the devicetree definition for ep_gpio. This means, whatever the logical value set by the driver for the ep_gpio, physical line will output the same logic level. For instance, gpiod_set_value_cansleep(rockchip->ep_gpio, 0); --> Level low gpiod_set_value_cansleep(rockchip->ep_gpio, 1); --> Level high But while requesting the ep_gpio, GPIOD_OUT_HIGH flag is currently used. Now, this also causes the physical line to output 'high' creating trouble for endpoint devices during host reboot. When host reboot happens, the ep_gpio will initially output 'low' due to the GPIO getting reset to its POR value. Then during host controller probe, it will output 'high' due to GPIOD_OUT_HIGH flag. Then during rockchip_pcie_host_init_port(), it will first output 'low' and then 'high' indicating the completion of controller initialization. On the endpoint side, each output 'low' of ep_gpio is accounted for PERST# assert and 'high' for PERST# deassert. With the above mentioned flow during host reboot, endpoint will witness below state changes for PERST#: (1) PERST# assert - GPIO POR state (2) PERST# deassert - GPIOD_OUT_HIGH while requesting GPIO (3) PERST# assert - rockchip_pcie_host_init_port() (4) PERST# deassert - rockchip_pcie_host_init_port() Now the time interval between (2) and (3) is very short as both happen during the driver probe(), and this results in a race in the endpoint. Because, before completing the PERST# deassertion in (2), endpoint got another PERST# assert in (3). A proper way to fix this issue is to change the GPIOD_OUT_HIGH flag in (2) to GPIOD_OUT_LOW. Because the usual convention is to request the GPIO with a state corresponding to its 'initial/default' value and let the driver change the state of the GPIO when required. As per that, the ep_gpio should be requested with GPIOD_OUT_LOW as it corresponds to the POR value of '0' (PERST# assert in the endpoint). Then the driver can change the state of the ep_gpio later in rockchip_pcie_host_init_port() as per the initialization sequence. This fixes the firmware crash issue in Qcom based modems connected to Rockpro64 based board. Cc: # 4.9 Reported-by: Slark Xiao Closes: https://lore.kernel.org/mhi/20240402045647.GG2933@thinkpad/ Fixes: e77f847df54c ("PCI: rockchip: Add Rockchip PCIe controller support") Signed-off-by: Manivannan Sadhasivam Reviewed-by: Niklas Cassel --- drivers/pci/controller/pcie-rockchip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: 4cece764965020c22cff7665b18a012006359095 change-id: 20240416-pci-rockchip-perst-fix-88c922621d9a Best regards, diff --git a/drivers/pci/controller/pcie-rockchip.c b/drivers/pci/controller/pcie-rockchip.c index 0ef2e622d36e..c07d7129f1c7 100644 --- a/drivers/pci/controller/pcie-rockchip.c +++ b/drivers/pci/controller/pcie-rockchip.c @@ -121,7 +121,7 @@ int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip) if (rockchip->is_rc) { rockchip->ep_gpio = devm_gpiod_get_optional(dev, "ep", - GPIOD_OUT_HIGH); + GPIOD_OUT_LOW); if (IS_ERR(rockchip->ep_gpio)) return dev_err_probe(dev, PTR_ERR(rockchip->ep_gpio), "failed to get ep GPIO\n");