From patchwork Mon Jun 25 08:30:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Douglas X-Patchwork-Id: 10485289 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 82F31601D5 for ; Mon, 25 Jun 2018 08:31:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B8EB2890B for ; Mon, 25 Jun 2018 08:31:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6029D28913; Mon, 25 Jun 2018 08:31:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B28582890B for ; Mon, 25 Jun 2018 08:31:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753716AbeFYIbW (ORCPT ); Mon, 25 Jun 2018 04:31:22 -0400 Received: from mail-co1nam03on0064.outbound.protection.outlook.com ([104.47.40.64]:43047 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754313AbeFYIbS (ORCPT ); Mon, 25 Jun 2018 04:31:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nZT1lRyBshaIneWyn0VFgsVUZd28kAxHuniEldkyM9Y=; b=YbPvb6hNWB+DDDsNabteYJr7L50+lwLoVyD0HJvbunvuMesN4cAFy1u3tMXK2+IF/MFj+kEvQgi+dGv0O2mbqKaXD7K1Vn/ZV1M3Dm+3N5Z3o347N5CbyiPp03NVUblkAc7n18qdvElaZhhWs82Khx71rUZVZRnELVHX2AmJSqc= Received: from DM6PR07CA0012.namprd07.prod.outlook.com (2603:10b6:5:94::25) by DM6PR07MB4713.namprd07.prod.outlook.com (2603:10b6:5:a1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.19; Mon, 25 Jun 2018 08:31:15 +0000 Received: from DM3NAM05FT025.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::208) by DM6PR07CA0012.outlook.office365.com (2603:10b6:5:94::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.884.19 via Frontend Transport; Mon, 25 Jun 2018 08:31:15 +0000 Authentication-Results: spf=softfail (sender IP is 199.43.4.28) smtp.mailfrom=cadence.com; arm.com; dkim=none (message not signed) header.d=none; arm.com; dmarc=fail action=none header.from=cadence.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 199.43.4.28 as permitted sender) Received: from rmmaillnx1.cadence.com (199.43.4.28) by DM3NAM05FT025.mail.protection.outlook.com (10.152.98.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.906.10 via Frontend Transport; Mon, 25 Jun 2018 08:31:15 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by rmmaillnx1.cadence.com (8.14.4/8.14.4) with ESMTP id w5P8V9Xv023349 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Mon, 25 Jun 2018 04:31:13 -0400 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 25 Jun 2018 10:31:29 +0200 Received: from lvloginb.cadence.com (10.165.177.11) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Mon, 25 Jun 2018 10:31:29 +0200 Received: from lvloginb.cadence.com (localhost [127.0.0.1]) by lvloginb.cadence.com (8.14.4/8.14.4) with ESMTP id w5P8VCFs006702; Mon, 25 Jun 2018 09:31:12 +0100 Received: (from adouglas@localhost) by lvloginb.cadence.com (8.14.4/8.14.4/Submit) id w5P8VBqS006697; Mon, 25 Jun 2018 09:31:11 +0100 From: Alan Douglas To: , , CC: , , , Alan Douglas Subject: [PATCH 2/5] PCI: cadence: Add generic PHY support to host and EP drivers Date: Mon, 25 Jun 2018 09:30:50 +0100 Message-ID: <1529915453-4633-3-git-send-email-adouglas@cadence.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1529915453-4633-1-git-send-email-adouglas@cadence.com> References: <1529915453-4633-1-git-send-email-adouglas@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:199.43.4.28; IPV:CAL; SCL:-1; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(396003)(376002)(39860400002)(346002)(39380400002)(2980300002)(3190300001)(189003)(36092001)(199004)(36756003)(2906002)(106466001)(69596002)(2616005)(336012)(476003)(105596002)(54906003)(110136005)(36906005)(42186006)(16586007)(316002)(486006)(126002)(305945005)(5660300001)(8676002)(6666003)(86362001)(356003)(51416003)(76176011)(186003)(446003)(2201001)(4326008)(59450400001)(426003)(11346002)(26005)(47776003)(50466002)(107886003)(68736007)(8936002)(81166006)(50226002)(53936002)(48376002)(81156014)(26826003)(478600001)(87636003)(97736004)(41533002); DIR:OUT; SFP:1101; SCL:1; SRVR:DM6PR07MB4713; H:rmmaillnx1.cadence.com; FPR:; SPF:SoftFail; LANG:en; PTR:InfoDomainNonexistent; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: 1; DM3NAM05FT025; 1:722PuWePw+62hkqkdqqVtyL+nzkBoaCI1PyCBkQQPey9t+NLv6Vf5BhNHC6DB+9x9C3lM8nkILy6mj8IhDCno/4g1dDw69MvHyyOoAqKau/YffHrBOw3cDMnmKVAQXUd X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1475355a-0ef7-49f7-0d3f-08d5da76043d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600026)(711020)(2017052603328)(7153060); SRVR:DM6PR07MB4713; X-Microsoft-Exchange-Diagnostics: 1; DM6PR07MB4713; 3:dDFfiiRg0KKqaLqKR6Wxl4M4EBXTepH+sO1+b8PNk3WhNLDkDyEMPFK3mLOMubOxdh9/MOVIs+o3piLKQXI3qGkJp6VIiLevGAX3MjDaT65a59f3VuGn9I+kC5xo26OW0S244P0aHXrz3RvDi9dOXCTHV7eqACcEfpcFixoBOZVELRqkNdomSJ4xiKkZKLi8dDABCMNlu6k+udVbFYWormssRXDpfP2sfUMNbmXwb3so4fN9lNPDZ7y0DyWHR7UC4g7PcQC1J/JrQdZYmGbD7J9yEbl4QNBAClerk7Ob5EVI2jpbitj1ikye438rUF8Q7sJMSx9fnQlkvY1EH90qMEce/pu2QKx269zNcIsz2xI=; 25:2yJCUJACiTIPKTNHHpLopursyiAev0gCtGrBgwklUsnkmWPOP3BIMs1PxV13T38CG/PIYt0aOZS4ADdUhkBSoq3ArqTth4BtghN+xeqJHT4DzifXMKzPdlaWx7Qjcyq4bFg8LU4WND16WwOQuEUMjw++WP3UGRSw2JOmVvexlqHCmbdqrRU1XW46qXmV7KRwwvYEuYxYwRN1vPnXafvD0e47AX4B96DJRj0fEZx1GdThpOfvEx0wi7fL9T//16Gs+K5ghcerbr+AcR4bsGAWqSHmIJvH8YN/invFxo0tJbfI/oVptP4adDfO1c2NGRo/4DYHjDatb1hLD+Vi+naeYQ== X-MS-TrafficTypeDiagnostic: DM6PR07MB4713: X-Microsoft-Exchange-Diagnostics: 1; DM6PR07MB4713; 31:FxqRgd+NPkpMqtiD88VHoNJ7euXS04/GFMHnTirazh6qAuIOvWNcrD5fDhjokiz18OUEY4gvjQhptoH9/MUCS+3pYtR5hJ/RqE9W8/monwvBNhWdSW6cnAhSLR933WMqrQJDITW+oto20BUGcu1vB32cc41+T1hirl6ckE3Hda8Ov04Usg5zzsK4OJ4fKfxhz8hHtvtfKxS9wm3LaW3fokaLi+HiMyf6OoJ99HCOkFs=; 20:sK9sB1xYCPi6m3FBhIizOk0REs3gTmSuQWKq70Ecb+ojOIIJrlEMwh5+acxZjaPfTbQuIJrG67HUBgHuuuglCe8inWnq1kSnPfNZ/n12u+aSgZ027wdJJfedKxmmYrb6WnC7iBKrdh1c8Hd7O5avFTR5LJeBUbG9PZWNLUaTgM3T6u4/BdmJ6UF0iiaACIWKeH+7PutbJpEVchRdL1BKesWZ9/7znuVYI+gJPHqZ0rTszpp8LNUaA4hVpbfsZe7VOyiVwN26DAUiSBKbxv2IBmYkVxc0WtuWL6efPNa57M8expP+yz5G7IaygAuKUkr97YQ7w5g/R217zZF20PIa+8KaBzZ83GLgGSzxxgBx25XIrsPkadYjOZQzgTDCD6gmz4xyBKZEnqm4Fj/dS3yBJjVZkt4AJl3f7tYqIE/ARHWWE95AsqNVxdcAji+3vEXtQYDmivei6GjHDmfjrazMfgni/5CxjoKyxJxhIZ6Qnfai/EyHsjpCJbfNGlkDPfPZ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(93003095)(10201501046)(3231254)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:DM6PR07MB4713; BCL:0; PCL:0; RULEID:; SRVR:DM6PR07MB4713; X-Microsoft-Exchange-Diagnostics: 1; DM6PR07MB4713; 4:+2EO86DAJIYUdIBdghpmZMFMQt2UbqtBAv7a4GNWEBka44E4UoXsQzFBeUAnbYaRcijLLU9AqmNdlOyDxdnd6kIpKyDfIH66zFt5HVdmYpcsq1RhxAQDPZjHfpJ1P4TRxQvUJTIT6rdUYtiuO+Sx8esun+8DzFuSaGHv66JuouXiAvcLocJFaS8cwRky5jFJAnluMjZ19SinA33kc5ZoAWak8GQQXyQazHJ4cqS2Yh1EXjDf2KEBpcyJz+u31d9x0PSGkTDlNmLwr1IhdBy+cXT9CgWGo02w/V6lhJ2ByswEQCbtssIMwte8hnEEMR89 X-Forefront-PRVS: 0714841678 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM6PR07MB4713; 23:iTlXSQ8BIUGvjwY7YFyYA6Oap6Yh1DaqegxbDiDQH?= =?us-ascii?Q?7kwhs03PILB98yRXnU4LP8zGBrW4tzs6NzGKf+Dgi4bQuS1oFauqB1KRoZXi?= =?us-ascii?Q?AB8WiPZUpGLdznC5rK8QW3Hg0N72zjl0pOjRpQH828QnuFUDhDVMJRX3lneN?= =?us-ascii?Q?votwZfSJmBQC8b/JAcG3ZQdLStOSc+ArSBKL5dFVrS6dpENlMcKBjHhbQS1B?= =?us-ascii?Q?ndxTQbKC5U6efe7iBGjix9ElgFll1IZ6CXVDx53OGd518A6dwNkpQFlSq9ja?= =?us-ascii?Q?3XxeH+7q3WVvH/iuvVk9oof6o6L9HiVAk8k9pbmrty/l7BXV7wlcfJUWn3Ju?= =?us-ascii?Q?ESLYKFfdT5rMDXKaFo6XOhQ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jJN3DfJZH4ubCiE+rhXa6xXom1MwmPjgtQWfMp72xVE/0YN6vtFV8zsI9VPQ1MdCxKxRv67To4vgrDVN5JzY0xFl73sGgQIbC2jPys8U4HcSr4Um4YEN7JtaPzhNqw=; 24:a0OOxzIO1odKUoEETIiPVQDVqD0bMfrBxCz6cQbchmWfyug0mGazu09SiH2FwIkycc1Y0HFUI2pU7ZT6DwD2tf5mjAAtskpgpuCP+OiVya4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM6PR07MB4713; 7:bhpzIVHlUhSraIJ4IstCHDDiCEMfVibNFUYR5azq46n8V/h551AYpqmBBRxBSr/GrdYWnjCnj7LfobyLi+vB9TpWeIuW+o7L0Kfw1hCnzmj/OzuP4onj5vFrddSqzOpMUuc9gjbkgM98qigjLZyOJpxYQ/4FVp9jg3v5XjGA84HT00l2wvZAZbRoT8vxEukeiBsoROiJbOwlTIbWeQULfzWc49pwX7RvHUZYeJ1Rdr0BLsRoNVBoKW41jeqMjBlC; 20:USe2bpDMOxbq0Jbuep0sB8bRi0O1SJMA07IuYWXMdyWcTfTEeZn4zoF3uMcLBKrB0g6Gc1xHYIXVpup82nfaU1esLXpD4rz2LKw0j02kX2mmZw8jydRyA8kIblK6ML8TA/FZ+NQGsTN6mX4DPh1WIelmPlJavp/F/hGXHRHQEmjEWRUG2h/5oYWO6/RHPlucxfTQUXvn67y4c6vgs3F3qW0C022A8xjjj8Kb8Td0ZsswT1F4wCCBPlOooX2AbSbD X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jun 2018 08:31:15.1149 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1475355a-0ef7-49f7-0d3f-08d5da76043d X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[199.43.4.28]; Helo=[rmmaillnx1.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB4713 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If PHYs are present, they will be initialized and enabled in driver probe Signed-off-by: Alan Douglas --- drivers/pci/controller/pcie-cadence-ep.c | 14 ++++- drivers/pci/controller/pcie-cadence-host.c | 15 +++++ drivers/pci/controller/pcie-cadence.c | 93 ++++++++++++++++++++++++++++ drivers/pci/controller/pcie-cadence.h | 7 ++ 4 files changed, 128 insertions(+), 1 deletions(-) diff --git a/drivers/pci/controller/pcie-cadence-ep.c b/drivers/pci/controller/pcie-cadence-ep.c index e3fe412..c02f33d 100644 --- a/drivers/pci/controller/pcie-cadence-ep.c +++ b/drivers/pci/controller/pcie-cadence-ep.c @@ -439,6 +439,7 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev) struct pci_epc *epc; struct resource *res; int ret; + int phy_count; ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); if (!ep) @@ -473,6 +474,12 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev) if (!ep->ob_addr) return -ENOMEM; + ret = cdns_pcie_init_phy(dev, pcie); + if (ret) { + dev_err(dev, "failed to init phy\n"); + return ret; + } + platform_set_drvdata(pdev, pcie); pm_runtime_enable(dev); ret = pm_runtime_get_sync(dev); if (ret < 0) { @@ -521,6 +528,10 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev) err_get_sync: pm_runtime_disable(dev); + cdns_pcie_disable_phy(pcie); + phy_count = pcie->phy_count; + while (phy_count--) + device_link_del(pcie->link[phy_count]); return ret; } @@ -528,6 +539,7 @@ static int cdns_pcie_ep_probe(struct platform_device *pdev) static void cdns_pcie_ep_shutdown(struct platform_device *pdev) { struct device *dev = &pdev->dev; + struct cdns_pcie *pcie = dev_get_drvdata(dev); int ret; ret = pm_runtime_put_sync(dev); @@ -536,7 +548,7 @@ static void cdns_pcie_ep_shutdown(struct platform_device *pdev) pm_runtime_disable(dev); - /* The PCIe controller can't be disabled. */ + cdns_pcie_disable_phy(pcie); } static struct platform_driver cdns_pcie_ep_driver = { diff --git a/drivers/pci/controller/pcie-cadence-host.c b/drivers/pci/controller/pcie-cadence-host.c index a4ebbd3..36f3109 100644 --- a/drivers/pci/controller/pcie-cadence-host.c +++ b/drivers/pci/controller/pcie-cadence-host.c @@ -58,6 +58,9 @@ struct cdns_pcie_rc { return pcie->reg_base + (where & 0xfff); } + /* Check that the link is up */ + if (!(cdns_pcie_readl(pcie, CDNS_PCIE_LM_BASE) & 0x1)) + return NULL; /* Update Output registers for AXI region 0. */ addr0 = CDNS_PCIE_AT_OB_REGION_PCI_ADDR0_NBITS(12) | @@ -239,6 +242,7 @@ static int cdns_pcie_host_probe(struct platform_device *pdev) struct cdns_pcie *pcie; struct resource *res; int ret; + int phy_count; bridge = devm_pci_alloc_host_bridge(dev, sizeof(*rc)); if (!bridge) @@ -290,6 +294,13 @@ static int cdns_pcie_host_probe(struct platform_device *pdev) } pcie->mem_res = res; + ret = cdns_pcie_init_phy(dev, pcie); + if (ret) { + dev_err(dev, "failed to init phy\n"); + return ret; + } + platform_set_drvdata(pdev, pcie); + pm_runtime_enable(dev); ret = pm_runtime_get_sync(dev); if (ret < 0) { @@ -322,6 +333,10 @@ static int cdns_pcie_host_probe(struct platform_device *pdev) err_get_sync: pm_runtime_disable(dev); + cdns_pcie_disable_phy(pcie); + phy_count = pcie->phy_count; + while (phy_count--) + device_link_del(pcie->link[phy_count]); return ret; } diff --git a/drivers/pci/controller/pcie-cadence.c b/drivers/pci/controller/pcie-cadence.c index 138d113..2edc126 100644 --- a/drivers/pci/controller/pcie-cadence.c +++ b/drivers/pci/controller/pcie-cadence.c @@ -124,3 +124,96 @@ void cdns_pcie_reset_outbound_region(struct cdns_pcie *pcie, u32 r) cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR0(r), 0); cdns_pcie_writel(pcie, CDNS_PCIE_AT_OB_REGION_CPU_ADDR1(r), 0); } + +void cdns_pcie_disable_phy(struct cdns_pcie *pcie) +{ + int i = pcie->phy_count; + + while (i--) { + phy_power_off(pcie->phy[i]); + phy_exit(pcie->phy[i]); + } +} + +int cdns_pcie_enable_phy(struct cdns_pcie *pcie) +{ + int ret; + int i; + + for (i = 0; i < pcie->phy_count; i++) { + ret = phy_init(pcie->phy[i]); + if (ret < 0) + goto err_phy; + + ret = phy_power_on(pcie->phy[i]); + if (ret < 0) { + phy_exit(pcie->phy[i]); + goto err_phy; + } + } + + return 0; + +err_phy: + while (--i >= 0) { + phy_power_off(pcie->phy[i]); + phy_exit(pcie->phy[i]); + } + + return ret; +} + +int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie) +{ + struct device_node *np = dev->of_node; + int phy_count; + struct phy **phy; + struct device_link **link; + int i; + int ret; + const char *name; + + phy_count = of_property_count_strings(np, "phy-names"); + if (phy_count < 1) { + dev_err(dev, "no phy-names. PHY will not be initialized\n"); + pcie->phy_count = 0; + return 0; + } + + phy = devm_kzalloc(dev, sizeof(*phy) * phy_count, GFP_KERNEL); + if (!phy) + return -ENOMEM; + + link = devm_kzalloc(dev, sizeof(*link) * phy_count, GFP_KERNEL); + if (!link) + return -ENOMEM; + + for (i = 0; i < phy_count; i++) { + of_property_read_string_index(np, "phy-names", i, &name); + phy[i] = devm_phy_optional_get(dev, name); + if (IS_ERR(phy)) + return PTR_ERR(phy); + + link[i] = device_link_add(dev, &phy[i]->dev, DL_FLAG_STATELESS); + if (!link[i]) { + ret = -EINVAL; + goto err_link; + } + } + + pcie->phy_count = phy_count; + pcie->phy = phy; + pcie->link = link; + + ret = cdns_pcie_enable_phy(pcie); + if (ret) + goto err_link; + + return 0; + +err_link: + while (--i >= 0) + device_link_del(link[i]); + + return ret; +} diff --git a/drivers/pci/controller/pcie-cadence.h b/drivers/pci/controller/pcie-cadence.h index ed336cc..b342c80 100644 --- a/drivers/pci/controller/pcie-cadence.h +++ b/drivers/pci/controller/pcie-cadence.h @@ -8,6 +8,7 @@ #include #include +#include /* * Local Management Registers @@ -229,6 +230,9 @@ struct cdns_pcie { struct resource *mem_res; bool is_rc; u8 bus; + int phy_count; + struct phy **phy; + struct device_link **link; }; /* Register access */ @@ -307,5 +311,8 @@ void cdns_pcie_set_outbound_region_for_normal_msg(struct cdns_pcie *pcie, u8 fn, u32 r, u64 cpu_addr); void cdns_pcie_reset_outbound_region(struct cdns_pcie *pcie, u32 r); +void cdns_pcie_disable_phy(struct cdns_pcie *pcie); +int cdns_pcie_enable_phy(struct cdns_pcie *pcie); +int cdns_pcie_init_phy(struct device *dev, struct cdns_pcie *pcie); #endif /* _PCIE_CADENCE_H */