From patchwork Mon Oct 16 16:17:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 153564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3578709vqb; Mon, 16 Oct 2023 09:27:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE32UfWwHU0eILepGc/dKwnS3DF9WMPIfwnmB8xM3SGPaMssN5AkvH2MGNFRvpNF7oQLpnO X-Received: by 2002:a05:6a00:1622:b0:6bc:ff89:a2fc with SMTP id e2-20020a056a00162200b006bcff89a2fcmr5650024pfc.2.1697473643187; Mon, 16 Oct 2023 09:27:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697473643; cv=pass; d=google.com; s=arc-20160816; b=xDUOpmsPbnTNcAmMA9g0WnRpago1Gc6MySH+t0B1GPkLVCYsc7jABeU7TnEd6j4buf OoSwj1QdXwsYX+OZMk2ZJqrKVA4BrSKNw0F+c7IvOIGAMqyxIVSgmtUDxfFCnCbO6sGI 8l2R7I49RXYHVkyypEMcw0BE7und3xgmD/iGjaEbHrCGdwOMRsFksGeub5HMWbt0SIKN npckpKZfQfPBarKUeJ93txUQ4IrqqVo4PHAqhF2e51G0KbPb9Kfq0oishkmfd/wWMTLU hcKKTizoGyUhtUCZ3DkYRQ+ekXBOEsdRya9gaGofd3ruNoF9Nphp4QDme/wtzPUvbh50 Vz9A== 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=IOR1gcPXA5TFwOrIuNws68vaKmjJdzXEgvOYYEXiSLk=; fh=hcaUxgS2XlQHla+W5HfOGEcJunKFhPD6I/OsnpJytRE=; b=OyeKO9sIySVh6+gZzkQEtmYBePOMkrWWBJobq9n7T2qlOy7+bQkfAcPL/tBj6dzo0d dYvfg28GsT3KLI/hS/neYGTCyX2mN+F8HAyaQpsfrUkmvKwhtFM9e1mZ5EIxA5xpqcNA dp54RM9TUJYjSHueCga6xC32SokW/76spKJKtLCswCQ7/5GKcTPqzr2X7WacYeJgW9mG OtjNj9gq1GWPDfV18RcSrAjMXzpaQl5wSIOwO3q9qAmUOdsIbg+C9lDndunh08NwLDN8 8ZQpWnJxLU6DpbHDIB++CqMooIafPVZxDOlOfuzNDPIRBT14KSDMo4dUVMRbvf10oKle cXDg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=hyP5aQX4; 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::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id g6-20020a636b06000000b0058a4883e6casi10519182pgc.225.2023.10.16.09.27.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:27:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=hyP5aQX4; 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::3:6 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id AC5D6807D406; Mon, 16 Oct 2023 09:27:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233517AbjJPQ06 (ORCPT + 18 others); Mon, 16 Oct 2023 12:26:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233904AbjJPQ0f (ORCPT ); Mon, 16 Oct 2023 12:26:35 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2060.outbound.protection.outlook.com [40.107.21.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEBF3173A; Mon, 16 Oct 2023 09:18:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mm/7XOQtmLbE2t1S4zT09aNL+T/JQdDjs2GS6hSDb7P/bDd+VIfyAGZ2LpewkOTEPhVJVl2aAgEn6sEUyOXY0aHryM0odufhQgQqxqW+NSQk6CZexvB3criqz6YtJ2gF070Dq4/WLf8he+k1q/IXz/35eS+4Tg0262eeEng1J5Hc4bg7yHjRk7ZeGimh17nRzRhPnSMysPa+zA2CJNsZtL3ZHCg0S5wf6xQ/rMneabse1EVXLIaPX3kBmWfQcEXUCo8iOGfEp60VyamnOCbR4C2gKa6sxd3iQ5gxhTrgIbzT21ASlaI9X84nbROCB0tdxaQXJSbL+GeXyKgPfbMAaw== 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=IOR1gcPXA5TFwOrIuNws68vaKmjJdzXEgvOYYEXiSLk=; b=DEbvDkUQZIam9BgJ53qDrStNKWu99Sby1TUU4xXM0QNxGHB6N8onj58i3LuT0CLhza88KblOHgHZU5jUjbrvNnG1hY2jf5UiE3xs1BV0vplUuRcoqY+wJnyE2Chp8YrSRcdAnLkrnSGXr1KkARyfQ70zb/jrou5ag+t8OuDyetL95McRmxahGVEbxstQeNRMMjyn5Hkl8ZS2JluE/UYHWSPDX3+csEssZ7EErdAmtkB6FAX79uvTvaav6L0i3Ubwzw72GJENc4qufBpAFqvDj06yJuL94RzWcOAkDP8asKHRefgWb2MBoC1tEEn3o771gTBNX2BryqFukzFKhFBdKg== 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=IOR1gcPXA5TFwOrIuNws68vaKmjJdzXEgvOYYEXiSLk=; b=hyP5aQX4qhoLwp4tMPEM0AVmDhDKOHMcsM6QlcfNbCaEgr686mTAXINKJp8rycgwX0FrQyJ1pZZkolx+QRUzzE/W5v0ME26rpJYtkxpYO75yrcTOxJsRsfJ1uULCw9cbmgpi26VapE5dnBT8VyhXHGLucpC6Xz5DOEIew2C8UMA= 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 AM9PR04MB7489.eurprd04.prod.outlook.com (2603:10a6:20b:281::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Mon, 16 Oct 2023 16:18:00 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::1774:e25f:f99:aca2]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::1774:e25f:f99:aca2%4]) with mapi id 15.20.6886.034; Mon, 16 Oct 2023 16:18:00 +0000 From: Frank Li To: lpieralisi@kernel.org Cc: Frank.li@nxp.com, bhelgaas@google.com, helgaas@kernel.org, imx@lists.linux.dev, kw@linux.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, minghuan.Lian@nxp.com, mingkai.hu@nxp.com, robh@kernel.org, roy.zang@nxp.com Subject: [PATCH v2 2/3] PCI: layerscape: Add suspend/resume for ls1021a Date: Mon, 16 Oct 2023 12:17:37 -0400 Message-Id: <20231016161738.2854352-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016161738.2854352-1-Frank.Li@nxp.com> References: <20231016161738.2854352-1-Frank.Li@nxp.com> X-ClientProxiedBy: BYAPR11CA0085.namprd11.prod.outlook.com (2603:10b6:a03:f4::26) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|AM9PR04MB7489:EE_ X-MS-Office365-Filtering-Correlation-Id: 6e701675-722c-46e6-ec70-08dbce637752 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nW3/1lfACoXRwxhEY2Y+dK9JzAv3IwJWJZWO9oYzHxZyw/PAdO3Cdfxtoqg2jnGQFSsUrfMTLIXKiQm61ns1iJYvHtY2Vn2fkdjK+p6QPNopuVI0E3k+YV4+JCTnpfHFfGNlrL6aWjxcQSJpdzNfcARiUHYr2uzqRKYSo4imqXdDDLTEZa1+vSSt9Yzd4C6c4m+KRJMYFOo5+H8sFV/ssmVFvZFbpFCQXbLW33E7zoFD2qgi8TRzWeh1zNtQXGRqIdn0AJo4Dm9IrX9syZ2v7o5hadyLjCyCpT9LmwRRfuNPIfZv9IZsxW9Uo9NXPfrRTb9jWxL5WTnL/u/y0TWGPqdog0bnX3YiibmL6IscDrslO4kbKzAhHMbgaJxeUUxntYiAUqwp7TOo/NtUBCemypm5eRGCkmvx6NvM6EKxmcmhMXjsTJswkyLWEzqtZjhdyEh/NjsIqbiN5EzD7iBX+5u1iOX5goX5Q/YzhbKiUyEeCHph62ZUiG0R4qvqEm0ag8Fa2LuVKZqb1RHifcw7IY+V/qcu6Azjlgeqlyj5pacT9+sb6RA9xeep6mcsXuOVqot7lZ9JyS1K75gfaNly7VEqxveYDecHEpf1Yxd84QWOLmCNNKKM2Pfo0cUgnOli 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:(13230031)(346002)(366004)(376002)(136003)(396003)(39860400002)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(86362001)(38350700005)(36756003)(478600001)(6486002)(41300700001)(52116002)(5660300002)(2906002)(6666004)(6506007)(38100700002)(2616005)(1076003)(26005)(66476007)(66946007)(8936002)(6916009)(316002)(66556008)(8676002)(4326008)(83380400001)(15650500001)(6512007)(7416002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9OcQmUVjxC9JrhHrHqTXUeR/jVxK7ZSky8S0zULVDYfexT49hyb4TodJ9vAX5J5FCcfJoq9RQBc424UeJflPot2j4DykwWr8PQzRchQH36wH3otRGYi6GrLy4vjN3QI0lhXrO41g4cnxAbf95H5Zb9xLggGCDQ9e1NgqBie3ZcU6mJZCprMp8hpKyJWyyhm2NlSsiXH8EOnh0Fj4VK1qFslVOjJ8LYq7RAW5nzR4rqaFaJCkzyc2YZpbkeXPiQ3hPSBDwJ1RhCgVfBJrojxMWndXvXXJ7Ca62/sdR+n1ZFU7OI47LsScWRmvQy8e+7IOhDNurnU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KVFTyGm0mXs5/vV6ndcW8fhLCcBOONOhHUYeiLYxq3gFN+dJ/g9lLftACjDKmEI5mpTSQSwZ98bi2hGS8CeZVfeXGZHIJtkr31aQN6KQ2bQSv0yNC48x3+xo7J1WBhZCI1E56smm6q32CWhlWZIWizzONG6sb+0p3MEEq0IK6N6pnuWksMrkLDTa8etf+Pvh49+mash8UicI X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e701675-722c-46e6-ec70-08dbce637752 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 16:18:00.3686 (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: 24afOsP9vrI8nizjKOB3ySN2tHIJDFI/ktk7YUclTO8CtBph1EfKD6RzWIptyOfcJxD87Jc3PPnc/jBqfbd4GQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB7489 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:27:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779930122864206178 X-GMAIL-MSGID: 1779930122864206178 ls1021a add suspend/resume support. Signed-off-by: Frank Li --- Notes: change from v1 to v2 - change subject 'a' to 'A' drivers/pci/controller/dwc/pci-layerscape.c | 88 ++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/dwc/pci-layerscape.c b/drivers/pci/controller/dwc/pci-layerscape.c index 20c48c06e224..bc5a8ff1a26c 100644 --- a/drivers/pci/controller/dwc/pci-layerscape.c +++ b/drivers/pci/controller/dwc/pci-layerscape.c @@ -35,6 +35,12 @@ #define PF_MCR_PTOMR BIT(0) #define PF_MCR_EXL2S BIT(1) +/* LS1021A PEXn PM Write Control Register */ +#define SCFG_PEXPMWRCR(idx) (0x5c + (idx) * 0x64) +#define PMXMTTURNOFF BIT(31) +#define SCFG_PEXSFTRSTCR 0x190 +#define PEXSR(idx) BIT(idx) + #define PCIE_IATU_NUM 6 struct ls_pcie_drvdata { @@ -48,6 +54,8 @@ struct ls_pcie { struct dw_pcie *pci; const struct ls_pcie_drvdata *drvdata; void __iomem *pf_base; + struct regmap *scfg; + int index; bool big_endian; }; @@ -170,13 +178,91 @@ static int ls_pcie_host_init(struct dw_pcie_rp *pp) return 0; } +static void ls1021a_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; + + if (!pcie->scfg) { + dev_dbg(pcie->pci->dev, "SYSCFG is NULL\n"); + return; + } + + /* Send Turn_off message */ + regmap_read(pcie->scfg, SCFG_PEXPMWRCR(pcie->index), &val); + val |= PMXMTTURNOFF; + regmap_write(pcie->scfg, SCFG_PEXPMWRCR(pcie->index), val); + + /* There are not register to check ACK, so wait PCIE_PME_TO_L2_TIMEOUT_US */ + mdelay(PCIE_PME_TO_L2_TIMEOUT_US/1000); + + /* Clear Turn_off message */ + regmap_read(pcie->scfg, SCFG_PEXPMWRCR(pcie->index), &val); + val &= ~PMXMTTURNOFF; + regmap_write(pcie->scfg, SCFG_PEXPMWRCR(pcie->index), val); +} + +static void ls1021a_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; + + regmap_read(pcie->scfg, SCFG_PEXSFTRSTCR, &val); + val |= PEXSR(pcie->index); + regmap_write(pcie->scfg, SCFG_PEXSFTRSTCR, val); + + regmap_read(pcie->scfg, SCFG_PEXSFTRSTCR, &val); + val &= ~PEXSR(pcie->index); + regmap_write(pcie->scfg, SCFG_PEXSFTRSTCR, val); +} + +static int ls1021a_pcie_host_init(struct dw_pcie_rp *pp) +{ + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct ls_pcie *pcie = to_ls_pcie(pci); + struct device *dev = pcie->pci->dev; + u32 index[2]; + int ret; + + ret = ls_pcie_host_init(pp); + if (ret) + return ret; + + pcie->scfg = syscon_regmap_lookup_by_phandle(dev->of_node, "fsl,pcie-scfg"); + if (IS_ERR(pcie->scfg)) { + ret = PTR_ERR(pcie->scfg); + dev_err(dev, "No syscfg phandle specified\n"); + pcie->scfg = NULL; + return ret; + } + + ret = of_property_read_u32_array(dev->of_node, "fsl,pcie-scfg", index, 2); + if (ret) { + pcie->scfg = NULL; + return ret; + } + + pcie->index = index[1]; + + return ret; +} + 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, }; +static const struct dw_pcie_host_ops ls1021a_pcie_host_ops = { + .host_init = ls1021a_pcie_host_init, + .pme_turn_off = ls1021a_pcie_send_turnoff_msg, +}; + static const struct ls_pcie_drvdata ls1021a_drvdata = { - .pm_support = false, + .pm_support = true, + .ops = &ls1021a_pcie_host_ops, + .exit_from_l2 = ls1021a_pcie_exit_from_l2, }; static const struct ls_pcie_drvdata layerscape_drvdata = {