diff mbox

[01/14] thermal: exynos: Reading temperature makes sense only when TMU is turned on

Message ID 1523873525-23718-2-git-send-email-b.zolnierkie@samsung.com (mailing list archive)
State Accepted
Delegated to: Eduardo Valentin
Headers show

Commit Message

Bartlomiej Zolnierkiewicz April 16, 2018, 10:11 a.m. UTC
From: Marek Szyprowski <m.szyprowski@samsung.com>

When thermal sensor is not yet enabled, reading temperature might return
random value. This might even result in stopping system booting when such
temperature is higher than the critical value. Fix this by checking if TMU
has been actually enabled before reading the temperature.

This change fixes booting of Exynos4210-based board with TMU enabled (for
example Samsung Trats board), which was broken since v4.4 kernel release.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Fixes: 9e4249b40340 ("thermal: exynos: Fix first temperature read after registering sensor")
CC: stable@vger.kernel.org # v4.6+
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
---
 drivers/thermal/samsung/exynos_tmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Daniel Lezcano April 16, 2018, 12:06 p.m. UTC | #1
On 16/04/2018 12:11, Bartlomiej Zolnierkiewicz wrote:
> From: Marek Szyprowski <m.szyprowski@samsung.com>
> 
> When thermal sensor is not yet enabled, reading temperature might return
> random value. This might even result in stopping system booting when such
> temperature is higher than the critical value. Fix this by checking if TMU
> has been actually enabled before reading the temperature.
> 
> This change fixes booting of Exynos4210-based board with TMU enabled (for
> example Samsung Trats board), which was broken since v4.4 kernel release.

Why not move the thermal_zone_of_sensor_register *after* initializing
the sensor ?

> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Fixes: 9e4249b40340 ("thermal: exynos: Fix first temperature read after registering sensor")
> CC: stable@vger.kernel.org # v4.6+
> Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Bartlomiej Zolnierkiewicz April 16, 2018, 12:17 p.m. UTC | #2
On Monday, April 16, 2018 02:06:41 PM Daniel Lezcano wrote:
> On 16/04/2018 12:11, Bartlomiej Zolnierkiewicz wrote:
> > From: Marek Szyprowski <m.szyprowski@samsung.com>
> > 
> > When thermal sensor is not yet enabled, reading temperature might return
> > random value. This might even result in stopping system booting when such
> > temperature is higher than the critical value. Fix this by checking if TMU
> > has been actually enabled before reading the temperature.
> > 
> > This change fixes booting of Exynos4210-based board with TMU enabled (for
> > example Samsung Trats board), which was broken since v4.4 kernel release.
> 
> Why not move the thermal_zone_of_sensor_register *after* initializing
> the sensor ?

For initializing the sensor we need data obtained from
therm_zone_of_sensor_register() so it cannot be easily
done (especially since we also want the fix to be
ported to -stable kernels). For more detailed description
please see:

https://lkml.org/lkml/2018/4/10/376

> > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> > Fixes: 9e4249b40340 ("thermal: exynos: Fix first temperature read after registering sensor")
> > CC: stable@vger.kernel.org # v4.6+
> > Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics
Daniel Lezcano April 16, 2018, 12:39 p.m. UTC | #3
On 16/04/2018 14:17, Bartlomiej Zolnierkiewicz wrote:
> On Monday, April 16, 2018 02:06:41 PM Daniel Lezcano wrote:
>> On 16/04/2018 12:11, Bartlomiej Zolnierkiewicz wrote:
>>> From: Marek Szyprowski <m.szyprowski@samsung.com>
>>>
>>> When thermal sensor is not yet enabled, reading temperature might return
>>> random value. This might even result in stopping system booting when such
>>> temperature is higher than the critical value. Fix this by checking if TMU
>>> has been actually enabled before reading the temperature.
>>>
>>> This change fixes booting of Exynos4210-based board with TMU enabled (for
>>> example Samsung Trats board), which was broken since v4.4 kernel release.
>>
>> Why not move the thermal_zone_of_sensor_register *after* initializing
>> the sensor ?
> 
> For initializing the sensor we need data obtained from
> therm_zone_of_sensor_register() so it cannot be easily
> done (especially since we also want the fix to be
> ported to -stable kernels). For more detailed description
> please see:
> 
> https://lkml.org/lkml/2018/4/10/376

I see, a chicken egg problem :/

Thanks for the pointer.
diff mbox

Patch

diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index ed805c7..986cbd0 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -185,6 +185,7 @@ 
  * @regulator: pointer to the TMU regulator structure.
  * @reg_conf: pointer to structure to register with core thermal.
  * @ntrip: number of supported trip points.
+ * @enabled: current status of TMU device
  * @tmu_initialize: SoC specific TMU initialization method
  * @tmu_control: SoC specific TMU control method
  * @tmu_read: SoC specific TMU temperature read method
@@ -205,6 +206,7 @@  struct exynos_tmu_data {
 	struct regulator *regulator;
 	struct thermal_zone_device *tzd;
 	unsigned int ntrip;
+	bool enabled;
 
 	int (*tmu_initialize)(struct platform_device *pdev);
 	void (*tmu_control)(struct platform_device *pdev, bool on);
@@ -398,6 +400,7 @@  static void exynos_tmu_control(struct platform_device *pdev, bool on)
 	mutex_lock(&data->lock);
 	clk_enable(data->clk);
 	data->tmu_control(pdev, on);
+	data->enabled = on;
 	clk_disable(data->clk);
 	mutex_unlock(&data->lock);
 }
@@ -890,7 +893,7 @@  static int exynos_get_temp(void *p, int *temp)
 {
 	struct exynos_tmu_data *data = p;
 
-	if (!data || !data->tmu_read)
+	if (!data || !data->tmu_read || !data->enabled)
 		return -EINVAL;
 
 	mutex_lock(&data->lock);