a82f5969542b2cac931b96efd7e58202f93cfb15
[openwrt/staging/ldir.git] / target / linux / ipq806x / patches-5.10 / 104-6-drivers-thermal-tsens-Replace-custom-8960-apis-with-.patch
1 From 1ff9f982051759e0387e8c7e793b49c48eae291d Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Wed, 25 Nov 2020 17:11:05 +0100
4 Subject: [PATCH 06/10] drivers: thermal: tsens: Replace custom 8960 apis with
5 generic apis
6
7 Rework calibrate function to use common function. Derive the offset from
8 a missing hardcoded slope table and the data from the nvmem calib
9 efuses.
10 Drop custom get_temp function and use generic api.
11
12 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
13 Acked-by: Thara Gopinath <thara.gopinath@linaro.org>
14 ---
15 drivers/thermal/qcom/tsens-8960.c | 56 +++++++++----------------------
16 1 file changed, 15 insertions(+), 41 deletions(-)
17
18 --- a/drivers/thermal/qcom/tsens-8960.c
19 +++ b/drivers/thermal/qcom/tsens-8960.c
20 @@ -67,6 +67,13 @@
21 #define S9_STATUS_OFF 0x3674
22 #define S10_STATUS_OFF 0x3678
23
24 +/* Original slope - 200 to compensate mC to C inaccuracy */
25 +static u32 tsens_msm8960_slope[] = {
26 + 976, 976, 954, 976,
27 + 911, 932, 932, 999,
28 + 932, 999, 932
29 + };
30 +
31 static int suspend_8960(struct tsens_priv *priv)
32 {
33 int ret;
34 @@ -194,9 +201,7 @@ static int calibrate_8960(struct tsens_p
35 {
36 int i;
37 char *data;
38 -
39 - ssize_t num_read = priv->num_sensors;
40 - struct tsens_sensor *s = priv->sensor;
41 + u32 p1[11];
42
43 data = qfprom_read(priv->dev, "calib");
44 if (IS_ERR(data))
45 @@ -204,49 +209,18 @@ static int calibrate_8960(struct tsens_p
46 if (IS_ERR(data))
47 return PTR_ERR(data);
48
49 - for (i = 0; i < num_read; i++, s++)
50 - s->offset = data[i];
51 + for (i = 0; i < priv->num_sensors; i++) {
52 + p1[i] = data[i];
53 + priv->sensor[i].slope = tsens_msm8960_slope[i];
54 + }
55 +
56 + compute_intercept_slope(priv, p1, NULL, ONE_PT_CALIB);
57
58 kfree(data);
59
60 return 0;
61 }
62
63 -/* Temperature on y axis and ADC-code on x-axis */
64 -static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s)
65 -{
66 - int slope, offset;
67 -
68 - slope = thermal_zone_get_slope(s->tzd);
69 - offset = CAL_MDEGC - slope * s->offset;
70 -
71 - return adc_code * slope + offset;
72 -}
73 -
74 -static int get_temp_8960(const struct tsens_sensor *s, int *temp)
75 -{
76 - int ret;
77 - u32 code, trdy;
78 - struct tsens_priv *priv = s->priv;
79 - unsigned long timeout;
80 -
81 - timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
82 - do {
83 - ret = regmap_read(priv->tm_map, INT_STATUS_ADDR, &trdy);
84 - if (ret)
85 - return ret;
86 - if (!(trdy & TRDY_MASK))
87 - continue;
88 - ret = regmap_read(priv->tm_map, s->status, &code);
89 - if (ret)
90 - return ret;
91 - *temp = code_to_mdegC(code, s);
92 - return 0;
93 - } while (time_before(jiffies, timeout));
94 -
95 - return -ETIMEDOUT;
96 -}
97 -
98 static struct tsens_features tsens_8960_feat = {
99 .ver_major = VER_0,
100 .crit_int = 0,
101 @@ -315,7 +289,7 @@ static const struct reg_field tsens_8960
102 static const struct tsens_ops ops_8960 = {
103 .init = init_common,
104 .calibrate = calibrate_8960,
105 - .get_temp = get_temp_8960,
106 + .get_temp = get_temp_common,
107 .enable = enable_8960,
108 .disable = disable_8960,
109 .suspend = suspend_8960,