Skip to contentSkip to conversation

drivers: qcom: enable system low power modes for SDM845

RFC PATCH In review Raju P.L.S.S.S.N 2 participants 8 messages Aug 24, 2018 – Sep 4, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover drivers: qcom: enable system low power modes for SDM845

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
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
#1 lore raw

RFC PATCH 1/6 drivers: qcom: system_pm: add system PM client for RPMH based SoCs

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.

---
 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
drivers/soc/qcom/Kconfig +11 -0
index 3223084..a52abe9 100644
@@ -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
drivers/soc/qcom/Makefile +1 -0
index 03d4c83..27d79d2 100644
@@ -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
drivers/soc/qcom/system_pm.c new file +82 -0

82 lines not on this page · raw message

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
#2 lore raw

RFC PATCH 2/6 dt-bindings: introduce System PM bindings for Qualcomm SoCs

In reply to Raju P.L.S.S.S.N

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.

---
 .../devicetree/bindings/soc/qcom/system_pm.txt     | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/system_pm.txt
Documentation/devicetree/bindings/soc/qcom/system_pm.txt new file +28 -0
new file mode 100644
index 0000000..0915760
@@ -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";
+		};
+	};
+
+
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
#4 lore raw

RFC PATCH 3/6 drivers: qcom: system_pm: Add power management ops

In reply to 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.

---
 drivers/soc/qcom/Kconfig     |  2 +-
 drivers/soc/qcom/system_pm.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/soc/qcom/Kconfig +1 -1
index a52abe9..ac0e413 100644
@@ -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
drivers/soc/qcom/system_pm.c +18 -0
index 40e5aa7..8810b84 100644
@@ -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);
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
#5 lore raw

RFC PATCH 4/6 drivers: qcom: system_pm: program next wakeup to PDC timer

In reply to 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.

---
 drivers/soc/qcom/system_pm.c | 61 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
drivers/soc/qcom/system_pm.c +61 -0
index 8810b84..1451bf8 100644
@@ -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;
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
#6 lore raw

RFC PATCH 5/6 drivers: qcom: rpmh: force flush new sleep/wake requests during suspend

In reply to 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.

---
 drivers/soc/qcom/rpmh-internal.h |  1 +
 drivers/soc/qcom/rpmh.c          | 17 +++++++++++++++++
 include/soc/qcom/rpmh.h          |  5 +++++
 3 files changed, 23 insertions(+)
drivers/soc/qcom/rpmh-internal.h +1 -0
index f5359be..45bab3b 100644
@@ -80,6 +80,7 @@ struct rpmh_ctrlr {
 	bool dirty;
 	struct list_head batch_cache;
 	bool in_solver_mode;
+	bool suspend_in_progress;
 };
 
 /**
drivers/soc/qcom/rpmh.c +17 -0
index 390e779..a9bd1a0 100644
@@ -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);
include/soc/qcom/rpmh.h +5 -0
index d5e736e..2e79bee 100644
@@ -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__ */
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
#7 lore raw

RFC PATCH 6/6 drivers: soc: system_pm: Add suspend notifier

In reply to 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.

---
 drivers/soc/qcom/system_pm.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/soc/qcom/system_pm.c +8 -1
index 1451bf8..6524f7e 100644
@@ -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[] = {
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
maintainer
#3 lore raw

Re: [PATCH RFC 2/6] dt-bindings: introduce System PM bindings for Qualcomm SoCs

In reply to Raju P.L.S.S.S.N
Quoted 24 lines · Raju P.L.S.S.S.N

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.

---
 .../devicetree/bindings/soc/qcom/system_pm.txt     | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/system_pm.txt
Documentation/devicetree/bindings/soc/qcom/system_pm.txt new file +7 -0
new file mode 100644
index 0000000..0915760
@@ -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

Documentation/devicetree/bindings/soc/qcom/system_pm.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/system_pm.txt new file +10 -0
+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