|
50 | 50 | #define SUN8I_THS_CTRL2_T_ACQ1(x) ((GENMASK(15, 0) & (x)) << 16)
|
51 | 51 | #define SUN8I_THS_DATA_IRQ_STS(x) BIT(x + 8)
|
52 | 52 |
|
53 |
| -#define SUN50I_THS_CTRL0_T_ACQ(x) ((GENMASK(15, 0) & (x)) << 16) |
| 53 | +#define SUN50I_THS_CTRL0_T_ACQ(x) (GENMASK(15, 0) & ((x) - 1)) |
| 54 | +#define SUN50I_THS_CTRL0_T_SAMPLE_PER(x) ((GENMASK(15, 0) & ((x) - 1)) << 16) |
54 | 55 | #define SUN50I_THS_FILTER_EN BIT(2)
|
55 | 56 | #define SUN50I_THS_FILTER_TYPE(x) (GENMASK(1, 0) & (x))
|
56 | 57 | #define SUN50I_H6_THS_PC_TEMP_PERIOD(x) ((GENMASK(19, 0) & (x)) << 12)
|
@@ -410,25 +411,27 @@ static int sun8i_h3_thermal_init(struct ths_device *tmdev)
|
410 | 411 | return 0;
|
411 | 412 | }
|
412 | 413 |
|
413 |
| -/* |
414 |
| - * Without this undocumented value, the returned temperatures would |
415 |
| - * be higher than real ones by about 20C. |
416 |
| - */ |
417 |
| -#define SUN50I_H6_CTRL0_UNK 0x0000002f |
418 |
| - |
419 | 414 | static int sun50i_h6_thermal_init(struct ths_device *tmdev)
|
420 | 415 | {
|
421 | 416 | int val;
|
422 | 417 |
|
423 | 418 | /*
|
424 |
| - * T_acq = 20us |
425 |
| - * clkin = 24MHz |
426 |
| - * |
427 |
| - * x = T_acq * clkin - 1 |
428 |
| - * = 479 |
| 419 | + * The manual recommends an overall sample frequency of 50 KHz (20us, |
| 420 | + * 480 cycles at 24 MHz), which provides plenty of time for both the |
| 421 | + * acquisition time (>24 cycles) and the actual conversion time |
| 422 | + * (>14 cycles). |
| 423 | + * The lower half of the CTRL register holds the "acquire time", in |
| 424 | + * clock cycles, which the manual recommends to be 2us: |
| 425 | + * 24MHz * 2us = 48 cycles. |
| 426 | + * The high half of THS_CTRL encodes the sample frequency, in clock |
| 427 | + * cycles: 24MHz * 20us = 480 cycles. |
| 428 | + * This is explained in the H616 manual, but apparently wrongly |
| 429 | + * described in the H6 manual, although the BSP code does the same |
| 430 | + * for both SoCs. |
429 | 431 | */
|
430 | 432 | regmap_write(tmdev->regmap, SUN50I_THS_CTRL0,
|
431 |
| - SUN50I_H6_CTRL0_UNK | SUN50I_THS_CTRL0_T_ACQ(479)); |
| 433 | + SUN50I_THS_CTRL0_T_ACQ(48) | |
| 434 | + SUN50I_THS_CTRL0_T_SAMPLE_PER(480)); |
432 | 435 | /* average over 4 samples */
|
433 | 436 | regmap_write(tmdev->regmap, SUN50I_H6_THS_MFC,
|
434 | 437 | SUN50I_THS_FILTER_EN |
|
|
0 commit comments