From patchwork Thu Feb 29 09:24:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 208277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp276488dyb; Thu, 29 Feb 2024 01:33:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsN2F+4aOk60j7krU2jM2nWUa2/BrWt9xIzlSSHZ0hwJWOsZzHJdz2s89qXDJo/tJFMBiLMDPvyco65Ig6D5UNHEAZuQ== X-Google-Smtp-Source: AGHT+IFenyMHgz7hXP8ZwqUYZbBnz7O3oHJzcQ3UbpciV6CR7+TXWff0oxEU08bvFbSJdbHQdBAb X-Received: by 2002:a05:6871:8e91:b0:21a:1aff:cceb with SMTP id zq17-20020a0568718e9100b0021a1affccebmr1284616oab.18.1709199213532; Thu, 29 Feb 2024 01:33:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709199213; cv=pass; d=google.com; s=arc-20160816; b=bayZI8haEDu0+Tq2PJ6HbdfkW0QZvSip1DHG7KI5WnNi2UZ8X30BSUq/KlyLIE9Gfm 69TGcjvRHhYVUI7ZofYfdy2VZfuKKRBUjGXXF2NgHYGhogm2BibacViRBDlSIzVyShku 20loViIkYkPI9z0x/9cOYTvJrtK4FBLY4SCWQ6k/Xjmo1Ujb8R70egUlrjY3yXZgWqqP aGtDk3NOEHmELPu4li2t91YEge7C5IBDVUhdVtZxtqJqSH8jCHnA/c8TJ1PoNI5hx3Am dQDPrFhwzjxK5Fwy3w/3xjMbpd2c7ouWYYMqQGJDM8BY49AUbD5ND3aqi5MEYh8xj14k b/bw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=QDgi3npwvvsIE/jl/CZlsKo1skX2AbE2tJyqxNAme5M=; fh=He2ByQA+9yaVa3esgOwhdatcI6NPOkZH1isFNEqppGk=; b=qd67mQ6osCc28CgQZ19BMtBdPrlUdxMu0kn+LUJNStgYXoqr0kbid4AkommJHteezD KU796gNULf5s+3sN30SNb2CrhbMcC/O0WCfUFxXfWZW2ICaiIFZKzHjchP7iRKxSh99U TamazHPXal450BW6gebJZJpxMMVQvKfKnBiKjtDKDqZi2C0Rg9ZG+F4BxPtr9yjQji96 7jmq0dRioGnxPaiWsDngIZfrKTnzNltLf7rzcpCCc2Xl75RfyVsn8ZMQDUYVPuupSzCj V4x7DdPcJxlvx11T60iE7UxWj5V/xD9WwIjzibfGnonVGEjhlkMswgDPKUeDOPmC55tY 7Hcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FE6Hx8J8; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-86407-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86407-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j2-20020a056a00234200b006e53edd5486si947368pfj.315.2024.02.29.01.33.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 01:33:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86407-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FE6Hx8J8; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-86407-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86407-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8B1FBB26912 for ; Thu, 29 Feb 2024 09:25:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C3C85A7BF; Thu, 29 Feb 2024 09:25:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="FE6Hx8J8" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15D245CDEC; Thu, 29 Feb 2024 09:24:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709198698; cv=none; b=uJo8FpM/wi01vJP0nCdslIBEFwfuFsjFr+nSX6RrA2VwRJTGmXLDVZjlYNiuvRnv3QcNTesq3tMXX7q8nEqkzR0jDcArq+/XwUBxdlVMv9zlngb5uV4Z8vWbvaeESQvd89cfyzRpnuTgeubIjLfx5UKB92EsFPCyaE0n3rugMM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709198698; c=relaxed/simple; bh=XZJdntqJVNSHehc3tw3MJZhLBZVBynJltmGB3n7U+yE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BNF7p88p4ui09DlQU81zBzPYKK5lRwukBnLyfqNuG1bqolKA00LPV86y1D9dtAfZVDj/c92xLGSxYDJ8nJDGdDBHF4ijmHvENUe73fhCd9PLJLM2vWVEB/quAHgA3eaksjRRlb2KvkU2GT+GzmbB/iofCpu3mCDz9Vj+70gkTv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=FE6Hx8J8; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1709198695; bh=XZJdntqJVNSHehc3tw3MJZhLBZVBynJltmGB3n7U+yE=; h=From:To:Cc:Subject:Date:From; b=FE6Hx8J82488o8NSMy1bbp1JLM8R52Ko3p7GNni4bCB77xmEPIgk44wLbS6SwVxv6 8+Y0yrSKNWONxg70YavAoO2hCvpM7HBGnwl0pr9RuwWu5uP7Eu/a5ivZsWLDvHgNRQ X+5GQYWRjzAfEoax51YxfNJIjfe7GIo6ZF5fS3GnGLiLvTKpwE2HeI2kyVP2oGdT2a yGJolz2Uy13th8ImVnm+qQOSaWBthYiwdIN1UbC34CFltTH9AQnYMS/PboDgb5q3TN HDruuLr+Uwrgl46Da1blP6ukhCQojMinmmKGstfNDEtc32ddVV21KO19xHMSsbJX3f 7lvPlVLP7Iw/w== Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 53A923781FE3; Thu, 29 Feb 2024 09:24:54 +0000 (UTC) From: AngeloGioacchino Del Regno To: linux-pci@vger.kernel.org Cc: ryder.lee@mediatek.com, jianjun.wang@mediatek.com, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, p.zabel@pengutronix.de, matthias.bgg@gmail.com, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, wenst@chromium.org, nfraprado@collabora.com, AngeloGioacchino Del Regno Subject: [PATCH v2] PCI: mediatek-gen3: Assert MAC reset only if PHY reset also present Date: Thu, 29 Feb 2024 10:24:49 +0100 Message-ID: <20240229092449.580971-1-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792225274339876430 X-GMAIL-MSGID: 1792225274339876430 Some SoCs have two PCI-Express controllers: in the case of MT8195, one of them is using a dedicated PHY, but the other uses a combo PHY that is shared with USB and in that case the PHY cannot be reset from the PCIe driver, or USB functionality will be unable to resume. Resetting the PCIe MAC without also resetting the PHY will result in a full system lockup at PCIe resume time and the only option to resume operation is to hard reboot the system (with a PMIC cut-off). To resolve this issue, check if we've got both a PHY and a MAC reset and, if not, never assert resets at PM suspend time: in that case, the link is still getting powered down as both the clocks and the power domains will go down anyway. Fixes: d537dc125f07 ("PCI: mediatek-gen3: Add system PM support") Signed-off-by: AngeloGioacchino Del Regno Tested-by: NĂ­colas F. R. A. Prado --- Changes in v2: - Rebased over next-20240229 drivers/pci/controller/pcie-mediatek-gen3.c | 25 ++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c index 975b3024fb08..99b5d7a49be1 100644 --- a/drivers/pci/controller/pcie-mediatek-gen3.c +++ b/drivers/pci/controller/pcie-mediatek-gen3.c @@ -874,17 +874,26 @@ static int mtk_pcie_power_up(struct mtk_gen3_pcie *pcie) return err; } -static void mtk_pcie_power_down(struct mtk_gen3_pcie *pcie) +static void mtk_pcie_power_down(struct mtk_gen3_pcie *pcie, bool is_suspend) { + bool suspend_reset_supported = pcie->mac_reset && pcie->phy_reset; + clk_bulk_disable_unprepare(pcie->num_clks, pcie->clks); pm_runtime_put_sync(pcie->dev); pm_runtime_disable(pcie->dev); - reset_control_assert(pcie->mac_reset); + + /* + * Assert MAC reset only if we also got a PHY reset, otherwise + * the system will lockup at PM resume time. + */ + if (is_suspend && suspend_reset_supported) + reset_control_assert(pcie->mac_reset); phy_power_off(pcie->phy); phy_exit(pcie->phy); - reset_control_assert(pcie->phy_reset); + if (is_suspend && suspend_reset_supported) + reset_control_assert(pcie->phy_reset); } static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie) @@ -920,7 +929,7 @@ static int mtk_pcie_setup(struct mtk_gen3_pcie *pcie) return 0; err_setup: - mtk_pcie_power_down(pcie); + mtk_pcie_power_down(pcie, false); return err; } @@ -951,7 +960,7 @@ static int mtk_pcie_probe(struct platform_device *pdev) err = pci_host_probe(host); if (err) { mtk_pcie_irq_teardown(pcie); - mtk_pcie_power_down(pcie); + mtk_pcie_power_down(pcie, false); return err; } @@ -969,7 +978,7 @@ static void mtk_pcie_remove(struct platform_device *pdev) pci_unlock_rescan_remove(); mtk_pcie_irq_teardown(pcie); - mtk_pcie_power_down(pcie); + mtk_pcie_power_down(pcie, false); } static void mtk_pcie_irq_save(struct mtk_gen3_pcie *pcie) @@ -1044,7 +1053,7 @@ static int mtk_pcie_suspend_noirq(struct device *dev) dev_dbg(pcie->dev, "entered L2 states successfully"); mtk_pcie_irq_save(pcie); - mtk_pcie_power_down(pcie); + mtk_pcie_power_down(pcie, true); return 0; } @@ -1060,7 +1069,7 @@ static int mtk_pcie_resume_noirq(struct device *dev) err = mtk_pcie_startup_port(pcie); if (err) { - mtk_pcie_power_down(pcie); + mtk_pcie_power_down(pcie, false); return err; }