sound/soc/codecs/sdw-mockup.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/sdw-mockup.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/sdw-mockup.c
Extension
.c
Size
6683 bytes
Lines
270
Domain
Driver Families
Bucket
sound/soc
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

struct  sdw_mockup_priv {
	struct sdw_slave *slave;
};

static int sdw_mockup_component_probe(struct snd_soc_component *component)
{
	return 0;
}

static void sdw_mockup_component_remove(struct snd_soc_component *component)
{
}

static const struct snd_soc_component_driver snd_soc_sdw_mockup_component = {
	.probe = sdw_mockup_component_probe,
	.remove = sdw_mockup_component_remove,
	.endianness = 1,
};

static int sdw_mockup_set_sdw_stream(struct snd_soc_dai *dai, void *sdw_stream,
				     int direction)
{
	snd_soc_dai_dma_data_set(dai, direction, sdw_stream);

	return 0;
}

static void sdw_mockup_shutdown(struct snd_pcm_substream *substream,
				struct snd_soc_dai *dai)
{
	snd_soc_dai_set_dma_data(dai, substream, NULL);
}

static int sdw_mockup_pcm_hw_params(struct snd_pcm_substream *substream,
				    struct snd_pcm_hw_params *params,
				    struct snd_soc_dai *dai)
{
	struct snd_soc_component *component = dai->component;
	struct sdw_mockup_priv *sdw_mockup = snd_soc_component_get_drvdata(component);
	struct sdw_stream_config stream_config = {0};
	struct sdw_port_config port_config = {0};
	struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream);
	int ret;

	if (!sdw_stream)
		return -EINVAL;

	if (!sdw_mockup->slave)
		return -EINVAL;

	/* SoundWire specific configuration */
	snd_sdw_params_to_config(substream, params, &stream_config, &port_config);

	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
		port_config.num = 1;
	else
		port_config.num = 8;

	ret = sdw_stream_add_slave(sdw_mockup->slave, &stream_config,
				   &port_config, 1, sdw_stream);
	if (ret)
		dev_err(dai->dev, "Unable to configure port\n");

	return ret;
}

static int sdw_mockup_pcm_hw_free(struct snd_pcm_substream *substream,
				  struct snd_soc_dai *dai)
{
	struct snd_soc_component *component = dai->component;
	struct sdw_mockup_priv *sdw_mockup = snd_soc_component_get_drvdata(component);
	struct sdw_stream_runtime *sdw_stream = snd_soc_dai_get_dma_data(dai, substream);

	if (!sdw_mockup->slave)
		return -EINVAL;

	sdw_stream_remove_slave(sdw_mockup->slave, sdw_stream);
	return 0;
}

static const struct snd_soc_dai_ops sdw_mockup_ops = {
	.hw_params	= sdw_mockup_pcm_hw_params,
	.hw_free	= sdw_mockup_pcm_hw_free,
	.set_stream	= sdw_mockup_set_sdw_stream,
	.shutdown	= sdw_mockup_shutdown,
};

static struct snd_soc_dai_driver sdw_mockup_dai[] = {
	{
		.name = "sdw-mockup-aif1",

Annotation

Implementation Notes