Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1804609imu; Fri, 14 Dec 2018 00:27:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/W8ZAZhwKWf/X4VeGAIA3G7EEe6GsOhl3Rf/IRiYl86NQcj2gcYjmhGJBr9gPDzkn5DBMvr X-Received: by 2002:a17:902:9a98:: with SMTP id w24mr2012939plp.213.1544776059666; Fri, 14 Dec 2018 00:27:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544776059; cv=none; d=google.com; s=arc-20160816; b=yqe33MfMJgNKy26u1xQnnxGXNMzAtF9dEoXtI5PJqEgPGuNsu0NtYM7oQI+/zxG4K6 7kKM/daTMzbRCj9KX72R0sJMBujYPBGCPRpeWQlzjm63kUAUPtg6qEkRUF9kin4zkc8o jK4kpjOmF4TujzTG7+wbNzj8FRiWL5L5eYTxEQDPaPYFuVxUSUIsfG0mgqFRmNeccQqo P1jaWECcxGb0OcgWXMdc6ileIubT9D+B+FcJNTEMNsQfJw1CG/06Y50jnntbkdcJ2853 8lXsCSzZSSPmER7M8MduTnt/0/N3W9wXCrp2+khhcBbuNx0lzs9DVgVFicYSdtFUPM07 y8Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:message-id:date:thread-index:thread-topic:subject :cc:to:from:dkim-signature; bh=FhY+LIcWiDlLbiDIn9klntQJRX5msaT2LNgrzAw0Jxc=; b=VP0dChgdFJ2cwPDzchYw+/y6y9lIm3UJMrv4aa/F0tkmLWhZYwjRzwf3824Vc5LqIk DKBAqKxzNRrYYUg1WZ5xnI/fCBKi2cf61ClbwZqxsI+6kzjAl+KQ2j3ccd1OhTk6Cgkw tiyAZXEOv6rx3Nxit13NTpfrc/8MAxmb/6iPfyl/g+KZnH06X0L9xD9+ZUgESjfQcnVm 6iyfc6grNSFy2Ndrhy2zXzJ8BefFPkpI7dMeSfarTxqCPlK8uW4Uf0R4TQWipBe2T6Rz okIO4YRkilZuV3B46u4weHAVGHYebNrHNIWze58P0hyZWQhjrfOdzAKWhlsSOLB40RBU 3cgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=PFvJvwqt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si3506162plq.25.2018.12.14.00.27.24; Fri, 14 Dec 2018 00:27:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector1 header.b=PFvJvwqt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728296AbeLNI01 (ORCPT + 99 others); Fri, 14 Dec 2018 03:26:27 -0500 Received: from mail-eopbgr80083.outbound.protection.outlook.com ([40.107.8.83]:13435 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726520AbeLNI01 (ORCPT ); Fri, 14 Dec 2018 03:26:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FhY+LIcWiDlLbiDIn9klntQJRX5msaT2LNgrzAw0Jxc=; b=PFvJvwqtLpf7In5f8lvLEErGPY7xfBd7f99zcHEEt4ogTGrEFS6QHNBMNmdmrRdwx+lWo2eE/iBI2imarCv15JPb8zQ+BmWDjOviTvphhhWbm7pLi1qYBDoQ3bE6mqB3bXLmGIcaPeMmMO2CVBS/BVki1R1+UbVZC6O1IwLEnXo= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (52.134.72.18) by DB3PR0402MB3691.eurprd04.prod.outlook.com (52.134.66.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.19; Fri, 14 Dec 2018 08:23:25 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::adf8:f49d:deb4:58fd]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::adf8:f49d:deb4:58fd%3]) with mapi id 15.20.1425.021; Fri, 14 Dec 2018 08:23:25 +0000 From: Anson Huang To: "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , Fabio Estevam , "linux@armlinux.org.uk" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" CC: dl-linux-imx Subject: [PATCH] ARM: imx: add i.MX7ULP cpuidle support Thread-Topic: [PATCH] ARM: imx: add i.MX7ULP cpuidle support Thread-Index: AQHUk4ZIRjPFoid9+UiCQ98N5HjNIw== Date: Fri, 14 Dec 2018 08:23:25 +0000 Message-ID: <1544775444-31544-1-git-send-email-Anson.Huang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK0PR03CA0017.apcprd03.prod.outlook.com (2603:1096:203:2e::29) To DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anson.huang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DB3PR0402MB3691;6:OX1GQvuKnCCopnvRqbng9UkQyO46FzDR+QVhD/EjkNwcdbVbcifhGvcbTdMlfs4M4zDzODx1k5PIyzYPWOyiIAhWsYOSoXcv3HOPOYYYIvGpLqRiyogkq/12nidx3FxPoAdDrgWUlZYmF5XZiHihVYHl0sPqovLJkGoiFdxjr0Xd5sB5SdllF0biPxHVeduogfBX7IzBvCw5MDmFqPsGHaAFN45OmBj3mb22odyEZIFxvte0vhIcfsV5RdVPO3VDW1g9tm4A5Eppuw6I1hmt+wH3ABKvkg5diWJnkTF734Pyugf13wbjxt8mGJF35iSCATCGSk4ap/AZRlDyI399nHzKxPeRP2gS8hwR3GiQQT5nUf8VUhSVCnLneaEuw1g2cCxPVddSXtXyftKgIbjYdGUX0z0q8vFtGahA+U9m6nSyIxH/eiRskrID8K04RVfuXa1KT8IVmombn/jZKG7oJw==;5:IGsZYAErq6whh+qJ+gimo0lOoCINzFFRta5PYx6ppw1jYZKnxfNneJL3cHnIhyNwDe3FoHnytxJZodIZvGZks97rBeBBI9AckKAUTvutqG8ZI81MrZmCkNjrabMesSBw3bZGyu2XjRVV6rAWL4XJoROF/cR1IOEd/9kpO81TD7w=;7:e4FJPWxPRMLR/hq9kIa8sF5RhRhu6qortNx+5IAd/s6TeMj/qNa/A4W+itofnG+oUJwKx3GDQKFLQ7uc7b0jyAJLHbHsNipCvpjqACTzaNwPt7UCKQBl8ylhN625dJa39wG1cfyQg8eHVB6kRER7WA== x-ms-office365-filtering-correlation-id: 45671085-7879-4388-5295-08d6619d6ac4 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:DB3PR0402MB3691; x-ms-traffictypediagnostic: DB3PR0402MB3691: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231475)(944501520)(52105112)(93006095)(93001095)(3002001)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(201708071742011)(7699051)(76991095);SRVR:DB3PR0402MB3691;BCL:0;PCL:0;RULEID:;SRVR:DB3PR0402MB3691; x-forefront-prvs: 08864C38AC x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(366004)(39860400002)(136003)(346002)(376002)(189003)(199004)(4326008)(316002)(110136005)(256004)(14444005)(66066001)(106356001)(97736004)(105586002)(71190400001)(478600001)(25786009)(71200400001)(14454004)(68736007)(2501003)(7736002)(305945005)(5660300001)(50226002)(36756003)(8936002)(8676002)(81156014)(81166006)(476003)(6506007)(386003)(486006)(2616005)(86362001)(575784001)(102836004)(2201001)(6512007)(6436002)(2906002)(6486002)(6116002)(3846002)(26005)(186003)(99286004)(52116002)(53936002);DIR:OUT;SFP:1101;SCL:1;SRVR:DB3PR0402MB3691;H:DB3PR0402MB3916.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: IXby0+1I9DPKyhDaNd0UKXq0yQe+7E6vYEvKU0Wn5/sBJ4pmYitf5ZBfts3vDCR7zsaUVzlzc1EV0tzdUoRp64rA4a8iIGvoQVtM71rq++1xTs951wD3g/mfKN4gt6rYFBRfTbYxNN733Aeka94oNFV1uNA/WqaaMeHqJoYur2h52TXgWBWvMPDzmV4Hs1JaV4pM5CMufF6Zoe482Pu2mrlFXLCK0p45UpdM5ibRcYsAFAEbPo8nJxLbnPvIMwFI15Cq4nHIdEkApA86FlUfP3Euk5pH4VSoSg22/sZrAyV5KqVXgwZwbhtvI0EbKJ3y spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45671085-7879-4388-5295-08d6619d6ac4 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Dec 2018 08:23:25.3368 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0402MB3691 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds cpuidle support for i.MX7ULP, 3 cpuidle states supported as below: 1. WFI, just ARM wfi; 2. WAIT mode, mapped to SoC's partial stop mode #3; 3. STOP mode, mapped to SoC's partial stop mode #1. In WAIT mode, system clock and bus clock will be enabled; In STOP mode, system clock and bus clock will be disabled. Signed-off-by: Anson Huang --- arch/arm/mach-imx/Makefile | 1 + arch/arm/mach-imx/common.h | 10 +++++++ arch/arm/mach-imx/cpuidle-imx7ulp.c | 60 +++++++++++++++++++++++++++++++++= ++++ arch/arm/mach-imx/cpuidle.h | 5 ++++ arch/arm/mach-imx/mach-imx7ulp.c | 7 +++++ arch/arm/mach-imx/pm-imx7ulp.c | 49 ++++++++++++++++++++++++++---- 6 files changed, 127 insertions(+), 5 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 8af2f7e..12aa44a 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_SOC_IMX6SL) +=3D cpuidle-imx6sl.o obj-$(CONFIG_SOC_IMX6SLL) +=3D cpuidle-imx6sx.o obj-$(CONFIG_SOC_IMX6SX) +=3D cpuidle-imx6sx.o obj-$(CONFIG_SOC_IMX6UL) +=3D cpuidle-imx6sx.o +obj-$(CONFIG_SOC_IMX7ULP) +=3D cpuidle-imx7ulp.o endif =20 ifdef CONFIG_SND_IMX_SOC diff --git a/arch/arm/mach-imx/common.h b/arch/arm/mach-imx/common.h index bc915e5..a87fab1 100644 --- a/arch/arm/mach-imx/common.h +++ b/arch/arm/mach-imx/common.h @@ -72,6 +72,15 @@ enum mxc_cpu_pwr_mode { STOP_POWER_OFF, /* STOP + SRPG */ }; =20 +enum ulp_cpu_pwr_mode { + HSRUN, /* High speed run mode */ + RUN, /* Run mode */ + WAIT, /* Wait mode */ + STOP, /* Stop mode */ + VLPS, /* Very low power stop mode */ + VLLS, /* very low leakage stop mode */ +}; + void imx_enable_cpu(int cpu, bool enable); void imx_set_cpu_jump(int cpu, void *jump_addr); u32 imx_get_cpu_arg(int cpu); @@ -98,6 +107,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 ulp_cpu_pwr_mode mode); =20 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/cpuidl= e-imx7ulp.c new file mode 100644 index 0000000..a59df93 --- /dev/null +++ b/arch/arm/mach-imx/cpuidle-imx7ulp.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * Copyright 2017-2018 NXP + * Anson Huang + */ + +#include +#include +#include + +#include "common.h" +#include "cpuidle.h" + +static int imx7ulp_enter_wait(struct cpuidle_device *dev, + struct cpuidle_driver *drv, int index) +{ + if (index =3D=3D 1) + imx7ulp_set_lpm(WAIT); + else + imx7ulp_set_lpm(STOP); + + cpu_do_idle(); + + imx7ulp_set_lpm(RUN); + + return index; +} + +static struct cpuidle_driver imx7ulp_cpuidle_driver =3D { + .name =3D "imx7ulp_cpuidle", + .owner =3D THIS_MODULE, + .states =3D { + /* WFI */ + ARM_CPUIDLE_WFI_STATE, + /* WAIT */ + { + .exit_latency =3D 50, + .target_residency =3D 75, + .enter =3D imx7ulp_enter_wait, + .name =3D "WAIT", + .desc =3D "PSTOP2", + }, + /* STOP */ + { + .exit_latency =3D 100, + .target_residency =3D 150, + .enter =3D imx7ulp_enter_wait, + .name =3D "STOP", + .desc =3D "PSTOP1", + }, + }, + .state_count =3D 3, + .safe_state_index =3D 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-imx7= ulp.c index 16b295b..95efb2d 100644 --- a/arch/arm/mach-imx/mach-imx7ulp.c +++ b/arch/arm/mach-imx/mach-imx7ulp.c @@ -12,6 +12,7 @@ #include =20 #include "common.h" +#include "cpuidle.h" #include "hardware.h" =20 #define SIM_JTAG_ID_REG 0x8c @@ -64,7 +65,13 @@ static const char *const imx7ulp_dt_compat[] __initconst= =3D { NULL, }; =20 +static void __init imx7ulp_init_late(void) +{ + imx7ulp_cpuidle_init(); +} + DT_MACHINE_START(IMX7ulp, "Freescale i.MX7ULP (Device Tree)") .init_machine =3D imx7ulp_init_machine, .dt_compat =3D imx7ulp_dt_compat, + .init_late =3D imx7ulp_init_late, MACHINE_END diff --git a/arch/arm/mach-imx/pm-imx7ulp.c b/arch/arm/mach-imx/pm-imx7ulp.= c index cf6a380..9551e1f 100644 --- a/arch/arm/mach-imx/pm-imx7ulp.c +++ b/arch/arm/mach-imx/pm-imx7ulp.c @@ -9,21 +9,60 @@ #include #include =20 +#include "common.h" + #define SMC_PMCTRL 0x10 #define BP_PMCTRL_PSTOPO 16 #define PSTOPO_PSTOP3 0x3 +#define PSTOPO_PSTOP2 0x2 +#define PSTOPO_PSTOP1 0x1 +#define BP_PMCTRL_RUNM 8 +#define RUNM_RUN 0 +#define BP_PMCTRL_STOPM 0 +#define STOPM_STOP 0 + +#define BM_PMCTRL_PSTOPO (3 << BP_PMCTRL_PSTOPO) +#define BM_PMCTRL_RUNM (3 << BP_PMCTRL_RUNM) +#define BM_PMCTRL_STOPM (7 << BP_PMCTRL_STOPM) + +static void __iomem *smc1_base; + +int imx7ulp_set_lpm(enum ulp_cpu_pwr_mode mode) +{ + u32 val =3D readl_relaxed(smc1_base + SMC_PMCTRL); + + /* clear all */ + val &=3D ~(BM_PMCTRL_RUNM | BM_PMCTRL_STOPM | BM_PMCTRL_PSTOPO); + + switch (mode) { + case RUN: + /* system/bus clock enabled */ + val |=3D PSTOPO_PSTOP3 << BP_PMCTRL_PSTOPO; + break; + case WAIT: + /* system clock disabled, bus clock enabled */ + val |=3D PSTOPO_PSTOP2 << BP_PMCTRL_PSTOPO; + break; + case STOP: + /* system/bus clock disabled */ + val |=3D PSTOPO_PSTOP1 << BP_PMCTRL_PSTOPO; + break; + default: + return -EINVAL; + } + + writel_relaxed(val, smc1_base + SMC_PMCTRL); + + return 0; +} =20 void __init imx7ulp_pm_init(void) { struct device_node *np; - void __iomem *smc1_base; =20 np =3D of_find_compatible_node(NULL, NULL, "fsl,imx7ulp-smc1"); smc1_base =3D of_iomap(np, 0); WARN_ON(!smc1_base); =20 - /* Partial Stop mode 3 with system/bus clock enabled */ - writel_relaxed(PSTOPO_PSTOP3 << BP_PMCTRL_PSTOPO, - smc1_base + SMC_PMCTRL); - iounmap(smc1_base); + imx7ulp_set_lpm(RUN); } --=20 2.7.4