From patchwork Sun Aug 27 13:43:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 9923873 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 4D1EE602BD for ; Sun, 27 Aug 2017 13:44:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CFFC284E4 for ; Sun, 27 Aug 2017 13:44:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3007028632; Sun, 27 Aug 2017 13:44:22 +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=-6.9 required=2.0 tests=BAYES_00,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 3A779284E4 for ; Sun, 27 Aug 2017 13:44:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751415AbdH0NoU (ORCPT ); Sun, 27 Aug 2017 09:44:20 -0400 Received: from mail-dm3nam03on0072.outbound.protection.outlook.com ([104.47.41.72]:41121 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751338AbdH0NoS (ORCPT ); Sun, 27 Aug 2017 09:44:18 -0400 Received: from BN6PR03CA0014.namprd03.prod.outlook.com (10.168.230.152) by BN6PR03MB3315.namprd03.prod.outlook.com (10.174.233.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1385.9; Sun, 27 Aug 2017 13:44:16 +0000 Received: from BN1AFFO11OLC001.protection.gbl (2a01:111:f400:7c10::170) by BN6PR03CA0014.outlook.office365.com (2603:10b6:404:23::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1385.9 via Frontend Transport; Sun, 27 Aug 2017 13:44:16 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BN1AFFO11OLC001.mail.protection.outlook.com (10.58.53.72) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1341.15 via Frontend Transport; Sun, 27 Aug 2017 13:44:15 +0000 Received: from b29396-OptiPlex-7040.ap.freescale.net (b29396-OptiPlex-7040.ap.freescale.net [10.192.242.182]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id v7RDiAks018325; Sun, 27 Aug 2017 06:44:10 -0700 From: Dong Aisheng To: CC: , , , , , Dong Aisheng Subject: [PATCH 1/1] ARM: imx7ulp: add cpuidle support Date: Sun, 27 Aug 2017 21:43:41 +0800 Message-ID: <1503841421-17677-1-git-send-email-aisheng.dong@nxp.com> X-Mailer: git-send-email 2.7.4 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131483150558907510; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39380400002)(39860400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(575784001)(86362001)(2906002)(81166006)(8676002)(8656003)(48376002)(81156014)(33646002)(8936002)(356003)(69596002)(305945005)(5660300001)(50466002)(5003940100001)(85426001)(2351001)(50226002)(4326008)(498600001)(106466001)(104016004)(105606002)(6916009)(626005)(47776003)(68736007)(53936002)(77096006)(189998001)(97736004)(36756003)(54906002)(50986999)(6666003)(110136004)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR03MB3315; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11OLC001; 1:FtlHQeF/+dOdIsvsb4w1qdFC0nCE33gbrmSKkTRdHh+ASs3BqFgKTzJbqVVmkTSraUUa5qbiN6vgGOj3GgJZmD7WrQBM/NXzHQsp9vnQqCVzf3UXIgAzuv8ihkzydvB1 MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 983105ce-1fad-4ecf-eb19-08d4ed51b577 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603199)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:BN6PR03MB3315; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB3315; 3:JFzSGx/Vd4rzvDpu8bT76b2/7M1omWXeeWeIQfCw7FmTf8joInXJXtLtDjLeXj2o3l3R4wka5ZtYBg/z4PRTh+5B3K8JkAW5UxhfrX7K587zb0Js6s5mqYs8dCSzI29C639PSNFzGyD5umxUQbFOtuC1Th8LDS52Wfs66Ol0jI7acs4hw0XXIc6H5F+DWRhqfrIB02rCzWn8Q/xKjo1+wqQbHkBJ4u03BRguk71crvhjd8uqQe4deDPqw74hEyD5an5uj6oDUDjza2LEvag6TXn6YEj/Q2jNROGZrjIXp5R3XC2Wz8cRR0aWPVRoO4fjeiy2/jPqokav9RriGtKAOA==; 25:20OQNZqgiXJ21sNxX3Yc1IylyJlvUxTpOA5qskDh+ZroejMvT7svUmFhoHs3cfdHzBzqXiV2uGssSCkZE9xboEIJXD8lgNFgknlIe2VVXm+0tQi1EGzuXc3YD+2yZqix1SbtmdtgessR+yXePKgjRwklwXfCqsFpmzTGXakNIjVB687/lz2pfxtfO85S3lWJvhEop6kUuJqa8TajLiOK8q27GEuWbTiNKBB9aPSEDHUlvzmbENATv8px2ZfLPJ0Lcvh+yVK8551ZRM8wU6M2ITcF4CuAU40MDdJTnXwb/7VQ7aXrFx+zfQr+OOhVGILigxoJF5qpJRN/xrWTX/GHCQ==; 31:9hysPuvez14/vRdM6jqNvp0xwEOzHey8LeywpYZHjuYhfi9d1pAx/2oZU2pbLrf/exW/7S7OnM71uDK7zfueOgNYLJuCEIJXm5oX4Q0QV19khm7G/cafwmCU/0ogk//MosefxMpc0h2dfHQ4vKQV9Z3W+aBYam/9XCU54lCnd0EYTHGFQO3QFtsA5Cj0vRMh05M2eeY6Ppek23rHl52/X1F533DtbU/TpYkOHuhlQ+8= X-MS-TrafficTypeDiagnostic: BN6PR03MB3315: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(601004)(2401047)(13018025)(8121501046)(13016025)(5005006)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6096035)(20161123565025)(20161123563025)(20161123556025)(20161123561025)(20161123559100)(201703131430075)(201703131448075)(201703131433075)(201703161259150)(201703151042153)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BN6PR03MB3315; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BN6PR03MB3315; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB3315; 4:y5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mHTY48Eww==; 5:REYffqO+277VoaoeYXLtg8btclaSzmR2h1LmahmLOcdvdXsrKzsEcShnaWYDRJN6tyDUxAaT5PY1PhUXAZxLSOwjYNxmOH8LdobDi3/RWwLzlDcFl5ir4ej22H5MnjzOFAmJmAT8XFNkCkCpAofVug==; 24:dUG6YyQkXkLKWH+ECD/cqG9NgqY5N+FMXhzYhjPvZYiNbx8SMA1BPl1wOPu/SZPi8L6TTf8udYpT0s45a5Kh/zHHU/MYV27bBuvERSVGOyk=; 7:Fu+Lh3rTX7ZfEjLpPlh2ergmM44Vzy+ix2azNg4je9vowjdAIUtjMNSJu5qdXJSfHykW4RecOgW41Te6JMZJGaPZIwaVGbBKYupXvtjbMZcKt61en4Xrj2RHagu4KSs1w5pG4Q6J9oiYl2mzHQXlkCtSsgjt5AVLbK+C+hsaAeagnRSpyDCKCCHRtNwQ0OcLH+RSvHx+osAL5qwJVahCnoKYa/ASF4zIp3Fz8bR+0u4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2017 13:44:15.6567 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR03MB3315 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP i.MX7ULP support 3 levels idle as below: 1. patial stop mode 3; 2. patial stop mode 2; 3. patial stop mode 1. PSTOP1 - Partial Stop with system and bus clock disabled PSTOP2 - Partial Stop with system clock disabled and bus clock enabled PSTOP3 - Partial Stop with system clock enabled and bus clock enabled For PSTOP 1/2 mode, as the system and bus clock will be disabled, the devices working inprogress may not be able to work anymore, driver needs to use pm_qos API to prevent system enter those modes. Cc: "Rafael J. Wysocki" Cc: Daniel Lezcano Cc: Shawn Guo Signed-off-by: Anson Huang Signed-off-by: Dong Aisheng Acked-by: Daniel Lezcano --- arch/arm/mach-imx/Makefile | 1 + arch/arm/mach-imx/common.h | 12 +++++++ arch/arm/mach-imx/cpuidle-imx7ulp.c | 69 +++++++++++++++++++++++++++++++++++++ arch/arm/mach-imx/cpuidle.h | 5 +++ arch/arm/mach-imx/mach-imx7ulp.c | 7 ++++ arch/arm/mach-imx/pm-imx7ulp.c | 65 +++++++++++++++++++++++++++++++--- 6 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 arch/arm/mach-imx/cpuidle-imx7ulp.c diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index c5948b7..a3f55a9 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -28,6 +28,7 @@ obj-$(CONFIG_SOC_IMX6Q) += cpuidle-imx6q.o obj-$(CONFIG_SOC_IMX6SL) += cpuidle-imx6sl.o obj-$(CONFIG_SOC_IMX6SX) += cpuidle-imx6sx.o obj-$(CONFIG_SOC_IMX6UL) += cpuidle-imx6sx.o +obj-$(CONFIG_SOC_IMX7ULP) += cpuidle-imx7ulp.o endif ifdef CONFIG_SND_IMX_SOC diff --git a/arch/arm/mach-imx/common.h b/arch/arm/mach-imx/common.h index b0e85df..9b78902 100644 --- a/arch/arm/mach-imx/common.h +++ b/arch/arm/mach-imx/common.h @@ -78,6 +78,17 @@ enum mx3_cpu_pwr_mode { MX3_SLEEP, }; +enum imx7ulp_cpu_pwr_mode { + HSRUN, + RUN, + VLPR, + WAIT, + VLPW, + STOP, + VLPS, + VLLS, +}; + void mx3_cpu_lp_set(enum mx3_cpu_pwr_mode mode); void imx_enable_cpu(int cpu, bool enable); @@ -106,6 +117,7 @@ int imx6_set_lpm(enum mxc_cpu_pwr_mode mode); void imx6_set_int_mem_clk_lpm(bool enable); void imx6sl_set_wait_clk(bool enter); int imx_mmdc_get_ddr_type(void); +int imx7ulp_set_lpm(enum imx7ulp_cpu_pwr_mode mode); void imx_cpu_die(unsigned int cpu); int imx_cpu_kill(unsigned int cpu); diff --git a/arch/arm/mach-imx/cpuidle-imx7ulp.c b/arch/arm/mach-imx/cpuidle-imx7ulp.c new file mode 100644 index 0000000..f165d85 --- /dev/null +++ b/arch/arm/mach-imx/cpuidle-imx7ulp.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * Copyright (C) 2017 NXP. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include + +#include "common.h" +#include "cpuidle.h" +#include "hardware.h" + +static int imx7ulp_enter_idle(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int index) +{ + switch (index) { + case 1: + imx7ulp_set_lpm(WAIT); + break; + case 2: + imx7ulp_set_lpm(STOP); + break; + default: + break; + } + + cpu_do_idle(); + + imx7ulp_set_lpm(RUN); + + return index; +} + +static struct cpuidle_driver imx7ulp_cpuidle_driver = { + .name = "imx7ulp_cpuidle", + .owner = THIS_MODULE, + .states = { + /* WFI */ + ARM_CPUIDLE_WFI_STATE, + /* WAIT */ + { + .exit_latency = 50, + .target_residency = 75, + .enter = imx7ulp_enter_idle, + .name = "WAIT", + .desc = "PSTOP2", + }, + /* STOP */ + { + .exit_latency = 100, + .target_residency = 150, + .enter = imx7ulp_enter_idle, + .name = "STOP", + .desc = "PSTOP1", + }, + }, + .state_count = 3, + .safe_state_index = 0, +}; + +int __init imx7ulp_cpuidle_init(void) +{ + return cpuidle_register(&imx7ulp_cpuidle_driver, NULL); +} diff --git a/arch/arm/mach-imx/cpuidle.h b/arch/arm/mach-imx/cpuidle.h index f914012..7694c8f 100644 --- a/arch/arm/mach-imx/cpuidle.h +++ b/arch/arm/mach-imx/cpuidle.h @@ -15,6 +15,7 @@ extern int imx5_cpuidle_init(void); extern int imx6q_cpuidle_init(void); extern int imx6sl_cpuidle_init(void); extern int imx6sx_cpuidle_init(void); +extern int imx7ulp_cpuidle_init(void); #else static inline int imx5_cpuidle_init(void) { @@ -32,4 +33,8 @@ static inline int imx6sx_cpuidle_init(void) { return 0; } +static inline int imx7ulp_cpuidle_init(void) +{ + return 0; +} #endif diff --git a/arch/arm/mach-imx/mach-imx7ulp.c b/arch/arm/mach-imx/mach-imx7ulp.c index 9f7a25c..1d8fe71 100644 --- a/arch/arm/mach-imx/mach-imx7ulp.c +++ b/arch/arm/mach-imx/mach-imx7ulp.c @@ -15,8 +15,14 @@ #include #include "common.h" +#include "cpuidle.h" #include "hardware.h" +static void __init imx7ulp_init_late(void) +{ + imx7ulp_cpuidle_init(); +} + static void __init imx7ulp_init_machine(void) { imx7ulp_pm_init(); @@ -33,5 +39,6 @@ static const char *const imx7ulp_dt_compat[] __initconst = { DT_MACHINE_START(IMX7ulp, "Freescale i.MX7ULP (Device Tree)") .init_machine = imx7ulp_init_machine, + .init_late = imx7ulp_init_late, .dt_compat = imx7ulp_dt_compat, MACHINE_END diff --git a/arch/arm/mach-imx/pm-imx7ulp.c b/arch/arm/mach-imx/pm-imx7ulp.c index df5d6b6..5f85040 100644 --- a/arch/arm/mach-imx/pm-imx7ulp.c +++ b/arch/arm/mach-imx/pm-imx7ulp.c @@ -14,20 +14,77 @@ #include #include +#include "common.h" + +/* SMC registers */ +#define SMC_PMPROT 0x8 #define SMC_PMCTRL 0x10 +#define SMC_PMSTAT 0x18 +#define SMC_SRS 0x20 +#define SMC_RPC 0x24 +#define SMC_SSRS 0x28 +#define SMC_SRIE 0x2c +#define SMC_SRIF 0x30 +#define SMC_CSRE 0x34 +#define SMC_MR 0x40 +#define SMC_FM 0x40 + +/* PMPROT */ +#define BM_PMPROT_AHSRUN BIT(7) +#define BM_PMPROT_AVLP BIT(5) +#define BM_PMPROT_ALLS BIT(3) +#define BM_PMPROT_AVLLS BIT(1) + +/* PMCTRL */ +#define BM_PMCTRL_STOPA (0x1 << 24) #define BP_PMCTRL_PSTOPO 16 +#define BM_PMCTRL_PSTOPO (0x3 << BP_PMCTRL_PSTOPO) +#define BP_PMCTRL_RUNM 8 +#define BM_PMCTRL_RUNM (0x3 << BP_PMCTRL_RUNM) +#define BP_PMCTRL_STOPM 0 +#define BM_PMCTRL_STOPM (0x7 << BP_PMCTRL_STOPM) + #define PSTOPO_PSTOP3 0x3 +#define PSTOPO_PSTOP2 0x2 +#define PSTOPO_PSTOP1 0x1 + +static void __iomem *smc1_base; + +int imx7ulp_set_lpm(enum imx7ulp_cpu_pwr_mode mode) +{ + u32 smc_ctrl = readl_relaxed(smc1_base + SMC_PMCTRL); + + smc_ctrl &= ~(BM_PMCTRL_RUNM | BM_PMCTRL_STOPM | BM_PMCTRL_PSTOPO); + + switch (mode) { + case RUN: + /* system/bus clock enabled */ + smc_ctrl |= PSTOPO_PSTOP3 << BP_PMCTRL_PSTOPO; + break; + case WAIT: + /* system clock disabled, bus clock enabled */ + smc_ctrl |= PSTOPO_PSTOP2 << BP_PMCTRL_PSTOPO; + break; + case STOP: + /* system/bus clock disabled */ + smc_ctrl |= PSTOPO_PSTOP1 << BP_PMCTRL_PSTOPO; + break; + default: + return -EINVAL; + } + + writel_relaxed(smc_ctrl, smc1_base + SMC_PMCTRL); + + return 0; +} void __init imx7ulp_pm_init(void) { struct device_node *np; - void __iomem *smc1_base; np = of_find_compatible_node(NULL, NULL, "fsl,imx7ulp-smc1"); smc1_base = of_iomap(np, 0); WARN_ON(!smc1_base); - /* Partial Stop mode 3 with system/bus clock enabled */ - writel_relaxed(PSTOPO_PSTOP3 << BP_PMCTRL_PSTOPO, - smc1_base + SMC_PMCTRL); + imx7ulp_set_lpm(RUN); }