stm32_adfsdm.c (1ac731c529cd4d6adbce134754b51ff7d822b145) | stm32_adfsdm.c (d69bd6dbc651ba86fe40f4cc6b125a7fb3f4be51) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * This file is part of STM32 DFSDM ASoC DAI driver 4 * 5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved 6 * Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com> 7 * Olivier Moysan <olivier.moysan@st.com> 8 */ --- 153 unchanged lines hidden (view full) --- 162 *d++ = *s++; 163 s++; 164 } 165} 166 167static int stm32_afsdm_pcm_cb(const void *data, size_t size, void *private) 168{ 169 struct stm32_adfsdm_priv *priv = private; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * This file is part of STM32 DFSDM ASoC DAI driver 4 * 5 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved 6 * Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com> 7 * Olivier Moysan <olivier.moysan@st.com> 8 */ --- 153 unchanged lines hidden (view full) --- 162 *d++ = *s++; 163 s++; 164 } 165} 166 167static int stm32_afsdm_pcm_cb(const void *data, size_t size, void *private) 168{ 169 struct stm32_adfsdm_priv *priv = private; |
170 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(priv->substream); | 170 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(priv->substream); |
171 u8 *pcm_buff = priv->pcm_buff; 172 u8 *src_buff = (u8 *)data; 173 unsigned int old_pos = priv->pos; 174 size_t buff_size = snd_pcm_lib_buffer_bytes(priv->substream); 175 size_t period_size = snd_pcm_lib_period_bytes(priv->substream); 176 size_t cur_size, src_size = size; 177 snd_pcm_format_t format = priv->substream->runtime->format; 178 --- 28 unchanged lines hidden (view full) --- 207 snd_pcm_period_elapsed(priv->substream); 208 209 return 0; 210} 211 212static int stm32_adfsdm_trigger(struct snd_soc_component *component, 213 struct snd_pcm_substream *substream, int cmd) 214{ | 171 u8 *pcm_buff = priv->pcm_buff; 172 u8 *src_buff = (u8 *)data; 173 unsigned int old_pos = priv->pos; 174 size_t buff_size = snd_pcm_lib_buffer_bytes(priv->substream); 175 size_t period_size = snd_pcm_lib_period_bytes(priv->substream); 176 size_t cur_size, src_size = size; 177 snd_pcm_format_t format = priv->substream->runtime->format; 178 --- 28 unchanged lines hidden (view full) --- 207 snd_pcm_period_elapsed(priv->substream); 208 209 return 0; 210} 211 212static int stm32_adfsdm_trigger(struct snd_soc_component *component, 213 struct snd_pcm_substream *substream, int cmd) 214{ |
215 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 215 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
216 struct stm32_adfsdm_priv *priv = | 216 struct stm32_adfsdm_priv *priv = |
217 snd_soc_dai_get_drvdata(asoc_rtd_to_cpu(rtd, 0)); | 217 snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0)); |
218 219 switch (cmd) { 220 case SNDRV_PCM_TRIGGER_START: 221 case SNDRV_PCM_TRIGGER_RESUME: 222 priv->pos = 0; 223 return stm32_dfsdm_get_buff_cb(priv->iio_ch->indio_dev, 224 stm32_afsdm_pcm_cb, priv); 225 case SNDRV_PCM_TRIGGER_SUSPEND: 226 case SNDRV_PCM_TRIGGER_STOP: 227 return stm32_dfsdm_release_buff_cb(priv->iio_ch->indio_dev); 228 } 229 230 return -EINVAL; 231} 232 233static int stm32_adfsdm_pcm_open(struct snd_soc_component *component, 234 struct snd_pcm_substream *substream) 235{ | 218 219 switch (cmd) { 220 case SNDRV_PCM_TRIGGER_START: 221 case SNDRV_PCM_TRIGGER_RESUME: 222 priv->pos = 0; 223 return stm32_dfsdm_get_buff_cb(priv->iio_ch->indio_dev, 224 stm32_afsdm_pcm_cb, priv); 225 case SNDRV_PCM_TRIGGER_SUSPEND: 226 case SNDRV_PCM_TRIGGER_STOP: 227 return stm32_dfsdm_release_buff_cb(priv->iio_ch->indio_dev); 228 } 229 230 return -EINVAL; 231} 232 233static int stm32_adfsdm_pcm_open(struct snd_soc_component *component, 234 struct snd_pcm_substream *substream) 235{ |
236 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 237 struct stm32_adfsdm_priv *priv = snd_soc_dai_get_drvdata(asoc_rtd_to_cpu(rtd, 0)); | 236 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 237 struct stm32_adfsdm_priv *priv = snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0)); |
238 int ret; 239 240 ret = snd_soc_set_runtime_hwparams(substream, &stm32_adfsdm_pcm_hw); 241 if (!ret) 242 priv->substream = substream; 243 244 return ret; 245} 246 247static int stm32_adfsdm_pcm_close(struct snd_soc_component *component, 248 struct snd_pcm_substream *substream) 249{ | 238 int ret; 239 240 ret = snd_soc_set_runtime_hwparams(substream, &stm32_adfsdm_pcm_hw); 241 if (!ret) 242 priv->substream = substream; 243 244 return ret; 245} 246 247static int stm32_adfsdm_pcm_close(struct snd_soc_component *component, 248 struct snd_pcm_substream *substream) 249{ |
250 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 250 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
251 struct stm32_adfsdm_priv *priv = | 251 struct stm32_adfsdm_priv *priv = |
252 snd_soc_dai_get_drvdata(asoc_rtd_to_cpu(rtd, 0)); | 252 snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0)); |
253 254 priv->substream = NULL; 255 256 return 0; 257} 258 259static snd_pcm_uframes_t stm32_adfsdm_pcm_pointer( 260 struct snd_soc_component *component, 261 struct snd_pcm_substream *substream) 262{ | 253 254 priv->substream = NULL; 255 256 return 0; 257} 258 259static snd_pcm_uframes_t stm32_adfsdm_pcm_pointer( 260 struct snd_soc_component *component, 261 struct snd_pcm_substream *substream) 262{ |
263 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 263 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
264 struct stm32_adfsdm_priv *priv = | 264 struct stm32_adfsdm_priv *priv = |
265 snd_soc_dai_get_drvdata(asoc_rtd_to_cpu(rtd, 0)); | 265 snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0)); |
266 267 return bytes_to_frames(substream->runtime, priv->pos); 268} 269 270static int stm32_adfsdm_pcm_hw_params(struct snd_soc_component *component, 271 struct snd_pcm_substream *substream, 272 struct snd_pcm_hw_params *params) 273{ | 266 267 return bytes_to_frames(substream->runtime, priv->pos); 268} 269 270static int stm32_adfsdm_pcm_hw_params(struct snd_soc_component *component, 271 struct snd_pcm_substream *substream, 272 struct snd_pcm_hw_params *params) 273{ |
274 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 274 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
275 struct stm32_adfsdm_priv *priv = | 275 struct stm32_adfsdm_priv *priv = |
276 snd_soc_dai_get_drvdata(asoc_rtd_to_cpu(rtd, 0)); | 276 snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0)); |
277 278 priv->pcm_buff = substream->runtime->dma_area; 279 280 return iio_channel_cb_set_buffer_watermark(priv->iio_cb, 281 params_period_size(params)); 282} 283 284static int stm32_adfsdm_pcm_new(struct snd_soc_component *component, 285 struct snd_soc_pcm_runtime *rtd) 286{ 287 struct snd_pcm *pcm = rtd->pcm; 288 struct stm32_adfsdm_priv *priv = | 277 278 priv->pcm_buff = substream->runtime->dma_area; 279 280 return iio_channel_cb_set_buffer_watermark(priv->iio_cb, 281 params_period_size(params)); 282} 283 284static int stm32_adfsdm_pcm_new(struct snd_soc_component *component, 285 struct snd_soc_pcm_runtime *rtd) 286{ 287 struct snd_pcm *pcm = rtd->pcm; 288 struct stm32_adfsdm_priv *priv = |
289 snd_soc_dai_get_drvdata(asoc_rtd_to_cpu(rtd, 0)); | 289 snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0)); |
290 unsigned int size = DFSDM_MAX_PERIODS * DFSDM_MAX_PERIOD_SIZE; 291 292 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, 293 priv->dev, size, size); 294 return 0; 295} 296 297static int stm32_adfsdm_dummy_cb(const void *data, void *private) --- 112 unchanged lines hidden --- | 290 unsigned int size = DFSDM_MAX_PERIODS * DFSDM_MAX_PERIOD_SIZE; 291 292 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, 293 priv->dev, size, size); 294 return 0; 295} 296 297static int stm32_adfsdm_dummy_cb(const void *data, void *private) --- 112 unchanged lines hidden --- |