|
59 | 59 |
|
60 | 60 | /* Less significant bit position definitions */
|
61 | 61 | #define TS1_T0_POS 16
|
62 |
| -#define TS1_SMP_TIME_POS 16 |
63 | 62 | #define TS1_HITTHD_POS 16
|
64 | 63 | #define TS1_LITTHD_POS 0
|
65 | 64 | #define HSREF_CLK_DIV_POS 24
|
|
83 | 82 | #define ONE_MHZ 1000000
|
84 | 83 | #define POLL_TIMEOUT 5000
|
85 | 84 | #define STARTUP_TIME 40
|
86 |
| -#define TS1_T0_VAL0 30 |
87 |
| -#define TS1_T0_VAL1 130 |
| 85 | +#define TS1_T0_VAL0 30000 /* 30 celsius */ |
| 86 | +#define TS1_T0_VAL1 130000 /* 130 celsius */ |
88 | 87 | #define NO_HW_TRIG 0
|
89 |
| - |
90 |
| -/* The Thermal Framework expects millidegrees */ |
91 |
| -#define mcelsius(temp) ((temp) * 1000) |
92 |
| - |
93 |
| -/* The Sensor expects oC degrees */ |
94 |
| -#define celsius(temp) ((temp) / 1000) |
| 88 | +#define SAMPLING_TIME 15 |
95 | 89 |
|
96 | 90 | struct stm_thermal_sensor {
|
97 | 91 | struct device *dev;
|
@@ -280,27 +274,17 @@ static int stm_thermal_calculate_threshold(struct stm_thermal_sensor *sensor,
|
280 | 274 | int temp, u32 *th)
|
281 | 275 | {
|
282 | 276 | int freqM;
|
283 |
| - u32 sampling_time; |
284 |
| - |
285 |
| - /* Retrieve the number of periods to sample */ |
286 |
| - sampling_time = (readl_relaxed(sensor->base + DTS_CFGR1_OFFSET) & |
287 |
| - TS1_SMP_TIME_MASK) >> TS1_SMP_TIME_POS; |
288 | 277 |
|
289 | 278 | /* Figure out the CLK_PTAT frequency for a given temperature */
|
290 |
| - freqM = ((temp - sensor->t0) * sensor->ramp_coeff) |
291 |
| - + sensor->fmt0; |
292 |
| - |
293 |
| - dev_dbg(sensor->dev, "%s: freqM for threshold = %d Hz", |
294 |
| - __func__, freqM); |
| 279 | + freqM = ((temp - sensor->t0) * sensor->ramp_coeff) / 1000 + |
| 280 | + sensor->fmt0; |
295 | 281 |
|
296 | 282 | /* Figure out the threshold sample number */
|
297 |
| - *th = clk_get_rate(sensor->clk); |
| 283 | + *th = clk_get_rate(sensor->clk) * SAMPLING_TIME / freqM; |
298 | 284 | if (!*th)
|
299 | 285 | return -EINVAL;
|
300 | 286 |
|
301 |
| - *th = *th / freqM; |
302 |
| - |
303 |
| - *th *= sampling_time; |
| 287 | + dev_dbg(sensor->dev, "freqM=%d Hz, threshold=0x%x", freqM, *th); |
304 | 288 |
|
305 | 289 | return 0;
|
306 | 290 | }
|
@@ -368,40 +352,26 @@ static int stm_thermal_set_trips(void *data, int low, int high)
|
368 | 352 | static int stm_thermal_get_temp(void *data, int *temp)
|
369 | 353 | {
|
370 | 354 | struct stm_thermal_sensor *sensor = data;
|
371 |
| - u32 sampling_time; |
| 355 | + u32 periods; |
372 | 356 | int freqM, ret;
|
373 | 357 |
|
374 | 358 | if (sensor->mode != THERMAL_DEVICE_ENABLED)
|
375 | 359 | return -EAGAIN;
|
376 | 360 |
|
377 |
| - /* Retrieve the number of samples */ |
378 |
| - ret = readl_poll_timeout(sensor->base + DTS_DR_OFFSET, freqM, |
379 |
| - (freqM & TS1_MFREQ_MASK), STARTUP_TIME, |
380 |
| - POLL_TIMEOUT); |
381 |
| - |
| 361 | + /* Retrieve the number of periods sampled */ |
| 362 | + ret = readl_relaxed_poll_timeout(sensor->base + DTS_DR_OFFSET, periods, |
| 363 | + (periods & TS1_MFREQ_MASK), |
| 364 | + STARTUP_TIME, POLL_TIMEOUT); |
382 | 365 | if (ret)
|
383 | 366 | return ret;
|
384 | 367 |
|
385 |
| - if (!freqM) |
386 |
| - return -ENODATA; |
387 |
| - |
388 |
| - /* Retrieve the number of periods sampled */ |
389 |
| - sampling_time = (readl_relaxed(sensor->base + DTS_CFGR1_OFFSET) & |
390 |
| - TS1_SMP_TIME_MASK) >> TS1_SMP_TIME_POS; |
391 |
| - |
392 |
| - /* Figure out the number of samples per period */ |
393 |
| - freqM /= sampling_time; |
394 |
| - |
395 | 368 | /* Figure out the CLK_PTAT frequency */
|
396 |
| - freqM = clk_get_rate(sensor->clk) / freqM; |
| 369 | + freqM = (clk_get_rate(sensor->clk) * SAMPLING_TIME) / periods; |
397 | 370 | if (!freqM)
|
398 | 371 | return -EINVAL;
|
399 | 372 |
|
400 |
| - dev_dbg(sensor->dev, "%s: freqM=%d\n", __func__, freqM); |
401 |
| - |
402 | 373 | /* Figure out the temperature in mili celsius */
|
403 |
| - *temp = mcelsius(sensor->t0 + ((freqM - sensor->fmt0) / |
404 |
| - sensor->ramp_coeff)); |
| 374 | + *temp = (freqM - sensor->fmt0) * 1000 / sensor->ramp_coeff + sensor->t0; |
405 | 375 |
|
406 | 376 | return 0;
|
407 | 377 | }
|
|
0 commit comments