Skip to content

Commit 1f835c6

Browse files
Anjelique Melendezdlezcano
authored andcommitted
thermal/drivers/qcom-spmi-temp-alarm: Prepare to support additional Temp Alarm subtypes
In preparation to support newer temp alarm subtypes, add the "ops", "sync_thresholds" and "configure_trip_temps" references to spmi_temp_alarm_data. This will allow for each Temp Alarm subtype to define its own thermal_zone_device_ops and properly initialize and configure thermal trip temperature. Signed-off-by: Anjelique Melendez <anjelique.melendez@oss.qualcomm.com> Acked-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Link: https://lore.kernel.org/r/20250710224555.3047790-4-anjelique.melendez@oss.qualcomm.com Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
1 parent 703f132 commit 1f835c6

1 file changed

Lines changed: 64 additions & 28 deletions

File tree

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

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ static const long temp_map_gen2_v1[THRESH_COUNT][STAGE_COUNT] = {
7777
struct qpnp_tm_chip;
7878

7979
struct spmi_temp_alarm_data {
80+
const struct thermal_zone_device_ops *ops;
8081
const long (*temp_map)[THRESH_COUNT][STAGE_COUNT];
82+
int (*sync_thresholds)(struct qpnp_tm_chip *chip);
8183
int (*get_temp_stage)(struct qpnp_tm_chip *chip);
84+
int (*configure_trip_temps)(struct qpnp_tm_chip *chip);
8285
};
8386

8487
struct qpnp_tm_chip {
@@ -316,73 +319,102 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data)
316319
return IRQ_HANDLED;
317320
}
318321

322+
/* Read the hardware default stage threshold temperatures */
323+
static int qpnp_tm_sync_thresholds(struct qpnp_tm_chip *chip)
324+
{
325+
u8 reg, threshold;
326+
int ret;
327+
328+
ret = qpnp_tm_read(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, &reg);
329+
if (ret < 0)
330+
return ret;
331+
332+
threshold = reg & SHUTDOWN_CTRL1_THRESHOLD_MASK;
333+
memcpy(chip->temp_thresh_map, chip->data->temp_map[threshold],
334+
sizeof(chip->temp_thresh_map));
335+
336+
return ret;
337+
}
338+
339+
static int qpnp_tm_configure_trip_temp(struct qpnp_tm_chip *chip)
340+
{
341+
int crit_temp, ret;
342+
343+
ret = thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp);
344+
if (ret)
345+
crit_temp = THERMAL_TEMP_INVALID;
346+
347+
mutex_lock(&chip->lock);
348+
ret = qpnp_tm_update_critical_trip_temp(chip, crit_temp);
349+
mutex_unlock(&chip->lock);
350+
351+
return ret;
352+
}
353+
319354
static const struct spmi_temp_alarm_data spmi_temp_alarm_data = {
355+
.ops = &qpnp_tm_sensor_ops,
320356
.temp_map = &temp_map_gen1,
357+
.sync_thresholds = qpnp_tm_sync_thresholds,
358+
.configure_trip_temps = qpnp_tm_configure_trip_temp,
321359
.get_temp_stage = qpnp_tm_gen1_get_temp_stage,
322360
};
323361

324362
static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_data = {
363+
.ops = &qpnp_tm_sensor_ops,
325364
.temp_map = &temp_map_gen1,
365+
.sync_thresholds = qpnp_tm_sync_thresholds,
366+
.configure_trip_temps = qpnp_tm_configure_trip_temp,
326367
.get_temp_stage = qpnp_tm_gen2_get_temp_stage,
327368
};
328369

329370
static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev1_data = {
371+
.ops = &qpnp_tm_sensor_ops,
330372
.temp_map = &temp_map_gen2_v1,
373+
.sync_thresholds = qpnp_tm_sync_thresholds,
374+
.configure_trip_temps = qpnp_tm_configure_trip_temp,
331375
.get_temp_stage = qpnp_tm_gen2_get_temp_stage,
332376
};
333377

334378
/*
335379
* This function initializes the internal temp value based on only the
336-
* current thermal stage and threshold. Setup threshold control and
337-
* disable shutdown override.
380+
* current thermal stage and threshold.
338381
*/
339-
static int qpnp_tm_init(struct qpnp_tm_chip *chip)
382+
static int qpnp_tm_threshold_init(struct qpnp_tm_chip *chip)
340383
{
341-
int crit_temp;
342-
u8 threshold;
343384
int ret;
344-
u8 reg;
345385

346-
mutex_lock(&chip->lock);
347-
348-
ret = qpnp_tm_read(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, &reg);
386+
ret = chip->data->sync_thresholds(chip);
349387
if (ret < 0)
350-
goto out;
351-
352-
threshold = reg & SHUTDOWN_CTRL1_THRESHOLD_MASK;
353-
memcpy(chip->temp_thresh_map, chip->data->temp_map[threshold],
354-
sizeof(chip->temp_thresh_map));
355-
356-
chip->temp = DEFAULT_TEMP;
388+
return ret;
357389

358390
ret = chip->data->get_temp_stage(chip);
359391
if (ret < 0)
360-
goto out;
392+
return ret;
361393
chip->stage = ret;
394+
chip->temp = DEFAULT_TEMP;
362395

363396
if (chip->stage)
364397
chip->temp = qpnp_tm_decode_temp(chip, chip->stage);
365398

366-
mutex_unlock(&chip->lock);
367-
368-
ret = thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp);
369-
if (ret)
370-
crit_temp = THERMAL_TEMP_INVALID;
399+
return ret;
400+
}
371401

372-
mutex_lock(&chip->lock);
402+
/* This function initializes threshold control and disables shutdown override. */
403+
static int qpnp_tm_init(struct qpnp_tm_chip *chip)
404+
{
405+
int ret;
406+
u8 reg;
373407

374-
ret = qpnp_tm_update_critical_trip_temp(chip, crit_temp);
408+
ret = chip->data->configure_trip_temps(chip);
375409
if (ret < 0)
376-
goto out;
410+
return ret;
377411

378412
/* Enable the thermal alarm PMIC module in always-on mode. */
379413
reg = ALARM_CTRL_FORCE_ENABLE;
380414
ret = qpnp_tm_write(chip, QPNP_TM_REG_ALARM_CTRL, reg);
381415

382416
chip->initialized = true;
383417

384-
out:
385-
mutex_unlock(&chip->lock);
386418
return ret;
387419
}
388420

@@ -481,13 +513,17 @@ static int qpnp_tm_probe(struct platform_device *pdev)
481513
}
482514
}
483515

516+
ret = qpnp_tm_threshold_init(chip);
517+
if (ret < 0)
518+
return dev_err_probe(&pdev->dev, ret, "threshold init failed\n");
519+
484520
/*
485521
* Register the sensor before initializing the hardware to be able to
486522
* read the trip points. get_temp() returns the default temperature
487523
* before the hardware initialization is completed.
488524
*/
489525
chip->tz_dev = devm_thermal_of_zone_register(
490-
&pdev->dev, 0, chip, &qpnp_tm_sensor_ops);
526+
&pdev->dev, 0, chip, chip->data->ops);
491527
if (IS_ERR(chip->tz_dev))
492528
return dev_err_probe(&pdev->dev, PTR_ERR(chip->tz_dev),
493529
"failed to register sensor\n");

0 commit comments

Comments
 (0)