Skip to content

Commit f8e157f

Browse files
David Collinsdlezcano
authored andcommitted
thermal/drivers/qcom-spmi-temp-alarm: Enable stage 2 shutdown when required
Certain TEMP_ALARM GEN2 PMIC peripherals need over-temperature stage 2 automatic PMIC partial shutdown. This will ensure that in the event of reaching the hotter stage 3 over-temperature threshold, repeated faults will be avoided during the automatic PMIC hardware full shutdown. Modify the stage 2 shutdown control logic to ensure that stage 2 shutdown is enabled on all affected PMICs. Read the digital major and minor revision registers to identify these PMICs. Signed-off-by: David Collins <david.collins@oss.qualcomm.com> Signed-off-by: Anjelique Melendez <anjelique.melendez@oss.qualcomm.com> Link: https://lore.kernel.org/r/20250710224555.3047790-2-anjelique.melendez@oss.qualcomm.com Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
1 parent d7b8f8e commit f8e157f

1 file changed

Lines changed: 34 additions & 9 deletions

File tree

drivers/thermal/qcom/qcom-spmi-temp-alarm.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
33
* Copyright (c) 2011-2015, 2017, 2020, The Linux Foundation. All rights reserved.
4+
* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
45
*/
56

67
#include <linux/bitops.h>
@@ -16,6 +17,7 @@
1617

1718
#include "../thermal_hwmon.h"
1819

20+
#define QPNP_TM_REG_DIG_MINOR 0x00
1921
#define QPNP_TM_REG_DIG_MAJOR 0x01
2022
#define QPNP_TM_REG_TYPE 0x04
2123
#define QPNP_TM_REG_SUBTYPE 0x05
@@ -31,7 +33,7 @@
3133
#define STATUS_GEN2_STATE_MASK GENMASK(6, 4)
3234
#define STATUS_GEN2_STATE_SHIFT 4
3335

34-
#define SHUTDOWN_CTRL1_OVERRIDE_S2 BIT(6)
36+
#define SHUTDOWN_CTRL1_OVERRIDE_STAGE2 BIT(6)
3537
#define SHUTDOWN_CTRL1_THRESHOLD_MASK GENMASK(1, 0)
3638

3739
#define SHUTDOWN_CTRL1_RATE_25HZ BIT(3)
@@ -78,6 +80,7 @@ struct qpnp_tm_chip {
7880
/* protects .thresh, .stage and chip registers */
7981
struct mutex lock;
8082
bool initialized;
83+
bool require_stage2_shutdown;
8184

8285
struct iio_channel *adc;
8386
const long (*temp_map)[THRESH_COUNT][STAGE_COUNT];
@@ -220,13 +223,13 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
220223
{
221224
long stage2_threshold_min = (*chip->temp_map)[THRESH_MIN][1];
222225
long stage2_threshold_max = (*chip->temp_map)[THRESH_MAX][1];
223-
bool disable_s2_shutdown = false;
226+
bool disable_stage2_shutdown = false;
224227
u8 reg;
225228

226229
WARN_ON(!mutex_is_locked(&chip->lock));
227230

228231
/*
229-
* Default: S2 and S3 shutdown enabled, thresholds at
232+
* Default: Stage 2 and Stage 3 shutdown enabled, thresholds at
230233
* lowest threshold set, monitoring at 25Hz
231234
*/
232235
reg = SHUTDOWN_CTRL1_RATE_25HZ;
@@ -241,12 +244,12 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
241244
chip->thresh = THRESH_MAX -
242245
((stage2_threshold_max - temp) /
243246
TEMP_THRESH_STEP);
244-
disable_s2_shutdown = true;
247+
disable_stage2_shutdown = true;
245248
} else {
246249
chip->thresh = THRESH_MAX;
247250

248251
if (chip->adc)
249-
disable_s2_shutdown = true;
252+
disable_stage2_shutdown = true;
250253
else
251254
dev_warn(chip->dev,
252255
"No ADC is configured and critical temperature %d mC is above the maximum stage 2 threshold of %ld mC! Configuring stage 2 shutdown at %ld mC.\n",
@@ -255,8 +258,8 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
255258

256259
skip:
257260
reg |= chip->thresh;
258-
if (disable_s2_shutdown)
259-
reg |= SHUTDOWN_CTRL1_OVERRIDE_S2;
261+
if (disable_stage2_shutdown && !chip->require_stage2_shutdown)
262+
reg |= SHUTDOWN_CTRL1_OVERRIDE_STAGE2;
260263

261264
return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg);
262265
}
@@ -350,8 +353,8 @@ static int qpnp_tm_probe(struct platform_device *pdev)
350353
{
351354
struct qpnp_tm_chip *chip;
352355
struct device_node *node;
353-
u8 type, subtype, dig_major;
354-
u32 res;
356+
u8 type, subtype, dig_major, dig_minor;
357+
u32 res, dig_revision;
355358
int ret, irq;
356359

357360
node = pdev->dev.of_node;
@@ -402,6 +405,11 @@ static int qpnp_tm_probe(struct platform_device *pdev)
402405
return dev_err_probe(&pdev->dev, ret,
403406
"could not read dig_major\n");
404407

408+
ret = qpnp_tm_read(chip, QPNP_TM_REG_DIG_MINOR, &dig_minor);
409+
if (ret < 0)
410+
return dev_err_probe(&pdev->dev, ret,
411+
"could not read dig_minor\n");
412+
405413
if (type != QPNP_TM_TYPE || (subtype != QPNP_TM_SUBTYPE_GEN1
406414
&& subtype != QPNP_TM_SUBTYPE_GEN2)) {
407415
dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n",
@@ -415,6 +423,23 @@ static int qpnp_tm_probe(struct platform_device *pdev)
415423
else
416424
chip->temp_map = &temp_map_gen1;
417425

426+
if (chip->subtype == QPNP_TM_SUBTYPE_GEN2) {
427+
dig_revision = (dig_major << 8) | dig_minor;
428+
/*
429+
* Check if stage 2 automatic partial shutdown must remain
430+
* enabled to avoid potential repeated faults upon reaching
431+
* over-temperature stage 3.
432+
*/
433+
switch (dig_revision) {
434+
case 0x0001:
435+
case 0x0002:
436+
case 0x0100:
437+
case 0x0101:
438+
chip->require_stage2_shutdown = true;
439+
break;
440+
}
441+
}
442+
418443
/*
419444
* Register the sensor before initializing the hardware to be able to
420445
* read the trip points. get_temp() returns the default temperature

0 commit comments

Comments
 (0)