Skip to content

Commit ef92dc8

Browse files
justephnunojsa
authored andcommitted
iio: adc: ad7380: fix oversampling formula
The formula in the datasheet for oversampling time conversion seems to be valid when device is at full speed using the maximum number of SDO lines. The driver currently support only 1 SDO line. The correct formula is: t_convert = T_CONVERT_0_NS + T_CONVERT_X_NS*(x - 1)*num_channel/number_of_sdo_lines. It will produce larger delays than what is currently set, but some devices actually require it. Signed-off-by: Julien Stephan <jstephan@baylibre.com> Reviewed-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20241030-ad7380-add-adaq4380-4-support-v4-2-864ff02babae@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 80979ce commit ef92dc8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/iio/adc/ad7380.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
#define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */
7878
#define T_POWERUP_US 5000 /* Power up */
7979

80+
/*
81+
* AD738x support several SDO lines to increase throughput, but driver currently
82+
* supports only 1 SDO line (standard SPI transaction)
83+
*/
84+
#define AD7380_NUM_SDO_LINES 1
85+
8086
struct ad7380_timing_specs {
8187
const unsigned int t_csh_ns; /* CS minimum high time */
8288
};
@@ -649,7 +655,8 @@ static int ad7380_set_ch(struct ad7380_state *st, unsigned int ch)
649655

650656
if (st->oversampling_ratio > 1)
651657
xfer.delay.value = T_CONVERT_0_NS +
652-
T_CONVERT_X_NS * (st->oversampling_ratio - 1);
658+
T_CONVERT_X_NS * (st->oversampling_ratio - 1) *
659+
st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES;
653660

654661
return spi_sync_transfer(st->spi, &xfer, 1);
655662
}
@@ -672,7 +679,8 @@ static void ad7380_update_xfers(struct ad7380_state *st,
672679
*/
673680
if (st->oversampling_ratio > 1)
674681
t_convert = T_CONVERT_0_NS + T_CONVERT_X_NS *
675-
(st->oversampling_ratio - 1);
682+
(st->oversampling_ratio - 1) *
683+
st->chip_info->num_simult_channels / AD7380_NUM_SDO_LINES;
676684

677685
if (st->seq) {
678686
xfer[0].delay.value = xfer[1].delay.value = t_convert;
@@ -1021,7 +1029,8 @@ static int ad7380_init(struct ad7380_state *st, bool external_ref_en)
10211029
/* SPI 1-wire mode */
10221030
return regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG2,
10231031
AD7380_CONFIG2_SDO,
1024-
FIELD_PREP(AD7380_CONFIG2_SDO, 1));
1032+
FIELD_PREP(AD7380_CONFIG2_SDO,
1033+
AD7380_NUM_SDO_LINES));
10251034
}
10261035

10271036
static int ad7380_probe(struct spi_device *spi)

0 commit comments

Comments
 (0)