All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] thermal: qcom: tsens: Add data for MSM8909
@ 2022-06-27 13:14 Stephan Gerhold
  2022-06-27 13:14 ` [PATCH 1/3] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles Stephan Gerhold
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Stephan Gerhold @ 2022-06-27 13:14 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, linux-arm-msm,
	linux-pm, devicetree, Stephan Gerhold, Stephan Gerhold

The MSM8909 SoC has 5 thermal sensors in a TSENS v0.1 block similar to
MSM8916. Add the data for MSM8909 to the existing tsens-v0_1.c driver
to make the thermal sensors work on MSM8909.

Stephan Gerhold (3):
  dt-bindings: thermal: qcom-tsens: Drop redundant compatibles
  dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible
  thermal: qcom: tsens: Add data for MSM8909

 .../bindings/thermal/qcom-tsens.yaml          |   6 +-
 drivers/thermal/qcom/tsens-v0_1.c             | 119 +++++++++++++++++-
 drivers/thermal/qcom/tsens.c                  |   3 +
 drivers/thermal/qcom/tsens.h                  |   2 +-
 4 files changed, 123 insertions(+), 7 deletions(-)

-- 
2.30.2


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

* [PATCH 1/3] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles
  2022-06-27 13:14 [PATCH 0/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
@ 2022-06-27 13:14 ` Stephan Gerhold
  2022-06-29 10:46   ` Krzysztof Kozlowski
  2022-06-27 13:14 ` [PATCH 2/3] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible Stephan Gerhold
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Stephan Gerhold @ 2022-06-27 13:14 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, linux-arm-msm,
	linux-pm, devicetree, Stephan Gerhold, Stephan Gerhold

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.

Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
 Documentation/devicetree/bindings/thermal/qcom-tsens.yaml | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
index 038d81338fcf..e93e9deec6f6 100644
--- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
+++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
@@ -117,12 +117,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:
-- 
2.30.2


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

* [PATCH 2/3] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible
  2022-06-27 13:14 [PATCH 0/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
  2022-06-27 13:14 ` [PATCH 1/3] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles Stephan Gerhold
@ 2022-06-27 13:14 ` Stephan Gerhold
  2022-06-29 10:46   ` Krzysztof Kozlowski
  2022-06-27 13:14 ` [PATCH 3/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
  2022-09-08 20:08 ` [PATCH 0/3] " Stephan Gerhold
  3 siblings, 1 reply; 10+ messages in thread
From: Stephan Gerhold @ 2022-06-27 13:14 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, linux-arm-msm,
	linux-pm, devicetree, Stephan Gerhold, Stephan Gerhold

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

Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
 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 e93e9deec6f6..5cd5501e578c 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] 10+ messages in thread

* [PATCH 3/3] thermal: qcom: tsens: Add data for MSM8909
  2022-06-27 13:14 [PATCH 0/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
  2022-06-27 13:14 ` [PATCH 1/3] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles Stephan Gerhold
  2022-06-27 13:14 ` [PATCH 2/3] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible Stephan Gerhold
@ 2022-06-27 13:14 ` Stephan Gerhold
  2022-09-08 20:57   ` Dmitry Baryshkov
  2022-09-08 20:08 ` [PATCH 0/3] " Stephan Gerhold
  3 siblings, 1 reply; 10+ messages in thread
From: Stephan Gerhold @ 2022-06-27 13:14 UTC (permalink / raw)
  To: Daniel Lezcano, Rafael J. Wysocki
  Cc: Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, linux-arm-msm,
	linux-pm, devicetree, Stephan Gerhold, Stephan Gerhold

The MSM8909 SoC has 5 thermal sensors in a TSENS v0.1 block similar to
MSM8916, except that the bit offsets in the qfprom were changed.
Also, some fixed correction factors are needed as workaround because the
factory calibration apparently was not reliable enough.

Add the defines and calibration function for MSM8909 in the existing
tsens-v0_1.c driver to make the thermal sensors work on MSM8909.
The changes are derived from the original msm-3.18 kernel [1] from
Qualcomm but cleaned up and adapted to the driver in mainline.

[1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LA.UM.7.7.c26-08600-8x09.0/drivers/thermal/msm-tsens.c

Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
---
 drivers/thermal/qcom/tsens-v0_1.c | 119 +++++++++++++++++++++++++++++-
 drivers/thermal/qcom/tsens.c      |   3 +
 drivers/thermal/qcom/tsens.h      |   2 +-
 3 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index f136cb350238..e17c4f9d9aa5 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -15,6 +15,48 @@
 #define TM_Sn_STATUS_OFF			0x0030
 #define TM_TRDY_OFF				0x005c
 
+/* eeprom layout data for 8909 */
+#define MSM8909_CAL_SEL_MASK	0x00070000
+#define MSM8909_CAL_SEL_SHIFT	16
+
+#define MSM8909_BASE0_MASK	0x000000ff
+#define MSM8909_BASE1_MASK	0x0000ff00
+#define MSM8909_BASE0_SHIFT	0
+#define MSM8909_BASE1_SHIFT	8
+
+#define MSM8909_S0_P1_MASK	0x0000003f
+#define MSM8909_S1_P1_MASK	0x0003f000
+#define MSM8909_S2_P1_MASK	0x3f000000
+#define MSM8909_S3_P1_MASK	0x000003f0
+#define MSM8909_S4_P1_MASK	0x003f0000
+
+#define MSM8909_S0_P2_MASK	0x00000fc0
+#define MSM8909_S1_P2_MASK	0x00fc0000
+#define MSM8909_S2_P2_MASK_0_1	0xc0000000
+#define MSM8909_S2_P2_MASK_2_5	0x0000000f
+#define MSM8909_S3_P2_MASK	0x0000fc00
+#define MSM8909_S4_P2_MASK	0x0fc00000
+
+#define MSM8909_S0_P1_SHIFT	0
+#define MSM8909_S1_P1_SHIFT	12
+#define MSM8909_S2_P1_SHIFT	24
+#define MSM8909_S3_P1_SHIFT	4
+#define MSM8909_S4_P1_SHIFT	16
+
+#define MSM8909_S0_P2_SHIFT	6
+#define MSM8909_S1_P2_SHIFT	18
+#define MSM8909_S2_P2_SHIFT_0_1	30
+#define MSM8909_S2_P2_SHIFT_2_5	2
+#define MSM8909_S3_P2_SHIFT	10
+#define MSM8909_S4_P2_SHIFT	22
+
+#define MSM8909_D30_WA_S1	10
+#define MSM8909_D30_WA_S3	9
+#define MSM8909_D30_WA_S4	8
+#define MSM8909_D120_WA_S1	6
+#define MSM8909_D120_WA_S3	9
+#define MSM8909_D120_WA_S4	10
+
 /* eeprom layout data for 8916 */
 #define MSM8916_BASE0_MASK	0x0000007f
 #define MSM8916_BASE1_MASK	0xfe000000
@@ -223,6 +265,68 @@
 #define MDM9607_CAL_SEL_MASK	0x00700000
 #define MDM9607_CAL_SEL_SHIFT	20
 
+static int calibrate_8909(struct tsens_priv *priv)
+{
+	u32 *qfprom_cdata, *qfprom_csel;
+	int base0, base1, mode, i;
+	u32 p1[5], p2[5];
+
+	qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
+	if (IS_ERR(qfprom_cdata))
+		return PTR_ERR(qfprom_cdata);
+
+	qfprom_csel = (u32 *)qfprom_read(priv->dev, "calib_sel");
+	if (IS_ERR(qfprom_csel)) {
+		kfree(qfprom_cdata);
+		return PTR_ERR(qfprom_csel);
+	}
+
+	mode = (qfprom_csel[0] & MSM8909_CAL_SEL_MASK) >> MSM8909_CAL_SEL_SHIFT;
+	dev_dbg(priv->dev, "calibration mode is %d\n", mode);
+
+	switch (mode) {
+	case TWO_PT_CALIB:
+		base1 = (qfprom_csel[0] & MSM8909_BASE1_MASK) >> MSM8909_BASE1_SHIFT;
+		p2[0] = (qfprom_cdata[0] & MSM8909_S0_P2_MASK) >> MSM8909_S0_P2_SHIFT;
+		p2[1] = (qfprom_cdata[0] & MSM8909_S1_P2_MASK) >> MSM8909_S1_P2_SHIFT;
+		p2[2] = (qfprom_cdata[0] & MSM8909_S2_P2_MASK_0_1) >> MSM8909_S2_P2_SHIFT_0_1;
+		p2[2] |= (qfprom_cdata[1] & MSM8909_S2_P2_MASK_2_5) << MSM8909_S2_P2_SHIFT_2_5;
+		p2[3] = (qfprom_cdata[1] & MSM8909_S3_P2_MASK) >> MSM8909_S3_P2_SHIFT;
+		p2[4] = (qfprom_cdata[1] & MSM8909_S4_P2_MASK) >> MSM8909_S4_P2_SHIFT;
+		for (i = 0; i < priv->num_sensors; i++)
+			p2[i] = ((base1 + p2[i]) << 2);
+		p2[1] -= MSM8909_D120_WA_S1;
+		p2[3] -= MSM8909_D120_WA_S3;
+		p2[4] -= MSM8909_D120_WA_S4;
+		fallthrough;
+	case ONE_PT_CALIB2:
+		base0 = (qfprom_csel[0] & MSM8909_BASE0_MASK) >> MSM8909_BASE0_SHIFT;
+		p1[0] = (qfprom_cdata[0] & MSM8909_S0_P1_MASK) >> MSM8909_S0_P1_SHIFT;
+		p1[1] = (qfprom_cdata[0] & MSM8909_S1_P1_MASK) >> MSM8909_S1_P1_SHIFT;
+		p1[2] = (qfprom_cdata[0] & MSM8909_S2_P1_MASK) >> MSM8909_S2_P1_SHIFT;
+		p1[3] = (qfprom_cdata[1] & MSM8909_S3_P1_MASK) >> MSM8909_S3_P1_SHIFT;
+		p1[4] = (qfprom_cdata[1] & MSM8909_S4_P1_MASK) >> MSM8909_S4_P1_SHIFT;
+		for (i = 0; i < priv->num_sensors; i++)
+			p1[i] = (((base0) + p1[i]) << 2);
+		p1[1] -= MSM8909_D30_WA_S1;
+		p1[3] -= MSM8909_D30_WA_S3;
+		p1[4] -= MSM8909_D30_WA_S4;
+		break;
+	default:
+		for (i = 0; i < priv->num_sensors; i++) {
+			p1[i] = 500;
+			p2[i] = 780;
+		}
+		break;
+	}
+
+	compute_intercept_slope(priv, p1, p2, mode);
+	kfree(qfprom_cdata);
+	kfree(qfprom_csel);
+
+	return 0;
+}
+
 static int calibrate_8916(struct tsens_priv *priv)
 {
 	int base0 = 0, base1 = 0, i;
@@ -534,7 +638,7 @@ static int calibrate_9607(struct tsens_priv *priv)
 	return 0;
 }
 
-/* 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,
@@ -580,6 +684,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_common,
+	.calibrate	= calibrate_8909,
+	.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 7963ee33bf75..cb7bbaa72d89 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -973,6 +973,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 1471a2c00f15..752d4718f26e 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -587,7 +587,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;
-- 
2.30.2


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

* Re: [PATCH 1/3] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles
  2022-06-27 13:14 ` [PATCH 1/3] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles Stephan Gerhold
@ 2022-06-29 10:46   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-29 10:46 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, linux-arm-msm,
	linux-pm, devicetree, Stephan Gerhold

On 27/06/2022 15:14, Stephan Gerhold wrote:
> 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.
> 
> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>


Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


Best regards,
Krzysztof

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

* Re: [PATCH 2/3] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible
  2022-06-27 13:14 ` [PATCH 2/3] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible Stephan Gerhold
@ 2022-06-29 10:46   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 10+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-29 10:46 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, linux-arm-msm,
	linux-pm, devicetree, Stephan Gerhold

On 27/06/2022 15:14, Stephan Gerhold wrote:
> MSM8909 uses the TSENS v0.1 block similar to other SoCs like MSM8916.
> Document the "qcom,msm8909-tsens" compatible in the existing schema.
> 
> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> ---


Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


Best regards,
Krzysztof

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

* Re: [PATCH 0/3] thermal: qcom: tsens: Add data for MSM8909
  2022-06-27 13:14 [PATCH 0/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
                   ` (2 preceding siblings ...)
  2022-06-27 13:14 ` [PATCH 3/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
@ 2022-09-08 20:08 ` Stephan Gerhold
  3 siblings, 0 replies; 10+ messages in thread
From: Stephan Gerhold @ 2022-09-08 20:08 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Rafael J. Wysocki, Amit Kucheria, Thara Gopinath, Zhang Rui,
	Rob Herring, Krzysztof Kozlowski, Bjorn Andersson, Andy Gross,
	linux-arm-msm, linux-pm, devicetree, Stephan Gerhold

Hi Daniel,

On Mon, Jun 27, 2022 at 03:14:12PM +0200, Stephan Gerhold wrote:
> The MSM8909 SoC has 5 thermal sensors in a TSENS v0.1 block similar to
> MSM8916. Add the data for MSM8909 to the existing tsens-v0_1.c driver
> to make the thermal sensors work on MSM8909.

Can you take a look at this series when you get a chance? It should be
mostly straightforward since it's just another platform with code
similar to the existing ones.

The series still applies cleanly on latest thermal/linux-next. But
just let me know if I should resend it anyway. :)

Thanks!
Stephan

> 
> Stephan Gerhold (3):
>   dt-bindings: thermal: qcom-tsens: Drop redundant compatibles
>   dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible
>   thermal: qcom: tsens: Add data for MSM8909
> 
>  .../bindings/thermal/qcom-tsens.yaml          |   6 +-
>  drivers/thermal/qcom/tsens-v0_1.c             | 119 +++++++++++++++++-
>  drivers/thermal/qcom/tsens.c                  |   3 +
>  drivers/thermal/qcom/tsens.h                  |   2 +-
>  4 files changed, 123 insertions(+), 7 deletions(-)
> 
> -- 
> 2.30.2
> 

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

* Re: [PATCH 3/3] thermal: qcom: tsens: Add data for MSM8909
  2022-06-27 13:14 ` [PATCH 3/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
@ 2022-09-08 20:57   ` Dmitry Baryshkov
  2022-09-09 13:51     ` Stephan Gerhold
  0 siblings, 1 reply; 10+ messages in thread
From: Dmitry Baryshkov @ 2022-09-08 20:57 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, linux-arm-msm,
	linux-pm, devicetree, Stephan Gerhold

On 27/06/2022 16:14, Stephan Gerhold wrote:
> The MSM8909 SoC has 5 thermal sensors in a TSENS v0.1 block similar to
> MSM8916, except that the bit offsets in the qfprom were changed.
> Also, some fixed correction factors are needed as workaround because the
> factory calibration apparently was not reliable enough.
> 
> Add the defines and calibration function for MSM8909 in the existing
> tsens-v0_1.c driver to make the thermal sensors work on MSM8909.
> The changes are derived from the original msm-3.18 kernel [1] from
> Qualcomm but cleaned up and adapted to the driver in mainline.
> 
> [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LA.UM.7.7.c26-08600-8x09.0/drivers/thermal/msm-tsens.c
> 
> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> ---
>   drivers/thermal/qcom/tsens-v0_1.c | 119 +++++++++++++++++++++++++++++-
>   drivers/thermal/qcom/tsens.c      |   3 +
>   drivers/thermal/qcom/tsens.h      |   2 +-
>   3 files changed, 122 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index f136cb350238..e17c4f9d9aa5 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -15,6 +15,48 @@
>   #define TM_Sn_STATUS_OFF			0x0030
>   #define TM_TRDY_OFF				0x005c
>   
> +/* eeprom layout data for 8909 */
> +#define MSM8909_CAL_SEL_MASK	0x00070000
> +#define MSM8909_CAL_SEL_SHIFT	16
> +
> +#define MSM8909_BASE0_MASK	0x000000ff
> +#define MSM8909_BASE1_MASK	0x0000ff00
> +#define MSM8909_BASE0_SHIFT	0
> +#define MSM8909_BASE1_SHIFT	8
> +
> +#define MSM8909_S0_P1_MASK	0x0000003f
> +#define MSM8909_S1_P1_MASK	0x0003f000
> +#define MSM8909_S2_P1_MASK	0x3f000000
> +#define MSM8909_S3_P1_MASK	0x000003f0
> +#define MSM8909_S4_P1_MASK	0x003f0000
> +
> +#define MSM8909_S0_P2_MASK	0x00000fc0
> +#define MSM8909_S1_P2_MASK	0x00fc0000
> +#define MSM8909_S2_P2_MASK_0_1	0xc0000000
> +#define MSM8909_S2_P2_MASK_2_5	0x0000000f
> +#define MSM8909_S3_P2_MASK	0x0000fc00
> +#define MSM8909_S4_P2_MASK	0x0fc00000
> +
> +#define MSM8909_S0_P1_SHIFT	0
> +#define MSM8909_S1_P1_SHIFT	12
> +#define MSM8909_S2_P1_SHIFT	24
> +#define MSM8909_S3_P1_SHIFT	4
> +#define MSM8909_S4_P1_SHIFT	16
> +
> +#define MSM8909_S0_P2_SHIFT	6
> +#define MSM8909_S1_P2_SHIFT	18
> +#define MSM8909_S2_P2_SHIFT_0_1	30
> +#define MSM8909_S2_P2_SHIFT_2_5	2
> +#define MSM8909_S3_P2_SHIFT	10
> +#define MSM8909_S4_P2_SHIFT	22
> +
> +#define MSM8909_D30_WA_S1	10
> +#define MSM8909_D30_WA_S3	9
> +#define MSM8909_D30_WA_S4	8
> +#define MSM8909_D120_WA_S1	6
> +#define MSM8909_D120_WA_S3	9
> +#define MSM8909_D120_WA_S4	10
> +
>   /* eeprom layout data for 8916 */
>   #define MSM8916_BASE0_MASK	0x0000007f
>   #define MSM8916_BASE1_MASK	0xfe000000
> @@ -223,6 +265,68 @@
>   #define MDM9607_CAL_SEL_MASK	0x00700000
>   #define MDM9607_CAL_SEL_SHIFT	20
>   
> +static int calibrate_8909(struct tsens_priv *priv)
> +{
> +	u32 *qfprom_cdata, *qfprom_csel;
> +	int base0, base1, mode, i;
> +	u32 p1[5], p2[5];
> +
> +	qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> +	if (IS_ERR(qfprom_cdata))
> +		return PTR_ERR(qfprom_cdata);
> +
> +	qfprom_csel = (u32 *)qfprom_read(priv->dev, "calib_sel");
> +	if (IS_ERR(qfprom_csel)) {
> +		kfree(qfprom_cdata);
> +		return PTR_ERR(qfprom_csel);
> +	}
> +
> +	mode = (qfprom_csel[0] & MSM8909_CAL_SEL_MASK) >> MSM8909_CAL_SEL_SHIFT;
> +	dev_dbg(priv->dev, "calibration mode is %d\n", mode);
> +
> +	switch (mode) {
> +	case TWO_PT_CALIB:
> +		base1 = (qfprom_csel[0] & MSM8909_BASE1_MASK) >> MSM8909_BASE1_SHIFT;
> +		p2[0] = (qfprom_cdata[0] & MSM8909_S0_P2_MASK) >> MSM8909_S0_P2_SHIFT;
> +		p2[1] = (qfprom_cdata[0] & MSM8909_S1_P2_MASK) >> MSM8909_S1_P2_SHIFT;
> +		p2[2] = (qfprom_cdata[0] & MSM8909_S2_P2_MASK_0_1) >> MSM8909_S2_P2_SHIFT_0_1;
> +		p2[2] |= (qfprom_cdata[1] & MSM8909_S2_P2_MASK_2_5) << MSM8909_S2_P2_SHIFT_2_5;
> +		p2[3] = (qfprom_cdata[1] & MSM8909_S3_P2_MASK) >> MSM8909_S3_P2_SHIFT;
> +		p2[4] = (qfprom_cdata[1] & MSM8909_S4_P2_MASK) >> MSM8909_S4_P2_SHIFT;

Please use nvmem_cell_read_* to read these values. This would allow you 
to push all the possible si_pi definitions into the DT and use mode to 
switch between them. And mode can be read using the nvmem_cell_read_* too.

> +		for (i = 0; i < priv->num_sensors; i++)
> +			p2[i] = ((base1 + p2[i]) << 2);
> +		p2[1] -= MSM8909_D120_WA_S1;
> +		p2[3] -= MSM8909_D120_WA_S3;
> +		p2[4] -= MSM8909_D120_WA_S4;
> +		fallthrough;
> +	case ONE_PT_CALIB2:
> +		base0 = (qfprom_csel[0] & MSM8909_BASE0_MASK) >> MSM8909_BASE0_SHIFT;
> +		p1[0] = (qfprom_cdata[0] & MSM8909_S0_P1_MASK) >> MSM8909_S0_P1_SHIFT;
> +		p1[1] = (qfprom_cdata[0] & MSM8909_S1_P1_MASK) >> MSM8909_S1_P1_SHIFT;
> +		p1[2] = (qfprom_cdata[0] & MSM8909_S2_P1_MASK) >> MSM8909_S2_P1_SHIFT;
> +		p1[3] = (qfprom_cdata[1] & MSM8909_S3_P1_MASK) >> MSM8909_S3_P1_SHIFT;
> +		p1[4] = (qfprom_cdata[1] & MSM8909_S4_P1_MASK) >> MSM8909_S4_P1_SHIFT;
> +		for (i = 0; i < priv->num_sensors; i++)
> +			p1[i] = (((base0) + p1[i]) << 2);
> +		p1[1] -= MSM8909_D30_WA_S1;
> +		p1[3] -= MSM8909_D30_WA_S3;
> +		p1[4] -= MSM8909_D30_WA_S4;
> +		break;
> +	default:
> +		for (i = 0; i < priv->num_sensors; i++) {
> +			p1[i] = 500;
> +			p2[i] = 780;
> +		}
> +		break;
> +	}
> +
> +	compute_intercept_slope(priv, p1, p2, mode);
> +	kfree(qfprom_cdata);
> +	kfree(qfprom_csel);
> +
> +	return 0;
> +}
> +
>   static int calibrate_8916(struct tsens_priv *priv)
>   {
>   	int base0 = 0, base1 = 0, i;
> @@ -534,7 +638,7 @@ static int calibrate_9607(struct tsens_priv *priv)
>   	return 0;
>   }
>   
> -/* 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,
> @@ -580,6 +684,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_common,
> +	.calibrate	= calibrate_8909,
> +	.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 7963ee33bf75..cb7bbaa72d89 100644
> --- a/drivers/thermal/qcom/tsens.c
> +++ b/drivers/thermal/qcom/tsens.c
> @@ -973,6 +973,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 1471a2c00f15..752d4718f26e 100644
> --- a/drivers/thermal/qcom/tsens.h
> +++ b/drivers/thermal/qcom/tsens.h
> @@ -587,7 +587,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;

-- 
With best wishes
Dmitry


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

* Re: [PATCH 3/3] thermal: qcom: tsens: Add data for MSM8909
  2022-09-08 20:57   ` Dmitry Baryshkov
@ 2022-09-09 13:51     ` Stephan Gerhold
  2022-09-09 14:54       ` Dmitry Baryshkov
  0 siblings, 1 reply; 10+ messages in thread
From: Stephan Gerhold @ 2022-09-09 13:51 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Stephan Gerhold, Daniel Lezcano, Rafael J. Wysocki,
	Amit Kucheria, Thara Gopinath, Zhang Rui, Rob Herring,
	Krzysztof Kozlowski, Bjorn Andersson, Andy Gross, linux-arm-msm,
	linux-pm, devicetree

On Thu, Sep 08, 2022 at 11:57:41PM +0300, Dmitry Baryshkov wrote:
> On 27/06/2022 16:14, Stephan Gerhold wrote:
> > The MSM8909 SoC has 5 thermal sensors in a TSENS v0.1 block similar to
> > MSM8916, except that the bit offsets in the qfprom were changed.
> > Also, some fixed correction factors are needed as workaround because the
> > factory calibration apparently was not reliable enough.
> > 
> > Add the defines and calibration function for MSM8909 in the existing
> > tsens-v0_1.c driver to make the thermal sensors work on MSM8909.
> > The changes are derived from the original msm-3.18 kernel [1] from
> > Qualcomm but cleaned up and adapted to the driver in mainline.
> > 
> > [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LA.UM.7.7.c26-08600-8x09.0/drivers/thermal/msm-tsens.c
> > 
> > Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
> > ---
> >   drivers/thermal/qcom/tsens-v0_1.c | 119 +++++++++++++++++++++++++++++-
> >   drivers/thermal/qcom/tsens.c      |   3 +
> >   drivers/thermal/qcom/tsens.h      |   2 +-
> >   3 files changed, 122 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> > index f136cb350238..e17c4f9d9aa5 100644
> > --- a/drivers/thermal/qcom/tsens-v0_1.c
> > +++ b/drivers/thermal/qcom/tsens-v0_1.c
> > @@ -15,6 +15,48 @@
> >   #define TM_Sn_STATUS_OFF			0x0030
> >   #define TM_TRDY_OFF				0x005c
> > +/* eeprom layout data for 8909 */
> > +#define MSM8909_CAL_SEL_MASK	0x00070000
> > +#define MSM8909_CAL_SEL_SHIFT	16
> > +
> > +#define MSM8909_BASE0_MASK	0x000000ff
> > +#define MSM8909_BASE1_MASK	0x0000ff00
> > +#define MSM8909_BASE0_SHIFT	0
> > +#define MSM8909_BASE1_SHIFT	8
> > +
> > +#define MSM8909_S0_P1_MASK	0x0000003f
> > +#define MSM8909_S1_P1_MASK	0x0003f000
> > +#define MSM8909_S2_P1_MASK	0x3f000000
> > +#define MSM8909_S3_P1_MASK	0x000003f0
> > +#define MSM8909_S4_P1_MASK	0x003f0000
> > +
> > +#define MSM8909_S0_P2_MASK	0x00000fc0
> > +#define MSM8909_S1_P2_MASK	0x00fc0000
> > +#define MSM8909_S2_P2_MASK_0_1	0xc0000000
> > +#define MSM8909_S2_P2_MASK_2_5	0x0000000f
> > +#define MSM8909_S3_P2_MASK	0x0000fc00
> > +#define MSM8909_S4_P2_MASK	0x0fc00000
> > +
> > +#define MSM8909_S0_P1_SHIFT	0
> > +#define MSM8909_S1_P1_SHIFT	12
> > +#define MSM8909_S2_P1_SHIFT	24
> > +#define MSM8909_S3_P1_SHIFT	4
> > +#define MSM8909_S4_P1_SHIFT	16
> > +
> > +#define MSM8909_S0_P2_SHIFT	6
> > +#define MSM8909_S1_P2_SHIFT	18
> > +#define MSM8909_S2_P2_SHIFT_0_1	30
> > +#define MSM8909_S2_P2_SHIFT_2_5	2
> > +#define MSM8909_S3_P2_SHIFT	10
> > +#define MSM8909_S4_P2_SHIFT	22
> > +
> > +#define MSM8909_D30_WA_S1	10
> > +#define MSM8909_D30_WA_S3	9
> > +#define MSM8909_D30_WA_S4	8
> > +#define MSM8909_D120_WA_S1	6
> > +#define MSM8909_D120_WA_S3	9
> > +#define MSM8909_D120_WA_S4	10
> > +
> >   /* eeprom layout data for 8916 */
> >   #define MSM8916_BASE0_MASK	0x0000007f
> >   #define MSM8916_BASE1_MASK	0xfe000000
> > @@ -223,6 +265,68 @@
> >   #define MDM9607_CAL_SEL_MASK	0x00700000
> >   #define MDM9607_CAL_SEL_SHIFT	20
> > +static int calibrate_8909(struct tsens_priv *priv)
> > +{
> > +	u32 *qfprom_cdata, *qfprom_csel;
> > +	int base0, base1, mode, i;
> > +	u32 p1[5], p2[5];
> > +
> > +	qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> > +	if (IS_ERR(qfprom_cdata))
> > +		return PTR_ERR(qfprom_cdata);
> > +
> > +	qfprom_csel = (u32 *)qfprom_read(priv->dev, "calib_sel");
> > +	if (IS_ERR(qfprom_csel)) {
> > +		kfree(qfprom_cdata);
> > +		return PTR_ERR(qfprom_csel);
> > +	}
> > +
> > +	mode = (qfprom_csel[0] & MSM8909_CAL_SEL_MASK) >> MSM8909_CAL_SEL_SHIFT;
> > +	dev_dbg(priv->dev, "calibration mode is %d\n", mode);
> > +
> > +	switch (mode) {
> > +	case TWO_PT_CALIB:
> > +		base1 = (qfprom_csel[0] & MSM8909_BASE1_MASK) >> MSM8909_BASE1_SHIFT;
> > +		p2[0] = (qfprom_cdata[0] & MSM8909_S0_P2_MASK) >> MSM8909_S0_P2_SHIFT;
> > +		p2[1] = (qfprom_cdata[0] & MSM8909_S1_P2_MASK) >> MSM8909_S1_P2_SHIFT;
> > +		p2[2] = (qfprom_cdata[0] & MSM8909_S2_P2_MASK_0_1) >> MSM8909_S2_P2_SHIFT_0_1;
> > +		p2[2] |= (qfprom_cdata[1] & MSM8909_S2_P2_MASK_2_5) << MSM8909_S2_P2_SHIFT_2_5;
> > +		p2[3] = (qfprom_cdata[1] & MSM8909_S3_P2_MASK) >> MSM8909_S3_P2_SHIFT;
> > +		p2[4] = (qfprom_cdata[1] & MSM8909_S4_P2_MASK) >> MSM8909_S4_P2_SHIFT;
> 
> Please use nvmem_cell_read_* to read these values. This would allow you to
> push all the possible si_pi definitions into the DT and use mode to switch
> between them. And mode can be read using the nvmem_cell_read_* too.

Thanks for the suggestion.

I agree that this would have been nicer if this had been implemented
that way for all the existing platforms supported by the tsens driver.
But now we already have 7+ platforms using exactly the approach I'm
using in this patch, with existing bindings and existing device trees
that must stay supported.

My msm8909.dtsi is actually mostly just a simple overlay on top of
msm8916.dtsi, so I would like to keep these platforms consistent
wherever possible. We could change all the existing platforms as well
but in my opinion this would just make the driver and bindings a lot
more complicated because the old approach still must be supported.

Also, I think the main benefit of having all the points as separate
NVMEM cells would be to allow having a generic qcom,tsens-v0.1
compatible, without SoC-specific code required in the driver. However,
subtle differences in the way the calibration points are used (e.g. the
fixed correction offsets in this patch) will likely make SoC-specific
code necessary anyway. And then it doesn't matter much if the bit masks
are in the driver like all existing code or end up being put into the DT.

TL;DR: I would prefer to keep this as-is to keep the driver simple and
consistent across all the supported platforms.

Thanks,
Stephan

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

* Re: [PATCH 3/3] thermal: qcom: tsens: Add data for MSM8909
  2022-09-09 13:51     ` Stephan Gerhold
@ 2022-09-09 14:54       ` Dmitry Baryshkov
  0 siblings, 0 replies; 10+ messages in thread
From: Dmitry Baryshkov @ 2022-09-09 14:54 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, linux-arm-msm,
	linux-pm, devicetree

On 09/09/2022 16:51, Stephan Gerhold wrote:
> On Thu, Sep 08, 2022 at 11:57:41PM +0300, Dmitry Baryshkov wrote:
>> On 27/06/2022 16:14, Stephan Gerhold wrote:
>>> The MSM8909 SoC has 5 thermal sensors in a TSENS v0.1 block similar to
>>> MSM8916, except that the bit offsets in the qfprom were changed.
>>> Also, some fixed correction factors are needed as workaround because the
>>> factory calibration apparently was not reliable enough.
>>>
>>> Add the defines and calibration function for MSM8909 in the existing
>>> tsens-v0_1.c driver to make the thermal sensors work on MSM8909.
>>> The changes are derived from the original msm-3.18 kernel [1] from
>>> Qualcomm but cleaned up and adapted to the driver in mainline.
>>>
>>> [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LA.UM.7.7.c26-08600-8x09.0/drivers/thermal/msm-tsens.c
>>>
>>> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
>>> ---
>>>    drivers/thermal/qcom/tsens-v0_1.c | 119 +++++++++++++++++++++++++++++-
>>>    drivers/thermal/qcom/tsens.c      |   3 +
>>>    drivers/thermal/qcom/tsens.h      |   2 +-
>>>    3 files changed, 122 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
>>> index f136cb350238..e17c4f9d9aa5 100644
>>> --- a/drivers/thermal/qcom/tsens-v0_1.c
>>> +++ b/drivers/thermal/qcom/tsens-v0_1.c
>>> @@ -15,6 +15,48 @@
>>>    #define TM_Sn_STATUS_OFF			0x0030
>>>    #define TM_TRDY_OFF				0x005c
>>> +/* eeprom layout data for 8909 */
>>> +#define MSM8909_CAL_SEL_MASK	0x00070000
>>> +#define MSM8909_CAL_SEL_SHIFT	16
>>> +
>>> +#define MSM8909_BASE0_MASK	0x000000ff
>>> +#define MSM8909_BASE1_MASK	0x0000ff00
>>> +#define MSM8909_BASE0_SHIFT	0
>>> +#define MSM8909_BASE1_SHIFT	8
>>> +
>>> +#define MSM8909_S0_P1_MASK	0x0000003f
>>> +#define MSM8909_S1_P1_MASK	0x0003f000
>>> +#define MSM8909_S2_P1_MASK	0x3f000000
>>> +#define MSM8909_S3_P1_MASK	0x000003f0
>>> +#define MSM8909_S4_P1_MASK	0x003f0000
>>> +
>>> +#define MSM8909_S0_P2_MASK	0x00000fc0
>>> +#define MSM8909_S1_P2_MASK	0x00fc0000
>>> +#define MSM8909_S2_P2_MASK_0_1	0xc0000000
>>> +#define MSM8909_S2_P2_MASK_2_5	0x0000000f
>>> +#define MSM8909_S3_P2_MASK	0x0000fc00
>>> +#define MSM8909_S4_P2_MASK	0x0fc00000
>>> +
>>> +#define MSM8909_S0_P1_SHIFT	0
>>> +#define MSM8909_S1_P1_SHIFT	12
>>> +#define MSM8909_S2_P1_SHIFT	24
>>> +#define MSM8909_S3_P1_SHIFT	4
>>> +#define MSM8909_S4_P1_SHIFT	16
>>> +
>>> +#define MSM8909_S0_P2_SHIFT	6
>>> +#define MSM8909_S1_P2_SHIFT	18
>>> +#define MSM8909_S2_P2_SHIFT_0_1	30
>>> +#define MSM8909_S2_P2_SHIFT_2_5	2
>>> +#define MSM8909_S3_P2_SHIFT	10
>>> +#define MSM8909_S4_P2_SHIFT	22
>>> +
>>> +#define MSM8909_D30_WA_S1	10
>>> +#define MSM8909_D30_WA_S3	9
>>> +#define MSM8909_D30_WA_S4	8
>>> +#define MSM8909_D120_WA_S1	6
>>> +#define MSM8909_D120_WA_S3	9
>>> +#define MSM8909_D120_WA_S4	10
>>> +
>>>    /* eeprom layout data for 8916 */
>>>    #define MSM8916_BASE0_MASK	0x0000007f
>>>    #define MSM8916_BASE1_MASK	0xfe000000
>>> @@ -223,6 +265,68 @@
>>>    #define MDM9607_CAL_SEL_MASK	0x00700000
>>>    #define MDM9607_CAL_SEL_SHIFT	20
>>> +static int calibrate_8909(struct tsens_priv *priv)
>>> +{
>>> +	u32 *qfprom_cdata, *qfprom_csel;
>>> +	int base0, base1, mode, i;
>>> +	u32 p1[5], p2[5];
>>> +
>>> +	qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>> +	if (IS_ERR(qfprom_cdata))
>>> +		return PTR_ERR(qfprom_cdata);
>>> +
>>> +	qfprom_csel = (u32 *)qfprom_read(priv->dev, "calib_sel");
>>> +	if (IS_ERR(qfprom_csel)) {
>>> +		kfree(qfprom_cdata);
>>> +		return PTR_ERR(qfprom_csel);
>>> +	}
>>> +
>>> +	mode = (qfprom_csel[0] & MSM8909_CAL_SEL_MASK) >> MSM8909_CAL_SEL_SHIFT;
>>> +	dev_dbg(priv->dev, "calibration mode is %d\n", mode);
>>> +
>>> +	switch (mode) {
>>> +	case TWO_PT_CALIB:
>>> +		base1 = (qfprom_csel[0] & MSM8909_BASE1_MASK) >> MSM8909_BASE1_SHIFT;
>>> +		p2[0] = (qfprom_cdata[0] & MSM8909_S0_P2_MASK) >> MSM8909_S0_P2_SHIFT;
>>> +		p2[1] = (qfprom_cdata[0] & MSM8909_S1_P2_MASK) >> MSM8909_S1_P2_SHIFT;
>>> +		p2[2] = (qfprom_cdata[0] & MSM8909_S2_P2_MASK_0_1) >> MSM8909_S2_P2_SHIFT_0_1;
>>> +		p2[2] |= (qfprom_cdata[1] & MSM8909_S2_P2_MASK_2_5) << MSM8909_S2_P2_SHIFT_2_5;
>>> +		p2[3] = (qfprom_cdata[1] & MSM8909_S3_P2_MASK) >> MSM8909_S3_P2_SHIFT;
>>> +		p2[4] = (qfprom_cdata[1] & MSM8909_S4_P2_MASK) >> MSM8909_S4_P2_SHIFT;
>>
>> Please use nvmem_cell_read_* to read these values. This would allow you to
>> push all the possible si_pi definitions into the DT and use mode to switch
>> between them. And mode can be read using the nvmem_cell_read_* too.
> 
> Thanks for the suggestion.
> 
> I agree that this would have been nicer if this had been implemented
> that way for all the existing platforms supported by the tsens driver.
> But now we already have 7+ platforms using exactly the approach I'm
> using in this patch, with existing bindings and existing device trees
> that must stay supported.
> 
> My msm8909.dtsi is actually mostly just a simple overlay on top of
> msm8916.dtsi, so I would like to keep these platforms consistent
> wherever possible. We could change all the existing platforms as well
> but in my opinion this would just make the driver and bindings a lot
> more complicated because the old approach still must be supported.
> 
> Also, I think the main benefit of having all the points as separate
> NVMEM cells would be to allow having a generic qcom,tsens-v0.1
> compatible, without SoC-specific code required in the driver. However,
> subtle differences in the way the calibration points are used (e.g. the
> fixed correction offsets in this patch) will likely make SoC-specific
> code necessary anyway. And then it doesn't matter much if the bit masks
> are in the driver like all existing code or end up being put into the DT.
> 
> TL;DR: I would prefer to keep this as-is to keep the driver simple and
> consistent across all the supported platforms.

At least let's change the driver to use FIELD_GET, this will allow us to 
remove SHIFT defines. I will take a look in the next few days if we can 
switch to nvmem_cell in a sensible manner.

-- 
With best wishes
Dmitry


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

end of thread, other threads:[~2022-09-09 14:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-27 13:14 [PATCH 0/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
2022-06-27 13:14 ` [PATCH 1/3] dt-bindings: thermal: qcom-tsens: Drop redundant compatibles Stephan Gerhold
2022-06-29 10:46   ` Krzysztof Kozlowski
2022-06-27 13:14 ` [PATCH 2/3] dt-bindings: thermal: qcom-tsens: Add MSM8909 compatible Stephan Gerhold
2022-06-29 10:46   ` Krzysztof Kozlowski
2022-06-27 13:14 ` [PATCH 3/3] thermal: qcom: tsens: Add data for MSM8909 Stephan Gerhold
2022-09-08 20:57   ` Dmitry Baryshkov
2022-09-09 13:51     ` Stephan Gerhold
2022-09-09 14:54       ` Dmitry Baryshkov
2022-09-08 20:08 ` [PATCH 0/3] " Stephan Gerhold

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.