* [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually
@ 2022-12-29 3:00 Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 01/20] dt-bindings: thermal: tsens: add msm8956 compat Dmitry Baryshkov
` (19 more replies)
0 siblings, 20 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
Historically the tsens driver fetches the calibration data as a blob and
then parses the blob on its own. This results in semi-duplicated code
spreading over the platform-specific functions.
This patch series changes tsens calibration code to per-value nvmem
cells rather than parsing the blob in the driver. For backwards
compatibility the old code is left in place for msm8916, msm8974 and
qcs404, the platforms which have in-tree DT files. For all other
affected platforms the old parsing code has been dropped as a part of
this series.
The code was tested on msm8916 and qcs404 only.
Note: the DTs changes depend on driver changes. Tsens driver will not
work if DT patches are merged, but the driver bits are not. As the
thermal sense is critical for device safety, I'kindly ask to have an
immutable branch with the driver changes that can be merged into the
msm-dts tree.
Note2:
I still have included patches to drop legacy support for 8939
(msm8939.dtsi is on the list, patch to convert it to the proposed
bindings is available at [1]) and 8976 (msm8976.dtsi and msm8956.dtsi,
which use single-blob bindings, have been accepted for 6.2, dropping old
bindings support depends on mutual consensuns of platform and thermal
code maintainers). Corresponding patches are the last ones in the
thermal part of the series, thus if they are declined, the reset of the
series still can be applied without any problems.
[1] https://pastebin.ubuntu.com/p/rfkZgy767K/
Changes since v4:
- Changed DT bindings to use HW sensor ids rather than bare indices.
This follows the usage of hw_ids in thermal-sensors specifications
(and corresponds to the ID visible in debugfs).
Previously there was no correspondence, which resulted e.g. in usage
of s0_p1/s0_p2 for sensor 0, but s4_p1/s4_p2 for the sensor 5 on
the msm8916 platform).
- Reworked msm8939 code to ignore the sensor10. It is available only on
latest hw revision, it doesn't seem to be actually used and it also
wasn't covered by the old single-blob bindings because of the parsing
error.
- Fixed missing include reported by testing robot.
Changes since v3:
- Added a patch to fix the tsens compatible string on msm8956 SoC,
- Fixed num-sensors and slope coefficients for the msm8939 SoC,
- Rewrote code supporting old bindings into the simple data-driven
parser common to all legacy platforms which made dropping support for
old bindings less demanding.
Changes since v2:
- Made init_8956 static, as pointed out by the testing robot and by
AngeloGioacchino Del Regno.
Changes since the RFC:
- Sorted out the msm8976/msm8956, custom slopes are used only for msm8956,
- Implemented proper support for msm8974/apq8084,
- Added tsens_calibrate_common() and ops_v0_1 which can be used in
common cases,
- Removed superfluous identity hw_ids
- Fixed calibration calculation in tsens_calibrate_nvmem() for
ONE_PT_CALIB case
Dmitry Baryshkov (20):
dt-bindings: thermal: tsens: add msm8956 compat
dt-bindings: thermal: tsens: support per-sensor calibration cells
dt-bindings: thermal: tsens: add per-sensor cells for msm8974
thermal/drivers/tsens: Drop unnecessary hw_ids
thermal/drivers/tsens: Drop msm8976-specific defines
thermal/drivers/tsens: Sort out msm8976 vs msm8956 data
thermal/drivers/tsens: fix slope values for msm8939
thermal/drivers/tsens: limit num_sensors to 9 for msm8939
thermal/drivers/tsens: Support using nvmem cells for calibration data
thermal/drivers/tsens: Support using nvmem cells for msm8974
calibration
thermal/drivers/tsens: Rework legacy calibration data parsers
thermal/drivers/tsens: Drop single-cell code for mdm9607
thermal/drivers/tsens: Drop single-cell code for msm8939
thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956
arm64: dts: qcom: msm8956: use SoC-specific compat for tsens
arm64: dts: qcom: msm8916: specify per-sensor calibration cells
arm64: dts: qcom: msm8976: specify per-sensor calibration cells
arm64: dts: qcom: qcs404: specify per-sensor calibration cells
ARM: dts: qcom-msm8974: specify per-sensor calibration cells
ARM: dts: qcom-apq8084: specify per-sensor calibration cells
.../bindings/thermal/qcom-tsens.yaml | 154 +++-
arch/arm/boot/dts/qcom-apq8084.dtsi | 313 ++++++++-
arch/arm/boot/dts/qcom-msm8974.dtsi | 313 ++++++++-
arch/arm64/boot/dts/qcom/msm8916.dtsi | 85 ++-
arch/arm64/boot/dts/qcom/msm8956.dtsi | 4 +
arch/arm64/boot/dts/qcom/msm8976.dtsi | 153 +++-
arch/arm64/boot/dts/qcom/qcs404.dtsi | 145 +++-
drivers/thermal/qcom/tsens-v0_1.c | 655 +++++-------------
drivers/thermal/qcom/tsens-v1.c | 340 +++------
drivers/thermal/qcom/tsens.c | 168 +++++
drivers/thermal/qcom/tsens.h | 46 +-
11 files changed, 1611 insertions(+), 765 deletions(-)
--
2.39.0
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH v5 01/20] dt-bindings: thermal: tsens: add msm8956 compat
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells Dmitry Baryshkov
` (18 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree, Krzysztof Kozlowski
When adding support for msm8976 it was thought that msm8956 would reuse
the same compat. However checking the vendor kernel revealed that these
two platforms use different slope values for calculating the calibration
data.
Add new compatible for the tsens on msm8956 SoC.
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
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 0231f187b097..f3660af0b3bf 100644
--- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
+++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
@@ -37,6 +37,7 @@ properties:
- description: v1 of TSENS
items:
- enum:
+ - qcom,msm8956-tsens
- qcom,msm8976-tsens
- qcom,qcs404-tsens
- const: qcom,tsens-v1
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 01/20] dt-bindings: thermal: tsens: add msm8956 compat Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 8:35 ` Krzysztof Kozlowski
2022-12-29 3:00 ` [PATCH v5 03/20] dt-bindings: thermal: tsens: add per-sensor cells for msm8974 Dmitry Baryshkov
` (17 subsequent siblings)
19 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
Allow specifying the exact calibration mode and calibration data as nvmem
cells, rather than specifying just a single calibration data blob.
Note, unlike the vendor kernel the calibration data uses hw_ids rather
than software sensor indices (to match actual tsens usage in
thermal zones).
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
.../bindings/thermal/qcom-tsens.yaml | 95 +++++++++++++++++--
1 file changed, 85 insertions(+), 10 deletions(-)
diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
index f3660af0b3bf..4bb689f4602d 100644
--- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
+++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
@@ -81,18 +81,63 @@ properties:
maxItems: 2
nvmem-cells:
- minItems: 1
- maxItems: 2
- description:
- Reference to an nvmem node for the calibration data
+ oneOf:
+ - minItems: 1
+ maxItems: 2
+ description:
+ Reference to an nvmem node for the calibration data
+ - minItems: 5
+ maxItems: 35
+ description: |
+ Reference to nvmem cells for the calibration mode, two calibration
+ bases and two cells per each sensor
nvmem-cell-names:
- minItems: 1
- items:
- - const: calib
- - enum:
- - calib_backup
- - calib_sel
+ oneOf:
+ - minItems: 1
+ items:
+ - const: calib
+ - enum:
+ - calib_backup
+ - calib_sel
+ - minItems: 5
+ items:
+ enum:
+ - mode
+ - base1
+ - base2
+ - s0_p1
+ - s0_p2
+ - s1_p1
+ - s1_p2
+ - s2_p1
+ - s2_p2
+ - s3_p1
+ - s3_p2
+ - s4_p1
+ - s4_p2
+ - s5_p1
+ - s5_p2
+ - s6_p1
+ - s6_p2
+ - s7_p1
+ - s7_p2
+ - s8_p1
+ - s8_p2
+ - s9_p1
+ - s9_p2
+ - s10_p1
+ - s10_p2
+ - s11_p1
+ - s11_p2
+ - s12_p1
+ - s12_p2
+ - s13_p1
+ - s13_p2
+ - s14_p1
+ - s14_p2
+ - s15_p1
+ - s15_p2
"#qcom,sensors":
description:
@@ -221,6 +266,36 @@ examples:
};
};
+ - |
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
+ // Example 1 (new calbiration data: for pre v1 IP):
+ thermal-sensor@900000 {
+ compatible = "qcom,msm8916-tsens", "qcom,tsens-v0_1";
+ reg = <0x4a9000 0x1000>, /* TM */
+ <0x4a8000 0x1000>; /* SROT */
+
+ nvmem-cells = <&tsens_mode>,
+ <&tsens_base1>, <&tsens_base2>,
+ <&tsens_s0_p1>, <&tsens_s0_p2>,
+ <&tsens_s1_p1>, <&tsens_s1_p2>,
+ <&tsens_s2_p1>, <&tsens_s2_p2>,
+ <&tsens_s4_p1>, <&tsens_s4_p2>,
+ <&tsens_s5_p1>, <&tsens_s5_p2>;
+ nvmem-cell-names = "mode",
+ "base1", "base2",
+ "s0_p1", "s0_p2",
+ "s1_p1", "s1_p2",
+ "s2_p1", "s2_p2",
+ "s4_p1", "s4_p2",
+ "s5_p1", "s5_p2";
+
+ interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL_HIGH>;
+ interrupt-names = "uplow";
+
+ #qcom,sensors = <5>;
+ #thermal-sensor-cells = <1>;
+ };
+
- |
#include <dt-bindings/interrupt-controller/arm-gic.h>
// Example 1 (legacy: for pre v1 IP):
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 03/20] dt-bindings: thermal: tsens: add per-sensor cells for msm8974
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 01/20] dt-bindings: thermal: tsens: add msm8956 compat Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 04/20] thermal/drivers/tsens: Drop unnecessary hw_ids Dmitry Baryshkov
` (16 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree, Krzysztof Kozlowski
The msm8974 platform uses two sets of calibration data, add a special
case to handle both of them.
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
.../bindings/thermal/qcom-tsens.yaml | 58 +++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
index 4bb689f4602d..5543df93f752 100644
--- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
+++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
@@ -91,6 +91,11 @@ properties:
description: |
Reference to nvmem cells for the calibration mode, two calibration
bases and two cells per each sensor
+ # special case for msm8974 / apq8084
+ - maxItems: 51
+ description: |
+ Reference to nvmem cells for the calibration mode, two calibration
+ bases and two cells per each sensor, main and backup copies, plus use_backup cell
nvmem-cell-names:
oneOf:
@@ -138,6 +143,59 @@ properties:
- s14_p2
- s15_p1
- s15_p2
+ # special case for msm8974 / apq8084
+ - items:
+ - const: mode
+ - const: base1
+ - const: base2
+ - const: s0_p1
+ - const: s0_p2
+ - const: s1_p1
+ - const: s1_p2
+ - const: s2_p1
+ - const: s2_p2
+ - const: s3_p1
+ - const: s3_p2
+ - const: s4_p1
+ - const: s4_p2
+ - const: s5_p1
+ - const: s5_p2
+ - const: s6_p1
+ - const: s6_p2
+ - const: s7_p1
+ - const: s7_p2
+ - const: s8_p1
+ - const: s8_p2
+ - const: s9_p1
+ - const: s9_p2
+ - const: s10_p1
+ - const: s10_p2
+ - const: use_backup
+ - const: mode_backup
+ - const: base1_backup
+ - const: base2_backup
+ - const: s0_p1_backup
+ - const: s0_p2_backup
+ - const: s1_p1_backup
+ - const: s1_p2_backup
+ - const: s2_p1_backup
+ - const: s2_p2_backup
+ - const: s3_p1_backup
+ - const: s3_p2_backup
+ - const: s4_p1_backup
+ - const: s4_p2_backup
+ - const: s5_p1_backup
+ - const: s5_p2_backup
+ - const: s6_p1_backup
+ - const: s6_p2_backup
+ - const: s7_p1_backup
+ - const: s7_p2_backup
+ - const: s8_p1_backup
+ - const: s8_p2_backup
+ - const: s9_p1_backup
+ - const: s9_p2_backup
+ - const: s10_p1_backup
+ - const: s10_p2_backup
"#qcom,sensors":
description:
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 04/20] thermal/drivers/tsens: Drop unnecessary hw_ids
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (2 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 03/20] dt-bindings: thermal: tsens: add per-sensor cells for msm8974 Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 05/20] thermal/drivers/tsens: Drop msm8976-specific defines Dmitry Baryshkov
` (15 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
The tsens driver defaults to using hw_id equal to the index of the
sensor. Thus it is superfluous to declare such hw_id arrays. Drop such
arrays from mdm9607 and msm8976 data.
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 1 -
drivers/thermal/qcom/tsens-v1.c | 1 -
2 files changed, 2 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 04d012e4f728..0bc4e5cec184 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -635,7 +635,6 @@ static const struct tsens_ops ops_9607 = {
struct tsens_plat_data data_9607 = {
.num_sensors = 5,
.ops = &ops_9607,
- .hw_ids = (unsigned int []){ 0, 1, 2, 3, 4 },
.feat = &tsens_v0_1_feat,
.fields = tsens_v0_1_regfields,
};
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 1d7f8a80bd13..96ef12d47bff 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -387,7 +387,6 @@ static const struct tsens_ops ops_8976 = {
struct tsens_plat_data data_8976 = {
.num_sensors = 11,
.ops = &ops_8976,
- .hw_ids = (unsigned int[]){0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
.feat = &tsens_v1_feat,
.fields = tsens_v1_regfields,
};
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 05/20] thermal/drivers/tsens: Drop msm8976-specific defines
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (3 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 04/20] thermal/drivers/tsens: Drop unnecessary hw_ids Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 06/20] thermal/drivers/tsens: Sort out msm8976 vs msm8956 data Dmitry Baryshkov
` (14 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree, AngeloGioacchino Del Regno
Drop msm8976-specific defines, which duplicate generic ones.
Fixes: 0e580290170d ("thermal: qcom: tsens-v1: Add support for MSM8956 and MSM8976")
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v1.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 96ef12d47bff..a7f53966156b 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -78,11 +78,6 @@
#define MSM8976_CAL_SEL_MASK 0x3
-#define MSM8976_CAL_DEGC_PT1 30
-#define MSM8976_CAL_DEGC_PT2 120
-#define MSM8976_SLOPE_FACTOR 1000
-#define MSM8976_SLOPE_DEFAULT 3200
-
/* eeprom layout data for qcs404/405 (v1) */
#define BASE0_MASK 0x000007f8
#define BASE1_MASK 0x0007f800
@@ -160,8 +155,8 @@ static void compute_intercept_slope_8976(struct tsens_priv *priv,
priv->sensor[10].slope = 3286;
for (i = 0; i < priv->num_sensors; i++) {
- priv->sensor[i].offset = (p1[i] * MSM8976_SLOPE_FACTOR) -
- (MSM8976_CAL_DEGC_PT1 *
+ priv->sensor[i].offset = (p1[i] * SLOPE_FACTOR) -
+ (CAL_DEGC_PT1 *
priv->sensor[i].slope);
}
}
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 06/20] thermal/drivers/tsens: Sort out msm8976 vs msm8956 data
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (4 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 05/20] thermal/drivers/tsens: Drop msm8976-specific defines Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 07/20] thermal/drivers/tsens: fix slope values for msm8939 Dmitry Baryshkov
` (13 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree, AngeloGioacchino Del Regno
Tsens driver mentions that msm8976 data should be used for both msm8976
and msm8956 SoCs. This is not quite correct, as according to the
vendor kernels, msm8976 should use standard slope values (3200), while
msm8956 really uses the slope values found in the driver.
Add separate compatibility string for msm8956, move slope value
overrides to the corresponding init function and use the standard
compute_intercept_slope() function for both platforms.
Fixes: 0e580290170d ("thermal: qcom: tsens-v1: Add support for MSM8956 and MSM8976")
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v1.c | 56 ++++++++++++++++++---------------
drivers/thermal/qcom/tsens.c | 3 ++
drivers/thermal/qcom/tsens.h | 2 +-
3 files changed, 34 insertions(+), 27 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index a7f53966156b..83c2853546d0 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -137,30 +137,6 @@
#define CAL_SEL_MASK 7
#define CAL_SEL_SHIFT 0
-static void compute_intercept_slope_8976(struct tsens_priv *priv,
- u32 *p1, u32 *p2, u32 mode)
-{
- int i;
-
- priv->sensor[0].slope = 3313;
- priv->sensor[1].slope = 3275;
- priv->sensor[2].slope = 3320;
- priv->sensor[3].slope = 3246;
- priv->sensor[4].slope = 3279;
- priv->sensor[5].slope = 3257;
- priv->sensor[6].slope = 3234;
- priv->sensor[7].slope = 3269;
- priv->sensor[8].slope = 3255;
- priv->sensor[9].slope = 3239;
- priv->sensor[10].slope = 3286;
-
- for (i = 0; i < priv->num_sensors; i++) {
- priv->sensor[i].offset = (p1[i] * SLOPE_FACTOR) -
- (CAL_DEGC_PT1 *
- priv->sensor[i].slope);
- }
-}
-
static int calibrate_v1(struct tsens_priv *priv)
{
u32 base0 = 0, base1 = 0;
@@ -286,7 +262,7 @@ static int calibrate_8976(struct tsens_priv *priv)
break;
}
- compute_intercept_slope_8976(priv, p1, p2, mode);
+ compute_intercept_slope(priv, p1, p2, mode);
kfree(qfprom_cdata);
return 0;
@@ -360,6 +336,22 @@ static const struct reg_field tsens_v1_regfields[MAX_REGFIELDS] = {
[TRDY] = REG_FIELD(TM_TRDY_OFF, 0, 0),
};
+static int __init init_8956(struct tsens_priv *priv) {
+ priv->sensor[0].slope = 3313;
+ priv->sensor[1].slope = 3275;
+ priv->sensor[2].slope = 3320;
+ priv->sensor[3].slope = 3246;
+ priv->sensor[4].slope = 3279;
+ priv->sensor[5].slope = 3257;
+ priv->sensor[6].slope = 3234;
+ priv->sensor[7].slope = 3269;
+ priv->sensor[8].slope = 3255;
+ priv->sensor[9].slope = 3239;
+ priv->sensor[10].slope = 3286;
+
+ return init_common(priv);
+}
+
static const struct tsens_ops ops_generic_v1 = {
.init = init_common,
.calibrate = calibrate_v1,
@@ -372,13 +364,25 @@ struct tsens_plat_data data_tsens_v1 = {
.fields = tsens_v1_regfields,
};
+static const struct tsens_ops ops_8956 = {
+ .init = init_8956,
+ .calibrate = calibrate_8976,
+ .get_temp = get_temp_tsens_valid,
+};
+
+struct tsens_plat_data data_8956 = {
+ .num_sensors = 11,
+ .ops = &ops_8956,
+ .feat = &tsens_v1_feat,
+ .fields = tsens_v1_regfields,
+};
+
static const struct tsens_ops ops_8976 = {
.init = init_common,
.calibrate = calibrate_8976,
.get_temp = get_temp_tsens_valid,
};
-/* Valid for both MSM8956 and MSM8976. */
struct tsens_plat_data data_8976 = {
.num_sensors = 11,
.ops = &ops_8976,
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index b5b136ff323f..b191e19df93d 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -983,6 +983,9 @@ static const struct of_device_id tsens_table[] = {
}, {
.compatible = "qcom,msm8939-tsens",
.data = &data_8939,
+ }, {
+ .compatible = "qcom,msm8956-tsens",
+ .data = &data_8956,
}, {
.compatible = "qcom,msm8960-tsens",
.data = &data_8960,
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index 899af128855f..7dd5fc246894 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -594,7 +594,7 @@ extern struct tsens_plat_data data_8960;
extern struct tsens_plat_data data_8916, data_8939, data_8974, data_9607;
/* TSENS v1 targets */
-extern struct tsens_plat_data data_tsens_v1, data_8976;
+extern struct tsens_plat_data data_tsens_v1, data_8976, data_8956;
/* TSENS v2 targets */
extern struct tsens_plat_data data_8996, data_ipq8074, data_tsens_v2;
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 07/20] thermal/drivers/tsens: fix slope values for msm8939
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (5 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 06/20] thermal/drivers/tsens: Sort out msm8976 vs msm8956 data Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 12:05 ` Shawn Guo
2022-12-29 3:00 ` [PATCH v5 08/20] thermal/drivers/tsens: limit num_sensors to 9 " Dmitry Baryshkov
` (12 subsequent siblings)
19 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
According to the vendor kernels (msm-3.10, 3.14 and 3.18), msm8939
uses non-standard slope values for calibrating the sensors. Fill them
accordingly.
Fixes: 332bc8ebab2c ("thermal: qcom: tsens-v0_1: Add support for MSM8939")
Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: Shawn Guo <shawn.guo@linaro.org>
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 0bc4e5cec184..6645c98ff56c 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -534,6 +534,21 @@ static int calibrate_9607(struct tsens_priv *priv)
return 0;
}
+static int __init init_8939(struct tsens_priv *priv) {
+ priv->sensor[0].slope = 2911;
+ priv->sensor[1].slope = 2789;
+ priv->sensor[2].slope = 2906;
+ priv->sensor[3].slope = 2763;
+ priv->sensor[4].slope = 2922;
+ priv->sensor[5].slope = 2867;
+ priv->sensor[6].slope = 2833;
+ priv->sensor[7].slope = 2838;
+ priv->sensor[8].slope = 2840;
+ priv->sensor[9].slope = 2852;
+
+ return init_common(priv);
+}
+
/* v0.1: 8916, 8939, 8974, 9607 */
static struct tsens_features tsens_v0_1_feat = {
@@ -599,7 +614,7 @@ struct tsens_plat_data data_8916 = {
};
static const struct tsens_ops ops_8939 = {
- .init = init_common,
+ .init = init_8939,
.calibrate = calibrate_8939,
.get_temp = get_temp_common,
};
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 08/20] thermal/drivers/tsens: limit num_sensors to 9 for msm8939
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (6 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 07/20] thermal/drivers/tsens: fix slope values for msm8939 Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 12:22 ` Shawn Guo
2022-12-29 3:00 ` [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data Dmitry Baryshkov
` (11 subsequent siblings)
19 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
On msm8939 last (hwid=10) sensor was added in the hw revision 3.0.
Calibration data for it was placed outside of the main calibration data
blob, so it is not accessible by the current blob-parsing code.
Moreover data for the sensor's p2 is not contiguous in the fuses. This
makes it hard to use nvmem_cell API to parse calibration data in a
generic way.
Since the sensor doesn't seem to be actually used by the existing
hardware, disable the sensor for now.
Fixes: 332bc8ebab2c ("thermal: qcom: tsens-v0_1: Add support for MSM8939")
Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 6645c98ff56c..579028ea48f4 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -285,7 +285,7 @@ static int calibrate_8939(struct tsens_priv *priv)
u32 p1[10], p2[10];
int mode = 0;
u32 *qfprom_cdata;
- u32 cdata[6];
+ u32 cdata[4];
qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(qfprom_cdata))
@@ -296,8 +296,6 @@ static int calibrate_8939(struct tsens_priv *priv)
cdata[1] = qfprom_cdata[13];
cdata[2] = qfprom_cdata[0];
cdata[3] = qfprom_cdata[1];
- cdata[4] = qfprom_cdata[22];
- cdata[5] = qfprom_cdata[21];
mode = (cdata[0] & MSM8939_CAL_SEL_MASK) >> MSM8939_CAL_SEL_SHIFT;
dev_dbg(priv->dev, "calibration mode is %d\n", mode);
@@ -314,8 +312,6 @@ static int calibrate_8939(struct tsens_priv *priv)
p2[6] = (cdata[2] & MSM8939_S6_P2_MASK) >> MSM8939_S6_P2_SHIFT;
p2[7] = (cdata[3] & MSM8939_S7_P2_MASK) >> MSM8939_S7_P2_SHIFT;
p2[8] = (cdata[3] & MSM8939_S8_P2_MASK) >> MSM8939_S8_P2_SHIFT;
- p2[9] = (cdata[4] & MSM8939_S9_P2_MASK_0_4) >> MSM8939_S9_P2_SHIFT_0_4;
- p2[9] |= ((cdata[5] & MSM8939_S9_P2_MASK_5) >> MSM8939_S9_P2_SHIFT_5) << 5;
for (i = 0; i < priv->num_sensors; i++)
p2[i] = (base1 + p2[i]) << 2;
fallthrough;
@@ -331,7 +327,6 @@ static int calibrate_8939(struct tsens_priv *priv)
p1[6] = (cdata[2] & MSM8939_S6_P1_MASK) >> MSM8939_S6_P1_SHIFT;
p1[7] = (cdata[3] & MSM8939_S7_P1_MASK) >> MSM8939_S7_P1_SHIFT;
p1[8] = (cdata[3] & MSM8939_S8_P1_MASK) >> MSM8939_S8_P1_SHIFT;
- p1[9] = (cdata[4] & MSM8939_S9_P1_MASK) >> MSM8939_S9_P1_SHIFT;
for (i = 0; i < priv->num_sensors; i++)
p1[i] = ((base0) + p1[i]) << 2;
break;
@@ -544,7 +539,7 @@ static int __init init_8939(struct tsens_priv *priv) {
priv->sensor[6].slope = 2833;
priv->sensor[7].slope = 2838;
priv->sensor[8].slope = 2840;
- priv->sensor[9].slope = 2852;
+ /* priv->sensor[9].slope = 2852; */
return init_common(priv);
}
@@ -620,9 +615,9 @@ static const struct tsens_ops ops_8939 = {
};
struct tsens_plat_data data_8939 = {
- .num_sensors = 10,
+ .num_sensors = 9,
.ops = &ops_8939,
- .hw_ids = (unsigned int []){ 0, 1, 2, 3, 5, 6, 7, 8, 9, 10 },
+ .hw_ids = (unsigned int []){ 0, 1, 2, 3, 5, 6, 7, 8, 9, /* 10 */ },
.feat = &tsens_v0_1_feat,
.fields = tsens_v0_1_regfields,
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (7 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 08/20] thermal/drivers/tsens: limit num_sensors to 9 " Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 10:47 ` Konrad Dybcio
2022-12-29 3:00 ` [PATCH v5 10/20] thermal/drivers/tsens: Support using nvmem cells for msm8974 calibration Dmitry Baryshkov
` (10 subsequent siblings)
19 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
Add a unified function using nvmem cells for parsing the calibration
data rather than parsing the calibration blob manually.
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 15 ++++++
drivers/thermal/qcom/tsens-v1.c | 11 ++++-
drivers/thermal/qcom/tsens.c | 76 +++++++++++++++++++++++++++++++
drivers/thermal/qcom/tsens.h | 5 ++
4 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 579028ea48f4..6c9e491f9559 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -229,6 +229,11 @@ static int calibrate_8916(struct tsens_priv *priv)
u32 p1[5], p2[5];
int mode = 0;
u32 *qfprom_cdata, *qfprom_csel;
+ int ret;
+
+ ret = tsens_calibrate_nvmem(priv, 3);
+ if (!ret)
+ return 0;
qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(qfprom_cdata))
@@ -286,6 +291,11 @@ static int calibrate_8939(struct tsens_priv *priv)
int mode = 0;
u32 *qfprom_cdata;
u32 cdata[4];
+ int ret;
+
+ ret = tsens_calibrate_common(priv);
+ if (!ret)
+ return 0;
qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(qfprom_cdata))
@@ -486,6 +496,11 @@ static int calibrate_9607(struct tsens_priv *priv)
u32 p1[5], p2[5];
int mode = 0;
u32 *qfprom_cdata;
+ int ret;
+
+ ret = tsens_calibrate_common(priv);
+ if (!ret)
+ return 0;
qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(qfprom_cdata))
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 83c2853546d0..5bba75a845c5 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -143,7 +143,11 @@ static int calibrate_v1(struct tsens_priv *priv)
u32 p1[10], p2[10];
u32 mode = 0, lsb = 0, msb = 0;
u32 *qfprom_cdata;
- int i;
+ int i, ret;
+
+ ret = tsens_calibrate_common(priv);
+ if (!ret)
+ return 0;
qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(qfprom_cdata))
@@ -209,6 +213,11 @@ static int calibrate_8976(struct tsens_priv *priv)
u32 p1[11], p2[11];
int mode = 0, tmp = 0;
u32 *qfprom_cdata;
+ int ret;
+
+ ret = tsens_calibrate_common(priv);
+ if (!ret)
+ return 0;
qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(qfprom_cdata))
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index b191e19df93d..ce568a68de4a 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -70,6 +70,82 @@ char *qfprom_read(struct device *dev, const char *cname)
return ret;
}
+int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
+{
+ u32 mode;
+ u32 base1, base2;
+ u32 p1[MAX_SENSORS], p2[MAX_SENSORS];
+ char name[] = "sXX_pY"; /* s10_p1 */
+ int i, ret;
+
+ if (priv->num_sensors > MAX_SENSORS)
+ return -EINVAL;
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, "mode", &mode);
+ if (ret == -ENOENT)
+ dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
+ if (ret < 0)
+ return ret;
+
+ dev_dbg(priv->dev, "calibration mode is %d\n", mode);
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, "base1", &base1);
+ if (ret < 0)
+ return ret;
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, "base2", &base2);
+ if (ret < 0)
+ return ret;
+
+ for (i = 0; i < priv->num_sensors; i++) {
+ ret = snprintf(name, sizeof(name), "s%d_p1", priv->sensor[i].hw_id);
+ if (ret < 0)
+ return ret;
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p1[i]);
+ if (ret)
+ return ret;
+
+ ret = snprintf(name, sizeof(name), "s%d_p2", priv->sensor[i].hw_id);
+ if (ret < 0)
+ return ret;
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p2[i]);
+ if (ret)
+ return ret;
+ }
+
+ switch (mode) {
+ case ONE_PT_CALIB:
+ for (i = 0; i < priv->num_sensors; i++)
+ p1[i] = p1[i] + (base1 << shift);
+ break;
+ case TWO_PT_CALIB:
+ for (i = 0; i < priv->num_sensors; i++)
+ p2[i] = (p2[i] + base2) << shift;
+ fallthrough;
+ case ONE_PT_CALIB2:
+ for (i = 0; i < priv->num_sensors; i++)
+ p1[i] = (p1[i] + base1) << shift;
+ break;
+ default:
+ dev_dbg(priv->dev, "calibrationless mode\n");
+ for (i = 0; i < priv->num_sensors; i++) {
+ p1[i] = 500;
+ p2[i] = 780;
+ }
+ }
+
+ compute_intercept_slope(priv, p1, p2, mode);
+
+ return 0;
+}
+
+int tsens_calibrate_common(struct tsens_priv *priv)
+{
+ return tsens_calibrate_nvmem(priv, 2);
+}
+
/*
* Use this function on devices where slope and offset calculations
* depend on calibration data read from qfprom. On others the slope
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index 7dd5fc246894..645ae02438fa 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -6,6 +6,7 @@
#ifndef __QCOM_TSENS_H__
#define __QCOM_TSENS_H__
+#define NO_PT_CALIB 0x0
#define ONE_PT_CALIB 0x1
#define ONE_PT_CALIB2 0x2
#define TWO_PT_CALIB 0x3
@@ -17,6 +18,8 @@
#define THRESHOLD_MAX_ADC_CODE 0x3ff
#define THRESHOLD_MIN_ADC_CODE 0x0
+#define MAX_SENSORS 16
+
#include <linux/interrupt.h>
#include <linux/thermal.h>
#include <linux/regmap.h>
@@ -582,6 +585,8 @@ struct tsens_priv {
};
char *qfprom_read(struct device *dev, const char *cname);
+int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
+int tsens_calibrate_common(struct tsens_priv *priv);
void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
int init_common(struct tsens_priv *priv);
int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 10/20] thermal/drivers/tsens: Support using nvmem cells for msm8974 calibration
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (8 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 11/20] thermal/drivers/tsens: Rework legacy calibration data parsers Dmitry Baryshkov
` (9 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
MSM8974 has two sets of calibration data: main one and backup. Add
support for parsing both sets of calibration data from nvmem cells.
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 50 +++++++++++++++++++++++++++++++
drivers/thermal/qcom/tsens.c | 41 ++++++++++++++++++++-----
drivers/thermal/qcom/tsens.h | 1 +
3 files changed, 84 insertions(+), 8 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 6c9e491f9559..3c08ad640940 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -3,6 +3,7 @@
* Copyright (c) 2015, The Linux Foundation. All rights reserved.
*/
+#include <linux/nvmem-consumer.h>
#include <linux/platform_device.h>
#include "tsens.h"
@@ -354,6 +355,50 @@ static int calibrate_8939(struct tsens_priv *priv)
return 0;
}
+static int calibrate_8974_nvmem(struct tsens_priv *priv)
+{
+ int i, ret, mode;
+ u32 p1[11], p2[11];
+ u32 backup;
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, "use_backup", &backup);
+ if (ret == -ENOENT)
+ dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
+ if (ret < 0)
+ return ret;
+
+ mode = tsens_read_calibration(priv, 2, p1, p2, backup == BKP_SEL);
+ if (mode < 0)
+ return mode;
+
+ if (mode == NO_PT_CALIB) {
+ p1[0] += 2;
+ p1[1] += 9;
+ p1[2] += 3;
+ p1[3] += 9;
+ p1[4] += 5;
+ p1[5] += 9;
+ p1[6] += 7;
+ p1[7] += 10;
+ p1[8] += 8;
+ p1[9] += 9;
+ p1[10] += 8;
+ } else {
+ for (i = 0; i < priv->num_sensors; i++) {
+ /*
+ * ONE_PT_CALIB requires using addition here instead of
+ * using OR operation.
+ */
+ p1[i] += BIT_APPEND;
+ p2[i] += BIT_APPEND;
+ }
+ }
+
+ compute_intercept_slope(priv, p1, p2, mode);
+
+ return 0;
+}
+
static int calibrate_8974(struct tsens_priv *priv)
{
int base1 = 0, base2 = 0, i;
@@ -361,6 +406,11 @@ static int calibrate_8974(struct tsens_priv *priv)
int mode = 0;
u32 *calib, *bkp;
u32 calib_redun_sel;
+ int ret;
+
+ ret = calibrate_8974_nvmem(priv);
+ if (ret == 0)
+ return 0;
calib = (u32 *)qfprom_read(priv->dev, "calib");
if (IS_ERR(calib))
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index ce568a68de4a..6facdb0246a5 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -70,18 +70,21 @@ char *qfprom_read(struct device *dev, const char *cname)
return ret;
}
-int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
+int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, bool backup)
{
u32 mode;
u32 base1, base2;
- u32 p1[MAX_SENSORS], p2[MAX_SENSORS];
- char name[] = "sXX_pY"; /* s10_p1 */
+ char name[] = "sXX_pY_backup"; /* s10_p1_backup */
int i, ret;
if (priv->num_sensors > MAX_SENSORS)
return -EINVAL;
- ret = nvmem_cell_read_variable_le_u32(priv->dev, "mode", &mode);
+ ret = snprintf(name, sizeof(name), "mode%s", backup ? "_backup" : "");
+ if (ret < 0)
+ return ret;
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &mode);
if (ret == -ENOENT)
dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
if (ret < 0)
@@ -89,16 +92,25 @@ int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
dev_dbg(priv->dev, "calibration mode is %d\n", mode);
- ret = nvmem_cell_read_variable_le_u32(priv->dev, "base1", &base1);
+ ret = snprintf(name, sizeof(name), "base1%s", backup ? "_backup" : "");
+ if (ret < 0)
+ return ret;
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &base1);
+ if (ret < 0)
+ return ret;
+
+ ret = snprintf(name, sizeof(name), "base2%s", backup ? "_backup" : "");
if (ret < 0)
return ret;
- ret = nvmem_cell_read_variable_le_u32(priv->dev, "base2", &base2);
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &base2);
if (ret < 0)
return ret;
for (i = 0; i < priv->num_sensors; i++) {
- ret = snprintf(name, sizeof(name), "s%d_p1", priv->sensor[i].hw_id);
+ ret = snprintf(name, sizeof(name), "s%d_p1%s", priv->sensor[i].hw_id,
+ backup ? "_backup" : "");
if (ret < 0)
return ret;
@@ -106,7 +118,8 @@ int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
if (ret)
return ret;
- ret = snprintf(name, sizeof(name), "s%d_p2", priv->sensor[i].hw_id);
+ ret = snprintf(name, sizeof(name), "s%d_p2%s", priv->sensor[i].hw_id,
+ backup ? "_backup" : "");
if (ret < 0)
return ret;
@@ -136,6 +149,18 @@ int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
}
}
+ return mode;
+}
+
+int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
+{
+ u32 p1[MAX_SENSORS], p2[MAX_SENSORS];
+ int mode;
+
+ mode = tsens_read_calibration(priv, shift, p1, p2, false);
+ if (mode < 0)
+ return mode;
+
compute_intercept_slope(priv, p1, p2, mode);
return 0;
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index 645ae02438fa..a9ae8df9f810 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -585,6 +585,7 @@ struct tsens_priv {
};
char *qfprom_read(struct device *dev, const char *cname);
+int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, bool backup);
int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
int tsens_calibrate_common(struct tsens_priv *priv);
void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 11/20] thermal/drivers/tsens: Rework legacy calibration data parsers
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (9 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 10/20] thermal/drivers/tsens: Support using nvmem cells for msm8974 calibration Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 12/20] thermal/drivers/tsens: Drop single-cell code for mdm9607 Dmitry Baryshkov
` (8 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree, kernel test robot
Rework existing calibration parsing code to use simple data structure
describing data layout. This allows us to drop all the mask & shift
values, replacing them with data tables.
The code for msm8974 is not reworked, as it has separate calibration and
backup data.
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 591 ++++++++----------------------
drivers/thermal/qcom/tsens-v1.c | 266 +++-----------
drivers/thermal/qcom/tsens.c | 64 ++++
drivers/thermal/qcom/tsens.h | 38 ++
4 files changed, 297 insertions(+), 662 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 3c08ad640940..f8b50bf14190 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -3,6 +3,7 @@
* Copyright (c) 2015, The Linux Foundation. All rights reserved.
*/
+#include <linux/bitfield.h>
#include <linux/nvmem-consumer.h>
#include <linux/platform_device.h>
#include "tsens.h"
@@ -16,221 +17,113 @@
#define TM_Sn_STATUS_OFF 0x0030
#define TM_TRDY_OFF 0x005c
-/* eeprom layout data for 8916 */
-#define MSM8916_BASE0_MASK 0x0000007f
-#define MSM8916_BASE1_MASK 0xfe000000
-#define MSM8916_BASE0_SHIFT 0
-#define MSM8916_BASE1_SHIFT 25
-
-#define MSM8916_S0_P1_MASK 0x00000f80
-#define MSM8916_S1_P1_MASK 0x003e0000
-#define MSM8916_S2_P1_MASK 0xf8000000
-#define MSM8916_S3_P1_MASK 0x000003e0
-#define MSM8916_S4_P1_MASK 0x000f8000
-
-#define MSM8916_S0_P2_MASK 0x0001f000
-#define MSM8916_S1_P2_MASK 0x07c00000
-#define MSM8916_S2_P2_MASK 0x0000001f
-#define MSM8916_S3_P2_MASK 0x00007c00
-#define MSM8916_S4_P2_MASK 0x01f00000
-
-#define MSM8916_S0_P1_SHIFT 7
-#define MSM8916_S1_P1_SHIFT 17
-#define MSM8916_S2_P1_SHIFT 27
-#define MSM8916_S3_P1_SHIFT 5
-#define MSM8916_S4_P1_SHIFT 15
-
-#define MSM8916_S0_P2_SHIFT 12
-#define MSM8916_S1_P2_SHIFT 22
-#define MSM8916_S2_P2_SHIFT 0
-#define MSM8916_S3_P2_SHIFT 10
-#define MSM8916_S4_P2_SHIFT 20
-
-#define MSM8916_CAL_SEL_MASK 0xe0000000
-#define MSM8916_CAL_SEL_SHIFT 29
-
-/* eeprom layout data for 8939 */
-#define MSM8939_BASE0_MASK 0x000000ff
-#define MSM8939_BASE1_MASK 0xff000000
-#define MSM8939_BASE0_SHIFT 0
-#define MSM8939_BASE1_SHIFT 24
-
-#define MSM8939_S0_P1_MASK 0x000001f8
-#define MSM8939_S1_P1_MASK 0x001f8000
-#define MSM8939_S2_P1_MASK_0_4 0xf8000000
-#define MSM8939_S2_P1_MASK_5 0x00000001
-#define MSM8939_S3_P1_MASK 0x00001f80
-#define MSM8939_S4_P1_MASK 0x01f80000
-#define MSM8939_S5_P1_MASK 0x00003f00
-#define MSM8939_S6_P1_MASK 0x03f00000
-#define MSM8939_S7_P1_MASK 0x0000003f
-#define MSM8939_S8_P1_MASK 0x0003f000
-#define MSM8939_S9_P1_MASK 0x07e00000
-
-#define MSM8939_S0_P2_MASK 0x00007e00
-#define MSM8939_S1_P2_MASK 0x07e00000
-#define MSM8939_S2_P2_MASK 0x0000007e
-#define MSM8939_S3_P2_MASK 0x0007e000
-#define MSM8939_S4_P2_MASK 0x7e000000
-#define MSM8939_S5_P2_MASK 0x000fc000
-#define MSM8939_S6_P2_MASK 0xfc000000
-#define MSM8939_S7_P2_MASK 0x00000fc0
-#define MSM8939_S8_P2_MASK 0x00fc0000
-#define MSM8939_S9_P2_MASK_0_4 0xf8000000
-#define MSM8939_S9_P2_MASK_5 0x00002000
-
-#define MSM8939_S0_P1_SHIFT 3
-#define MSM8939_S1_P1_SHIFT 15
-#define MSM8939_S2_P1_SHIFT_0_4 27
-#define MSM8939_S2_P1_SHIFT_5 0
-#define MSM8939_S3_P1_SHIFT 7
-#define MSM8939_S4_P1_SHIFT 19
-#define MSM8939_S5_P1_SHIFT 8
-#define MSM8939_S6_P1_SHIFT 20
-#define MSM8939_S7_P1_SHIFT 0
-#define MSM8939_S8_P1_SHIFT 12
-#define MSM8939_S9_P1_SHIFT 21
-
-#define MSM8939_S0_P2_SHIFT 9
-#define MSM8939_S1_P2_SHIFT 21
-#define MSM8939_S2_P2_SHIFT 1
-#define MSM8939_S3_P2_SHIFT 13
-#define MSM8939_S4_P2_SHIFT 25
-#define MSM8939_S5_P2_SHIFT 14
-#define MSM8939_S6_P2_SHIFT 26
-#define MSM8939_S7_P2_SHIFT 6
-#define MSM8939_S8_P2_SHIFT 18
-#define MSM8939_S9_P2_SHIFT_0_4 27
-#define MSM8939_S9_P2_SHIFT_5 13
-
-#define MSM8939_CAL_SEL_MASK 0x7
-#define MSM8939_CAL_SEL_SHIFT 0
-
-/* eeprom layout data for 8974 */
-#define BASE1_MASK 0xff
-#define S0_P1_MASK 0x3f00
-#define S1_P1_MASK 0xfc000
-#define S2_P1_MASK 0x3f00000
-#define S3_P1_MASK 0xfc000000
-#define S4_P1_MASK 0x3f
-#define S5_P1_MASK 0xfc0
-#define S6_P1_MASK 0x3f000
-#define S7_P1_MASK 0xfc0000
-#define S8_P1_MASK 0x3f000000
-#define S8_P1_MASK_BKP 0x3f
-#define S9_P1_MASK 0x3f
-#define S9_P1_MASK_BKP 0xfc0
-#define S10_P1_MASK 0xfc0
-#define S10_P1_MASK_BKP 0x3f000
-#define CAL_SEL_0_1 0xc0000000
-#define CAL_SEL_2 0x40000000
-#define CAL_SEL_SHIFT 30
-#define CAL_SEL_SHIFT_2 28
-
-#define S0_P1_SHIFT 8
-#define S1_P1_SHIFT 14
-#define S2_P1_SHIFT 20
-#define S3_P1_SHIFT 26
-#define S5_P1_SHIFT 6
-#define S6_P1_SHIFT 12
-#define S7_P1_SHIFT 18
-#define S8_P1_SHIFT 24
-#define S9_P1_BKP_SHIFT 6
-#define S10_P1_SHIFT 6
-#define S10_P1_BKP_SHIFT 12
-
-#define BASE2_SHIFT 12
-#define BASE2_BKP_SHIFT 18
-#define S0_P2_SHIFT 20
-#define S0_P2_BKP_SHIFT 26
-#define S1_P2_SHIFT 26
-#define S2_P2_BKP_SHIFT 6
-#define S3_P2_SHIFT 6
-#define S3_P2_BKP_SHIFT 12
-#define S4_P2_SHIFT 12
-#define S4_P2_BKP_SHIFT 18
-#define S5_P2_SHIFT 18
-#define S5_P2_BKP_SHIFT 24
-#define S6_P2_SHIFT 24
-#define S7_P2_BKP_SHIFT 6
-#define S8_P2_SHIFT 6
-#define S8_P2_BKP_SHIFT 12
-#define S9_P2_SHIFT 12
-#define S9_P2_BKP_SHIFT 18
-#define S10_P2_SHIFT 18
-#define S10_P2_BKP_SHIFT 24
-
-#define BASE2_MASK 0xff000
-#define BASE2_BKP_MASK 0xfc0000
-#define S0_P2_MASK 0x3f00000
-#define S0_P2_BKP_MASK 0xfc000000
-#define S1_P2_MASK 0xfc000000
-#define S1_P2_BKP_MASK 0x3f
-#define S2_P2_MASK 0x3f
-#define S2_P2_BKP_MASK 0xfc0
-#define S3_P2_MASK 0xfc0
-#define S3_P2_BKP_MASK 0x3f000
-#define S4_P2_MASK 0x3f000
-#define S4_P2_BKP_MASK 0xfc0000
-#define S5_P2_MASK 0xfc0000
-#define S5_P2_BKP_MASK 0x3f000000
-#define S6_P2_MASK 0x3f000000
-#define S6_P2_BKP_MASK 0x3f
-#define S7_P2_MASK 0x3f
-#define S7_P2_BKP_MASK 0xfc0
-#define S8_P2_MASK 0xfc0
-#define S8_P2_BKP_MASK 0x3f000
-#define S9_P2_MASK 0x3f000
-#define S9_P2_BKP_MASK 0xfc0000
-#define S10_P2_MASK 0xfc0000
-#define S10_P2_BKP_MASK 0x3f000000
-
+/* extra data for 8974 */
#define BKP_SEL 0x3
#define BKP_REDUN_SEL 0xe0000000
-#define BKP_REDUN_SHIFT 29
#define BIT_APPEND 0x3
-/* eeprom layout data for mdm9607 */
-#define MDM9607_BASE0_MASK 0x000000ff
-#define MDM9607_BASE1_MASK 0x000ff000
-#define MDM9607_BASE0_SHIFT 0
-#define MDM9607_BASE1_SHIFT 12
-
-#define MDM9607_S0_P1_MASK 0x00003f00
-#define MDM9607_S1_P1_MASK 0x03f00000
-#define MDM9607_S2_P1_MASK 0x0000003f
-#define MDM9607_S3_P1_MASK 0x0003f000
-#define MDM9607_S4_P1_MASK 0x0000003f
-
-#define MDM9607_S0_P2_MASK 0x000fc000
-#define MDM9607_S1_P2_MASK 0xfc000000
-#define MDM9607_S2_P2_MASK 0x00000fc0
-#define MDM9607_S3_P2_MASK 0x00fc0000
-#define MDM9607_S4_P2_MASK 0x00000fc0
-
-#define MDM9607_S0_P1_SHIFT 8
-#define MDM9607_S1_P1_SHIFT 20
-#define MDM9607_S2_P1_SHIFT 0
-#define MDM9607_S3_P1_SHIFT 12
-#define MDM9607_S4_P1_SHIFT 0
-
-#define MDM9607_S0_P2_SHIFT 14
-#define MDM9607_S1_P2_SHIFT 26
-#define MDM9607_S2_P2_SHIFT 6
-#define MDM9607_S3_P2_SHIFT 18
-#define MDM9607_S4_P2_SHIFT 6
-
-#define MDM9607_CAL_SEL_MASK 0x00700000
-#define MDM9607_CAL_SEL_SHIFT 20
+struct tsens_legacy_calibration_format tsens_8916_nvmem = {
+ .base_len = 7,
+ .base_shift = 3,
+ .sp_len = 5,
+ .mode = { 0, 29, 1 },
+ .invalid = { 0, 31, 1 },
+ .base = { { 0, 0 }, { 1, 25 } },
+ .sp = {
+ { { 0, 7 }, { 0, 12 } },
+ { { 0, 17 }, { 0, 22 } },
+ { { 0, 27 }, { 1, 0 } },
+ { { 1, 5 }, { 1, 10 } },
+ { { 1, 15 }, { 1, 20 } },
+ },
+};
+
+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,
+ .sp_len = 6,
+ .mode = { 1, 30 },
+ .invalid = { 3, 30 },
+ .base = { { 0, 0 }, { 2, 12 } },
+ .sp = {
+ { { 0, 8 }, { 2, 20 } },
+ { { 0, 14 }, { 2, 26 } },
+ { { 0, 20 }, { 3, 0 } },
+ { { 0, 26 }, { 3, 6 } },
+ { { 1, 0 }, { 3, 12 } },
+ { { 1, 6 }, { 3, 18 } },
+ { { 1, 12 }, { 3, 24 } },
+ { { 1, 18 }, { 4, 0 } },
+ { { 1, 24 }, { 4, 6 } },
+ { { 2, 0 }, { 4, 12 } },
+ { { 2, 6 }, { 4, 18 } },
+ },
+};
+
+struct tsens_legacy_calibration_format tsens_8974_backup_nvmem = {
+ .base_len = 8,
+ .base_shift = 2,
+ .sp_len = 6,
+ .mode = { 4, 30, 1 },
+ .invalid = { 5, 30, 1 },
+ .base = { { 0, 0 }, { 2, 18 } },
+ .sp = {
+ { { 0, 8 }, { 2, 26 } },
+ { { 0, 14 }, { 3, 0 } },
+ { { 0, 20 }, { 3, 6 } },
+ { { 0, 26 }, { 3, 12 } },
+ { { 1, 0 }, { 3, 18 } },
+ { { 1, 6 }, { 3, 24, 1 } },
+ { { 1, 12 }, { 4, 0, 1 } },
+ { { 1, 18 }, { 4, 6, 1 } },
+ { { 2, 0 }, { 4, 12, 1 } },
+ { { 2, 6 }, { 4, 18, 1 } },
+ { { 2, 12 }, { 4, 24, 1 } },
+ },
+};
+
+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)
{
- int base0 = 0, base1 = 0, i;
u32 p1[5], p2[5];
- int mode = 0;
u32 *qfprom_cdata, *qfprom_csel;
- int ret;
+ int mode, ret;
ret = tsens_calibrate_nvmem(priv, 3);
if (!ret)
@@ -246,37 +139,9 @@ static int calibrate_8916(struct tsens_priv *priv)
return PTR_ERR(qfprom_csel);
}
- mode = (qfprom_csel[0] & MSM8916_CAL_SEL_MASK) >> MSM8916_CAL_SEL_SHIFT;
- dev_dbg(priv->dev, "calibration mode is %d\n", mode);
-
- switch (mode) {
- case TWO_PT_CALIB:
- base1 = (qfprom_cdata[1] & MSM8916_BASE1_MASK) >> MSM8916_BASE1_SHIFT;
- p2[0] = (qfprom_cdata[0] & MSM8916_S0_P2_MASK) >> MSM8916_S0_P2_SHIFT;
- p2[1] = (qfprom_cdata[0] & MSM8916_S1_P2_MASK) >> MSM8916_S1_P2_SHIFT;
- p2[2] = (qfprom_cdata[1] & MSM8916_S2_P2_MASK) >> MSM8916_S2_P2_SHIFT;
- p2[3] = (qfprom_cdata[1] & MSM8916_S3_P2_MASK) >> MSM8916_S3_P2_SHIFT;
- p2[4] = (qfprom_cdata[1] & MSM8916_S4_P2_MASK) >> MSM8916_S4_P2_SHIFT;
- for (i = 0; i < priv->num_sensors; i++)
- p2[i] = ((base1 + p2[i]) << 3);
- fallthrough;
- case ONE_PT_CALIB2:
- base0 = (qfprom_cdata[0] & MSM8916_BASE0_MASK);
- p1[0] = (qfprom_cdata[0] & MSM8916_S0_P1_MASK) >> MSM8916_S0_P1_SHIFT;
- p1[1] = (qfprom_cdata[0] & MSM8916_S1_P1_MASK) >> MSM8916_S1_P1_SHIFT;
- p1[2] = (qfprom_cdata[0] & MSM8916_S2_P1_MASK) >> MSM8916_S2_P1_SHIFT;
- p1[3] = (qfprom_cdata[1] & MSM8916_S3_P1_MASK) >> MSM8916_S3_P1_SHIFT;
- p1[4] = (qfprom_cdata[1] & MSM8916_S4_P1_MASK) >> MSM8916_S4_P1_SHIFT;
- for (i = 0; i < priv->num_sensors; i++)
- p1[i] = (((base0) + p1[i]) << 3);
- break;
- default:
- for (i = 0; i < priv->num_sensors; i++) {
- p1[i] = 500;
- p2[i] = 780;
- }
- break;
- }
+ mode = tsens_read_calibration_legacy(priv, &tsens_8916_nvmem,
+ p1, p2,
+ qfprom_cdata, qfprom_csel);
compute_intercept_slope(priv, p1, p2, mode);
kfree(qfprom_cdata);
@@ -287,12 +152,9 @@ static int calibrate_8916(struct tsens_priv *priv)
static int calibrate_8939(struct tsens_priv *priv)
{
- int base0 = 0, base1 = 0, i;
u32 p1[10], p2[10];
- int mode = 0;
u32 *qfprom_cdata;
- u32 cdata[4];
- int ret;
+ int mode, ret;
ret = tsens_calibrate_common(priv);
if (!ret)
@@ -302,52 +164,9 @@ static int calibrate_8939(struct tsens_priv *priv)
if (IS_ERR(qfprom_cdata))
return PTR_ERR(qfprom_cdata);
- /* Mapping between qfprom nvmem and calibration data */
- cdata[0] = qfprom_cdata[12];
- cdata[1] = qfprom_cdata[13];
- cdata[2] = qfprom_cdata[0];
- cdata[3] = qfprom_cdata[1];
-
- mode = (cdata[0] & MSM8939_CAL_SEL_MASK) >> MSM8939_CAL_SEL_SHIFT;
- dev_dbg(priv->dev, "calibration mode is %d\n", mode);
-
- switch (mode) {
- case TWO_PT_CALIB:
- base1 = (cdata[3] & MSM8939_BASE1_MASK) >> MSM8939_BASE1_SHIFT;
- p2[0] = (cdata[0] & MSM8939_S0_P2_MASK) >> MSM8939_S0_P2_SHIFT;
- p2[1] = (cdata[0] & MSM8939_S1_P2_MASK) >> MSM8939_S1_P2_SHIFT;
- p2[2] = (cdata[1] & MSM8939_S2_P2_MASK) >> MSM8939_S2_P2_SHIFT;
- p2[3] = (cdata[1] & MSM8939_S3_P2_MASK) >> MSM8939_S3_P2_SHIFT;
- p2[4] = (cdata[1] & MSM8939_S4_P2_MASK) >> MSM8939_S4_P2_SHIFT;
- p2[5] = (cdata[2] & MSM8939_S5_P2_MASK) >> MSM8939_S5_P2_SHIFT;
- p2[6] = (cdata[2] & MSM8939_S6_P2_MASK) >> MSM8939_S6_P2_SHIFT;
- p2[7] = (cdata[3] & MSM8939_S7_P2_MASK) >> MSM8939_S7_P2_SHIFT;
- p2[8] = (cdata[3] & MSM8939_S8_P2_MASK) >> MSM8939_S8_P2_SHIFT;
- for (i = 0; i < priv->num_sensors; i++)
- p2[i] = (base1 + p2[i]) << 2;
- fallthrough;
- case ONE_PT_CALIB2:
- base0 = (cdata[2] & MSM8939_BASE0_MASK) >> MSM8939_BASE0_SHIFT;
- p1[0] = (cdata[0] & MSM8939_S0_P1_MASK) >> MSM8939_S0_P1_SHIFT;
- p1[1] = (cdata[0] & MSM8939_S1_P1_MASK) >> MSM8939_S1_P1_SHIFT;
- p1[2] = (cdata[0] & MSM8939_S2_P1_MASK_0_4) >> MSM8939_S2_P1_SHIFT_0_4;
- p1[2] |= ((cdata[1] & MSM8939_S2_P1_MASK_5) >> MSM8939_S2_P1_SHIFT_5) << 5;
- p1[3] = (cdata[1] & MSM8939_S3_P1_MASK) >> MSM8939_S3_P1_SHIFT;
- p1[4] = (cdata[1] & MSM8939_S4_P1_MASK) >> MSM8939_S4_P1_SHIFT;
- p1[5] = (cdata[2] & MSM8939_S5_P1_MASK) >> MSM8939_S5_P1_SHIFT;
- p1[6] = (cdata[2] & MSM8939_S6_P1_MASK) >> MSM8939_S6_P1_SHIFT;
- p1[7] = (cdata[3] & MSM8939_S7_P1_MASK) >> MSM8939_S7_P1_SHIFT;
- p1[8] = (cdata[3] & MSM8939_S8_P1_MASK) >> MSM8939_S8_P1_SHIFT;
- for (i = 0; i < priv->num_sensors; i++)
- p1[i] = ((base0) + p1[i]) << 2;
- break;
- default:
- for (i = 0; i < priv->num_sensors; i++) {
- p1[i] = 500;
- p2[i] = 780;
- }
- break;
- }
+ mode = tsens_read_calibration_legacy(priv, &tsens_8939_nvmem,
+ p1, p2,
+ qfprom_cdata, NULL);
compute_intercept_slope(priv, p1, p2, mode);
kfree(qfprom_cdata);
@@ -355,21 +174,9 @@ static int calibrate_8939(struct tsens_priv *priv)
return 0;
}
-static int calibrate_8974_nvmem(struct tsens_priv *priv)
+static void fixup_8974_points(int mode, u32 *p1, u32 *p2)
{
- int i, ret, mode;
- u32 p1[11], p2[11];
- u32 backup;
-
- ret = nvmem_cell_read_variable_le_u32(priv->dev, "use_backup", &backup);
- if (ret == -ENOENT)
- dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
- if (ret < 0)
- return ret;
-
- mode = tsens_read_calibration(priv, 2, p1, p2, backup == BKP_SEL);
- if (mode < 0)
- return mode;
+ int i;
if (mode == NO_PT_CALIB) {
p1[0] += 2;
@@ -384,7 +191,7 @@ static int calibrate_8974_nvmem(struct tsens_priv *priv)
p1[9] += 9;
p1[10] += 8;
} else {
- for (i = 0; i < priv->num_sensors; i++) {
+ for (i = 0; i < 11; i++) {
/*
* ONE_PT_CALIB requires using addition here instead of
* using OR operation.
@@ -394,6 +201,26 @@ static int calibrate_8974_nvmem(struct tsens_priv *priv)
}
}
+}
+
+static int calibrate_8974_nvmem(struct tsens_priv *priv)
+{
+ u32 p1[11], p2[11];
+ u32 backup;
+ int ret, mode;
+
+ ret = nvmem_cell_read_variable_le_u32(priv->dev, "use_backup", &backup);
+ if (ret == -ENOENT)
+ dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
+ if (ret < 0)
+ return ret;
+
+ mode = tsens_read_calibration(priv, 2, p1, p2, backup == BKP_SEL);
+ if (mode < 0)
+ return mode;
+
+ fixup_8974_points(mode, p1, p2);
+
compute_intercept_slope(priv, p1, p2, mode);
return 0;
@@ -401,12 +228,10 @@ static int calibrate_8974_nvmem(struct tsens_priv *priv)
static int calibrate_8974(struct tsens_priv *priv)
{
- int base1 = 0, base2 = 0, i;
u32 p1[11], p2[11];
- int mode = 0;
u32 *calib, *bkp;
u32 calib_redun_sel;
- int ret;
+ int mode, ret;
ret = calibrate_8974_nvmem(priv);
if (ret == 0)
@@ -422,116 +247,18 @@ static int calibrate_8974(struct tsens_priv *priv)
return PTR_ERR(bkp);
}
- calib_redun_sel = bkp[1] & BKP_REDUN_SEL;
- calib_redun_sel >>= BKP_REDUN_SHIFT;
-
- if (calib_redun_sel == BKP_SEL) {
- mode = (calib[4] & CAL_SEL_0_1) >> CAL_SEL_SHIFT;
- mode |= (calib[5] & CAL_SEL_2) >> CAL_SEL_SHIFT_2;
-
- switch (mode) {
- case TWO_PT_CALIB:
- base2 = (bkp[2] & BASE2_BKP_MASK) >> BASE2_BKP_SHIFT;
- p2[0] = (bkp[2] & S0_P2_BKP_MASK) >> S0_P2_BKP_SHIFT;
- p2[1] = (bkp[3] & S1_P2_BKP_MASK);
- p2[2] = (bkp[3] & S2_P2_BKP_MASK) >> S2_P2_BKP_SHIFT;
- p2[3] = (bkp[3] & S3_P2_BKP_MASK) >> S3_P2_BKP_SHIFT;
- p2[4] = (bkp[3] & S4_P2_BKP_MASK) >> S4_P2_BKP_SHIFT;
- p2[5] = (calib[4] & S5_P2_BKP_MASK) >> S5_P2_BKP_SHIFT;
- p2[6] = (calib[5] & S6_P2_BKP_MASK);
- p2[7] = (calib[5] & S7_P2_BKP_MASK) >> S7_P2_BKP_SHIFT;
- p2[8] = (calib[5] & S8_P2_BKP_MASK) >> S8_P2_BKP_SHIFT;
- p2[9] = (calib[5] & S9_P2_BKP_MASK) >> S9_P2_BKP_SHIFT;
- p2[10] = (calib[5] & S10_P2_BKP_MASK) >> S10_P2_BKP_SHIFT;
- fallthrough;
- case ONE_PT_CALIB:
- case ONE_PT_CALIB2:
- base1 = bkp[0] & BASE1_MASK;
- p1[0] = (bkp[0] & S0_P1_MASK) >> S0_P1_SHIFT;
- p1[1] = (bkp[0] & S1_P1_MASK) >> S1_P1_SHIFT;
- p1[2] = (bkp[0] & S2_P1_MASK) >> S2_P1_SHIFT;
- p1[3] = (bkp[0] & S3_P1_MASK) >> S3_P1_SHIFT;
- p1[4] = (bkp[1] & S4_P1_MASK);
- p1[5] = (bkp[1] & S5_P1_MASK) >> S5_P1_SHIFT;
- p1[6] = (bkp[1] & S6_P1_MASK) >> S6_P1_SHIFT;
- p1[7] = (bkp[1] & S7_P1_MASK) >> S7_P1_SHIFT;
- p1[8] = (bkp[2] & S8_P1_MASK_BKP) >> S8_P1_SHIFT;
- p1[9] = (bkp[2] & S9_P1_MASK_BKP) >> S9_P1_BKP_SHIFT;
- p1[10] = (bkp[2] & S10_P1_MASK_BKP) >> S10_P1_BKP_SHIFT;
- break;
- }
- } else {
- mode = (calib[1] & CAL_SEL_0_1) >> CAL_SEL_SHIFT;
- mode |= (calib[3] & CAL_SEL_2) >> CAL_SEL_SHIFT_2;
-
- switch (mode) {
- case TWO_PT_CALIB:
- base2 = (calib[2] & BASE2_MASK) >> BASE2_SHIFT;
- p2[0] = (calib[2] & S0_P2_MASK) >> S0_P2_SHIFT;
- p2[1] = (calib[2] & S1_P2_MASK) >> S1_P2_SHIFT;
- p2[2] = (calib[3] & S2_P2_MASK);
- p2[3] = (calib[3] & S3_P2_MASK) >> S3_P2_SHIFT;
- p2[4] = (calib[3] & S4_P2_MASK) >> S4_P2_SHIFT;
- p2[5] = (calib[3] & S5_P2_MASK) >> S5_P2_SHIFT;
- p2[6] = (calib[3] & S6_P2_MASK) >> S6_P2_SHIFT;
- p2[7] = (calib[4] & S7_P2_MASK);
- p2[8] = (calib[4] & S8_P2_MASK) >> S8_P2_SHIFT;
- p2[9] = (calib[4] & S9_P2_MASK) >> S9_P2_SHIFT;
- p2[10] = (calib[4] & S10_P2_MASK) >> S10_P2_SHIFT;
- fallthrough;
- case ONE_PT_CALIB:
- case ONE_PT_CALIB2:
- base1 = calib[0] & BASE1_MASK;
- p1[0] = (calib[0] & S0_P1_MASK) >> S0_P1_SHIFT;
- p1[1] = (calib[0] & S1_P1_MASK) >> S1_P1_SHIFT;
- p1[2] = (calib[0] & S2_P1_MASK) >> S2_P1_SHIFT;
- p1[3] = (calib[0] & S3_P1_MASK) >> S3_P1_SHIFT;
- p1[4] = (calib[1] & S4_P1_MASK);
- p1[5] = (calib[1] & S5_P1_MASK) >> S5_P1_SHIFT;
- p1[6] = (calib[1] & S6_P1_MASK) >> S6_P1_SHIFT;
- p1[7] = (calib[1] & S7_P1_MASK) >> S7_P1_SHIFT;
- p1[8] = (calib[1] & S8_P1_MASK) >> S8_P1_SHIFT;
- p1[9] = (calib[2] & S9_P1_MASK);
- p1[10] = (calib[2] & S10_P1_MASK) >> S10_P1_SHIFT;
- break;
- }
- }
+ calib_redun_sel = FIELD_GET(BKP_REDUN_SEL, bkp[1]);
- switch (mode) {
- case ONE_PT_CALIB:
- for (i = 0; i < priv->num_sensors; i++)
- p1[i] += (base1 << 2) | BIT_APPEND;
- break;
- case TWO_PT_CALIB:
- for (i = 0; i < priv->num_sensors; i++) {
- p2[i] += base2;
- p2[i] <<= 2;
- p2[i] |= BIT_APPEND;
- }
- fallthrough;
- case ONE_PT_CALIB2:
- for (i = 0; i < priv->num_sensors; i++) {
- p1[i] += base1;
- p1[i] <<= 2;
- p1[i] |= BIT_APPEND;
- }
- break;
- default:
- for (i = 0; i < priv->num_sensors; i++)
- p2[i] = 780;
- p1[0] = 502;
- p1[1] = 509;
- p1[2] = 503;
- p1[3] = 509;
- p1[4] = 505;
- p1[5] = 509;
- p1[6] = 507;
- p1[7] = 510;
- p1[8] = 508;
- p1[9] = 509;
- p1[10] = 508;
- break;
- }
+ if (calib_redun_sel == BKP_SEL)
+ mode = tsens_read_calibration_legacy(priv, &tsens_8974_backup_nvmem,
+ p1, p2,
+ bkp, calib);
+ else
+ mode = tsens_read_calibration_legacy(priv, &tsens_8974_nvmem,
+ p1, p2,
+ calib, NULL);
+
+ fixup_8974_points(mode, p1, p2);
compute_intercept_slope(priv, p1, p2, mode);
kfree(calib);
@@ -542,11 +269,9 @@ static int calibrate_8974(struct tsens_priv *priv)
static int calibrate_9607(struct tsens_priv *priv)
{
- int base, i;
u32 p1[5], p2[5];
- int mode = 0;
u32 *qfprom_cdata;
- int ret;
+ int mode, ret;
ret = tsens_calibrate_common(priv);
if (!ret)
@@ -556,37 +281,9 @@ static int calibrate_9607(struct tsens_priv *priv)
if (IS_ERR(qfprom_cdata))
return PTR_ERR(qfprom_cdata);
- mode = (qfprom_cdata[2] & MDM9607_CAL_SEL_MASK) >> MDM9607_CAL_SEL_SHIFT;
- dev_dbg(priv->dev, "calibration mode is %d\n", mode);
-
- switch (mode) {
- case TWO_PT_CALIB:
- base = (qfprom_cdata[2] & MDM9607_BASE1_MASK) >> MDM9607_BASE1_SHIFT;
- p2[0] = (qfprom_cdata[0] & MDM9607_S0_P2_MASK) >> MDM9607_S0_P2_SHIFT;
- p2[1] = (qfprom_cdata[0] & MDM9607_S1_P2_MASK) >> MDM9607_S1_P2_SHIFT;
- p2[2] = (qfprom_cdata[1] & MDM9607_S2_P2_MASK) >> MDM9607_S2_P2_SHIFT;
- p2[3] = (qfprom_cdata[1] & MDM9607_S3_P2_MASK) >> MDM9607_S3_P2_SHIFT;
- p2[4] = (qfprom_cdata[2] & MDM9607_S4_P2_MASK) >> MDM9607_S4_P2_SHIFT;
- for (i = 0; i < priv->num_sensors; i++)
- p2[i] = ((base + p2[i]) << 2);
- fallthrough;
- case ONE_PT_CALIB2:
- base = (qfprom_cdata[0] & MDM9607_BASE0_MASK);
- p1[0] = (qfprom_cdata[0] & MDM9607_S0_P1_MASK) >> MDM9607_S0_P1_SHIFT;
- p1[1] = (qfprom_cdata[0] & MDM9607_S1_P1_MASK) >> MDM9607_S1_P1_SHIFT;
- p1[2] = (qfprom_cdata[1] & MDM9607_S2_P1_MASK) >> MDM9607_S2_P1_SHIFT;
- p1[3] = (qfprom_cdata[1] & MDM9607_S3_P1_MASK) >> MDM9607_S3_P1_SHIFT;
- p1[4] = (qfprom_cdata[2] & MDM9607_S4_P1_MASK) >> MDM9607_S4_P1_SHIFT;
- for (i = 0; i < priv->num_sensors; i++)
- p1[i] = ((base + p1[i]) << 2);
- break;
- default:
- for (i = 0; i < priv->num_sensors; i++) {
- p1[i] = 500;
- p2[i] = 780;
- }
- break;
- }
+ mode = tsens_read_calibration_legacy(priv, &tsens_9607_nvmem,
+ p1, p2,
+ qfprom_cdata, NULL);
compute_intercept_slope(priv, p1, p2, mode);
kfree(qfprom_cdata);
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 5bba75a845c5..6d1ea430f90b 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -21,129 +21,54 @@
#define TM_HIGH_LOW_INT_STATUS_OFF 0x0088
#define TM_HIGH_LOW_Sn_INT_THRESHOLD_OFF 0x0090
-/* eeprom layout data for msm8956/76 (v1) */
-#define MSM8976_BASE0_MASK 0xff
-#define MSM8976_BASE1_MASK 0xff
-#define MSM8976_BASE1_SHIFT 8
-
-#define MSM8976_S0_P1_MASK 0x3f00
-#define MSM8976_S1_P1_MASK 0x3f00000
-#define MSM8976_S2_P1_MASK 0x3f
-#define MSM8976_S3_P1_MASK 0x3f000
-#define MSM8976_S4_P1_MASK 0x3f00
-#define MSM8976_S5_P1_MASK 0x3f00000
-#define MSM8976_S6_P1_MASK 0x3f
-#define MSM8976_S7_P1_MASK 0x3f000
-#define MSM8976_S8_P1_MASK 0x1f8
-#define MSM8976_S9_P1_MASK 0x1f8000
-#define MSM8976_S10_P1_MASK 0xf8000000
-#define MSM8976_S10_P1_MASK_1 0x1
-
-#define MSM8976_S0_P2_MASK 0xfc000
-#define MSM8976_S1_P2_MASK 0xfc000000
-#define MSM8976_S2_P2_MASK 0xfc0
-#define MSM8976_S3_P2_MASK 0xfc0000
-#define MSM8976_S4_P2_MASK 0xfc000
-#define MSM8976_S5_P2_MASK 0xfc000000
-#define MSM8976_S6_P2_MASK 0xfc0
-#define MSM8976_S7_P2_MASK 0xfc0000
-#define MSM8976_S8_P2_MASK 0x7e00
-#define MSM8976_S9_P2_MASK 0x7e00000
-#define MSM8976_S10_P2_MASK 0x7e
-
-#define MSM8976_S0_P1_SHIFT 8
-#define MSM8976_S1_P1_SHIFT 20
-#define MSM8976_S2_P1_SHIFT 0
-#define MSM8976_S3_P1_SHIFT 12
-#define MSM8976_S4_P1_SHIFT 8
-#define MSM8976_S5_P1_SHIFT 20
-#define MSM8976_S6_P1_SHIFT 0
-#define MSM8976_S7_P1_SHIFT 12
-#define MSM8976_S8_P1_SHIFT 3
-#define MSM8976_S9_P1_SHIFT 15
-#define MSM8976_S10_P1_SHIFT 27
-#define MSM8976_S10_P1_SHIFT_1 0
-
-#define MSM8976_S0_P2_SHIFT 14
-#define MSM8976_S1_P2_SHIFT 26
-#define MSM8976_S2_P2_SHIFT 6
-#define MSM8976_S3_P2_SHIFT 18
-#define MSM8976_S4_P2_SHIFT 14
-#define MSM8976_S5_P2_SHIFT 26
-#define MSM8976_S6_P2_SHIFT 6
-#define MSM8976_S7_P2_SHIFT 18
-#define MSM8976_S8_P2_SHIFT 9
-#define MSM8976_S9_P2_SHIFT 21
-#define MSM8976_S10_P2_SHIFT 1
-
-#define MSM8976_CAL_SEL_MASK 0x3
-
-/* eeprom layout data for qcs404/405 (v1) */
-#define BASE0_MASK 0x000007f8
-#define BASE1_MASK 0x0007f800
-#define BASE0_SHIFT 3
-#define BASE1_SHIFT 11
-
-#define S0_P1_MASK 0x0000003f
-#define S1_P1_MASK 0x0003f000
-#define S2_P1_MASK 0x3f000000
-#define S3_P1_MASK 0x000003f0
-#define S4_P1_MASK 0x003f0000
-#define S5_P1_MASK 0x0000003f
-#define S6_P1_MASK 0x0003f000
-#define S7_P1_MASK 0x3f000000
-#define S8_P1_MASK 0x000003f0
-#define S9_P1_MASK 0x003f0000
-
-#define S0_P2_MASK 0x00000fc0
-#define S1_P2_MASK 0x00fc0000
-#define S2_P2_MASK_1_0 0xc0000000
-#define S2_P2_MASK_5_2 0x0000000f
-#define S3_P2_MASK 0x0000fc00
-#define S4_P2_MASK 0x0fc00000
-#define S5_P2_MASK 0x00000fc0
-#define S6_P2_MASK 0x00fc0000
-#define S7_P2_MASK_1_0 0xc0000000
-#define S7_P2_MASK_5_2 0x0000000f
-#define S8_P2_MASK 0x0000fc00
-#define S9_P2_MASK 0x0fc00000
-
-#define S0_P1_SHIFT 0
-#define S0_P2_SHIFT 6
-#define S1_P1_SHIFT 12
-#define S1_P2_SHIFT 18
-#define S2_P1_SHIFT 24
-#define S2_P2_SHIFT_1_0 30
-
-#define S2_P2_SHIFT_5_2 0
-#define S3_P1_SHIFT 4
-#define S3_P2_SHIFT 10
-#define S4_P1_SHIFT 16
-#define S4_P2_SHIFT 22
-
-#define S5_P1_SHIFT 0
-#define S5_P2_SHIFT 6
-#define S6_P1_SHIFT 12
-#define S6_P2_SHIFT 18
-#define S7_P1_SHIFT 24
-#define S7_P2_SHIFT_1_0 30
-
-#define S7_P2_SHIFT_5_2 0
-#define S8_P1_SHIFT 4
-#define S8_P2_SHIFT 10
-#define S9_P1_SHIFT 16
-#define S9_P2_SHIFT 22
-
-#define CAL_SEL_MASK 7
-#define CAL_SEL_SHIFT 0
+struct tsens_legacy_calibration_format tsens_qcs404_nvmem = {
+ .base_len = 8,
+ .base_shift = 2,
+ .sp_len = 6,
+ .mode = { 4, 0 },
+ .invalid = { 4, 2 },
+ .base = { { 4, 3 }, { 4, 11 } },
+ .sp = {
+ { { 0, 0 }, { 0, 6 } },
+ { { 0, 12 }, { 0, 18 } },
+ { { 0, 24 }, { 0, 30 } },
+ { { 1, 4 }, { 1, 10 } },
+ { { 1, 16 }, { 1, 22 } },
+ { { 2, 0 }, { 2, 6 } },
+ { { 2, 12 }, { 2, 18 } },
+ { { 2, 24 }, { 2, 30 } },
+ { { 3, 4 }, { 3, 10 } },
+ { { 3, 16 }, { 3, 22 } },
+ },
+};
+
+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 base0 = 0, base1 = 0;
u32 p1[10], p2[10];
- u32 mode = 0, lsb = 0, msb = 0;
u32 *qfprom_cdata;
- int i, ret;
+ int mode, ret;
ret = tsens_calibrate_common(priv);
if (!ret)
@@ -153,53 +78,9 @@ static int calibrate_v1(struct tsens_priv *priv)
if (IS_ERR(qfprom_cdata))
return PTR_ERR(qfprom_cdata);
- mode = (qfprom_cdata[4] & CAL_SEL_MASK) >> CAL_SEL_SHIFT;
- dev_dbg(priv->dev, "calibration mode is %d\n", mode);
-
- switch (mode) {
- case TWO_PT_CALIB:
- base1 = (qfprom_cdata[4] & BASE1_MASK) >> BASE1_SHIFT;
- p2[0] = (qfprom_cdata[0] & S0_P2_MASK) >> S0_P2_SHIFT;
- p2[1] = (qfprom_cdata[0] & S1_P2_MASK) >> S1_P2_SHIFT;
- /* This value is split over two registers, 2 bits and 4 bits */
- lsb = (qfprom_cdata[0] & S2_P2_MASK_1_0) >> S2_P2_SHIFT_1_0;
- msb = (qfprom_cdata[1] & S2_P2_MASK_5_2) >> S2_P2_SHIFT_5_2;
- p2[2] = msb << 2 | lsb;
- p2[3] = (qfprom_cdata[1] & S3_P2_MASK) >> S3_P2_SHIFT;
- p2[4] = (qfprom_cdata[1] & S4_P2_MASK) >> S4_P2_SHIFT;
- p2[5] = (qfprom_cdata[2] & S5_P2_MASK) >> S5_P2_SHIFT;
- p2[6] = (qfprom_cdata[2] & S6_P2_MASK) >> S6_P2_SHIFT;
- /* This value is split over two registers, 2 bits and 4 bits */
- lsb = (qfprom_cdata[2] & S7_P2_MASK_1_0) >> S7_P2_SHIFT_1_0;
- msb = (qfprom_cdata[3] & S7_P2_MASK_5_2) >> S7_P2_SHIFT_5_2;
- p2[7] = msb << 2 | lsb;
- p2[8] = (qfprom_cdata[3] & S8_P2_MASK) >> S8_P2_SHIFT;
- p2[9] = (qfprom_cdata[3] & S9_P2_MASK) >> S9_P2_SHIFT;
- for (i = 0; i < priv->num_sensors; i++)
- p2[i] = ((base1 + p2[i]) << 2);
- fallthrough;
- case ONE_PT_CALIB2:
- base0 = (qfprom_cdata[4] & BASE0_MASK) >> BASE0_SHIFT;
- p1[0] = (qfprom_cdata[0] & S0_P1_MASK) >> S0_P1_SHIFT;
- p1[1] = (qfprom_cdata[0] & S1_P1_MASK) >> S1_P1_SHIFT;
- p1[2] = (qfprom_cdata[0] & S2_P1_MASK) >> S2_P1_SHIFT;
- p1[3] = (qfprom_cdata[1] & S3_P1_MASK) >> S3_P1_SHIFT;
- p1[4] = (qfprom_cdata[1] & S4_P1_MASK) >> S4_P1_SHIFT;
- p1[5] = (qfprom_cdata[2] & S5_P1_MASK) >> S5_P1_SHIFT;
- p1[6] = (qfprom_cdata[2] & S6_P1_MASK) >> S6_P1_SHIFT;
- p1[7] = (qfprom_cdata[2] & S7_P1_MASK) >> S7_P1_SHIFT;
- p1[8] = (qfprom_cdata[3] & S8_P1_MASK) >> S8_P1_SHIFT;
- p1[9] = (qfprom_cdata[3] & S9_P1_MASK) >> S9_P1_SHIFT;
- for (i = 0; i < priv->num_sensors; i++)
- p1[i] = (((base0) + p1[i]) << 2);
- break;
- default:
- for (i = 0; i < priv->num_sensors; i++) {
- p1[i] = 500;
- p2[i] = 780;
- }
- break;
- }
+ mode = tsens_read_calibration_legacy(priv, &tsens_qcs404_nvmem,
+ p1, p2,
+ qfprom_cdata, NULL);
compute_intercept_slope(priv, p1, p2, mode);
kfree(qfprom_cdata);
@@ -209,11 +90,9 @@ static int calibrate_v1(struct tsens_priv *priv)
static int calibrate_8976(struct tsens_priv *priv)
{
- int base0 = 0, base1 = 0, i;
u32 p1[11], p2[11];
- int mode = 0, tmp = 0;
u32 *qfprom_cdata;
- int ret;
+ int mode, ret;
ret = tsens_calibrate_common(priv);
if (!ret)
@@ -223,53 +102,10 @@ static int calibrate_8976(struct tsens_priv *priv)
if (IS_ERR(qfprom_cdata))
return PTR_ERR(qfprom_cdata);
- mode = (qfprom_cdata[4] & MSM8976_CAL_SEL_MASK);
- dev_dbg(priv->dev, "calibration mode is %d\n", mode);
-
- switch (mode) {
- case TWO_PT_CALIB:
- base1 = (qfprom_cdata[2] & MSM8976_BASE1_MASK) >> MSM8976_BASE1_SHIFT;
- p2[0] = (qfprom_cdata[0] & MSM8976_S0_P2_MASK) >> MSM8976_S0_P2_SHIFT;
- p2[1] = (qfprom_cdata[0] & MSM8976_S1_P2_MASK) >> MSM8976_S1_P2_SHIFT;
- p2[2] = (qfprom_cdata[1] & MSM8976_S2_P2_MASK) >> MSM8976_S2_P2_SHIFT;
- p2[3] = (qfprom_cdata[1] & MSM8976_S3_P2_MASK) >> MSM8976_S3_P2_SHIFT;
- p2[4] = (qfprom_cdata[2] & MSM8976_S4_P2_MASK) >> MSM8976_S4_P2_SHIFT;
- p2[5] = (qfprom_cdata[2] & MSM8976_S5_P2_MASK) >> MSM8976_S5_P2_SHIFT;
- p2[6] = (qfprom_cdata[3] & MSM8976_S6_P2_MASK) >> MSM8976_S6_P2_SHIFT;
- p2[7] = (qfprom_cdata[3] & MSM8976_S7_P2_MASK) >> MSM8976_S7_P2_SHIFT;
- p2[8] = (qfprom_cdata[4] & MSM8976_S8_P2_MASK) >> MSM8976_S8_P2_SHIFT;
- p2[9] = (qfprom_cdata[4] & MSM8976_S9_P2_MASK) >> MSM8976_S9_P2_SHIFT;
- p2[10] = (qfprom_cdata[5] & MSM8976_S10_P2_MASK) >> MSM8976_S10_P2_SHIFT;
-
- for (i = 0; i < priv->num_sensors; i++)
- p2[i] = ((base1 + p2[i]) << 2);
- fallthrough;
- case ONE_PT_CALIB2:
- base0 = qfprom_cdata[0] & MSM8976_BASE0_MASK;
- p1[0] = (qfprom_cdata[0] & MSM8976_S0_P1_MASK) >> MSM8976_S0_P1_SHIFT;
- p1[1] = (qfprom_cdata[0] & MSM8976_S1_P1_MASK) >> MSM8976_S1_P1_SHIFT;
- p1[2] = (qfprom_cdata[1] & MSM8976_S2_P1_MASK) >> MSM8976_S2_P1_SHIFT;
- p1[3] = (qfprom_cdata[1] & MSM8976_S3_P1_MASK) >> MSM8976_S3_P1_SHIFT;
- p1[4] = (qfprom_cdata[2] & MSM8976_S4_P1_MASK) >> MSM8976_S4_P1_SHIFT;
- p1[5] = (qfprom_cdata[2] & MSM8976_S5_P1_MASK) >> MSM8976_S5_P1_SHIFT;
- p1[6] = (qfprom_cdata[3] & MSM8976_S6_P1_MASK) >> MSM8976_S6_P1_SHIFT;
- p1[7] = (qfprom_cdata[3] & MSM8976_S7_P1_MASK) >> MSM8976_S7_P1_SHIFT;
- p1[8] = (qfprom_cdata[4] & MSM8976_S8_P1_MASK) >> MSM8976_S8_P1_SHIFT;
- p1[9] = (qfprom_cdata[4] & MSM8976_S9_P1_MASK) >> MSM8976_S9_P1_SHIFT;
- p1[10] = (qfprom_cdata[4] & MSM8976_S10_P1_MASK) >> MSM8976_S10_P1_SHIFT;
- tmp = (qfprom_cdata[5] & MSM8976_S10_P1_MASK_1) << MSM8976_S10_P1_SHIFT_1;
- p1[10] |= tmp;
-
- for (i = 0; i < priv->num_sensors; i++)
- p1[i] = (((base0) + p1[i]) << 2);
- break;
- default:
- for (i = 0; i < priv->num_sensors; i++) {
- p1[i] = 500;
- p2[i] = 780;
- }
- break;
- }
+ mode = tsens_read_calibration_legacy(priv, &tsens_8976_nvmem,
+ p1, p2,
+ qfprom_cdata, NULL);
+
compute_intercept_slope(priv, p1, p2, mode);
kfree(qfprom_cdata);
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index 6facdb0246a5..6d785ffe8fac 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -171,6 +171,70 @@ int tsens_calibrate_common(struct tsens_priv *priv)
return tsens_calibrate_nvmem(priv, 2);
}
+static u32 tsens_read_cell(const struct tsens_single_value *cell, u8 len, u32 *data0, u32 *data1)
+{
+ u32 val;
+ u32 *data = cell->blob ? data1 : data0;
+
+ if (cell->shift + len <= 32) {
+ val = data[cell->idx] >> cell->shift;
+ } else {
+ u8 part = 32 - cell->shift;
+
+ val = data[cell->idx] >> cell->shift;
+ val |= data[cell->idx + 1] << part;
+ }
+
+ return val & ((1 << len) - 1);
+}
+
+int tsens_read_calibration_legacy(struct tsens_priv *priv,
+ const struct tsens_legacy_calibration_format *format,
+ u32 *p1, u32 *p2,
+ u32 *cdata0, u32 *cdata1)
+{
+ u32 mode, invalid;
+ u32 base1, base2;
+ int i;
+
+ mode = tsens_read_cell(&format->mode, 2, cdata0, cdata1);
+ invalid = tsens_read_cell(&format->invalid, 1, cdata0, cdata1);
+ if (invalid)
+ mode = NO_PT_CALIB;
+ dev_dbg(priv->dev, "calibration mode is %d\n", mode);
+
+ base1 = tsens_read_cell(&format->base[0], format->base_len, cdata0, cdata1);
+ base2 = tsens_read_cell(&format->base[1], format->base_len, cdata0, cdata1);
+
+ for (i = 0; i < priv->num_sensors; i++) {
+ p1[i] = tsens_read_cell(&format->sp[i][0], format->sp_len, cdata0, cdata1);
+ p2[i] = tsens_read_cell(&format->sp[i][1], format->sp_len, cdata0, cdata1);
+ }
+
+ switch (mode) {
+ case ONE_PT_CALIB:
+ for (i = 0; i < priv->num_sensors; i++)
+ p1[i] = p1[i] + (base1 << format->base_shift);
+ break;
+ case TWO_PT_CALIB:
+ for (i = 0; i < priv->num_sensors; i++)
+ p2[i] = (p2[i] + base2) << format->base_shift;
+ fallthrough;
+ case ONE_PT_CALIB2:
+ for (i = 0; i < priv->num_sensors; i++)
+ p1[i] = (p1[i] + base1) << format->base_shift;
+ break;
+ default:
+ dev_dbg(priv->dev, "calibrationless mode\n");
+ for (i = 0; i < priv->num_sensors; i++) {
+ p1[i] = 500;
+ p2[i] = 780;
+ }
+ }
+
+ return mode;
+}
+
/*
* Use this function on devices where slope and offset calculations
* depend on calibration data read from qfprom. On others the slope
diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
index a9ae8df9f810..dba9cd38f637 100644
--- a/drivers/thermal/qcom/tsens.h
+++ b/drivers/thermal/qcom/tsens.h
@@ -584,7 +584,45 @@ struct tsens_priv {
struct tsens_sensor sensor[];
};
+/**
+ * struct tsens_single_value - internal representation of a single field inside nvmem calibration data
+ * @idx: index into the u32 data array
+ * @shift: the shift of the first bit in the value
+ * @blob: index of the data blob to use for this cell
+ */
+struct tsens_single_value {
+ u8 idx;
+ u8 shift;
+ u8 blob;
+};
+
+/**
+ * struct tsens_legacy_calibration_format - description of calibration data used when parsing the legacy nvmem blob
+ * @base_len: the length of the base fields inside calibration data
+ * @base_shift: the shift to be applied to base data
+ * @sp_len: the length of the sN_pM fields inside calibration data
+ * @mode: descriptor of the calibration mode field
+ * @invalid: descriptor of the calibration mode invalid field
+ * @base: descriptors of the base0 and base1 fields
+ * @sp: descriptors of the sN_pM fields
+ */
+struct tsens_legacy_calibration_format {
+ unsigned int base_len;
+ unsigned int base_shift;
+ unsigned int sp_len;
+ /* just two bits */
+ struct tsens_single_value mode;
+ /* on all platforms except 8974 invalid is the third bit of what downstream calls 'mode' */
+ struct tsens_single_value invalid;
+ struct tsens_single_value base[2];
+ struct tsens_single_value sp[][2];
+};
+
char *qfprom_read(struct device *dev, const char *cname);
+int tsens_read_calibration_legacy(struct tsens_priv *priv,
+ const struct tsens_legacy_calibration_format *format,
+ u32 *p1, u32 *p2,
+ u32 *cdata, u32 *csel);
int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2, bool backup);
int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
int tsens_calibrate_common(struct tsens_priv *priv);
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 12/20] thermal/drivers/tsens: Drop single-cell code for mdm9607
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (10 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 11/20] thermal/drivers/tsens: Rework legacy calibration data parsers Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 13/20] thermal/drivers/tsens: Drop single-cell code for msm8939 Dmitry Baryshkov
` (7 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
There is no dtsi file for mdm9607 in the kernel sources. Drop the
compatibility with unofficial dtsi and remove support for handling the
single-cell calibration data on mdm9607.
Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 38 ++++++-------------------------
1 file changed, 7 insertions(+), 31 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index f8b50bf14190..9488416b568c 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -267,30 +267,6 @@ static int calibrate_8974(struct tsens_priv *priv)
return 0;
}
-static int calibrate_9607(struct tsens_priv *priv)
-{
- u32 p1[5], p2[5];
- u32 *qfprom_cdata;
- int mode, ret;
-
- ret = tsens_calibrate_common(priv);
- if (!ret)
- return 0;
-
- qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
- if (IS_ERR(qfprom_cdata))
- return PTR_ERR(qfprom_cdata);
-
- mode = tsens_read_calibration_legacy(priv, &tsens_9607_nvmem,
- p1, p2,
- qfprom_cdata, NULL);
-
- compute_intercept_slope(priv, p1, p2, mode);
- kfree(qfprom_cdata);
-
- return 0;
-}
-
static int __init init_8939(struct tsens_priv *priv) {
priv->sensor[0].slope = 2911;
priv->sensor[1].slope = 2789;
@@ -355,6 +331,12 @@ 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,
@@ -398,15 +380,9 @@ struct tsens_plat_data data_8974 = {
.fields = tsens_v0_1_regfields,
};
-static const struct tsens_ops ops_9607 = {
- .init = init_common,
- .calibrate = calibrate_9607,
- .get_temp = get_temp_common,
-};
-
struct tsens_plat_data data_9607 = {
.num_sensors = 5,
- .ops = &ops_9607,
+ .ops = &ops_v0_1,
.feat = &tsens_v0_1_feat,
.fields = tsens_v0_1_regfields,
};
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 13/20] thermal/drivers/tsens: Drop single-cell code for msm8939
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (11 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 12/20] thermal/drivers/tsens: Drop single-cell code for mdm9607 Dmitry Baryshkov
@ 2022-12-29 3:00 ` Dmitry Baryshkov
2022-12-29 11:27 ` Konrad Dybcio
2022-12-29 12:27 ` Shawn Guo
2022-12-29 3:01 ` [PATCH v5 14/20] thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956 Dmitry Baryshkov
` (6 subsequent siblings)
19 siblings, 2 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:00 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
There is no dtsi file for msm8939 in the kernel sources. Drop the
compatibility with unofficial dtsi and remove support for handling the
single-cell calibration data on msm8939.
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v0_1.c | 26 +-------------------------
1 file changed, 1 insertion(+), 25 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
index 9488416b568c..e89c6f39a3ae 100644
--- a/drivers/thermal/qcom/tsens-v0_1.c
+++ b/drivers/thermal/qcom/tsens-v0_1.c
@@ -150,30 +150,6 @@ static int calibrate_8916(struct tsens_priv *priv)
return 0;
}
-static int calibrate_8939(struct tsens_priv *priv)
-{
- u32 p1[10], p2[10];
- u32 *qfprom_cdata;
- int mode, ret;
-
- ret = tsens_calibrate_common(priv);
- if (!ret)
- return 0;
-
- qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
- if (IS_ERR(qfprom_cdata))
- return PTR_ERR(qfprom_cdata);
-
- mode = tsens_read_calibration_legacy(priv, &tsens_8939_nvmem,
- p1, p2,
- qfprom_cdata, NULL);
-
- compute_intercept_slope(priv, p1, p2, mode);
- kfree(qfprom_cdata);
-
- return 0;
-}
-
static void fixup_8974_points(int mode, u32 *p1, u32 *p2)
{
int i;
@@ -354,7 +330,7 @@ struct tsens_plat_data data_8916 = {
static const struct tsens_ops ops_8939 = {
.init = init_8939,
- .calibrate = calibrate_8939,
+ .calibrate = tsens_calibrate_common,
.get_temp = get_temp_common,
};
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 14/20] thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (12 preceding siblings ...)
2022-12-29 3:00 ` [PATCH v5 13/20] thermal/drivers/tsens: Drop single-cell code for msm8939 Dmitry Baryshkov
@ 2022-12-29 3:01 ` Dmitry Baryshkov
2022-12-29 11:27 ` Konrad Dybcio
2022-12-29 3:01 ` [PATCH v5 15/20] arm64: dts: qcom: msm8956: use SoC-specific compat for tsens Dmitry Baryshkov
` (5 subsequent siblings)
19 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:01 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree, AngeloGioacchino Del Regno
There is no dtsi file for msm8976 in the kernel sources. Drop the
compatibility with unofficial dtsi and remove support for handling the
single-cell calibration data on msm8976.
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
drivers/thermal/qcom/tsens-v1.c | 29 ++---------------------------
1 file changed, 2 insertions(+), 27 deletions(-)
diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
index 6d1ea430f90b..b822a426066d 100644
--- a/drivers/thermal/qcom/tsens-v1.c
+++ b/drivers/thermal/qcom/tsens-v1.c
@@ -88,31 +88,6 @@ static int calibrate_v1(struct tsens_priv *priv)
return 0;
}
-static int calibrate_8976(struct tsens_priv *priv)
-{
- u32 p1[11], p2[11];
- u32 *qfprom_cdata;
- int mode, ret;
-
- ret = tsens_calibrate_common(priv);
- if (!ret)
- return 0;
-
- qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
- if (IS_ERR(qfprom_cdata))
- return PTR_ERR(qfprom_cdata);
-
- mode = tsens_read_calibration_legacy(priv, &tsens_8976_nvmem,
- p1, p2,
- qfprom_cdata, NULL);
-
-
- compute_intercept_slope(priv, p1, p2, mode);
- kfree(qfprom_cdata);
-
- return 0;
-}
-
/* v1.x: msm8956,8976,qcs404,405 */
static struct tsens_features tsens_v1_feat = {
@@ -211,7 +186,7 @@ struct tsens_plat_data data_tsens_v1 = {
static const struct tsens_ops ops_8956 = {
.init = init_8956,
- .calibrate = calibrate_8976,
+ .calibrate = tsens_calibrate_common,
.get_temp = get_temp_tsens_valid,
};
@@ -224,7 +199,7 @@ struct tsens_plat_data data_8956 = {
static const struct tsens_ops ops_8976 = {
.init = init_common,
- .calibrate = calibrate_8976,
+ .calibrate = tsens_calibrate_common,
.get_temp = get_temp_tsens_valid,
};
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 15/20] arm64: dts: qcom: msm8956: use SoC-specific compat for tsens
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (13 preceding siblings ...)
2022-12-29 3:01 ` [PATCH v5 14/20] thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956 Dmitry Baryshkov
@ 2022-12-29 3:01 ` Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 16/20] arm64: dts: qcom: msm8916: specify per-sensor calibration cells Dmitry Baryshkov
` (4 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:01 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
The slope values used during tsens calibration differ between msm8976
and msm8956 SoCs. Use SoC-specific compat value for the msm8956 SoC.
Fixes: 0484d3ce0902 ("arm64: dts: qcom: Add DTS for MSM8976 and MSM8956 SoCs")
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
arch/arm64/boot/dts/qcom/msm8956.dtsi | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm64/boot/dts/qcom/msm8956.dtsi b/arch/arm64/boot/dts/qcom/msm8956.dtsi
index e432512d8716..668e05185c21 100644
--- a/arch/arm64/boot/dts/qcom/msm8956.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8956.dtsi
@@ -12,6 +12,10 @@ &pmu {
interrupts = <GIC_PPI 7 (GIC_CPU_MASK_SIMPLE(6) | IRQ_TYPE_LEVEL_HIGH)>;
};
+&tsens {
+ compatible = "qcom,msm8956-tsens", "qcom,tsens-v1";
+};
+
/*
* You might be wondering.. why is it so empty out there?
* Well, the SoCs are almost identical.
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 16/20] arm64: dts: qcom: msm8916: specify per-sensor calibration cells
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (14 preceding siblings ...)
2022-12-29 3:01 ` [PATCH v5 15/20] arm64: dts: qcom: msm8956: use SoC-specific compat for tsens Dmitry Baryshkov
@ 2022-12-29 3:01 ` Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 17/20] arm64: dts: qcom: msm8976: " Dmitry Baryshkov
` (3 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:01 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
Specify pre-parsed per-sensor calibration nvmem cells in the tsens
device node rather than parsing the whole data blob in the driver.
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
arch/arm64/boot/dts/qcom/msm8916.dtsi | 85 +++++++++++++++++++++++++--
1 file changed, 79 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi
index 2ca8e977fc2a..2ae21c5ade03 100644
--- a/arch/arm64/boot/dts/qcom/msm8916.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi
@@ -442,11 +442,70 @@ qfprom: qfprom@5c000 {
reg = <0x0005c000 0x1000>;
#address-cells = <1>;
#size-cells = <1>;
- tsens_caldata: caldata@d0 {
- reg = <0xd0 0x8>;
+
+ tsens_base1: base1@d0 {
+ reg = <0xd0 0x1>;
+ bits = <0 7>;
+ };
+
+ tsens_s0_p1: s0-p1@d0 {
+ reg = <0xd0 0x2>;
+ bits = <7 5>;
+ };
+
+ tsens_s0_p2: s0-p2@d1 {
+ reg = <0xd1 0x2>;
+ bits = <4 5>;
+ };
+
+ tsens_s1_p1: s1-p1@d2 {
+ reg = <0xd2 0x1>;
+ bits = <1 5>;
+ };
+ tsens_s1_p2: s1-p2@d2 {
+ reg = <0xd2 0x2>;
+ bits = <6 5>;
+ };
+ tsens_s2_p1: s2-p1@d3 {
+ reg = <0xd3 0x1>;
+ bits = <3 5>;
+ };
+
+ tsens_s2_p2: s2-p2@d4 {
+ reg = <0xd4 0x1>;
+ bits = <0 5>;
+ };
+
+ // no tsens with hw_id 3
+
+ tsens_s4_p1: s4-p1@d4 {
+ reg = <0xd4 0x2>;
+ bits = <5 5>;
+ };
+
+ tsens_s4_p2: s4-p2@d5 {
+ reg = <0xd5 0x1>;
+ bits = <2 5>;
+ };
+
+ tsens_s5_p1: s5-p1@d5 {
+ reg = <0xd5 0x2>;
+ bits = <7 5>;
};
- tsens_calsel: calsel@ec {
- reg = <0xec 0x4>;
+
+ tsens_s5_p2: s5-p2@d6 {
+ reg = <0xd6 0x2>;
+ bits = <4 5>;
+ };
+
+ tsens_base2: base2@d7 {
+ reg = <0xd7 0x1>;
+ bits = <1 7>;
+ };
+
+ tsens_mode: mode@ec {
+ reg = <0xef 0x1>;
+ bits = <5 3>;
};
};
@@ -473,8 +532,22 @@ tsens: thermal-sensor@4a9000 {
compatible = "qcom,msm8916-tsens", "qcom,tsens-v0_1";
reg = <0x004a9000 0x1000>, /* TM */
<0x004a8000 0x1000>; /* SROT */
- nvmem-cells = <&tsens_caldata>, <&tsens_calsel>;
- nvmem-cell-names = "calib", "calib_sel";
+
+ // no hw_id 3
+ nvmem-cells = <&tsens_mode>,
+ <&tsens_base1>, <&tsens_base2>,
+ <&tsens_s0_p1>, <&tsens_s0_p2>,
+ <&tsens_s1_p1>, <&tsens_s1_p2>,
+ <&tsens_s2_p1>, <&tsens_s2_p2>,
+ <&tsens_s4_p1>, <&tsens_s4_p2>,
+ <&tsens_s5_p1>, <&tsens_s5_p2>;
+ nvmem-cell-names = "mode",
+ "base1", "base2",
+ "s0_p1", "s0_p2",
+ "s1_p1", "s1_p2",
+ "s2_p1", "s2_p2",
+ "s4_p1", "s4_p2",
+ "s5_p1", "s5_p2";
#qcom,sensors = <5>;
interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "uplow";
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 17/20] arm64: dts: qcom: msm8976: specify per-sensor calibration cells
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (15 preceding siblings ...)
2022-12-29 3:01 ` [PATCH v5 16/20] arm64: dts: qcom: msm8916: specify per-sensor calibration cells Dmitry Baryshkov
@ 2022-12-29 3:01 ` Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 18/20] arm64: dts: qcom: qcs404: " Dmitry Baryshkov
` (2 subsequent siblings)
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:01 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
Specify pre-parsed per-sensor calibration nvmem cells in the tsens
device node rather than parsing the whole data blob in the driver.
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
arch/arm64/boot/dts/qcom/msm8976.dtsi | 153 +++++++++++++++++++++++++-
1 file changed, 149 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/boot/dts/qcom/msm8976.dtsi b/arch/arm64/boot/dts/qcom/msm8976.dtsi
index 05dcb30b0779..2d360d05aa5e 100644
--- a/arch/arm64/boot/dts/qcom/msm8976.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8976.dtsi
@@ -481,8 +481,129 @@ qfprom: qfprom@a4000 {
#address-cells = <1>;
#size-cells = <1>;
- tsens_caldata: caldata@218 {
- reg = <0x218 0x18>;
+ tsens_base1: base1@218 {
+ reg = <0x218 1>;
+ bits = <0 8>;
+ };
+
+ tsens_s0_p1: s0-p1@219 {
+ reg = <0x219 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s0_p2: s0-p2@219 {
+ reg = <0x219 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s1_p1: s1-p1@21a {
+ reg = <0x21a 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s1_p2: s1-p2@21b {
+ reg = <0x21b 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s2_p1: s2-p1@21c {
+ reg = <0x21c 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s2_p2: s2-p2@21c {
+ reg = <0x21c 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s3_p1: s3-p1@21d {
+ reg = <0x21d 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s3_p2: s3-p2@21e {
+ reg = <0x21e 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_base2: base2@220 {
+ reg = <0x220 1>;
+ bits = <0 8>;
+ };
+
+ tsens_s4_p1: s4-p1@221 {
+ reg = <0x221 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s4_p2: s4-p2@221 {
+ reg = <0x221 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s5_p1: s5-p1@222 {
+ reg = <0x222 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s5_p2: s5-p2@223 {
+ reg = <0x224 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s6_p1: s6-p1@224 {
+ reg = <0x224 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s6_p2: s6-p2@224 {
+ reg = <0x224 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s7_p1: s7-p1@225 {
+ reg = <0x225 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s7_p2: s7-p2@226 {
+ reg = <0x226 0x2>;
+ bits = <2 6>;
+ };
+
+ tsens_mode: mode@228 {
+ reg = <0x228 1>;
+ bits = <0 3>;
+ };
+
+ tsens_s8_p1: s8-p1@228 {
+ reg = <0x228 0x2>;
+ bits = <3 6>;
+ };
+
+ tsens_s8_p2: s8-p2@229 {
+ reg = <0x229 0x1>;
+ bits = <1 6>;
+ };
+
+ tsens_s9_p1: s9-p1@229 {
+ reg = <0x229 0x2>;
+ bits = <7 6>;
+ };
+
+ tsens_s9_p2: s9-p2@22a {
+ reg = <0x22a 0x2>;
+ bits = <5 6>;
+ };
+
+ tsens_s10_p1: s10-p1@22b {
+ reg = <0x22b 0x2>;
+ bits = <3 6>;
+ };
+
+ tsens_s10_p2: s10-p2@22c {
+ reg = <0x22c 0x1>;
+ bits = <1 6>;
};
};
@@ -492,8 +613,32 @@ tsens: thermal-sensor@4a9000 {
<0x004a8000 0x1000>; /* SROT */
interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "uplow";
- nvmem-cells = <&tsens_caldata>;
- nvmem-cell-names = "calib";
+ nvmem-cells = <&tsens_mode>,
+ <&tsens_base1>, <&tsens_base2>,
+ <&tsens_s0_p1>, <&tsens_s0_p2>,
+ <&tsens_s1_p1>, <&tsens_s1_p2>,
+ <&tsens_s2_p1>, <&tsens_s2_p2>,
+ <&tsens_s3_p1>, <&tsens_s3_p2>,
+ <&tsens_s4_p1>, <&tsens_s4_p2>,
+ <&tsens_s5_p1>, <&tsens_s5_p2>,
+ <&tsens_s6_p1>, <&tsens_s6_p2>,
+ <&tsens_s7_p1>, <&tsens_s7_p2>,
+ <&tsens_s8_p1>, <&tsens_s8_p2>,
+ <&tsens_s9_p1>, <&tsens_s9_p2>,
+ <&tsens_s10_p1>, <&tsens_s10_p2>;
+ nvmem-cell-names = "mode",
+ "base1", "base2",
+ "s0_p1", "s0_p2",
+ "s1_p1", "s1_p2",
+ "s2_p1", "s2_p2",
+ "s3_p1", "s3_p2",
+ "s4_p1", "s4_p2",
+ "s5_p1", "s5_p2",
+ "s6_p1", "s6_p2",
+ "s7_p1", "s7_p2",
+ "s8_p1", "s8_p2",
+ "s9_p1", "s9_p2",
+ "s10_p1", "s10_p2";
#qcom,sensors = <11>;
#thermal-sensor-cells = <1>;
};
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 18/20] arm64: dts: qcom: qcs404: specify per-sensor calibration cells
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (16 preceding siblings ...)
2022-12-29 3:01 ` [PATCH v5 17/20] arm64: dts: qcom: msm8976: " Dmitry Baryshkov
@ 2022-12-29 3:01 ` Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 19/20] ARM: dts: qcom-msm8974: " Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 20/20] ARM: dts: qcom-apq8084: " Dmitry Baryshkov
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:01 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
Specify pre-parsed per-sensor calibration nvmem cells in the tsens
device node rather than parsing the whole data blob in the driver.
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
arch/arm64/boot/dts/qcom/qcs404.dtsi | 145 ++++++++++++++++++++++++++-
1 file changed, 140 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/boot/dts/qcom/qcs404.dtsi b/arch/arm64/boot/dts/qcom/qcs404.dtsi
index a5324eecb50a..84ff9df2b904 100644
--- a/arch/arm64/boot/dts/qcom/qcs404.dtsi
+++ b/arch/arm64/boot/dts/qcom/qcs404.dtsi
@@ -366,13 +366,126 @@ qfprom: qfprom@a4000 {
reg = <0x000a4000 0x1000>;
#address-cells = <1>;
#size-cells = <1>;
- tsens_caldata: caldata@d0 {
- reg = <0x1f8 0x14>;
- };
cpr_efuse_speedbin: speedbin@13c {
reg = <0x13c 0x4>;
bits = <2 3>;
};
+
+ tsens_s0_p1: s0-p1@1f8 {
+ reg = <0x1f8 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s0_p2: s0-p2@1f8 {
+ reg = <0x1f8 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s1_p1: s1-p1@1f9 {
+ reg = <0x1f9 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s1_p2: s1-p2@1fa {
+ reg = <0x1fa 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s2_p1: s2-p1@1fb {
+ reg = <0x1fb 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s2_p2: s2-p2@1fb {
+ reg = <0x1fb 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s3_p1: s3-p1@1fc {
+ reg = <0x1fc 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s3_p2: s3-p2@1fd {
+ reg = <0x1fd 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s4_p1: s4-p1@1fe {
+ reg = <0x1fe 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s4_p2: s4-p2@1fe {
+ reg = <0x1fe 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s5_p1: s5-p1@200 {
+ reg = <0x200 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s5_p2: s5-p2@200 {
+ reg = <0x200 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s6_p1: s6-p1@201 {
+ reg = <0x201 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s6_p2: s6-p2@202 {
+ reg = <0x202 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s7_p1: s7-p1@203 {
+ reg = <0x203 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s7_p2: s7-p2@203 {
+ reg = <0x203 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s8_p1: s8-p1@204 {
+ reg = <0x204 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s8_p2: s8-p2@205 {
+ reg = <0x205 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s9_p1: s9-p1@206 {
+ reg = <0x206 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s9_p2: s9-p2@206 {
+ reg = <0x206 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_mode: mode@208 {
+ reg = <0x208 1>;
+ bits = <0 3>;
+ };
+
+ tsens_base1: base1@208 {
+ reg = <0x208 2>;
+ bits = <3 8>;
+ };
+
+ tsens_base2: base2@208 {
+ reg = <0x209 2>;
+ bits = <3 8>;
+ };
+
cpr_efuse_quot_offset1: qoffset1@231 {
reg = <0x231 0x4>;
bits = <4 7>;
@@ -447,8 +560,30 @@ tsens: thermal-sensor@4a9000 {
compatible = "qcom,qcs404-tsens", "qcom,tsens-v1";
reg = <0x004a9000 0x1000>, /* TM */
<0x004a8000 0x1000>; /* SROT */
- nvmem-cells = <&tsens_caldata>;
- nvmem-cell-names = "calib";
+ nvmem-cells = <&tsens_mode>,
+ <&tsens_base1>, <&tsens_base2>,
+ <&tsens_s0_p1>, <&tsens_s0_p2>,
+ <&tsens_s1_p1>, <&tsens_s1_p2>,
+ <&tsens_s2_p1>, <&tsens_s2_p2>,
+ <&tsens_s3_p1>, <&tsens_s3_p2>,
+ <&tsens_s4_p1>, <&tsens_s4_p2>,
+ <&tsens_s5_p1>, <&tsens_s5_p2>,
+ <&tsens_s6_p1>, <&tsens_s6_p2>,
+ <&tsens_s7_p1>, <&tsens_s7_p2>,
+ <&tsens_s8_p1>, <&tsens_s8_p2>,
+ <&tsens_s9_p1>, <&tsens_s9_p2>;
+ nvmem-cell-names = "mode",
+ "base1", "base2",
+ "s0_p1", "s0_p2",
+ "s1_p1", "s1_p2",
+ "s2_p1", "s2_p2",
+ "s3_p1", "s3_p2",
+ "s4_p1", "s4_p2",
+ "s5_p1", "s5_p2",
+ "s6_p1", "s6_p2",
+ "s7_p1", "s7_p2",
+ "s8_p1", "s8_p2",
+ "s9_p1", "s9_p2";
#qcom,sensors = <10>;
interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "uplow";
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 19/20] ARM: dts: qcom-msm8974: specify per-sensor calibration cells
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (17 preceding siblings ...)
2022-12-29 3:01 ` [PATCH v5 18/20] arm64: dts: qcom: qcs404: " Dmitry Baryshkov
@ 2022-12-29 3:01 ` Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 20/20] ARM: dts: qcom-apq8084: " Dmitry Baryshkov
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:01 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
Specify pre-parsed per-sensor calibration nvmem cells in the tsens
device node rather than parsing the whole data blob in the driver.
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
arch/arm/boot/dts/qcom-msm8974.dtsi | 313 +++++++++++++++++++++++++++-
1 file changed, 307 insertions(+), 6 deletions(-)
diff --git a/arch/arm/boot/dts/qcom-msm8974.dtsi b/arch/arm/boot/dts/qcom-msm8974.dtsi
index 8d216a3c0851..4d3df70e6158 100644
--- a/arch/arm/boot/dts/qcom-msm8974.dtsi
+++ b/arch/arm/boot/dts/qcom-msm8974.dtsi
@@ -1119,8 +1119,60 @@ tsens: thermal-sensor@fc4a9000 {
compatible = "qcom,msm8974-tsens", "qcom,tsens-v0_1";
reg = <0xfc4a9000 0x1000>, /* TM */
<0xfc4a8000 0x1000>; /* SROT */
- nvmem-cells = <&tsens_calib>, <&tsens_backup>;
- nvmem-cell-names = "calib", "calib_backup";
+ nvmem-cells = <&tsens_mode>,
+ <&tsens_base1>, <&tsens_base2>,
+ <&tsens_s0_p1>, <&tsens_s0_p2>,
+ <&tsens_s1_p1>, <&tsens_s1_p2>,
+ <&tsens_s2_p1>, <&tsens_s2_p2>,
+ <&tsens_s3_p1>, <&tsens_s3_p2>,
+ <&tsens_s4_p1>, <&tsens_s4_p2>,
+ <&tsens_s5_p1>, <&tsens_s5_p2>,
+ <&tsens_s6_p1>, <&tsens_s6_p2>,
+ <&tsens_s7_p1>, <&tsens_s7_p2>,
+ <&tsens_s8_p1>, <&tsens_s8_p2>,
+ <&tsens_s9_p1>, <&tsens_s9_p2>,
+ <&tsens_s10_p1>, <&tsens_s10_p2>,
+ <&tsens_use_backup>,
+ <&tsens_mode_backup>,
+ <&tsens_base1_backup>, <&tsens_base2_backup>,
+ <&tsens_s0_p1_backup>, <&tsens_s0_p2_backup>,
+ <&tsens_s1_p1_backup>, <&tsens_s1_p2_backup>,
+ <&tsens_s2_p1_backup>, <&tsens_s2_p2_backup>,
+ <&tsens_s3_p1_backup>, <&tsens_s3_p2_backup>,
+ <&tsens_s4_p1_backup>, <&tsens_s4_p2_backup>,
+ <&tsens_s5_p1_backup>, <&tsens_s5_p2_backup>,
+ <&tsens_s6_p1_backup>, <&tsens_s6_p2_backup>,
+ <&tsens_s7_p1_backup>, <&tsens_s7_p2_backup>,
+ <&tsens_s8_p1_backup>, <&tsens_s8_p2_backup>,
+ <&tsens_s9_p1_backup>, <&tsens_s9_p2_backup>,
+ <&tsens_s10_p1_backup>, <&tsens_s10_p2_backup>;
+ nvmem-cell-names = "mode",
+ "base1", "base2",
+ "s0_p1", "s0_p2",
+ "s1_p1", "s1_p2",
+ "s2_p1", "s2_p2",
+ "s3_p1", "s3_p2",
+ "s4_p1", "s4_p2",
+ "s5_p1", "s5_p2",
+ "s6_p1", "s6_p2",
+ "s7_p1", "s7_p2",
+ "s8_p1", "s8_p2",
+ "s9_p1", "s9_p2",
+ "s10_p1", "s10_p2",
+ "use_backup",
+ "mode_backup",
+ "base1_backup", "base2_backup",
+ "s0_p1_backup", "s0_p2_backup",
+ "s1_p1_backup", "s1_p2_backup",
+ "s2_p1_backup", "s2_p2_backup",
+ "s3_p1_backup", "s3_p2_backup",
+ "s4_p1_backup", "s4_p2_backup",
+ "s5_p1_backup", "s5_p2_backup",
+ "s6_p1_backup", "s6_p2_backup",
+ "s7_p1_backup", "s7_p2_backup",
+ "s8_p1_backup", "s8_p2_backup",
+ "s9_p1_backup", "s9_p2_backup",
+ "s10_p1_backup", "s10_p2_backup";
#qcom,sensors = <11>;
interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "uplow";
@@ -1137,11 +1189,260 @@ qfprom: qfprom@fc4bc000 {
reg = <0xfc4bc000 0x1000>;
#address-cells = <1>;
#size-cells = <1>;
- tsens_calib: calib@d0 {
- reg = <0xd0 0x18>;
+
+ tsens_base1: base1@d0 {
+ reg = <0xd0 0x1>;
+ bits = <0 8>;
+ };
+
+ tsens_s0_p1: s0-p1@d1 {
+ reg = <0xd1 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s1_p1: s1-p1@d2 {
+ reg = <0xd1 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s2_p1: s2-p1@d2 {
+ reg = <0xd2 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s3_p1: s3-p1@d3 {
+ reg = <0xd3 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s4_p1: s4-p1@d4 {
+ reg = <0xd4 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s5_p1: s5-p1@d4 {
+ reg = <0xd4 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s6_p1: s6-p1@d5 {
+ reg = <0xd5 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s7_p1: s7-p1@d6 {
+ reg = <0xd6 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s8_p1: s8-p1@d7 {
+ reg = <0xd7 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_mode: mode@d7 {
+ reg = <0xd7 0x1>;
+ bits = <6 2>;
+ };
+
+ tsens_s9_p1: s9-p1@d8 {
+ reg = <0xd8 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s10_p1: s10_p1@d8 {
+ reg = <0xd8 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_base2: base2@d9 {
+ reg = <0xd9 0x2>;
+ bits = <4 8>;
+ };
+
+ tsens_s0_p2: s0-p2@da {
+ reg = <0xda 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s1_p2: s1-p2@db {
+ reg = <0xdb 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s2_p2: s2-p2@dc {
+ reg = <0xdc 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s3_p2: s3-p2@dc {
+ reg = <0xdc 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s4_p2: s4-p2@dd {
+ reg = <0xdd 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s5_p2: s5-p2@de {
+ reg = <0xde 0x2>;
+ bits = <2 6>;
+ };
+
+ tsens_s6_p2: s6-p2@df {
+ reg = <0xdf 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s7_p2: s7-p2@e0 {
+ reg = <0xe0 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s8_p2: s8-p2@e0 {
+ reg = <0xe0 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s9_p2: s9-p2@e1 {
+ reg = <0xe1 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s10_p2: s10_p2@e2 {
+ reg = <0xe2 0x2>;
+ bits = <2 6>;
+ };
+
+ tsens_s5_p2_backup: s5-p2_backup@e3 {
+ reg = <0xe3 0x2>;
+ bits = <0 6>;
+ };
+
+ tsens_mode_backup: mode_backup@e3 {
+ reg = <0xe3 0x1>;
+ bits = <6 2>;
+ };
+
+ tsens_s6_p2_backup: s6-p2_backup@e4 {
+ reg = <0xe4 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s7_p2_backup: s7-p2_backup@e4 {
+ reg = <0xe4 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s8_p2_backup: s8-p2_backup@e5 {
+ reg = <0xe5 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s9_p2_backup: s9-p2_backup@e6 {
+ reg = <0xe6 0x2>;
+ bits = <2 6>;
+ };
+
+ tsens_s10_p2_backup: s10_p2_backup@e7 {
+ reg = <0xe7 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_base1_backup: base1_backup@440 {
+ reg = <0x440 0x1>;
+ bits = <0 8>;
+ };
+
+ tsens_s0_p1_backup: s0-p1_backup@441 {
+ reg = <0x441 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s1_p1_backup: s1-p1_backup@442 {
+ reg = <0x441 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s2_p1_backup: s2-p1_backup@442 {
+ reg = <0x442 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s3_p1_backup: s3-p1_backup@443 {
+ reg = <0x443 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s4_p1_backup: s4-p1_backup@444 {
+ reg = <0x444 0x1>;
+ bits = <0 6>;
};
- tsens_backup: backup@440 {
- reg = <0x440 0x10>;
+
+ tsens_s5_p1_backup: s5-p1_backup@444 {
+ reg = <0x444 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s6_p1_backup: s6-p1_backup@445 {
+ reg = <0x445 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s7_p1_backup: s7-p1_backup@446 {
+ reg = <0x446 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_use_backup: use_backup@447 {
+ reg = <0x447 0x1>;
+ bits = <5 3>;
+ };
+
+ tsens_s8_p1_backup: s8-p1_backup@448 {
+ reg = <0x448 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s9_p1_backup: s9-p1_backup@448 {
+ reg = <0x448 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s10_p1_backup: s10_p1_backup@449 {
+ reg = <0x449 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_base2_backup: base2_backup@44a {
+ reg = <0x44a 0x2>;
+ bits = <2 8>;
+ };
+
+ tsens_s0_p2_backup: s0-p2_backup@44b {
+ reg = <0x44b 0x3>;
+ bits = <2 6>;
+ };
+
+ tsens_s1_p2_backup: s1-p2_backup@44c {
+ reg = <0x44c 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s2_p2_backup: s2-p2_backup@44c {
+ reg = <0x44c 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s3_p2_backup: s3-p2_backup@44d {
+ reg = <0x44d 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s4_p2_backup: s4-p2_backup@44e {
+ reg = <0x44e 0x1>;
+ bits = <2 6>;
};
};
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v5 20/20] ARM: dts: qcom-apq8084: specify per-sensor calibration cells
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
` (18 preceding siblings ...)
2022-12-29 3:01 ` [PATCH v5 19/20] ARM: dts: qcom-msm8974: " Dmitry Baryshkov
@ 2022-12-29 3:01 ` Dmitry Baryshkov
19 siblings, 0 replies; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 3:01 UTC (permalink / raw)
To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
Specify pre-parsed per-sensor calibration nvmem cells in the tsens
device node rather than parsing the whole data blob in the driver.
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
arch/arm/boot/dts/qcom-apq8084.dtsi | 313 +++++++++++++++++++++++++++-
1 file changed, 307 insertions(+), 6 deletions(-)
diff --git a/arch/arm/boot/dts/qcom-apq8084.dtsi b/arch/arm/boot/dts/qcom-apq8084.dtsi
index fe30abfff90a..22e56ee82a20 100644
--- a/arch/arm/boot/dts/qcom-apq8084.dtsi
+++ b/arch/arm/boot/dts/qcom-apq8084.dtsi
@@ -249,11 +249,260 @@ qfprom: qfprom@fc4bc000 {
reg = <0xfc4bc000 0x1000>;
#address-cells = <1>;
#size-cells = <1>;
- tsens_calib: calib@d0 {
- reg = <0xd0 0x18>;
+
+ tsens_base1: base1@d0 {
+ reg = <0xd0 0x1>;
+ bits = <0 8>;
+ };
+
+ tsens_s0_p1: s0-p1@d1 {
+ reg = <0xd1 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s1_p1: s1-p1@d2 {
+ reg = <0xd1 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s2_p1: s2-p1@d2 {
+ reg = <0xd2 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s3_p1: s3-p1@d3 {
+ reg = <0xd3 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s4_p1: s4-p1@d4 {
+ reg = <0xd4 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s5_p1: s5-p1@d4 {
+ reg = <0xd4 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s6_p1: s6-p1@d5 {
+ reg = <0xd5 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s7_p1: s7-p1@d6 {
+ reg = <0xd6 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s8_p1: s8-p1@d7 {
+ reg = <0xd7 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_mode: mode@d7 {
+ reg = <0xd7 0x1>;
+ bits = <6 2>;
+ };
+
+ tsens_s9_p1: s9-p1@d8 {
+ reg = <0xd8 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s10_p1: s10_p1@d8 {
+ reg = <0xd8 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_base2: base2@d9 {
+ reg = <0xd9 0x2>;
+ bits = <4 8>;
+ };
+
+ tsens_s0_p2: s0-p2@da {
+ reg = <0xda 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s1_p2: s1-p2@db {
+ reg = <0xdb 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s2_p2: s2-p2@dc {
+ reg = <0xdc 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s3_p2: s3-p2@dc {
+ reg = <0xdc 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s4_p2: s4-p2@dd {
+ reg = <0xdd 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s5_p2: s5-p2@de {
+ reg = <0xde 0x2>;
+ bits = <2 6>;
+ };
+
+ tsens_s6_p2: s6-p2@df {
+ reg = <0xdf 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s7_p2: s7-p2@e0 {
+ reg = <0xe0 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s8_p2: s8-p2@e0 {
+ reg = <0xe0 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s9_p2: s9-p2@e1 {
+ reg = <0xe1 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s10_p2: s10_p2@e2 {
+ reg = <0xe2 0x2>;
+ bits = <2 6>;
+ };
+
+ tsens_s5_p2_backup: s5-p2_backup@e3 {
+ reg = <0xe3 0x2>;
+ bits = <0 6>;
+ };
+
+ tsens_mode_backup: mode_backup@e3 {
+ reg = <0xe3 0x1>;
+ bits = <6 2>;
+ };
+
+ tsens_s6_p2_backup: s6-p2_backup@e4 {
+ reg = <0xe4 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s7_p2_backup: s7-p2_backup@e4 {
+ reg = <0xe4 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s8_p2_backup: s8-p2_backup@e5 {
+ reg = <0xe5 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s9_p2_backup: s9-p2_backup@e6 {
+ reg = <0xe6 0x2>;
+ bits = <2 6>;
+ };
+
+ tsens_s10_p2_backup: s10_p2_backup@e7 {
+ reg = <0xe7 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_base1_backup: base1_backup@440 {
+ reg = <0x440 0x1>;
+ bits = <0 8>;
+ };
+
+ tsens_s0_p1_backup: s0-p1_backup@441 {
+ reg = <0x441 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s1_p1_backup: s1-p1_backup@442 {
+ reg = <0x441 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s2_p1_backup: s2-p1_backup@442 {
+ reg = <0x442 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s3_p1_backup: s3-p1_backup@443 {
+ reg = <0x443 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_s4_p1_backup: s4-p1_backup@444 {
+ reg = <0x444 0x1>;
+ bits = <0 6>;
};
- tsens_backup: backup@440 {
- reg = <0x440 0x10>;
+
+ tsens_s5_p1_backup: s5-p1_backup@444 {
+ reg = <0x444 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s6_p1_backup: s6-p1_backup@445 {
+ reg = <0x445 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s7_p1_backup: s7-p1_backup@446 {
+ reg = <0x446 0x1>;
+ bits = <2 6>;
+ };
+
+ tsens_use_backup: use_backup@447 {
+ reg = <0x447 0x1>;
+ bits = <5 3>;
+ };
+
+ tsens_s8_p1_backup: s8-p1_backup@448 {
+ reg = <0x448 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s9_p1_backup: s9-p1_backup@448 {
+ reg = <0x448 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s10_p1_backup: s10_p1_backup@449 {
+ reg = <0x449 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_base2_backup: base2_backup@44a {
+ reg = <0x44a 0x2>;
+ bits = <2 8>;
+ };
+
+ tsens_s0_p2_backup: s0-p2_backup@44b {
+ reg = <0x44b 0x3>;
+ bits = <2 6>;
+ };
+
+ tsens_s1_p2_backup: s1-p2_backup@44c {
+ reg = <0x44c 0x1>;
+ bits = <0 6>;
+ };
+
+ tsens_s2_p2_backup: s2-p2_backup@44c {
+ reg = <0x44c 0x2>;
+ bits = <6 6>;
+ };
+
+ tsens_s3_p2_backup: s3-p2_backup@44d {
+ reg = <0x44d 0x2>;
+ bits = <4 6>;
+ };
+
+ tsens_s4_p2_backup: s4-p2_backup@44e {
+ reg = <0x44e 0x1>;
+ bits = <2 6>;
};
};
@@ -261,8 +510,60 @@ tsens: thermal-sensor@fc4a8000 {
compatible = "qcom,msm8974-tsens", "qcom,tsens-v0_1";
reg = <0xfc4a9000 0x1000>, /* TM */
<0xfc4a8000 0x1000>; /* SROT */
- nvmem-cells = <&tsens_calib>, <&tsens_backup>;
- nvmem-cell-names = "calib", "calib_backup";
+ nvmem-cells = <&tsens_mode>,
+ <&tsens_base1>, <&tsens_base2>,
+ <&tsens_s0_p1>, <&tsens_s0_p2>,
+ <&tsens_s1_p1>, <&tsens_s1_p2>,
+ <&tsens_s2_p1>, <&tsens_s2_p2>,
+ <&tsens_s3_p1>, <&tsens_s3_p2>,
+ <&tsens_s4_p1>, <&tsens_s4_p2>,
+ <&tsens_s5_p1>, <&tsens_s5_p2>,
+ <&tsens_s6_p1>, <&tsens_s6_p2>,
+ <&tsens_s7_p1>, <&tsens_s7_p2>,
+ <&tsens_s8_p1>, <&tsens_s8_p2>,
+ <&tsens_s9_p1>, <&tsens_s9_p2>,
+ <&tsens_s10_p1>, <&tsens_s10_p2>,
+ <&tsens_use_backup>,
+ <&tsens_mode_backup>,
+ <&tsens_base1_backup>, <&tsens_base2_backup>,
+ <&tsens_s0_p1_backup>, <&tsens_s0_p2_backup>,
+ <&tsens_s1_p1_backup>, <&tsens_s1_p2_backup>,
+ <&tsens_s2_p1_backup>, <&tsens_s2_p2_backup>,
+ <&tsens_s3_p1_backup>, <&tsens_s3_p2_backup>,
+ <&tsens_s4_p1_backup>, <&tsens_s4_p2_backup>,
+ <&tsens_s5_p1_backup>, <&tsens_s5_p2_backup>,
+ <&tsens_s6_p1_backup>, <&tsens_s6_p2_backup>,
+ <&tsens_s7_p1_backup>, <&tsens_s7_p2_backup>,
+ <&tsens_s8_p1_backup>, <&tsens_s8_p2_backup>,
+ <&tsens_s9_p1_backup>, <&tsens_s9_p2_backup>,
+ <&tsens_s10_p1_backup>, <&tsens_s10_p2_backup>;
+ nvmem-cell-names = "mode",
+ "base1", "base2",
+ "s0_p1", "s0_p2",
+ "s1_p1", "s1_p2",
+ "s2_p1", "s2_p2",
+ "s3_p1", "s3_p2",
+ "s4_p1", "s4_p2",
+ "s5_p1", "s5_p2",
+ "s6_p1", "s6_p2",
+ "s7_p1", "s7_p2",
+ "s8_p1", "s8_p2",
+ "s9_p1", "s9_p2",
+ "s10_p1", "s10_p2",
+ "use_backup",
+ "mode_backup",
+ "base1_backup", "base2_backup",
+ "s0_p1_backup", "s0_p2_backup",
+ "s1_p1_backup", "s1_p2_backup",
+ "s2_p1_backup", "s2_p2_backup",
+ "s3_p1_backup", "s3_p2_backup",
+ "s4_p1_backup", "s4_p2_backup",
+ "s5_p1_backup", "s5_p2_backup",
+ "s6_p1_backup", "s6_p2_backup",
+ "s7_p1_backup", "s7_p2_backup",
+ "s8_p1_backup", "s8_p2_backup",
+ "s9_p1_backup", "s9_p2_backup",
+ "s10_p1_backup", "s10_p2_backup";
#qcom,sensors = <11>;
interrupts = <GIC_SPI 184 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "uplow";
--
2.39.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells
2022-12-29 3:00 ` [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells Dmitry Baryshkov
@ 2022-12-29 8:35 ` Krzysztof Kozlowski
2022-12-29 11:49 ` Dmitry Baryshkov
0 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2022-12-29 8:35 UTC (permalink / raw)
To: Dmitry Baryshkov, Andy Gross, Bjorn Andersson, Konrad Dybcio,
Rob Herring, Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
On 29/12/2022 04:00, Dmitry Baryshkov wrote:
> Allow specifying the exact calibration mode and calibration data as nvmem
> cells, rather than specifying just a single calibration data blob.
>
> Note, unlike the vendor kernel the calibration data uses hw_ids rather
> than software sensor indices (to match actual tsens usage in
> thermal zones).
>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
> .../bindings/thermal/qcom-tsens.yaml | 95 +++++++++++++++++--
> 1 file changed, 85 insertions(+), 10 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
> index f3660af0b3bf..4bb689f4602d 100644
> --- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
> +++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
> @@ -81,18 +81,63 @@ properties:
> maxItems: 2
>
> nvmem-cells:
> - minItems: 1
> - maxItems: 2
> - description:
> - Reference to an nvmem node for the calibration data
> + oneOf:
> + - minItems: 1
> + maxItems: 2
> + description:
> + Reference to an nvmem node for the calibration data
> + - minItems: 5
> + maxItems: 35
> + description: |
> + Reference to nvmem cells for the calibration mode, two calibration
> + bases and two cells per each sensor
>
> nvmem-cell-names:
> - minItems: 1
> - items:
> - - const: calib
> - - enum:
> - - calib_backup
> - - calib_sel
> + oneOf:
> + - minItems: 1
> + items:
> + - const: calib
> + - enum:
> + - calib_backup
> + - calib_sel
> + - minItems: 5
> + items:
> + enum:
This should not be an enum but a list of const... unless "holes" are
expected (e.g. s0_p1 and s5_p2, without ones in between).
> + - mode
> + - base1
> + - base2
> + - s0_p1
> + - s0_p2
> + - s1_p1
> + - s1_p2
> + - s2_p1
> + - s2_p2
> + - s3_p1
> + - s3_p2
> + - s4_p1
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data
2022-12-29 3:00 ` [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data Dmitry Baryshkov
@ 2022-12-29 10:47 ` Konrad Dybcio
2022-12-29 11:42 ` Dmitry Baryshkov
0 siblings, 1 reply; 36+ messages in thread
From: Konrad Dybcio @ 2022-12-29 10:47 UTC (permalink / raw)
To: Dmitry Baryshkov, Andy Gross, Bjorn Andersson, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
On 29.12.2022 04:00, Dmitry Baryshkov wrote:
> Add a unified function using nvmem cells for parsing the calibration
> data rather than parsing the calibration blob manually.
>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
> drivers/thermal/qcom/tsens-v0_1.c | 15 ++++++
> drivers/thermal/qcom/tsens-v1.c | 11 ++++-
> drivers/thermal/qcom/tsens.c | 76 +++++++++++++++++++++++++++++++
> drivers/thermal/qcom/tsens.h | 5 ++
> 4 files changed, 106 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index 579028ea48f4..6c9e491f9559 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -229,6 +229,11 @@ static int calibrate_8916(struct tsens_priv *priv)
> u32 p1[5], p2[5];
> int mode = 0;
> u32 *qfprom_cdata, *qfprom_csel;
> + int ret;
> +
> + ret = tsens_calibrate_nvmem(priv, 3);
> + if (!ret)
> + return 0;
>
> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> if (IS_ERR(qfprom_cdata))
> @@ -286,6 +291,11 @@ static int calibrate_8939(struct tsens_priv *priv)
> int mode = 0;
> u32 *qfprom_cdata;
> u32 cdata[4];
> + int ret;
> +
> + ret = tsens_calibrate_common(priv);
> + if (!ret)
> + return 0;
>
> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> if (IS_ERR(qfprom_cdata))
> @@ -486,6 +496,11 @@ static int calibrate_9607(struct tsens_priv *priv)
> u32 p1[5], p2[5];
> int mode = 0;
> u32 *qfprom_cdata;
> + int ret;
> +
> + ret = tsens_calibrate_common(priv);
> + if (!ret)
> + return 0;
>
> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> if (IS_ERR(qfprom_cdata))
> diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
> index 83c2853546d0..5bba75a845c5 100644
> --- a/drivers/thermal/qcom/tsens-v1.c
> +++ b/drivers/thermal/qcom/tsens-v1.c
> @@ -143,7 +143,11 @@ static int calibrate_v1(struct tsens_priv *priv)
> u32 p1[10], p2[10];
> u32 mode = 0, lsb = 0, msb = 0;
> u32 *qfprom_cdata;
> - int i;
> + int i, ret;
> +
> + ret = tsens_calibrate_common(priv);
> + if (!ret)
> + return 0;
>
> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> if (IS_ERR(qfprom_cdata))
> @@ -209,6 +213,11 @@ static int calibrate_8976(struct tsens_priv *priv)
> u32 p1[11], p2[11];
> int mode = 0, tmp = 0;
> u32 *qfprom_cdata;
> + int ret;
> +
> + ret = tsens_calibrate_common(priv);
> + if (!ret)
> + return 0;
>
> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> if (IS_ERR(qfprom_cdata))
> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> index b191e19df93d..ce568a68de4a 100644
> --- a/drivers/thermal/qcom/tsens.c
> +++ b/drivers/thermal/qcom/tsens.c
> @@ -70,6 +70,82 @@ char *qfprom_read(struct device *dev, const char *cname)
> return ret;
> }
>
> +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
> +{
> + u32 mode;
> + u32 base1, base2;
> + u32 p1[MAX_SENSORS], p2[MAX_SENSORS];
> + char name[] = "sXX_pY"; /* s10_p1 */
> + int i, ret;
> +
> + if (priv->num_sensors > MAX_SENSORS)
> + return -EINVAL;
> +
> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "mode", &mode);
> + if (ret == -ENOENT)
> + dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
> + if (ret < 0)
> + return ret;
> +
> + dev_dbg(priv->dev, "calibration mode is %d\n", mode);
> +
> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base1", &base1);
> + if (ret < 0)
> + return ret;
> +
> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base2", &base2);
> + if (ret < 0)
> + return ret;
> +
> + for (i = 0; i < priv->num_sensors; i++) {
> + ret = snprintf(name, sizeof(name), "s%d_p1", priv->sensor[i].hw_id);
I think you forgot to update the underscore to a hyphen here
(unless the nvmem api does some magic internally).
Konrad
> + if (ret < 0)
> + return ret;
> +
> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p1[i]);
> + if (ret)
> + return ret;
> +
> + ret = snprintf(name, sizeof(name), "s%d_p2", priv->sensor[i].hw_id);
> + if (ret < 0)
> + return ret;
> +
> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p2[i]);
> + if (ret)
> + return ret;
> + }
> +
> + switch (mode) {
> + case ONE_PT_CALIB:
> + for (i = 0; i < priv->num_sensors; i++)
> + p1[i] = p1[i] + (base1 << shift);
> + break;
> + case TWO_PT_CALIB:
> + for (i = 0; i < priv->num_sensors; i++)
> + p2[i] = (p2[i] + base2) << shift;
> + fallthrough;
> + case ONE_PT_CALIB2:
> + for (i = 0; i < priv->num_sensors; i++)
> + p1[i] = (p1[i] + base1) << shift;
> + break;
> + default:
> + dev_dbg(priv->dev, "calibrationless mode\n");
> + for (i = 0; i < priv->num_sensors; i++) {
> + p1[i] = 500;
> + p2[i] = 780;
> + }
> + }
> +
> + compute_intercept_slope(priv, p1, p2, mode);
> +
> + return 0;
> +}
> +
> +int tsens_calibrate_common(struct tsens_priv *priv)
> +{
> + return tsens_calibrate_nvmem(priv, 2);
> +}
> +
> /*
> * Use this function on devices where slope and offset calculations
> * depend on calibration data read from qfprom. On others the slope
> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
> index 7dd5fc246894..645ae02438fa 100644
> --- a/drivers/thermal/qcom/tsens.h
> +++ b/drivers/thermal/qcom/tsens.h
> @@ -6,6 +6,7 @@
> #ifndef __QCOM_TSENS_H__
> #define __QCOM_TSENS_H__
>
> +#define NO_PT_CALIB 0x0
> #define ONE_PT_CALIB 0x1
> #define ONE_PT_CALIB2 0x2
> #define TWO_PT_CALIB 0x3
> @@ -17,6 +18,8 @@
> #define THRESHOLD_MAX_ADC_CODE 0x3ff
> #define THRESHOLD_MIN_ADC_CODE 0x0
>
> +#define MAX_SENSORS 16
> +
> #include <linux/interrupt.h>
> #include <linux/thermal.h>
> #include <linux/regmap.h>
> @@ -582,6 +585,8 @@ struct tsens_priv {
> };
>
> char *qfprom_read(struct device *dev, const char *cname);
> +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
> +int tsens_calibrate_common(struct tsens_priv *priv);
> void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
> int init_common(struct tsens_priv *priv);
> int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 13/20] thermal/drivers/tsens: Drop single-cell code for msm8939
2022-12-29 3:00 ` [PATCH v5 13/20] thermal/drivers/tsens: Drop single-cell code for msm8939 Dmitry Baryshkov
@ 2022-12-29 11:27 ` Konrad Dybcio
2022-12-29 12:27 ` Shawn Guo
1 sibling, 0 replies; 36+ messages in thread
From: Konrad Dybcio @ 2022-12-29 11:27 UTC (permalink / raw)
To: Dmitry Baryshkov, Andy Gross, Bjorn Andersson, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm, devicetree
On 29.12.2022 04:00, Dmitry Baryshkov wrote:
> There is no dtsi file for msm8939 in the kernel sources. Drop the
> compatibility with unofficial dtsi and remove support for handling the
> single-cell calibration data on msm8939.
>
> Cc: Shawn Guo <shawn.guo@linaro.org>
> Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Konrad
> drivers/thermal/qcom/tsens-v0_1.c | 26 +-------------------------
> 1 file changed, 1 insertion(+), 25 deletions(-)
>
> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> index 9488416b568c..e89c6f39a3ae 100644
> --- a/drivers/thermal/qcom/tsens-v0_1.c
> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> @@ -150,30 +150,6 @@ static int calibrate_8916(struct tsens_priv *priv)
> return 0;
> }
>
> -static int calibrate_8939(struct tsens_priv *priv)
> -{
> - u32 p1[10], p2[10];
> - u32 *qfprom_cdata;
> - int mode, ret;
> -
> - ret = tsens_calibrate_common(priv);
> - if (!ret)
> - return 0;
> -
> - qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> - if (IS_ERR(qfprom_cdata))
> - return PTR_ERR(qfprom_cdata);
> -
> - mode = tsens_read_calibration_legacy(priv, &tsens_8939_nvmem,
> - p1, p2,
> - qfprom_cdata, NULL);
> -
> - compute_intercept_slope(priv, p1, p2, mode);
> - kfree(qfprom_cdata);
> -
> - return 0;
> -}
> -
> static void fixup_8974_points(int mode, u32 *p1, u32 *p2)
> {
> int i;
> @@ -354,7 +330,7 @@ struct tsens_plat_data data_8916 = {
>
> static const struct tsens_ops ops_8939 = {
> .init = init_8939,
> - .calibrate = calibrate_8939,
> + .calibrate = tsens_calibrate_common,
> .get_temp = get_temp_common,
> };
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 14/20] thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956
2022-12-29 3:01 ` [PATCH v5 14/20] thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956 Dmitry Baryshkov
@ 2022-12-29 11:27 ` Konrad Dybcio
0 siblings, 0 replies; 36+ messages in thread
From: Konrad Dybcio @ 2022-12-29 11:27 UTC (permalink / raw)
To: Dmitry Baryshkov, Andy Gross, Bjorn Andersson, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui
Cc: Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree, AngeloGioacchino Del Regno
On 29.12.2022 04:01, Dmitry Baryshkov wrote:
> There is no dtsi file for msm8976 in the kernel sources. Drop the
> compatibility with unofficial dtsi and remove support for handling the
> single-cell calibration data on msm8976.
>
> Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Konrad
> drivers/thermal/qcom/tsens-v1.c | 29 ++---------------------------
> 1 file changed, 2 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
> index 6d1ea430f90b..b822a426066d 100644
> --- a/drivers/thermal/qcom/tsens-v1.c
> +++ b/drivers/thermal/qcom/tsens-v1.c
> @@ -88,31 +88,6 @@ static int calibrate_v1(struct tsens_priv *priv)
> return 0;
> }
>
> -static int calibrate_8976(struct tsens_priv *priv)
> -{
> - u32 p1[11], p2[11];
> - u32 *qfprom_cdata;
> - int mode, ret;
> -
> - ret = tsens_calibrate_common(priv);
> - if (!ret)
> - return 0;
> -
> - qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> - if (IS_ERR(qfprom_cdata))
> - return PTR_ERR(qfprom_cdata);
> -
> - mode = tsens_read_calibration_legacy(priv, &tsens_8976_nvmem,
> - p1, p2,
> - qfprom_cdata, NULL);
> -
> -
> - compute_intercept_slope(priv, p1, p2, mode);
> - kfree(qfprom_cdata);
> -
> - return 0;
> -}
> -
> /* v1.x: msm8956,8976,qcs404,405 */
>
> static struct tsens_features tsens_v1_feat = {
> @@ -211,7 +186,7 @@ struct tsens_plat_data data_tsens_v1 = {
>
> static const struct tsens_ops ops_8956 = {
> .init = init_8956,
> - .calibrate = calibrate_8976,
> + .calibrate = tsens_calibrate_common,
> .get_temp = get_temp_tsens_valid,
> };
>
> @@ -224,7 +199,7 @@ struct tsens_plat_data data_8956 = {
>
> static const struct tsens_ops ops_8976 = {
> .init = init_common,
> - .calibrate = calibrate_8976,
> + .calibrate = tsens_calibrate_common,
> .get_temp = get_temp_tsens_valid,
> };
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data
2022-12-29 10:47 ` Konrad Dybcio
@ 2022-12-29 11:42 ` Dmitry Baryshkov
2022-12-29 11:47 ` Konrad Dybcio
0 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 11:42 UTC (permalink / raw)
To: Konrad Dybcio
Cc: Andy Gross, Bjorn Andersson, Rob Herring, Krzysztof Kozlowski,
Amit Kucheria, Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Bryan O'Donoghue, Shawn Guo, linux-arm-msm,
linux-pm, devicetree
On Thu, 29 Dec 2022 at 12:47, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
>
>
>
> On 29.12.2022 04:00, Dmitry Baryshkov wrote:
> > Add a unified function using nvmem cells for parsing the calibration
> > data rather than parsing the calibration blob manually.
> >
> > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> > ---
> > drivers/thermal/qcom/tsens-v0_1.c | 15 ++++++
> > drivers/thermal/qcom/tsens-v1.c | 11 ++++-
> > drivers/thermal/qcom/tsens.c | 76 +++++++++++++++++++++++++++++++
> > drivers/thermal/qcom/tsens.h | 5 ++
> > 4 files changed, 106 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> > index 579028ea48f4..6c9e491f9559 100644
> > --- a/drivers/thermal/qcom/tsens-v0_1.c
> > +++ b/drivers/thermal/qcom/tsens-v0_1.c
> > @@ -229,6 +229,11 @@ static int calibrate_8916(struct tsens_priv *priv)
> > u32 p1[5], p2[5];
> > int mode = 0;
> > u32 *qfprom_cdata, *qfprom_csel;
> > + int ret;
> > +
> > + ret = tsens_calibrate_nvmem(priv, 3);
> > + if (!ret)
> > + return 0;
> >
> > qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> > if (IS_ERR(qfprom_cdata))
> > @@ -286,6 +291,11 @@ static int calibrate_8939(struct tsens_priv *priv)
> > int mode = 0;
> > u32 *qfprom_cdata;
> > u32 cdata[4];
> > + int ret;
> > +
> > + ret = tsens_calibrate_common(priv);
> > + if (!ret)
> > + return 0;
> >
> > qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> > if (IS_ERR(qfprom_cdata))
> > @@ -486,6 +496,11 @@ static int calibrate_9607(struct tsens_priv *priv)
> > u32 p1[5], p2[5];
> > int mode = 0;
> > u32 *qfprom_cdata;
> > + int ret;
> > +
> > + ret = tsens_calibrate_common(priv);
> > + if (!ret)
> > + return 0;
> >
> > qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> > if (IS_ERR(qfprom_cdata))
> > diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
> > index 83c2853546d0..5bba75a845c5 100644
> > --- a/drivers/thermal/qcom/tsens-v1.c
> > +++ b/drivers/thermal/qcom/tsens-v1.c
> > @@ -143,7 +143,11 @@ static int calibrate_v1(struct tsens_priv *priv)
> > u32 p1[10], p2[10];
> > u32 mode = 0, lsb = 0, msb = 0;
> > u32 *qfprom_cdata;
> > - int i;
> > + int i, ret;
> > +
> > + ret = tsens_calibrate_common(priv);
> > + if (!ret)
> > + return 0;
> >
> > qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> > if (IS_ERR(qfprom_cdata))
> > @@ -209,6 +213,11 @@ static int calibrate_8976(struct tsens_priv *priv)
> > u32 p1[11], p2[11];
> > int mode = 0, tmp = 0;
> > u32 *qfprom_cdata;
> > + int ret;
> > +
> > + ret = tsens_calibrate_common(priv);
> > + if (!ret)
> > + return 0;
> >
> > qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> > if (IS_ERR(qfprom_cdata))
> > diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> > index b191e19df93d..ce568a68de4a 100644
> > --- a/drivers/thermal/qcom/tsens.c
> > +++ b/drivers/thermal/qcom/tsens.c
> > @@ -70,6 +70,82 @@ char *qfprom_read(struct device *dev, const char *cname)
> > return ret;
> > }
> >
> > +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
> > +{
> > + u32 mode;
> > + u32 base1, base2;
> > + u32 p1[MAX_SENSORS], p2[MAX_SENSORS];
> > + char name[] = "sXX_pY"; /* s10_p1 */
> > + int i, ret;
> > +
> > + if (priv->num_sensors > MAX_SENSORS)
> > + return -EINVAL;
> > +
> > + ret = nvmem_cell_read_variable_le_u32(priv->dev, "mode", &mode);
> > + if (ret == -ENOENT)
> > + dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
> > + if (ret < 0)
> > + return ret;
> > +
> > + dev_dbg(priv->dev, "calibration mode is %d\n", mode);
> > +
> > + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base1", &base1);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base2", &base2);
> > + if (ret < 0)
> > + return ret;
> > +
> > + for (i = 0; i < priv->num_sensors; i++) {
> > + ret = snprintf(name, sizeof(name), "s%d_p1", priv->sensor[i].hw_id);
> I think you forgot to update the underscore to a hyphen here
> (unless the nvmem api does some magic internally).
No. Please see the nvmem-cell-names property of the tsens nodes. It
uses underscores. Then OF code translates this sX_pY string into an
index in the nvmem-cells array or phandles. The sX-pY@ZZ node name is
not used during lookups at all.
>
> Konrad
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p1[i]);
> > + if (ret)
> > + return ret;
> > +
> > + ret = snprintf(name, sizeof(name), "s%d_p2", priv->sensor[i].hw_id);
> > + if (ret < 0)
> > + return ret;
> > +
> > + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p2[i]);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + switch (mode) {
> > + case ONE_PT_CALIB:
> > + for (i = 0; i < priv->num_sensors; i++)
> > + p1[i] = p1[i] + (base1 << shift);
> > + break;
> > + case TWO_PT_CALIB:
> > + for (i = 0; i < priv->num_sensors; i++)
> > + p2[i] = (p2[i] + base2) << shift;
> > + fallthrough;
> > + case ONE_PT_CALIB2:
> > + for (i = 0; i < priv->num_sensors; i++)
> > + p1[i] = (p1[i] + base1) << shift;
> > + break;
> > + default:
> > + dev_dbg(priv->dev, "calibrationless mode\n");
> > + for (i = 0; i < priv->num_sensors; i++) {
> > + p1[i] = 500;
> > + p2[i] = 780;
> > + }
> > + }
> > +
> > + compute_intercept_slope(priv, p1, p2, mode);
> > +
> > + return 0;
> > +}
> > +
> > +int tsens_calibrate_common(struct tsens_priv *priv)
> > +{
> > + return tsens_calibrate_nvmem(priv, 2);
> > +}
> > +
> > /*
> > * Use this function on devices where slope and offset calculations
> > * depend on calibration data read from qfprom. On others the slope
> > diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
> > index 7dd5fc246894..645ae02438fa 100644
> > --- a/drivers/thermal/qcom/tsens.h
> > +++ b/drivers/thermal/qcom/tsens.h
> > @@ -6,6 +6,7 @@
> > #ifndef __QCOM_TSENS_H__
> > #define __QCOM_TSENS_H__
> >
> > +#define NO_PT_CALIB 0x0
> > #define ONE_PT_CALIB 0x1
> > #define ONE_PT_CALIB2 0x2
> > #define TWO_PT_CALIB 0x3
> > @@ -17,6 +18,8 @@
> > #define THRESHOLD_MAX_ADC_CODE 0x3ff
> > #define THRESHOLD_MIN_ADC_CODE 0x0
> >
> > +#define MAX_SENSORS 16
> > +
> > #include <linux/interrupt.h>
> > #include <linux/thermal.h>
> > #include <linux/regmap.h>
> > @@ -582,6 +585,8 @@ struct tsens_priv {
> > };
> >
> > char *qfprom_read(struct device *dev, const char *cname);
> > +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
> > +int tsens_calibrate_common(struct tsens_priv *priv);
> > void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
> > int init_common(struct tsens_priv *priv);
> > int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data
2022-12-29 11:42 ` Dmitry Baryshkov
@ 2022-12-29 11:47 ` Konrad Dybcio
2022-12-29 11:52 ` Dmitry Baryshkov
0 siblings, 1 reply; 36+ messages in thread
From: Konrad Dybcio @ 2022-12-29 11:47 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Andy Gross, Bjorn Andersson, Rob Herring, Krzysztof Kozlowski,
Amit Kucheria, Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Bryan O'Donoghue, Shawn Guo, linux-arm-msm,
linux-pm, devicetree
On 29.12.2022 12:42, Dmitry Baryshkov wrote:
> On Thu, 29 Dec 2022 at 12:47, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
>>
>>
>>
>> On 29.12.2022 04:00, Dmitry Baryshkov wrote:
>>> Add a unified function using nvmem cells for parsing the calibration
>>> data rather than parsing the calibration blob manually.
>>>
>>> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>>> ---
>>> drivers/thermal/qcom/tsens-v0_1.c | 15 ++++++
>>> drivers/thermal/qcom/tsens-v1.c | 11 ++++-
>>> drivers/thermal/qcom/tsens.c | 76 +++++++++++++++++++++++++++++++
>>> drivers/thermal/qcom/tsens.h | 5 ++
>>> 4 files changed, 106 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
>>> index 579028ea48f4..6c9e491f9559 100644
>>> --- a/drivers/thermal/qcom/tsens-v0_1.c
>>> +++ b/drivers/thermal/qcom/tsens-v0_1.c
>>> @@ -229,6 +229,11 @@ static int calibrate_8916(struct tsens_priv *priv)
>>> u32 p1[5], p2[5];
>>> int mode = 0;
>>> u32 *qfprom_cdata, *qfprom_csel;
>>> + int ret;
>>> +
>>> + ret = tsens_calibrate_nvmem(priv, 3);
>>> + if (!ret)
>>> + return 0;
>>>
>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>> if (IS_ERR(qfprom_cdata))
>>> @@ -286,6 +291,11 @@ static int calibrate_8939(struct tsens_priv *priv)
>>> int mode = 0;
>>> u32 *qfprom_cdata;
>>> u32 cdata[4];
>>> + int ret;
>>> +
>>> + ret = tsens_calibrate_common(priv);
>>> + if (!ret)
>>> + return 0;
>>>
>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>> if (IS_ERR(qfprom_cdata))
>>> @@ -486,6 +496,11 @@ static int calibrate_9607(struct tsens_priv *priv)
>>> u32 p1[5], p2[5];
>>> int mode = 0;
>>> u32 *qfprom_cdata;
>>> + int ret;
>>> +
>>> + ret = tsens_calibrate_common(priv);
>>> + if (!ret)
>>> + return 0;
>>>
>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>> if (IS_ERR(qfprom_cdata))
>>> diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
>>> index 83c2853546d0..5bba75a845c5 100644
>>> --- a/drivers/thermal/qcom/tsens-v1.c
>>> +++ b/drivers/thermal/qcom/tsens-v1.c
>>> @@ -143,7 +143,11 @@ static int calibrate_v1(struct tsens_priv *priv)
>>> u32 p1[10], p2[10];
>>> u32 mode = 0, lsb = 0, msb = 0;
>>> u32 *qfprom_cdata;
>>> - int i;
>>> + int i, ret;
>>> +
>>> + ret = tsens_calibrate_common(priv);
>>> + if (!ret)
>>> + return 0;
>>>
>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>> if (IS_ERR(qfprom_cdata))
>>> @@ -209,6 +213,11 @@ static int calibrate_8976(struct tsens_priv *priv)
>>> u32 p1[11], p2[11];
>>> int mode = 0, tmp = 0;
>>> u32 *qfprom_cdata;
>>> + int ret;
>>> +
>>> + ret = tsens_calibrate_common(priv);
>>> + if (!ret)
>>> + return 0;
>>>
>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>> if (IS_ERR(qfprom_cdata))
>>> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
>>> index b191e19df93d..ce568a68de4a 100644
>>> --- a/drivers/thermal/qcom/tsens.c
>>> +++ b/drivers/thermal/qcom/tsens.c
>>> @@ -70,6 +70,82 @@ char *qfprom_read(struct device *dev, const char *cname)
>>> return ret;
>>> }
>>>
>>> +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
>>> +{
>>> + u32 mode;
>>> + u32 base1, base2;
>>> + u32 p1[MAX_SENSORS], p2[MAX_SENSORS];
>>> + char name[] = "sXX_pY"; /* s10_p1 */
>>> + int i, ret;
>>> +
>>> + if (priv->num_sensors > MAX_SENSORS)
>>> + return -EINVAL;
>>> +
>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "mode", &mode);
>>> + if (ret == -ENOENT)
>>> + dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>> + dev_dbg(priv->dev, "calibration mode is %d\n", mode);
>>> +
>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base1", &base1);
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base2", &base2);
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>> + for (i = 0; i < priv->num_sensors; i++) {
>>> + ret = snprintf(name, sizeof(name), "s%d_p1", priv->sensor[i].hw_id);
>> I think you forgot to update the underscore to a hyphen here
>> (unless the nvmem api does some magic internally).
>
> No. Please see the nvmem-cell-names property of the tsens nodes. It
> uses underscores. Then OF code translates this sX_pY string into an
> index in the nvmem-cells array or phandles. The sX-pY@ZZ node name is
> not used during lookups at all.
Right, I overlooked that!
>
>>
>> Konrad
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p1[i]);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + ret = snprintf(name, sizeof(name), "s%d_p2", priv->sensor[i].hw_id);
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p2[i]);
>>> + if (ret)
>>> + return ret;
>>> + }
>>> +
>>> + switch (mode) {
>>> + case ONE_PT_CALIB:
>>> + for (i = 0; i < priv->num_sensors; i++)
>>> + p1[i] = p1[i] + (base1 << shift);
>>> + break;
>>> + case TWO_PT_CALIB:
>>> + for (i = 0; i < priv->num_sensors; i++)
>>> + p2[i] = (p2[i] + base2) << shift;
>>> + fallthrough;
>>> + case ONE_PT_CALIB2:
>>> + for (i = 0; i < priv->num_sensors; i++)
>>> + p1[i] = (p1[i] + base1) << shift;
>>> + break;
>>> + default:
>>> + dev_dbg(priv->dev, "calibrationless mode\n");
This could be a dev_warn, as we usually don't expect it to happen.
Other than that:
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Konrad
>>> + for (i = 0; i < priv->num_sensors; i++) {
>>> + p1[i] = 500;
>>> + p2[i] = 780;
>>> + }
>>> + }
>>> +
>>> + compute_intercept_slope(priv, p1, p2, mode);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +int tsens_calibrate_common(struct tsens_priv *priv)
>>> +{
>>> + return tsens_calibrate_nvmem(priv, 2);
>>> +}
>>> +
>>> /*
>>> * Use this function on devices where slope and offset calculations
>>> * depend on calibration data read from qfprom. On others the slope
>>> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
>>> index 7dd5fc246894..645ae02438fa 100644
>>> --- a/drivers/thermal/qcom/tsens.h
>>> +++ b/drivers/thermal/qcom/tsens.h
>>> @@ -6,6 +6,7 @@
>>> #ifndef __QCOM_TSENS_H__
>>> #define __QCOM_TSENS_H__
>>>
>>> +#define NO_PT_CALIB 0x0
>>> #define ONE_PT_CALIB 0x1
>>> #define ONE_PT_CALIB2 0x2
>>> #define TWO_PT_CALIB 0x3
>>> @@ -17,6 +18,8 @@
>>> #define THRESHOLD_MAX_ADC_CODE 0x3ff
>>> #define THRESHOLD_MIN_ADC_CODE 0x0
>>>
>>> +#define MAX_SENSORS 16
>>> +
>>> #include <linux/interrupt.h>
>>> #include <linux/thermal.h>
>>> #include <linux/regmap.h>
>>> @@ -582,6 +585,8 @@ struct tsens_priv {
>>> };
>>>
>>> char *qfprom_read(struct device *dev, const char *cname);
>>> +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
>>> +int tsens_calibrate_common(struct tsens_priv *priv);
>>> void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
>>> int init_common(struct tsens_priv *priv);
>>> int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells
2022-12-29 8:35 ` Krzysztof Kozlowski
@ 2022-12-29 11:49 ` Dmitry Baryshkov
2023-01-01 15:56 ` Krzysztof Kozlowski
0 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 11:49 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree
On Thu, 29 Dec 2022 at 10:35, Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> On 29/12/2022 04:00, Dmitry Baryshkov wrote:
> > Allow specifying the exact calibration mode and calibration data as nvmem
> > cells, rather than specifying just a single calibration data blob.
> >
> > Note, unlike the vendor kernel the calibration data uses hw_ids rather
> > than software sensor indices (to match actual tsens usage in
> > thermal zones).
> >
> > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> > ---
> > .../bindings/thermal/qcom-tsens.yaml | 95 +++++++++++++++++--
> > 1 file changed, 85 insertions(+), 10 deletions(-)
> >
> > diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
> > index f3660af0b3bf..4bb689f4602d 100644
> > --- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
> > +++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
> > @@ -81,18 +81,63 @@ properties:
> > maxItems: 2
> >
> > nvmem-cells:
> > - minItems: 1
> > - maxItems: 2
> > - description:
> > - Reference to an nvmem node for the calibration data
> > + oneOf:
> > + - minItems: 1
> > + maxItems: 2
> > + description:
> > + Reference to an nvmem node for the calibration data
> > + - minItems: 5
> > + maxItems: 35
> > + description: |
> > + Reference to nvmem cells for the calibration mode, two calibration
> > + bases and two cells per each sensor
> >
> > nvmem-cell-names:
> > - minItems: 1
> > - items:
> > - - const: calib
> > - - enum:
> > - - calib_backup
> > - - calib_sel
> > + oneOf:
> > + - minItems: 1
> > + items:
> > + - const: calib
> > + - enum:
> > + - calib_backup
> > + - calib_sel
> > + - minItems: 5
> > + items:
> > + enum:
>
> This should not be an enum but a list of const... unless "holes" are
> expected (e.g. s0_p1 and s5_p2, without ones in between).
Yes, this is the case. See the msm8916.dtsi changes. There is no
sensor with hw_id 3, so the sequence is: ... s2_p1, s2_p2, s4_p1,
s4_p2,....
Same applies to the msm8939 (no sensor #4).
Note: if there was support for the prefixItems, I'd have probably
marked mode/base1/base2 to be the first items of the array.
>
> > + - mode
> > + - base1
> > + - base2
> > + - s0_p1
> > + - s0_p2
> > + - s1_p1
> > + - s1_p2
> > + - s2_p1
> > + - s2_p2
> > + - s3_p1
> > + - s3_p2
> > + - s4_p1
>
>
> Best regards,
> Krzysztof
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data
2022-12-29 11:47 ` Konrad Dybcio
@ 2022-12-29 11:52 ` Dmitry Baryshkov
2022-12-29 12:23 ` Konrad Dybcio
0 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2022-12-29 11:52 UTC (permalink / raw)
To: Konrad Dybcio
Cc: Andy Gross, Bjorn Andersson, Rob Herring, Krzysztof Kozlowski,
Amit Kucheria, Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Bryan O'Donoghue, Shawn Guo, linux-arm-msm,
linux-pm, devicetree
On Thu, 29 Dec 2022 at 13:47, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
> On 29.12.2022 12:42, Dmitry Baryshkov wrote:
> > On Thu, 29 Dec 2022 at 12:47, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
> >> On 29.12.2022 04:00, Dmitry Baryshkov wrote:
> >>> Add a unified function using nvmem cells for parsing the calibration
> >>> data rather than parsing the calibration blob manually.
> >>>
> >>> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> >>> ---
> >>> drivers/thermal/qcom/tsens-v0_1.c | 15 ++++++
> >>> drivers/thermal/qcom/tsens-v1.c | 11 ++++-
> >>> drivers/thermal/qcom/tsens.c | 76 +++++++++++++++++++++++++++++++
> >>> drivers/thermal/qcom/tsens.h | 5 ++
> >>> 4 files changed, 106 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
> >>> index 579028ea48f4..6c9e491f9559 100644
> >>> --- a/drivers/thermal/qcom/tsens-v0_1.c
> >>> +++ b/drivers/thermal/qcom/tsens-v0_1.c
> >>> @@ -229,6 +229,11 @@ static int calibrate_8916(struct tsens_priv *priv)
> >>> u32 p1[5], p2[5];
> >>> int mode = 0;
> >>> u32 *qfprom_cdata, *qfprom_csel;
> >>> + int ret;
> >>> +
> >>> + ret = tsens_calibrate_nvmem(priv, 3);
> >>> + if (!ret)
> >>> + return 0;
> >>>
> >>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> >>> if (IS_ERR(qfprom_cdata))
> >>> @@ -286,6 +291,11 @@ static int calibrate_8939(struct tsens_priv *priv)
> >>> int mode = 0;
> >>> u32 *qfprom_cdata;
> >>> u32 cdata[4];
> >>> + int ret;
> >>> +
> >>> + ret = tsens_calibrate_common(priv);
> >>> + if (!ret)
> >>> + return 0;
> >>>
> >>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> >>> if (IS_ERR(qfprom_cdata))
> >>> @@ -486,6 +496,11 @@ static int calibrate_9607(struct tsens_priv *priv)
> >>> u32 p1[5], p2[5];
> >>> int mode = 0;
> >>> u32 *qfprom_cdata;
> >>> + int ret;
> >>> +
> >>> + ret = tsens_calibrate_common(priv);
> >>> + if (!ret)
> >>> + return 0;
> >>>
> >>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> >>> if (IS_ERR(qfprom_cdata))
> >>> diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
> >>> index 83c2853546d0..5bba75a845c5 100644
> >>> --- a/drivers/thermal/qcom/tsens-v1.c
> >>> +++ b/drivers/thermal/qcom/tsens-v1.c
> >>> @@ -143,7 +143,11 @@ static int calibrate_v1(struct tsens_priv *priv)
> >>> u32 p1[10], p2[10];
> >>> u32 mode = 0, lsb = 0, msb = 0;
> >>> u32 *qfprom_cdata;
> >>> - int i;
> >>> + int i, ret;
> >>> +
> >>> + ret = tsens_calibrate_common(priv);
> >>> + if (!ret)
> >>> + return 0;
> >>>
> >>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> >>> if (IS_ERR(qfprom_cdata))
> >>> @@ -209,6 +213,11 @@ static int calibrate_8976(struct tsens_priv *priv)
> >>> u32 p1[11], p2[11];
> >>> int mode = 0, tmp = 0;
> >>> u32 *qfprom_cdata;
> >>> + int ret;
> >>> +
> >>> + ret = tsens_calibrate_common(priv);
> >>> + if (!ret)
> >>> + return 0;
> >>>
> >>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
> >>> if (IS_ERR(qfprom_cdata))
> >>> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
> >>> index b191e19df93d..ce568a68de4a 100644
> >>> --- a/drivers/thermal/qcom/tsens.c
> >>> +++ b/drivers/thermal/qcom/tsens.c
> >>> @@ -70,6 +70,82 @@ char *qfprom_read(struct device *dev, const char *cname)
> >>> return ret;
> >>> }
> >>>
> >>> +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
> >>> +{
> >>> + u32 mode;
> >>> + u32 base1, base2;
> >>> + u32 p1[MAX_SENSORS], p2[MAX_SENSORS];
> >>> + char name[] = "sXX_pY"; /* s10_p1 */
> >>> + int i, ret;
> >>> +
> >>> + if (priv->num_sensors > MAX_SENSORS)
> >>> + return -EINVAL;
> >>> +
> >>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "mode", &mode);
> >>> + if (ret == -ENOENT)
> >>> + dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
> >>> + if (ret < 0)
> >>> + return ret;
> >>> +
> >>> + dev_dbg(priv->dev, "calibration mode is %d\n", mode);
> >>> +
> >>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base1", &base1);
> >>> + if (ret < 0)
> >>> + return ret;
> >>> +
> >>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base2", &base2);
> >>> + if (ret < 0)
> >>> + return ret;
> >>> +
> >>> + for (i = 0; i < priv->num_sensors; i++) {
> >>> + ret = snprintf(name, sizeof(name), "s%d_p1", priv->sensor[i].hw_id);
> >> I think you forgot to update the underscore to a hyphen here
> >> (unless the nvmem api does some magic internally).
> >
> > No. Please see the nvmem-cell-names property of the tsens nodes. It
> > uses underscores. Then OF code translates this sX_pY string into an
> > index in the nvmem-cells array or phandles. The sX-pY@ZZ node name is
> > not used during lookups at all.
> Right, I overlooked that!
>
> >
> >>
> >> Konrad
> >>> + if (ret < 0)
> >>> + return ret;
> >>> +
> >>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p1[i]);
> >>> + if (ret)
> >>> + return ret;
> >>> +
> >>> + ret = snprintf(name, sizeof(name), "s%d_p2", priv->sensor[i].hw_id);
> >>> + if (ret < 0)
> >>> + return ret;
> >>> +
> >>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p2[i]);
> >>> + if (ret)
> >>> + return ret;
> >>> + }
> >>> +
> >>> + switch (mode) {
> >>> + case ONE_PT_CALIB:
> >>> + for (i = 0; i < priv->num_sensors; i++)
> >>> + p1[i] = p1[i] + (base1 << shift);
> >>> + break;
> >>> + case TWO_PT_CALIB:
> >>> + for (i = 0; i < priv->num_sensors; i++)
> >>> + p2[i] = (p2[i] + base2) << shift;
> >>> + fallthrough;
> >>> + case ONE_PT_CALIB2:
> >>> + for (i = 0; i < priv->num_sensors; i++)
> >>> + p1[i] = (p1[i] + base1) << shift;
> >>> + break;
> >>> + default:
> >>> + dev_dbg(priv->dev, "calibrationless mode\n");
> This could be a dev_warn, as we usually don't expect it to happen.
I'm not so sure here. Current code handles this case without any
warnings, as one of the expected cases So, I don't think the rework
should start emitting warnings.
> Other than that:
>
> Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
>
> Konrad
> >>> + for (i = 0; i < priv->num_sensors; i++) {
> >>> + p1[i] = 500;
> >>> + p2[i] = 780;
> >>> + }
> >>> + }
> >>> +
> >>> + compute_intercept_slope(priv, p1, p2, mode);
> >>> +
> >>> + return 0;
> >>> +}
> >>> +
> >>> +int tsens_calibrate_common(struct tsens_priv *priv)
> >>> +{
> >>> + return tsens_calibrate_nvmem(priv, 2);
> >>> +}
> >>> +
> >>> /*
> >>> * Use this function on devices where slope and offset calculations
> >>> * depend on calibration data read from qfprom. On others the slope
> >>> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
> >>> index 7dd5fc246894..645ae02438fa 100644
> >>> --- a/drivers/thermal/qcom/tsens.h
> >>> +++ b/drivers/thermal/qcom/tsens.h
> >>> @@ -6,6 +6,7 @@
> >>> #ifndef __QCOM_TSENS_H__
> >>> #define __QCOM_TSENS_H__
> >>>
> >>> +#define NO_PT_CALIB 0x0
> >>> #define ONE_PT_CALIB 0x1
> >>> #define ONE_PT_CALIB2 0x2
> >>> #define TWO_PT_CALIB 0x3
> >>> @@ -17,6 +18,8 @@
> >>> #define THRESHOLD_MAX_ADC_CODE 0x3ff
> >>> #define THRESHOLD_MIN_ADC_CODE 0x0
> >>>
> >>> +#define MAX_SENSORS 16
> >>> +
> >>> #include <linux/interrupt.h>
> >>> #include <linux/thermal.h>
> >>> #include <linux/regmap.h>
> >>> @@ -582,6 +585,8 @@ struct tsens_priv {
> >>> };
> >>>
> >>> char *qfprom_read(struct device *dev, const char *cname);
> >>> +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
> >>> +int tsens_calibrate_common(struct tsens_priv *priv);
> >>> void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
> >>> int init_common(struct tsens_priv *priv);
> >>> int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
> >
> >
> >
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 07/20] thermal/drivers/tsens: fix slope values for msm8939
2022-12-29 3:00 ` [PATCH v5 07/20] thermal/drivers/tsens: fix slope values for msm8939 Dmitry Baryshkov
@ 2022-12-29 12:05 ` Shawn Guo
0 siblings, 0 replies; 36+ messages in thread
From: Shawn Guo @ 2022-12-29 12:05 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Bryan O'Donoghue, linux-arm-msm, linux-pm, devicetree
On Thu, Dec 29, 2022 at 05:00:53AM +0200, Dmitry Baryshkov wrote:
> According to the vendor kernels (msm-3.10, 3.14 and 3.18), msm8939
> uses non-standard slope values for calibrating the sensors. Fill them
> accordingly.
>
> Fixes: 332bc8ebab2c ("thermal: qcom: tsens-v0_1: Add support for MSM8939")
> Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Cc: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
> Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 08/20] thermal/drivers/tsens: limit num_sensors to 9 for msm8939
2022-12-29 3:00 ` [PATCH v5 08/20] thermal/drivers/tsens: limit num_sensors to 9 " Dmitry Baryshkov
@ 2022-12-29 12:22 ` Shawn Guo
0 siblings, 0 replies; 36+ messages in thread
From: Shawn Guo @ 2022-12-29 12:22 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Bryan O'Donoghue, linux-arm-msm, linux-pm, devicetree
On Thu, Dec 29, 2022 at 05:00:54AM +0200, Dmitry Baryshkov wrote:
> On msm8939 last (hwid=10) sensor was added in the hw revision 3.0.
> Calibration data for it was placed outside of the main calibration data
> blob, so it is not accessible by the current blob-parsing code.
>
> Moreover data for the sensor's p2 is not contiguous in the fuses. This
> makes it hard to use nvmem_cell API to parse calibration data in a
> generic way.
>
> Since the sensor doesn't seem to be actually used by the existing
> hardware, disable the sensor for now.
>
> Fixes: 332bc8ebab2c ("thermal: qcom: tsens-v0_1: Add support for MSM8939")
> Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Cc: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data
2022-12-29 11:52 ` Dmitry Baryshkov
@ 2022-12-29 12:23 ` Konrad Dybcio
0 siblings, 0 replies; 36+ messages in thread
From: Konrad Dybcio @ 2022-12-29 12:23 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Andy Gross, Bjorn Andersson, Rob Herring, Krzysztof Kozlowski,
Amit Kucheria, Thara Gopinath, Rafael J. Wysocki, Daniel Lezcano,
Zhang Rui, Bryan O'Donoghue, Shawn Guo, linux-arm-msm,
linux-pm, devicetree
On 29.12.2022 12:52, Dmitry Baryshkov wrote:
> On Thu, 29 Dec 2022 at 13:47, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
>> On 29.12.2022 12:42, Dmitry Baryshkov wrote:
>>> On Thu, 29 Dec 2022 at 12:47, Konrad Dybcio <konrad.dybcio@linaro.org> wrote:
>>>> On 29.12.2022 04:00, Dmitry Baryshkov wrote:
>>>>> Add a unified function using nvmem cells for parsing the calibration
>>>>> data rather than parsing the calibration blob manually.
>>>>>
>>>>> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>>>>> ---
>>>>> drivers/thermal/qcom/tsens-v0_1.c | 15 ++++++
>>>>> drivers/thermal/qcom/tsens-v1.c | 11 ++++-
>>>>> drivers/thermal/qcom/tsens.c | 76 +++++++++++++++++++++++++++++++
>>>>> drivers/thermal/qcom/tsens.h | 5 ++
>>>>> 4 files changed, 106 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/thermal/qcom/tsens-v0_1.c b/drivers/thermal/qcom/tsens-v0_1.c
>>>>> index 579028ea48f4..6c9e491f9559 100644
>>>>> --- a/drivers/thermal/qcom/tsens-v0_1.c
>>>>> +++ b/drivers/thermal/qcom/tsens-v0_1.c
>>>>> @@ -229,6 +229,11 @@ static int calibrate_8916(struct tsens_priv *priv)
>>>>> u32 p1[5], p2[5];
>>>>> int mode = 0;
>>>>> u32 *qfprom_cdata, *qfprom_csel;
>>>>> + int ret;
>>>>> +
>>>>> + ret = tsens_calibrate_nvmem(priv, 3);
>>>>> + if (!ret)
>>>>> + return 0;
>>>>>
>>>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>>>> if (IS_ERR(qfprom_cdata))
>>>>> @@ -286,6 +291,11 @@ static int calibrate_8939(struct tsens_priv *priv)
>>>>> int mode = 0;
>>>>> u32 *qfprom_cdata;
>>>>> u32 cdata[4];
>>>>> + int ret;
>>>>> +
>>>>> + ret = tsens_calibrate_common(priv);
>>>>> + if (!ret)
>>>>> + return 0;
>>>>>
>>>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>>>> if (IS_ERR(qfprom_cdata))
>>>>> @@ -486,6 +496,11 @@ static int calibrate_9607(struct tsens_priv *priv)
>>>>> u32 p1[5], p2[5];
>>>>> int mode = 0;
>>>>> u32 *qfprom_cdata;
>>>>> + int ret;
>>>>> +
>>>>> + ret = tsens_calibrate_common(priv);
>>>>> + if (!ret)
>>>>> + return 0;
>>>>>
>>>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>>>> if (IS_ERR(qfprom_cdata))
>>>>> diff --git a/drivers/thermal/qcom/tsens-v1.c b/drivers/thermal/qcom/tsens-v1.c
>>>>> index 83c2853546d0..5bba75a845c5 100644
>>>>> --- a/drivers/thermal/qcom/tsens-v1.c
>>>>> +++ b/drivers/thermal/qcom/tsens-v1.c
>>>>> @@ -143,7 +143,11 @@ static int calibrate_v1(struct tsens_priv *priv)
>>>>> u32 p1[10], p2[10];
>>>>> u32 mode = 0, lsb = 0, msb = 0;
>>>>> u32 *qfprom_cdata;
>>>>> - int i;
>>>>> + int i, ret;
>>>>> +
>>>>> + ret = tsens_calibrate_common(priv);
>>>>> + if (!ret)
>>>>> + return 0;
>>>>>
>>>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>>>> if (IS_ERR(qfprom_cdata))
>>>>> @@ -209,6 +213,11 @@ static int calibrate_8976(struct tsens_priv *priv)
>>>>> u32 p1[11], p2[11];
>>>>> int mode = 0, tmp = 0;
>>>>> u32 *qfprom_cdata;
>>>>> + int ret;
>>>>> +
>>>>> + ret = tsens_calibrate_common(priv);
>>>>> + if (!ret)
>>>>> + return 0;
>>>>>
>>>>> qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
>>>>> if (IS_ERR(qfprom_cdata))
>>>>> diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
>>>>> index b191e19df93d..ce568a68de4a 100644
>>>>> --- a/drivers/thermal/qcom/tsens.c
>>>>> +++ b/drivers/thermal/qcom/tsens.c
>>>>> @@ -70,6 +70,82 @@ char *qfprom_read(struct device *dev, const char *cname)
>>>>> return ret;
>>>>> }
>>>>>
>>>>> +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift)
>>>>> +{
>>>>> + u32 mode;
>>>>> + u32 base1, base2;
>>>>> + u32 p1[MAX_SENSORS], p2[MAX_SENSORS];
>>>>> + char name[] = "sXX_pY"; /* s10_p1 */
>>>>> + int i, ret;
>>>>> +
>>>>> + if (priv->num_sensors > MAX_SENSORS)
>>>>> + return -EINVAL;
>>>>> +
>>>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "mode", &mode);
>>>>> + if (ret == -ENOENT)
>>>>> + dev_warn(priv->dev, "Please migrate to separate nvmem cells for calibration data\n");
>>>>> + if (ret < 0)
>>>>> + return ret;
>>>>> +
>>>>> + dev_dbg(priv->dev, "calibration mode is %d\n", mode);
>>>>> +
>>>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base1", &base1);
>>>>> + if (ret < 0)
>>>>> + return ret;
>>>>> +
>>>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, "base2", &base2);
>>>>> + if (ret < 0)
>>>>> + return ret;
>>>>> +
>>>>> + for (i = 0; i < priv->num_sensors; i++) {
>>>>> + ret = snprintf(name, sizeof(name), "s%d_p1", priv->sensor[i].hw_id);
>>>> I think you forgot to update the underscore to a hyphen here
>>>> (unless the nvmem api does some magic internally).
>>>
>>> No. Please see the nvmem-cell-names property of the tsens nodes. It
>>> uses underscores. Then OF code translates this sX_pY string into an
>>> index in the nvmem-cells array or phandles. The sX-pY@ZZ node name is
>>> not used during lookups at all.
>> Right, I overlooked that!
>>
>>>
>>>>
>>>> Konrad
>>>>> + if (ret < 0)
>>>>> + return ret;
>>>>> +
>>>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p1[i]);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> +
>>>>> + ret = snprintf(name, sizeof(name), "s%d_p2", priv->sensor[i].hw_id);
>>>>> + if (ret < 0)
>>>>> + return ret;
>>>>> +
>>>>> + ret = nvmem_cell_read_variable_le_u32(priv->dev, name, &p2[i]);
>>>>> + if (ret)
>>>>> + return ret;
>>>>> + }
>>>>> +
>>>>> + switch (mode) {
>>>>> + case ONE_PT_CALIB:
>>>>> + for (i = 0; i < priv->num_sensors; i++)
>>>>> + p1[i] = p1[i] + (base1 << shift);
>>>>> + break;
>>>>> + case TWO_PT_CALIB:
>>>>> + for (i = 0; i < priv->num_sensors; i++)
>>>>> + p2[i] = (p2[i] + base2) << shift;
>>>>> + fallthrough;
>>>>> + case ONE_PT_CALIB2:
>>>>> + for (i = 0; i < priv->num_sensors; i++)
>>>>> + p1[i] = (p1[i] + base1) << shift;
>>>>> + break;
>>>>> + default:
>>>>> + dev_dbg(priv->dev, "calibrationless mode\n");
>> This could be a dev_warn, as we usually don't expect it to happen.
>
> I'm not so sure here. Current code handles this case without any
> warnings, as one of the expected cases So, I don't think the rework
> should start emitting warnings.
Right, perhaps that's something to consider at a different time.
Konrad
>
>> Other than that:
>>
>> Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
>>
>> Konrad
>>>>> + for (i = 0; i < priv->num_sensors; i++) {
>>>>> + p1[i] = 500;
>>>>> + p2[i] = 780;
>>>>> + }
>>>>> + }
>>>>> +
>>>>> + compute_intercept_slope(priv, p1, p2, mode);
>>>>> +
>>>>> + return 0;
>>>>> +}
>>>>> +
>>>>> +int tsens_calibrate_common(struct tsens_priv *priv)
>>>>> +{
>>>>> + return tsens_calibrate_nvmem(priv, 2);
>>>>> +}
>>>>> +
>>>>> /*
>>>>> * Use this function on devices where slope and offset calculations
>>>>> * depend on calibration data read from qfprom. On others the slope
>>>>> diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h
>>>>> index 7dd5fc246894..645ae02438fa 100644
>>>>> --- a/drivers/thermal/qcom/tsens.h
>>>>> +++ b/drivers/thermal/qcom/tsens.h
>>>>> @@ -6,6 +6,7 @@
>>>>> #ifndef __QCOM_TSENS_H__
>>>>> #define __QCOM_TSENS_H__
>>>>>
>>>>> +#define NO_PT_CALIB 0x0
>>>>> #define ONE_PT_CALIB 0x1
>>>>> #define ONE_PT_CALIB2 0x2
>>>>> #define TWO_PT_CALIB 0x3
>>>>> @@ -17,6 +18,8 @@
>>>>> #define THRESHOLD_MAX_ADC_CODE 0x3ff
>>>>> #define THRESHOLD_MIN_ADC_CODE 0x0
>>>>>
>>>>> +#define MAX_SENSORS 16
>>>>> +
>>>>> #include <linux/interrupt.h>
>>>>> #include <linux/thermal.h>
>>>>> #include <linux/regmap.h>
>>>>> @@ -582,6 +585,8 @@ struct tsens_priv {
>>>>> };
>>>>>
>>>>> char *qfprom_read(struct device *dev, const char *cname);
>>>>> +int tsens_calibrate_nvmem(struct tsens_priv *priv, int shift);
>>>>> +int tsens_calibrate_common(struct tsens_priv *priv);
>>>>> void compute_intercept_slope(struct tsens_priv *priv, u32 *pt1, u32 *pt2, u32 mode);
>>>>> int init_common(struct tsens_priv *priv);
>>>>> int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp);
>>>
>>>
>>>
>
>
>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 13/20] thermal/drivers/tsens: Drop single-cell code for msm8939
2022-12-29 3:00 ` [PATCH v5 13/20] thermal/drivers/tsens: Drop single-cell code for msm8939 Dmitry Baryshkov
2022-12-29 11:27 ` Konrad Dybcio
@ 2022-12-29 12:27 ` Shawn Guo
1 sibling, 0 replies; 36+ messages in thread
From: Shawn Guo @ 2022-12-29 12:27 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Bryan O'Donoghue, linux-arm-msm, linux-pm, devicetree
On Thu, Dec 29, 2022 at 05:00:59AM +0200, Dmitry Baryshkov wrote:
> There is no dtsi file for msm8939 in the kernel sources. Drop the
> compatibility with unofficial dtsi and remove support for handling the
> single-cell calibration data on msm8939.
>
> Cc: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
> Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells
2022-12-29 11:49 ` Dmitry Baryshkov
@ 2023-01-01 15:56 ` Krzysztof Kozlowski
2023-01-01 19:18 ` Dmitry Baryshkov
0 siblings, 1 reply; 36+ messages in thread
From: Krzysztof Kozlowski @ 2023-01-01 15:56 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree
On 29/12/2022 12:49, Dmitry Baryshkov wrote:
> On Thu, 29 Dec 2022 at 10:35, Krzysztof Kozlowski
> <krzysztof.kozlowski@linaro.org> wrote:
>>
>> On 29/12/2022 04:00, Dmitry Baryshkov wrote:
>>> Allow specifying the exact calibration mode and calibration data as nvmem
>>> cells, rather than specifying just a single calibration data blob.
>>>
>>> Note, unlike the vendor kernel the calibration data uses hw_ids rather
>>> than software sensor indices (to match actual tsens usage in
>>> thermal zones).
>>>
>>> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>>> ---
>>> .../bindings/thermal/qcom-tsens.yaml | 95 +++++++++++++++++--
>>> 1 file changed, 85 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
>>> index f3660af0b3bf..4bb689f4602d 100644
>>> --- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
>>> +++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
>>> @@ -81,18 +81,63 @@ properties:
>>> maxItems: 2
>>>
>>> nvmem-cells:
>>> - minItems: 1
>>> - maxItems: 2
>>> - description:
>>> - Reference to an nvmem node for the calibration data
>>> + oneOf:
>>> + - minItems: 1
>>> + maxItems: 2
>>> + description:
>>> + Reference to an nvmem node for the calibration data
>>> + - minItems: 5
>>> + maxItems: 35
>>> + description: |
>>> + Reference to nvmem cells for the calibration mode, two calibration
>>> + bases and two cells per each sensor
>>>
>>> nvmem-cell-names:
>>> - minItems: 1
>>> - items:
>>> - - const: calib
>>> - - enum:
>>> - - calib_backup
>>> - - calib_sel
>>> + oneOf:
>>> + - minItems: 1
>>> + items:
>>> + - const: calib
>>> + - enum:
>>> + - calib_backup
>>> + - calib_sel
>>> + - minItems: 5
>>> + items:
>>> + enum:
>>
>> This should not be an enum but a list of const... unless "holes" are
>> expected (e.g. s0_p1 and s5_p2, without ones in between).
>
> Yes, this is the case. See the msm8916.dtsi changes. There is no
> sensor with hw_id 3, so the sequence is: ... s2_p1, s2_p2, s4_p1,
> s4_p2,....
>
> Same applies to the msm8939 (no sensor #4).
>
> Note: if there was support for the prefixItems, I'd have probably
> marked mode/base1/base2 to be the first items of the array.
Then how about list of const items and patterns? Would be similar number
of lines, just a bit more complicated pattern instead of simple string
to enum.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells
2023-01-01 15:56 ` Krzysztof Kozlowski
@ 2023-01-01 19:18 ` Dmitry Baryshkov
2023-01-02 8:32 ` Krzysztof Kozlowski
0 siblings, 1 reply; 36+ messages in thread
From: Dmitry Baryshkov @ 2023-01-01 19:18 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree
On 01/01/2023 17:56, Krzysztof Kozlowski wrote:
> On 29/12/2022 12:49, Dmitry Baryshkov wrote:
>> On Thu, 29 Dec 2022 at 10:35, Krzysztof Kozlowski
>> <krzysztof.kozlowski@linaro.org> wrote:
>>>
>>> On 29/12/2022 04:00, Dmitry Baryshkov wrote:
>>>> Allow specifying the exact calibration mode and calibration data as nvmem
>>>> cells, rather than specifying just a single calibration data blob.
>>>>
>>>> Note, unlike the vendor kernel the calibration data uses hw_ids rather
>>>> than software sensor indices (to match actual tsens usage in
>>>> thermal zones).
>>>>
>>>> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>>>> ---
>>>> .../bindings/thermal/qcom-tsens.yaml | 95 +++++++++++++++++--
>>>> 1 file changed, 85 insertions(+), 10 deletions(-)
>>>>
>>>> diff --git a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
>>>> index f3660af0b3bf..4bb689f4602d 100644
>>>> --- a/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
>>>> +++ b/Documentation/devicetree/bindings/thermal/qcom-tsens.yaml
>>>> @@ -81,18 +81,63 @@ properties:
>>>> maxItems: 2
>>>>
>>>> nvmem-cells:
>>>> - minItems: 1
>>>> - maxItems: 2
>>>> - description:
>>>> - Reference to an nvmem node for the calibration data
>>>> + oneOf:
>>>> + - minItems: 1
>>>> + maxItems: 2
>>>> + description:
>>>> + Reference to an nvmem node for the calibration data
>>>> + - minItems: 5
>>>> + maxItems: 35
>>>> + description: |
>>>> + Reference to nvmem cells for the calibration mode, two calibration
>>>> + bases and two cells per each sensor
>>>>
>>>> nvmem-cell-names:
>>>> - minItems: 1
>>>> - items:
>>>> - - const: calib
>>>> - - enum:
>>>> - - calib_backup
>>>> - - calib_sel
>>>> + oneOf:
>>>> + - minItems: 1
>>>> + items:
>>>> + - const: calib
>>>> + - enum:
>>>> + - calib_backup
>>>> + - calib_sel
>>>> + - minItems: 5
>>>> + items:
>>>> + enum:
>>>
>>> This should not be an enum but a list of const... unless "holes" are
>>> expected (e.g. s0_p1 and s5_p2, without ones in between).
>>
>> Yes, this is the case. See the msm8916.dtsi changes. There is no
>> sensor with hw_id 3, so the sequence is: ... s2_p1, s2_p2, s4_p1,
>> s4_p2,....
>>
>> Same applies to the msm8939 (no sensor #4).
>>
>> Note: if there was support for the prefixItems, I'd have probably
>> marked mode/base1/base2 to be the first items of the array.
>
> Then how about list of const items and patterns? Would be similar number
> of lines, just a bit more complicated pattern instead of simple string
> to enum.
Ack, this sounds good. I'll send it in the v6.
BTW: do you know if there are any plans to add support for prefixItems?
>
> Best regards,
> Krzysztof
>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells
2023-01-01 19:18 ` Dmitry Baryshkov
@ 2023-01-02 8:32 ` Krzysztof Kozlowski
0 siblings, 0 replies; 36+ messages in thread
From: Krzysztof Kozlowski @ 2023-01-02 8:32 UTC (permalink / raw)
To: Dmitry Baryshkov
Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Rob Herring,
Krzysztof Kozlowski, Amit Kucheria, Thara Gopinath,
Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
Bryan O'Donoghue, Shawn Guo, linux-arm-msm, linux-pm,
devicetree
On 01/01/2023 20:18, Dmitry Baryshkov wrote:
>>> Same applies to the msm8939 (no sensor #4).
>>>
>>> Note: if there was support for the prefixItems, I'd have probably
>>> marked mode/base1/base2 to be the first items of the array.
>>
>> Then how about list of const items and patterns? Would be similar number
>> of lines, just a bit more complicated pattern instead of simple string
>> to enum.
>
> Ack, this sounds good. I'll send it in the v6.
>
> BTW: do you know if there are any plans to add support for prefixItems?
Yes, I think Rob is planning to introduce it.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 36+ messages in thread
end of thread, other threads:[~2023-01-02 8:33 UTC | newest]
Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-29 3:00 [PATCH v5 00/20] thermal/drivers/tsens: specify nvmem cells in DT rather than parsing them manually Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 01/20] dt-bindings: thermal: tsens: add msm8956 compat Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 02/20] dt-bindings: thermal: tsens: support per-sensor calibration cells Dmitry Baryshkov
2022-12-29 8:35 ` Krzysztof Kozlowski
2022-12-29 11:49 ` Dmitry Baryshkov
2023-01-01 15:56 ` Krzysztof Kozlowski
2023-01-01 19:18 ` Dmitry Baryshkov
2023-01-02 8:32 ` Krzysztof Kozlowski
2022-12-29 3:00 ` [PATCH v5 03/20] dt-bindings: thermal: tsens: add per-sensor cells for msm8974 Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 04/20] thermal/drivers/tsens: Drop unnecessary hw_ids Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 05/20] thermal/drivers/tsens: Drop msm8976-specific defines Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 06/20] thermal/drivers/tsens: Sort out msm8976 vs msm8956 data Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 07/20] thermal/drivers/tsens: fix slope values for msm8939 Dmitry Baryshkov
2022-12-29 12:05 ` Shawn Guo
2022-12-29 3:00 ` [PATCH v5 08/20] thermal/drivers/tsens: limit num_sensors to 9 " Dmitry Baryshkov
2022-12-29 12:22 ` Shawn Guo
2022-12-29 3:00 ` [PATCH v5 09/20] thermal/drivers/tsens: Support using nvmem cells for calibration data Dmitry Baryshkov
2022-12-29 10:47 ` Konrad Dybcio
2022-12-29 11:42 ` Dmitry Baryshkov
2022-12-29 11:47 ` Konrad Dybcio
2022-12-29 11:52 ` Dmitry Baryshkov
2022-12-29 12:23 ` Konrad Dybcio
2022-12-29 3:00 ` [PATCH v5 10/20] thermal/drivers/tsens: Support using nvmem cells for msm8974 calibration Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 11/20] thermal/drivers/tsens: Rework legacy calibration data parsers Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 12/20] thermal/drivers/tsens: Drop single-cell code for mdm9607 Dmitry Baryshkov
2022-12-29 3:00 ` [PATCH v5 13/20] thermal/drivers/tsens: Drop single-cell code for msm8939 Dmitry Baryshkov
2022-12-29 11:27 ` Konrad Dybcio
2022-12-29 12:27 ` Shawn Guo
2022-12-29 3:01 ` [PATCH v5 14/20] thermal/drivers/tsens: Drop single-cell code for msm8976/msm8956 Dmitry Baryshkov
2022-12-29 11:27 ` Konrad Dybcio
2022-12-29 3:01 ` [PATCH v5 15/20] arm64: dts: qcom: msm8956: use SoC-specific compat for tsens Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 16/20] arm64: dts: qcom: msm8916: specify per-sensor calibration cells Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 17/20] arm64: dts: qcom: msm8976: " Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 18/20] arm64: dts: qcom: qcs404: " Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 19/20] ARM: dts: qcom-msm8974: " Dmitry Baryshkov
2022-12-29 3:01 ` [PATCH v5 20/20] ARM: dts: qcom-apq8084: " Dmitry Baryshkov
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.