Skip to contentSkip to conversation

thermal: imx: fix for dependency on cpu-freq

PATCH Superseded Anson Huang 2 participants 3 messages Nov 21, 2018

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 thermal: imx: fix for dependency on cpu-freq

The thermal driver is a standalone driver for monitoring SoC temperature by enabling thermal sensor, so it can be enabled even when CONFIG_CPU_FREQ is NOT set. So remove the dependency with CPU_THERMAL.

Introduce dummy function of legacy cooling register/unregister to make thermal driver probe successfully when CONFIG_CPU_FREQ is NOT set.

---
changes since V2:
fix build warning of no return value for imx_thermal_unregister_legacy_cooling.

 drivers/thermal/Kconfig       |  2 +-
 drivers/thermal/imx_thermal.c | 38 +++++++++++++++++++++++++++++---------
 2 files changed, 30 insertions(+), 10 deletions(-)
drivers/thermal/Kconfig +1 -1
index 5422523..93bd3bb 100644
@@ -212,7 +212,7 @@ config HISI_THERMAL
 
 config IMX_THERMAL
 	tristate "Temperature sensor driver for Freescale i.MX SoCs"
-	depends on (ARCH_MXC && CPU_THERMAL) || COMPILE_TEST
+	depends on ARCH_MXC || COMPILE_TEST
 	depends on NVMEM || !NVMEM
 	depends on MFD_SYSCON
 	depends on OF
drivers/thermal/imx_thermal.c +29 -9
index 1566154..518e5a0 100644
@@ -648,15 +648,24 @@ static const struct of_device_id of_imx_thermal_match[] = {
 };
 MODULE_DEVICE_TABLE(of, of_imx_thermal_match);
 
+#ifdef CONFIG_CPU_FREQ
 /*
  * 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_node *np = of_get_cpu_node(data->policy->cpu, NULL);
+	struct device_node *np;
 	int ret;
 
+	data->policy = cpufreq_cpu_get(0);
+	if (!data->policy) {
+		pr_debug("%s: CPUFreq policy not found\n", __func__);
+		return -EPROBE_DEFER;
+	}
+
+	np = of_get_cpu_node(data->policy->cpu, NULL);
+
 	if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
 		data->cdev = cpufreq_cooling_register(data->policy);
 		if (IS_ERR(data->cdev)) {
@@ -669,6 +678,22 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 	return 0;
 }
 
+static void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data *data)
+{
+	cpufreq_cooling_unregister(data->cdev);
+	cpufreq_cpu_put(data->policy);
+}
+#else
+static inline int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
+{
+	return 0;
+}
+
+static inline void imx_thermal_unregister_legacy_cooling(struct imx_thermal_data *data)
+{
+}
+#endif
+
 static int imx_thermal_probe(struct platform_device *pdev)
 {
 	struct imx_thermal_data *data;
@@ -743,13 +768,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
 	regmap_write(map, data->socdata->sensor_ctrl + REG_SET,
 		     data->socdata->power_down_mask);
 
-	data->policy = cpufreq_cpu_get(0);
-	if (!data->policy) {
-		pr_debug("%s: CPUFreq policy not found\n", __func__);
-		return -EPROBE_DEFER;
-	}
-
 	ret = imx_thermal_register_legacy_cooling(data);
+	if (ret == -EPROBE_DEFER)
+		return ret;
 	if (ret) {
 		dev_err(&pdev->dev,
 			"failed to register cpufreq cooling device: %d\n", ret);
@@ -830,8 +851,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
 clk_disable:
 	clk_disable_unprepare(data->thermal_clk);
 cpufreq_put:
-	cpufreq_cooling_unregister(data->cdev);
-	cpufreq_cpu_put(data->policy);
+	imx_thermal_unregister_legacy_cooling(data);
 
 	return ret;
 }
Signature · 1 line
2.7.4
#1 lore raw

drivers/thermal/imx_thermal.c static int imx_thermal_probe(struct platform_device *pdev) · line 853

Quoted 4 lines · Anson Huang
drivers/thermal/imx_thermal.c +0 -0
@@ -830,8 +851,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
 clk_disable:
        clk_disable_unprepare(data->thermal_clk);
 cpufreq_put:

While at it, rename this label as well to something like legacy_cleanup.

Quoted 6 lines
drivers/thermal/imx_thermal.c +1 -2
-       cpufreq_cooling_unregister(data->cdev);
-       cpufreq_cpu_put(data->policy);
+       imx_thermal_unregister_legacy_cooling(data);
 
        return ret;
 }
#2 lore raw

Best Regards!
Anson Huang

Quoted 14 lines

-----Original Message-----
From: Viresh Kumar [mailto:[email protected]]
Sent: 2018年11月21日 11:54
To: Anson Huang <[email protected]>
Cc: Zhang Rui <[email protected]>; Eduardo Valentin <[email protected]>; Daniel Lezcano <[email protected]>; Linux PM list <[email protected]>; Linux Kernel Mailing List <[email protected]>; [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V3] thermal: imx: fix for dependency on cpu-freq

On Wed, Nov 21, 2018 at 8:11 AM Anson Huang <[email protected]> wrote:

Quoted 7 lines

Review static int imx_thermal_probe(struct platform_device

Quoted 1 line
(quoted diff) +0 -0
@@ -830,8 +851,7 @@ static int imx_thermal_probe(struct platform_device

*pdev)

drivers/thermal/imx_thermal.c static int imx_thermal_probe(struct platform_device *pdev) · line 853

Quoted 3 lines
drivers/thermal/imx_thermal.c +0 -0
 clk_disable:
        clk_disable_unprepare(data->thermal_clk);
 cpufreq_put:

While at it, rename this label as well to something like legacy_cleanup.

Done with V4 patch, thanks.

Anson.

Quoted 7 lines
Quoted 7 lines
drivers/thermal/imx_thermal.c +1 -2
-       cpufreq_cooling_unregister(data->cdev);
-       cpufreq_cpu_put(data->policy);
+       imx_thermal_unregister_legacy_cooling(data);
 
        return ret;
 }