Skip to content

Commit 41161d8

Browse files
ukleineknunojsa
authored andcommitted
iio: adc: ltc2387: Fix duty offset calculation for fetching ADC values
t_{FIRSTCLK} must be at least 65 ns. Fix the driver to not request (approximately) 70 ps and add a description for not using the respective exact value from the datasheet. Fixes: 31d7a2a ("iio: adc: ltc2387: Fix the conversion signal phase") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
1 parent 7b3e9ea commit 41161d8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/iio/adc/ltc2387.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@
2626

2727
#define LTC2387_VREF 4096
2828
#define LTC2387_T_CNVH 8
29-
#define LTC2387_T_FIRSTCLK 70
29+
30+
/*
31+
* Minimal value for t_{FIRSTCLK} according to
32+
* https://www.analog.com/media/en/technical-documentation/data-sheets/238718fa.pdf
33+
* is 65 ns. Add some slack because there is some rounding involved in the PWM
34+
* driver. With the PWM driver rounding to the nearest possible value, targeting
35+
* 70 ns works for input clk rates >= 100 MHz.
36+
*/
37+
#define LTC2387_T_FIRSTCLK_NS 70
3038

3139
#define KHz 1000
3240
#define MHz (1000 * KHz)
@@ -173,7 +181,7 @@ static int ltc2387_set_sampling_freq(struct ltc2387_dev *ltc, int freq)
173181
clk_en_state = (struct pwm_state) {
174182
.period = cnv_state.period,
175183
.duty_cycle = ref_clk_period_ps * clk_en_time,
176-
.phase = cnv_state.phase + LTC2387_T_FIRSTCLK,
184+
.phase = cnv_state.phase + LTC2387_T_FIRSTCLK_NS * PSEC_PER_NSEC,
177185
.time_unit = PWM_UNIT_PSEC,
178186
.enabled = true,
179187
};

0 commit comments

Comments
 (0)