Skip to content

Commit 0e58029

Browse files
kholkdlezcano
authored andcommitted
thermal: qcom: tsens-v1: Add support for MSM8956 and MSM8976
Add support for reading calibrated value from thermistors in MSM8956, MSM8976 and their APQ variants. Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Amit Kucheria <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 573ae2d commit 0e58029

File tree

3 files changed

+174
-2
lines changed

3 files changed

+174
-2
lines changed

drivers/thermal/qcom/tsens-v1.c

Lines changed: 170 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/bitops.h>
77
#include <linux/regmap.h>
88
#include <linux/delay.h>
9+
#include <linux/slab.h>
910
#include "tsens.h"
1011

1112
/* ----- SROT ------ */
@@ -20,6 +21,68 @@
2021
#define TM_HIGH_LOW_INT_STATUS_OFF 0x0088
2122
#define TM_HIGH_LOW_Sn_INT_THRESHOLD_OFF 0x0090
2223

24+
/* eeprom layout data for msm8956/76 (v1) */
25+
#define MSM8976_BASE0_MASK 0xff
26+
#define MSM8976_BASE1_MASK 0xff
27+
#define MSM8976_BASE1_SHIFT 8
28+
29+
#define MSM8976_S0_P1_MASK 0x3f00
30+
#define MSM8976_S1_P1_MASK 0x3f00000
31+
#define MSM8976_S2_P1_MASK 0x3f
32+
#define MSM8976_S3_P1_MASK 0x3f000
33+
#define MSM8976_S4_P1_MASK 0x3f00
34+
#define MSM8976_S5_P1_MASK 0x3f00000
35+
#define MSM8976_S6_P1_MASK 0x3f
36+
#define MSM8976_S7_P1_MASK 0x3f000
37+
#define MSM8976_S8_P1_MASK 0x1f8
38+
#define MSM8976_S9_P1_MASK 0x1f8000
39+
#define MSM8976_S10_P1_MASK 0xf8000000
40+
#define MSM8976_S10_P1_MASK_1 0x1
41+
42+
#define MSM8976_S0_P2_MASK 0xfc000
43+
#define MSM8976_S1_P2_MASK 0xfc000000
44+
#define MSM8976_S2_P2_MASK 0xfc0
45+
#define MSM8976_S3_P2_MASK 0xfc0000
46+
#define MSM8976_S4_P2_MASK 0xfc000
47+
#define MSM8976_S5_P2_MASK 0xfc000000
48+
#define MSM8976_S6_P2_MASK 0xfc0
49+
#define MSM8976_S7_P2_MASK 0xfc0000
50+
#define MSM8976_S8_P2_MASK 0x7e00
51+
#define MSM8976_S9_P2_MASK 0x7e00000
52+
#define MSM8976_S10_P2_MASK 0x7e
53+
54+
#define MSM8976_S0_P1_SHIFT 8
55+
#define MSM8976_S1_P1_SHIFT 20
56+
#define MSM8976_S2_P1_SHIFT 0
57+
#define MSM8976_S3_P1_SHIFT 12
58+
#define MSM8976_S4_P1_SHIFT 8
59+
#define MSM8976_S5_P1_SHIFT 20
60+
#define MSM8976_S6_P1_SHIFT 0
61+
#define MSM8976_S7_P1_SHIFT 12
62+
#define MSM8976_S8_P1_SHIFT 3
63+
#define MSM8976_S9_P1_SHIFT 15
64+
#define MSM8976_S10_P1_SHIFT 27
65+
#define MSM8976_S10_P1_SHIFT_1 0
66+
67+
#define MSM8976_S0_P2_SHIFT 14
68+
#define MSM8976_S1_P2_SHIFT 26
69+
#define MSM8976_S2_P2_SHIFT 6
70+
#define MSM8976_S3_P2_SHIFT 18
71+
#define MSM8976_S4_P2_SHIFT 14
72+
#define MSM8976_S5_P2_SHIFT 26
73+
#define MSM8976_S6_P2_SHIFT 6
74+
#define MSM8976_S7_P2_SHIFT 18
75+
#define MSM8976_S8_P2_SHIFT 9
76+
#define MSM8976_S9_P2_SHIFT 21
77+
#define MSM8976_S10_P2_SHIFT 1
78+
79+
#define MSM8976_CAL_SEL_MASK 0x3
80+
81+
#define MSM8976_CAL_DEGC_PT1 30
82+
#define MSM8976_CAL_DEGC_PT2 120
83+
#define MSM8976_SLOPE_FACTOR 1000
84+
#define MSM8976_SLOPE_DEFAULT 3200
85+
2386
/* eeprom layout data for qcs404/405 (v1) */
2487
#define BASE0_MASK 0x000007f8
2588
#define BASE1_MASK 0x0007f800
@@ -79,6 +142,30 @@
79142
#define CAL_SEL_MASK 7
80143
#define CAL_SEL_SHIFT 0
81144

145+
static void compute_intercept_slope_8976(struct tsens_priv *priv,
146+
u32 *p1, u32 *p2, u32 mode)
147+
{
148+
int i;
149+
150+
priv->sensor[0].slope = 3313;
151+
priv->sensor[1].slope = 3275;
152+
priv->sensor[2].slope = 3320;
153+
priv->sensor[3].slope = 3246;
154+
priv->sensor[4].slope = 3279;
155+
priv->sensor[5].slope = 3257;
156+
priv->sensor[6].slope = 3234;
157+
priv->sensor[7].slope = 3269;
158+
priv->sensor[8].slope = 3255;
159+
priv->sensor[9].slope = 3239;
160+
priv->sensor[10].slope = 3286;
161+
162+
for (i = 0; i < priv->num_sensors; i++) {
163+
priv->sensor[i].offset = (p1[i] * MSM8976_SLOPE_FACTOR) -
164+
(MSM8976_CAL_DEGC_PT1 *
165+
priv->sensor[i].slope);
166+
}
167+
}
168+
82169
static int calibrate_v1(struct tsens_priv *priv)
83170
{
84171
u32 base0 = 0, base1 = 0;
@@ -145,7 +232,74 @@ static int calibrate_v1(struct tsens_priv *priv)
145232
return 0;
146233
}
147234

148-
/* v1.x: qcs404,405 */
235+
static int calibrate_8976(struct tsens_priv *priv)
236+
{
237+
int base0 = 0, base1 = 0, i;
238+
u32 p1[11], p2[11];
239+
int mode = 0, tmp = 0;
240+
u32 *qfprom_cdata;
241+
242+
qfprom_cdata = (u32 *)qfprom_read(priv->dev, "calib");
243+
if (IS_ERR(qfprom_cdata)) {
244+
kfree(qfprom_cdata);
245+
return PTR_ERR(qfprom_cdata);
246+
}
247+
248+
mode = (qfprom_cdata[4] & MSM8976_CAL_SEL_MASK);
249+
dev_dbg(priv->dev, "calibration mode is %d\n", mode);
250+
251+
switch (mode) {
252+
case TWO_PT_CALIB:
253+
base1 = (qfprom_cdata[2] & MSM8976_BASE1_MASK) >> MSM8976_BASE1_SHIFT;
254+
p2[0] = (qfprom_cdata[0] & MSM8976_S0_P2_MASK) >> MSM8976_S0_P2_SHIFT;
255+
p2[1] = (qfprom_cdata[0] & MSM8976_S1_P2_MASK) >> MSM8976_S1_P2_SHIFT;
256+
p2[2] = (qfprom_cdata[1] & MSM8976_S2_P2_MASK) >> MSM8976_S2_P2_SHIFT;
257+
p2[3] = (qfprom_cdata[1] & MSM8976_S3_P2_MASK) >> MSM8976_S3_P2_SHIFT;
258+
p2[4] = (qfprom_cdata[2] & MSM8976_S4_P2_MASK) >> MSM8976_S4_P2_SHIFT;
259+
p2[5] = (qfprom_cdata[2] & MSM8976_S5_P2_MASK) >> MSM8976_S5_P2_SHIFT;
260+
p2[6] = (qfprom_cdata[3] & MSM8976_S6_P2_MASK) >> MSM8976_S6_P2_SHIFT;
261+
p2[7] = (qfprom_cdata[3] & MSM8976_S7_P2_MASK) >> MSM8976_S7_P2_SHIFT;
262+
p2[8] = (qfprom_cdata[4] & MSM8976_S8_P2_MASK) >> MSM8976_S8_P2_SHIFT;
263+
p2[9] = (qfprom_cdata[4] & MSM8976_S9_P2_MASK) >> MSM8976_S9_P2_SHIFT;
264+
p2[10] = (qfprom_cdata[5] & MSM8976_S10_P2_MASK) >> MSM8976_S10_P2_SHIFT;
265+
266+
for (i = 0; i < priv->num_sensors; i++)
267+
p2[i] = ((base1 + p2[i]) << 2);
268+
/* Fall through */
269+
case ONE_PT_CALIB2:
270+
base0 = qfprom_cdata[0] & MSM8976_BASE0_MASK;
271+
p1[0] = (qfprom_cdata[0] & MSM8976_S0_P1_MASK) >> MSM8976_S0_P1_SHIFT;
272+
p1[1] = (qfprom_cdata[0] & MSM8976_S1_P1_MASK) >> MSM8976_S1_P1_SHIFT;
273+
p1[2] = (qfprom_cdata[1] & MSM8976_S2_P1_MASK) >> MSM8976_S2_P1_SHIFT;
274+
p1[3] = (qfprom_cdata[1] & MSM8976_S3_P1_MASK) >> MSM8976_S3_P1_SHIFT;
275+
p1[4] = (qfprom_cdata[2] & MSM8976_S4_P1_MASK) >> MSM8976_S4_P1_SHIFT;
276+
p1[5] = (qfprom_cdata[2] & MSM8976_S5_P1_MASK) >> MSM8976_S5_P1_SHIFT;
277+
p1[6] = (qfprom_cdata[3] & MSM8976_S6_P1_MASK) >> MSM8976_S6_P1_SHIFT;
278+
p1[7] = (qfprom_cdata[3] & MSM8976_S7_P1_MASK) >> MSM8976_S7_P1_SHIFT;
279+
p1[8] = (qfprom_cdata[4] & MSM8976_S8_P1_MASK) >> MSM8976_S8_P1_SHIFT;
280+
p1[9] = (qfprom_cdata[4] & MSM8976_S9_P1_MASK) >> MSM8976_S9_P1_SHIFT;
281+
p1[10] = (qfprom_cdata[4] & MSM8976_S10_P1_MASK) >> MSM8976_S10_P1_SHIFT;
282+
tmp = (qfprom_cdata[5] & MSM8976_S10_P1_MASK_1) << MSM8976_S10_P1_SHIFT_1;
283+
p1[10] |= tmp;
284+
285+
for (i = 0; i < priv->num_sensors; i++)
286+
p1[i] = (((base0) + p1[i]) << 2);
287+
break;
288+
default:
289+
for (i = 0; i < priv->num_sensors; i++) {
290+
p1[i] = 500;
291+
p2[i] = 780;
292+
}
293+
break;
294+
}
295+
296+
compute_intercept_slope_8976(priv, p1, p2, mode);
297+
kfree(qfprom_cdata);
298+
299+
return 0;
300+
}
301+
302+
/* v1.x: msm8956,8976,qcs404,405 */
149303

150304
static const struct tsens_features tsens_v1_feat = {
151305
.ver_major = VER_1_X,
@@ -221,3 +375,18 @@ const struct tsens_plat_data data_tsens_v1 = {
221375
.feat = &tsens_v1_feat,
222376
.fields = tsens_v1_regfields,
223377
};
378+
379+
static const struct tsens_ops ops_8976 = {
380+
.init = init_common,
381+
.calibrate = calibrate_8976,
382+
.get_temp = get_temp_tsens_valid,
383+
};
384+
385+
/* Valid for both MSM8956 and MSM8976. Sensor ID 3 is unused. */
386+
const struct tsens_plat_data data_8976 = {
387+
.num_sensors = 11,
388+
.ops = &ops_8976,
389+
.hw_ids = (unsigned int[]){0, 1, 2, 4, 5, 6, 7, 8, 9, 10},
390+
.feat = &tsens_v1_feat,
391+
.fields = tsens_v1_regfields,
392+
};

drivers/thermal/qcom/tsens.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ static const struct of_device_id tsens_table[] = {
6262
}, {
6363
.compatible = "qcom,msm8974-tsens",
6464
.data = &data_8974,
65+
}, {
66+
.compatible = "qcom,msm8976-tsens",
67+
.data = &data_8976,
6568
}, {
6669
.compatible = "qcom,msm8996-tsens",
6770
.data = &data_8996,

drivers/thermal/qcom/tsens.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ extern const struct tsens_plat_data data_8960;
508508
extern const struct tsens_plat_data data_8916, data_8974;
509509

510510
/* TSENS v1 targets */
511-
extern const struct tsens_plat_data data_tsens_v1;
511+
extern const struct tsens_plat_data data_tsens_v1, data_8976;
512512

513513
/* TSENS v2 targets */
514514
extern const struct tsens_plat_data data_8996, data_tsens_v2;

0 commit comments

Comments
 (0)