sound/firewire/fireface/ff-pcm.c

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

File Facts

System
Linux kernel
Corpus path
sound/firewire/fireface/ff-pcm.c
Extension
.c
Size
9660 bytes
Lines
388
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 (src != SND_FF_CLOCK_SRC_INTERNAL) {
			for (i = 0; i < CIP_SFC_COUNT; ++i) {
				if (amdtp_rate_table[i] == rate)
					break;
			}

			// The unit is configured at sampling frequency which packet
			// streaming engine can't support.
			if (i >= CIP_SFC_COUNT) {
				err = -EIO;
				goto release_lock;
			}

			substream->runtime->hw.rate_min = rate;
			substream->runtime->hw.rate_max = rate;
		} else {
			if (ff->substreams_counter > 0) {
				unsigned int frames_per_period = d->events_per_period;
				unsigned int frames_per_buffer = d->events_per_buffer;

				rate = amdtp_rate_table[ff->rx_stream.sfc];
				substream->runtime->hw.rate_min = rate;
				substream->runtime->hw.rate_max = rate;

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

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

	snd_pcm_set_sync(substream);

	return 0;

release_lock:
	snd_ff_stream_lock_release(ff);
	return err;
}

static int pcm_close(struct snd_pcm_substream *substream)
{
	struct snd_ff *ff = substream->private_data;

	snd_ff_stream_lock_release(ff);

	return 0;
}

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

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

		guard(mutex)(&ff->mutex);
		err = snd_ff_stream_reserve_duplex(ff, rate, frames_per_period,
						   frames_per_buffer);
		if (err >= 0)
			++ff->substreams_counter;
	}

	return err;
}

static int pcm_hw_free(struct snd_pcm_substream *substream)
{
	struct snd_ff *ff = substream->private_data;

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

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

	snd_ff_stream_stop_duplex(ff);

	return 0;

Annotation

Implementation Notes