From patchwork Fri Aug 31 03:52:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ran Wang X-Patchwork-Id: 964278 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 421m6Q5CGzz9rvt for ; Fri, 31 Aug 2018 14:07:42 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 421m6Q3QyPzF36k for ; Fri, 31 Aug 2018 14:07:42 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nxp.com (client-ip=92.121.34.21; helo=inva021.nxp.com; envelope-from=ran.wang_1@nxp.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 421m044703zF37x for ; Fri, 31 Aug 2018 14:02:12 +1000 (AEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 5EE842000AD; Fri, 31 Aug 2018 05:55:38 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 6A05720000C; Fri, 31 Aug 2018 05:55:34 +0200 (CEST) Received: from titan.ap.freescale.net (TITAN.ap.freescale.net [10.192.208.233]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 6EAC9402F0; Fri, 31 Aug 2018 11:55:29 +0800 (SGT) From: Ran Wang To: Leo Li , Rob Herring , Mark Rutland Subject: [PATCH 1/3] soc: fsl: add Platform PM driver QorIQ platforms Date: Fri, 31 Aug 2018 11:52:17 +0800 Message-Id: <20180831035219.31619-1-ran.wang_1@nxp.com> X-Mailer: git-send-email 2.14.1 X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Ran Wang , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This driver is to provide a independent framework for PM service provider and consumer to configure system level wake up feature. For example, RCPM driver could register a callback function on this platform first, and Flex timer driver who want to enable timer wake up feature, will call generic API provided by this platform driver, and then it will trigger RCPM driver to do it. The benefit is to isolate the user and service, such as flex timer driver will not have to know the implement details of wakeup function it require. Besides, it is also easy for service side to upgrade its logic when design is changed and remain user side unchanged. Signed-off-by: Ran Wang --- drivers/soc/fsl/Kconfig | 14 +++++ drivers/soc/fsl/Makefile | 1 + drivers/soc/fsl/plat_pm.c | 144 +++++++++++++++++++++++++++++++++++++++++++++ include/soc/fsl/plat_pm.h | 22 +++++++ 4 files changed, 181 insertions(+), 0 deletions(-) create mode 100644 drivers/soc/fsl/plat_pm.c create mode 100644 include/soc/fsl/plat_pm.h diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig index 7a9fb9b..6517412 100644 --- a/drivers/soc/fsl/Kconfig +++ b/drivers/soc/fsl/Kconfig @@ -16,3 +16,17 @@ config FSL_GUTS Initially only reading SVR and registering soc device are supported. Other guts accesses, such as reading RCW, should eventually be moved into this driver as well. + +config FSL_PLAT_PM + bool "Freescale platform PM framework" + help + This driver is to provide a independent framework for PM service + provider and consumer to configure system level wake up feature. For + example, RCPM driver could register a callback function on this + platform first, and Flex timer driver who want to enable timer wake + up feature, will call generic API provided by this platform driver, + and then it will trigger RCPM driver to do it. The benefit is to + isolate the user and service, such as flex timer driver will not + have to know the implement details of wakeup function it require. + Besides, it is also easy for service side to upgrade its logic when + design changed and remain user side unchanged. diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile index 44b3beb..8f9db23 100644 --- a/drivers/soc/fsl/Makefile +++ b/drivers/soc/fsl/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_FSL_DPAA) += qbman/ obj-$(CONFIG_QUICC_ENGINE) += qe/ obj-$(CONFIG_CPM) += qe/ obj-$(CONFIG_FSL_GUTS) += guts.o +obj-$(CONFIG_FSL_PLAT_PM) += plat_pm.o diff --git a/drivers/soc/fsl/plat_pm.c b/drivers/soc/fsl/plat_pm.c new file mode 100644 index 0000000..19ea14e --- /dev/null +++ b/drivers/soc/fsl/plat_pm.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// plat_pm.c - Freescale platform PM framework +// +// Copyright 2018 NXP +// +// Author: Ran Wang , + +#include +#include +#include +#include +#include +#include + + +struct plat_pm_t { + struct list_head node; + fsl_plat_pm_handle handle; + void *handle_priv; + spinlock_t lock; +}; + +static struct plat_pm_t plat_pm; + +// register_fsl_platform_wakeup_source - Register callback function to plat_pm +// @handle: Pointer to handle PM feature requirement +// @handle_priv: Handler specific data struct +// +// Return 0 on success other negative errno +int register_fsl_platform_wakeup_source(fsl_plat_pm_handle handle, + void *handle_priv) +{ + struct plat_pm_t *p; + unsigned long flags; + + if (!handle) { + pr_err("FSL plat_pm: Handler invalid, reject\n"); + return -EINVAL; + } + + p = kmalloc(sizeof(*p), GFP_KERNEL); + if (!p) + return -ENOMEM; + + p->handle = handle; + p->handle_priv = handle_priv; + + spin_lock_irqsave(&plat_pm.lock, flags); + list_add_tail(&p->node, &plat_pm.node); + spin_unlock_irqrestore(&plat_pm.lock, flags); + + return 0; +} +EXPORT_SYMBOL_GPL(register_fsl_platform_wakeup_source); + +// Deregister_fsl_platform_wakeup_source - deregister callback function +// @handle_priv: Handler specific data struct +// +// Return 0 on success other negative errno +int deregister_fsl_platform_wakeup_source(void *handle_priv) +{ + struct plat_pm_t *p, *tmp; + unsigned long flags; + + spin_lock_irqsave(&plat_pm.lock, flags); + list_for_each_entry_safe(p, tmp, &plat_pm.node, node) { + if (p->handle_priv == handle_priv) { + list_del(&p->node); + kfree(p); + } + } + spin_unlock_irqrestore(&plat_pm.lock, flags); + return 0; +} +EXPORT_SYMBOL_GPL(deregister_fsl_platform_wakeup_source); + +// fsl_platform_wakeup_config - Configure wakeup source by calling handlers +// @dev: pointer to user's device struct +// @flag: to tell enable or disable wakeup source +// +// Return 0 on success other negative errno +int fsl_platform_wakeup_config(struct device *dev, bool flag) +{ + struct plat_pm_t *p; + int ret; + bool success_handled; + unsigned long flags; + + success_handled = false; + + // Will consider success if at least one callback return 0. + // Also, rest handles still get oppertunity to be executed + spin_lock_irqsave(&plat_pm.lock, flags); + list_for_each_entry(p, &plat_pm.node, node) { + if (p->handle) { + ret = p->handle(dev, flag, p->handle_priv); + if (!ret) + success_handled = true; + else if (ret != -ENODEV) { + pr_err("FSL plat_pm: Failed to config wakeup source:%d\n", ret); + return ret; + } + } else + pr_warn("FSL plat_pm: Invalid handler detected, skip\n"); + } + spin_unlock_irqrestore(&plat_pm.lock, flags); + + if (success_handled == false) { + pr_err("FSL plat_pm: Cannot find the matchhed handler for wakeup source config\n"); + return -ENODEV; + } + + return 0; +} + +// fsl_platform_wakeup_enable - Enable wakeup source +// @dev: pointer to user's device struct +// +// Return 0 on success other negative errno +int fsl_platform_wakeup_enable(struct device *dev) +{ + return fsl_platform_wakeup_config(dev, true); +} +EXPORT_SYMBOL_GPL(fsl_platform_wakeup_enable); + +// fsl_platform_wakeup_disable - Disable wakeup source +// @dev: pointer to user's device struct +// +// Return 0 on success other negative errno +int fsl_platform_wakeup_disable(struct device *dev) +{ + return fsl_platform_wakeup_config(dev, false); +} +EXPORT_SYMBOL_GPL(fsl_platform_wakeup_disable); + +static int __init fsl_plat_pm_init(void) +{ + spin_lock_init(&plat_pm.lock); + INIT_LIST_HEAD(&plat_pm.node); + return 0; +} + +core_initcall(fsl_plat_pm_init); diff --git a/include/soc/fsl/plat_pm.h b/include/soc/fsl/plat_pm.h new file mode 100644 index 0000000..bbe151e --- /dev/null +++ b/include/soc/fsl/plat_pm.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// plat_pm.h - Freescale platform PM Header +// +// Copyright 2018 NXP +// +// Author: Ran Wang , + +#ifndef __FSL_PLAT_PM_H +#define __FSL_PLAT_PM_H + +typedef int (*fsl_plat_pm_handle)(struct device *dev, bool flag, + void *handle_priv); + +int register_fsl_platform_wakeup_source(fsl_plat_pm_handle handle, + void *handle_priv); +int deregister_fsl_platform_wakeup_source(void *handle_priv); +int fsl_platform_wakeup_config(struct device *dev, bool flag); +int fsl_platform_wakeup_enable(struct device *dev); +int fsl_platform_wakeup_disable(struct device *dev); + +#endif // __FSL_PLAT_PM_H From patchwork Fri Aug 31 03:52:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ran Wang X-Patchwork-Id: 964276 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 421m1q2cqfz9s2P for ; Fri, 31 Aug 2018 14:03:43 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 421m1q03sczF38L for ; Fri, 31 Aug 2018 14:03:43 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nxp.com (client-ip=92.121.34.21; helo=inva021.nxp.com; envelope-from=ran.wang_1@nxp.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com X-Greylist: delayed 382 seconds by postgrey-1.36 at bilbo; Fri, 31 Aug 2018 14:02:12 AEST Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 421m043yNSzF37t for ; Fri, 31 Aug 2018 14:02:12 +1000 (AEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 22584200075; Fri, 31 Aug 2018 05:55:39 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 5D5DD200063; Fri, 31 Aug 2018 05:55:35 +0200 (CEST) Received: from titan.ap.freescale.net (TITAN.ap.freescale.net [10.192.208.233]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 60E0B402FB; Fri, 31 Aug 2018 11:55:30 +0800 (SGT) From: Ran Wang To: Leo Li , Rob Herring , Mark Rutland Subject: [PATCH 2/3] Documentation: dt: binding: fsl: update property description for RCPM Date: Fri, 31 Aug 2018 11:52:18 +0800 Message-Id: <20180831035219.31619-2-ran.wang_1@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180831035219.31619-1-ran.wang_1@nxp.com> References: <20180831035219.31619-1-ran.wang_1@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Ran Wang , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add property 'big-endian' and supportted IP's configuration info. Remove property 'fsl,#rcpm-wakeup-cell'. Signed-off-by: Ran Wang --- Documentation/devicetree/bindings/soc/fsl/rcpm.txt | 42 ++++++------------- 1 files changed, 13 insertions(+), 29 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt index e284e4e..7fc630a 100644 --- a/Documentation/devicetree/bindings/soc/fsl/rcpm.txt +++ b/Documentation/devicetree/bindings/soc/fsl/rcpm.txt @@ -5,8 +5,6 @@ and power management. Required properites: - reg : Offset and length of the register set of the RCPM block. - - fsl,#rcpm-wakeup-cells : The number of IPPDEXPCR register cells in the - fsl,rcpm-wakeup property. - compatible : Must contain a chip-specific RCPM block compatible string and (if applicable) may contain a chassis-version RCPM compatible string. Chip-specific strings are of the form "fsl,-rcpm", @@ -27,37 +25,23 @@ Chassis Version Example Chips --------------- ------------------------------- 1.0 p4080, p5020, p5040, p2041, p3041 2.0 t4240, b4860, b4420 -2.1 t1040, ls1021 +2.1 t1040, ls1021, ls1012 + +Optional properties: + - big-endian : Indicate RCPM registers is big-endian. A RCPM node + that doesn't have this property will be regarded as little-endian. + - : This string + is referred by RCPM driver to judge if the consumer (such as flex timer) + is able to be regards as wakeup source or not, such as 'fsl,ls1012a-ftm'. + Further, this property will carry the bit mask info to control + coresponding wake up source. Example: The RCPM node for T4240: rcpm: global-utilities@e2000 { compatible = "fsl,t4240-rcpm", "fsl,qoriq-rcpm-2.0"; reg = <0xe2000 0x1000>; - fsl,#rcpm-wakeup-cells = <2>; - }; - -* Freescale RCPM Wakeup Source Device Tree Bindings -------------------------------------------- -Required fsl,rcpm-wakeup property should be added to a device node if the device -can be used as a wakeup source. - - - fsl,rcpm-wakeup: Consists of a phandle to the rcpm node and the IPPDEXPCR - register cells. The number of IPPDEXPCR register cells is defined in - "fsl,#rcpm-wakeup-cells" in the rcpm node. The first register cell is - the bit mask that should be set in IPPDEXPCR0, and the second register - cell is for IPPDEXPCR1, and so on. - - Note: IPPDEXPCR(IP Powerdown Exception Control Register) provides a - mechanism for keeping certain blocks awake during STANDBY and MEM, in - order to use them as wake-up sources. - -Example: - lpuart0: serial@2950000 { - compatible = "fsl,ls1021a-lpuart"; - reg = <0x0 0x2950000 0x0 0x1000>; - interrupts = ; - clocks = <&sysclk>; - clock-names = "ipg"; - fsl,rcpm-wakeup = <&rcpm 0x0 0x40000000>; + big-endian; + fsl,ls1012a-ftm = <0x20000>; + fsl,pfe = <0xf0000020>; }; From patchwork Fri Aug 31 03:52:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ran Wang X-Patchwork-Id: 964277 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 421m4D4J08z9rvt for ; Fri, 31 Aug 2018 14:05:48 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 421m4D39cszF386 for ; Fri, 31 Aug 2018 14:05:48 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nxp.com (client-ip=92.121.34.21; helo=inva021.nxp.com; envelope-from=ran.wang_1@nxp.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 421m04447LzF37w for ; Fri, 31 Aug 2018 14:02:12 +1000 (AEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 45AC2200063; Fri, 31 Aug 2018 05:55:40 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 4EE042000A0; Fri, 31 Aug 2018 05:55:36 +0200 (CEST) Received: from titan.ap.freescale.net (TITAN.ap.freescale.net [10.192.208.233]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 53AFE4030C; Fri, 31 Aug 2018 11:55:31 +0800 (SGT) From: Ran Wang To: Leo Li , Rob Herring , Mark Rutland Subject: [PATCH 3/3] soc: fsl: add RCPM driver Date: Fri, 31 Aug 2018 11:52:19 +0800 Message-Id: <20180831035219.31619-3-ran.wang_1@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180831035219.31619-1-ran.wang_1@nxp.com> References: <20180831035219.31619-1-ran.wang_1@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Ran Wang , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The NXP's QorIQ Processors based on ARM Core have RCPM module (Run Control and Power Management), which performs all device-level tasks associated with power management such as wakeup source control. This driver depends on FSL platform PM driver framework which help to isolate user and PM service provider (such as RCPM driver). Signed-off-by: Chenhui Zhao Signed-off-by: Ying Zhang Signed-off-by: Ran Wang --- drivers/soc/fsl/Kconfig | 6 ++ drivers/soc/fsl/Makefile | 1 + drivers/soc/fsl/ls-rcpm.c | 153 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+), 0 deletions(-) create mode 100644 drivers/soc/fsl/ls-rcpm.c diff --git a/drivers/soc/fsl/Kconfig b/drivers/soc/fsl/Kconfig index 6517412..882330d 100644 --- a/drivers/soc/fsl/Kconfig +++ b/drivers/soc/fsl/Kconfig @@ -30,3 +30,9 @@ config FSL_PLAT_PM have to know the implement details of wakeup function it require. Besides, it is also easy for service side to upgrade its logic when design changed and remain user side unchanged. + +config LS_RCPM + bool "Freescale RCPM support" + depends on (FSL_PLAT_PM) + help + This feature is to enable specified wakeup source for system sleep. diff --git a/drivers/soc/fsl/Makefile b/drivers/soc/fsl/Makefile index 8f9db23..43ff71a 100644 --- a/drivers/soc/fsl/Makefile +++ b/drivers/soc/fsl/Makefile @@ -7,3 +7,4 @@ obj-$(CONFIG_QUICC_ENGINE) += qe/ obj-$(CONFIG_CPM) += qe/ obj-$(CONFIG_FSL_GUTS) += guts.o obj-$(CONFIG_FSL_PLAT_PM) += plat_pm.o +obj-$(CONFIG_LS_RCPM) += ls-rcpm.o diff --git a/drivers/soc/fsl/ls-rcpm.c b/drivers/soc/fsl/ls-rcpm.c new file mode 100644 index 0000000..b0feb88 --- /dev/null +++ b/drivers/soc/fsl/ls-rcpm.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// plat_pm.c - Freescale Layerscape RCPM driver +// +// Copyright 2018 NXP +// +// Author: Ran Wang , + +#include +#include +#include +#include +#include +#include + +#define MAX_COMPATIBLE_NUM 10 + +struct rcpm_t { + struct device *dev; + void __iomem *ippdexpcr_addr; + bool big_endian; /* Big/Little endian of RCPM module */ +}; + +// rcpm_handle - Configure RCPM reg according to wake up source request +// @user_dev: pointer to user's device struct +// @flag: to enable(true) or disable(false) wakeup source +// @handle_priv: pointer to struct rcpm_t instance +// +// Return 0 on success other negative errno +static int rcpm_handle(struct device *user_dev, bool flag, void *handle_priv) +{ + struct rcpm_t *rcpm; + bool big_endian; + const char *dev_compatible_array[MAX_COMPATIBLE_NUM]; + void __iomem *ippdexpcr_addr; + u32 ippdexpcr; + u32 set_bit; + int ret, num, i; + + rcpm = handle_priv; + big_endian = rcpm->big_endian; + ippdexpcr_addr = rcpm->ippdexpcr_addr; + + num = device_property_read_string_array(user_dev, "compatible", + dev_compatible_array, MAX_COMPATIBLE_NUM); + if (num < 0) + return num; + + for (i = 0; i < num; i++) { + if (!device_property_present(rcpm->dev, + dev_compatible_array[i])) + continue; + else { + ret = device_property_read_u32(rcpm->dev, + dev_compatible_array[i], &set_bit); + if (ret) + return ret; + + if (!device_property_present(rcpm->dev, + dev_compatible_array[i])) + return -ENODEV; + else { + ret = device_property_read_u32(rcpm->dev, + dev_compatible_array[i], &set_bit); + if (ret) + return ret; + + if (big_endian) + ippdexpcr = ioread32be(ippdexpcr_addr); + else + ippdexpcr = ioread32(ippdexpcr_addr); + + if (flag) + ippdexpcr |= set_bit; + else + ippdexpcr &= ~set_bit; + + if (big_endian) { + iowrite32be(ippdexpcr, ippdexpcr_addr); + ippdexpcr = ioread32be(ippdexpcr_addr); + } else + iowrite32(ippdexpcr, ippdexpcr_addr); + + return 0; + } + } + } + + return -ENODEV; +} + +static int ls_rcpm_probe(struct platform_device *pdev) +{ + struct resource *r; + struct rcpm_t *rcpm; + + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!r) + return -ENODEV; + + rcpm = kmalloc(sizeof(*rcpm), GFP_KERNEL); + if (!rcpm) + return -ENOMEM; + + rcpm->big_endian = device_property_read_bool(&pdev->dev, "big-endian"); + + rcpm->ippdexpcr_addr = devm_ioremap_resource(&pdev->dev, r); + if (IS_ERR(rcpm->ippdexpcr_addr)) + return PTR_ERR(rcpm->ippdexpcr_addr); + + rcpm->dev = &pdev->dev; + platform_set_drvdata(pdev, rcpm); + + return register_fsl_platform_wakeup_source(rcpm_handle, rcpm); +} + +static int ls_rcpm_remove(struct platform_device *pdev) +{ + struct rcpm_t *rcpm; + + rcpm = platform_get_drvdata(pdev); + deregister_fsl_platform_wakeup_source(rcpm); + kfree(rcpm); + + return 0; +} + +static const struct of_device_id ls_rcpm_of_match[] = { + { .compatible = "fsl,qoriq-rcpm-2.1", }, + {} +}; +MODULE_DEVICE_TABLE(of, ls_rcpm_of_match); + +static struct platform_driver ls_rcpm_driver = { + .driver = { + .name = "ls-rcpm", + .of_match_table = ls_rcpm_of_match, + }, + .probe = ls_rcpm_probe, + .remove = ls_rcpm_remove, +}; + +static int __init ls_rcpm_init(void) +{ + return platform_driver_register(&ls_rcpm_driver); +} +subsys_initcall(ls_rcpm_init); + +static void __exit ls_rcpm_exit(void) +{ + platform_driver_unregister(&ls_rcpm_driver); +} +module_exit(ls_rcpm_exit);