sound/soc/soc-topology-test.c

Source file repositories/reference/linux-study-clean/sound/soc/soc-topology-test.c

File Facts

System
Linux kernel
Corpus path
sound/soc/soc-topology-test.c
Extension
.c
Size
24224 bytes
Lines
822
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 kunit_soc_component {
	struct kunit *kunit;
	int expect; /* what result we expect when loading topology */
	struct snd_soc_component comp;
	struct snd_soc_card card;
	struct firmware fw;
};

static int d_probe(struct snd_soc_component *component)
{
	struct kunit_soc_component *kunit_comp =
			container_of(component, struct kunit_soc_component, comp);
	int ret;

	ret = snd_soc_tplg_component_load(component, NULL, &kunit_comp->fw);
	KUNIT_EXPECT_EQ_MSG(kunit_comp->kunit, kunit_comp->expect, ret,
			    "Failed topology load");

	return 0;
}

static void d_remove(struct snd_soc_component *component)
{
	struct kunit_soc_component *kunit_comp =
			container_of(component, struct kunit_soc_component, comp);
	int ret;

	ret = snd_soc_tplg_component_remove(component);
	KUNIT_EXPECT_EQ(kunit_comp->kunit, 0, ret);
}

/*
 * ASoC minimal boiler plate
 */
SND_SOC_DAILINK_DEF(dummy, DAILINK_COMP_ARRAY(COMP_DUMMY()));

SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("sound-soc-topology-test")));

static struct snd_soc_dai_link kunit_dai_links[] = {
	{
		.name = "KUNIT Audio Port",
		.id = 0,
		.stream_name = "Audio Playback/Capture",
		.nonatomic = 1,
		.dynamic = 1,
		.trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
		SND_SOC_DAILINK_REG(dummy, dummy, platform),
	},
};

static const struct snd_soc_component_driver test_component = {
	.name = "sound-soc-topology-test",
	.probe = d_probe,
	.remove = d_remove,
};

/* ===== TOPOLOGY TEMPLATES ================================================= */

// Structural representation of topology which can be generated with:
// $ touch empty
// $ alsatplg -c empty -o empty.tplg
// $ xxd -i empty.tplg

struct tplg_tmpl_001 {
	struct snd_soc_tplg_hdr header;
	struct snd_soc_tplg_manifest manifest;
} __packed;

static struct tplg_tmpl_001 tplg_tmpl_empty = {
	.header = {
		.magic = cpu_to_le32(SND_SOC_TPLG_MAGIC),
		.abi = cpu_to_le32(5),
		.version = 0,
		.type = cpu_to_le32(SND_SOC_TPLG_TYPE_MANIFEST),
		.size = cpu_to_le32(sizeof(struct snd_soc_tplg_hdr)),
		.vendor_type = 0,
		.payload_size = cpu_to_le32(sizeof(struct snd_soc_tplg_manifest)),
		.index = 0,
		.count = cpu_to_le32(1),
	},

	.manifest = {
		.size = cpu_to_le32(sizeof(struct snd_soc_tplg_manifest)),
		/* rest of fields is 0 */
	},
};

// Structural representation of topology containing SectionPCM

struct tplg_tmpl_002 {

Annotation

Implementation Notes