linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/6] thermal: qcom: tsens: Fix MDM9607, add MSM8909
@ 2023-03-15 10:39 Stephan Gerhold
  2023-03-15 10:39 ` [PATCH v3 1/6] thermal: qcom: tsens: Drop unused legacy structs Stephan Gerhold
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-15 10:39 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, Konrad Dybcio,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold, Stephan Gerhold

Make the MDM9607 thermal sensor support consistent with Qualcomm's
vendor kernel (msm-3.18) by applying the correct default slope values
and adding "correction factors" to the factory calibration values in the
fuses. Use the same functionality to add the very similar MSM8909 SoC to
the tsens driver.

---
Changes in v3: Drop now unused definition reported by kernel test robot
Changes in v2:
  - Rewrite on top of per-sensor nvmem cell changes that landed in 6.3
  - Add patches to fix existing support for MDM9607

Stephan Gerhold (6):
  thermal: qcom: tsens: Drop unused legacy structs
  thermal: qcom: tsens-v0_1: Fix mdm9607 slope values
  thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets
  dt-bindings: thermal: qcom-tsens: Drop redundant compatibles
  dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible
  thermal: qcom: tsens-v0_1: Add MSM8909 data

 .../bindings/thermal/qcom-tsens.yaml          | 23 +----
 drivers/thermal/qcom/tsens-v0_1.c             | 95 +++++++++++--------
 drivers/thermal/qcom/tsens-v1.c               | 22 -----
 drivers/thermal/qcom/tsens.c                  | 19 +++-
 drivers/thermal/qcom/tsens.h                  |  6 +-
 5 files changed, 80 insertions(+), 85 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v3 1/6] thermal: qcom: tsens: Drop unused legacy structs
  2023-03-15 10:39 [PATCH v3 0/6] thermal: qcom: tsens: Fix MDM9607, add MSM8909 Stephan Gerhold
@ 2023-03-15 10:39 ` Stephan Gerhold
  2023-03-17  0:34   ` Konrad Dybcio
  2023-03-15 10:39 ` [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values Stephan Gerhold
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-15 10:39 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, Konrad Dybcio,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold, Stephan Gerhold

The old single-cell parsing code was removed for MSM8939, MDM9607 and
MSM8976 but for some reason the structs defining the bit positions etc
were kept around (unused). Drop them now.

Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Fixes: 51d78b8b1beb ("thermal/drivers/tsens: Drop single-cell code for mdm9607")
Fixes: dfadb4599ab0 ("thermal/drivers/tsens: Drop single-cell code for msm8939")
Fixes: 3a908971f7cb ("thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956")
Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
Changes in v3: None
Changes in v2: New patch
---
 drivers/thermal/qcom/tsens-v0_1.c | 36 -------------------------------
 drivers/thermal/qcom/tsens-v1.c   | 22 -------------------
 2 files changed, 58 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index e89c6f39a3ae..106d26076e3f 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -39,26 +39,6 @@ struct tsens_legacy_calibration_format tsens_8916_nvmem = {
 	},
 };
 
-struct tsens_legacy_calibration_format tsens_8939_nvmem = {
-	.base_len = 8,
-	.base_shift = 2,
-	.sp_len = 6,
-	.mode = { 12, 0 },
-	.invalid = { 12, 2 },
-	.base = { { 0, 0 }, { 1, 24 } },
-	.sp = {
-		{ { 12, 3 },  { 12, 9 } },
-		{ { 12, 15 }, { 12, 21 } },
-		{ { 12, 27 }, { 13, 1 } },
-		{ { 13, 7 },  { 13, 13 } },
-		{ { 13, 19 }, { 13, 25 } },
-		{ { 0, 8 },   { 0, 14 } },
-		{ { 0, 20 },  { 0, 26 } },
-		{ { 1, 0 },   { 1, 6 } },
-		{ { 1, 12 },  { 1, 18 } },
-	},
-};
-
 struct tsens_legacy_calibration_format tsens_8974_nvmem = {
 	.base_len = 8,
 	.base_shift = 2,
@@ -103,22 +83,6 @@ struct tsens_legacy_calibration_format tsens_8974_backup_nvmem = {
 	},
 };
 
-struct tsens_legacy_calibration_format tsens_9607_nvmem = {
-	.base_len = 8,
-	.base_shift = 2,
-	.sp_len = 6,
-	.mode = { 2, 20 },
-	.invalid = { 2, 22 },
-	.base = { { 0, 0 }, { 2, 12 } },
-	.sp = {
-		{ { 0, 8 },  { 0, 14 } },
-		{ { 0, 20 }, { 0, 26 } },
-		{ { 1, 0 },  { 1, 6 } },
-		{ { 1, 12 }, { 1, 18 } },
-		{ { 2, 0 },  { 2, 6 } },
-	},
-};
-
 static int calibrate_8916(struct tsens_priv *priv)
 {
 	u32 p1[5], p2[5];
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index b822a426066d..51322430f1fe 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -42,28 +42,6 @@ struct tsens_legacy_calibration_format tsens_qcs404_nvmem = {
 	},
 };
 
-struct tsens_legacy_calibration_format tsens_8976_nvmem = {
-	.base_len = 8,
-	.base_shift = 2,
-	.sp_len = 6,
-	.mode = { 4, 0 },
-	.invalid = { 4, 2 },
-	.base = { { 0, 0 }, { 2, 8 } },
-	.sp = {
-		{ { 0, 8 },  { 0, 14 } },
-		{ { 0, 20 }, { 0, 26 } },
-		{ { 1, 0 },  { 1, 6 } },
-		{ { 1, 12 }, { 1, 18 } },
-		{ { 2, 8 },  { 2, 14 } },
-		{ { 2, 20 }, { 2, 26 } },
-		{ { 3, 0 },  { 3, 6 } },
-		{ { 3, 12 }, { 3, 18 } },
-		{ { 4, 2 },  { 4, 9 } },
-		{ { 4, 14 }, { 4, 21 } },
-		{ { 4, 26 }, { 5, 1 } },
-	},
-};
-
 static int calibrate_v1(struct tsens_priv *priv)
 {
 	u32 p1[10], p2[10];
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values
  2023-03-15 10:39 [PATCH v3 0/6] thermal: qcom: tsens: Fix MDM9607, add MSM8909 Stephan Gerhold
  2023-03-15 10:39 ` [PATCH v3 1/6] thermal: qcom: tsens: Drop unused legacy structs Stephan Gerhold
@ 2023-03-15 10:39 ` Stephan Gerhold
  2023-03-17  0:39   ` Konrad Dybcio
  2023-03-15 10:39 ` [PATCH v3 3/6] thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets Stephan Gerhold
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-15 10:39 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, Konrad Dybcio,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold, Stephan Gerhold

According to the msm-3.18 vendor kernel from Qualcomm [1], mdm9607 uses
a non-standard slope value of 3000 (instead of 3200) for all sensors.
Fill it properly similar to the 8939 code added recently.

[1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi#L875

Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
Fixes: a2149ab815fc ("thermal/drivers/qcom/tsens-v0_1: Add support for MDM9607")
Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
Changes in v3: Drop now unused ops_v0_1 definition
Changes in v2: New patch
---
 drivers/thermal/qcom/tsens-v0_1.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 106d26076e3f..1b454de3928d 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -222,6 +222,16 @@ static int __init init_8939(struct tsens_priv *priv) {
 	return init_common(priv);
 }
 
+static int __init init_9607(struct tsens_priv *priv)
+{
+	int i;
+
+	for (i = 0; i < priv->num_sensors; ++i)
+		priv->sensor[i].slope = 3000;
+
+	return init_common(priv);
+}
+
 /* v0.1: 8916, 8939, 8974, 9607 */
 
 static struct tsens_features tsens_v0_1_feat = {
@@ -271,12 +281,6 @@ static const struct reg_field tsens_v0_1_regfields[MAX_REGFIELDS] = {
 	[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
 };
 
-static const struct tsens_ops ops_v0_1 = {
-	.init		= init_common,
-	.calibrate	= tsens_calibrate_common,
-	.get_temp	= get_temp_common,
-};
-
 static const struct tsens_ops ops_8916 = {
 	.init		= init_common,
 	.calibrate	= calibrate_8916,
@@ -320,9 +324,15 @@ struct tsens_plat_data data_8974 = {
 	.fields	= tsens_v0_1_regfields,
 };
 
+static const struct tsens_ops ops_9607 = {
+	.init		= init_9607,
+	.calibrate	= tsens_calibrate_common,
+	.get_temp	= get_temp_common,
+};
+
 struct tsens_plat_data data_9607 = {
 	.num_sensors	= 5,
-	.ops		= &ops_v0_1,
+	.ops		= &ops_9607,
 	.feat		= &tsens_v0_1_feat,
 	.fields	= tsens_v0_1_regfields,
 };
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 3/6] thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets
  2023-03-15 10:39 [PATCH v3 0/6] thermal: qcom: tsens: Fix MDM9607, add MSM8909 Stephan Gerhold
  2023-03-15 10:39 ` [PATCH v3 1/6] thermal: qcom: tsens: Drop unused legacy structs Stephan Gerhold
  2023-03-15 10:39 ` [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values Stephan Gerhold
@ 2023-03-15 10:39 ` Stephan Gerhold
  2023-03-18 14:02   ` Konrad Dybcio
  2023-03-15 10:39 ` [PATCH v3 4/6] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles Stephan Gerhold
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-15 10:39 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, Konrad Dybcio,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold, Stephan Gerhold

According to the msm-3.18 vendor kernel from Qualcomm, mdm9607 needs
"correction factors" to adjust for additional offsets observed after the
factory calibration values in the fuses [1, 2].

The fixed offsets should be applied unless there is a special
calibration mode value that indicates that no offsets are needed [3].

Note that the new calibration mode values are called differently in this
patch compared to the vendor kernel:
  - TSENS_TWO_POINT_CALIB_N_WA        -> ONE_PT_CALIB2_NO_OFFSET
  - TSENS_TWO_POINT_CALIB_N_OFFSET_WA -> TWO_PT_CALIB_NO_OFFSET
This is because close inspection of the calibration function [3] reveals
that TSENS_TWO_POINT_CALIB_N_WA is actually a "one point" calibration
because the if statements skip all "point2" related code for it.

[1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d9d2db1b82bf3f72f5de0803d55e6849eb5b671e
[2]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d75aef53a760e8ff7bac54049d00c8b2ee1b193e
[3]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/drivers/thermal/msm-tsens.c#L2987-3136

Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
Fixes: a2149ab815fc ("thermal/drivers/qcom/tsens-v0_1: Add support for MDM9607")
Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
Changes in v3: None
Changes in v2: New patch
---
 drivers/thermal/qcom/tsens-v0_1.c | 11 +++++++++++
 drivers/thermal/qcom/tsens.c      | 16 +++++++++++++++-
 drivers/thermal/qcom/tsens.h      |  4 ++++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 1b454de3928d..e69889dd524a 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -229,6 +229,17 @@ static int __init init_9607(struct tsens_priv *priv)
 	for (i = 0; i < priv->num_sensors; ++i)
 		priv->sensor[i].slope = 3000;
 
+	priv->sensor[0].p1_calib_offset = 1;
+	priv->sensor[0].p2_calib_offset = 1;
+	priv->sensor[1].p1_calib_offset = -4;
+	priv->sensor[1].p2_calib_offset = -2;
+	priv->sensor[2].p1_calib_offset = 4;
+	priv->sensor[2].p2_calib_offset = 8;
+	priv->sensor[3].p1_calib_offset = -3;
+	priv->sensor[3].p2_calib_offset = -5;
+	priv->sensor[4].p1_calib_offset = -4;
+	priv->sensor[4].p2_calib_offset = -4;
+
 	return init_common(priv);
 }
 
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 8020ead2794e..32d2907f76e5 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -134,10 +134,12 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
 			p1[i] = p1[i] + (base1 << shift);
 		break;
 	case TWO_PT_CALIB:
+	case TWO_PT_CALIB_NO_OFFSET:
 		for (i = 0; i < priv->num_sensors; i++)
 			p2[i] = (p2[i] + base2) << shift;
 		fallthrough;
 	case ONE_PT_CALIB2:
+	case ONE_PT_CALIB2_NO_OFFSET:
 		for (i = 0; i < priv->num_sensors; i++)
 			p1[i] = (p1[i] + base1) << shift;
 		break;
@@ -149,6 +151,18 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
 		}
 	}
 
+	/* Apply calibration offset workaround except for _NO_OFFSET modes */
+	switch (mode) {
+	case TWO_PT_CALIB:
+		for (i = 0; i < priv->num_sensors; i++)
+			p2[i] += priv->sensor[i].p2_calib_offset;
+		fallthrough;
+	case ONE_PT_CALIB2:
+		for (i = 0; i < priv->num_sensors; i++)
+			p1[i] += priv->sensor[i].p1_calib_offset;
+		break;
+	}
+
 	return mode;
 }
 
@@ -254,7 +268,7 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *p1,
 
 		if (!priv->sensor[i].slope)
 			priv->sensor[i].slope = SLOPE_DEFAULT;
-		if (mode == TWO_PT_CALIB) {
+		if (mode == TWO_PT_CALIB || mode == TWO_PT_CALIB_NO_OFFSET) {
 			/*
 			 * slope (m) = adc_code2 - adc_code1 (y2 - y1)/
 			 *	temp_120_degc - temp_30_degc (x2 - x1)
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index dba9cd38f637..880be6be5c3f 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -10,6 +10,8 @@
 #define ONE_PT_CALIB		0x1
 #define ONE_PT_CALIB2		0x2
 #define TWO_PT_CALIB		0x3
+#define ONE_PT_CALIB2_NO_OFFSET	0x6
+#define TWO_PT_CALIB_NO_OFFSET	0x7
 #define CAL_DEGC_PT1		30
 #define CAL_DEGC_PT2		120
 #define SLOPE_FACTOR		1000
@@ -57,6 +59,8 @@ struct tsens_sensor {
 	unsigned int			hw_id;
 	int				slope;
 	u32				status;
+	int				p1_calib_offset;
+	int				p2_calib_offset;
 };
 
 /**
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 4/6] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles
  2023-03-15 10:39 [PATCH v3 0/6] thermal: qcom: tsens: Fix MDM9607, add MSM8909 Stephan Gerhold
                   ` (2 preceding siblings ...)
  2023-03-15 10:39 ` [PATCH v3 3/6] thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets Stephan Gerhold
@ 2023-03-15 10:39 ` Stephan Gerhold
  2023-03-15 10:39 ` [PATCH v3 5/6] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible Stephan Gerhold
  2023-03-15 10:39 ` [PATCH v3 6/6] thermal: qcom: tsens-v0_1: Add MSM8909 data Stephan Gerhold
  5 siblings, 0 replies; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-15 10:39 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, Konrad Dybcio,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold, Stephan Gerhold, Krzysztof Kozlowski

Since the SoC compatibles must be followed by the IP version compatible
(e.g. compatible = "qcom,msm8916-tsens", "qcom,tsens-v0_1";) it is
redundant to list all the SoC compatibles again in the if statement.
It will already match the IP-version compatible.

The list has already become inconsistent since for example
"qcom,msm8939-tsens" is covered by the if statement but is not listed
there explicitly like the other SoCs.

Simplify this by dropping the redundant SoC compatibles. ipq8064 and
msm8960 are still needed because they do not have an IP-version
compatible.

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
Changes in v3: Add Krzysztof's Reviewed-by
Changes in v2:
  - Drop new redundant qcom,tsens-v2 compatibles as well (see discussion
    in https://lore.kernel.org/linux-arm-msm/Y3ZFDRI6ypg18S27@gerhold.net/)
---
 .../bindings/thermal/qcom-tsens.yaml          | 22 +------------------
 1 file changed, 1 insertion(+), 21 deletions(-)

diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
index 926e9c51c93c..49416e1ec295 100644
--- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
+++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
@@ -223,12 +223,7 @@ allOf:
           contains:
             enum:
               - qcom,ipq8064-tsens
-              - qcom,mdm9607-tsens
-              - qcom,msm8916-tsens
               - qcom,msm8960-tsens
-              - qcom,msm8974-tsens
-              - qcom,msm8976-tsens
-              - qcom,qcs404-tsens
               - qcom,tsens-v0_1
               - qcom,tsens-v1
     then:
@@ -244,22 +239,7 @@ allOf:
       properties:
         compatible:
           contains:
-            enum:
-              - qcom,msm8953-tsens
-              - qcom,msm8996-tsens
-              - qcom,msm8998-tsens
-              - qcom,sc7180-tsens
-              - qcom,sc7280-tsens
-              - qcom,sc8180x-tsens
-              - qcom,sc8280xp-tsens
-              - qcom,sdm630-tsens
-              - qcom,sdm845-tsens
-              - qcom,sm6350-tsens
-              - qcom,sm8150-tsens
-              - qcom,sm8250-tsens
-              - qcom,sm8350-tsens
-              - qcom,sm8450-tsens
-              - qcom,tsens-v2
+            const: qcom,tsens-v2
     then:
       properties:
         interrupts:
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 5/6] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible
  2023-03-15 10:39 [PATCH v3 0/6] thermal: qcom: tsens: Fix MDM9607, add MSM8909 Stephan Gerhold
                   ` (3 preceding siblings ...)
  2023-03-15 10:39 ` [PATCH v3 4/6] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles Stephan Gerhold
@ 2023-03-15 10:39 ` Stephan Gerhold
  2023-03-15 10:39 ` [PATCH v3 6/6] thermal: qcom: tsens-v0_1: Add MSM8909 data Stephan Gerhold
  5 siblings, 0 replies; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-15 10:39 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, Konrad Dybcio,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold, Stephan Gerhold, Krzysztof Kozlowski

MSM8909 uses the TSENS v0.1 block similar to other SoCs like MDM9607.
Document the "qcom,msm8909-tsens" compatible in the existing schema.

Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
Changes in v3: None
Changes in v2: None
---
 Documentation/devicetree/bindings/thermal/qcom-tsens.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
index 49416e1ec295..d6a9bb39c2a7 100644
--- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
+++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
@@ -29,6 +29,7 @@ properties:
         items:
           - enum:
               - qcom,mdm9607-tsens
+              - qcom,msm8909-tsens
               - qcom,msm8916-tsens
               - qcom,msm8939-tsens
               - qcom,msm8974-tsens
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v3 6/6] thermal: qcom: tsens-v0_1: Add MSM8909 data
  2023-03-15 10:39 [PATCH v3 0/6] thermal: qcom: tsens: Fix MDM9607, add MSM8909 Stephan Gerhold
                   ` (4 preceding siblings ...)
  2023-03-15 10:39 ` [PATCH v3 5/6] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible Stephan Gerhold
@ 2023-03-15 10:39 ` Stephan Gerhold
  2023-03-18 14:01   ` Konrad Dybcio
  5 siblings, 1 reply; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-15 10:39 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, Konrad Dybcio,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold, Stephan Gerhold

The MSM8909 SoC has 5 thermal sensors in a TSENS v0.1 block. Like
MDM9607 it uses a non-standard default slope value of 3000 [1] and needs
per-sensor "correction factors" to workaround issues with the factory
calibration [2].

[1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LA.UM.7.7.c26-09100-8x09.0/arch/arm/boot/dts/qcom/msm8909.dtsi#L476
[2]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/6df022c6d0c2c1b4a5a6c2124dba4d57910c0911

Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
Changes in v3: None
Changes in v2:
  - Rewrite on top of per-sensor nvmem cell changes that landed in 6.3
---
 drivers/thermal/qcom/tsens-v0_1.c | 32 ++++++++++++++++++++++++++++++-
 drivers/thermal/qcom/tsens.c      |  3 +++
 drivers/thermal/qcom/tsens.h      |  2 +-
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index e69889dd524a..2fda1ff4f6a6 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -207,6 +207,23 @@ static int calibrate_8974(struct tsens_priv *priv)
 	return 0;
 }
 
+static int __init init_8909(struct tsens_priv *priv)
+{
+	int i;
+
+	for (i = 0; i < priv->num_sensors; ++i)
+		priv->sensor[i].slope = 3000;
+
+	priv->sensor[1].p1_calib_offset = -10;
+	priv->sensor[1].p2_calib_offset = -6;
+	priv->sensor[3].p1_calib_offset = -9;
+	priv->sensor[3].p2_calib_offset = -9;
+	priv->sensor[4].p1_calib_offset = -8;
+	priv->sensor[4].p2_calib_offset = -10;
+
+	return init_common(priv);
+}
+
 static int __init init_8939(struct tsens_priv *priv) {
 	priv->sensor[0].slope = 2911;
 	priv->sensor[1].slope = 2789;
@@ -243,7 +260,7 @@ static int __init init_9607(struct tsens_priv *priv)
 	return init_common(priv);
 }
 
-/* v0.1: 8916, 8939, 8974, 9607 */
+/* v0.1: 8909, 8916, 8939, 8974, 9607 */
 
 static struct tsens_features tsens_v0_1_feat = {
 	.ver_major	= VER_0_1,
@@ -292,6 +309,19 @@ static const struct reg_field tsens_v0_1_regfields[MAX_REGFIELDS] = {
 	[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
 };
 
+static const struct tsens_ops ops_8909 = {
+	.init		= init_8909,
+	.calibrate	= tsens_calibrate_common,
+	.get_temp	= get_temp_common,
+};
+
+struct tsens_plat_data data_8909 = {
+	.num_sensors	= 5,
+	.ops		= &ops_8909,
+	.feat		= &tsens_v0_1_feat,
+	.fields	= tsens_v0_1_regfields,
+};
+
 static const struct tsens_ops ops_8916 = {
 	.init		= init_common,
 	.calibrate	= calibrate_8916,
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 32d2907f76e5..a04179247b34 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -1109,6 +1109,9 @@ static const struct of_device_id tsens_table[] = {
 	}, {
 		.compatible = "qcom,mdm9607-tsens",
 		.data = &data_9607,
+	}, {
+		.compatible = "qcom,msm8909-tsens",
+		.data = &data_8909,
 	}, {
 		.compatible = "qcom,msm8916-tsens",
 		.data = &data_8916,
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index 880be6be5c3f..c88287dede96 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -639,7 +639,7 @@ int get_temp_common(const struct tsens_sensor *s, int *temp);
 extern struct tsens_plat_data data_8960;
 
 /* TSENS v0.1 targets */
-extern struct tsens_plat_data data_8916, data_8939, data_8974, data_9607;
+extern struct tsens_plat_data data_8909, data_8916, data_8939, data_8974, data_9607;
 
 /* TSENS v1 targets */
 extern struct tsens_plat_data data_tsens_v1, data_8976, data_8956;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 1/6] thermal: qcom: tsens: Drop unused legacy structs
  2023-03-15 10:39 ` [PATCH v3 1/6] thermal: qcom: tsens: Drop unused legacy structs Stephan Gerhold
@ 2023-03-17  0:34   ` Konrad Dybcio
  0 siblings, 0 replies; 15+ messages in thread
From: Konrad Dybcio @ 2023-03-17  0:34 UTC (permalink / raw)
  To: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold



On 15.03.2023 11:39, Stephan Gerhold wrote:
> The old single-cell parsing code was removed for MSM8939, MDM9607 and
> MSM8976 but for some reason the structs defining the bit positions etc
> were kept around (unused). Drop them now.
> 
> Cc: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> Fixes: 51d78b8b1beb ("thermal/drivers/tsens: Drop single-cell code for mdm9607")
> Fixes: dfadb4599ab0 ("thermal/drivers/tsens: Drop single-cell code for msm8939")
> Fixes: 3a908971f7cb ("thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956")
> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> ---
> Changes in v3: None
> Changes in v2: New patch
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
>  drivers/thermal/qcom/tsens-v0_1.c | 36 -------------------------------
>  drivers/thermal/qcom/tsens-v1.c   | 22 -------------------
>  2 files changed, 58 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index e89c6f39a3ae..106d26076e3f 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -39,26 +39,6 @@ struct tsens_legacy_calibration_format tsens_8916_nvmem = {
>  	},
>  };
>  
> -struct tsens_legacy_calibration_format tsens_8939_nvmem = {
> -	.base_len = 8,
> -	.base_shift = 2,
> -	.sp_len = 6,
> -	.mode = { 12, 0 },
> -	.invalid = { 12, 2 },
> -	.base = { { 0, 0 }, { 1, 24 } },
> -	.sp = {
> -		{ { 12, 3 },  { 12, 9 } },
> -		{ { 12, 15 }, { 12, 21 } },
> -		{ { 12, 27 }, { 13, 1 } },
> -		{ { 13, 7 },  { 13, 13 } },
> -		{ { 13, 19 }, { 13, 25 } },
> -		{ { 0, 8 },   { 0, 14 } },
> -		{ { 0, 20 },  { 0, 26 } },
> -		{ { 1, 0 },   { 1, 6 } },
> -		{ { 1, 12 },  { 1, 18 } },
> -	},
> -};
> -
>  struct tsens_legacy_calibration_format tsens_8974_nvmem = {
>  	.base_len = 8,
>  	.base_shift = 2,
> @@ -103,22 +83,6 @@ struct tsens_legacy_calibration_format tsens_8974_backup_nvmem = {
>  	},
>  };
>  
> -struct tsens_legacy_calibration_format tsens_9607_nvmem = {
> -	.base_len = 8,
> -	.base_shift = 2,
> -	.sp_len = 6,
> -	.mode = { 2, 20 },
> -	.invalid = { 2, 22 },
> -	.base = { { 0, 0 }, { 2, 12 } },
> -	.sp = {
> -		{ { 0, 8 },  { 0, 14 } },
> -		{ { 0, 20 }, { 0, 26 } },
> -		{ { 1, 0 },  { 1, 6 } },
> -		{ { 1, 12 }, { 1, 18 } },
> -		{ { 2, 0 },  { 2, 6 } },
> -	},
> -};
> -
>  static int calibrate_8916(struct tsens_priv *priv)
>  {
>  	u32 p1[5], p2[5];
> diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
> index b822a426066d..51322430f1fe 100644
> --- a/drivers/thermal/qcom/tsens-v1.c
> +++ b/drivers/thermal/qcom/tsens-v1.c
> @@ -42,28 +42,6 @@ struct tsens_legacy_calibration_format tsens_qcs404_nvmem = {
>  	},
>  };
>  
> -struct tsens_legacy_calibration_format tsens_8976_nvmem = {
> -	.base_len = 8,
> -	.base_shift = 2,
> -	.sp_len = 6,
> -	.mode = { 4, 0 },
> -	.invalid = { 4, 2 },
> -	.base = { { 0, 0 }, { 2, 8 } },
> -	.sp = {
> -		{ { 0, 8 },  { 0, 14 } },
> -		{ { 0, 20 }, { 0, 26 } },
> -		{ { 1, 0 },  { 1, 6 } },
> -		{ { 1, 12 }, { 1, 18 } },
> -		{ { 2, 8 },  { 2, 14 } },
> -		{ { 2, 20 }, { 2, 26 } },
> -		{ { 3, 0 },  { 3, 6 } },
> -		{ { 3, 12 }, { 3, 18 } },
> -		{ { 4, 2 },  { 4, 9 } },
> -		{ { 4, 14 }, { 4, 21 } },
> -		{ { 4, 26 }, { 5, 1 } },
> -	},
> -};
> -
>  static int calibrate_v1(struct tsens_priv *priv)
>  {
>  	u32 p1[10], p2[10];

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values
  2023-03-15 10:39 ` [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values Stephan Gerhold
@ 2023-03-17  0:39   ` Konrad Dybcio
  2023-03-17 15:07     ` Stephan Gerhold
  0 siblings, 1 reply; 15+ messages in thread
From: Konrad Dybcio @ 2023-03-17  0:39 UTC (permalink / raw)
  To: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold



On 15.03.2023 11:39, Stephan Gerhold wrote:
> According to the msm-3.18 vendor kernel from Qualcomm [1], mdm9607 uses
> a non-standard slope value of 3000 (instead of 3200) for all sensors.
> Fill it properly similar to the 8939 code added recently.
> 
> [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi#L875
> 
FWIW there's a 4.9 release for 9607

https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.2.3.6.c5-03900-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi
> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> Fixes: a2149ab815fc ("thermal/drivers/qcom/tsens-v0_1: Add support for MDM9607")
> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
> Changes in v3: Drop now unused ops_v0_1 definition
> Changes in v2: New patch
> ---
>  drivers/thermal/qcom/tsens-v0_1.c | 24 +++++++++++++++++-------
>  1 file changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index 106d26076e3f..1b454de3928d 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -222,6 +222,16 @@ static int __init init_8939(struct tsens_priv *priv) {
>  	return init_common(priv);
>  }
>  
> +static int __init init_9607(struct tsens_priv *priv)
> +{
> +	int i;
> +
> +	for (i = 0; i < priv->num_sensors; ++i)
> +		priv->sensor[i].slope = 3000;
> +
> +	return init_common(priv);
> +}
> +
>  /* v0.1: 8916, 8939, 8974, 9607 */
>  
>  static struct tsens_features tsens_v0_1_feat = {
> @@ -271,12 +281,6 @@ static const struct reg_field tsens_v0_1_regfields[MAX_REGFIELDS] = {
>  	[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
>  };
>  
> -static const struct tsens_ops ops_v0_1 = {
> -	.init		= init_common,
> -	.calibrate	= tsens_calibrate_common,
> -	.get_temp	= get_temp_common,
> -};
> -
>  static const struct tsens_ops ops_8916 = {
>  	.init		= init_common,
>  	.calibrate	= calibrate_8916,
> @@ -320,9 +324,15 @@ struct tsens_plat_data data_8974 = {
>  	.fields	= tsens_v0_1_regfields,
>  };
>  
> +static const struct tsens_ops ops_9607 = {
> +	.init		= init_9607,
> +	.calibrate	= tsens_calibrate_common,
> +	.get_temp	= get_temp_common,
> +};
> +
>  struct tsens_plat_data data_9607 = {
>  	.num_sensors	= 5,
> -	.ops		= &ops_v0_1,
> +	.ops		= &ops_9607,
>  	.feat		= &tsens_v0_1_feat,
>  	.fields	= tsens_v0_1_regfields,
>  };

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values
  2023-03-17  0:39   ` Konrad Dybcio
@ 2023-03-17 15:07     ` Stephan Gerhold
  2023-03-17 17:37       ` Konrad Dybcio
  0 siblings, 1 reply; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-17 15:07 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki,
	Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree

On Fri, Mar 17, 2023 at 01:39:25AM +0100, Konrad Dybcio wrote:
> On 15.03.2023 11:39, Stephan Gerhold wrote:
> > According to the msm-3.18 vendor kernel from Qualcomm [1], mdm9607 uses
> > a non-standard slope value of 3000 (instead of 3200) for all sensors.
> > Fill it properly similar to the 8939 code added recently.
> > 
> > [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi#L875
> > 
> FWIW there's a 4.9 release for 9607
> 
> https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.2.3.6.c5-03900-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi

You seem to have linked 3.18 too?

I don't see tsens support for mdm9607 in msm-4.9, although maybe I'm
looking at the wrong branch. :D

Thanks,
Stephan

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values
  2023-03-17 15:07     ` Stephan Gerhold
@ 2023-03-17 17:37       ` Konrad Dybcio
  2023-03-18 16:00         ` Stephan Gerhold
  0 siblings, 1 reply; 15+ messages in thread
From: Konrad Dybcio @ 2023-03-17 17:37 UTC (permalink / raw)
  To: Stephan Gerhold
  Cc: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki,
	Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree



On 17.03.2023 16:07, Stephan Gerhold wrote:
> On Fri, Mar 17, 2023 at 01:39:25AM +0100, Konrad Dybcio wrote:
>> On 15.03.2023 11:39, Stephan Gerhold wrote:
>>> According to the msm-3.18 vendor kernel from Qualcomm [1], mdm9607 uses
>>> a non-standard slope value of 3000 (instead of 3200) for all sensors.
>>> Fill it properly similar to the 8939 code added recently.
>>>
>>> [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi#L875
>>>
>> FWIW there's a 4.9 release for 9607
>>
>> https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.2.3.6.c5-03900-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi
> 
> You seem to have linked 3.18 too?
> 
> I don't see tsens support for mdm9607 in msm-4.9, although maybe I'm
> looking at the wrong branch. :D
Yeah wrong link

and wrong kernel, it's actually 4.14

https://git.codelinaro.org/clo/la/kernel/msm-4.14/-/blob/637e99f66c270385149d1f0041758c24c4f84aaf/arch/arm64/boot/dts/qcom/mdm9607.dtsi

Konrad
> 
> Thanks,
> Stephan

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 6/6] thermal: qcom: tsens-v0_1: Add MSM8909 data
  2023-03-15 10:39 ` [PATCH v3 6/6] thermal: qcom: tsens-v0_1: Add MSM8909 data Stephan Gerhold
@ 2023-03-18 14:01   ` Konrad Dybcio
  0 siblings, 0 replies; 15+ messages in thread
From: Konrad Dybcio @ 2023-03-18 14:01 UTC (permalink / raw)
  To: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold



On 15.03.2023 11:39, Stephan Gerhold wrote:
> The MSM8909 SoC has 5 thermal sensors in a TSENS v0.1 block. Like
> MDM9607 it uses a non-standard default slope value of 3000 [1] and needs
> per-sensor "correction factors" to workaround issues with the factory
> calibration [2].
> 
> [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LA.UM.7.7.c26-09100-8x09.0/arch/arm/boot/dts/qcom/msm8909.dtsi#L476
> [2]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/6df022c6d0c2c1b4a5a6c2124dba4d57910c0911
> 
> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> ---
> Changes in v3: None
> Changes in v2:
>   - Rewrite on top of per-sensor nvmem cell changes that landed in 6.3
> ---
>  drivers/thermal/qcom/tsens-v0_1.c | 32 ++++++++++++++++++++++++++++++-
>  drivers/thermal/qcom/tsens.c      |  3 +++
>  drivers/thermal/qcom/tsens.h      |  2 +-
>  3 files changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index e69889dd524a..2fda1ff4f6a6 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -207,6 +207,23 @@ static int calibrate_8974(struct tsens_priv *priv)
>  	return 0;
>  }
>  
> +static int __init init_8909(struct tsens_priv *priv)
> +{
> +	int i;
> +
> +	for (i = 0; i < priv->num_sensors; ++i)
> +		priv->sensor[i].slope = 3000;
> +
I think assigning 0 here explicitly to priv->sensor[0].p12_calib_offset,
while unnecessary, would make it a bit more obvious.

Either way:

Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
> +	priv->sensor[1].p1_calib_offset = -10;
> +	priv->sensor[1].p2_calib_offset = -6;
> +	priv->sensor[3].p1_calib_offset = -9;
> +	priv->sensor[3].p2_calib_offset = -9;
> +	priv->sensor[4].p1_calib_offset = -8;
> +	priv->sensor[4].p2_calib_offset = -10;
> +
> +	return init_common(priv);
> +}
> +
>  static int __init init_8939(struct tsens_priv *priv) {
>  	priv->sensor[0].slope = 2911;
>  	priv->sensor[1].slope = 2789;
> @@ -243,7 +260,7 @@ static int __init init_9607(struct tsens_priv *priv)
>  	return init_common(priv);
>  }
>  
> -/* v0.1: 8916, 8939, 8974, 9607 */
> +/* v0.1: 8909, 8916, 8939, 8974, 9607 */
>  
>  static struct tsens_features tsens_v0_1_feat = {
>  	.ver_major	= VER_0_1,
> @@ -292,6 +309,19 @@ static const struct reg_field tsens_v0_1_regfields[MAX_REGFIELDS] = {
>  	[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
>  };
>  
> +static const struct tsens_ops ops_8909 = {
> +	.init		= init_8909,
> +	.calibrate	= tsens_calibrate_common,
> +	.get_temp	= get_temp_common,
> +};
> +
> +struct tsens_plat_data data_8909 = {
> +	.num_sensors	= 5,
> +	.ops		= &ops_8909,
> +	.feat		= &tsens_v0_1_feat,
> +	.fields	= tsens_v0_1_regfields,
> +};
> +
>  static const struct tsens_ops ops_8916 = {
>  	.init		= init_common,
>  	.calibrate	= calibrate_8916,
> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> index 32d2907f76e5..a04179247b34 100644
> --- a/drivers/thermal/qcom/tsens.c
> +++ b/drivers/thermal/qcom/tsens.c
> @@ -1109,6 +1109,9 @@ static const struct of_device_id tsens_table[] = {
>  	}, {
>  		.compatible = "qcom,mdm9607-tsens",
>  		.data = &data_9607,
> +	}, {
> +		.compatible = "qcom,msm8909-tsens",
> +		.data = &data_8909,
>  	}, {
>  		.compatible = "qcom,msm8916-tsens",
>  		.data = &data_8916,
> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
> index 880be6be5c3f..c88287dede96 100644
> --- a/drivers/thermal/qcom/tsens.h
> +++ b/drivers/thermal/qcom/tsens.h
> @@ -639,7 +639,7 @@ int get_temp_common(const struct tsens_sensor *s, int *temp);
>  extern struct tsens_plat_data data_8960;
>  
>  /* TSENS v0.1 targets */
> -extern struct tsens_plat_data data_8916, data_8939, data_8974, data_9607;
> +extern struct tsens_plat_data data_8909, data_8916, data_8939, data_8974, data_9607;
>  
>  /* TSENS v1 targets */
>  extern struct tsens_plat_data data_tsens_v1, data_8976, data_8956;

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 3/6] thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets
  2023-03-15 10:39 ` [PATCH v3 3/6] thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets Stephan Gerhold
@ 2023-03-18 14:02   ` Konrad Dybcio
  2023-03-18 16:06     ` Stephan Gerhold
  0 siblings, 1 reply; 15+ messages in thread
From: Konrad Dybcio @ 2023-03-18 14:02 UTC (permalink / raw)
  To: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree,
	Stephan Gerhold



On 15.03.2023 11:39, Stephan Gerhold wrote:
> According to the msm-3.18 vendor kernel from Qualcomm, mdm9607 needs
> "correction factors" to adjust for additional offsets observed after the
> factory calibration values in the fuses [1, 2].
> 
> The fixed offsets should be applied unless there is a special
> calibration mode value that indicates that no offsets are needed [3].
> 
> Note that the new calibration mode values are called differently in this
> patch compared to the vendor kernel:
>   - TSENS_TWO_POINT_CALIB_N_WA        -> ONE_PT_CALIB2_NO_OFFSET
>   - TSENS_TWO_POINT_CALIB_N_OFFSET_WA -> TWO_PT_CALIB_NO_OFFSET
> This is because close inspection of the calibration function [3] reveals
> that TSENS_TWO_POINT_CALIB_N_WA is actually a "one point" calibration
> because the if statements skip all "point2" related code for it.
> 
> [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d9d2db1b82bf3f72f5de0803d55e6849eb5b671e
> [2]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d75aef53a760e8ff7bac54049d00c8b2ee1b193e
> [3]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/drivers/thermal/msm-tsens.c#L2987-3136
> 
> Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> Fixes: a2149ab815fc ("thermal/drivers/qcom/tsens-v0_1: Add support for MDM9607")
> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

BTW, did you notice some crazy readouts or would this have gone
unnoticed had you not dug in the code?

Konrad
> Changes in v3: None
> Changes in v2: New patch
> ---
>  drivers/thermal/qcom/tsens-v0_1.c | 11 +++++++++++
>  drivers/thermal/qcom/tsens.c      | 16 +++++++++++++++-
>  drivers/thermal/qcom/tsens.h      |  4 ++++
>  3 files changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index 1b454de3928d..e69889dd524a 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -229,6 +229,17 @@ static int __init init_9607(struct tsens_priv *priv)
>  	for (i = 0; i < priv->num_sensors; ++i)
>  		priv->sensor[i].slope = 3000;
>  
> +	priv->sensor[0].p1_calib_offset = 1;
> +	priv->sensor[0].p2_calib_offset = 1;
> +	priv->sensor[1].p1_calib_offset = -4;
> +	priv->sensor[1].p2_calib_offset = -2;
> +	priv->sensor[2].p1_calib_offset = 4;
> +	priv->sensor[2].p2_calib_offset = 8;
> +	priv->sensor[3].p1_calib_offset = -3;
> +	priv->sensor[3].p2_calib_offset = -5;
> +	priv->sensor[4].p1_calib_offset = -4;
> +	priv->sensor[4].p2_calib_offset = -4;
> +
>  	return init_common(priv);
>  }
>  
> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> index 8020ead2794e..32d2907f76e5 100644
> --- a/drivers/thermal/qcom/tsens.c
> +++ b/drivers/thermal/qcom/tsens.c
> @@ -134,10 +134,12 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
>  			p1[i] = p1[i] + (base1 << shift);
>  		break;
>  	case TWO_PT_CALIB:
> +	case TWO_PT_CALIB_NO_OFFSET:
>  		for (i = 0; i < priv->num_sensors; i++)
>  			p2[i] = (p2[i] + base2) << shift;
>  		fallthrough;
>  	case ONE_PT_CALIB2:
> +	case ONE_PT_CALIB2_NO_OFFSET:
>  		for (i = 0; i < priv->num_sensors; i++)
>  			p1[i] = (p1[i] + base1) << shift;
>  		break;
> @@ -149,6 +151,18 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
>  		}
>  	}
>  
> +	/* Apply calibration offset workaround except for _NO_OFFSET modes */
> +	switch (mode) {
> +	case TWO_PT_CALIB:
> +		for (i = 0; i < priv->num_sensors; i++)
> +			p2[i] += priv->sensor[i].p2_calib_offset;
> +		fallthrough;
> +	case ONE_PT_CALIB2:
> +		for (i = 0; i < priv->num_sensors; i++)
> +			p1[i] += priv->sensor[i].p1_calib_offset;
> +		break;
> +	}
> +
>  	return mode;
>  }
>  
> @@ -254,7 +268,7 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *p1,
>  
>  		if (!priv->sensor[i].slope)
>  			priv->sensor[i].slope = SLOPE_DEFAULT;
> -		if (mode == TWO_PT_CALIB) {
> +		if (mode == TWO_PT_CALIB || mode == TWO_PT_CALIB_NO_OFFSET) {
>  			/*
>  			 * slope (m) = adc_code2 - adc_code1 (y2 - y1)/
>  			 *	temp_120_degc - temp_30_degc (x2 - x1)
> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
> index dba9cd38f637..880be6be5c3f 100644
> --- a/drivers/thermal/qcom/tsens.h
> +++ b/drivers/thermal/qcom/tsens.h
> @@ -10,6 +10,8 @@
>  #define ONE_PT_CALIB		0x1
>  #define ONE_PT_CALIB2		0x2
>  #define TWO_PT_CALIB		0x3
> +#define ONE_PT_CALIB2_NO_OFFSET	0x6
> +#define TWO_PT_CALIB_NO_OFFSET	0x7
>  #define CAL_DEGC_PT1		30
>  #define CAL_DEGC_PT2		120
>  #define SLOPE_FACTOR		1000
> @@ -57,6 +59,8 @@ struct tsens_sensor {
>  	unsigned int			hw_id;
>  	int				slope;
>  	u32				status;
> +	int				p1_calib_offset;
> +	int				p2_calib_offset;
>  };
>  
>  /**

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values
  2023-03-17 17:37       ` Konrad Dybcio
@ 2023-03-18 16:00         ` Stephan Gerhold
  0 siblings, 0 replies; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-18 16:00 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki,
	Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree

On Fri, Mar 17, 2023 at 06:37:16PM +0100, Konrad Dybcio wrote:
> On 17.03.2023 16:07, Stephan Gerhold wrote:
> > On Fri, Mar 17, 2023 at 01:39:25AM +0100, Konrad Dybcio wrote:
> >> On 15.03.2023 11:39, Stephan Gerhold wrote:
> >>> According to the msm-3.18 vendor kernel from Qualcomm [1], mdm9607 uses
> >>> a non-standard slope value of 3000 (instead of 3200) for all sensors.
> >>> Fill it properly similar to the 8939 code added recently.
> >>>
> >>> [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi#L875
> >>>
> >> FWIW there's a 4.9 release for 9607
> >>
> >> https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.2.3.6.c5-03900-9x07/arch/arm/boot/dts/qcom/mdm9607.dtsi
> > 
> > You seem to have linked 3.18 too?
> > 
> > I don't see tsens support for mdm9607 in msm-4.9, although maybe I'm
> > looking at the wrong branch. :D
> Yeah wrong link
> 
> and wrong kernel, it's actually 4.14
> 
> https://git.codelinaro.org/clo/la/kernel/msm-4.14/-/blob/637e99f66c270385149d1f0041758c24c4f84aaf/arch/arm64/boot/dts/qcom/mdm9607.dtsi
> 

Nice, I didn't know there is mdm9607 in msm-4.14. :)

Nevertheless I think msm-3.18 is a better reference for the tsens code.
In 4.9+ Qualcomm originally removed support for tsens v0.1. When porting
the older targets it seems to have been hacked back in with very little
thought. Note how it's called tsens 14xx there instead of v0.1, just
with different register offsets. Personally I wouldn't trust what they
did there, especially because most mdm9607 devices in the wild use 3.18.

Thanks,
Stephan

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v3 3/6] thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets
  2023-03-18 14:02   ` Konrad Dybcio
@ 2023-03-18 16:06     ` Stephan Gerhold
  0 siblings, 0 replies; 15+ messages in thread
From: Stephan Gerhold @ 2023-03-18 16:06 UTC (permalink / raw)
  To: Konrad Dybcio
  Cc: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki,
	Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	Dmitry Baryshkov, linux-arm-msm, linux-pm, devicetree

On Sat, Mar 18, 2023 at 03:02:35PM +0100, Konrad Dybcio wrote:
> On 15.03.2023 11:39, Stephan Gerhold wrote:
> > According to the msm-3.18 vendor kernel from Qualcomm, mdm9607 needs
> > "correction factors" to adjust for additional offsets observed after the
> > factory calibration values in the fuses [1, 2].
> > 
> > The fixed offsets should be applied unless there is a special
> > calibration mode value that indicates that no offsets are needed [3].
> > 
> > Note that the new calibration mode values are called differently in this
> > patch compared to the vendor kernel:
> >   - TSENS_TWO_POINT_CALIB_N_WA        -> ONE_PT_CALIB2_NO_OFFSET
> >   - TSENS_TWO_POINT_CALIB_N_OFFSET_WA -> TWO_PT_CALIB_NO_OFFSET
> > This is because close inspection of the calibration function [3] reveals
> > that TSENS_TWO_POINT_CALIB_N_WA is actually a "one point" calibration
> > because the if statements skip all "point2" related code for it.
> > 
> > [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d9d2db1b82bf3f72f5de0803d55e6849eb5b671e
> > [2]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d75aef53a760e8ff7bac54049d00c8b2ee1b193e
> > [3]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/drivers/thermal/msm-tsens.c#L2987-3136
> > 
> > Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
> > Fixes: a2149ab815fc ("thermal/drivers/qcom/tsens-v0_1: Add support for MDM9607")
> > Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> > ---
> Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
> 
> BTW, did you notice some crazy readouts or would this have gone
> unnoticed had you not dug in the code?
> 

I'm afraid it would likely have remained unnoticed. I think these
offsets only make a small difference but it's still good to have them
for slightly more accurate readings.

In v1 of this series I had the offsets for MSM8909 already (hardcoded
into the old calibration function with all the bit shifts/masks etc).
It was more coincidence that I checked MDM9607 for v2 because I had to
make the code more generic with the new per-sensor nvmem cells. ;)

Thanks,
Stephan

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-03-18 16:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-15 10:39 [PATCH v3 0/6] thermal: qcom: tsens: Fix MDM9607, add MSM8909 Stephan Gerhold
2023-03-15 10:39 ` [PATCH v3 1/6] thermal: qcom: tsens: Drop unused legacy structs Stephan Gerhold
2023-03-17  0:34   ` Konrad Dybcio
2023-03-15 10:39 ` [PATCH v3 2/6] thermal: qcom: tsens-v0_1: Fix mdm9607 slope values Stephan Gerhold
2023-03-17  0:39   ` Konrad Dybcio
2023-03-17 15:07     ` Stephan Gerhold
2023-03-17 17:37       ` Konrad Dybcio
2023-03-18 16:00         ` Stephan Gerhold
2023-03-15 10:39 ` [PATCH v3 3/6] thermal: qcom: tsens-v0_1: Add mdm9607 correction offsets Stephan Gerhold
2023-03-18 14:02   ` Konrad Dybcio
2023-03-18 16:06     ` Stephan Gerhold
2023-03-15 10:39 ` [PATCH v3 4/6] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles Stephan Gerhold
2023-03-15 10:39 ` [PATCH v3 5/6] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible Stephan Gerhold
2023-03-15 10:39 ` [PATCH v3 6/6] thermal: qcom: tsens-v0_1: Add MSM8909 data Stephan Gerhold
2023-03-18 14:01   ` Konrad Dybcio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).