657f8b801b15bb0c42232c6c61f11ced7e54fb01
[openwrt/staging/zorun.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 diff --git a/drivers/thermal/qcom/tsens-8960.c b/drivers/thermal/qcom/tsens-8960.c
19 index 95fcccafae14..9cc8a7dd23ae 100644
20 --- a/drivers/thermal/qcom/tsens-8960.c
21 +++ b/drivers/thermal/qcom/tsens-8960.c
22 @@ -67,6 +67,13 @@
23 #define S9_STATUS_OFF 0x3674
24 #define S10_STATUS_OFF 0x3678
25
26 +/* Original slope - 200 to compensate mC to C inaccuracy */
27 +static u32 tsens_msm8960_slope[] = {
28 + 976, 976, 954, 976,
29 + 911, 932, 932, 999,
30 + 932, 999, 932
31 + };
32 +
33 static int suspend_8960(struct tsens_priv *priv)
34 {
35 int ret;
36 @@ -194,9 +201,7 @@ static int calibrate_8960(struct tsens_priv *priv)
37 {
38 int i;
39 char *data;
40 -
41 - ssize_t num_read = priv->num_sensors;
42 - struct tsens_sensor *s = priv->sensor;
43 + u32 p1[11];
44
45 data = qfprom_read(priv->dev, "calib");
46 if (IS_ERR(data))
47 @@ -204,49 +209,18 @@ static int calibrate_8960(struct tsens_priv *priv)
48 if (IS_ERR(data))
49 return PTR_ERR(data);
50
51 - for (i = 0; i < num_read; i++, s++)
52 - s->offset = data[i];
53 + for (i = 0; i < priv->num_sensors; i++) {
54 + p1[i] = data[i];
55 + priv->sensor[i].slope = tsens_msm8960_slope[i];
56 + }
57 +
58 + compute_intercept_slope(priv, p1, NULL, ONE_PT_CALIB);
59
60 kfree(data);
61
62 return 0;
63 }
64
65 -/* Temperature on y axis and ADC-code on x-axis */
66 -static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s)
67 -{
68 - int slope, offset;
69 -
70 - slope = thermal_zone_get_slope(s->tzd);
71 - offset = CAL_MDEGC - slope * s->offset;
72 -
73 - return adc_code * slope + offset;
74 -}
75 -
76 -static int get_temp_8960(const struct tsens_sensor *s, int *temp)
77 -{
78 - int ret;
79 - u32 code, trdy;
80 - struct tsens_priv *priv = s->priv;
81 - unsigned long timeout;
82 -
83 - timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
84 - do {
85 - ret = regmap_read(priv->tm_map, INT_STATUS_ADDR, &trdy);
86 - if (ret)
87 - return ret;
88 - if (!(trdy & TRDY_MASK))
89 - continue;
90 - ret = regmap_read(priv->tm_map, s->status, &code);
91 - if (ret)
92 - return ret;
93 - *temp = code_to_mdegC(code, s);
94 - return 0;
95 - } while (time_before(jiffies, timeout));
96 -
97 - return -ETIMEDOUT;
98 -}
99 -
100 static struct tsens_features tsens_8960_feat = {
101 .ver_major = VER_0,
102 .crit_int = 0,
103 @@ -315,7 +289,7 @@ static const struct reg_field tsens_8960_regfields[MAX_REGFIELDS] = {
104 static const struct tsens_ops ops_8960 = {
105 .init = init_common,
106 .calibrate = calibrate_8960,
107 - .get_temp = get_temp_8960,
108 + .get_temp = get_temp_common,
109 .enable = enable_8960,
110 .disable = disable_8960,
111 .suspend = suspend_8960,
112 --
113 2.30.2
114