wlan-ap-Telecominfraproject/feeds/qca-wifi-7/ipq53xx/patches-6.1/0358-drivers-thermal-qcom-Thermal-panic-notifier.patch
John Crispin 68cf54d9f7 qca-wifi-7: update to ath12.5.5
Signed-off-by: John Crispin <john@phrozen.org>
2025-02-27 12:45:52 +01:00

142 lines
4.1 KiB
Diff

From 95489a5899e663ebc714dd3a87fcf29cff96dc59 Mon Sep 17 00:00:00 2001
From: Hariharan K <quic_harihk@quicinc.com>
Date: Sat, 8 Jul 2023 16:16:33 +0530
Subject: [PATCH] drivers: thermal: qcom: Thermal panic notifier
Adding a panic notifier to the tsens driver.
Whenever there is a kernel panic or crash the
thermal panic notifier will print the status
register of each sensor.
Change-Id: Ida8ecdb2f968ab93d4c350c9d43c7d39f21081ad
Signed-off-by: Hariharan K <quic_harihk@quicinc.com>
---
drivers/thermal/qcom/tsens.c | 41 ++++++++++++++++++++++++++++++++++
drivers/thermal/thermal_core.c | 24 ++++++++++++++++++++
include/linux/thermal.h | 1 +
3 files changed, 66 insertions(+)
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 6fbb390163c2..ddad192f9a32 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -535,6 +535,46 @@ static void notify_uspace_tsens_fn(struct work_struct *work)
sysfs_notify(&s->tzd->device.kobj, NULL, "type");
}
+static int tsens_panic_notify(struct thermal_zone_device *tz)
+{
+ struct tsens_sensor *s = tz->devdata;
+ struct tsens_priv *priv = s->priv;
+ u32 hw_id = s->hw_id;
+ unsigned int try = 0;
+ u32 trdy, valid;
+ unsigned int reg_val = 0;
+
+ if (tsens_version(priv) < VER_0_1) {
+ /* Pre v0.1 IP had a single register for each type of interrupt
+ * and thresholds
+ */
+ hw_id = 0;
+ }
+
+ if ((hw_id < 0) || (hw_id > (MAX_SENSOR - 1)))
+ return -EINVAL;
+
+ for(try = 0; try < 100; try++) {
+ try++;
+ regmap_field_read(priv->rf[TRDY], &trdy);
+
+ if (!trdy)
+ continue;
+
+ regmap_field_read(priv->rf[VALID_0 + hw_id], &valid);
+
+ if (!valid)
+ continue;
+
+ regmap_read(priv->tm_map, priv->fields[VALID_0 + hw_id].reg, &reg_val);
+ pr_emerg("The reading for sensor %d is 0x%08x\n", s->hw_id, reg_val);
+ return 0;
+ }
+
+ pr_emerg("Couldn't get reading for sensor %d\n", s->hw_id);
+ return -EINVAL;
+}
+
static int __maybe_unused tsens_set_trip_activate(void *data, int trip,
enum thermal_trip_activation_mode mode)
{
@@ -1105,6 +1145,7 @@ MODULE_DEVICE_TABLE(of, tsens_table);
static const struct thermal_zone_device_ops tsens_of_ops = {
.get_temp = tsens_get_temp,
+ .panic_notify = tsens_panic_notify,
#ifdef CONFIG_CPU_THERMAL
.set_trips = tsens_set_trips,
#else
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 1eae4ec719a8..8afd6799098a 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -20,6 +20,7 @@
#include <linux/string.h>
#include <linux/of.h>
#include <linux/suspend.h>
+#include <linux/panic_notifier.h>
#define CREATE_TRACE_POINTS
#include <trace/events/thermal.h>
@@ -1475,6 +1476,23 @@ static struct notifier_block thermal_pm_nb = {
.notifier_call = thermal_pm_notify,
};
+static int thermal_panic_notify(struct notifier_block *nb,
+ unsigned long mode, void *_unused)
+{
+ struct thermal_zone_device *tz;
+
+ list_for_each_entry(tz, &thermal_tz_list, node) {
+ if (tz->ops->panic_notify)
+ tz->ops->panic_notify(tz);
+ }
+
+ return 0;
+}
+
+static struct notifier_block panic_nb = {
+ .notifier_call = thermal_panic_notify,
+};
+
static int __init thermal_init(void)
{
int result;
@@ -1496,6 +1514,12 @@ static int __init thermal_init(void)
pr_warn("Thermal: Can not register suspend notifier, return %d\n",
result);
+ result = atomic_notifier_chain_register(&panic_notifier_list,
+ &panic_nb);
+ if (result)
+ pr_warn("Thermal: Can not register panic notifier, return %d\n",
+ result);
+
return 0;
unregister_governors:
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 04f97b7f835f..789c9eebf668 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -59,6 +59,7 @@ struct thermal_zone_device_ops {
int (*unbind) (struct thermal_zone_device *,
struct thermal_cooling_device *);
int (*get_temp) (struct thermal_zone_device *, int *);
+ int (*panic_notify) (struct thermal_zone_device *);
int (*set_trips) (struct thermal_zone_device *, int, int);
int (*change_mode) (struct thermal_zone_device *,
enum thermal_device_mode);
--
2.34.1