From 691718eeb035a05246131fc62300e23a458808ff Mon Sep 17 00:00:00 2001 From: Raghavendra Kakarla Date: Wed, 1 Apr 2020 03:01:41 +0530 Subject: [PATCH] drivers: soc: qcom: handle system sleep activities When all the CPUs in the Apps processor subsystem are powered off, the system may also reduce its bandwidth and shared resource requirements. The resource requests are sent through the SMD from APSS subsystem. The sleep requests also need to be written to the rpm to save power. This driver handles the last few steps when entering system sleep. When notified, the next wakeup timer value is written to the MPM to be setup in the always-on domain timer. Change-Id: Iab9e38d602d4f84e506471ec0864d2c6fb550b42 Signed-off-by: Raghavendra Kakarla --- drivers/soc/qcom/Kconfig | 11 +++++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/system_pm_rpm.c | 84 ++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 drivers/soc/qcom/system_pm_rpm.c diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index 75aa658b1fb3..cfac7b5b24ce 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -646,10 +646,21 @@ config MSM_PM bool select MSM_IDLE_STATS if DEBUG_FS select QTI_SYSTEM_PM if QCOM_RPMH + select QTI_SYSTEM_PM_RPM if MSM_RPM_SMD && QGKI && QCOM_MPM + bool "Qualcomm Technologies, Inc. (QTI) Power Management Drivers" + help + Platform specific power driver to manage cores and l2 low power + modes. It interface with various system driver and put the cores + into low power modes. It implements OS initiated scheme and + determines last CPU to call into PSCI for cluster Low power + modes. config QTI_SYSTEM_PM bool +config QTI_SYSTEM_PM_RPM + bool + if MSM_PM menuconfig MSM_IDLE_STATS bool "Collect idle statistics" diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 1759810ccb36..67fa1bdeb884 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -63,6 +63,7 @@ obj-$(CONFIG_QTI_BATTERY_GLINK_DEBUG) += qti_battery_debug.o obj-$(CONFIG_QTI_ALTMODE_GLINK) += altmode-glink.o obj-$(CONFIG_QTI_DDR_STATS_LOG) += ddr_stats.o obj-$(CONFIG_QTI_SYSTEM_PM) += system_pm.o +obj-$(CONFIG_QTI_SYSTEM_PM_RPM) += system_pm_rpm.o obj-$(CONFIG_MSM_REMOTEQDSS) += remoteqdss.o obj-$(CONFIG_MSM_SPSS_UTILS) += spss_utils.o obj-$(CONFIG_MSM_IDLE_STATS) += lpm-stats.o diff --git a/drivers/soc/qcom/system_pm_rpm.c b/drivers/soc/qcom/system_pm_rpm.c new file mode 100644 index 000000000000..23c5c9e11562 --- /dev/null +++ b/drivers/soc/qcom/system_pm_rpm.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void system_sleep_exit(bool success) +{ + msm_rpm_exit_sleep(); +} + +static int system_sleep_update_wakeup(bool from_idle) +{ + uint32_t lo = ~0U, hi = ~0U; + u64 wakeup; + + /* Read the hardware to get the most accurate value */ + arch_timer_mem_get_cval(&lo, &hi); + wakeup = lo; + wakeup |= ((uint64_t)(hi) << 32); + msm_mpm_timer_write((uint32_t *)&wakeup); + + return 0; +} + +static int system_sleep_enter(struct cpumask *mask) +{ + int ret = 0; + + ret = msm_rpm_enter_sleep(0, mask); + if (ret) + return ret; + + msm_mpm_enter_sleep(mask); + + return ret; +} + +static bool system_sleep_allowed(void) +{ + return !msm_rpm_waiting_for_ack(); +} + +static struct system_pm_ops pm_ops = { + .enter = system_sleep_enter, + .exit = system_sleep_exit, + .update_wakeup = system_sleep_update_wakeup, + .sleep_allowed = system_sleep_allowed, +}; + +static int sys_pm_rpm_probe(struct platform_device *pdev) +{ + return register_system_pm_ops(&pm_ops); +} + +static const struct of_device_id sys_pm_drv_match[] = { + { .compatible = "qcom,system-pm-rpm", }, + { } +}; + +static struct platform_driver sys_pm_rpm_driver = { + .probe = sys_pm_rpm_probe, + .driver = { + .name = KBUILD_MODNAME, + .suppress_bind_attrs = true, + .of_match_table = sys_pm_drv_match, + }, +}; +module_platform_driver(sys_pm_rpm_driver); + +MODULE_DESCRIPTION("Qualcomm Technologies, Inc. (QTI) SYSTEM PM RPM Driver"); +MODULE_LICENSE("GPL v2");