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
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
10 Drop custom get_temp function and use generic api.
12 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
13 Acked-by: Thara Gopinath <thara.gopinath@linaro.org>
15 drivers/thermal/qcom/tsens-8960.c | 56 +++++++++----------------------
16 1 file changed, 15 insertions(+), 41 deletions(-)
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
23 #define S9_STATUS_OFF 0x3674
24 #define S10_STATUS_OFF 0x3678
26 +/* Original slope - 200 to compensate mC to C inaccuracy */
27 +static u32 tsens_msm8960_slope[] = {
33 static int suspend_8960(struct tsens_priv *priv)
36 @@ -194,9 +201,7 @@ static int calibrate_8960(struct tsens_priv *priv)
41 - ssize_t num_read = priv->num_sensors;
42 - struct tsens_sensor *s = priv->sensor;
45 data = qfprom_read(priv->dev, "calib");
47 @@ -204,49 +209,18 @@ static int calibrate_8960(struct tsens_priv *priv)
51 - for (i = 0; i < num_read; i++, s++)
52 - s->offset = data[i];
53 + for (i = 0; i < priv->num_sensors; i++) {
55 + priv->sensor[i].slope = tsens_msm8960_slope[i];
58 + compute_intercept_slope(priv, p1, NULL, ONE_PT_CALIB);
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)
70 - slope = thermal_zone_get_slope(s->tzd);
71 - offset = CAL_MDEGC - slope * s->offset;
73 - return adc_code * slope + offset;
76 -static int get_temp_8960(const struct tsens_sensor *s, int *temp)
80 - struct tsens_priv *priv = s->priv;
81 - unsigned long timeout;
83 - timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
85 - ret = regmap_read(priv->tm_map, INT_STATUS_ADDR, &trdy);
88 - if (!(trdy & TRDY_MASK))
90 - ret = regmap_read(priv->tm_map, s->status, &code);
93 - *temp = code_to_mdegC(code, s);
95 - } while (time_before(jiffies, timeout));
100 static struct tsens_features tsens_8960_feat = {
103 @@ -315,7 +289,7 @@ static const struct reg_field tsens_8960_regfields[MAX_REGFIELDS] = {
104 static const struct tsens_ops ops_8960 = {
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,