Lines Matching +full:open +full:- +full:dice

1 // SPDX-License-Identifier: GPL-2.0-only
3 * dice_pcm.c - a part of driver for DICE based devices
6 * Copyright (c) 2014 Takashi Sakamoto <o-takashi@sakamocchi.jp>
9 #include "dice.h"
14 struct snd_pcm_substream *substream = rule->private;
15 struct snd_dice *dice = substream->private_data;
16 unsigned int index = substream->pcm->device;
29 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
30 pcm_channels = dice->tx_pcm_chs[index];
32 pcm_channels = dice->rx_pcm_chs[index];
36 if (snd_dice_stream_get_rate_mode(dice, rate, &mode) < 0)
52 struct snd_pcm_substream *substream = rule->private;
53 struct snd_dice *dice = substream->private_data;
54 unsigned int index = substream->pcm->device;
67 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
68 pcm_channels = dice->tx_pcm_chs[index];
70 pcm_channels = dice->rx_pcm_chs[index];
74 if (snd_dice_stream_get_rate_mode(dice, rate, &mode) < 0)
87 static int limit_channels_and_rates(struct snd_dice *dice,
92 struct snd_pcm_hardware *hw = &runtime->hw;
97 pcm_channels = dice->tx_pcm_chs[index];
99 pcm_channels = dice->rx_pcm_chs[index];
101 hw->channels_min = UINT_MAX;
102 hw->channels_max = 0;
109 if (snd_dice_stream_get_rate_mode(dice, rate, &mode) < 0)
111 hw->rates |= snd_pcm_rate_to_rate_bit(rate);
116 hw->channels_min = min(hw->channels_min, channels);
117 hw->channels_max = max(hw->channels_max, channels);
125 static int init_hw_info(struct snd_dice *dice,
128 struct snd_pcm_runtime *runtime = substream->runtime;
129 struct snd_pcm_hardware *hw = &runtime->hw;
130 unsigned int index = substream->pcm->device;
135 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
136 hw->formats = AM824_IN_PCM_FORMAT_BITS;
138 stream = &dice->tx_stream[index];
140 hw->formats = AM824_OUT_PCM_FORMAT_BITS;
142 stream = &dice->rx_stream[index];
145 err = limit_channels_and_rates(dice, substream->runtime, dir,
152 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
157 SNDRV_PCM_HW_PARAM_RATE, -1);
166 struct snd_dice *dice = substream->private_data;
167 struct amdtp_domain *d = &dice->domain;
172 err = snd_dice_stream_lock_try(dice);
176 err = init_hw_info(dice, substream);
180 err = snd_dice_transaction_get_clock_source(dice, &source);
199 scoped_guard(mutex, &dice->mutex) {
204 (dice->substreams_counter > 0 && d->events_per_period > 0)) {
205 unsigned int frames_per_period = d->events_per_period;
206 unsigned int frames_per_buffer = d->events_per_buffer;
209 err = snd_dice_transaction_get_rate(dice, &rate);
213 substream->runtime->hw.rate_min = rate;
214 substream->runtime->hw.rate_max = rate;
218 if (rate > 96000 && !dice->disable_double_pcm_frames) {
223 err = snd_pcm_hw_constraint_minmax(substream->runtime,
229 err = snd_pcm_hw_constraint_minmax(substream->runtime,
242 snd_dice_stream_lock_release(dice);
248 struct snd_dice *dice = substream->private_data;
250 snd_dice_stream_lock_release(dice);
258 struct snd_dice *dice = substream->private_data;
261 if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
266 guard(mutex)(&dice->mutex);
268 if (rate > 96000 && !dice->disable_double_pcm_frames) {
272 err = snd_dice_stream_reserve_duplex(dice, rate,
275 ++dice->substreams_counter;
283 struct snd_dice *dice = substream->private_data;
285 guard(mutex)(&dice->mutex);
287 if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
288 --dice->substreams_counter;
290 snd_dice_stream_stop_duplex(dice);
297 struct snd_dice *dice = substream->private_data;
298 struct amdtp_stream *stream = &dice->tx_stream[substream->pcm->device];
301 scoped_guard(mutex, &dice->mutex) {
302 err = snd_dice_stream_start_duplex(dice);
311 struct snd_dice *dice = substream->private_data;
312 struct amdtp_stream *stream = &dice->rx_stream[substream->pcm->device];
315 scoped_guard(mutex, &dice->mutex) {
316 err = snd_dice_stream_start_duplex(dice);
326 struct snd_dice *dice = substream->private_data;
327 struct amdtp_stream *stream = &dice->tx_stream[substream->pcm->device];
337 return -EINVAL;
344 struct snd_dice *dice = substream->private_data;
345 struct amdtp_stream *stream = &dice->rx_stream[substream->pcm->device];
355 return -EINVAL;
363 struct snd_dice *dice = substream->private_data;
364 struct amdtp_stream *stream = &dice->tx_stream[substream->pcm->device];
366 return amdtp_domain_stream_pcm_pointer(&dice->domain, stream);
370 struct snd_dice *dice = substream->private_data;
371 struct amdtp_stream *stream = &dice->rx_stream[substream->pcm->device];
373 return amdtp_domain_stream_pcm_pointer(&dice->domain, stream);
378 struct snd_dice *dice = substream->private_data;
379 struct amdtp_stream *stream = &dice->tx_stream[substream->pcm->device];
381 return amdtp_domain_stream_pcm_ack(&dice->domain, stream);
386 struct snd_dice *dice = substream->private_data;
387 struct amdtp_stream *stream = &dice->rx_stream[substream->pcm->device];
389 return amdtp_domain_stream_pcm_ack(&dice->domain, stream);
392 int snd_dice_create_pcm(struct snd_dice *dice)
395 .open = pcm_open,
405 .open = pcm_open,
422 if (dice->tx_pcm_chs[i][j] > 0)
424 if (dice->rx_pcm_chs[i][j] > 0)
428 err = snd_pcm_new(dice->card, "DICE", i, playback, capture,
432 pcm->private_data = dice;
433 pcm->nonatomic = true;
434 strscpy(pcm->name, dice->card->shortname);