Lines Matching +full:stm32 +full:- +full:dfsdm +full:- +full:adc
1 // SPDX-License-Identifier: GPL-2.0
3 * This file is part of STM32 DFSDM ASoC DAI driver
5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
18 #include <linux/iio/adc/stm32-dfsdm-adc.h>
23 #define STM32_ADFSDM_DRV_NAME "stm32-adfsdm"
65 mutex_lock(&priv->lock); in stm32_adfsdm_shutdown()
66 if (priv->iio_active) { in stm32_adfsdm_shutdown()
67 iio_channel_stop_all_cb(priv->iio_cb); in stm32_adfsdm_shutdown()
68 priv->iio_active = false; in stm32_adfsdm_shutdown()
70 mutex_unlock(&priv->lock); in stm32_adfsdm_shutdown()
79 mutex_lock(&priv->lock); in stm32_adfsdm_dai_prepare()
80 if (priv->iio_active) { in stm32_adfsdm_dai_prepare()
81 iio_channel_stop_all_cb(priv->iio_cb); in stm32_adfsdm_dai_prepare()
82 priv->iio_active = false; in stm32_adfsdm_dai_prepare()
85 ret = iio_write_channel_attribute(priv->iio_ch, in stm32_adfsdm_dai_prepare()
86 substream->runtime->rate, 0, in stm32_adfsdm_dai_prepare()
89 dev_err(dai->dev, "%s: Failed to set %d sampling rate\n", in stm32_adfsdm_dai_prepare()
90 __func__, substream->runtime->rate); in stm32_adfsdm_dai_prepare()
94 if (!priv->iio_active) { in stm32_adfsdm_dai_prepare()
95 ret = iio_channel_start_all_cb(priv->iio_cb); in stm32_adfsdm_dai_prepare()
97 priv->iio_active = true; in stm32_adfsdm_dai_prepare()
99 dev_err(dai->dev, "%s: IIO channel start failed (%d)\n", in stm32_adfsdm_dai_prepare()
104 mutex_unlock(&priv->lock); in stm32_adfsdm_dai_prepare()
116 dev_dbg(dai->dev, "%s: Enter for freq %d\n", __func__, freq); in stm32_adfsdm_set_sysclk()
121 size = iio_write_channel_ext_info(priv->iio_ch, "spi_clk_freq", in stm32_adfsdm_set_sysclk()
124 dev_err(dai->dev, "%s: Failed to set SPI clock\n", in stm32_adfsdm_set_sysclk()
126 return -EINVAL; in stm32_adfsdm_set_sysclk()
161 for (i = n >> 1; i > 0; i--) { in stm32_memcpy_32to16()
170 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(priv->substream); in stm32_afsdm_pcm_cb()
171 u8 *pcm_buff = priv->pcm_buff; in stm32_afsdm_pcm_cb()
173 unsigned int old_pos = priv->pos; in stm32_afsdm_pcm_cb()
174 size_t buff_size = snd_pcm_lib_buffer_bytes(priv->substream); in stm32_afsdm_pcm_cb()
175 size_t period_size = snd_pcm_lib_period_bytes(priv->substream); in stm32_afsdm_pcm_cb()
177 snd_pcm_format_t format = priv->substream->runtime->format; in stm32_afsdm_pcm_cb()
183 dev_dbg(rtd->dev, "%s: buff_add :%pK, pos = %d, size = %zu\n", in stm32_afsdm_pcm_cb()
184 __func__, &pcm_buff[priv->pos], priv->pos, src_size); in stm32_afsdm_pcm_cb()
186 if ((priv->pos + src_size) > buff_size) { in stm32_afsdm_pcm_cb()
188 stm32_memcpy_32to16(&pcm_buff[priv->pos], src_buff, in stm32_afsdm_pcm_cb()
189 buff_size - priv->pos); in stm32_afsdm_pcm_cb()
191 memcpy(&pcm_buff[priv->pos], src_buff, in stm32_afsdm_pcm_cb()
192 buff_size - priv->pos); in stm32_afsdm_pcm_cb()
193 cur_size -= buff_size - priv->pos; in stm32_afsdm_pcm_cb()
194 priv->pos = 0; in stm32_afsdm_pcm_cb()
198 stm32_memcpy_32to16(&pcm_buff[priv->pos], in stm32_afsdm_pcm_cb()
199 &src_buff[src_size - cur_size], cur_size); in stm32_afsdm_pcm_cb()
201 memcpy(&pcm_buff[priv->pos], &src_buff[src_size - cur_size], in stm32_afsdm_pcm_cb()
204 priv->pos = (priv->pos + cur_size) % buff_size; in stm32_afsdm_pcm_cb()
207 snd_pcm_period_elapsed(priv->substream); in stm32_afsdm_pcm_cb()
222 priv->pos = 0; in stm32_adfsdm_trigger()
223 return stm32_dfsdm_get_buff_cb(priv->iio_ch->indio_dev, in stm32_adfsdm_trigger()
227 return stm32_dfsdm_release_buff_cb(priv->iio_ch->indio_dev); in stm32_adfsdm_trigger()
230 return -EINVAL; in stm32_adfsdm_trigger()
242 priv->substream = substream; in stm32_adfsdm_pcm_open()
254 priv->substream = NULL; in stm32_adfsdm_pcm_close()
267 return bytes_to_frames(substream->runtime, priv->pos); in stm32_adfsdm_pcm_pointer()
278 priv->pcm_buff = substream->runtime->dma_area; in stm32_adfsdm_pcm_hw_params()
280 return iio_channel_cb_set_buffer_watermark(priv->iio_cb, in stm32_adfsdm_pcm_hw_params()
287 struct snd_pcm *pcm = rtd->pcm; in stm32_adfsdm_pcm_new()
293 priv->dev, size, size); in stm32_adfsdm_pcm_new()
322 {.compatible = "st,stm32h7-dfsdm-dai"},
333 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in stm32_adfsdm_probe()
335 return -ENOMEM; in stm32_adfsdm_probe()
337 priv->dev = &pdev->dev; in stm32_adfsdm_probe()
338 priv->dai_drv = stm32_adfsdm_dai; in stm32_adfsdm_probe()
339 mutex_init(&priv->lock); in stm32_adfsdm_probe()
341 dev_set_drvdata(&pdev->dev, priv); in stm32_adfsdm_probe()
343 ret = devm_snd_soc_register_component(&pdev->dev, in stm32_adfsdm_probe()
345 &priv->dai_drv, 1); in stm32_adfsdm_probe()
350 priv->iio_ch = devm_iio_channel_get_all(&pdev->dev); in stm32_adfsdm_probe()
351 if (IS_ERR(priv->iio_ch)) in stm32_adfsdm_probe()
352 return PTR_ERR(priv->iio_ch); in stm32_adfsdm_probe()
354 priv->iio_cb = iio_channel_get_all_cb(&pdev->dev, &stm32_adfsdm_dummy_cb, NULL); in stm32_adfsdm_probe()
355 if (IS_ERR(priv->iio_cb)) in stm32_adfsdm_probe()
356 return PTR_ERR(priv->iio_cb); in stm32_adfsdm_probe()
358 ret = devm_add_action_or_reset(&pdev->dev, stm32_adfsdm_cleanup, priv->iio_cb); in stm32_adfsdm_probe()
360 dev_err(&pdev->dev, "Unable to add action\n"); in stm32_adfsdm_probe()
364 component = devm_kzalloc(&pdev->dev, sizeof(*component), GFP_KERNEL); in stm32_adfsdm_probe()
366 return -ENOMEM; in stm32_adfsdm_probe()
370 &pdev->dev); in stm32_adfsdm_probe()
374 component->debugfs_prefix = "pcm"; in stm32_adfsdm_probe()
379 dev_err(&pdev->dev, "%s: Failed to register PCM platform\n", in stm32_adfsdm_probe()
384 pm_runtime_enable(&pdev->dev); in stm32_adfsdm_probe()
391 snd_soc_unregister_component(&pdev->dev); in stm32_adfsdm_remove()
392 pm_runtime_disable(&pdev->dev); in stm32_adfsdm_remove()
406 MODULE_DESCRIPTION("stm32 DFSDM DAI driver");