Skip to contentSkip to conversation

Add cold interrupt support to tsens driver

PATCH Superseded Manaf Meethalavalappu Pallikunhi 1 participant 3 messages May 22, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover Add cold interrupt support to tsens driver

The changes have dependency on merging tsens-common.c into tsens.c [1] to merge first.

Dependencies:
[1] https://lkml.org/lkml/2020/4/29/1028

Changes in v3:
* Add cold interrupt support to tsens driver
* Update cold interrupt support in yaml

*** BLURB HERE ***

Manaf Meethalavalappu Pallikunhi (2):
drivers: thermal: tsens: Add cold interrupt support
dt-bindings: thermal: tsens: Add cold interrupt support in yaml

 .../bindings/thermal/qcom-tsens.yaml          |  42 +++++++
 drivers/thermal/qcom/tsens-v2.c               |   5 +
 drivers/thermal/qcom/tsens.c                  | 112 +++++++++++++++++-
 drivers/thermal/qcom/tsens.h                  |  11 ++
 4 files changed, 169 insertions(+), 1 deletion(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v3 1/2 drivers: thermal: tsens: Add cold interrupt support

TSENS IP v2.6+ adds cold interrupt support. It triggers set interrupt when aggregated minimum temperature of all TSENS falls below cold preset threshold, 5 degree Celsius and triggers reset interrupt when aggregated minimum temperature of all TSENS crosses above reset threshold, 10 degree Celsius. These threshold values could change in boot firmware code. Add support for this interrupt in the driver.

It adds another virtual sensor to the of-thermal along with all individual TSENS. This cold sensor only gives cold state value of 1 or 0 for successful temperature read. A state value of 1 indicates minimum one TSENS is in cold temperature condition and state value of 0 indicates all TSENS are out of cold temperature condition.

---
 drivers/thermal/qcom/tsens-v2.c |   5 ++
 drivers/thermal/qcom/tsens.c    | 112 +++++++++++++++++++++++++++++++-
 drivers/thermal/qcom/tsens.h    |  11 ++++
 3 files changed, 127 insertions(+), 1 deletion(-)
drivers/thermal/qcom/tsens-v2.c +5 -0
index b293ed32174b..1692e636d3bd 100644
@@ -23,6 +23,7 @@
 #define TM_Sn_UPPER_LOWER_THRESHOLD_OFF 0x0020
 #define TM_Sn_CRITICAL_THRESHOLD_OFF	0x0060
 #define TM_Sn_STATUS_OFF		0x00a0
+#define TM_COLD_INT_STATUS_OFF		0x00e0
 #define TM_TRDY_OFF			0x00e4
 #define TM_WDOG_LOG_OFF		0x013c
 
@@ -86,6 +87,9 @@ static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = {
 	REG_FIELD_FOR_EACH_SENSOR16(CRITICAL_STATUS, TM_Sn_STATUS_OFF, 19,  19),
 	REG_FIELD_FOR_EACH_SENSOR16(MAX_STATUS,      TM_Sn_STATUS_OFF, 20,  20),
 
+	/* COLD INTERRUPT STATUS */
+	[COLD_STATUS] = REG_FIELD(TM_COLD_INT_STATUS_OFF, 0, 0),
+
 	/* TRDY: 1=ready, 0=in progress */
 	[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
 };
@@ -93,6 +97,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,
+	.get_cold_status  = get_cold_int_status,
 };
 
 struct tsens_plat_data data_tsens_v2 = {
drivers/thermal/qcom/tsens.c +111 -1

160 lines not on this page · raw message

drivers/thermal/qcom/tsens.h +11 -0
index 59d01162c66a..be532fabef30 100644
@@ -15,6 +15,7 @@
 #define SLOPE_DEFAULT		3200
 #define THRESHOLD_MAX_ADC_CODE	0x3ff
 #define THRESHOLD_MIN_ADC_CODE	0x0
+#define COLD_SENSOR_HW_ID	128
 
 #include <linux/interrupt.h>
 #include <linux/thermal.h>
@@ -34,6 +35,7 @@ enum tsens_irq_type {
 	LOWER,
 	UPPER,
 	CRITICAL,
+	COLD,
 };
 
 /**
@@ -64,6 +66,7 @@ struct tsens_sensor {
  * @suspend: Function to suspend the tsens device
  * @resume: Function to resume the tsens device
  * @get_trend: Function to get the thermal/temp trend
+ * @get_cold_status: Function to get the cold interrupt status
  */
 struct tsens_ops {
 	/* mandatory callbacks */
@@ -76,6 +79,7 @@ struct tsens_ops {
 	int (*suspend)(struct tsens_priv *priv);
 	int (*resume)(struct tsens_priv *priv);
 	int (*get_trend)(struct tsens_sensor *s, enum thermal_trend *trend);
+	int (*get_cold_status)(const struct tsens_sensor *s, bool *cold_status);
 };
 
 #define REG_FIELD_FOR_EACH_SENSOR11(_name, _offset, _startbit, _stopbit) \
@@ -485,6 +489,8 @@ enum regfield_ids {
 	MAX_STATUS_14,
 	MAX_STATUS_15,
 
+	COLD_STATUS,		/* COLD interrupt status */
+
 	/* Keep last */
 	MAX_REGFIELDS
 };
@@ -497,6 +503,7 @@ enum regfield_ids {
  * @srot_split: does the IP neatly splits the register space into SROT and TM,
  *              with SROT only being available to secure boot firmware?
  * @has_watchdog: does this IP support watchdog functionality?
+ * @cold_int: does this IP support COLD interrupt ?
  * @max_sensors: maximum sensors supported by this version of the IP
  */
 struct tsens_features {
@@ -505,6 +512,7 @@ struct tsens_features {
 	unsigned int adc:1;
 	unsigned int srot_split:1;
 	unsigned int has_watchdog:1;
+	unsigned int cold_int:1;
 	unsigned int max_sensors;
 };
 
@@ -551,6 +559,7 @@ struct tsens_context {
  * @ops: pointer to list of callbacks supported by this device
  * @debug_root: pointer to debugfs dentry for all tsens
  * @debug: pointer to debugfs dentry for tsens controller
+ * @cold_sensor: pointer to cold sensor attached to this device
  * @sensor: list of sensors attached to this device
  */
 struct tsens_priv {
@@ -571,6 +580,7 @@ struct tsens_priv {
 
 	struct dentry			*debug_root;
 	struct dentry			*debug;
+	struct tsens_sensor		*cold_sensor;
 
 	struct tsens_sensor		sensor[];
 };
@@ -580,6 +590,7 @@ 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);
+int get_cold_int_status(const struct tsens_sensor *s, bool *cold_status);
 
 /* TSENS target */
 extern struct tsens_plat_data data_8960;
Signature · 1 line
2.26.2
#2 lore raw

PATCH v3 2/2 dt-bindings: thermal: tsens: Add cold interrupt support in yaml

In reply to Manaf Meethalavalappu Pallikunhi

Add cold interrupt support for tsens in yaml.

---
 .../bindings/thermal/qcom-tsens.yaml          | 42 +++++++++++++++++++
 1 file changed, 42 insertions(+)
Documentation/devicetree/bindings/thermal/qcom-tsens.yaml +42 -0
index 2ddd39d96766..3592322fe172 100644
@@ -52,12 +52,14 @@ properties:
     items:
       - description: Combined interrupt if upper or lower threshold crossed
       - description: Interrupt if critical threshold crossed
+      - description: Interrupt if cold threshold is crossed
 
   interrupt-names:
     minItems: 1
     items:
       - const: uplow
       - const: critical
+      - const: cold
 
   nvmem-cells:
     minItems: 1
@@ -109,8 +111,10 @@ allOf:
       properties:
         interrupts:
           minItems: 2
+          maxItems: 3
         interrupt-names:
           minItems: 2
+          maxItems: 3
 
 required:
   - compatible
@@ -174,4 +178,42 @@ examples:
            #qcom,sensors = <13>;
            #thermal-sensor-cells = <1>;
     };
+
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    // Example 4 (for any platform containing v2.6+ of the TSENS IP)
+    //           (with thermal-zone):
+    tsens4: thermal-sensor@c265000 {
+           compatible = "qcom,sc7180-tsens", "qcom,tsens-v2";
+           reg = <0xc265000 0x1ff>,
+                 <0xc223000 0x1ff>;
+
+           interrupts = <GIC_SPI 507 IRQ_TYPE_LEVEL_HIGH>,
+                        <GIC_SPI 509 IRQ_TYPE_LEVEL_HIGH>,
+                        <GIC_SPI 501 IRQ_TYPE_EDGE_RISING>;
+           interrupt-names = "uplow", "critical", "cold";
+
+           #qcom,sensors = <15>;
+           #thermal-sensor-cells = <1>;
+    };
+
+    thermal-zones {
+            cold_thermal: cold-thermal {
+                    polling-delay-passive = <0>;
+                    polling-delay = <0>;
+
+                    thermal-sensors = <&tsens4 128>;
+
+                    trips {
+                            cold-trip {
+                                    temperature = <1>;
+                                    hysteresis = <1>;
+                                    type = "passive";
+                            };
+                    };
+
+                    cooling-maps {
+                    };
+            };
+    };
 ...
Signature · 1 line
2.26.2