From patchwork Wed Oct 17 07:24:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aisheng Dong X-Patchwork-Id: 10644811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEDE01508 for ; Wed, 17 Oct 2018 07:24:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96A902880A for ; Wed, 17 Oct 2018 07:24:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AA392A3D6; Wed, 17 Oct 2018 07:24:55 +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 BD69C2A370 for ; Wed, 17 Oct 2018 07:24:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727451AbeJQPTN (ORCPT ); Wed, 17 Oct 2018 11:19:13 -0400 Received: from mail-eopbgr10064.outbound.protection.outlook.com ([40.107.1.64]:56384 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727430AbeJQPTN (ORCPT ); Wed, 17 Oct 2018 11:19:13 -0400 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=icLts82HiDfHZLPDFFvbFawde+9issdPTKlQchiEvHA=; b=TCSZXwDyFEZOtLZHpYDyKKi9AEXF6mdFzbYGOrMktjTJObRd3eTcsz6qWQNnMNCgrlvB5XCB83HYIVpk0WdWsOjfXXBTkcuJbtACAugMzza4KHda3Q5OxH3/G3GUcZzCX7hJkSL+rYZ2abCkWXGAdeLjmx+9wl0YrTjCW7Zi2YE= Received: from AM0PR04MB4211.eurprd04.prod.outlook.com (52.134.126.21) by AM0PR04MB4642.eurprd04.prod.outlook.com (52.135.149.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.23; Wed, 17 Oct 2018 07:24:48 +0000 Received: from AM0PR04MB4211.eurprd04.prod.outlook.com ([fe80::25a0:3167:d718:91c1]) by AM0PR04MB4211.eurprd04.prod.outlook.com ([fe80::25a0:3167:d718:91c1%3]) with mapi id 15.20.1228.032; Wed, 17 Oct 2018 07:24:48 +0000 From: "A.s. Dong" To: "linux-arm-kernel@lists.infradead.org" CC: "dongas86@gmail.com" , "kernel@pengutronix.de" , "shawnguo@kernel.org" , Fabio Estevam , dl-linux-imx , "rjw@rjwysocki.net" , "ulf.hansson@linaro.org" , "khilman@kernel.org" , "linux-pm@vger.kernel.org" , "A.s. Dong" Subject: [PATCH V6 3/3] firmware: imx: add SCU power domain driver Thread-Topic: [PATCH V6 3/3] firmware: imx: add SCU power domain driver Thread-Index: AQHUZep8XBt2mvFEk0KI47ISD3yJKA== Date: Wed, 17 Oct 2018 07:24:48 +0000 Message-ID: <1539760797-12991-4-git-send-email-aisheng.dong@nxp.com> References: <1539760797-12991-1-git-send-email-aisheng.dong@nxp.com> In-Reply-To: <1539760797-12991-1-git-send-email-aisheng.dong@nxp.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: HK0PR03CA0092.apcprd03.prod.outlook.com (2603:1096:203:72::32) To AM0PR04MB4211.eurprd04.prod.outlook.com (2603:10a6:208:66::21) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aisheng.dong@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;AM0PR04MB4642;6:SHdSei3j6AGNFUD7N30dt7idSHkt67Q+30awa32yPyjQGt2cRRAPoW5N/cVnUXsSYRzm4XHWYC4fbU9pufY8EgaFaTvjo+6UafO0sIXQONpzKd5EhfodKulkhluQhtDkZl+Xwq5CHfuwtK1kwBQ5Dl0ZiuWR83kWnECAXwVLxULkyUGnwlBIKQZzWd/Qxmiz2hdmTsT47OoODzED4NlSsINqRujeAO0gq044ITqRHHz30t67MUi2y4+vdQfqF7RBn/ZQdyf24TjE7h/r3EvNiMDO2JeuA86/zrksiHkrHJsJp5LIPery/Uh6VjjWM4lcnROR4e00SlkDTshOLXecP5G3apk+bbDAYEqJ63zJB1JYaGfEEwFwDQL7fZ0BHUrTaKKfoqP2YoVOo+ZQZK4cBKNwwPgi/sCJYDEvGxUuf9IjAQVCfvyVxrcPPsaE6KQgQfLcGGLUnY2QJf5fNF5gpA==;5:QNgFXTMPN7EljNkb5rLUpn1Z1AjXCMI1bnbVvKZRLnSkHiwaZzvaGxmDfCOkzkQ0YPQDfP5mPujxngL9RCr2YJxidRgx8Ze6A7tpr3iV6I3LYvIbbTZMEAgtGmKOeVy7v3X76ZzLIL/TzZpQ6U4R0hwc7cbiYBC/pHyEd9LbaoM=;7:1YrRrQ9w4C9WOK3rFdjUqAGHQ61ShHNF3hI/ev75u+R54qSoMKIpOXJOe6Pzu2kIxPqzN6F8YmgQW5SCoNxQgh/Y8t1gKno9UrrCTd7htDKPweKyfG8ioK9Ig9blv28GEb2Yk4VVhdvrcRp7+YcnE5thOIKwLe49dThmRFL8TQG+suLkY4Kg347hKsbu2VUAuM/KKYKw0CNYL0IbJBstKsNy2mBWw9jS9LyKlJMr/shlS1gHra5Tp52/1pFwPfsf x-ms-office365-filtering-correlation-id: fd60945b-e92d-4cc3-186a-08d634019ead x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM0PR04MB4642; x-ms-traffictypediagnostic: AM0PR04MB4642: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(269456686620040)(9452136761055)(185117386973197); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231355)(944501410)(52105095)(6055026)(149066)(150057)(6041310)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(201708071742011)(7699051)(76991095);SRVR:AM0PR04MB4642;BCL:0;PCL:0;RULEID:;SRVR:AM0PR04MB4642; x-forefront-prvs: 08286A0BE2 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(396003)(376002)(346002)(136003)(39860400002)(189003)(54534003)(199004)(7736002)(2501003)(6512007)(4326008)(105586002)(5250100002)(5640700003)(36756003)(102836004)(305945005)(6916009)(2906002)(54906003)(3846002)(26005)(8936002)(6506007)(386003)(68736007)(6436002)(5660300001)(14444005)(256004)(25786009)(316002)(11346002)(478600001)(476003)(14454004)(81166006)(99286004)(446003)(76176011)(106356001)(66066001)(486006)(2616005)(6486002)(52116002)(81156014)(53936002)(50226002)(86362001)(2900100001)(186003)(71190400001)(8676002)(39060400002)(71200400001)(2351001)(97736004)(6116002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM0PR04MB4642;H:AM0PR04MB4211.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: pUP3xx4XLI+gI081Yr4ndSapjmjqSpqW5D1blPKga6Cj/VBQ4bnx4RH6XeJ+AaD25i2m0DuJ4IKm2UMXIR1463QwDHN/1UMu6XfPBxr8lZ94rqSjxXldUfqGnyUE6K3UuaDDCbT6lElwr8w9YF/sLEh4zdZzzcgcnnK4FT8zwW4eyzJxO6rOiuxMpA9OYnSglCiWZLW1h9Et8VXNKiJl16WpmSsBU9NM+7MT8uzF/axX3pAFjjf8nfLIwBx7s0jax1ipn/w4iFtwmDOSbXMHSKzeHL2VFQVLzojiP5Jd24xG03k9WbZ9QMVy6JIMw/akEMjdkSPu7lxVWNdtbRivM0HCkp6QMhJvU7xef/pGrvg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd60945b-e92d-4cc3-186a-08d634019ead X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Oct 2018 07:24:48.5662 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4642 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 Some i.MX SoCs contain a system controller that is responsible for controlling the state of the IPs that are present. Communication between the host processor running an OS and the system controller happens through a SCU protocol. This patch adds SCU protocol based power domains drivers. Cc: Shawn Guo Cc: Sascha Hauer Cc: Fabio Estevam Cc: "Rafael J. Wysocki" Cc: Kevin Hilman Cc: linux-pm@vger.kernel.org Reviewed-by: Ulf Hansson Signed-off-by: Dong Aisheng --- ChangeLog: v5->v6: * only compatible string name updated from fsl,scu-pd to fsl,imx8qxp-scu-pd accordingly v4->v5: * minor improvements according to Sascha's suggestions v3->v4: * update firmware headfile patch from include/soc/imx to include/linux/firmware/imx v2->v3: * name of structures/enums updated with imx_sc prefix v1->v2: * move into drivers/firmware/imx * Implement sc_pm_set_resource_power_mode() API in the driver instead of call it via SCU API according to Sascha's suggestion --- drivers/firmware/imx/Kconfig | 6 ++ drivers/firmware/imx/Makefile | 3 +- drivers/firmware/imx/scu-pd.c | 164 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/imx/scu-pd.c diff --git a/drivers/firmware/imx/Kconfig b/drivers/firmware/imx/Kconfig index b170c28..6a7a7c2 100644 --- a/drivers/firmware/imx/Kconfig +++ b/drivers/firmware/imx/Kconfig @@ -9,3 +9,9 @@ config IMX_SCU This driver manages the IPC interface between host CPU and the SCU firmware running on M4. + +config IMX_SCU_PD + bool "IMX SCU Power Domain driver" + depends on IMX_SCU + help + The System Controller Firmware (SCFW) based power domain driver. diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile index 0ac04df..1b2e15b 100644 --- a/drivers/firmware/imx/Makefile +++ b/drivers/firmware/imx/Makefile @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 -obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o +obj-$(CONFIG_IMX_SCU) += imx-scu.o misc.o +obj-$(CONFIG_IMX_SCU_PD) += scu-pd.o diff --git a/drivers/firmware/imx/scu-pd.c b/drivers/firmware/imx/scu-pd.c new file mode 100644 index 0000000..1fbf4fe --- /dev/null +++ b/drivers/firmware/imx/scu-pd.c @@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2016 Freescale Semiconductor, Inc. + * Copyright 2017~2018 NXP + * Dong Aisheng + * + * Implementation of the SCU based Power Domains + */ + +#define pr_fmt(fmt) "scu_pd: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct imx_sc_pm_domain { + struct generic_pm_domain pd; + u32 rsrc_id; +}; + +static struct imx_sc_ipc *pm_ipc_handle; + +/* SCU Power Mode Protocol definition */ +struct imx_sc_msg_req_set_resource_power_mode { + struct imx_sc_rpc_msg hdr; + u16 resource; + u8 mode; +} __packed; + +static int imx_sc_pd_power(struct generic_pm_domain *domain, bool power_on) +{ + struct imx_sc_msg_req_set_resource_power_mode msg; + struct imx_sc_rpc_msg *hdr = &msg.hdr; + struct imx_sc_pm_domain *pd; + int ret; + + pd = container_of(domain, struct imx_sc_pm_domain, pd); + + hdr->ver = IMX_SC_RPC_VERSION; + hdr->svc = (uint8_t)IMX_SC_RPC_SVC_PM; + hdr->func = (uint8_t)IMX_SC_PM_FUNC_SET_RESOURCE_POWER_MODE; + hdr->size = 2; + + msg.resource = pd->rsrc_id; + msg.mode = power_on ? IMX_SC_PM_PW_MODE_ON : IMX_SC_PM_PW_MODE_LP; + + ret = imx_scu_call_rpc(pm_ipc_handle, &msg, true); + if (ret) + pr_err("failed to power %s resource %d ret %d\n", + power_on ? "up" : "off", pd->rsrc_id, ret); + + return ret; +} + +static int imx_sc_pd_power_on(struct generic_pm_domain *domain) +{ + return imx_sc_pd_power(domain, true); +} + +static int imx_sc_pd_power_off(struct generic_pm_domain *domain) +{ + return imx_sc_pd_power(domain, false); +} + +static struct generic_pm_domain *imx_sc_pm_add_one_domain( + struct device_node *np, + struct generic_pm_domain *genpd_parent) +{ + struct imx_sc_pm_domain *imx_sc_pd; + u32 rsrc_id; + int ret; + + imx_sc_pd = kzalloc(sizeof(*imx_sc_pd), GFP_KERNEL); + if (!imx_sc_pd) + return ERR_PTR(-ENOMEM); + + if (!of_property_read_u32(np, "reg", &rsrc_id)) { + if (rsrc_id >= IMX_SC_R_LAST) { + pr_warn("%pOF: invalid rsrc id %d found", np, rsrc_id); + ret = -EINVAL; + goto err; + } + imx_sc_pd->rsrc_id = rsrc_id; + imx_sc_pd->pd.power_off = imx_sc_pd_power_off; + imx_sc_pd->pd.power_on = imx_sc_pd_power_on; + } else { + imx_sc_pd->rsrc_id = IMX_SC_R_LAST; + } + + imx_sc_pd->pd.name = np->name; + + ret = pm_genpd_init(&imx_sc_pd->pd, NULL, true); + if (ret < 0) + goto err; + + if (genpd_parent) { + ret = pm_genpd_add_subdomain(genpd_parent, &imx_sc_pd->pd); + if (ret) + goto err; + } + + ret = of_genpd_add_provider_simple(np, &imx_sc_pd->pd); + if (!ret) + return &imx_sc_pd->pd; + + pm_genpd_remove_subdomain(genpd_parent, &imx_sc_pd->pd); + +err: + pr_warn("failed to add PM domain %pOF: %d\n", np, ret); + kfree(imx_sc_pd); + return ERR_PTR(ret); +} + +static void imx_sc_pm_add_pm_domains(struct device_node *parent, + struct generic_pm_domain *genpd_parent) +{ + struct generic_pm_domain *pd; + struct device_node *np; + + for_each_child_of_node(parent, np) { + pd = imx_sc_pm_add_one_domain(np, genpd_parent); + if (!IS_ERR(pd)) + imx_sc_pm_add_pm_domains(np, pd); + } +} + +static int imx_sc_pd_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + int ret; + + ret = imx_scu_get_handle(&pm_ipc_handle); + if (ret) + return ret; + + imx_sc_pm_add_pm_domains(np, NULL); + + return 0; +} + +static const struct of_device_id imx_sc_pd_match[] = { + { .compatible = "fsl,imx8qxp-scu-pd", }, + { /* sentinel */ } +}; + +static struct platform_driver imx_sc_pd_driver = { + .driver = { + .name = "imx-scu-pd", + .of_match_table = imx_sc_pd_match, + }, + .probe = imx_sc_pd_probe, +}; +builtin_platform_driver(imx_sc_pd_driver); + +MODULE_AUTHOR("Dong Aisheng "); +MODULE_DESCRIPTION("IMX SCU Power Domain driver"); +MODULE_LICENSE("GPL v2");