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 && in stm32_dfsdm_channels_configure()
483 for_each_set_bit(bit, &adc->smask, in stm32_dfsdm_channels_configure()
484 sizeof(adc->smask) * BITS_PER_BYTE) { in stm32_dfsdm_channels_configure()
502 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_filter_configure() local
503 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_filter_configure()
504 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[fl_id]; in stm32_dfsdm_filter_configure()
557 if (adc->nconv == 1 && !trig) { in stm32_dfsdm_filter_configure()
558 bit = __ffs(adc->smask); in stm32_dfsdm_filter_configure()
571 for_each_set_bit(bit, &adc->smask, in stm32_dfsdm_filter_configure()
572 sizeof(adc->smask) * BITS_PER_BYTE) { in stm32_dfsdm_filter_configure()
581 cr1 = DFSDM_CR1_JSCAN((adc->nconv > 1) ? 1 : 0); in stm32_dfsdm_filter_configure()
674 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in dfsdm_adc_audio_get_spiclk() local
676 return snprintf(buf, PAGE_SIZE, "%d\n", adc->spi_freq); in dfsdm_adc_audio_get_spiclk()
683 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in dfsdm_adc_set_samp_freq() local
697 adc->sample_freq = spi_freq / oversamp; in dfsdm_adc_set_samp_freq()
698 adc->oversamp = oversamp; in dfsdm_adc_set_samp_freq()
708 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in dfsdm_adc_audio_set_spiclk() local
709 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel]; in dfsdm_adc_audio_set_spiclk()
710 unsigned int sample_freq = adc->sample_freq; in dfsdm_adc_audio_set_spiclk()
731 adc->spi_freq = spi_freq; in dfsdm_adc_audio_set_spiclk()
739 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_start_conv() local
740 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_start_conv()
743 ret = stm32_dfsdm_channels_configure(indio_dev, adc->fl_id, trig); in stm32_dfsdm_start_conv()
751 ret = stm32_dfsdm_filter_configure(indio_dev, adc->fl_id, trig); in stm32_dfsdm_start_conv()
755 ret = stm32_dfsdm_start_filter(adc, adc->fl_id, trig); in stm32_dfsdm_start_conv()
762 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), in stm32_dfsdm_start_conv()
772 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_stop_conv() local
773 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_stop_conv()
775 stm32_dfsdm_stop_filter(adc->dfsdm, adc->fl_id); in stm32_dfsdm_stop_conv()
777 regmap_update_bits(regmap, DFSDM_CR1(adc->fl_id), in stm32_dfsdm_stop_conv()
786 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_set_watermark() local
797 adc->buf_sz = min(rx_buf_sz, watermark * 2 * adc->nconv); in stm32_dfsdm_set_watermark()
802 static unsigned int stm32_dfsdm_adc_dma_residue(struct stm32_dfsdm_adc *adc) in stm32_dfsdm_adc_dma_residue() argument
807 status = dmaengine_tx_status(adc->dma_chan, in stm32_dfsdm_adc_dma_residue()
808 adc->dma_chan->cookie, in stm32_dfsdm_adc_dma_residue()
812 unsigned int i = adc->buf_sz - state.residue; in stm32_dfsdm_adc_dma_residue()
816 if (i >= adc->bufi) in stm32_dfsdm_adc_dma_residue()
817 size = i - adc->bufi; in stm32_dfsdm_adc_dma_residue()
819 size = adc->buf_sz + i - adc->bufi; in stm32_dfsdm_adc_dma_residue()
827 static inline void stm32_dfsdm_process_data(struct stm32_dfsdm_adc *adc, in stm32_dfsdm_process_data() argument
830 struct stm32_dfsdm_filter *fl = &adc->dfsdm->fl_list[adc->fl_id]; in stm32_dfsdm_process_data()
832 unsigned int i = adc->nconv; in stm32_dfsdm_process_data()
854 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_dma_buffer_done() local
855 int available = stm32_dfsdm_adc_dma_residue(adc); in stm32_dfsdm_dma_buffer_done()
868 adc->bufi, available); in stm32_dfsdm_dma_buffer_done()
869 old_pos = adc->bufi; in stm32_dfsdm_dma_buffer_done()
872 s32 *buffer = (s32 *)&adc->rx_buf[adc->bufi]; in stm32_dfsdm_dma_buffer_done()
874 stm32_dfsdm_process_data(adc, buffer); in stm32_dfsdm_dma_buffer_done()
877 adc->bufi += indio_dev->scan_bytes; in stm32_dfsdm_dma_buffer_done()
878 if (adc->bufi >= adc->buf_sz) { in stm32_dfsdm_dma_buffer_done()
879 if (adc->cb) in stm32_dfsdm_dma_buffer_done()
880 adc->cb(&adc->rx_buf[old_pos], in stm32_dfsdm_dma_buffer_done()
881 adc->buf_sz - old_pos, adc->cb_priv); in stm32_dfsdm_dma_buffer_done()
882 adc->bufi = 0; in stm32_dfsdm_dma_buffer_done()
894 if (adc->dev_data->type == DFSDM_IIO) in stm32_dfsdm_dma_buffer_done()
897 if (adc->cb) in stm32_dfsdm_dma_buffer_done()
898 adc->cb(&adc->rx_buf[old_pos], adc->bufi - old_pos, in stm32_dfsdm_dma_buffer_done()
899 adc->cb_priv); in stm32_dfsdm_dma_buffer_done()
904 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_dma_start() local
911 .src_addr = (dma_addr_t)adc->dfsdm->phys_base, in stm32_dfsdm_adc_dma_start()
918 if (!adc->dma_chan) in stm32_dfsdm_adc_dma_start()
922 adc->buf_sz, adc->buf_sz / 2); in stm32_dfsdm_adc_dma_start()
924 if (adc->nconv == 1 && !indio_dev->trig) in stm32_dfsdm_adc_dma_start()
925 config.src_addr += DFSDM_RDATAR(adc->fl_id); in stm32_dfsdm_adc_dma_start()
927 config.src_addr += DFSDM_JDATAR(adc->fl_id); in stm32_dfsdm_adc_dma_start()
928 ret = dmaengine_slave_config(adc->dma_chan, &config); in stm32_dfsdm_adc_dma_start()
933 desc = dmaengine_prep_dma_cyclic(adc->dma_chan, in stm32_dfsdm_adc_dma_start()
934 adc->dma_buf, in stm32_dfsdm_adc_dma_start()
935 adc->buf_sz, adc->buf_sz / 2, in stm32_dfsdm_adc_dma_start()
950 dma_async_issue_pending(adc->dma_chan); in stm32_dfsdm_adc_dma_start()
952 if (adc->nconv == 1 && !indio_dev->trig) { in stm32_dfsdm_adc_dma_start()
954 ret = regmap_update_bits(adc->dfsdm->regmap, in stm32_dfsdm_adc_dma_start()
955 DFSDM_CR1(adc->fl_id), in stm32_dfsdm_adc_dma_start()
960 ret = regmap_update_bits(adc->dfsdm->regmap, in stm32_dfsdm_adc_dma_start()
961 DFSDM_CR1(adc->fl_id), in stm32_dfsdm_adc_dma_start()
972 dmaengine_terminate_all(adc->dma_chan); in stm32_dfsdm_adc_dma_start()
979 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_dma_stop() local
981 if (!adc->dma_chan) in stm32_dfsdm_adc_dma_stop()
984 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR1(adc->fl_id), in stm32_dfsdm_adc_dma_stop()
986 dmaengine_terminate_all(adc->dma_chan); in stm32_dfsdm_adc_dma_stop()
992 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_update_scan_mode() local
994 adc->nconv = bitmap_weight(scan_mask, indio_dev->masklength); in stm32_dfsdm_update_scan_mode()
995 adc->smask = *scan_mask; in stm32_dfsdm_update_scan_mode()
997 dev_dbg(&indio_dev->dev, "nconv=%d mask=%lx\n", adc->nconv, *scan_mask); in stm32_dfsdm_update_scan_mode()
1004 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_postenable() local
1008 adc->bufi = 0; in stm32_dfsdm_postenable()
1010 if (adc->hwc) { in stm32_dfsdm_postenable()
1011 ret = iio_hw_consumer_enable(adc->hwc); in stm32_dfsdm_postenable()
1016 ret = stm32_dfsdm_start_dfsdm(adc->dfsdm); in stm32_dfsdm_postenable()
1037 stm32_dfsdm_stop_dfsdm(adc->dfsdm); in stm32_dfsdm_postenable()
1039 if (adc->hwc) in stm32_dfsdm_postenable()
1040 iio_hw_consumer_disable(adc->hwc); in stm32_dfsdm_postenable()
1047 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_predisable() local
1053 stm32_dfsdm_stop_dfsdm(adc->dfsdm); in stm32_dfsdm_predisable()
1055 if (adc->hwc) in stm32_dfsdm_predisable()
1056 iio_hw_consumer_disable(adc->hwc); in stm32_dfsdm_predisable()
1082 struct stm32_dfsdm_adc *adc; in stm32_dfsdm_get_buff_cb() local
1086 adc = iio_priv(iio_dev); in stm32_dfsdm_get_buff_cb()
1088 adc->cb = cb; in stm32_dfsdm_get_buff_cb()
1089 adc->cb_priv = private; in stm32_dfsdm_get_buff_cb()
1102 struct stm32_dfsdm_adc *adc; in stm32_dfsdm_release_buff_cb() local
1106 adc = iio_priv(iio_dev); in stm32_dfsdm_release_buff_cb()
1108 adc->cb = NULL; in stm32_dfsdm_release_buff_cb()
1109 adc->cb_priv = NULL; in stm32_dfsdm_release_buff_cb()
1118 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_single_conv() local
1122 reinit_completion(&adc->completion); in stm32_dfsdm_single_conv()
1124 adc->buffer = res; in stm32_dfsdm_single_conv()
1126 ret = stm32_dfsdm_start_dfsdm(adc->dfsdm); in stm32_dfsdm_single_conv()
1130 ret = regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), in stm32_dfsdm_single_conv()
1135 adc->nconv = 1; in stm32_dfsdm_single_conv()
1136 adc->smask = BIT(chan->scan_index); in stm32_dfsdm_single_conv()
1139 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), in stm32_dfsdm_single_conv()
1144 timeout = wait_for_completion_interruptible_timeout(&adc->completion, in stm32_dfsdm_single_conv()
1148 regmap_update_bits(adc->dfsdm->regmap, DFSDM_CR2(adc->fl_id), in stm32_dfsdm_single_conv()
1160 stm32_dfsdm_process_data(adc, res); in stm32_dfsdm_single_conv()
1163 stm32_dfsdm_stop_dfsdm(adc->dfsdm); in stm32_dfsdm_single_conv()
1172 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_write_raw() local
1173 struct stm32_dfsdm_channel *ch = &adc->dfsdm->ch_list[chan->channel]; in stm32_dfsdm_write_raw()
1179 spi_freq = adc->dfsdm->spi_master_freq; in stm32_dfsdm_write_raw()
1183 spi_freq = adc->dfsdm->spi_master_freq / 2; in stm32_dfsdm_write_raw()
1186 spi_freq = adc->spi_freq; in stm32_dfsdm_write_raw()
1199 adc->sample_freq, spi_freq / val); in stm32_dfsdm_write_raw()
1200 adc->oversamp = val; in stm32_dfsdm_write_raw()
1201 adc->sample_freq = spi_freq / val; in stm32_dfsdm_write_raw()
1226 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_read_raw() local
1234 ret = iio_hw_consumer_enable(adc->hwc); in stm32_dfsdm_read_raw()
1243 iio_hw_consumer_disable(adc->hwc); in stm32_dfsdm_read_raw()
1255 *val = adc->oversamp; in stm32_dfsdm_read_raw()
1260 *val = adc->sample_freq; in stm32_dfsdm_read_raw()
1292 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_irq() local
1293 struct regmap *regmap = adc->dfsdm->regmap; in stm32_dfsdm_irq()
1296 regmap_read(regmap, DFSDM_ISR(adc->fl_id), &status); in stm32_dfsdm_irq()
1297 regmap_read(regmap, DFSDM_CR2(adc->fl_id), &int_en); in stm32_dfsdm_irq()
1301 regmap_read(regmap, DFSDM_RDATAR(adc->fl_id), adc->buffer); in stm32_dfsdm_irq()
1302 complete(&adc->completion); in stm32_dfsdm_irq()
1308 regmap_update_bits(regmap, DFSDM_ICR(adc->fl_id), in stm32_dfsdm_irq()
1333 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_dma_release() local
1335 if (adc->dma_chan) { in stm32_dfsdm_dma_release()
1336 dma_free_coherent(adc->dma_chan->device->dev, in stm32_dfsdm_dma_release()
1338 adc->rx_buf, adc->dma_buf); in stm32_dfsdm_dma_release()
1339 dma_release_channel(adc->dma_chan); in stm32_dfsdm_dma_release()
1346 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_dma_request() local
1348 adc->dma_chan = dma_request_chan(dev, "rx"); in stm32_dfsdm_dma_request()
1349 if (IS_ERR(adc->dma_chan)) { in stm32_dfsdm_dma_request()
1350 int ret = PTR_ERR(adc->dma_chan); in stm32_dfsdm_dma_request()
1352 adc->dma_chan = NULL; in stm32_dfsdm_dma_request()
1356 adc->rx_buf = dma_alloc_coherent(adc->dma_chan->device->dev, in stm32_dfsdm_dma_request()
1358 &adc->dma_buf, GFP_KERNEL); in stm32_dfsdm_dma_request()
1359 if (!adc->rx_buf) { in stm32_dfsdm_dma_request()
1360 dma_release_channel(adc->dma_chan); in stm32_dfsdm_dma_request()
1373 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_chan_init_one() local
1376 ret = stm32_dfsdm_channel_parse_of(adc->dfsdm, indio_dev, ch); in stm32_dfsdm_adc_chan_init_one()
1391 if (adc->dev_data->type == DFSDM_AUDIO) { in stm32_dfsdm_adc_chan_init_one()
1400 return stm32_dfsdm_chan_configure(adc->dfsdm, in stm32_dfsdm_adc_chan_init_one()
1401 &adc->dfsdm->ch_list[ch->channel]); in stm32_dfsdm_adc_chan_init_one()
1407 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_audio_init() local
1424 d_ch = &adc->dfsdm->ch_list[ch->channel]; in stm32_dfsdm_audio_init()
1426 adc->spi_freq = adc->dfsdm->spi_master_freq; in stm32_dfsdm_audio_init()
1437 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_init() local
1441 adc->oversamp = DFSDM_DEFAULT_OVERSAMPLING; in stm32_dfsdm_adc_init()
1442 ret = stm32_dfsdm_compute_all_osrs(indio_dev, adc->oversamp); in stm32_dfsdm_adc_init()
1448 if (num_ch < 0 || num_ch > adc->dfsdm->num_chs) { in stm32_dfsdm_adc_init()
1454 adc->hwc = devm_iio_hw_consumer_alloc(&indio_dev->dev); in stm32_dfsdm_adc_init()
1455 if (IS_ERR(adc->hwc)) in stm32_dfsdm_adc_init()
1475 init_completion(&adc->completion); in stm32_dfsdm_adc_init()
1528 struct stm32_dfsdm_adc *adc; in stm32_dfsdm_adc_probe() local
1536 iio = devm_iio_device_alloc(dev, sizeof(*adc)); in stm32_dfsdm_adc_probe()
1542 adc = iio_priv(iio); in stm32_dfsdm_adc_probe()
1543 adc->dfsdm = dev_get_drvdata(dev->parent); in stm32_dfsdm_adc_probe()
1550 ret = of_property_read_u32(dev->of_node, "reg", &adc->fl_id); in stm32_dfsdm_adc_probe()
1551 if (ret != 0 || adc->fl_id >= adc->dfsdm->num_fls) { in stm32_dfsdm_adc_probe()
1561 snprintf(name, sizeof("dfsdm-pdm0"), "dfsdm-pdm%d", adc->fl_id); in stm32_dfsdm_adc_probe()
1564 snprintf(name, sizeof("dfsdm-adc0"), "dfsdm-adc%d", adc->fl_id); in stm32_dfsdm_adc_probe()
1589 adc->dfsdm->fl_list[adc->fl_id].ford = val; in stm32_dfsdm_adc_probe()
1593 adc->dfsdm->fl_list[adc->fl_id].sync_mode = val; in stm32_dfsdm_adc_probe()
1595 adc->dev_data = dev_data; in stm32_dfsdm_adc_probe()
1625 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_remove() local
1627 if (adc->dev_data->type == DFSDM_AUDIO) in stm32_dfsdm_adc_remove()
1648 struct stm32_dfsdm_adc *adc = iio_priv(indio_dev); in stm32_dfsdm_adc_resume() local
1656 ch = &adc->dfsdm->ch_list[chan->channel]; in stm32_dfsdm_adc_resume()
1657 ret = stm32_dfsdm_chan_configure(adc->dfsdm, ch); in stm32_dfsdm_adc_resume()