Skip to content

Commit b6f739d

Browse files
stephan-ghdlezcano
authored andcommitted
thermal/drivers/qcom/tsens-v0_1: Add mdm9607 correction offsets
According to the msm-3.18 vendor kernel from Qualcomm, mdm9607 needs "correction factors" to adjust for additional offsets observed after the factory calibration values in the fuses [1, 2]. The fixed offsets should be applied unless there is a special calibration mode value that indicates that no offsets are needed [3]. Note that the new calibration mode values are called differently in this patch compared to the vendor kernel: - TSENS_TWO_POINT_CALIB_N_WA -> ONE_PT_CALIB2_NO_OFFSET - TSENS_TWO_POINT_CALIB_N_OFFSET_WA -> TWO_PT_CALIB_NO_OFFSET This is because close inspection of the calibration function [3] reveals that TSENS_TWO_POINT_CALIB_N_WA is actually a "one point" calibration because the if statements skip all "point2" related code for it. [1]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d9d2db1b82bf3f72f5de0803d55e6849eb5b671e [2]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/commit/d75aef53a760e8ff7bac54049d00c8b2ee1b193e [3]: https://git.codelinaro.org/clo/la/kernel/msm-3.18/-/blob/LE.UM.4.3.2.r1-04200-9x07/drivers/thermal/msm-tsens.c#L2987-3136 Fixes: a2149ab ("thermal/drivers/qcom/tsens-v0_1: Add support for MDM9607") Reviewed-by: Konrad Dybcio <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Signed-off-by: Stephan Gerhold <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6812d1d commit b6f739d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

drivers/thermal/qcom/tsens-v0_1.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ static int __init init_9607(struct tsens_priv *priv)
241241
for (i = 0; i < priv->num_sensors; ++i)
242242
priv->sensor[i].slope = 3000;
243243

244+
priv->sensor[0].p1_calib_offset = 1;
245+
priv->sensor[0].p2_calib_offset = 1;
246+
priv->sensor[1].p1_calib_offset = -4;
247+
priv->sensor[1].p2_calib_offset = -2;
248+
priv->sensor[2].p1_calib_offset = 4;
249+
priv->sensor[2].p2_calib_offset = 8;
250+
priv->sensor[3].p1_calib_offset = -3;
251+
priv->sensor[3].p2_calib_offset = -5;
252+
priv->sensor[4].p1_calib_offset = -4;
253+
priv->sensor[4].p2_calib_offset = -4;
254+
244255
return init_common(priv);
245256
}
246257

drivers/thermal/qcom/tsens.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
134134
p1[i] = p1[i] + (base1 << shift);
135135
break;
136136
case TWO_PT_CALIB:
137+
case TWO_PT_CALIB_NO_OFFSET:
137138
for (i = 0; i < priv->num_sensors; i++)
138139
p2[i] = (p2[i] + base2) << shift;
139140
fallthrough;
140141
case ONE_PT_CALIB2:
142+
case ONE_PT_CALIB2_NO_OFFSET:
141143
for (i = 0; i < priv->num_sensors; i++)
142144
p1[i] = (p1[i] + base1) << shift;
143145
break;
@@ -149,6 +151,18 @@ int tsens_read_calibration(struct tsens_priv *priv, int shift, u32 *p1, u32 *p2,
149151
}
150152
}
151153

154+
/* Apply calibration offset workaround except for _NO_OFFSET modes */
155+
switch (mode) {
156+
case TWO_PT_CALIB:
157+
for (i = 0; i < priv->num_sensors; i++)
158+
p2[i] += priv->sensor[i].p2_calib_offset;
159+
fallthrough;
160+
case ONE_PT_CALIB2:
161+
for (i = 0; i < priv->num_sensors; i++)
162+
p1[i] += priv->sensor[i].p1_calib_offset;
163+
break;
164+
}
165+
152166
return mode;
153167
}
154168

@@ -254,7 +268,7 @@ void compute_intercept_slope(struct tsens_priv *priv, u32 *p1,
254268

255269
if (!priv->sensor[i].slope)
256270
priv->sensor[i].slope = SLOPE_DEFAULT;
257-
if (mode == TWO_PT_CALIB) {
271+
if (mode == TWO_PT_CALIB || mode == TWO_PT_CALIB_NO_OFFSET) {
258272
/*
259273
* slope (m) = adc_code2 - adc_code1 (y2 - y1)/
260274
* temp_120_degc - temp_30_degc (x2 - x1)

drivers/thermal/qcom/tsens.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#define ONE_PT_CALIB 0x1
1111
#define ONE_PT_CALIB2 0x2
1212
#define TWO_PT_CALIB 0x3
13+
#define ONE_PT_CALIB2_NO_OFFSET 0x6
14+
#define TWO_PT_CALIB_NO_OFFSET 0x7
1315
#define CAL_DEGC_PT1 30
1416
#define CAL_DEGC_PT2 120
1517
#define SLOPE_FACTOR 1000
@@ -57,6 +59,8 @@ struct tsens_sensor {
5759
unsigned int hw_id;
5860
int slope;
5961
u32 status;
62+
int p1_calib_offset;
63+
int p2_calib_offset;
6064
};
6165

6266
/**

0 commit comments

Comments
 (0)