Message ID | 20191127131008.18896-1-olivier.moysan@st.com (mailing list archive) |
---|---|
State | Mainlined |
Commit | f81ec5bf0cab29693980abbc983d0971e0efb0ea |
Headers | show |
Series | [v2] iio: adc: stm32-dfsdm: adapt sampling rate to oversampling ratio | expand |
On 11/27/19 2:10 PM, Olivier Moysan wrote: > Update sampling rate when oversampling ratio is changed > through the IIO ABI. > > Signed-off-by: Olivier Moysan <olivier.moysan@st.com> Hi Olivier, Acked-by: Fabrice Gasnier <fabrice.gasnier@st.com> Thanks, Fabrice > --- > changes in version 2: > - correct title > --- > drivers/iio/adc/stm32-dfsdm-adc.c | 32 ++++++++++++++++++------------- > 1 file changed, 19 insertions(+), 13 deletions(-) > > diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c > index 0339ecdd06bd..87a842507509 100644 > --- a/drivers/iio/adc/stm32-dfsdm-adc.c > +++ b/drivers/iio/adc/stm32-dfsdm-adc.c > @@ -1221,14 +1221,32 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, > unsigned int spi_freq; > int ret = -EINVAL; > > + switch (ch->src) { > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: > + spi_freq = adc->dfsdm->spi_master_freq; > + break; > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: > + spi_freq = adc->dfsdm->spi_master_freq / 2; > + break; > + default: > + spi_freq = adc->spi_freq; > + } > + > switch (mask) { > case IIO_CHAN_INFO_OVERSAMPLING_RATIO: > ret = iio_device_claim_direct_mode(indio_dev); > if (ret) > return ret; > + > ret = stm32_dfsdm_compute_all_osrs(indio_dev, val); > - if (!ret) > + if (!ret) { > + dev_dbg(&indio_dev->dev, > + "Sampling rate changed from (%u) to (%u)\n", > + adc->sample_freq, spi_freq / val); > adc->oversamp = val; > + adc->sample_freq = spi_freq / val; > + } > iio_device_release_direct_mode(indio_dev); > return ret; > > @@ -1240,18 +1258,6 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, > if (ret) > return ret; > > - switch (ch->src) { > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: > - spi_freq = adc->dfsdm->spi_master_freq; > - break; > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: > - spi_freq = adc->dfsdm->spi_master_freq / 2; > - break; > - default: > - spi_freq = adc->spi_freq; > - } > - > ret = dfsdm_adc_set_samp_freq(indio_dev, val, spi_freq); > iio_device_release_direct_mode(indio_dev); > return ret; >
Hi Jonathan, all, Kind reminder on this patch. Regards Olivier On 11/27/19 2:10 PM, Olivier Moysan wrote: > Update sampling rate when oversampling ratio is changed > through the IIO ABI. > > Signed-off-by: Olivier Moysan <olivier.moysan@st.com> > --- > changes in version 2: > - correct title > --- > drivers/iio/adc/stm32-dfsdm-adc.c | 32 ++++++++++++++++++------------- > 1 file changed, 19 insertions(+), 13 deletions(-) > > diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c > index 0339ecdd06bd..87a842507509 100644 > --- a/drivers/iio/adc/stm32-dfsdm-adc.c > +++ b/drivers/iio/adc/stm32-dfsdm-adc.c > @@ -1221,14 +1221,32 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, > unsigned int spi_freq; > int ret = -EINVAL; > > + switch (ch->src) { > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: > + spi_freq = adc->dfsdm->spi_master_freq; > + break; > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: > + spi_freq = adc->dfsdm->spi_master_freq / 2; > + break; > + default: > + spi_freq = adc->spi_freq; > + } > + > switch (mask) { > case IIO_CHAN_INFO_OVERSAMPLING_RATIO: > ret = iio_device_claim_direct_mode(indio_dev); > if (ret) > return ret; > + > ret = stm32_dfsdm_compute_all_osrs(indio_dev, val); > - if (!ret) > + if (!ret) { > + dev_dbg(&indio_dev->dev, > + "Sampling rate changed from (%u) to (%u)\n", > + adc->sample_freq, spi_freq / val); > adc->oversamp = val; > + adc->sample_freq = spi_freq / val; > + } > iio_device_release_direct_mode(indio_dev); > return ret; > > @@ -1240,18 +1258,6 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, > if (ret) > return ret; > > - switch (ch->src) { > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: > - spi_freq = adc->dfsdm->spi_master_freq; > - break; > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: > - spi_freq = adc->dfsdm->spi_master_freq / 2; > - break; > - default: > - spi_freq = adc->spi_freq; > - } > - > ret = dfsdm_adc_set_samp_freq(indio_dev, val, spi_freq); > iio_device_release_direct_mode(indio_dev); > return ret;
On Fri, 10 Jan 2020 10:06:13 +0000 Olivier MOYSAN <olivier.moysan@st.com> wrote: > Hi Jonathan, all, > > Kind reminder on this patch. Thanks! Applied to the togreg branch of iio.git and pushed out of testing to give the build bots a brief period to poke at it. Sorry again for the delay Thanks, Jonathan > Regards > Olivier > > On 11/27/19 2:10 PM, Olivier Moysan wrote: > > Update sampling rate when oversampling ratio is changed > > through the IIO ABI. > > > > Signed-off-by: Olivier Moysan <olivier.moysan@st.com> > > --- > > changes in version 2: > > - correct title > > --- > > drivers/iio/adc/stm32-dfsdm-adc.c | 32 ++++++++++++++++++------------- > > 1 file changed, 19 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c > > index 0339ecdd06bd..87a842507509 100644 > > --- a/drivers/iio/adc/stm32-dfsdm-adc.c > > +++ b/drivers/iio/adc/stm32-dfsdm-adc.c > > @@ -1221,14 +1221,32 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, > > unsigned int spi_freq; > > int ret = -EINVAL; > > > > + switch (ch->src) { > > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: > > + spi_freq = adc->dfsdm->spi_master_freq; > > + break; > > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: > > + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: > > + spi_freq = adc->dfsdm->spi_master_freq / 2; > > + break; > > + default: > > + spi_freq = adc->spi_freq; > > + } > > + > > switch (mask) { > > case IIO_CHAN_INFO_OVERSAMPLING_RATIO: > > ret = iio_device_claim_direct_mode(indio_dev); > > if (ret) > > return ret; > > + > > ret = stm32_dfsdm_compute_all_osrs(indio_dev, val); > > - if (!ret) > > + if (!ret) { > > + dev_dbg(&indio_dev->dev, > > + "Sampling rate changed from (%u) to (%u)\n", > > + adc->sample_freq, spi_freq / val); > > adc->oversamp = val; > > + adc->sample_freq = spi_freq / val; > > + } > > iio_device_release_direct_mode(indio_dev); > > return ret; > > > > @@ -1240,18 +1258,6 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, > > if (ret) > > return ret; > > > > - switch (ch->src) { > > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: > > - spi_freq = adc->dfsdm->spi_master_freq; > > - break; > > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: > > - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: > > - spi_freq = adc->dfsdm->spi_master_freq / 2; > > - break; > > - default: > > - spi_freq = adc->spi_freq; > > - } > > - > > ret = dfsdm_adc_set_samp_freq(indio_dev, val, spi_freq); > > iio_device_release_direct_mode(indio_dev); > > return ret;
diff --git a/drivers/iio/adc/stm32-dfsdm-adc.c b/drivers/iio/adc/stm32-dfsdm-adc.c index 0339ecdd06bd..87a842507509 100644 --- a/drivers/iio/adc/stm32-dfsdm-adc.c +++ b/drivers/iio/adc/stm32-dfsdm-adc.c @@ -1221,14 +1221,32 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, unsigned int spi_freq; int ret = -EINVAL; + switch (ch->src) { + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: + spi_freq = adc->dfsdm->spi_master_freq; + break; + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: + case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: + spi_freq = adc->dfsdm->spi_master_freq / 2; + break; + default: + spi_freq = adc->spi_freq; + } + switch (mask) { case IIO_CHAN_INFO_OVERSAMPLING_RATIO: ret = iio_device_claim_direct_mode(indio_dev); if (ret) return ret; + ret = stm32_dfsdm_compute_all_osrs(indio_dev, val); - if (!ret) + if (!ret) { + dev_dbg(&indio_dev->dev, + "Sampling rate changed from (%u) to (%u)\n", + adc->sample_freq, spi_freq / val); adc->oversamp = val; + adc->sample_freq = spi_freq / val; + } iio_device_release_direct_mode(indio_dev); return ret; @@ -1240,18 +1258,6 @@ static int stm32_dfsdm_write_raw(struct iio_dev *indio_dev, if (ret) return ret; - switch (ch->src) { - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL: - spi_freq = adc->dfsdm->spi_master_freq; - break; - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_FALLING: - case DFSDM_CHANNEL_SPI_CLOCK_INTERNAL_DIV2_RISING: - spi_freq = adc->dfsdm->spi_master_freq / 2; - break; - default: - spi_freq = adc->spi_freq; - } - ret = dfsdm_adc_set_samp_freq(indio_dev, val, spi_freq); iio_device_release_direct_mode(indio_dev); return ret;
Update sampling rate when oversampling ratio is changed through the IIO ABI. Signed-off-by: Olivier Moysan <olivier.moysan@st.com> --- changes in version 2: - correct title --- drivers/iio/adc/stm32-dfsdm-adc.c | 32 ++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)