Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2516183lqt; Mon, 22 Apr 2024 13:00:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWIVEfMrez1kSZaFiV9ItgpJPudOyxvGtY0np+FuxkKhu7tKCZbI4asZuvcn146vRg4b0jKl176By2/Ao487QjSA07/8g8JcO3I94Rp2Q== X-Google-Smtp-Source: AGHT+IHEAz4LIXfd0321Af+7Dl4iryfoahNbPflAye0SKmllQggHB45/lZ+2KFNt/umaJHLVm5dH X-Received: by 2002:a0c:e154:0:b0:6a0:6e91:9bfc with SMTP id c20-20020a0ce154000000b006a06e919bfcmr8510107qvl.57.1713816055719; Mon, 22 Apr 2024 13:00:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713816055; cv=pass; d=google.com; s=arc-20160816; b=SplW5Uv4pA/sQQcNCXJ1Jrpw3sz9DZq2WXkTgLclRVha9PbFDaSRMLD4DbS375ZIwM 29k4AQZ45wqfAAVhy7uaNMM7BwmrchwesOL1r5raVcprzTFkrF8N1U5lynaoSEv5bEM4 H0/wKayQNZnbVXcHYg0KTfk797Ke5ebcF4k93RFQYOUupxw0z0nkQMoDfAMugO9gRAUk Nh3ARaspIFKbPuG1kWTUpKOm3/vvHujfkjcP6v0IYZEUPGKBY89YJp0L9lagRl+FFnOM WQjSgaQ9v8tx6Nth+kkO2ncBCLqglMIe/46y34Tob6V4W9v/1nxhL5POgzf80SAeSwGq C+wQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ztQEUQ1VXVN/3kCcl2i+7uwX3vjmlv6H5lsYtuFHU80=; fh=7DncAfBWi8QNyB2hJxfXbRinZf9eL5UZzQFv5RS7kSU=; b=J2a9DpJ+keyvngjEZM5WGEmpwCFNDFFDwNP24o97Qxv1yvg9ULU+C/zajMaayzVUQD 1CZr2U7PFmK1FkfhLhvaQdLSYeBr2pCOAeSaAxjgW9GlTt6qtHsV0bHXjTcwXR/DhIBi HcTj+Fk+KtZY/R7VhcMXHJ++HUeSoPSrp8V9b/Dt9I/cfacQDV2KG7hqMXdWtiFnDidw 1/bt1qfQTQTtz67FOPyLosW4AiiAcz5ZFg/bPDuz9lPZjmlZ+SUorpz6Trnq4keWsu6X AHNc1Tk7wo0SJLxGTUkJh1BxG0N/frwSCdP0uuJp9JSC60HHMJidvguAwh/fGYZhFPSU RKjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pSBfgAL1; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-153969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153969-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 12-20020ad45bac000000b006a085cacaa7si1548175qvq.557.2024.04.22.13.00.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 13:00:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=pSBfgAL1; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-153969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153969-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 72AB51C20F0C for ; Mon, 22 Apr 2024 20:00:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2561156C69; Mon, 22 Apr 2024 19:59:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pSBfgAL1" Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (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 8152A15698F for ; Mon, 22 Apr 2024 19:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713815967; cv=none; b=AwBopsg+WflKZQyCL9QqyPBEGUVWVyYMP67o/uoxHL+tAsvyQoFZWELpilQyJJKEIWS6zL8Fk+VBBdG9Kvh8RTp0toDyaq/bB/F99tZjwBJw2Sn+FTrpH8+YRaBHffBLJGFa4NIwJHYBukMqVuSedIbl/XmPErgHqtiSWN5kyiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713815967; c=relaxed/simple; bh=bKIRdcv+IsQ1KdaKP2rdYU5S61mJTyYBq22uBE/yjnM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SM0H7MGdTZjUxfnt/h8PbcVp5SCdupiPRScdDMDVxe0xzAQhvfeFFTFfARQHGzx++6ANtsEiogdFLHFtsv6a5ofOOKkrg64t+c+3KQhVIeq5FcEFxUYuSBfKEiXHnMAwyNrgQTmEjRtqG3ayRW8/JoLzrLm5xIwnpqwFGoVpbO4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=pSBfgAL1; arc=none smtp.client-ip=95.215.58.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1713815963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ztQEUQ1VXVN/3kCcl2i+7uwX3vjmlv6H5lsYtuFHU80=; b=pSBfgAL127YmQuamNHkZgu6BDxmwJA8i/SI74qw8qczqUNhRfh6G+lQ2cRcZbQxaOFwPiD qJtXG8VTT0+2Po5SddgGQ+ljgrnKEmcYBCXFcX4ZqXx5BZx7KGhKDiNYRoIOMnyvKviuiu 7LpggJ864j7Gz0KmV/7omj+9wKMwgRE= From: Sean Anderson To: Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Rob Herring , linux-pci@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Thippeswamy Havalige , Michal Simek , Bjorn Helgaas , Sean Anderson Subject: [PATCH 6/7] PCI: xilinx-nwl: Add phy support Date: Mon, 22 Apr 2024 15:59:03 -0400 Message-Id: <20240422195904.3591683-7-sean.anderson@linux.dev> In-Reply-To: <20240422195904.3591683-1-sean.anderson@linux.dev> References: <20240422195904.3591683-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Add support for enabling/disabling PCIe phys. We can't really do anything about failures in the disable/remove path, so just warn. Signed-off-by: Sean Anderson --- drivers/pci/controller/pcie-xilinx-nwl.c | 70 +++++++++++++++++++++++- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pcie-xilinx-nwl.c b/drivers/pci/controller/pcie-xilinx-nwl.c index 424cc5a1b4d1..19a0ff105401 100644 --- a/drivers/pci/controller/pcie-xilinx-nwl.c +++ b/drivers/pci/controller/pcie-xilinx-nwl.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -157,6 +158,7 @@ struct nwl_pcie { void __iomem *breg_base; void __iomem *pcireg_base; void __iomem *ecam_base; + struct phy *phy[4]; phys_addr_t phys_breg_base; /* Physical Bridge Register Base */ phys_addr_t phys_pcie_reg_base; /* Physical PCIe Controller Base */ phys_addr_t phys_ecam_base; /* Physical Configuration Base */ @@ -521,6 +523,43 @@ static int nwl_pcie_init_msi_irq_domain(struct nwl_pcie *pcie) return 0; } +static int nwl_pcie_phy_enable(struct nwl_pcie *pcie) +{ + int i, ret; + + for (i = 0; i < ARRAY_SIZE(pcie->phy); i++) { + ret = phy_init(pcie->phy[i]); + if (ret) + goto err; + + ret = phy_power_on(pcie->phy[i]); + if (ret) { + WARN_ON(phy_exit(pcie->phy[i])); + goto err; + } + } + + return 0; + +err: + while (--i) { + WARN_ON(phy_power_off(pcie->phy[i])); + WARN_ON(phy_exit(pcie->phy[i])); + } + + return ret; +} + +static void nwl_pcie_phy_disable(struct nwl_pcie *pcie) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(pcie->phy); i++) { + WARN_ON(phy_power_off(pcie->phy[i])); + WARN_ON(phy_exit(pcie->phy[i])); + } +} + static int nwl_pcie_init_irq_domain(struct nwl_pcie *pcie) { struct device *dev = pcie->dev; @@ -732,6 +771,7 @@ static int nwl_pcie_parse_dt(struct nwl_pcie *pcie, { struct device *dev = pcie->dev; struct resource *res; + int i; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "breg"); pcie->breg_base = devm_ioremap_resource(dev, res); @@ -759,6 +799,20 @@ static int nwl_pcie_parse_dt(struct nwl_pcie *pcie, irq_set_chained_handler_and_data(pcie->irq_intx, nwl_pcie_leg_handler, pcie); + for (i = 0; i < ARRAY_SIZE(pcie->phy); i++) { + char name[16]; + + snprintf(name, sizeof(name), "pcie-phy%d", i); + pcie->phy[i] = devm_phy_get(dev, name); + if (PTR_ERR(pcie->phy[i]) == -ENODEV) { + pcie->phy[i] = NULL; + break; + } + + if (IS_ERR(pcie->phy[i])) + return PTR_ERR(pcie->phy[i]); + } + return 0; } @@ -799,16 +853,22 @@ static int nwl_pcie_probe(struct platform_device *pdev) return err; } + err = nwl_pcie_phy_enable(pcie); + if (err) { + dev_err(dev, "could not enable PHYs\n"); + goto err_clk; + } + err = nwl_pcie_bridge_init(pcie); if (err) { dev_err(dev, "HW Initialization failed\n"); - goto err_clk; + goto err_phy; } err = nwl_pcie_init_irq_domain(pcie); if (err) { dev_err(dev, "Failed creating IRQ Domain\n"); - goto err_clk; + goto err_phy; } bridge->sysdata = pcie; @@ -818,12 +878,15 @@ static int nwl_pcie_probe(struct platform_device *pdev) err = nwl_pcie_enable_msi(pcie); if (err < 0) { dev_err(dev, "failed to enable MSI support: %d\n", err); - goto err_clk; + goto err_phy; } } err = pci_host_probe(bridge); +err_phy: + if (err) + nwl_pcie_phy_disable(pcie); err_clk: if (err) clk_disable_unprepare(pcie->clk); @@ -834,6 +897,7 @@ static void nwl_pcie_remove(struct platform_device *pdev) { struct nwl_pcie *pcie = platform_get_drvdata(pdev); + nwl_pcie_phy_disable(pcie); clk_disable_unprepare(pcie->clk); } -- 2.35.1.1320.gc452695387.dirty