From patchwork Mon Jul 31 19:40:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 128863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2252800vqg; Mon, 31 Jul 2023 13:36:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlHm0K83rsBghebIalU+cNIJTGmMPz4caXTr8vd9fXlmsel5OvqXpGu46E4DV4D8+z3Kv5FI X-Received: by 2002:a17:907:7846:b0:99b:dea3:8d44 with SMTP id lb6-20020a170907784600b0099bdea38d44mr625833ejc.71.1690835796717; Mon, 31 Jul 2023 13:36:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690835796; cv=pass; d=google.com; s=arc-20160816; b=LKe/VmxmNt3TlaaqDPotvMBTJ/43HyZ1RXUGdRgCA1nISmU3qBC9qUzuBvA0pRBJ5p grFu1O2lU1107cpJby4ssRWKEQvqYIenn41OJMceyWEj00ZcQkBzSs8ZcyM6ugRvRl9V x6kE8nbGrYqGcGoBMImUpHCGCi+YiEynyf3oWMbr/5yG6tRFUfrq8wyjQnPrhLEcRphY 27hwuW/lj50NdqNSsXoXqekBkgCV/lx1ue2loQnpUV3h1wUQKoh6D81/4DHGgoSSFBtl pJ/eTBUJXAbTaAQtQAyRQIlrXJtAkqqLVKP0/6c2CBTh1hFRh6UmUENIYJT3bH2jy8qL D71A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=zz2r2hHL2LC3oYTGVkmkscPRMOeUXOrgP8c3nTPXCCc=; fh=J5oSUDXEPwknT4mz7Zo+di4xln/YaOK/kgRn6VOhtBk=; b=KvxmfZhwiOhkIxpOH0jzcSDE8f/GK+gHq3MsCq819STMzRxirMw8Q6FUYV2rlmPvPp RYzFrK13v92wygoA3JZBSy8zKLVRGK/knESE4QNXunBV/6RQNSiIIw33U/1UB8XtVF4r oCq5EV7NZ3bTMe5zUnKlVm0wpze2Ta5WLvQ5gyO9UpLmZjLWopQg6MxPqT20kjZBledX VF/LZAG2JuQNjPTZHCKgTm4PggP9EvGXKjdPj4jfHzN91f11l4vFf2HPSbSyRbUV1KHP RitL+/I1fCxTD105XcKjrVq6lS54E9y5BnpYxZ8nzM8i3YJg/3X43KmDIx0ybaYB0gGm TtnQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=NXIMejZg; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gl23-20020a170906e0d700b0098aa2c42095si4049348ejb.196.2023.07.31.13.36.12; Mon, 31 Jul 2023 13:36:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=NXIMejZg; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230493AbjGaTkj (ORCPT + 99 others); Mon, 31 Jul 2023 15:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230420AbjGaTkf (ORCPT ); Mon, 31 Jul 2023 15:40:35 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2062.outbound.protection.outlook.com [40.107.22.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CB2619A2; Mon, 31 Jul 2023 12:40:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FcR+yyLe4Ro/rkHiqszukrQx7XU3c3YSKOI9aw48dOt1apG2KsEllspr/ibflmd1ASIm6ncbGkgdWHxV0MAEBF7SqUGw3qvxC0bMTOiuAbjr73Bk9/MMgmGLY0BMRV4DxfdVitWPQt6UkQciqf/Fh+JTzx3cAZ79fjpWJwfoMEraI19g6LqoltzjrxG+IEVGpv3/JdLgT05/RrnptRmYQ2oUbOW869hr2A29xqtTLNNSRTOKCs8OjYC45jOjBaI9Yv6sSHuU7hC2lIDiJV4FqjMstfGZOgx996DXiOSJsEk34S8j7wy3WFbEtozy9qCLKf1xMu4hmQxBSmHtmR01xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zz2r2hHL2LC3oYTGVkmkscPRMOeUXOrgP8c3nTPXCCc=; b=oFhs6eDmJrEzq6fwRLUG5SkPW7ltCSQQUQ/RZ7oFXKMO0qCCZv4rzUctrPNuUdS4qkYMRFSelxiia7VWfpatZuHatb6Fx1AGwEYUxTxUUQb1nFSJA9xhnxU/IvZ6+l+r7FH2gRD9rUveuKYLRZuZFNYYaG79Iz0153wRgw9LTpTO6LQZqEWrn0fxpUSs4Q31dRKkyB5iPeD3EznfgRKHjc/2w/goAXbHaSEM2fmyVPuEKfb5VaaxtbAEfG2CaJsCIWK55elAfNXCwafxaGl5M48U747+NhByIZfbDrKV7SWVyLQuKz04f3+jjGSOF70yl1ewvRGYncGeE+ulEJSXwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zz2r2hHL2LC3oYTGVkmkscPRMOeUXOrgP8c3nTPXCCc=; b=NXIMejZg+AhXI95cC6Qz0tqmT9W1nOTmoASE8MMJGIZyBuUEZRZU87KczElcJKFCAGQQ+0doQBlG8frqFButG56p49uRjZaTLkRFz0bwgIbhyDbDTTvtspLTLt29+7K8O+Ha7kheDsyzI8AhtAXYKOqy/AYWTvTUiSTgVnfwvUY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by AS8PR04MB8344.eurprd04.prod.outlook.com (2603:10a6:20b:3b3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 19:40:31 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::d0d5:3604:98da:20b1]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::d0d5:3604:98da:20b1%7]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 19:40:30 +0000 From: Frank Li To: lpieralisi@kernel.org Cc: Frank.Li@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, gustavo.pimentel@synopsys.com, helgaas@kernel.org, imx@lists.linux.dev, kw@linux.com, leoyang.li@nxp.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, mani@kernel.org, manivannan.sadhasivam@linaro.org, minghuan.lian@nxp.com, mingkai.hu@nxp.com, robh+dt@kernel.org, roy.zang@nxp.com, shawnguo@kernel.org, zhiqiang.hou@nxp.com Subject: [PATCH v6 1/2] PCI: dwc: Implement general suspend/resume functionality for L2/L3 transitions Date: Mon, 31 Jul 2023 15:40:09 -0400 Message-Id: <20230731194010.73016-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: BYAPR05CA0018.namprd05.prod.outlook.com (2603:10b6:a03:c0::31) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8344:EE_ X-MS-Office365-Filtering-Correlation-Id: 596d22e9-bdcb-4150-3f66-08db91fdffbf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +XrQUGqgQB+meaNd3uY9JTd54XHVebTQx/9HbJALMbCEUhSNmSv7AvUcRr1+s47GlevU2ZPHlwCQYVWgQchU9viDM8wjoou901A/VH9wDBvJQBklA6FMOe1JumDBbRLLhzpyAvKeFg5Y4kajPAIfzJHNinsXJirSLQ1fsRx9I4J9AMSsNDiLIHPj/mi1xlL33JdIw8GZZOYrY0H6CRWXjp3s9G/IKK7NEnmY/Peyn8QB6O83iJaibPqwHZKZAC3WIPaFui+3vOSH0r28HIBILYmVEuAF1RjUieTn6PRn5TF9j7Q5Y+58XmfnvwZsgGhKF0L+/decW/IEOiXkHdTEjURfYPUJk5S+nC1c/lxWxdBdlUGDJ9+v+cU/kgHoZOcY9jr7vPnp81vFQUOm52/HpOCX1egmiSkdJOYhLZnkg0kQeOBHRqy95yNHB7eqwhpwVoByGLaQh+MkEWDmHhqlnnCcfnfIwx9LzfQj1+LDO53JIFrPWvkUpNXECyEyBZv0WrZ/4Guhh+hJBpVLOu/SysgMuXYvh9xi7I8FWIZogTSkbqQwjo3yrHElS+ITPsgnSK/NHvOQI/nu8YhEtpZBcuuSaMq5RX3OdL+zLlTD8Wc= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(346002)(39860400002)(366004)(136003)(451199021)(38100700002)(66476007)(86362001)(8676002)(8936002)(5660300002)(316002)(4326008)(6916009)(7416002)(41300700001)(66556008)(66946007)(38350700002)(15650500001)(478600001)(2906002)(6666004)(36756003)(966005)(6512007)(52116002)(6486002)(6506007)(26005)(1076003)(83380400001)(186003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wfRicOr6DypTVC5uTaPnuuKobhCbi3bNNVQsiBs2c2ZHJsxi08I+MIA1OrkuBvx/pTy9gZvWlMJeRKqn6KH5lSLsLRsf6KCDavEN8kzooeFaqzv//t4ZUKHPucAulJA6//wMETowPgfYcEE2LAO3jtquINVxBu/jmgIto5nHn1l1tvF+B/9oynvI9eGKPfkx3/aloLPaKdoJ0Z+FiMIwk3qS0ESnEyF2xFtXHJK5Y6K5nhB9yHTlbtHD4lqGOO9mj+1IDNYwQY8Yqbqx/ZQgHSeZ/FufKUb5+xBSkGmi+CDlac/w2PHKlmaqvcFp0jsaPhbwWsR1pnXJC+nnnvYqa9AY6xs05TXR+LUplf9BJHqTbvy/gj5KXUA9IahZMosmsVX19H1LOStTuM1Uomtt9NguXP9ZWclxij+TQkmnU2wmNctsFRo2kKt9mPUaBMK6vR69L5SblVVvQW1cORc+sqbLLssAog66MnfN9TPVnxhXII6K6UraW2CaBrbUuO8gIGGGZqjPrZY52wBIc6R8okGtGt6mFnmwcbcR5VsAO17U6Cyc7WwdwfuqTC0RDI71pFKWJfv3umzREXcaC/rsaRd3b07cWuYAvU9BUHanf7C6VIqJCpAOYaQwghYnowOlbvuxyuuveajLoUCBI9PwX8qJuEgWtCPXbKtY/vgO7B3QUp8GFe+zvIzvbxyshlMOg1JMkhZWrAobPQaQ5Y7ktjsK1jeftOpJ2kCjKAxL7ua5IzwmM9TrJlIzHZXOz/pzuQ8fiqPrHY68aStYq2xEbmWVMyxYsGwcLsS4m95+WZ7IaJNUl8tP1TdwoKAXIxVRrK0hI4GuGpGmJAiHZ+/6JZCjJF9o6VRa4TjXQo6BIjhwyYxajBmQW71zc/Dcsoy9/k1pvgAw9zO4j8d8GESeRG+yxsO3/KFb2yivqtQvdzqalnZowSt6EfN1PGcMb/Gp7/iBS/DPjh38lN2coIbJhVwWOKo1Ywqk2sbQK+2LFmNfrcX31iFP1tLO0z6RLUMAV47Hh22GhGdTyHQmgPy2ZkKeH6XKDUEm/gRkHqMf1V0vocTdRTtFD10Ep+4bzCmN/Nl1ii29I8tK1HsqA6Js7mJN0CSqyfOf0tiH+ateaupiezpGnvyBMQuReBfAhWZ4UghhHIC2zvBOQHMXVs7C4Kxgob23MjXRJCsuBhcpvbiOXAIRkN8Qo6+nidTHJwZVAB0v3bp25xFMCCQxuAdrg/nEVw9HlBxFZXWadX93RnIG1mQ9x5e0mIlBSVivguaV0L7uK2SBMR2wgxuUpWgfZ5lSJKTf29LjZZObIYxzrZTmoZi4CF/ieTmdSqPerqVv3jRMwDbG9ER7reEtdovjKsgeJNWa4mP19gqDoj2O3nK2+nFvVXIekRUYkgZqW34OMgeTBbQm5x0SgA20z0pNbEFhcdkgzMd+MfleU5xUO5kVMfRLewWGip3f/WpUuvJZjIYC/fljPeUki+j9YYZZuG3RKL1K5AUwglU/fgzM3wLLl9+ijYjIBtA+lM4wHwYWKXi7wnDacBx4Jbl/N8Pi6yrs12acWEWPiJUr4M7UgYg= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 596d22e9-bdcb-4150-3f66-08db91fdffbf X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 19:40:30.8404 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: s1bXnxrkBCffl31D3gbyf9KAFviFnQBVJeHGTuWLmCynRDUTWKmxZRp3IDJKp+GwGWCo3qmbnyNxJ88kbKCeDw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8344 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772969836429943994 X-GMAIL-MSGID: 1772969836429943994 Introduce helper function dw_pcie_get_ltssm to retrieve SMLH_LTSS_STATE. Add callback .pme_turn_off and .exit_from_l2 for platform specific PME handle. Add common dw_pcie_suspend(resume)_noirq() API to avoid duplicated code in dwc pci host controller platform driver. Typical L2 entry workflow/dw_pcie_suspend_noirq() 1. Transmit PME turn off signal to PCI devices and wait for PME_To_Ack. 2. Await link entering L2_IDLE state. Typical L2 exit workflow/dw_pcie_resume_noirq() 1. Issue exit from L2 command. 2. Reinitialize PCI host. 3. Wait for link to become active. Signed-off-by: Frank Li --- Change from v5 to v6: - refine commit message change according to Manivannan's comments. - remove reduncate step dw_pcie_set_dstate() - return 0 when .pme_turn_off is zero - call host_deinit() in suspend - check .host_deinit and .host_init point before call. Change from v4 to v5: - Closes: https://lore.kernel.org/oe-kbuild-all/202307211904.zExw4Q8H-lkp@intel.com/ Change from v3 to v4: - change according to Manivannan's comments. I hope I have not missed anything. quite long discuss thread Change from v2 to v3: - Basic rewrite whole patch according rob herry suggestion. put common function into dwc, so more soc can share the same logic. .../pci/controller/dwc/pcie-designware-host.c | 78 +++++++++++++++++++ drivers/pci/controller/dwc/pcie-designware.h | 28 +++++++ 2 files changed, 106 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 9952057c8819c..1822c04d370b2 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -8,6 +8,7 @@ * Author: Jingoo Han */ +#include #include #include #include @@ -807,3 +808,80 @@ int dw_pcie_setup_rc(struct dw_pcie_rp *pp) return 0; } EXPORT_SYMBOL_GPL(dw_pcie_setup_rc); + +int dw_pcie_suspend_noirq(struct dw_pcie *pci) +{ + u8 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + u32 val; + int ret; + + /* + * If L1SS is supported, then do not put the link into L2 as some + * devices such as NVMe expect low resume latency. + */ + if (dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKCTL) & PCI_EXP_LNKCTL_ASPM_L1) + return 0; + + if (dw_pcie_get_ltssm(pci) <= DW_PCIE_LTSSM_DETECT_ACT) + return 0; + + if (!pci->pp.ops->pme_turn_off) + return 0; + + pci->pp.ops->pme_turn_off(&pci->pp); + + /* + * PCI Express Base Specification Rev 4.0 5.3.3.2.1 PME Synchronization + * Recommands 1ms to 10ms timeout to check L2 ready + */ + ret = read_poll_timeout(dw_pcie_get_ltssm, val, val == DW_PCIE_LTSSM_L2_IDLE, + 100, 10000, false, pci); + if (ret) { + dev_err(pci->dev, "Timeout waiting for L2 entry! LTSSM: 0x%x\n", val); + return ret; + } + + if (pci->pp.ops->host_deinit) + pci->pp.ops->host_deinit(&pci->pp); + + pci->suspended = true; + + return ret; +} +EXPORT_SYMBOL_GPL(dw_pcie_suspend_noirq); + +int dw_pcie_resume_noirq(struct dw_pcie *pci) +{ + int ret; + + if (!pci->suspended) + return 0; + + pci->suspended = false; + + if (!pci->pp.ops->exit_from_l2) + return 0; + + pci->pp.ops->exit_from_l2(&pci->pp); + + if (pci->pp.ops->host_init) { + ret = pci->pp.ops->host_init(&pci->pp); + if (ret) { + dev_err(pci->dev, "Host init failed! ret = 0x%x\n", ret); + return ret; + } + } + + dw_pcie_setup_rc(&pci->pp); + + ret = dw_pcie_start_link(pci); + if (ret) + return ret; + + ret = dw_pcie_wait_for_link(pci); + if (ret) + return ret; + + return ret; +} +EXPORT_SYMBOL_GPL(dw_pcie_resume_noirq); diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index 79713ce075cc1..cbba3ed19b3c0 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -288,10 +288,21 @@ enum dw_pcie_core_rst { DW_PCIE_NUM_CORE_RSTS }; +enum dw_pcie_ltssm { + DW_PCIE_LTSSM_UNKNOWN = 0xFFFFFFFF, + /* Need to align with PCIE_PORT_DEBUG0 bits 0:5 */ + DW_PCIE_LTSSM_DETECT_QUIET = 0x0, + DW_PCIE_LTSSM_DETECT_ACT = 0x1, + DW_PCIE_LTSSM_L0 = 0x11, + DW_PCIE_LTSSM_L2_IDLE = 0x15, +}; + struct dw_pcie_host_ops { int (*host_init)(struct dw_pcie_rp *pp); void (*host_deinit)(struct dw_pcie_rp *pp); int (*msi_host_init)(struct dw_pcie_rp *pp); + void (*pme_turn_off)(struct dw_pcie_rp *pp); + void (*exit_from_l2)(struct dw_pcie_rp *pp); }; struct dw_pcie_rp { @@ -364,6 +375,7 @@ struct dw_pcie_ops { void (*write_dbi2)(struct dw_pcie *pcie, void __iomem *base, u32 reg, size_t size, u32 val); int (*link_up)(struct dw_pcie *pcie); + enum dw_pcie_ltssm (*get_ltssm)(struct dw_pcie *pcie); int (*start_link)(struct dw_pcie *pcie); void (*stop_link)(struct dw_pcie *pcie); }; @@ -393,6 +405,7 @@ struct dw_pcie { struct reset_control_bulk_data app_rsts[DW_PCIE_NUM_APP_RSTS]; struct reset_control_bulk_data core_rsts[DW_PCIE_NUM_CORE_RSTS]; struct gpio_desc *pe_rst; + bool suspended; }; #define to_dw_pcie_from_pp(port) container_of((port), struct dw_pcie, pp) @@ -430,6 +443,9 @@ void dw_pcie_iatu_detect(struct dw_pcie *pci); int dw_pcie_edma_detect(struct dw_pcie *pci); void dw_pcie_edma_remove(struct dw_pcie *pci); +int dw_pcie_suspend_noirq(struct dw_pcie *pci); +int dw_pcie_resume_noirq(struct dw_pcie *pci); + static inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val) { dw_pcie_write_dbi(pci, reg, 0x4, val); @@ -501,6 +517,18 @@ static inline void dw_pcie_stop_link(struct dw_pcie *pci) pci->ops->stop_link(pci); } +static inline enum dw_pcie_ltssm dw_pcie_get_ltssm(struct dw_pcie *pci) +{ + u32 val; + + if (pci->ops && pci->ops->get_ltssm) + return pci->ops->get_ltssm(pci); + + val = dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0); + + return (enum dw_pcie_ltssm)FIELD_GET(PORT_LOGIC_LTSSM_STATE_MASK, val); +} + #ifdef CONFIG_PCIE_DW_HOST irqreturn_t dw_handle_msi_irq(struct dw_pcie_rp *pp); int dw_pcie_setup_rc(struct dw_pcie_rp *pp); From patchwork Mon Jul 31 19:40:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 128864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2254095vqg; Mon, 31 Jul 2023 13:39:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlHjM6yXHrPEJn32eIjkDSGNGmIln+ou+2LIWsNbRKI5GIUSqwUlM5uHhfpIORicEx5DdZxt X-Received: by 2002:a17:906:74d0:b0:993:e9b8:90ec with SMTP id z16-20020a17090674d000b00993e9b890ecmr681182ejl.22.1690835978018; Mon, 31 Jul 2023 13:39:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690835978; cv=pass; d=google.com; s=arc-20160816; b=Z8pg/GLt8o/co49GRsmSWNC+Z+c9c1ymZtZPSavCBHF3sDG1hP8GCv9MBSJgvCHRMN QtYrt2FHgISyUTlkxnvF2SExU8qTZNQcMytm19LXbFxL2+PbwwOPd11NMA+Y51AQmBgV 68MdWW84TWcfmY+owZ5xMc/ZFMZADPp7dfImq1E6VQDWt7w6eQd6Fqy1QP53niiIqGs5 QxA4HhJFiaduXCSHeytmNE20XoPDmq5HZ1G3jC056QqqGLeyhNAJcRWNyEiPTnGwyYdQ 4aQJPxKmAXFCBhzyfwKwA9HSncmANdJgtMD6jLPo8iWys1uEGEkOu+RnvEtR3DVDXPEG TiIQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JK3JVtd0hBY4zvVsCFWwRi98AxDmHi8wbX8FY1pWbX8=; fh=J5oSUDXEPwknT4mz7Zo+di4xln/YaOK/kgRn6VOhtBk=; b=g9c3vtBy1OJzIpZEouSnPeqvIHiRizmA+shaZvKrs1mEfGlMttuFtLX0l7OJ6b7kx/ NH2pvcn0T41mQWpdC6JS25NyZb3D3+ohin8fwcaQEqx+Zw6EBQ4/RjAS2v4su3k8T9td s+EqfyL5xS/bHekmmm9Z03KJMkaVbEdDy9Hw5+hlNPPoDtQOUH/ewo7niIKANw2h8XJQ XKmMFPBU2xGrv4Oa0okQDBO+IHFzuOIjpXmK+NT8w/jh/erfTeuuP4jU/R2CpVghZ708 rBtqfNY5Ma1GDUhLLAE7RR9LNzVuTb/R/ZkxgA/ftyGzjzdbfhhUcntN7SIiw7P4MYli b8mw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=QnFAV0rF; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id um26-20020a170906cf9a00b0099bc58ab34csi7659860ejb.135.2023.07.31.13.39.14; Mon, 31 Jul 2023 13:39:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=QnFAV0rF; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231283AbjGaTkq (ORCPT + 99 others); Mon, 31 Jul 2023 15:40:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231319AbjGaTkk (ORCPT ); Mon, 31 Jul 2023 15:40:40 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2077.outbound.protection.outlook.com [40.107.22.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 740B9199F; Mon, 31 Jul 2023 12:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y0fjGfHZQyKhER4tDBJC0K+d+w99F+weaBrBmYbp8UzVpmfyPMfVdLxppW9cZb6xDrozsc2FAtnydDszaCY8AFEvTs5zu19JAlsWtgxWzq+3TbVNJiFyxEeKXmHeNwa0cecHDv5dy5723jFr0QRoi13LQ/ieK/beTCWC+zAxU6SLa6DiHj1GZgHHfAHMzUBy4wKDHNo2owzRaP44V9g9if78MzSUla6OfZKSAMwt3KleQR3Y8dlfiIq6qIrGYIuKnmSPZgJeL0slXj1/1yEvAi/VzQk54CtiaxVLFIYG4Oj4WdavZXhdq+O1Zikzi9NFc0rZilQ7dAB8pivBCcunVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JK3JVtd0hBY4zvVsCFWwRi98AxDmHi8wbX8FY1pWbX8=; b=DKcCtQmWTSld84GcJnakQyrGU72npRHKzD7s9Jryi1zSGcZ4eiCNVtHZrXeLujOhTKmapZayvIkVsfGSnyCp7VMO7WpPKevC02nqPpyxkDw5fd6Ugij+ap1PzMJqfYRKE7qlr7RquNt9frmFpNdUX1LaP+Zy81JRExEGSG+FCf3cdedxio0h1xZq6vJ3GyyoK5WSuzvbPCLBlff5NiHDFc+cpT7dyTK5+1BRO6plHyhYmyvVisUUXahGhk9VEXsafEotk+Gjw24rY7+++XoRm5sGhs0YWLX4RpcWy2ETgwN0pgMjyZpw+vxPa1F6E7L7JKFiShvZusyvY0gvfKyn0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JK3JVtd0hBY4zvVsCFWwRi98AxDmHi8wbX8FY1pWbX8=; b=QnFAV0rFF9u11dzfXBsLUQaKvprKhOfNNVMxrjtkIbLXK9qF8Lb3XNIebNRgxLmEja/XhA5H6AkwL0HTYcQFdvObsbRR9rDAumVTmXUEnWtkUs8XVCGddAYVxjlvH8v2b5sqJQiU1Q2tvi8mR9TUFbz5xuAA7OR0Rnl8yqvIYdM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by AS8PR04MB8344.eurprd04.prod.outlook.com (2603:10a6:20b:3b3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 19:40:35 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::d0d5:3604:98da:20b1]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::d0d5:3604:98da:20b1%7]) with mapi id 15.20.6631.043; Mon, 31 Jul 2023 19:40:35 +0000 From: Frank Li To: lpieralisi@kernel.org Cc: Frank.Li@nxp.com, bhelgaas@google.com, devicetree@vger.kernel.org, gustavo.pimentel@synopsys.com, helgaas@kernel.org, imx@lists.linux.dev, kw@linux.com, leoyang.li@nxp.com, linux-arm-kernel@lists.infradead.org, linux-imx@nxp.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, mani@kernel.org, manivannan.sadhasivam@linaro.org, minghuan.lian@nxp.com, mingkai.hu@nxp.com, robh+dt@kernel.org, roy.zang@nxp.com, shawnguo@kernel.org, zhiqiang.hou@nxp.com Subject: [PATCH v6 2/2] PCI: layerscape: Add power management support for ls1028a Date: Mon, 31 Jul 2023 15:40:10 -0400 Message-Id: <20230731194010.73016-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731194010.73016-1-Frank.Li@nxp.com> References: <20230731194010.73016-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR05CA0018.namprd05.prod.outlook.com (2603:10b6:a03:c0::31) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AS8PR04MB8344:EE_ X-MS-Office365-Filtering-Correlation-Id: ad32cd01-4011-468d-2202-08db91fe02ba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cXUPnSNV2DHdq2FYH0+Y6m4xQ5iyu/bCR5pjgEC2yJAG+qwB27ySOv7MMkRxnvE9mW5rbGoTDbmkyZrSBML89Iza/+IUmVUmIBESlWPGn89YiQdSpyDMuAjboydDOhAQ8t9z7VI+9f9h+juZeqRrRh3DzY/G0IKVQRBVBe3y7L/utMaCNhA6NnFvfbYpPuu0N2JH/Kih9lMpKMEhSAAddY842DgQa4X0QLN58CaTKG7F/kOlZW46QKYQkiN/bNUt7USL/yAOfOaAe/HQiJmYzuz7d1t2MngFVQ15z79MDnvD+WxA8J6zpddpG9oJxue7gQC3xPPiE+f+3zrg2tCkYTw3Ow4QQadv4RXROO3EcmJVHjle6KfqhIvQtiE4WQfr2cpV0ZFerwV04peJkfaA3eEVVDVSIkYnQQhurwsG4zzn0jP/Hmt4h6XEKJDYEnRtyHX/qaAq6uPIs67CUn/+SwhPjjQWA+KgckxNeWJEFdTwRB2/yDB1+gnM6lXbfN+8mpPDPSwGbyVOTi9+vGkejdVoCFiyTdwW3hWPEo0bVIurQBMhykNxl1Xk30lpLj/mZt5EmIujgnirHAlTByiU0nrIn+tIpAimb7uIir+MgElornGlkDW4MkuDEGWPSQsD X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(346002)(39860400002)(366004)(136003)(451199021)(38100700002)(66476007)(86362001)(8676002)(8936002)(5660300002)(316002)(4326008)(6916009)(7416002)(41300700001)(66556008)(66946007)(38350700002)(478600001)(2906002)(6666004)(36756003)(6512007)(52116002)(6486002)(6506007)(26005)(1076003)(83380400001)(186003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: h6FCGSCiyFf4egmIoVeDOeh2pPG33vGWOM+4TffSCARS/8+JkUosX8ZuhNuIoGFafrd79ul8qrCjN25HgIHoQDUvjBPg0aD46tAJlvPRtqX8K4mmz1PA/jDuE50SIgvDjoZkQQUEhw+lcFFK0Wu9oxJO0rcffORh8NDendx8Ii9JvndZXHUzqqD7vXRw/FlMQnDYcorvAniEQhGAxnbt0D4A4HC/nF7tpeH85LvwHGIqmR9H0qPCkVM5ra8rJ6FnmBUEgNy2RL8gevZd1tYLJ90fsVIBJg3uQIAaMhUTpkrbgs5J+HTGyeTO5/iDlkAb7iUGlaZx2VnvOkGJNajpnod0ZaMYZoezWXDWOrhGAxrUOQYeSvopeZSqnWXs2X/5hO9TiUhPE5ngVa2L7A/3Pn2Pue9X04gt5ziEOEbnbG7j3qcjxk5mmyUnCkhPES1MX/YZld7Kr6mHdi8U5KCtN+ApSaAuUU6jGI6HYFWvuZ9RwjsjMlCohpXqm9X5mRueHCO+8WC0Zx5pAZwHicwgp6Ms4ElHptqwQII0BFz28HjVE81NTNgkT3W4D6jg8gd2zwDT9tZ0InKxydT6kBVQknTqvUDy233DmrB3NQJpdFx2CUrNDxIrY+h0MQcPhHRMFIh8LaFXPI3YrgSJCXgLwlj4JCacX8tF35X02+3xsmqtzFavUWg6OkKLqhefhLHakjfmd3076+3NUTWs66nkVO8iCE8V1WaGJdqAkgXKr6jmTet9MqdmGiRUse0eEZFGmvsaTi8aRphWWf+d5MAbtWgG7kiYjDQ9caZDoq+v2UFQVBwkHXc4z3RcoyOp7MXHlveOnuCLd2SJ0RCyvwIzy5LfnAn9nRTCizfiheyDJauA18XHwZKZ1lnQ9IUFwY/GwdrEYjGfQeCB4C1XL/cZj0WuDjivu3j1ZblJtkO3rD0ogr6P4YQMIoyuxsVOXdN/br0yeiY2X7Qhy36sriEVSvb7G1Ou9PfiwWKEcGteVU04QKcs89y4F6pXdXqtlf/79rGPWUHhANIQV1At/HVaDvRVCxr+Go4BDfn/WJHzi9F4b0elvvZRS1lSOsSsDw60n+QO8jdhvvqQzmLWaI+5h8zJXkH5YE+83hgV9GXbleGPb88Xp2qphb1Luns13YmIk1uRATY+U3FSfytIB7UNGe+nYpfVwHpV0DjUAVY1EtPpb83OHJ42LNSYl0AKXhXwhtd9vPwvn5rpzsUzY47YLkJsq0oPHufbDY2XYdjs8rg7yHswD17C27PG35mWeqIOEuzmznatrqrxXqLQUyNujNt75R8S1ZH5/6aNfkIviIE8qfDHCDkVpR9ixsaUJSijw56PCsB9fgtBqiIEsXQUL0DPQbD36dL+Out8ZKmuHRy71W4YHgziO0vOwl4wbSHH3He2eciHGj6R+eMvpAWE6NZ4gSJzfCIMoELYAjwKQfkyYyi1/k4Mr550Dh6zSCO1KAq6fnMgrx27Jjh2yr+JPGCsvqzkRRf6C+4K6AP6G8CEvT/G98kdaDpPHn1EhTIpN2/DdBCixi6fvE7SQTUCaYQDXIboiKZe0ZrMp4/IWqI= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad32cd01-4011-468d-2202-08db91fe02ba X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2023 19:40:35.8041 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HiGP0vQX+xoFMhwnlZx2rk2r7pO04lZ1w5ZUr7GjyUv4e55564yvV88nB4YGvvY+8A8um/J+7UXR9x0FJFBlmA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8344 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772970026206595646 X-GMAIL-MSGID: 1772970026206595646 From: Hou Zhiqiang Add PME_Turn_Off/PME_TO_Ack handshake sequence, and finally put the PCIe controller into D3 state after the L2/L3 ready state transition process completion. Signed-off-by: Hou Zhiqiang Signed-off-by: Frank Li --- - Change from v5 to v6 change to NOIRQ_SYSTEM_SLEEP_PM_OPS to remove #ifdef PM_CONFIG - Change from v3 to v5 none - change at v3 Basic rewrite whole patch according rob herry suggestion. put common function into dwc, so more soc can share the same logic. drivers/pci/controller/dwc/pci-layerscape.c | 146 ++++++++++++++++++-- 1 file changed, 137 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-layerscape.c b/drivers/pci/controller/dwc/pci-layerscape.c index ed5fb492fe084..f235c79600277 100644 --- a/drivers/pci/controller/dwc/pci-layerscape.c +++ b/drivers/pci/controller/dwc/pci-layerscape.c @@ -8,9 +8,11 @@ * Author: Minghuan Lian */ +#include #include #include #include +#include #include #include #include @@ -27,12 +29,33 @@ #define PCIE_ABSERR 0x8d0 /* Bridge Slave Error Response Register */ #define PCIE_ABSERR_SETTING 0x9401 /* Forward error of non-posted request */ +/* PF Message Command Register */ +#define LS_PCIE_PF_MCR 0x2c +#define PF_MCR_PTOMR BIT(0) +#define PF_MCR_EXL2S BIT(1) + #define PCIE_IATU_NUM 6 +struct ls_pcie; + +struct ls_pcie_drvdata { + const u32 pf_off; + const u32 lut_off; + bool pm_support; +}; + struct ls_pcie { struct dw_pcie *pci; + const struct ls_pcie_drvdata *drvdata; + void __iomem *pf_base; + void __iomem *lut_base; + bool big_endian; + bool ep_presence; + struct regmap *scfg; + int index; }; +#define ls_pcie_pf_readl_addr(addr) ls_pcie_pf_readl(pcie, addr) #define to_ls_pcie(x) dev_get_drvdata((x)->dev) static bool ls_pcie_is_bridge(struct ls_pcie *pcie) @@ -73,6 +96,57 @@ static void ls_pcie_fix_error_response(struct ls_pcie *pcie) iowrite32(PCIE_ABSERR_SETTING, pci->dbi_base + PCIE_ABSERR); } +static u32 ls_pcie_pf_readl(struct ls_pcie *pcie, u32 off) +{ + if (pcie->big_endian) + return ioread32be(pcie->pf_base + off); + + return ioread32(pcie->pf_base + off); +} + +static void ls_pcie_pf_writel(struct ls_pcie *pcie, u32 off, u32 val) +{ + if (pcie->big_endian) + return iowrite32be(val, pcie->pf_base + off); + + return iowrite32(val, pcie->pf_base + off); + +} + +static void ls_pcie_send_turnoff_msg(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct ls_pcie *pcie = to_ls_pcie(pci); + u32 val; + int ret; + + val = ls_pcie_pf_readl(pcie, LS_PCIE_PF_MCR); + val |= PF_MCR_PTOMR; + ls_pcie_pf_writel(pcie, LS_PCIE_PF_MCR, val); + + ret = readx_poll_timeout(ls_pcie_pf_readl_addr, LS_PCIE_PF_MCR, + val, !(val & PF_MCR_PTOMR), 100, 10000); + if (ret) + dev_info(pcie->pci->dev, "poll turn off message timeout\n"); +} + +static void ls_pcie_exit_from_l2(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct ls_pcie *pcie = to_ls_pcie(pci); + u32 val; + int ret; + + val = ls_pcie_pf_readl(pcie, LS_PCIE_PF_MCR); + val |= PF_MCR_EXL2S; + ls_pcie_pf_writel(pcie, LS_PCIE_PF_MCR, val); + + ret = readx_poll_timeout(ls_pcie_pf_readl_addr, LS_PCIE_PF_MCR, + val, !(val & PF_MCR_EXL2S), 100, 10000); + if (ret) + dev_info(pcie->pci->dev, "poll exit L2 state timeout\n"); +} + static int ls_pcie_host_init(struct dw_pcie_rp *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); @@ -91,18 +165,33 @@ static int ls_pcie_host_init(struct dw_pcie_rp *pp) static const struct dw_pcie_host_ops ls_pcie_host_ops = { .host_init = ls_pcie_host_init, + .pme_turn_off = ls_pcie_send_turnoff_msg, + .exit_from_l2 = ls_pcie_exit_from_l2, +}; + +static const struct ls_pcie_drvdata ls1021a_drvdata = { +}; + +static const struct ls_pcie_drvdata ls1043a_drvdata = { + .lut_off = 0x10000, +}; + +static const struct ls_pcie_drvdata layerscape_drvdata = { + .lut_off = 0x80000, + .pf_off = 0xc0000, + .pm_support = true, }; static const struct of_device_id ls_pcie_of_match[] = { - { .compatible = "fsl,ls1012a-pcie", }, - { .compatible = "fsl,ls1021a-pcie", }, - { .compatible = "fsl,ls1028a-pcie", }, - { .compatible = "fsl,ls1043a-pcie", }, - { .compatible = "fsl,ls1046a-pcie", }, - { .compatible = "fsl,ls2080a-pcie", }, - { .compatible = "fsl,ls2085a-pcie", }, - { .compatible = "fsl,ls2088a-pcie", }, - { .compatible = "fsl,ls1088a-pcie", }, + { .compatible = "fsl,ls1012a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls1021a-pcie", .data = &ls1021a_drvdata }, + { .compatible = "fsl,ls1028a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls1043a-pcie", .data = &ls1043a_drvdata }, + { .compatible = "fsl,ls1046a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls2080a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls2085a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls2088a-pcie", .data = &layerscape_drvdata }, + { .compatible = "fsl,ls1088a-pcie", .data = &layerscape_drvdata }, { }, }; @@ -121,6 +210,8 @@ static int ls_pcie_probe(struct platform_device *pdev) if (!pci) return -ENOMEM; + pcie->drvdata = of_device_get_match_data(dev); + pci->dev = dev; pci->pp.ops = &ls_pcie_host_ops; @@ -131,6 +222,14 @@ static int ls_pcie_probe(struct platform_device *pdev) if (IS_ERR(pci->dbi_base)) return PTR_ERR(pci->dbi_base); + pcie->big_endian = of_property_read_bool(dev->of_node, "big-endian"); + + if (pcie->drvdata->lut_off) + pcie->lut_base = pci->dbi_base + pcie->drvdata->lut_off; + + if (pcie->drvdata->pf_off) + pcie->pf_base = pci->dbi_base + pcie->drvdata->pf_off; + if (!ls_pcie_is_bridge(pcie)) return -ENODEV; @@ -139,12 +238,41 @@ static int ls_pcie_probe(struct platform_device *pdev) return dw_pcie_host_init(&pci->pp); } +static int ls_pcie_suspend_noirq(struct device *dev) +{ + struct ls_pcie *pcie = dev_get_drvdata(dev); + struct dw_pcie *pci = pcie->pci; + + if (!pcie->drvdata->pm_support) + return 0; + + return dw_pcie_suspend_noirq(pci); +} + +static int ls_pcie_resume_noirq(struct device *dev) +{ + + struct ls_pcie *pcie = dev_get_drvdata(dev); + struct dw_pcie *pci = pcie->pci; + + if (!pcie->drvdata->pm_support) + return 0; + + return dw_pcie_resume_noirq(pci); +} + +static const struct dev_pm_ops ls_pcie_pm_ops = { + NOIRQ_SYSTEM_SLEEP_PM_OPS(ls_pcie_suspend_noirq, + ls_pcie_resume_noirq) +}; + static struct platform_driver ls_pcie_driver = { .probe = ls_pcie_probe, .driver = { .name = "layerscape-pcie", .of_match_table = ls_pcie_of_match, .suppress_bind_attrs = true, + .pm = &ls_pcie_pm_ops, }, }; builtin_platform_driver(ls_pcie_driver);