Skip to content

Commit 735c353

Browse files
tmlinddlezcano
authored andcommitted
thermal: ti-soc-thermal: Fix stuck sensor with continuous mode for 4430
At least for 4430, trying to use the single conversion mode eventually hangs the thermal sensor. This can be quite easily seen with errors: thermal thermal_zone0: failed to read out thermal zone (-5) Also, trying to read the temperature shows a stuck value with: $ while true; do cat /sys/class/thermal/thermal_zone0/temp; done Where the temperature is not rising at all with the busy loop. Additionally, the EOCZ (end of conversion) bit is not rising on 4430 in single conversion mode while it works fine in continuous conversion mode. It is also possible that the hung temperature sensor can affect the thermal shutdown alert too. Let's fix the issue by adding TI_BANDGAP_FEATURE_CONT_MODE_ONLY flag and use it for 4430. Note that we also need to add udelay to for the EOCZ (end of conversion) bit polling as otherwise we have it time out too early on 4430. We'll be changing the loop to use iopoll in the following clean-up patch. Cc: Adam Ford <aford173@gmail.com> Cc: Carl Philipp Klemm <philipp@uvos.xyz> Cc: Eduardo Valentin <edubezval@gmail.com> Cc: H. Nikolaus Schaller <hns@goldelico.com> Cc: Merlijn Wajer <merlijn@wizzup.org> Cc: Pavel Machek <pavel@ucw.cz> Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com> Cc: Sebastian Reichel <sre@kernel.org> Signed-off-by: Tony Lindgren <tony@atomide.com> Tested-by: Adam Ford <aford173@gmail.com> #logicpd-torpedo-37xx-devkit Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20210205134534.49200-3-tony@atomide.com
1 parent b57b4b4 commit 735c353

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

drivers/thermal/ti-soc-thermal/omap4-thermal-data.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ omap4430_adc_to_temp[OMAP4430_ADC_END_VALUE - OMAP4430_ADC_START_VALUE + 1] = {
5858
const struct ti_bandgap_data omap4430_data = {
5959
.features = TI_BANDGAP_FEATURE_MODE_CONFIG |
6060
TI_BANDGAP_FEATURE_CLK_CTRL |
61-
TI_BANDGAP_FEATURE_POWER_SWITCH,
61+
TI_BANDGAP_FEATURE_POWER_SWITCH |
62+
TI_BANDGAP_FEATURE_CONT_MODE_ONLY,
6263
.fclock_name = "bandgap_fclk",
6364
.div_ck_name = "bandgap_fclk",
6465
.conv_table = omap4430_adc_to_temp,

drivers/thermal/ti-soc-thermal/ti-bandgap.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/kernel.h>
1616
#include <linux/interrupt.h>
1717
#include <linux/clk.h>
18+
#include <linux/delay.h>
1819
#include <linux/gpio/consumer.h>
1920
#include <linux/platform_device.h>
2021
#include <linux/err.h>
@@ -605,9 +606,13 @@ ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id)
605606
struct temp_sensor_registers *tsr = bgp->conf->sensors[id].registers;
606607
u32 counter;
607608

608-
/* Select single conversion mode */
609-
if (TI_BANDGAP_HAS(bgp, MODE_CONFIG))
610-
RMW_BITS(bgp, id, bgap_mode_ctrl, mode_ctrl_mask, 0);
609+
/* Select continuous or single conversion mode */
610+
if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) {
611+
if (TI_BANDGAP_HAS(bgp, CONT_MODE_ONLY))
612+
RMW_BITS(bgp, id, bgap_mode_ctrl, mode_ctrl_mask, 1);
613+
else
614+
RMW_BITS(bgp, id, bgap_mode_ctrl, mode_ctrl_mask, 0);
615+
}
611616

612617
/* Set Start of Conversion if available */
613618
if (tsr->bgap_soc_mask) {
@@ -619,6 +624,7 @@ ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id)
619624
if (ti_bandgap_readl(bgp, tsr->temp_sensor_ctrl) &
620625
tsr->bgap_eocz_mask)
621626
break;
627+
udelay(1);
622628
}
623629

624630
/* Clear Start of Conversion if available */
@@ -631,6 +637,7 @@ ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id)
631637
if (!(ti_bandgap_readl(bgp, tsr->temp_sensor_ctrl) &
632638
tsr->bgap_eocz_mask))
633639
break;
640+
udelay(1);
634641
}
635642

636643
return 0;

drivers/thermal/ti-soc-thermal/ti-bandgap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ struct ti_temp_sensor {
280280
* has Errata 814
281281
* TI_BANDGAP_FEATURE_UNRELIABLE - used when the sensor readings are too
282282
* inaccurate.
283+
* TI_BANDGAP_FEATURE_CONT_MODE_ONLY - used when single mode hangs the sensor
283284
* TI_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a
284285
* specific feature (above) or not. Return non-zero, if yes.
285286
*/
@@ -295,6 +296,7 @@ struct ti_temp_sensor {
295296
#define TI_BANDGAP_FEATURE_HISTORY_BUFFER BIT(9)
296297
#define TI_BANDGAP_FEATURE_ERRATA_814 BIT(10)
297298
#define TI_BANDGAP_FEATURE_UNRELIABLE BIT(11)
299+
#define TI_BANDGAP_FEATURE_CONT_MODE_ONLY BIT(12)
298300
#define TI_BANDGAP_HAS(b, f) \
299301
((b)->conf->features & TI_BANDGAP_FEATURE_ ## f)
300302

0 commit comments

Comments
 (0)