Skip to contentSkip to conversation

mediatek: Add cpuidle cluster sleep support for MT8173

PATCH New Fan Chen 1 participant 5 messages Dec 18, 2015

Subsystems (2)
lore
Share & tools
lore

Fan Chen

author
#0 lore raw

cover mediatek: Add cpuidle cluster sleep support for MT8173

This patchset is to enable cpuidle cluster sleep for MT8173, which is based on Lorenzo Pieralisi's patch[1] to give different configuration for each cluster in big.LITTLE architecture.

Power domain control flow is the same in both cpu and non-cpu domains, and some of power domains(e.g. cpu clusters, mfg, mm in mt8173) need to set bus protection bits before power off and vice versa on power on. However, in PSCI framework, cpu power domain controlling is hidden in ARM TF but non-cpu ones are controlled in kernel driver so that race condition on accessing bus protection register will happen between cpu power domains and non-cpu ones in runtime once we enable cluster sleep without any protection.

Therefore, we also introduce patches to create SIP call API based on Jens Wiklander's patches[2][3] and modify scpsys driver to give an option to put non-cpu power control into ARM TF via SIP call, which gives a way to manage all power domains together in firmware.

[1] https://patchwork.kernel.org/patch/6226871/
[2] https://patchwork.kernel.org/patch/7517271/
[3] https://patchwork.kernel.org/patch/7517261/

Fan Chen (1):
soc: Mediatek: Create Mediatek SIP call

Weiyi Lu (2):
arm64: dts: mediatek: Add cluster sleep support on MT8173
arm64: dts: mediatek: Improve cpuidle latency on MT8173

yt.lee (1):
soc: mediatek: To move power control logic to ARM TF

 arch/arm64/boot/dts/mediatek/mt8173.dtsi |   41 ++++++++--
 drivers/soc/mediatek/Kconfig             |    8 ++
 drivers/soc/mediatek/Makefile            |    1 +
 drivers/soc/mediatek/mtk-scpsys.c        |  122 +++++++++++++++++++-----------
 drivers/soc/mediatek/mtk-sip.c           |   28 +++++++
 include/linux/soc/mediatek/mtk-sip.h     |   21 +++++
 6 files changed, 170 insertions(+), 51 deletions(-)
 create mode 100644 drivers/soc/mediatek/mtk-sip.c
 create mode 100644 include/linux/soc/mediatek/mtk-sip.h
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 1/4 soc: Mediatek: Create Mediatek SIP call

Create a generic interface for issuing SIP Service calls which are specified in ARM SMC CALLING CONVENTION.

---
 drivers/soc/mediatek/Kconfig         |    8 ++++++++
 drivers/soc/mediatek/Makefile        |    1 +
 drivers/soc/mediatek/mtk-sip.c       |   28 ++++++++++++++++++++++++++++
 include/linux/soc/mediatek/mtk-sip.h |   17 +++++++++++++++++
 4 files changed, 54 insertions(+)
 create mode 100644 drivers/soc/mediatek/mtk-sip.c
 create mode 100644 include/linux/soc/mediatek/mtk-sip.h
drivers/soc/mediatek/Kconfig +8 -0
index 9d50682..65c1323 100644
@@ -29,3 +29,11 @@ config MTK_SCPSYS
 	help
 	  Say yes here to add support for the MediaTek SCPSYS power domain
 	  driver.
+
+config MTK_SIP
+        bool "Mediatek SIP Support"
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	depends on HAVE_SMCCC
+	help
+	Say yes here to add support for the MediaTek SIP call.
+
drivers/soc/mediatek/Makefile +1 -0
index 12998b0..67077dc 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o
 obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
 obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o
+obj-$(CONFIG_MTK_SIP) += mtk-sip.o
drivers/soc/mediatek/mtk-sip.c new file +28 -0
new file mode 100644
index 0000000..882617f
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 MediaTek Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/arm-smccc.h>
+#include <linux/soc/mediatek/mtk-sip.h>
+
+int mtk_sip_simple_call(unsigned long func_id,
+			unsigned long a1,
+			unsigned long a2,
+			unsigned long a3)
+{
+	struct smccc_res res;
+
+	smccc_smc(func_id, a1, a2, a3, 0, 0, 0, 0, &res);
+
+	return res.a0;
+}
+
include/linux/soc/mediatek/mtk-sip.h new file +17 -0
new file mode 100644
index 0000000..dce1818
@@ -0,0 +1,17 @@
+#ifndef __SOC_MEDIATEK_MTKSIP_H
+#define __SOC_MEDIATEK_MTKSIP_H
+
+#ifdef CONFIG_MTK_SIP
+int mtk_sip_simple_call(unsigned long func_id,
+			unsigned long a1,
+			unsigned long a2,
+			unsigned long a3);
+#else
+static inline int mtk_sip_simple_call(unsigned long func_id,
+				      unsigned long a1,
+				      unsigned long a2,
+				      unsigned long a3)
+{       return -EOPNOTSUPP; }
+#endif
+
+#endif /*__SOC_MEDIATEK_MTKSIP_H*/
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH 2/4 soc: mediatek: To move power control logic to ARM TF

In reply to Fan Chen

From: "yt.lee" <[email protected]>

Add an option to test if ARM TF supports non-cpus power control and do it in firmware. Otherwise, fallback to legecy way handling it in kernel driver.

Regarding time consumption of sip call for the power control. In 52051 times of sip calls with power_LoadTest, the maximum cost is 433us and the average cost is 118us.

---
 drivers/soc/mediatek/mtk-scpsys.c    |  122 ++++++++++++++++++++++------------
 include/linux/soc/mediatek/mtk-sip.h |    4 ++
 2 files changed, 82 insertions(+), 44 deletions(-)
drivers/soc/mediatek/mtk-scpsys.c +78 -44
index 4d4203c..cc8d0c8 100644
@@ -21,6 +21,7 @@
 #include <linux/pm_domain.h>
 #include <linux/regmap.h>
 #include <linux/soc/mediatek/infracfg.h>
+#include <linux/soc/mediatek/mtk-sip.h>
 #include <dt-bindings/power/mt8173-power.h>
 
 #define SPM_VDE_PWR_CON			0x0210
@@ -187,6 +188,7 @@ struct scp {
 	struct device *dev;
 	void __iomem *base;
 	struct regmap *infracfg;
+	bool sip_support;
 };
 
 static int scpsys_domain_is_on(struct scp_domain *scpd)
@@ -209,9 +211,8 @@ static int scpsys_domain_is_on(struct scp_domain *scpd)
 	return -EINVAL;
 }
 
-static int scpsys_power_on(struct generic_pm_domain *genpd)
+static int scpsys_power_on_mtcmos(struct scp_domain *scpd)
 {
-	struct scp_domain *scpd = container_of(genpd, struct scp_domain, genpd);
 	struct scp *scp = scpd->scp;
 	unsigned long timeout;
 	bool expired;
@@ -219,17 +220,6 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
 	u32 sram_pdn_ack = scpd->sram_pdn_ack_bits;
 	u32 val;
 	int ret;
-	int i;
-
-	for (i = 0; i < MAX_CLKS && scpd->clk[i]; i++) {
-		ret = clk_prepare_enable(scpd->clk[i]);
-		if (ret) {
-			for (--i; i >= 0; i--)
-				clk_disable_unprepare(scpd->clk[i]);
-
-			goto err_clk;
-		}
-	}
 
 	val = readl(ctl_addr);
 	val |= PWR_ON_BIT;
@@ -245,10 +235,8 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
 		if (ret > 0)
 			break;
 
-		if (expired) {
-			ret = -ETIMEDOUT;
-			goto err_pwr_ack;
-		}
+		if (expired)
+			return -ETIMEDOUT;
 
 		cpu_relax();
 
@@ -273,10 +261,8 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
 	expired = false;
 	while (sram_pdn_ack && (readl(ctl_addr) & sram_pdn_ack)) {
 
-		if (expired) {
-			ret = -ETIMEDOUT;
-			goto err_pwr_ack;
-		}
+		if (expired)
+			return  -ETIMEDOUT;
 
 		cpu_relax();
 
@@ -288,25 +274,14 @@ static int scpsys_power_on(struct generic_pm_domain *genpd)
 		ret = mtk_infracfg_clear_bus_protection(scp->infracfg,
 				scpd->bus_prot_mask);
 		if (ret)
-			goto err_pwr_ack;
+			return ret;
 	}
 
 	return 0;
-
-err_pwr_ack:
-	for (i = MAX_CLKS - 1; i >= 0; i--) {
-		if (scpd->clk[i])
-			clk_disable_unprepare(scpd->clk[i]);
-	}
-err_clk:
-	dev_err(scp->dev, "Failed to power on domain %s\n", genpd->name);
-
-	return ret;
 }
 
-static int scpsys_power_off(struct generic_pm_domain *genpd)
+static int scpsys_power_off_mtcmos(struct scp_domain *scpd)
 {
-	struct scp_domain *scpd = container_of(genpd, struct scp_domain, genpd);
 	struct scp *scp = scpd->scp;
 	unsigned long timeout;
 	bool expired;
@@ -314,13 +289,12 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 	u32 pdn_ack = scpd->sram_pdn_ack_bits;
 	u32 val;
 	int ret;
-	int i;
 
 	if (scpd->bus_prot_mask) {
 		ret = mtk_infracfg_set_bus_protection(scp->infracfg,
 				scpd->bus_prot_mask);
 		if (ret)
-			goto out;
+			return ret;
 	}
 
 	val = readl(ctl_addr);
@@ -331,10 +305,9 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 	timeout = jiffies + HZ;
 	expired = false;
 	while (pdn_ack && (readl(ctl_addr) & pdn_ack) != pdn_ack) {
-		if (expired) {
-			ret = -ETIMEDOUT;
-			goto out;
-		}
+
+		if (expired)
+			return -ETIMEDOUT;
 
 		cpu_relax();
 
@@ -365,10 +338,8 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 		if (ret == 0)
 			break;
 
-		if (expired) {
-			ret = -ETIMEDOUT;
-			goto out;
-		}
+		if (expired)
+			return -ETIMEDOUT;
 
 		cpu_relax();
 
@@ -376,6 +347,62 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
 			expired = true;
 	}
 
+	return 0;
+}
+
+static int scpsys_power_on(struct generic_pm_domain *genpd)
+{
+	struct scp_domain *scpd = container_of(genpd, struct scp_domain, genpd);
+	struct scp *scp = scpd->scp;
+	int ret;
+	int i;
+
+	for (i = 0; i < MAX_CLKS && scpd->clk[i]; i++) {
+		ret = clk_prepare_enable(scpd->clk[i]);
+		if (ret) {
+			for (--i; i >= 0; i--)
+				clk_disable_unprepare(scpd->clk[i]);
+
+			goto err_clk;
+		}
+	}
+
+	if (!scp->sip_support)
+		ret = scpsys_power_on_mtcmos(scpd);
+	else
+		ret = mtk_sip_simple_call(MTK_SIP_PWR_ON_MTCMOS,
+				  scpd->ctl_addr - scp->base, 0, 0);
+	if (ret)
+		goto err_pwr_ack;
+
+	return 0;
+
+err_pwr_ack:
+	for (i = MAX_CLKS - 1; i >= 0; i--) {
+		if (scpd->clk[i])
+			clk_disable_unprepare(scpd->clk[i]);
+	}
+err_clk:
+	dev_err(scp->dev, "Failed to power on domain %s\n", genpd->name);
+
+	return ret;
+}
+
+static int scpsys_power_off(struct generic_pm_domain *genpd)
+{
+	struct scp_domain *scpd = container_of(genpd, struct scp_domain, genpd);
+	struct scp *scp = scpd->scp;
+	int ret;
+	int i;
+
+	if (!scp->sip_support)
+		ret = scpsys_power_off_mtcmos(scpd);
+	else
+		ret = mtk_sip_simple_call(MTK_SIP_PWR_OFF_MTCMOS,
+				  scpd->ctl_addr - scp->base, 0, 0);
+	if (ret)
+		goto out;
+
 	for (i = 0; i < MAX_CLKS && scpd->clk[i]; i++)
 		clk_disable_unprepare(scpd->clk[i]);
 
@@ -503,6 +530,13 @@ static int __init scpsys_probe(struct platform_device *pdev)
 	if (ret)
 		dev_err(&pdev->dev, "Failed to add OF provider: %d\n", ret);
 
+	ret = mtk_sip_simple_call(MTK_SIP_PWR_MTCMOS_SUPPORT, 0, 0, 0);
+	if (ret) {
+		scp->sip_support = false;
+		dev_info(&pdev->dev, "SIP call is not supported: %d\n", ret);
+	} else
+		scp->sip_support = true;
+
 	return 0;
 }
 
include/linux/soc/mediatek/mtk-sip.h +4 -0
index dce1818..c803490 100644
@@ -1,6 +1,10 @@
 #ifndef __SOC_MEDIATEK_MTKSIP_H
 #define __SOC_MEDIATEK_MTKSIP_H
 
+#define MTK_SIP_PWR_ON_MTCMOS			0x82000402
+#define MTK_SIP_PWR_OFF_MTCMOS			0x82000403
+#define MTK_SIP_PWR_MTCMOS_SUPPORT		0x82000404
+
 #ifdef CONFIG_MTK_SIP
 int mtk_sip_simple_call(unsigned long func_id,
 			unsigned long a1,
Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH 3/4 arm64: dts: mediatek: Add cluster sleep support on MT8173

In reply to Fan Chen

From: Weiyi Lu <[email protected]>

Enable cluster sleep state by adding cluster-sleep node to mt8173.dtsi

---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
arch/arm64/boot/dts/mediatek/mt8173.dtsi +13 -4
index 880dacb..77c1f84 100644
@@ -53,7 +53,7 @@
 			compatible = "arm,cortex-a53";
 			reg = <0x000>;
 			enable-method = "psci";
-			cpu-idle-states = <&CPU_SLEEP_0>;
+			cpu-idle-states = <&CPU_SLEEP_0 &CLUSTER_SLEEP_0>;
 		};
 
 		cpu1: cpu at 1 {
@@ -61,7 +61,7 @@
 			compatible = "arm,cortex-a53";
 			reg = <0x001>;
 			enable-method = "psci";
-			cpu-idle-states = <&CPU_SLEEP_0>;
+			cpu-idle-states = <&CPU_SLEEP_0 &CLUSTER_SLEEP_0>;
 		};
 
 		cpu2: cpu at 100 {
@@ -69,7 +69,7 @@
 			compatible = "arm,cortex-a57";
 			reg = <0x100>;
 			enable-method = "psci";
-			cpu-idle-states = <&CPU_SLEEP_0>;
+			cpu-idle-states = <&CPU_SLEEP_0 &CLUSTER_SLEEP_0>;
 		};
 
 		cpu3: cpu at 101 {
@@ -77,7 +77,7 @@
 			compatible = "arm,cortex-a57";
 			reg = <0x101>;
 			enable-method = "psci";
-			cpu-idle-states = <&CPU_SLEEP_0>;
+			cpu-idle-states = <&CPU_SLEEP_0 &CLUSTER_SLEEP_0>;
 		};
 
 		idle-states {
@@ -91,6 +91,15 @@
 				min-residency-us = <1088>;
 				arm,psci-suspend-param = <0x0010000>;
 			};
+
+			CLUSTER_SLEEP_0: cluster-sleep-0 {
+				compatible = "arm,idle-state";
+				local-timer-stop;
+				entry-latency-us = <800>;
+				exit-latency-us = <1000>;
+				min-residency-us = <2000>;
+				arm,psci-suspend-param = <0x1010000>;
+			};
 		};
 	};
 
Signature · 1 line
1.7.9.5
author
#4 lore raw

PATCH 4/4 arm64: dts: mediatek: Improve cpuidle latency on MT8173

In reply to Fan Chen

From: Weiyi Lu <[email protected]>

All according to the exact profiling result:
First, each CPU cluster needs its own nodes due to the latency gap between each other.
Second, tune the parameters to enter the lowest idle state as much time as possible without disturbing the system performance for power-saving demand.

---
 arch/arm64/boot/dts/mediatek/mt8173.dtsi |   34 +++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 8 deletions(-)
arch/arm64/boot/dts/mediatek/mt8173.dtsi +26 -8
index 77c1f84..0ae3983 100644
@@ -69,7 +69,7 @@
 			compatible = "arm,cortex-a57";
 			reg = <0x100>;
 			enable-method = "psci";
-			cpu-idle-states = <&CPU_SLEEP_0 &CLUSTER_SLEEP_0>;
+			cpu-idle-states = <&CPU_SLEEP_1 &CLUSTER_SLEEP_1>;
 		};
 
 		cpu3: cpu at 101 {
@@ -77,7 +77,7 @@
 			compatible = "arm,cortex-a57";
 			reg = <0x101>;
 			enable-method = "psci";
-			cpu-idle-states = <&CPU_SLEEP_0 &CLUSTER_SLEEP_0>;
+			cpu-idle-states = <&CPU_SLEEP_1 &CLUSTER_SLEEP_1>;
 		};
 
 		idle-states {
@@ -86,18 +86,36 @@
 			CPU_SLEEP_0: cpu-sleep-0 {
 				compatible = "arm,idle-state";
 				local-timer-stop;
-				entry-latency-us = <639>;
-				exit-latency-us = <680>;
-				min-residency-us = <1088>;
+				entry-latency-us = <72>;
+				exit-latency-us = <66>;
+				min-residency-us = <458>;
 				arm,psci-suspend-param = <0x0010000>;
 			};
 
 			CLUSTER_SLEEP_0: cluster-sleep-0 {
 				compatible = "arm,idle-state";
 				local-timer-stop;
-				entry-latency-us = <800>;
-				exit-latency-us = <1000>;
-				min-residency-us = <2000>;
+				entry-latency-us = <145>;
+				exit-latency-us = <60>;
+				min-residency-us = <331>;
+				arm,psci-suspend-param = <0x1010000>;
+			};
+
+			CPU_SLEEP_1: cpu-sleep-1 {
+				compatible = "arm,idle-state";
+				local-timer-stop;
+				entry-latency-us = <72>;
+				exit-latency-us = <66>;
+				min-residency-us = <516>;
+				arm,psci-suspend-param = <0x0010000>;
+			};
+
+			CLUSTER_SLEEP_1: cluster-sleep-1 {
+				compatible = "arm,idle-state";
+				local-timer-stop;
+				entry-latency-us = <287>;
+				exit-latency-us = <62>;
+				min-residency-us = <1423>;
 				arm,psci-suspend-param = <0x1010000>;
 			};
 		};
Signature · 1 line
1.7.9.5