sound/hda/codecs/side-codecs/hda_component.c

Source file repositories/reference/linux-study-clean/sound/hda/codecs/side-codecs/hda_component.c

File Facts

System
Linux kernel
Corpus path
sound/hda/codecs/side-codecs/hda_component.c
Extension
.c
Size
5841 bytes
Lines
210
Domain
Driver Families
Bucket
sound/hda
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 hda_scodec_match {
	const char *bus;
	const char *hid;
	const char *match_str;
	int index;
};

/* match the device name in a slightly relaxed manner */
static int hda_comp_match_dev_name(struct device *dev, void *data)
{
	struct hda_scodec_match *p = data;
	const char *d = dev_name(dev);
	int n = strlen(p->bus);
	char tmp[32];

	/* check the bus name */
	if (strncmp(d, p->bus, n))
		return 0;
	/* skip the bus number */
	if (isdigit(d[n]))
		n++;
	/* the rest must be exact matching */
	snprintf(tmp, sizeof(tmp), p->match_str, p->hid, p->index);
	return !strcmp(d + n, tmp);
}

int hda_component_manager_bind(struct hda_codec *cdc,
			       struct hda_component_parent *parent)
{
	/* Init shared and component specific data */
	memset(parent->comps, 0, sizeof(parent->comps));

	guard(mutex)(&parent->mutex);
	return component_bind_all(hda_codec_dev(cdc), parent);
}
EXPORT_SYMBOL_NS_GPL(hda_component_manager_bind, "SND_HDA_SCODEC_COMPONENT");

int hda_component_manager_init(struct hda_codec *cdc,
			       struct hda_component_parent *parent, int count,
			       const char *bus, const char *hid,
			       const char *match_str,
			       const struct component_master_ops *ops)
{
	struct device *dev = hda_codec_dev(cdc);
	struct component_match *match = NULL;
	struct hda_scodec_match *sm;
	int ret, i;

	if (parent->codec) {
		codec_err(cdc, "Component binding already created (SSID: %x)\n",
			  cdc->core.subsystem_id);
		return -EINVAL;
	}
	parent->codec = cdc;

	mutex_init(&parent->mutex);

	for (i = 0; i < count; i++) {
		sm = devm_kmalloc(dev, sizeof(*sm), GFP_KERNEL);
		if (!sm)
			return -ENOMEM;

		sm->bus = bus;
		sm->hid = hid;
		sm->match_str = match_str;
		sm->index = i;
		component_match_add(dev, &match, hda_comp_match_dev_name, sm);
		if (IS_ERR(match)) {
			codec_err(cdc, "Fail to add component %ld\n", PTR_ERR(match));
			return PTR_ERR(match);
		}
	}

	ret = component_master_add_with_match(dev, ops, match);
	if (ret)
		codec_err(cdc, "Fail to register component aggregator %d\n", ret);

	return ret;
}
EXPORT_SYMBOL_NS_GPL(hda_component_manager_init, "SND_HDA_SCODEC_COMPONENT");

void hda_component_manager_free(struct hda_component_parent *parent,
				const struct component_master_ops *ops)
{
	struct device *dev;

	if (!parent->codec)
		return;

	dev = hda_codec_dev(parent->codec);

Annotation

Implementation Notes