thermal/drivers/tsens: Add suspend to RAM support for tsens
authorPriyansh Jain <quic_priyjain@quicinc.com>
Thu, 28 Mar 2024 05:02:30 +0000 (10:32 +0530)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Tue, 23 Apr 2024 10:40:29 +0000 (12:40 +0200)
As part of suspend to RAM, tsens hardware will be turned off.
While resume callback, re-initialize tsens hardware.

Signed-off-by: Priyansh Jain <quic_priyjain@quicinc.com>
Acked-by: Amit Kucheria <amitk@kernel.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20240328050230.31770-1-quic_priyjain@quicinc.com
drivers/thermal/qcom/tsens-v2.c
drivers/thermal/qcom/tsens.c
drivers/thermal/qcom/tsens.h

index 29a61d2d6ca312c715a086e848ae0978aaf7dbd2..0cb7301eca6e93cf5bc07fe3706730a32a5fb822 100644 (file)
@@ -107,6 +107,7 @@ static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = {
 static const struct tsens_ops ops_generic_v2 = {
        .init           = init_common,
        .get_temp       = get_temp_tsens_valid,
+       .resume         = tsens_resume_common,
 };
 
 struct tsens_plat_data data_tsens_v2 = {
index 6d7c16ccb44dc44946ec7937659e2727fe2fe0ba..1c9df4f84641109c527e274b34efb4c17121dd34 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/pm.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
+#include <linux/suspend.h>
 #include <linux/thermal.h>
 #include "../thermal_hwmon.h"
 #include "tsens.h"
@@ -1193,6 +1194,36 @@ static int tsens_register_irq(struct tsens_priv *priv, char *irqname,
        return ret;
 }
 
+#ifdef CONFIG_SUSPEND
+static int tsens_reinit(struct tsens_priv *priv)
+{
+       if (tsens_version(priv) >= VER_2_X) {
+               /*
+                * Re-enable the watchdog, unmask the bark.
+                * Disable cycle completion monitoring
+                */
+               if (priv->feat->has_watchdog) {
+                       regmap_field_write(priv->rf[WDOG_BARK_MASK], 0);
+                       regmap_field_write(priv->rf[CC_MON_MASK], 1);
+               }
+
+               /* Re-enable interrupts */
+               tsens_enable_irq(priv);
+       }
+
+       return 0;
+}
+
+int tsens_resume_common(struct tsens_priv *priv)
+{
+       if (pm_suspend_target_state == PM_SUSPEND_MEM)
+               tsens_reinit(priv);
+
+       return 0;
+}
+
+#endif /* !CONFIG_SUSPEND */
+
 static int tsens_register(struct tsens_priv *priv)
 {
        int i, ret;
index cb637fa289cac1f75da4305bbbc927385f005b54..cab39de045b100030de6a1209c58bb09561a3224 100644 (file)
@@ -634,6 +634,11 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mo
 int init_common(struct tsens_priv *priv);
 int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
 int get_temp_common(const struct tsens_sensor *s, int *temp);
+#ifdef CONFIG_SUSPEND
+int tsens_resume_common(struct tsens_priv *priv);
+#else
+#define tsens_resume_common            NULL
+#endif
 
 /* TSENS target */
 extern struct tsens_plat_data data_8960;