devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF
@ 2018-06-07  9:51 Bastian Stender
  2018-06-07  9:51 ` [PATCH RESEND 2/2] ARM: dts: imx: add cooling-cells for cpufreq cooling device Bastian Stender
  2018-06-08  7:22 ` [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF kbuild test robot
  0 siblings, 2 replies; 5+ messages in thread
From: Bastian Stender @ 2018-06-07  9:51 UTC (permalink / raw)
  To: Shawn Guo, Rafael J . Wysocki, Viresh Kumar, Zhang Rui,
	Leonard Crestez
  Cc: devicetree, linux-pm, linux-imx, Anson Huang, kernel,
	Bastian Stender

The cooling device should be part of the i.MX cpufreq driver, but it
cannot be removed for the sake of DT stability. So turn the cooling
device registration into a separate function and perform the
registration only if the CPU OF node does not have the #cooling-cells
property.

Use of_cpufreq_power_cooling_register in imx_thermal code to link the
cooling device to the device tree node provided.

This makes it possible to bind the cpufreq cooling device to a custom
thermal zone via a cooling-maps entry like:

	cooling-maps {
		map0 {
			trip = <&board_alert>;
			cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
		};
	};

Assuming a cpu node exists with label "cpu0" and #cooling-cells
property.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
---
Changes since implicit v1 ("cpufreq: imx6q/thermal: imx: move CPU cooling device from thermal to cpufreq",
id:20171115092332.9320-1-bst@pengutronix.de):

- create cooling device in imx_thermal in case no #cooling-cells
  property is available instead of removing it (DT stability)
- fix indentation
---
 drivers/cpufreq/imx6q-cpufreq.c | 38 +++++++++++++++++++++++++++++++++
 drivers/thermal/imx_thermal.c   | 29 +++++++++++++++++++++----
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
index 83cf631fc9bc..47995beed3ac 100644
--- a/drivers/cpufreq/imx6q-cpufreq.c
+++ b/drivers/cpufreq/imx6q-cpufreq.c
@@ -9,6 +9,7 @@
 #include <linux/clk.h>
 #include <linux/cpu.h>
 #include <linux/cpufreq.h>
+#include <linux/cpu_cooling.h>
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -50,6 +51,7 @@ static struct clk_bulk_data clks[] = {
 };
 
 static struct device *cpu_dev;
+static struct thermal_cooling_device *cdev;
 static bool free_opp;
 static struct cpufreq_frequency_table *freq_table;
 static unsigned int max_freq;
@@ -191,6 +193,33 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
 	return 0;
 }
 
+static void imx6q_cpufreq_ready(struct cpufreq_policy *policy)
+{
+	struct device_node *np = of_node_get(cpu_dev->of_node);
+	u32 capacitance = 0;
+
+	if (WARN_ON(!np))
+		return;
+
+	if (of_find_property(np, "#cooling-cells", NULL)) {
+		of_property_read_u32(np, "dynamic-power-coefficient",
+				     &capacitance);
+
+		cdev = of_cpufreq_power_cooling_register(np, policy,
+							 capacitance, NULL);
+
+		if (IS_ERR(cdev)) {
+			dev_err(cpu_dev,
+				"running cpufreq without cooling device: %ld\n",
+				PTR_ERR(cdev));
+
+			cdev = NULL;
+		}
+	}
+
+	of_node_put(np);
+}
+
 static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
 {
 	int ret;
@@ -202,13 +231,22 @@ static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
 	return ret;
 }
 
+static int imx6q_cpufreq_exit(struct cpufreq_policy *policy)
+{
+	cpufreq_cooling_unregister(cdev);
+
+	return 0;
+}
+
 static struct cpufreq_driver imx6q_cpufreq_driver = {
 	.flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK,
 	.verify = cpufreq_generic_frequency_table_verify,
 	.target_index = imx6q_set_target,
 	.get = cpufreq_generic_get,
 	.init = imx6q_cpufreq_init,
+	.exit = imx6q_cpufreq_exit,
 	.name = "imx6q-cpufreq",
+	.ready = imx6q_cpufreq_ready,
 	.attr = cpufreq_generic_attr,
 	.suspend = cpufreq_generic_suspend,
 };
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 334d98be03b9..d701298f3fd1 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -3,6 +3,7 @@
 // Copyright 2013 Freescale Semiconductor, Inc.
 
 #include <linux/clk.h>
+#include <linux/cpu.h>
 #include <linux/cpufreq.h>
 #include <linux/cpu_cooling.h>
 #include <linux/delay.h>
@@ -644,6 +645,28 @@ static const struct of_device_id of_imx_thermal_match[] = {
 };
 MODULE_DEVICE_TABLE(of, of_imx_thermal_match);
 
+/*
+ * Create cooling device in case no #cooling-cells property is available in
+ * CPU node
+ */
+static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
+{
+	struct device *cpu_dev = get_cpu_device(0);
+	struct device_node *np = of_node_get(cpu_dev->of_node);
+	int ret;
+
+	if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
+		data->cdev = cpufreq_cooling_register(data->policy);
+		if (IS_ERR(data->cdev)) {
+			ret = PTR_ERR(data->cdev);
+			cpufreq_cpu_put(data->policy);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 static int imx_thermal_probe(struct platform_device *pdev)
 {
 	struct imx_thermal_data *data;
@@ -724,12 +747,10 @@ static int imx_thermal_probe(struct platform_device *pdev)
 		return -EPROBE_DEFER;
 	}
 
-	data->cdev = cpufreq_cooling_register(data->policy);
-	if (IS_ERR(data->cdev)) {
-		ret = PTR_ERR(data->cdev);
+	ret = imx_thermal_register_legacy_cooling(data);
+	if (ret) {
 		dev_err(&pdev->dev,
 			"failed to register cpufreq cooling device: %d\n", ret);
-		cpufreq_cpu_put(data->policy);
 		return ret;
 	}
 
-- 
2.17.1


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

* [PATCH RESEND 2/2] ARM: dts: imx: add cooling-cells for cpufreq cooling device
  2018-06-07  9:51 [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF Bastian Stender
@ 2018-06-07  9:51 ` Bastian Stender
  2018-06-07 10:15   ` Bastian Stender
  2018-06-08  7:22 ` [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF kbuild test robot
  1 sibling, 1 reply; 5+ messages in thread
From: Bastian Stender @ 2018-06-07  9:51 UTC (permalink / raw)
  To: Shawn Guo, Rafael J . Wysocki, Viresh Kumar, Zhang Rui,
	Leonard Crestez
  Cc: devicetree, linux-pm, linux-imx, Anson Huang, kernel, Anson Huang

From: Anson Huang <Anson.Huang@nxp.com>

Add #cooling-cells for i.MX6/7 SoCs for cpufreq
cooling device usage.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
This is a resend of id:1526285359-17978-3-git-send-email-Anson.Huang@nxp.com
The rest of Huang's series was a duplicate of my original series and was
skipped (as requested by Huang) in favor of the prior v2 patch.
---
 arch/arm/boot/dts/imx6dl.dtsi | 1 +
 arch/arm/boot/dts/imx6q.dtsi  | 1 +
 arch/arm/boot/dts/imx6sl.dtsi | 1 +
 arch/arm/boot/dts/imx6sx.dtsi | 1 +
 arch/arm/boot/dts/imx6ul.dtsi | 1 +
 arch/arm/boot/dts/imx7d.dtsi  | 1 +
 6 files changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/imx6dl.dtsi b/arch/arm/boot/dts/imx6dl.dtsi
index 558bce81209d..b830dfd74ad3 100644
--- a/arch/arm/boot/dts/imx6dl.dtsi
+++ b/arch/arm/boot/dts/imx6dl.dtsi
@@ -39,6 +39,7 @@
 				396000	1175000
 			>;
 			clock-latency = <61036>; /* two CLK32 periods */
+			#cooling-cells = <2>;
 			clocks = <&clks IMX6QDL_CLK_ARM>,
 				 <&clks IMX6QDL_CLK_PLL2_PFD2_396M>,
 				 <&clks IMX6QDL_CLK_STEP>,
diff --git a/arch/arm/boot/dts/imx6q.dtsi b/arch/arm/boot/dts/imx6q.dtsi
index ae7b3f107893..ac9f5cb65dec 100644
--- a/arch/arm/boot/dts/imx6q.dtsi
+++ b/arch/arm/boot/dts/imx6q.dtsi
@@ -44,6 +44,7 @@
 				396000	1175000
 			>;
 			clock-latency = <61036>; /* two CLK32 periods */
+			#cooling-cells = <2>;
 			clocks = <&clks IMX6QDL_CLK_ARM>,
 				 <&clks IMX6QDL_CLK_PLL2_PFD2_396M>,
 				 <&clks IMX6QDL_CLK_STEP>,
diff --git a/arch/arm/boot/dts/imx6sl.dtsi b/arch/arm/boot/dts/imx6sl.dtsi
index ab6a7e2e7e8f..d35d4e93236a 100644
--- a/arch/arm/boot/dts/imx6sl.dtsi
+++ b/arch/arm/boot/dts/imx6sl.dtsi
@@ -65,6 +65,7 @@
 				396000          1175000
 			>;
 			clock-latency = <61036>; /* two CLK32 periods */
+			#cooling-cells = <2>;
 			clocks = <&clks IMX6SL_CLK_ARM>, <&clks IMX6SL_CLK_PLL2_PFD2>,
 					<&clks IMX6SL_CLK_STEP>, <&clks IMX6SL_CLK_PLL1_SW>,
 					<&clks IMX6SL_CLK_PLL1_SYS>;
diff --git a/arch/arm/boot/dts/imx6sx.dtsi b/arch/arm/boot/dts/imx6sx.dtsi
index 49c7205b8db8..966e39a99792 100644
--- a/arch/arm/boot/dts/imx6sx.dtsi
+++ b/arch/arm/boot/dts/imx6sx.dtsi
@@ -83,6 +83,7 @@
 				198000	    1175000
 			>;
 			clock-latency = <61036>; /* two CLK32 periods */
+			#cooling-cells = <2>;
 			clocks = <&clks IMX6SX_CLK_ARM>,
 				 <&clks IMX6SX_CLK_PLL2_PFD2>,
 				 <&clks IMX6SX_CLK_STEP>,
diff --git a/arch/arm/boot/dts/imx6ul.dtsi b/arch/arm/boot/dts/imx6ul.dtsi
index 1241972b16ba..14b6ac78d323 100644
--- a/arch/arm/boot/dts/imx6ul.dtsi
+++ b/arch/arm/boot/dts/imx6ul.dtsi
@@ -66,6 +66,7 @@
 			device_type = "cpu";
 			reg = <0>;
 			clock-latency = <61036>; /* two CLK32 periods */
+			#cooling-cells = <2>;
 			operating-points = <
 				/* kHz	uV */
 				696000	1275000
diff --git a/arch/arm/boot/dts/imx7d.dtsi b/arch/arm/boot/dts/imx7d.dtsi
index 200714e3feea..4991371734d9 100644
--- a/arch/arm/boot/dts/imx7d.dtsi
+++ b/arch/arm/boot/dts/imx7d.dtsi
@@ -53,6 +53,7 @@
 				792000	975000
 			>;
 			clock-frequency = <996000000>;
+			#cooling-cells = <2>;
 		};
 
 		cpu1: cpu@1 {
-- 
2.17.1


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

* Re: [PATCH RESEND 2/2] ARM: dts: imx: add cooling-cells for cpufreq cooling device
  2018-06-07  9:51 ` [PATCH RESEND 2/2] ARM: dts: imx: add cooling-cells for cpufreq cooling device Bastian Stender
@ 2018-06-07 10:15   ` Bastian Stender
  0 siblings, 0 replies; 5+ messages in thread
From: Bastian Stender @ 2018-06-07 10:15 UTC (permalink / raw)
  To: Shawn Guo, Rafael J . Wysocki, Viresh Kumar, Zhang Rui,
	Leonard Crestez
  Cc: kernel, devicetree, linux-imx, Anson Huang, linux-pm

Hi,

On 06/07/2018 11:51 AM, Bastian Stender wrote:
> From: Anson Huang <Anson.Huang@nxp.com>
> 
> Add #cooling-cells for i.MX6/7 SoCs for cpufreq
> cooling device usage.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>

I forgot my SoB here, so:

Signed-off-by: Bastian Stender <bst@pengutronix.de>

Regards,
Bastian

-- 
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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

* Re: [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF
  2018-06-07  9:51 [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF Bastian Stender
  2018-06-07  9:51 ` [PATCH RESEND 2/2] ARM: dts: imx: add cooling-cells for cpufreq cooling device Bastian Stender
@ 2018-06-08  7:22 ` kbuild test robot
  2018-06-08  8:48   ` Bastian Stender
  1 sibling, 1 reply; 5+ messages in thread
From: kbuild test robot @ 2018-06-08  7:22 UTC (permalink / raw)
  To: Bastian Stender
  Cc: kbuild-all, Shawn Guo, Rafael J . Wysocki, Viresh Kumar,
	Zhang Rui, Leonard Crestez, devicetree, linux-pm, linux-imx,
	Anson Huang, kernel

[-- Attachment #1: Type: text/plain, Size: 2546 bytes --]

Hi Bastian,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on soc-thermal/next]
[also build test ERROR on v4.17 next-20180607]
[cannot apply to shawnguo/for-next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Bastian-Stender/cpufreq-imx6q-thermal-imx-register-cooling-device-depending-on-OF/20180608-134429
base:   https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git next
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=arm 

All error/warnings (new ones prefixed by >>):

   drivers//cpufreq/imx6q-cpufreq.c: In function 'imx6q_cpufreq_ready':
>> drivers//cpufreq/imx6q-cpufreq.c:208:10: error: implicit declaration of function 'of_cpufreq_power_cooling_register'; did you mean 'of_cpufreq_cooling_register'? [-Werror=implicit-function-declaration]
      cdev = of_cpufreq_power_cooling_register(np, policy,
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             of_cpufreq_cooling_register
>> drivers//cpufreq/imx6q-cpufreq.c:208:8: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
      cdev = of_cpufreq_power_cooling_register(np, policy,
           ^
   cc1: some warnings being treated as errors

vim +208 drivers//cpufreq/imx6q-cpufreq.c

   195	
   196	static void imx6q_cpufreq_ready(struct cpufreq_policy *policy)
   197	{
   198		struct device_node *np = of_node_get(cpu_dev->of_node);
   199		u32 capacitance = 0;
   200	
   201		if (WARN_ON(!np))
   202			return;
   203	
   204		if (of_find_property(np, "#cooling-cells", NULL)) {
   205			of_property_read_u32(np, "dynamic-power-coefficient",
   206					     &capacitance);
   207	
 > 208			cdev = of_cpufreq_power_cooling_register(np, policy,
   209								 capacitance, NULL);
   210	
   211			if (IS_ERR(cdev)) {
   212				dev_err(cpu_dev,
   213					"running cpufreq without cooling device: %ld\n",
   214					PTR_ERR(cdev));
   215	
   216				cdev = NULL;
   217			}
   218		}
   219	
   220		of_node_put(np);
   221	}
   222	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 43337 bytes --]

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

* Re: [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF
  2018-06-08  7:22 ` [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF kbuild test robot
@ 2018-06-08  8:48   ` Bastian Stender
  0 siblings, 0 replies; 5+ messages in thread
From: Bastian Stender @ 2018-06-08  8:48 UTC (permalink / raw)
  To: kbuild test robot
  Cc: devicetree, Anson Huang, linux-pm, Viresh Kumar,
	Rafael J . Wysocki, kbuild-all, kernel, Zhang Rui,
	Leonard Crestez, Shawn Guo, linux-imx

On 06/08/2018 09:22 AM, kbuild test robot wrote:
> Hi Bastian,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on soc-thermal/next]
> [also build test ERROR on v4.17 next-20180607]
> [cannot apply to shawnguo/for-next]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
> 
> url:    https://github.com/0day-ci/linux/commits/Bastian-Stender/cpufreq-imx6q-thermal-imx-register-cooling-device-depending-on-OF/20180608-134429
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux-soc-thermal.git next
> config: arm-multi_v7_defconfig (attached as .config)
> compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
> reproduce:
>          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>          chmod +x ~/bin/make.cross
>          # save the attached .config to linux build tree
>          make.cross ARCH=arm
> 
> All error/warnings (new ones prefixed by >>):
> 
>     drivers//cpufreq/imx6q-cpufreq.c: In function 'imx6q_cpufreq_ready':
>>> drivers//cpufreq/imx6q-cpufreq.c:208:10: error: implicit declaration of function 'of_cpufreq_power_cooling_register'; did you mean 'of_cpufreq_cooling_register'? [-Werror=implicit-function-declaration]
>        cdev = of_cpufreq_power_cooling_register(np, policy,
>               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>               of_cpufreq_cooling_register
>>> drivers//cpufreq/imx6q-cpufreq.c:208:8: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
>        cdev = of_cpufreq_power_cooling_register(np, policy,
>             ^
>     cc1: some warnings being treated as errors

Sorry for that. I missed changes in the CPU cooling API and confused my
kconfig ultimately resulting in the drivers not getting compiled. Will
fix and simplify this in v3.

Regards,
Bastian

-- 
Pengutronix e.K.
Industrial Linux Solutions
http://www.pengutronix.de/
Peiner Str. 6-8, 31137 Hildesheim, Germany
Amtsgericht Hildesheim, HRA 2686

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

end of thread, other threads:[~2018-06-08  8:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-07  9:51 [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF Bastian Stender
2018-06-07  9:51 ` [PATCH RESEND 2/2] ARM: dts: imx: add cooling-cells for cpufreq cooling device Bastian Stender
2018-06-07 10:15   ` Bastian Stender
2018-06-08  7:22 ` [PATCH v2 1/2] cpufreq: imx6q/thermal: imx: register cooling device depending on OF kbuild test robot
2018-06-08  8:48   ` Bastian Stender

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).