sound/firewire/dice/dice-pcm.c

Source file repositories/reference/linux-study-clean/sound/firewire/dice/dice-pcm.c

File Facts

System
Linux kernel
Corpus path
sound/firewire/dice/dice-pcm.c
Extension
.c
Size
11690 bytes
Lines
450
Domain
Driver Families
Bucket
sound/firewire
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (frames_per_period > 0) {
				// For double_pcm_frame quirk.
				if (rate > 96000 && !dice->disable_double_pcm_frames) {
					frames_per_period *= 2;
					frames_per_buffer *= 2;
				}

				err = snd_pcm_hw_constraint_minmax(substream->runtime,
								   SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
								   frames_per_period, frames_per_period);
				if (err < 0)
					goto err_locked;

				err = snd_pcm_hw_constraint_minmax(substream->runtime,
								   SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
								   frames_per_buffer, frames_per_buffer);
				if (err < 0)
					goto err_locked;
			}
		}
	}

	snd_pcm_set_sync(substream);

	return 0;
err_locked:
	snd_dice_stream_lock_release(dice);
	return err;
}

static int pcm_close(struct snd_pcm_substream *substream)
{
	struct snd_dice *dice = substream->private_data;

	snd_dice_stream_lock_release(dice);

	return 0;
}

static int pcm_hw_params(struct snd_pcm_substream *substream,
			 struct snd_pcm_hw_params *hw_params)
{
	struct snd_dice *dice = substream->private_data;
	int err = 0;

	if (substream->runtime->state == SNDRV_PCM_STATE_OPEN) {
		unsigned int rate = params_rate(hw_params);
		unsigned int events_per_period = params_period_size(hw_params);
		unsigned int events_per_buffer = params_buffer_size(hw_params);

		guard(mutex)(&dice->mutex);
		// For double_pcm_frame quirk.
		if (rate > 96000 && !dice->disable_double_pcm_frames) {
			events_per_period /= 2;
			events_per_buffer /= 2;
		}
		err = snd_dice_stream_reserve_duplex(dice, rate,
					events_per_period, events_per_buffer);
		if (err >= 0)
			++dice->substreams_counter;
	}

	return err;
}

static int pcm_hw_free(struct snd_pcm_substream *substream)
{
	struct snd_dice *dice = substream->private_data;

	guard(mutex)(&dice->mutex);

	if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
		--dice->substreams_counter;

	snd_dice_stream_stop_duplex(dice);

	return 0;
}

static int capture_prepare(struct snd_pcm_substream *substream)
{
	struct snd_dice *dice = substream->private_data;
	struct amdtp_stream *stream = &dice->tx_stream[substream->pcm->device];
	int err;

	scoped_guard(mutex, &dice->mutex) {
		err = snd_dice_stream_start_duplex(dice);
	}
	if (err >= 0)
		amdtp_stream_pcm_prepare(stream);

Annotation

Implementation Notes