Lines Matching refs:adc
315 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_compute_all_osrs() local
316 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id]; in stm32_dfsdm_compute_all_osrs()
336 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_start_channel() local
337 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_start_channel()
342 for_each_set_bit(bit, &adc->smask, sizeof(adc->smask) * BITS_PER_BYTE) { in stm32_dfsdm_start_channel()
356 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_stop_channel() local
357 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_stop_channel()
361 for_each_set_bit(bit, &adc->smask, sizeof(adc->smask) * BITS_PER_BYTE) { in stm32_dfsdm_stop_channel()
391 static int stm32_dfsdm_start_filter(struct stm32_dfsdm_adc *adc, in stm32_dfsdm_start_filter() argument
395 struct stm32_dfsdm *dfsdm = adc->dfsdm; in stm32_dfsdm_start_filter()
405 if (adc->nconv > 1 || trig) in stm32_dfsdm_start_filter()
426 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_filter_set_trig() local
427 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_filter_set_trig()
455 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_channels_configure() local
456 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_channels_configure()
457 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id]; in stm32_dfsdm_channels_configure()
469 if (adc->nconv == 1 && !trig && iio_buffer_enabled(indio_dev)) { in stm32_dfsdm_channels_configure()
482 for_each_set_bit(bit, &adc->smask, in stm32_dfsdm_channels_configure()
483 sizeof(adc->smask) * BITS_PER_BYTE) { in stm32_dfsdm_channels_configure()
501 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_filter_configure() local
502 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_filter_configure()
503 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id]; in stm32_dfsdm_filter_configure()
556 if (adc->nconv == 1 && !trig) { in stm32_dfsdm_filter_configure()
557 bit = __ffs(adc->smask); in stm32_dfsdm_filter_configure()
570 for_each_set_bit(bit, &adc->smask, in stm32_dfsdm_filter_configure()
571 sizeof(adc->smask) * BITS_PER_BYTE) { in stm32_dfsdm_filter_configure()
580 cr1 = DFSDM_CR1_JSCAN((adc->nconv > 1) ? 1 : 0); in stm32_dfsdm_filter_configure()
673 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in dfsdm_adc_audio_get_spiclk() local
675 return snprintf(buf, PAGE_SIZE, "%d\n", adc->spi_freq); in dfsdm_adc_audio_get_spiclk()
682 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in dfsdm_adc_set_samp_freq() local
696 adc->sample_freq = spi_freq / oversamp; in dfsdm_adc_set_samp_freq()
697 adc->oversamp = oversamp; in dfsdm_adc_set_samp_freq()
707 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in dfsdm_adc_audio_set_spiclk() local
708 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel]; in dfsdm_adc_audio_set_spiclk()
709 unsigned int sample_freq = adc->sample_freq; in dfsdm_adc_audio_set_spiclk()
730 adc->spi_freq = spi_freq; in dfsdm_adc_audio_set_spiclk()
738 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_start_conv() local
739 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_start_conv()
742 ret = stm32_dfsdm_channels_configure(indio_dev, adc->fl_id, trig); in stm32_dfsdm_start_conv()
750 ret = stm32_dfsdm_filter_configure(indio_dev, adc->fl_id, trig); in stm32_dfsdm_start_conv()
754 ret = stm32_dfsdm_start_filter(adc, adc->fl_id, trig); in stm32_dfsdm_start_conv()
761 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), in stm32_dfsdm_start_conv()
771 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_stop_conv() local
772 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_stop_conv()
774 stm32_dfsdm_stop_filter(adc->dfsdm, adc->fl_id); in stm32_dfsdm_stop_conv()
776 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), in stm32_dfsdm_stop_conv()
785 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_set_watermark() local
796 adc->buf_sz = min(rx_buf_sz, watermark * 2 * adc->nconv); in stm32_dfsdm_set_watermark()
801 static unsigned int stm32_dfsdm_adc_dma_residue(struct stm32_dfsdm_adc *adc) in stm32_dfsdm_adc_dma_residue() argument
806 status = dmaengine_tx_status(adc->dma_chan, in stm32_dfsdm_adc_dma_residue()
807 adc->dma_chan->cookie, in stm32_dfsdm_adc_dma_residue()
811 unsigned int i = adc->buf_sz - state.residue; in stm32_dfsdm_adc_dma_residue()
815 if (i >= adc->bufi) in stm32_dfsdm_adc_dma_residue()
816 size = i - adc->bufi; in stm32_dfsdm_adc_dma_residue()
818 size = adc->buf_sz + i - adc->bufi; in stm32_dfsdm_adc_dma_residue()
826 static inline void stm32_dfsdm_process_data(struct stm32_dfsdm_adc *adc, in stm32_dfsdm_process_data() argument
829 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id]; in stm32_dfsdm_process_data()
831 unsigned int i = adc->nconv; in stm32_dfsdm_process_data()
853 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_dma_buffer_done() local
854 int available = stm32_dfsdm_adc_dma_residue(adc); in stm32_dfsdm_dma_buffer_done()
867 adc->bufi, available); in stm32_dfsdm_dma_buffer_done()
868 old_pos = adc->bufi; in stm32_dfsdm_dma_buffer_done()
871 s32 *buffer = (s32 *)&adc->rx_buf[adc->bufi]; in stm32_dfsdm_dma_buffer_done()
873 stm32_dfsdm_process_data(adc, buffer); in stm32_dfsdm_dma_buffer_done()
876 adc->bufi += indio_dev->scan_bytes; in stm32_dfsdm_dma_buffer_done()
877 if (adc->bufi >= adc->buf_sz) { in stm32_dfsdm_dma_buffer_done()
878 if (adc->cb) in stm32_dfsdm_dma_buffer_done()
879 adc->cb(&adc->rx_buf[old_pos], in stm32_dfsdm_dma_buffer_done()
880 adc->buf_sz - old_pos, adc->cb_priv); in stm32_dfsdm_dma_buffer_done()
881 adc->bufi = 0; in stm32_dfsdm_dma_buffer_done()
893 if (adc->dev_data->type == DFSDM_IIO) in stm32_dfsdm_dma_buffer_done()
896 if (adc->cb) in stm32_dfsdm_dma_buffer_done()
897 adc->cb(&adc->rx_buf[old_pos], adc->bufi - old_pos, in stm32_dfsdm_dma_buffer_done()
898 adc->cb_priv); in stm32_dfsdm_dma_buffer_done()
903 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_dma_start() local
910 .src_addr = (dma_addr_t)adc->dfsdm->phys_base, in stm32_dfsdm_adc_dma_start()
917 if (!adc->dma_chan) in stm32_dfsdm_adc_dma_start()
921 adc->buf_sz, adc->buf_sz / 2); in stm32_dfsdm_adc_dma_start()
923 if (adc->nconv == 1 && !indio_dev->trig) in stm32_dfsdm_adc_dma_start()
924 config.src_addr += DFSDM_RDATAR(adc->fl_id); in stm32_dfsdm_adc_dma_start()
926 config.src_addr += DFSDM_JDATAR(adc->fl_id); in stm32_dfsdm_adc_dma_start()
927 ret = dmaengine_slave_config(adc->dma_chan, &config); in stm32_dfsdm_adc_dma_start()
932 desc = dmaengine_prep_dma_cyclic(adc->dma_chan, in stm32_dfsdm_adc_dma_start()
933 adc->dma_buf, in stm32_dfsdm_adc_dma_start()
934 adc->buf_sz, adc->buf_sz / 2, in stm32_dfsdm_adc_dma_start()
949 dma_async_issue_pending(adc->dma_chan); in stm32_dfsdm_adc_dma_start()
951 if (adc->nconv == 1 && !indio_dev->trig) { in stm32_dfsdm_adc_dma_start()
953 ret = regmap_update_bits(adc->dfsdm->regmap, in stm32_dfsdm_adc_dma_start()
954 DFSDM_CR1(adc->fl_id), in stm32_dfsdm_adc_dma_start()
959 ret = regmap_update_bits(adc->dfsdm->regmap, in stm32_dfsdm_adc_dma_start()
960 DFSDM_CR1(adc->fl_id), in stm32_dfsdm_adc_dma_start()
971 dmaengine_terminate_all(adc->dma_chan); in stm32_dfsdm_adc_dma_start()
978 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_dma_stop() local
980 if (!adc->dma_chan) in stm32_dfsdm_adc_dma_stop()
983 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR1(adc->fl_id), in stm32_dfsdm_adc_dma_stop()
985 dmaengine_terminate_all(adc->dma_chan); in stm32_dfsdm_adc_dma_stop()
991 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_update_scan_mode() local
993 adc->nconv = bitmap_weight(scan_mask, indio_dev->masklength); in stm32_dfsdm_update_scan_mode()
994 adc->smask = *scan_mask; in stm32_dfsdm_update_scan_mode()
996 dev_dbg(&indio_dev->dev, "nconv=%d mask=%lx\n", adc->nconv, *scan_mask); in stm32_dfsdm_update_scan_mode()
1003 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_postenable() local
1007 adc->bufi = 0; in stm32_dfsdm_postenable()
1009 if (adc->hwc) { in stm32_dfsdm_postenable()
1010 ret = iio_hw_consumer_enable(adc->hwc); in stm32_dfsdm_postenable()
1015 ret = stm32_dfsdm_start_dfsdm(adc->dfsdm); in stm32_dfsdm_postenable()
1036 stm32_dfsdm_stop_dfsdm(adc->dfsdm); in stm32_dfsdm_postenable()
1038 if (adc->hwc) in stm32_dfsdm_postenable()
1039 iio_hw_consumer_disable(adc->hwc); in stm32_dfsdm_postenable()
1046 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_predisable() local
1052 stm32_dfsdm_stop_dfsdm(adc->dfsdm); in stm32_dfsdm_predisable()
1054 if (adc->hwc) in stm32_dfsdm_predisable()
1055 iio_hw_consumer_disable(adc->hwc); in stm32_dfsdm_predisable()
1081 struct stm32_dfsdm_adc *adc; in stm32_dfsdm_get_buff_cb() local
1085 adc = iio_priv(iio_dev); in stm32_dfsdm_get_buff_cb()
1087 adc->cb = cb; in stm32_dfsdm_get_buff_cb()
1088 adc->cb_priv = private; in stm32_dfsdm_get_buff_cb()
1101 struct stm32_dfsdm_adc *adc; in stm32_dfsdm_release_buff_cb() local
1105 adc = iio_priv(iio_dev); in stm32_dfsdm_release_buff_cb()
1107 adc->cb = NULL; in stm32_dfsdm_release_buff_cb()
1108 adc->cb_priv = NULL; in stm32_dfsdm_release_buff_cb()
1117 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_single_conv() local
1121 reinit_completion(&adc->completion); in stm32_dfsdm_single_conv()
1123 adc->buffer = res; in stm32_dfsdm_single_conv()
1125 ret = stm32_dfsdm_start_dfsdm(adc->dfsdm); in stm32_dfsdm_single_conv()
1129 ret = regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), in stm32_dfsdm_single_conv()
1134 adc->nconv = 1; in stm32_dfsdm_single_conv()
1135 adc->smask = BIT(chan->scan_index); in stm32_dfsdm_single_conv()
1138 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), in stm32_dfsdm_single_conv()
1143 timeout = wait_for_completion_interruptible_timeout(&adc->completion, in stm32_dfsdm_single_conv()
1147 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), in stm32_dfsdm_single_conv()
1159 stm32_dfsdm_process_data(adc, res); in stm32_dfsdm_single_conv()
1162 stm32_dfsdm_stop_dfsdm(adc->dfsdm); in stm32_dfsdm_single_conv()
1171 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_write_raw() local
1172 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel]; in stm32_dfsdm_write_raw()
1178 spi_freq = adc->dfsdm->spi_master_freq; in stm32_dfsdm_write_raw()
1182 spi_freq = adc->dfsdm->spi_master_freq / 2; in stm32_dfsdm_write_raw()
1185 spi_freq = adc->spi_freq; in stm32_dfsdm_write_raw()
1198 adc->sample_freq, spi_freq / val); in stm32_dfsdm_write_raw()
1199 adc->oversamp = val; in stm32_dfsdm_write_raw()
1200 adc->sample_freq = spi_freq / val; in stm32_dfsdm_write_raw()
1225 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_read_raw() local
1233 ret = iio_hw_consumer_enable(adc->hwc); in stm32_dfsdm_read_raw()
1242 iio_hw_consumer_disable(adc->hwc); in stm32_dfsdm_read_raw()
1254 *val = adc->oversamp; in stm32_dfsdm_read_raw()
1259 *val = adc->sample_freq; in stm32_dfsdm_read_raw()
1291 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_irq() local
1292 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_irq()
1295 regmap_read(regmap, DFSDM_ISR(adc->fl_id), &status); in stm32_dfsdm_irq()
1296 regmap_read(regmap, DFSDM_CR2(adc->fl_id), &int_en); in stm32_dfsdm_irq()
1300 regmap_read(regmap, DFSDM_RDATAR(adc->fl_id), adc->buffer); in stm32_dfsdm_irq()
1301 complete(&adc->completion); in stm32_dfsdm_irq()
1307 regmap_update_bits(regmap, DFSDM_ICR(adc->fl_id), in stm32_dfsdm_irq()
1332 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_dma_release() local
1334 if (adc->dma_chan) { in stm32_dfsdm_dma_release()
1335 dma_free_coherent(adc->dma_chan->device->dev, in stm32_dfsdm_dma_release()
1337 adc->rx_buf, adc->dma_buf); in stm32_dfsdm_dma_release()
1338 dma_release_channel(adc->dma_chan); in stm32_dfsdm_dma_release()
1345 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_dma_request() local
1347 adc->dma_chan = dma_request_chan(dev, "rx"); in stm32_dfsdm_dma_request()
1348 if (IS_ERR(adc->dma_chan)) { in stm32_dfsdm_dma_request()
1349 int ret = PTR_ERR(adc->dma_chan); in stm32_dfsdm_dma_request()
1351 adc->dma_chan = NULL; in stm32_dfsdm_dma_request()
1355 adc->rx_buf = dma_alloc_coherent(adc->dma_chan->device->dev, in stm32_dfsdm_dma_request()
1357 &adc->dma_buf, GFP_KERNEL); in stm32_dfsdm_dma_request()
1358 if (!adc->rx_buf) { in stm32_dfsdm_dma_request()
1359 dma_release_channel(adc->dma_chan); in stm32_dfsdm_dma_request()
1372 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_chan_init_one() local
1375 ret = stm32_dfsdm_channel_parse_of(adc->dfsdm, indio_dev, ch); in stm32_dfsdm_adc_chan_init_one()
1390 if (adc->dev_data->type == DFSDM_AUDIO) { in stm32_dfsdm_adc_chan_init_one()
1399 return stm32_dfsdm_chan_configure(adc->dfsdm, in stm32_dfsdm_adc_chan_init_one()
1400 &adc->dfsdm->ch_list[ch->channel]); in stm32_dfsdm_adc_chan_init_one()
1406 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_audio_init() local
1423 d_ch = &adc->dfsdm->ch_list[ch->channel]; in stm32_dfsdm_audio_init()
1425 adc->spi_freq = adc->dfsdm->spi_master_freq; in stm32_dfsdm_audio_init()
1436 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_init() local
1440 adc->oversamp = DFSDM_DEFAULT_OVERSAMPLING; in stm32_dfsdm_adc_init()
1441 ret = stm32_dfsdm_compute_all_osrs(indio_dev, adc->oversamp); in stm32_dfsdm_adc_init()
1447 if (num_ch < 0 || num_ch > adc->dfsdm->num_chs) { in stm32_dfsdm_adc_init()
1453 adc->hwc = devm_iio_hw_consumer_alloc(&indio_dev->dev); in stm32_dfsdm_adc_init()
1454 if (IS_ERR(adc->hwc)) in stm32_dfsdm_adc_init()
1474 init_completion(&adc->completion); in stm32_dfsdm_adc_init()
1527 struct stm32_dfsdm_adc *adc; in stm32_dfsdm_adc_probe() local
1535 iio = devm_iio_device_alloc(dev, sizeof(*adc)); in stm32_dfsdm_adc_probe()
1541 adc = iio_priv(iio); in stm32_dfsdm_adc_probe()
1542 adc->dfsdm = dev_get_drvdata(dev->parent); in stm32_dfsdm_adc_probe()
1549 ret = of_property_read_u32(dev->of_node, "reg", &adc->fl_id); in stm32_dfsdm_adc_probe()
1550 if (ret != 0 || adc->fl_id >= adc->dfsdm->num_fls) { in stm32_dfsdm_adc_probe()
1560 snprintf(name, sizeof("dfsdm-pdm0"), "dfsdm-pdm%d", adc->fl_id); in stm32_dfsdm_adc_probe()
1563 snprintf(name, sizeof("dfsdm-adc0"), "dfsdm-adc%d", adc->fl_id); in stm32_dfsdm_adc_probe()
1588 adc->dfsdm->fl_list[adc->fl_id].ford = val; in stm32_dfsdm_adc_probe()
1592 adc->dfsdm->fl_list[adc->fl_id].sync_mode = val; in stm32_dfsdm_adc_probe()
1594 adc->dev_data = dev_data; in stm32_dfsdm_adc_probe()
1624 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_remove() local
1626 if (adc->dev_data->type == DFSDM_AUDIO) in stm32_dfsdm_adc_remove()
1647 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_resume() local
1655 ch = &adc->dfsdm->ch_list[chan->channel]; in stm32_dfsdm_adc_resume()
1656 ret = stm32_dfsdm_chan_configure(adc->dfsdm, ch); in stm32_dfsdm_adc_resume()