sound/soc/codecs/cs-amp-lib.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/cs-amp-lib.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/cs-amp-lib.c
Extension
.c
Size
25401 bytes
Lines
865
Domain
Driver Families
Bucket
sound/soc
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 cs_amp_spkid_efi {
	efi_char16_t *name;
	efi_guid_t *guid;
	u8 values[2];
};

static int cs_amp_get_efi_byte_spkid(struct device *dev, const struct cs_amp_spkid_efi *info)
{
	efi_status_t status;
	unsigned long size;
	u8 spkid;
	int i, ret;

	size = sizeof(spkid);
	status = cs_amp_get_efi_variable(info->name, info->guid, NULL, &size, &spkid);
	ret = cs_amp_convert_efi_status(status);
	if (ret < 0)
		return ret;

	if (size == 0)
		return -ENOENT;

	for (i = 0; i < ARRAY_SIZE(info->values); i++) {
		if (info->values[i] == spkid)
			return i;
	}

	dev_err(dev, "EFI speaker ID bad value %#x\n", spkid);

	return -EINVAL;
}

static const struct cs_amp_spkid_efi cs_amp_spkid_byte_types[] = {
	{
		.name = LENOVO_SPEAKER_ID_EFI_NAME,
		.guid = &LENOVO_SPEAKER_ID_EFI_GUID,
		.values = { 0xd0, 0xd1 },
	},
	{
		.name = HP_SPEAKER_ID_EFI_NAME,
		.guid = &HP_SPEAKER_ID_EFI_GUID,
		.values = { 0x30, 0x31 },
	},
};

/**
 * cs_amp_get_vendor_spkid - get a speaker ID from vendor-specific storage
 * @dev:	pointer to struct device
 *
 * Known vendor-specific methods of speaker ID are checked and if one is
 * found its speaker ID value is returned.
 *
 * Return: >=0 is a valid speaker ID. -ENOENT if a vendor-specific method
 *	   was not found. -EACCES if the vendor-specific storage could not
 *	   be read. Other error values indicate that the data from the
 *	   vendor-specific storage was found but could not be understood.
 */
int cs_amp_get_vendor_spkid(struct device *dev)
{
	int i, ret;

	KUNIT_STATIC_STUB_REDIRECT(cs_amp_get_vendor_spkid, dev);

	if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE) &&
	    !IS_ENABLED(CONFIG_SND_SOC_CS_AMP_LIB_TEST_HOOKS))
		return -ENOENT;

	for (i = 0; i < ARRAY_SIZE(cs_amp_spkid_byte_types); i++) {
		ret = cs_amp_get_efi_byte_spkid(dev, &cs_amp_spkid_byte_types[i]);
		if (ret != -ENOENT)
			return ret;
	}

	return -ENOENT;
}
EXPORT_SYMBOL_NS_GPL(cs_amp_get_vendor_spkid, "SND_SOC_CS_AMP_LIB");

static const char *cs_amp_devm_get_dell_ssidex(struct device *dev,
					       int ssid_vendor, int ssid_device)
{
	unsigned int hex_prefix;
	char audio_id[4];
	char delim;
	char *p;
	int ret;

	if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE) &&
	    !IS_ENABLED(CONFIG_SND_SOC_CS_AMP_LIB_TEST_HOOKS))
		return ERR_PTR(-ENOENT);

Annotation

Implementation Notes