All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/6] drivers: qcom: enable system low power modes for SDM845
@ 2018-08-24 20:06 Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 1/6] drivers: qcom: system_pm: add system PM client for RPMH based SoCs Raju P.L.S.S.S.N
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Raju P.L.S.S.S.N @ 2018-08-24 20:06 UTC (permalink / raw)
  To: andy.gross, david.brown, linux-arm-msm, linux-soc, linux-pm
  Cc: rnayak, bjorn.andersson, linux-kernel, lorenzo.pieralisi, rafael,
	drake, sboyd, evgreen, dianders, mka, ilina, Raju P.L.S.S.S.N

Hi,

This is an attempt at a solution to perform activities necessary while entering
deeper low power modes supported by firmware for QCOM SoCs which have hardened
IP (Resource Power Manager Hardened - RPMH) for shared resource management.

The shared resources that are no longer used, when processor enters deep idle
states, can be turned off or put to lower state via sleep requests. Clients vote
for lower resource state when application processor is asleep. These votes need
to be flushed only during entry to low power modes.

In addition to this, an always-on power domain wake-up timer present in PDC
(Power Domain Controller)  needs to be programmed so that RSC is up and running
by the time CPU has to wake-up. 

The kernel does not notify that the CPU powering down is the last CPU.
Therefore, in this series, we are doing a reference count to determine the last
CPU in the system to enter idle and use that to perform the last-man activities.
It would be optimal to do this than to flush whenever a core enters idle. The
current approach can be revisited in future if OS-initiated support becomes
available that enables certain actions to be taken when last core enters deepest
low power mode.

Apart from idle sleep, the deeper low modes can be exercised in system suspend.
As it is expected that all other cores except the core entering system suspend
will be disabled during suspend operations, the device suspend calls are
utilized to perform the required tasks.

Please review these patches. Your inputs would be greatly appreciated.

Thanks,
Raju

Dependencies:

The current series depends on patches[1][2], which add RPMH communication
support, to send shared resource request votes by clients. The patches[1][2]
also provide functions that are expected to be called by sleep manager client
during low power mode entry. The other patches[3][4][5] which fix couple of
issues are also needed. Apart from RPMH related patches, the current series
depends on knowing the next wake up timer of a CPU[6] for programing the
always-on timer present in PDC.

[1]. https://lkml.org/lkml/2018/6/20/519
[2]. https://lkml.org/lkml/2018/7/27/326
[3]. https://lkml.org/lkml/2018/7/13/358 
[4]. https://lkml.org/lkml/2018/7/19/84
[5]. https://lkml.org/lkml/2018/8/24/641
[6]. https://lkml.org/lkml/2018/6/20/800

Raju P.L.S.S.S.N (6):
  drivers: qcom: system_pm: add system PM client for RPMH based SoCs
  dt-bindings: introduce System PM bindings for Qualcomm SoCs
  drivers: qcom: system_pm: Add power management ops
  drivers: qcom: system_pm: program next wakeup to PDC timer
  drivers: qcom: rpmh: force flush new sleep/wake requests during
    suspend
  drivers: soc: system_pm: Add suspend notifier

 .../devicetree/bindings/soc/qcom/system_pm.txt     |  28 ++++
 drivers/soc/qcom/Kconfig                           |  11 ++
 drivers/soc/qcom/Makefile                          |   1 +
 drivers/soc/qcom/rpmh-internal.h                   |   1 +
 drivers/soc/qcom/rpmh.c                            |  17 +++
 drivers/soc/qcom/system_pm.c                       | 168 +++++++++++++++++++++
 include/soc/qcom/rpmh.h                            |   5 +
 7 files changed, 231 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/system_pm.txt
 create mode 100644 drivers/soc/qcom/system_pm.c

-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH RFC 1/6] drivers: qcom: system_pm: add system PM client for RPMH based SoCs
  2018-08-24 20:06 [PATCH RFC 0/6] drivers: qcom: enable system low power modes for SDM845 Raju P.L.S.S.S.N
@ 2018-08-24 20:06 ` Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 2/6] dt-bindings: introduce System PM bindings for Qualcomm SoCs Raju P.L.S.S.S.N
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Raju P.L.S.S.S.N @ 2018-08-24 20:06 UTC (permalink / raw)
  To: andy.gross, david.brown, linux-arm-msm, linux-soc, linux-pm
  Cc: rnayak, bjorn.andersson, linux-kernel, lorenzo.pieralisi, rafael,
	drake, sboyd, evgreen, dianders, mka, ilina, Raju P.L.S.S.S.N

RPMH based targets require that the sleep and wake state request votes
be sent during system low power mode entry. The votes help reduce the
power consumption when the AP is not using them. The votes sent by the
clients are cached in RPMH controller and needs to be flushed by a sleep
manager. So add system power manager client for RPMH client and invoke
RPMH flush when last core is being powered off by listening to
cpu_pm_notifications.

Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org>
---
 drivers/soc/qcom/Kconfig     | 11 ++++++
 drivers/soc/qcom/Makefile    |  1 +
 drivers/soc/qcom/system_pm.c | 82 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)
 create mode 100644 drivers/soc/qcom/system_pm.c

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index 3223084..a52abe9 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -78,6 +78,7 @@ config QCOM_RMTFS_MEM
 config QCOM_RPMH
 	bool "Qualcomm RPM-Hardened (RPMH) Communication"
 	depends on ARCH_QCOM && ARM64 && OF || COMPILE_TEST
+	select QCOM_SYSTEM_PM
 	help
 	  Support for communication with the hardened-RPM blocks in
 	  Qualcomm Technologies Inc (QTI) SoCs. RPMH communication uses an
@@ -85,6 +86,16 @@ config QCOM_RPMH
 	  of hardware components aggregate requests for these resources and
 	  help apply the aggregated state on the resource.
 
+config QCOM_SYSTEM_PM
+	bool "Qualcomm System PM"
+	depends on CPU_PM && QCOM_RPMH
+	help
+	  Support for QCOM platform system power management to perform tasks
+	  necessary while application processor votes for deeper modes so that
+	  the firmware can enter SoC level low power modes to save power.
+	  Deeper low power modes can be voted during idle power management or
+	  pm suspend state.
+
 config QCOM_SMEM
 	tristate "Qualcomm Shared Memory Manager (SMEM)"
 	depends on ARCH_QCOM
diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile
index 03d4c83..27d79d2 100644
--- a/drivers/soc/qcom/Makefile
+++ b/drivers/soc/qcom/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_QCOM_RMTFS_MEM)	+= rmtfs_mem.o
 obj-$(CONFIG_QCOM_RPMH)		+= qcom_rpmh.o
 qcom_rpmh-y			+= rpmh-rsc.o
 qcom_rpmh-y			+= rpmh.o
+obj-$(CONFIG_QCOM_SYSTEM_PM) += system_pm.o
 obj-$(CONFIG_QCOM_SMD_RPM)	+= smd-rpm.o
 obj-$(CONFIG_QCOM_SMEM) +=	smem.o
 obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
diff --git a/drivers/soc/qcom/system_pm.c b/drivers/soc/qcom/system_pm.c
new file mode 100644
index 0000000..40e5aa7
--- /dev/null
+++ b/drivers/soc/qcom/system_pm.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include <linux/cpu_pm.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+
+#include <soc/qcom/rpmh.h>
+
+static struct cpumask cpu_pm_state_mask;
+static raw_spinlock_t cpu_pm_state_lock;
+
+static struct device *sys_pm_dev;
+
+static int sys_pm_notifier(struct notifier_block *b,
+			       unsigned long cmd, void *v)
+{
+	switch (cmd) {
+	case CPU_PM_ENTER:
+		raw_spin_lock(&cpu_pm_state_lock);
+		cpumask_set_cpu(smp_processor_id(), &cpu_pm_state_mask);
+		if (cpumask_equal(&cpu_pm_state_mask, cpu_possible_mask)) {
+			if (rpmh_ctrlr_idle(sys_pm_dev)) {
+				/* Flush the sleep/wake sets */
+				rpmh_flush(sys_pm_dev);
+			} else {
+				pr_err("%s:rpmh controller is busy\n",
+						__func__);
+				raw_spin_unlock(&cpu_pm_state_lock);
+				return NOTIFY_BAD;
+			}
+		}
+		raw_spin_unlock(&cpu_pm_state_lock);
+		break;
+	case CPU_PM_EXIT:
+	case CPU_PM_ENTER_FAILED:
+		raw_spin_lock(&cpu_pm_state_lock);
+		cpumask_clear_cpu(smp_processor_id(), &cpu_pm_state_mask);
+		raw_spin_unlock(&cpu_pm_state_lock);
+		break;
+	default:
+		return NOTIFY_DONE;
+	}
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block sys_pm_notifier_block = {
+	.notifier_call = sys_pm_notifier,
+	.priority = -1, /* Should be last in the order of notifications */
+};
+
+static int sys_pm_probe(struct platform_device *pdev)
+{
+	sys_pm_dev = &pdev->dev;
+
+	if (IS_ERR_OR_NULL(sys_pm_dev)) {
+		pr_err("%s fail\n", __func__);
+		return PTR_ERR(sys_pm_dev);
+	}
+
+	raw_spin_lock_init(&cpu_pm_state_lock);
+	cpu_pm_register_notifier(&sys_pm_notifier_block);
+
+	return 0;
+}
+
+static const struct of_device_id sys_pm_drv_match[] = {
+	{ .compatible = "qcom,system-pm", },
+	{ }
+};
+
+static struct platform_driver sys_pm_driver = {
+	.probe = sys_pm_probe,
+	.driver = {
+		.name = KBUILD_MODNAME,
+		.of_match_table = sys_pm_drv_match,
+	},
+};
+builtin_platform_driver(sys_pm_driver);
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 2/6] dt-bindings: introduce System PM bindings for Qualcomm SoCs
  2018-08-24 20:06 [PATCH RFC 0/6] drivers: qcom: enable system low power modes for SDM845 Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 1/6] drivers: qcom: system_pm: add system PM client for RPMH based SoCs Raju P.L.S.S.S.N
@ 2018-08-24 20:06 ` Raju P.L.S.S.S.N
  2018-09-04 13:14   ` Rob Herring
  2018-08-24 20:06 ` [PATCH RFC 3/6] drivers: qcom: system_pm: Add power management ops Raju P.L.S.S.S.N
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Raju P.L.S.S.S.N @ 2018-08-24 20:06 UTC (permalink / raw)
  To: andy.gross, david.brown, linux-arm-msm, linux-soc, linux-pm
  Cc: rnayak, bjorn.andersson, linux-kernel, lorenzo.pieralisi, rafael,
	drake, sboyd, evgreen, dianders, mka, ilina, Raju P.L.S.S.S.N,
	devicetree

Add device binding documentation for Qualcomm Technology Inc's System PM
driver. The driver is used for managing system sleep activities that are
required when application processor is going to deepest low power mode.

Cc: devicetree@vger.kernel.org
Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org>
---
 .../devicetree/bindings/soc/qcom/system_pm.txt     | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/system_pm.txt

diff --git a/Documentation/devicetree/bindings/soc/qcom/system_pm.txt b/Documentation/devicetree/bindings/soc/qcom/system_pm.txt
new file mode 100644
index 0000000..0915760
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/qcom/system_pm.txt
@@ -0,0 +1,28 @@
+System PM
+---------
+
+System PM device handles the tasks that need to be performed during application
+processor deeper low power mode entry for QCOM SoCs which have hardened IP blocks
+combinedly called as RPMH (Resource Power Manager Hardened) for shared resource
+management. System PM is a client of APPS_RSC. Flushing the buffered requests to
+TCSs in RSC and programming the wakeup timer in PDC for timer based wakeup are
+handled by this device.
+
+The bindings for System PM is specified in the RSC section in devicetree.
+
+Properties:
+- compatible:
+	Usage: required
+	Value type: <string>
+	Definition: must be "qcom,system-pm".
+
+Example:
+
+	apps_rsc: rsc@179c0000 {
+		[...]
+		system_pm {
+			compatible = "qcom,system-pm";
+		};
+	};
+
+
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 3/6] drivers: qcom: system_pm: Add power management ops
  2018-08-24 20:06 [PATCH RFC 0/6] drivers: qcom: enable system low power modes for SDM845 Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 1/6] drivers: qcom: system_pm: add system PM client for RPMH based SoCs Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 2/6] dt-bindings: introduce System PM bindings for Qualcomm SoCs Raju P.L.S.S.S.N
@ 2018-08-24 20:06 ` Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 4/6] drivers: qcom: system_pm: program next wakeup to PDC timer Raju P.L.S.S.S.N
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Raju P.L.S.S.S.N @ 2018-08-24 20:06 UTC (permalink / raw)
  To: andy.gross, david.brown, linux-arm-msm, linux-soc, linux-pm
  Cc: rnayak, bjorn.andersson, linux-kernel, lorenzo.pieralisi, rafael,
	drake, sboyd, evgreen, dianders, mka, ilina, Raju P.L.S.S.S.N

Add suspend power management ops so that the sleep & wake resource
requests are flushed to corresponding TCS. The firmware would ensure
that the buffered requests in TCS are sent to Resource Power Manager
during entry to deepest low power modes.

Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org>
---
 drivers/soc/qcom/Kconfig     |  2 +-
 drivers/soc/qcom/system_pm.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig
index a52abe9..ac0e413 100644
--- a/drivers/soc/qcom/Kconfig
+++ b/drivers/soc/qcom/Kconfig
@@ -88,7 +88,7 @@ config QCOM_RPMH
 
 config QCOM_SYSTEM_PM
 	bool "Qualcomm System PM"
-	depends on CPU_PM && QCOM_RPMH
+	depends on CPU_PM && PM_SLEEP && QCOM_RPMH
 	help
 	  Support for QCOM platform system power management to perform tasks
 	  necessary while application processor votes for deeper modes so that
diff --git a/drivers/soc/qcom/system_pm.c b/drivers/soc/qcom/system_pm.c
index 40e5aa7..8810b84 100644
--- a/drivers/soc/qcom/system_pm.c
+++ b/drivers/soc/qcom/system_pm.c
@@ -67,6 +67,23 @@ static int sys_pm_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int sys_pm_suspend(struct device *dev)
+{
+	if (rpmh_ctrlr_idle(dev)) {
+		/* Flush the sleep/wake sets in RSC controller */
+		rpmh_flush(dev);
+	} else {
+		pr_err("%s:rpmh controller is busy\n", __func__);
+		return -EBUSY;
+	}
+
+	return 0;
+}
+
+static const struct dev_pm_ops sys_pm_dev_pm_ops = {
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(sys_pm_suspend, NULL)
+};
+
 static const struct of_device_id sys_pm_drv_match[] = {
 	{ .compatible = "qcom,system-pm", },
 	{ }
@@ -77,6 +94,7 @@ static int sys_pm_probe(struct platform_device *pdev)
 	.driver = {
 		.name = KBUILD_MODNAME,
 		.of_match_table = sys_pm_drv_match,
+		.pm = &sys_pm_dev_pm_ops,
 	},
 };
 builtin_platform_driver(sys_pm_driver);
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 4/6] drivers: qcom: system_pm: program next wakeup to PDC timer
  2018-08-24 20:06 [PATCH RFC 0/6] drivers: qcom: enable system low power modes for SDM845 Raju P.L.S.S.S.N
                   ` (2 preceding siblings ...)
  2018-08-24 20:06 ` [PATCH RFC 3/6] drivers: qcom: system_pm: Add power management ops Raju P.L.S.S.S.N
@ 2018-08-24 20:06 ` Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 5/6] drivers: qcom: rpmh: force flush new sleep/wake requests during suspend Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 6/6] drivers: soc: system_pm: Add suspend notifier Raju P.L.S.S.S.N
  5 siblings, 0 replies; 8+ messages in thread
From: Raju P.L.S.S.S.N @ 2018-08-24 20:06 UTC (permalink / raw)
  To: andy.gross, david.brown, linux-arm-msm, linux-soc, linux-pm
  Cc: rnayak, bjorn.andersson, linux-kernel, lorenzo.pieralisi, rafael,
	drake, sboyd, evgreen, dianders, mka, ilina, Raju P.L.S.S.S.N

In addition to sleep and wake request votes that need to be sent to
remote processor as part of low power mode entry, the next wake-up timer
value needs to be programmed to PDC (Power Domain Controller) which has
its own timer and is in an always on power domain. A specific control
register is provided in RSC address space for this purpose. PDC wakes-up
the RSC and sets up the resources back in active state before the
processor is woken up by a timer interrupt.

Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org>
---
 drivers/soc/qcom/system_pm.c | 61 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/drivers/soc/qcom/system_pm.c b/drivers/soc/qcom/system_pm.c
index 8810b84..1451bf8 100644
--- a/drivers/soc/qcom/system_pm.c
+++ b/drivers/soc/qcom/system_pm.c
@@ -5,15 +5,67 @@
 
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
+#include <linux/ktime.h>
 #include <linux/platform_device.h>
+#include <linux/tick.h>
 
 #include <soc/qcom/rpmh.h>
 
+#define ARCH_TIMER_HZ (19200000)
+#define PDC_TIME_VALID_SHIFT	31
+#define PDC_TIME_UPPER_MASK	0xFFFFFF
 static struct cpumask cpu_pm_state_mask;
 static raw_spinlock_t cpu_pm_state_lock;
 
 static struct device *sys_pm_dev;
 
+static uint64_t us_to_ticks(uint64_t time_us)
+{
+	uint64_t sec, nsec, time_cycles;
+
+	sec = time_us;
+	do_div(sec, USEC_PER_SEC);
+	nsec = time_us - sec * USEC_PER_SEC;
+
+	if (nsec > 0) {
+		nsec = nsec * NSEC_PER_USEC;
+		do_div(nsec, NSEC_PER_SEC);
+	}
+
+	sec += nsec;
+
+	time_cycles = (u64)sec * ARCH_TIMER_HZ;
+
+	return time_cycles;
+}
+
+static int setup_pdc_wakeup_timer(bool suspend)
+{
+	int cpu;
+	struct tcs_cmd cmd[2] = { { 0 } };
+	ktime_t next_wakeup, cpu_wakeup;
+	uint64_t wakeup_cycles = ~0U;
+
+	if (!suspend) {
+		/*
+		 * Find the next wakeup for any of the online CPUs
+		 */
+		next_wakeup = ktime_set(KTIME_SEC_MAX, 0);
+		for_each_online_cpu(cpu) {
+			cpu_wakeup = tick_nohz_get_next_wakeup(cpu);
+			if (ktime_before(cpu_wakeup, next_wakeup))
+				next_wakeup = cpu_wakeup;
+		}
+		wakeup_cycles = us_to_ticks(ktime_to_us(next_wakeup));
+	}
+
+	cmd[0].data =  (wakeup_cycles >> 32) & PDC_TIME_UPPER_MASK;
+	cmd[0].data |= 1 << PDC_TIME_VALID_SHIFT;
+	cmd[1].data = (wakeup_cycles & 0xFFFFFFFF);
+
+	return rpmh_write_pdc_data(sys_pm_dev, cmd, ARRAY_SIZE(cmd));
+}
+
 static int sys_pm_notifier(struct notifier_block *b,
 			       unsigned long cmd, void *v)
 {
@@ -25,6 +77,14 @@ static int sys_pm_notifier(struct notifier_block *b,
 			if (rpmh_ctrlr_idle(sys_pm_dev)) {
 				/* Flush the sleep/wake sets */
 				rpmh_flush(sys_pm_dev);
+				/*
+				 * The next wakeup value is converted to ticks
+				 * and copied to the Power Domain Controller
+				 * that has its own timer, which is in an
+				 * always-on power domain. The programming is
+				 * done through a separate register on the RSC
+				 */
+				setup_pdc_wakeup_timer(false);
 			} else {
 				pr_err("%s:rpmh controller is busy\n",
 						__func__);
@@ -72,6 +132,7 @@ static int sys_pm_suspend(struct device *dev)
 	if (rpmh_ctrlr_idle(dev)) {
 		/* Flush the sleep/wake sets in RSC controller */
 		rpmh_flush(dev);
+		setup_pdc_wakeup_timer(true);
 	} else {
 		pr_err("%s:rpmh controller is busy\n", __func__);
 		return -EBUSY;
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 5/6] drivers: qcom: rpmh: force flush new sleep/wake requests during suspend
  2018-08-24 20:06 [PATCH RFC 0/6] drivers: qcom: enable system low power modes for SDM845 Raju P.L.S.S.S.N
                   ` (3 preceding siblings ...)
  2018-08-24 20:06 ` [PATCH RFC 4/6] drivers: qcom: system_pm: program next wakeup to PDC timer Raju P.L.S.S.S.N
@ 2018-08-24 20:06 ` Raju P.L.S.S.S.N
  2018-08-24 20:06 ` [PATCH RFC 6/6] drivers: soc: system_pm: Add suspend notifier Raju P.L.S.S.S.N
  5 siblings, 0 replies; 8+ messages in thread
From: Raju P.L.S.S.S.N @ 2018-08-24 20:06 UTC (permalink / raw)
  To: andy.gross, david.brown, linux-arm-msm, linux-soc, linux-pm
  Cc: rnayak, bjorn.andersson, linux-kernel, lorenzo.pieralisi, rafael,
	drake, sboyd, evgreen, dianders, mka, ilina, Raju P.L.S.S.S.N

During pm suspend, newer sleep/wake requests may come as it can't be
guaranteed that system PM device suspend will be called only in the end.
After system PM does rpmh_flush, the suspend_in_progress flag is set to
enable rpmh controller to manage new sleep/wake requests if any.

Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org>
---
 drivers/soc/qcom/rpmh-internal.h |  1 +
 drivers/soc/qcom/rpmh.c          | 17 +++++++++++++++++
 include/soc/qcom/rpmh.h          |  5 +++++
 3 files changed, 23 insertions(+)

diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h
index f5359be..45bab3b 100644
--- a/drivers/soc/qcom/rpmh-internal.h
+++ b/drivers/soc/qcom/rpmh-internal.h
@@ -80,6 +80,7 @@ struct rpmh_ctrlr {
 	bool dirty;
 	struct list_head batch_cache;
 	bool in_solver_mode;
+	bool suspend_in_progress;
 };
 
 /**
diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c
index 390e779..a9bd1a0 100644
--- a/drivers/soc/qcom/rpmh.c
+++ b/drivers/soc/qcom/rpmh.c
@@ -237,6 +237,8 @@ static int __rpmh_write(const struct device *dev, enum rpmh_state state,
 		WARN_ON(irqs_disabled());
 		ret = rpmh_rsc_send_data(ctrlr_to_drv(ctrlr), &rpm_msg->msg);
 	} else {
+		if (ctrlr->suspend_in_progress)
+			rpmh_flush(dev);
 		/* Clean up our call by spoofing tx_done */
 		ret = 0;
 		rpmh_tx_done(&rpm_msg->msg, ret);
@@ -434,6 +436,8 @@ int rpmh_write_batch(const struct device *dev, enum rpmh_state state,
 
 	if (state != RPMH_ACTIVE_ONLY_STATE) {
 		cache_batch(ctrlr, req);
+		if (ctrlr->suspend_in_progress)
+			rpmh_flush(dev);
 		return 0;
 	}
 
@@ -610,3 +614,16 @@ int rpmh_ctrlr_idle(const struct device *dev)
 	return rpmh_rsc_ctrlr_is_idle(ctrlr_to_drv(ctrlr));
 }
 EXPORT_SYMBOL(rpmh_ctrlr_idle);
+
+/**
+ * rpmh_notify_suspend: Set suspend in progress flag
+ *
+ * @suspend: boolean to indicate the supend mode
+ */
+void rpmh_notify_suspend(const struct device *dev, bool suspend)
+{
+	struct rpmh_ctrlr *ctrlr = get_rpmh_ctrlr(dev);
+
+	ctrlr->suspend_in_progress = suspend;
+}
+EXPORT_SYMBOL(rpmh_notify_suspend);
diff --git a/include/soc/qcom/rpmh.h b/include/soc/qcom/rpmh.h
index d5e736e..2e79bee 100644
--- a/include/soc/qcom/rpmh.h
+++ b/include/soc/qcom/rpmh.h
@@ -31,6 +31,8 @@ int rpmh_write_batch(const struct device *dev, enum rpmh_state state,
 int rpmh_write_pdc_data(const struct device *dev,
 			const struct tcs_cmd *cmd, u32 n);
 
+void rpmh_notify_suspend(const struct device *dev, bool suspend);
+
 #else
 
 static inline int rpmh_write(const struct device *dev, enum rpmh_state state,
@@ -62,6 +64,9 @@ static inline int rpmh_mode_solver_set(const struct device *dev, bool enable)
 static inline int rpmh_write_pdc_data(const struct device *dev,
 				      const struct tcs_cmd *cmd, u32 n)
 { return -ENODEV; }
+
+static inline void rpmh_notify_suspend(const struct device *dev, bool suspend)
+{ }
 #endif /* CONFIG_QCOM_RPMH */
 
 #endif /* __SOC_QCOM_RPMH_H__ */
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH RFC 6/6] drivers: soc: system_pm: Add suspend notifier
  2018-08-24 20:06 [PATCH RFC 0/6] drivers: qcom: enable system low power modes for SDM845 Raju P.L.S.S.S.N
                   ` (4 preceding siblings ...)
  2018-08-24 20:06 ` [PATCH RFC 5/6] drivers: qcom: rpmh: force flush new sleep/wake requests during suspend Raju P.L.S.S.S.N
@ 2018-08-24 20:06 ` Raju P.L.S.S.S.N
  5 siblings, 0 replies; 8+ messages in thread
From: Raju P.L.S.S.S.N @ 2018-08-24 20:06 UTC (permalink / raw)
  To: andy.gross, david.brown, linux-arm-msm, linux-soc, linux-pm
  Cc: rnayak, bjorn.andersson, linux-kernel, lorenzo.pieralisi, rafael,
	drake, sboyd, evgreen, dianders, mka, ilina, Raju P.L.S.S.S.N

The order of suspending different devices, which is part of device
suspend, during pm suspend can't be guaranteed. So once system PM device
flushes the cached sleep/wake requests, other client devices may send
new sleep or wake requests in their device suspend operations. The rpmh
controller needs to manage such new requests if any. A notification is
sent to controller to indicate the same.

Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org>
---
 drivers/soc/qcom/system_pm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/system_pm.c b/drivers/soc/qcom/system_pm.c
index 1451bf8..6524f7e 100644
--- a/drivers/soc/qcom/system_pm.c
+++ b/drivers/soc/qcom/system_pm.c
@@ -133,6 +133,7 @@ static int sys_pm_suspend(struct device *dev)
 		/* Flush the sleep/wake sets in RSC controller */
 		rpmh_flush(dev);
 		setup_pdc_wakeup_timer(true);
+		rpmh_notify_suspend(sys_pm_dev, true);
 	} else {
 		pr_err("%s:rpmh controller is busy\n", __func__);
 		return -EBUSY;
@@ -141,8 +142,14 @@ static int sys_pm_suspend(struct device *dev)
 	return 0;
 }
 
+static int sys_pm_resume(struct device *dev)
+{
+	rpmh_notify_suspend(sys_pm_dev, false);
+	return 0;
+}
+
 static const struct dev_pm_ops sys_pm_dev_pm_ops = {
-	SET_LATE_SYSTEM_SLEEP_PM_OPS(sys_pm_suspend, NULL)
+	SET_LATE_SYSTEM_SLEEP_PM_OPS(sys_pm_suspend, sys_pm_resume)
 };
 
 static const struct of_device_id sys_pm_drv_match[] = {
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH RFC 2/6] dt-bindings: introduce System PM bindings for Qualcomm SoCs
  2018-08-24 20:06 ` [PATCH RFC 2/6] dt-bindings: introduce System PM bindings for Qualcomm SoCs Raju P.L.S.S.S.N
@ 2018-09-04 13:14   ` Rob Herring
  0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2018-09-04 13:14 UTC (permalink / raw)
  To: Raju P.L.S.S.S.N
  Cc: andy.gross, david.brown, linux-arm-msm, linux-soc, linux-pm,
	rnayak, bjorn.andersson, linux-kernel, lorenzo.pieralisi, rafael,
	drake, sboyd, evgreen, dianders, mka, ilina, devicetree

On Sat, Aug 25, 2018 at 01:36:24AM +0530, Raju P.L.S.S.S.N wrote:
> Add device binding documentation for Qualcomm Technology Inc's System PM
> driver. The driver is used for managing system sleep activities that are
> required when application processor is going to deepest low power mode.
> 
> Cc: devicetree@vger.kernel.org
> Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org>
> ---
>  .../devicetree/bindings/soc/qcom/system_pm.txt     | 28 ++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/soc/qcom/system_pm.txt
> 
> diff --git a/Documentation/devicetree/bindings/soc/qcom/system_pm.txt b/Documentation/devicetree/bindings/soc/qcom/system_pm.txt
> new file mode 100644
> index 0000000..0915760
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/qcom/system_pm.txt
> @@ -0,0 +1,28 @@
> +System PM
> +---------
> +
> +System PM device handles the tasks that need to be performed during application
> +processor deeper low power mode entry for QCOM SoCs which have hardened IP blocks
> +combinedly called as RPMH (Resource Power Manager Hardened) for shared resource
> +management. System PM is a client of APPS_RSC. Flushing the buffered requests to
> +TCSs in RSC and programming the wakeup timer in PDC for timer based wakeup are
> +handled by this device.
> +
> +The bindings for System PM is specified in the RSC section in devicetree.
> +
> +Properties:
> +- compatible:
> +	Usage: required
> +	Value type: <string>
> +	Definition: must be "qcom,system-pm".

h/w devices have some sort of resources and this has nothing. Looks like 
you are just using DT to instantiate some sort of virtual driver. Don't 
do that.

Rob

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-09-04 13:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-24 20:06 [PATCH RFC 0/6] drivers: qcom: enable system low power modes for SDM845 Raju P.L.S.S.S.N
2018-08-24 20:06 ` [PATCH RFC 1/6] drivers: qcom: system_pm: add system PM client for RPMH based SoCs Raju P.L.S.S.S.N
2018-08-24 20:06 ` [PATCH RFC 2/6] dt-bindings: introduce System PM bindings for Qualcomm SoCs Raju P.L.S.S.S.N
2018-09-04 13:14   ` Rob Herring
2018-08-24 20:06 ` [PATCH RFC 3/6] drivers: qcom: system_pm: Add power management ops Raju P.L.S.S.S.N
2018-08-24 20:06 ` [PATCH RFC 4/6] drivers: qcom: system_pm: program next wakeup to PDC timer Raju P.L.S.S.S.N
2018-08-24 20:06 ` [PATCH RFC 5/6] drivers: qcom: rpmh: force flush new sleep/wake requests during suspend Raju P.L.S.S.S.N
2018-08-24 20:06 ` [PATCH RFC 6/6] drivers: soc: system_pm: Add suspend notifier Raju P.L.S.S.S.N

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.