From patchwork Tue May 22 13:27:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Douglas X-Patchwork-Id: 10418661 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 C1EEE6032A for ; Tue, 22 May 2018 13:27:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B219528CE6 for ; Tue, 22 May 2018 13:27:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6EA628CF7; Tue, 22 May 2018 13:27:27 +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 CD13F28CE6 for ; Tue, 22 May 2018 13:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751308AbeEVN1Z (ORCPT ); Tue, 22 May 2018 09:27:25 -0400 Received: from mail-sn1nam02on0049.outbound.protection.outlook.com ([104.47.36.49]:22770 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751214AbeEVN1X (ORCPT ); Tue, 22 May 2018 09:27:23 -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=IRwufZp4om0wHduw7NVTpKIFWyPEuzAK4gC2W0YldI8=; b=PM8eow/ZdOImregfxBurjxe6AkXYQo+9svAjWjsbiefFhs7XtPCyjKYTPE/4mMe4aH2pnpgdLKHbe/uW/CP46VnPSe/2ChgbZXO4NwH7ortyq4JRxFESB5sUEIS0IjftXjbVsvncIreGcJMuAZdGQbU4FrEnLQgNoGkJ5jdDZ3s= Received: from SN4PR0701CA0005.namprd07.prod.outlook.com (2603:10b6:803:28::15) by BN3PR0701MB1186.namprd07.prod.outlook.com (2a01:111:e400:4010::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.776.11; Tue, 22 May 2018 13:27:19 +0000 Received: from BY2NAM05FT027.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e52::201) by SN4PR0701CA0005.outlook.office365.com (2603:10b6:803:28::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.776.11 via Frontend Transport; Tue, 22 May 2018 13:27:19 +0000 Authentication-Results: spf=temperror (sender IP is 158.140.1.28) smtp.mailfrom=cadence.com; arm.com; dkim=none (message not signed) header.d=none; arm.com; dmarc=temperror action=none header.from=cadence.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of cadence.com: DNS Timeout) Received: from sjmaillnx1.cadence.com (158.140.1.28) by BY2NAM05FT027.mail.protection.outlook.com (10.152.100.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.797.3 via Frontend Transport; Tue, 22 May 2018 13:27:15 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx1.cadence.com (8.14.4/8.14.4) with ESMTP id w4MDRB8O020141 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 22 May 2018 06:27:13 -0700 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; Tue, 22 May 2018 15:27:20 +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; Tue, 22 May 2018 15:27:20 +0200 Received: from lvloginb.cadence.com (localhost [127.0.0.1]) by lvloginb.cadence.com (8.14.4/8.14.4) with ESMTP id w4MDRA8A009509; Tue, 22 May 2018 14:27:10 +0100 Received: (from adouglas@localhost) by lvloginb.cadence.com (8.14.4/8.14.4/Submit) id w4MDR9qJ009494; Tue, 22 May 2018 14:27:09 +0100 From: Alan Douglas To: , , , CC: , , , Alan Douglas Subject: [RESEND PATCH 2/4] PCI: cadence: Add generic PHY support to host and EP drivers Date: Tue, 22 May 2018 14:27:06 +0100 Message-ID: <1526995626-9333-1-git-send-email-adouglas@cadence.com> X-Mailer: git-send-email 2.2.2 MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28; IPV:CAL; SCL:-1; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(346002)(376002)(39860400002)(39380400002)(396003)(2980300002)(3190300001)(199004)(189003)(36092001)(6666003)(2906002)(51416003)(246002)(50226002)(356003)(4326008)(186003)(8676002)(7636002)(8936002)(5660300001)(86362001)(63370400001)(63350400001)(126002)(305945005)(486006)(426003)(2616005)(2201001)(476003)(47776003)(110136005)(478600001)(16586007)(316002)(26826003)(42186006)(48376002)(106466001)(54906003)(36756003)(26005)(59450400001)(107886003)(105596002)(336012)(87636003)(50466002)(41533002)(217873001)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR0701MB1186; H:sjmaillnx1.cadence.com; FPR:; SPF:TempError; LANG:en; PTR:corp.cadence.com; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: 1; BY2NAM05FT027; 1:h09cumLkB+7b5s/q8bF6JBk651TRwkY+n/UKlVOQ71YZd2l33ESSKLGT82t9AYUOajY0TuK99M+rfq5NEArfTA0au7icdfCtZafJVtXXOetqcQK43IOTwn6xBS1DCIBw X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060); SRVR:BN3PR0701MB1186; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1186; 3:NFpFtMh1zLOgYrCWvguEaOcodkhw4gEdtvaW0vFmoWLcn7QSKr/Lzb/fPbeXm719HtkjT+YNlI/8jV465j516pQiMDUDLF0XJ4Ay+2Ktj3E31MqdgrhXM2MvNVb8Hd1Z/Utu79dOqkRbZTvu0cYHOyegbLbElDOs1ik4peDxqiYe9amXemNsq1AUTfbxaW8zKMW/gR4VaEn4/y+WuCHy1qX5hPPciCr2u17qZ6NiERAKZy7W6JacFLDv35DUMPusyFFJD/hYVt/Cm25cKNfhrOpSFq4BUKQMl/gy3hQrdbEvSiDJMLBoOZXXOfWZNbocvYDpCjQQZ26rdG9M+1S64ryTw+WX8UiojLh8AuNlpT0=; 25:6b+itop55xTXFRDM4qWvhki6AwS/nxJfyD9GL8ISMGcEuf7/4gO9sulxC75ToATvP09zsSIeLByzRwV+9TfDlytV4qRpSwkewYSkSSrLg/KN/G6Iqs+sGwxPgzwqljwJDvDZrLRc765NPttIGbH1nqzDfOcEPvrzMzsYQpKW4tvNRl8RyzZuvanHOv183KYHtWRy1im+yYTcobWMLIvmvw+CLrrE/d6ZcQZdyKTMekTTytkAQGWLXLqGPK1YIr/qH2eiFUL19qvyotquEZW0Sw3XwwWtp77FHyMH3mv4NmWYmDzeu8Evxd+Abc1TLpRbGenKIC/9E84ZSdyXldOD0A== X-MS-TrafficTypeDiagnostic: BN3PR0701MB1186: X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1186; 31:eK3hg2ve+74AOUARgdweippcIUgRoL+MbF/LB1dyPZoRZAGECmAY4GrCrGn/ECIWywviLqgbE36/c5HeFovfkxOSvDb+Q+OX3G+eykJm/ssxD+BcFZr2i45VoCqIOVh1nZflSpvAClXUSMQxG9/GQvkL5KR3sr9RpH3A1tYwYeBg7OFfRkFzd8IjcIa8QEbhoHdptNi5wkS91kXnbNafLpVcV/9Mzkchy7SjOWU8OV0=; 20:jVHLas93YMwTQH5bLuXqTmoos3RXU02D6CeuPCCghr/rLEzEHRV+8bCDLomB1tZIwi4MK5BbzEY5oyXkiqoKF7BW1SRsD3YQbn8j1VgUsQhm3GCXEDzAH5cVXBC2vbZlKJXNBCNXxOsUOO5gWkABuKC3GlzH5424KFqd1C4REOaFCbGR40yuwfGz0u6fGEfP5wgZO6zBG1krpIP8LXT55aI5BcaHMDiPcIe5qIl0FOKHrdPh0FGnfyI+u2qSaafKkK3e94ERcm+Nusrzjt5V5AgV05U+caTMulpGxEHLAdNjb7jEvtLP8vV6bVkAIBtbOSudNmwXmGYC5pSUVyiqZXd3AXAE03TKyNap9NOHA6T1D3Zqf+78eLTUzqo0ta25/cA9WSxBpmF/yxIHpqTOcEXK+Pulg+kbj6buOblUGa3QA20Jr+xoSwNEQcsJVfssXuOes8F9o2bDGWw/bLPTxxbVlW3GrS5qJ1iHFXlvzpAVrQkDV3IxzEFM+x0MHo3i 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)(5005006)(8121501046)(3231254)(944501410)(52105095)(3002001)(10201501046)(93006095)(93003095)(149027)(150027)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:BN3PR0701MB1186; BCL:0; PCL:0; RULEID:; SRVR:BN3PR0701MB1186; X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1186; 4:Z6hjwch7hvXUARJCQqUjULsQcxQgR2V9MoiVdT0TfljuiFsH21NCkY7FpOcuuZp7ycNKsGEr8paUfh0oa6CQ6En47e2b4wEpNtQg6iUUkY4lmtjKm/bYnzXQl7Onl5kix/gsjUFArCp0rPXDHEP9JYUZbipzSBLe2VGnfb6gDHhP9Vwrej//RAOJ+P75/TBFeoMg9ZogQMZIr14aWcqPhtNsCmBAxcMpR541Y9UIzQOri9snTFPLoAnUJyDehX1Avslsno5bIEOTRbhqpg0NKZzdYAskam6tYTnamLOsT9KNOOfd9fcC6fem3ZN3xK8G X-Forefront-PRVS: 0680FADD48 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR0701MB1186; 23:+ptkmWyX3MhY9FjTPqvkiekxG2BFvLQ+XMhZ/3t?= =?us-ascii?Q?mgGop0YOsj8W5DUFeLRKXApNNL0kDehqYWYoPSU0Pp0bCioIl/Cd1mA0TmqX?= =?us-ascii?Q?kOfRX0qT5/wY6W4feMbaxxVmnsTaPBlmN/E/jqxD6bX/Uu6q21RwOzCyciN8?= =?us-ascii?Q?SEw8znFORRmOGjk3SzhXeEMMsRT1qXbrR9H8QW/RA5eZrw7g2/WLTGlBo/7J?= =?us-ascii?Q?7xAIgntvWHDuNaRwtx+nE2fkT6PlQTqyfGUGdnLOFdT5vEyt/R7lzYzY+Qlh?= =?us-ascii?Q?ujonk6u7JVXXrVnBWaU+aFtri25uk301VbRx4Zjmej66g6G0eyP6EuGiw5l0?= =?us-ascii?Q?wRvW8Z1GUuYi6rjLL21K/26eQspo2TTT5TunLEn0BqrOMsFV+0y6eXYNcb/+?= =?us-ascii?Q?Q//sX9dZskvqOJHkCz+ObhFmO454271+c2TkSqNPYnIlh88NOCGz7E6Ra7SI?= =?us-ascii?Q?lGbcD++lso8lsUFxDM4Z1chV4sqKEHEbnb57yQE/AqXV6FNzqsjdnBx+/AEK?= =?us-ascii?Q?xp63X3lH+7UAdxjYpDpQygC+w93kMQYgvug133Bb7RcunSa22amVzXgBcWV8?= =?us-ascii?Q?q5dWpu4RfAZ8EYsmtaO/7aKyadl7yy8lrSZOB33KldH+q8P9IZR9xWHA5YZR?= =?us-ascii?Q?X9zJ2XnJ3lGq+gQdJkIxDL+cyVNM0zwM2oHB49TOHpRPx8uGDJJ/wuUgxglt?= =?us-ascii?Q?4KDeH2jYvsgWId9Y7aNLvBRGdpQW9NofrmVNdwBVMOs1g5iI0VA5r0IHrtL4?= =?us-ascii?Q?WZHp0cLlSdyODJVRQthBYWQzHAtaLHnnXcEmdJx3slpWO8+GVbfgeyMnYQlP?= =?us-ascii?Q?5bDyx4qjwgaf4YSHk9rDs36ZBmyjtpbipUCYo6NCRCH2Fj1LWknOC90XKGGd?= =?us-ascii?Q?GVB3ZyKgilFevuv1QOO12AU9qVbbr2BsTYC/b6adiIgSHRT9Zpx6L0DK/x5B?= =?us-ascii?Q?dyr784dBlGHmio582NpSVU5baKc4FUzR1x5OihTV1rbz6MmeB/6gOh1eTObe?= =?us-ascii?Q?FkF3y3w28liAMmFM/kvdM/G59bS6j9G+SpTShE+3Nu81tuDo7XRLR1Hrv90z?= =?us-ascii?Q?k9BWwZQVfGzQhequSzMWiOlhgBTMdfKjtguKWZ9cwL0EwvimcNP2Fj+bAyG2?= =?us-ascii?Q?Zi/77E6rMG10/3iifJqhT2+TN6zrMKTt/miV9aWOfKGJuXzSJZ7vs3DFCkjw?= =?us-ascii?Q?VEM4KRJ1xrnOQHM5jgfhLVHcTHQYmv9oigJEj?= X-Microsoft-Antispam-Message-Info: TgavQjEgfujIzRWwYnXsAwora5c0On/Ny9iVmZxelz/ETCJn/j+snMzPsELM4AZhnrWCMjHEy9tdpHJgYNRMV5kq/VVueIofTFGCbJMeukDG/dur/GLNCVddvfiyqjjRVWOiVcUygBOVk0UmO4Sg8IHoIwk3XAx+YMyEF3dlw4RdICQ+UK00BVwCoG16aevIySt3ayS/MrCCO9fhFXmMcQAd7GUDUoQD2FCUwo0j2lRJqleH0HCZNvYkBrPzhUVc X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1186; 6:GkkKNKpb6utpC2AqPbctcw/08okWSqaPfYcw08t4Rkl5RSnw4gTtG1h09zBCNTBzqMa9B37gwoFZ4hHdUt5tdgFxctFAxI2Cm5Xfc1BDRZIq5hTD+ywFRUxUpIs1cDVaQRSnXiI/MnmNGrevZ4ckwV2TuMtIfumo7IS3L4YUwNlpRmzbrLmifpQCql8e5EdxjmI4tioFdcHm1TLwxCvr41MUUJBin4L22ueq1ZsSeJWOuY15pWQdLQpL0DGJldWPe97ASSjbTuJUV8rlvQazS194CIOwBnh2iwJq8kEHXofxUtKSb+khnKFCVLhftHKmr8EAh6A3LlnEMW8CgYFRHEYPb0yP8BBxLsuNa0STiOGnc13qUFQf70tttUEuhGa9DHDec1uAJL5cD+RhQG5+ozCYC1oqgF+pZqCag2K+THCydFM/701HtEsdb6K4yX33r7+GksX7ISa+/83w+/w79Q==; 5:kNpjjVf3kwXHt2JY63mmOPgedwTKoGlQSzpaDFi9O7nhKbV67pr2J8Tyn9zAvLqVfwyCl7ettbSjjwQYLsryBpkYjY3/oAC1UABXlKlhiu16nhQhIqMArnpvIRCV3+G33uPI6e+DUdEjQ/uShpdTp2nZH+JqkvalW6j+f5PQah4=; 24:TwBOaD09/NsStIu2tpZpNWFfXeyL982dMSABJO9ftF5MZd039i5Fi2wt+stcLrl//6k5WqQxifHZtDtYp/axJE/j14a/Diw7XOaTSX+AMzM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN3PR0701MB1186; 7:SNFQ9V04WWvcWFQn/79aKkxgBt5XakRFcDKcEAjKecPD109c6cfqq1ArzNLmu3kdZQr0GMRVuA9gGe/pvWDwQUPRj56ruGBwZme4/+4DtoS1gteqLlU7VHzSyxNhbaCq1amH9uaHlItb5bZeoRWd5BMKCa3mXaURj6e+WxK7Kr0WsG1G1hNT1yYL0DcF60yqRE3ZaWqkEqYZMuMSeqKLRpeUO+l60+UcVKnXVg9ISulMbuP/y3ccWiMZ6GSqpFG2; 20:ByoRRgfSni6UPor43BumWaYuQZZcQIDTeYwsRZA2pXVPjIN6P1O6Yb6qz2tHoCEu040WNGwhd2fr950DaSAmx5QYaJWXOzFBFOVNj71tsMmJNGZqEyUCs3DzpxyynKDwem+nLmtOlem3XSXS1kpqvCrEAbMgL0WC+F2mmq2crRMkDzEald5aUqGB1X9HLdUct30TSItEtSJwEoSQFTydL2usN9d5TS2lq6m1djAV+9srNzA04yUXl8DZQzPPyddh X-MS-Office365-Filtering-Correlation-Id: a0da2b81-7ba0-42a8-1fb6-08d5bfe7bd6f X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2018 13:27:15.4163 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0da2b81-7ba0-42a8-1fb6-08d5bfe7bd6f X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[158.140.1.28]; Helo=[sjmaillnx1.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR0701MB1186 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, and disabled in driver shutdown. Signed-off-by: Alan Douglas --- drivers/pci/cadence/pcie-cadence-ep.c | 14 ++++- drivers/pci/cadence/pcie-cadence-host.c | 31 +++++++++++ drivers/pci/cadence/pcie-cadence.c | 93 +++++++++++++++++++++++++++++++++ drivers/pci/cadence/pcie-cadence.h | 7 +++ 4 files changed, 144 insertions(+), 1 deletion(-) diff --git a/drivers/pci/cadence/pcie-cadence-ep.c b/drivers/pci/cadence/pcie-cadence-ep.c index 3d8283e..2581caf 100644 --- a/drivers/pci/cadence/pcie-cadence-ep.c +++ b/drivers/pci/cadence/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) @@ -472,6 +473,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) { @@ -520,6 +527,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; } @@ -527,6 +538,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); @@ -535,7 +547,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/cadence/pcie-cadence-host.c b/drivers/pci/cadence/pcie-cadence-host.c index a4ebbd3..7536926a 100644 --- a/drivers/pci/cadence/pcie-cadence-host.c +++ b/drivers/pci/cadence/pcie-cadence-host.c @@ -58,6 +58,9 @@ static void __iomem *cdns_pci_map_bus(struct pci_bus *bus, unsigned int devfn, 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,15 +333,35 @@ 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; } +static void cdns_pcie_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); + if (ret < 0) + dev_dbg(dev, "pm_runtime_put_sync failed\n"); + + pm_runtime_disable(dev); + cdns_pcie_disable_phy(pcie); +} + + static struct platform_driver cdns_pcie_host_driver = { .driver = { .name = "cdns-pcie-host", .of_match_table = cdns_pcie_host_of_match, }, .probe = cdns_pcie_host_probe, + .shutdown = cdns_pcie_shutdown, }; builtin_platform_driver(cdns_pcie_host_driver); diff --git a/drivers/pci/cadence/pcie-cadence.c b/drivers/pci/cadence/pcie-cadence.c index 138d113..681609a 100644 --- a/drivers/pci/cadence/pcie-cadence.c +++ b/drivers/pci/cadence/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_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/cadence/pcie-cadence.h b/drivers/pci/cadence/pcie-cadence.h index ed336cc..b342c80 100644 --- a/drivers/pci/cadence/pcie-cadence.h +++ b/drivers/pci/cadence/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 */