diff mbox

[2/3] thermal: imx: add necessary clk operation

Message ID 1387477045-19037-2-git-send-email-b20788@freescale.com (mailing list archive)
State New, archived
Headers show

Commit Message

Anson Huang Dec. 19, 2013, 6:17 p.m. UTC
Thermal sensor needs pll3_usb_otg when measuring temperature,
otherwise the temperature read will be incorrect, so need to
enable this clk before sensor working, for alarm function,
as hardware will take measurement periodically, so we should
keep this clk always on once alarm function is enabled.

Signed-off-by: Anson Huang <b20788@freescale.com>
---
 drivers/thermal/imx_thermal.c |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Baruch Siach Dec. 19, 2013, 6:24 a.m. UTC | #1
Hi Anson,

On Thu, Dec 19, 2013 at 01:17:24PM -0500, Anson Huang wrote:
> +	if (IS_ERR(data->thermal_clk)) {
> +		ret = IS_ERR(data->thermal_clk);

You probably what to return PTR_ERR here.

baruch

> +		dev_err(&pdev->dev, "failed to get thermal clk!\n");
> +		return ret;
> +	}
Anson.Huang@freescale.com Dec. 19, 2013, 6:52 a.m. UTC | #2
Best Regards.
Anson huang ???
 
Freescale Semiconductor Shanghai
?????????192?A?2?
201203
Tel:021-28937058


>-----Original Message-----

>From: Baruch Siach [mailto:baruch@tkos.co.il]

>Sent: Thursday, December 19, 2013 2:25 PM

>To: Huang Yongcai-B20788

>Cc: shawn.guo@linaro.org; kernel@pengutronix.de; rui.zhang@intel.com;

>eduardo.valentin@ti.com; devicetree@vger.kernel.org; linux-pm@vger.kernel.org;

>linux-arm-kernel@lists.infradead.org; linux-doc@vger.kernel.org

>Subject: Re: [PATCH 2/3] thermal: imx: add necessary clk operation

>

>Hi Anson,

>

>On Thu, Dec 19, 2013 at 01:17:24PM -0500, Anson Huang wrote:

>> +	if (IS_ERR(data->thermal_clk)) {

>> +		ret = IS_ERR(data->thermal_clk);

>

>You probably what to return PTR_ERR here.

>


Yes, thanks, will fix it in V2.
[Anson] 


>baruch

>

>> +		dev_err(&pdev->dev, "failed to get thermal clk!\n");

>> +		return ret;

>> +	}

>

>--

>     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems

>=}------------------------------------------------ooO--U--Ooo------------{=

>   - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

>
Shawn Guo Dec. 19, 2013, 6:59 a.m. UTC | #3
On Thu, Dec 19, 2013 at 01:17:24PM -0500, Anson Huang wrote:
> @@ -427,6 +429,13 @@ static int imx_thermal_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> +	data->thermal_clk = devm_clk_get(&pdev->dev, NULL);
> +	if (IS_ERR(data->thermal_clk)) {
> +		ret = IS_ERR(data->thermal_clk);
> +		dev_err(&pdev->dev, "failed to get thermal clk!\n");
> +		return ret;
> +	}
> +

So when the new kernel runs on a board with an old DTB installed,
thermal driver will be broken.

Shawn
Anson.Huang@freescale.com Dec. 19, 2013, 7:08 a.m. UTC | #4
Best Regards.
Anson huang ???
 
Freescale Semiconductor Shanghai
?????????192?A?2?
201203
Tel:021-28937058


>-----Original Message-----

>From: Shawn Guo [mailto:shawn.guo@linaro.org]

>Sent: Thursday, December 19, 2013 2:59 PM

>To: Huang Yongcai-B20788

>Cc: kernel@pengutronix.de; rui.zhang@intel.com; eduardo.valentin@ti.com;

>devicetree@vger.kernel.org; linux-doc@vger.kernel.org; linux-arm-

>kernel@lists.infradead.org; linux-pm@vger.kernel.org

>Subject: Re: [PATCH 2/3] thermal: imx: add necessary clk operation

>

>On Thu, Dec 19, 2013 at 01:17:24PM -0500, Anson Huang wrote:

>> @@ -427,6 +429,13 @@ static int imx_thermal_probe(struct platform_device

>*pdev)

>>  		return ret;

>>  	}

>>

>> +	data->thermal_clk = devm_clk_get(&pdev->dev, NULL);

>> +	if (IS_ERR(data->thermal_clk)) {

>> +		ret = IS_ERR(data->thermal_clk);

>> +		dev_err(&pdev->dev, "failed to get thermal clk!\n");

>> +		return ret;

>> +	}

>> +

>

>So when the new kernel runs on a board with an old DTB installed, thermal

>driver will be broken.

>

Yes, I thought about this case, but the previous implement is incorrect, if
the PLL3 is not enabled by other drivers, thermal driver will not work, so
this patch is a bug fix, not enhancement. So we still need to consider old
dts case? 

Anson

>Shawn
Shawn Guo Dec. 19, 2013, 7:29 a.m. UTC | #5
On Thu, Dec 19, 2013 at 07:08:16AM +0000, Anson.Huang@freescale.com wrote:
> >On Thu, Dec 19, 2013 at 01:17:24PM -0500, Anson Huang wrote:
> >> @@ -427,6 +429,13 @@ static int imx_thermal_probe(struct platform_device
> >*pdev)
> >>  		return ret;
> >>  	}
> >>
> >> +	data->thermal_clk = devm_clk_get(&pdev->dev, NULL);
> >> +	if (IS_ERR(data->thermal_clk)) {
> >> +		ret = IS_ERR(data->thermal_clk);
> >> +		dev_err(&pdev->dev, "failed to get thermal clk!\n");
> >> +		return ret;
> >> +	}
> >> +
> >
> >So when the new kernel runs on a board with an old DTB installed, thermal
> >driver will be broken.
> >
> Yes, I thought about this case, but the previous implement is incorrect, if
> the PLL3 is not enabled by other drivers, thermal driver will not work, so
> this patch is a bug fix, not enhancement. So we still need to consider old
> dts case? 

The thing is mainline kernel runs on many board with thermal driver
being functional today.  That said, PLL3 is already enabled on these
platforms when thermal driver is running.  You cannot fix a bug but
meanwhile break these users who use old DTB.

Shawn
Anson.Huang@freescale.com Dec. 19, 2013, 7:33 a.m. UTC | #6
Best Regards.
Anson huang ???
 
Freescale Semiconductor Shanghai
?????????192?A?2?
201203
Tel:021-28937058


>-----Original Message-----

>From: Shawn Guo [mailto:shawn.guo@linaro.org]

>Sent: Thursday, December 19, 2013 3:29 PM

>To: Huang Yongcai-B20788

>Cc: kernel@pengutronix.de; rui.zhang@intel.com; eduardo.valentin@ti.com;

>devicetree@vger.kernel.org; linux-doc@vger.kernel.org; linux-arm-

>kernel@lists.infradead.org; linux-pm@vger.kernel.org

>Subject: Re: [PATCH 2/3] thermal: imx: add necessary clk operation

>

>On Thu, Dec 19, 2013 at 07:08:16AM +0000, Anson.Huang@freescale.com wrote:

>> >On Thu, Dec 19, 2013 at 01:17:24PM -0500, Anson Huang wrote:

>> >> @@ -427,6 +429,13 @@ static int imx_thermal_probe(struct

>> >> platform_device

>> >*pdev)

>> >>  		return ret;

>> >>  	}

>> >>

>> >> +	data->thermal_clk = devm_clk_get(&pdev->dev, NULL);

>> >> +	if (IS_ERR(data->thermal_clk)) {

>> >> +		ret = IS_ERR(data->thermal_clk);

>> >> +		dev_err(&pdev->dev, "failed to get thermal clk!\n");

>> >> +		return ret;

>> >> +	}

>> >> +

>> >

>> >So when the new kernel runs on a board with an old DTB installed,

>> >thermal driver will be broken.

>> >

>> Yes, I thought about this case, but the previous implement is

>> incorrect, if the PLL3 is not enabled by other drivers, thermal driver

>> will not work, so this patch is a bug fix, not enhancement. So we

>> still need to consider old dts case?

>

>The thing is mainline kernel runs on many board with thermal driver being

>functional today.  That said, PLL3 is already enabled on these platforms when

>thermal driver is running.  You cannot fix a bug but meanwhile break these

>users who use old DTB.


Okay, got it, I will replace the return with one warning message in V2.

Anson 


>

>Shawn
diff mbox

Patch

diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 1d6c801..7abbc04 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -7,6 +7,7 @@ 
  *
  */
 
+#include <linux/clk.h>
 #include <linux/cpu_cooling.h>
 #include <linux/cpufreq.h>
 #include <linux/delay.h>
@@ -73,6 +74,7 @@  struct imx_thermal_data {
 	unsigned long last_temp;
 	bool irq_enabled;
 	int irq;
+	struct clk *thermal_clk;
 };
 
 static void imx_set_alarm_temp(struct imx_thermal_data *data,
@@ -427,6 +429,13 @@  static int imx_thermal_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	data->thermal_clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(data->thermal_clk)) {
+		ret = IS_ERR(data->thermal_clk);
+		dev_err(&pdev->dev, "failed to get thermal clk!\n");
+		return ret;
+	}
+
 	/* Make sure sensor is in known good state for measurements */
 	regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_POWER_DOWN);
 	regmap_write(map, TEMPSENSE0 + REG_CLR, TEMPSENSE0_MEASURE_TEMP);
@@ -457,6 +466,19 @@  static int imx_thermal_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	/*
+	 * Thermal sensor needs clk on to get correct value, normally
+	 * we should enable its clk before taking measurement and disable
+	 * clk after measurement is done, but if alarm function is enabled,
+	 * hardware will auto measure the temperature periodically, so we
+	 * need to keep the clk always on for alarm function.
+	 */
+	ret = clk_prepare_enable(data->thermal_clk);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to enable thermal clk: %d\n", ret);
+		return ret;
+	}
+
 	/* Enable measurements at ~ 10 Hz */
 	regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ);
 	measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */