Skip to content

Commit d58109d

Browse files
Fabrice Gasnierjic23
authored andcommitted
iio: adc: stm32-dfsdm: fix sample rate for div2 spi clock
When channel clk source is set to "CLKOUT_F" or "CLKOUT_R" (e.g. div2), sample rate is currently set to half the requested value. Fixes: eca9498 ("IIO: ADC: add stm32 DFSDM support for PDM microphone") Signed-off-by: Fabrice Gasnier <[email protected]> Acked-by: Arnaud Pouliquen <[email protected]> Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 7531cf5 commit d58109d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/iio/adc/stm32-dfsdm-adc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
771771
struct stm32_dfsdm_adc *adc = iio_priv(indio_dev);
772772
struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id];
773773
struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel];
774-
unsigned int spi_freq = adc->spi_freq;
774+
unsigned int spi_freq;
775775
int ret = -EINVAL;
776776

777777
switch (mask) {
@@ -785,8 +785,18 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev,
785785
case IIO_CHAN_INFO_SAMP_FREQ:
786786
if (!val)
787787
return -EINVAL;
788-
if (ch->src != DFSDM_CHANNEL_SPI_CLOCK_EXTERNAL)
788+
789+
switch (ch->src) {
790+
case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL:
789791
spi_freq = adc->dfsdm->spi_master_freq;
792+
break;
793+
case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING:
794+
case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING:
795+
spi_freq = adc->dfsdm->spi_master_freq / 2;
796+
break;
797+
default:
798+
spi_freq = adc->spi_freq;
799+
}
790800

791801
if (spi_freq % val)
792802
dev_warn(&indio_dev->dev,

0 commit comments

Comments
 (0)