Skip to content

Commit dfc1193

Browse files
Ansueldlezcano
authored andcommitted
thermal/drivers/tsens: Replace custom 8960 apis with generic apis
Rework calibrate function to use common function. Derive the offset from a missing hardcoded slope table and the data from the nvmem calib efuses. Drop custom get_temp function and use generic api. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com> Acked-by: Thara Gopinath <thara.gopinath@linaro.org> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20210420183343.2272-7-ansuelsmth@gmail.com
1 parent 3d08f02 commit dfc1193

1 file changed

Lines changed: 15 additions & 41 deletions

File tree

drivers/thermal/qcom/tsens-8960.c

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@
6767
#define S9_STATUS_OFF 0x3674
6868
#define S10_STATUS_OFF 0x3678
6969

70+
/* Original slope - 350 to compensate mC to C inaccuracy */
71+
static u32 tsens_msm8960_slope[] = {
72+
826, 826, 804, 826,
73+
761, 782, 782, 849,
74+
782, 849, 782
75+
};
76+
7077
static int suspend_8960(struct tsens_priv *priv)
7178
{
7279
int ret;
@@ -194,59 +201,26 @@ static int calibrate_8960(struct tsens_priv *priv)
194201
{
195202
int i;
196203
char *data;
197-
198-
ssize_t num_read = priv->num_sensors;
199-
struct tsens_sensor *s = priv->sensor;
204+
u32 p1[11];
200205

201206
data = qfprom_read(priv->dev, "calib");
202207
if (IS_ERR(data))
203208
data = qfprom_read(priv->dev, "calib_backup");
204209
if (IS_ERR(data))
205210
return PTR_ERR(data);
206211

207-
for (i = 0; i < num_read; i++, s++)
208-
s->offset = data[i];
212+
for (i = 0; i < priv->num_sensors; i++) {
213+
p1[i] = data[i];
214+
priv->sensor[i].slope = tsens_msm8960_slope[i];
215+
}
216+
217+
compute_intercept_slope(priv, p1, NULL, ONE_PT_CALIB);
209218

210219
kfree(data);
211220

212221
return 0;
213222
}
214223

215-
/* Temperature on y axis and ADC-code on x-axis */
216-
static inline int code_to_mdegC(u32 adc_code, const struct tsens_sensor *s)
217-
{
218-
int slope, offset;
219-
220-
slope = thermal_zone_get_slope(s->tzd);
221-
offset = CAL_MDEGC - slope * s->offset;
222-
223-
return adc_code * slope + offset;
224-
}
225-
226-
static int get_temp_8960(const struct tsens_sensor *s, int *temp)
227-
{
228-
int ret;
229-
u32 code, trdy;
230-
struct tsens_priv *priv = s->priv;
231-
unsigned long timeout;
232-
233-
timeout = jiffies + usecs_to_jiffies(TIMEOUT_US);
234-
do {
235-
ret = regmap_read(priv->tm_map, INT_STATUS_ADDR, &trdy);
236-
if (ret)
237-
return ret;
238-
if (!(trdy & TRDY_MASK))
239-
continue;
240-
ret = regmap_read(priv->tm_map, s->status, &code);
241-
if (ret)
242-
return ret;
243-
*temp = code_to_mdegC(code, s);
244-
return 0;
245-
} while (time_before(jiffies, timeout));
246-
247-
return -ETIMEDOUT;
248-
}
249-
250224
static const struct reg_field tsens_8960_regfields[MAX_REGFIELDS] = {
251225
/* ----- SROT ------ */
252226
/* No VERSION information */
@@ -307,7 +281,7 @@ static const struct reg_field tsens_8960_regfields[MAX_REGFIELDS] = {
307281
static const struct tsens_ops ops_8960 = {
308282
.init = init_common,
309283
.calibrate = calibrate_8960,
310-
.get_temp = get_temp_8960,
284+
.get_temp = get_temp_common,
311285
.enable = enable_8960,
312286
.disable = disable_8960,
313287
.suspend = suspend_8960,

0 commit comments

Comments
 (0)