Lines Matching +full:pcm +full:- +full:interface +full:- +full:rate

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * sh_dac_audio.c - SuperH DAC audio driver for ALSA
18 #include <sound/pcm.h>
44 int rate; member
55 hrtimer_start(&chip->hrtimer, chip->wakeups_per_second, in dac_audio_start_timer()
61 hrtimer_cancel(&chip->hrtimer); in dac_audio_stop_timer()
67 chip->buffer_begin = chip->buffer_end = chip->data_buffer; in dac_audio_reset()
68 chip->processed = 0; in dac_audio_reset()
69 chip->empty = 1; in dac_audio_reset()
74 chip->wakeups_per_second = 1000000000 / chip->rate; in dac_audio_set_rate()
78 /* PCM INTERFACE */
101 struct snd_pcm_runtime *runtime = substream->runtime; in snd_sh_dac_pcm_open()
103 runtime->hw = snd_sh_dac_pcm_hw; in snd_sh_dac_pcm_open()
105 chip->substream = substream; in snd_sh_dac_pcm_open()
106 chip->buffer_begin = chip->buffer_end = chip->data_buffer; in snd_sh_dac_pcm_open()
107 chip->processed = 0; in snd_sh_dac_pcm_open()
108 chip->empty = 1; in snd_sh_dac_pcm_open()
110 chip->pdata->start(chip->pdata); in snd_sh_dac_pcm_open()
119 chip->substream = NULL; in snd_sh_dac_pcm_close()
122 chip->pdata->stop(chip->pdata); in snd_sh_dac_pcm_close()
130 struct snd_pcm_runtime *runtime = chip->substream->runtime; in snd_sh_dac_pcm_prepare()
132 chip->buffer_size = runtime->buffer_size; in snd_sh_dac_pcm_prepare()
133 memset(chip->data_buffer, 0, chip->pdata->buffer_size); in snd_sh_dac_pcm_prepare()
147 chip->buffer_begin = chip->buffer_end = chip->data_buffer; in snd_sh_dac_pcm_trigger()
148 chip->processed = 0; in snd_sh_dac_pcm_trigger()
149 chip->empty = 1; in snd_sh_dac_pcm_trigger()
153 return -EINVAL; in snd_sh_dac_pcm_trigger()
166 if (copy_from_iter(chip->data_buffer + pos, count, src) != count) in snd_sh_dac_pcm_copy()
167 return -EFAULT; in snd_sh_dac_pcm_copy()
168 chip->buffer_end = chip->data_buffer + pos + count; in snd_sh_dac_pcm_copy()
170 if (chip->empty) { in snd_sh_dac_pcm_copy()
171 chip->empty = 0; in snd_sh_dac_pcm_copy()
185 memset(chip->data_buffer + pos, 0, count); in snd_sh_dac_pcm_silence()
186 chip->buffer_end = chip->data_buffer + pos + count; in snd_sh_dac_pcm_silence()
188 if (chip->empty) { in snd_sh_dac_pcm_silence()
189 chip->empty = 0; in snd_sh_dac_pcm_silence()
200 int pointer = chip->buffer_begin - chip->data_buffer; in snd_sh_dac_pcm_pointer()
205 /* pcm ops */
219 struct snd_pcm *pcm; in snd_sh_dac_pcm() local
222 err = snd_pcm_new(chip->card, "SH_DAC PCM", device, 1, 0, &pcm); in snd_sh_dac_pcm()
226 pcm->private_data = chip; in snd_sh_dac_pcm()
227 strcpy(pcm->name, "SH_DAC PCM"); in snd_sh_dac_pcm()
228 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sh_dac_pcm_ops); in snd_sh_dac_pcm()
231 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, in snd_sh_dac_pcm()
236 /* END OF PCM INTERFACE */
239 /* driver .remove -- destructor */
245 /* free -- it has been defined by create */
249 kfree(chip->data_buffer); in snd_sh_dac_free()
257 struct snd_sh_dac *chip = device->device_data; in snd_sh_dac_dev_free()
266 struct snd_pcm_runtime *runtime = chip->substream->runtime; in sh_dac_audio_timer()
267 ssize_t b_ps = frames_to_bytes(runtime, runtime->period_size); in sh_dac_audio_timer()
269 if (!chip->empty) { in sh_dac_audio_timer()
270 sh_dac_output(*chip->buffer_begin, chip->pdata->channel); in sh_dac_audio_timer()
271 chip->buffer_begin++; in sh_dac_audio_timer()
273 chip->processed++; in sh_dac_audio_timer()
274 if (chip->processed >= b_ps) { in sh_dac_audio_timer()
275 chip->processed -= b_ps; in sh_dac_audio_timer()
276 snd_pcm_period_elapsed(chip->substream); in sh_dac_audio_timer()
279 if (chip->buffer_begin == (chip->data_buffer + in sh_dac_audio_timer()
280 chip->buffer_size - 1)) in sh_dac_audio_timer()
281 chip->buffer_begin = chip->data_buffer; in sh_dac_audio_timer()
283 if (chip->buffer_begin == chip->buffer_end) in sh_dac_audio_timer()
284 chip->empty = 1; in sh_dac_audio_timer()
288 if (!chip->empty) in sh_dac_audio_timer()
289 hrtimer_start(&chip->hrtimer, chip->wakeups_per_second, in sh_dac_audio_timer()
295 /* create -- chip-specific constructor for the cards components */
311 return -ENOMEM; in snd_sh_dac_create()
313 chip->card = card; in snd_sh_dac_create()
315 hrtimer_setup(&chip->hrtimer, sh_dac_audio_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in snd_sh_dac_create()
318 chip->rate = 8000; in snd_sh_dac_create()
321 chip->pdata = devptr->dev.platform_data; in snd_sh_dac_create()
323 chip->data_buffer = kmalloc(chip->pdata->buffer_size, GFP_KERNEL); in snd_sh_dac_create()
324 if (chip->data_buffer == NULL) { in snd_sh_dac_create()
326 return -ENOMEM; in snd_sh_dac_create()
340 /* driver .probe -- constructor */
347 err = snd_card_new(&devptr->dev, index, id, THIS_MODULE, 0, &card); in snd_sh_dac_probe()
349 dev_err(&devptr->dev, "cannot allocate the card\n"); in snd_sh_dac_probe()
361 strcpy(card->driver, "snd_sh_dac"); in snd_sh_dac_probe()
362 strcpy(card->shortname, "SuperH DAC audio driver"); in snd_sh_dac_probe()
363 dev_info(&devptr->dev, "%s %s\n", card->longname, card->shortname); in snd_sh_dac_probe()
369 dev_info(&devptr->dev, "ALSA driver for SuperH DAC audio\n"); in snd_sh_dac_probe()