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 --- a/drivers/thermal/qcom/tsens-8960.c
19 +++ b/drivers/thermal/qcom/tsens-8960.c
21 #define S9_STATUS_OFF 0x3674
22 #define S10_STATUS_OFF 0x3678
24 +/* Original slope - 200 to compensate mC to C inaccuracy */
25 +static u32 tsens_msm8960_slope[] = {
31 static int suspend_8960(struct tsens_priv *priv)
34 @@ -194,9 +201,7 @@ static int calibrate_8960(struct tsens_p
39 - ssize_t num_read = priv->num_sensors;
40 - struct tsens_sensor *s = priv->sensor;
43 data = qfprom_read(priv->dev, "calib");
45 @@ -204,49 +209,18 @@ static int calibrate_8960(struct tsens_p
49 - for (i = 0; i < num_read; i++, s++)
50 - s->offset = data[i];
51 + for (i = 0; i < priv->num_sensors; i++) {
53 + priv->sensor[i].slope = tsens_msm8960_slope[i];
56 + compute_intercept_slope(priv, p1, NULL, ONE_PT_CALIB);
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)
68 - slope = thermal_zone_get_slope(s->tzd);
69 - offset = CAL_MDEGC - slope * s->offset;
71 - return adc_code * slope + offset;
74 -static int get_temp_8960(const struct tsens_sensor *s, int *temp)
78 - struct tsens_priv *priv = s->priv;
79 - unsigned long timeout;
81 - timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
83 - ret = regmap_read(priv->tm_map, INT_STATUS_ADDR, &trdy);
86 - if (!(trdy & TRDY_MASK))
88 - ret = regmap_read(priv->tm_map, s->status, &code);
91 - *temp = code_to_mdegC(code, s);
93 - } while (time_before(jiffies, timeout));
98 static struct tsens_features tsens_8960_feat = {
101 @@ -315,7 +289,7 @@ static const struct reg_field tsens_8960
102 static const struct tsens_ops ops_8960 = {
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,