1 // SPDX-License-Identifier: GPL-2.0
3 // soc-apci.c - support for ACPI enumeration.
5 // Copyright (c) 2013-15, Intel Corporation.
7 #include <linux/export.h>
8 #include <linux/module.h>
9 #include <sound/soc-acpi.h>
11 static bool snd_soc_acpi_id_present(struct snd_soc_acpi_mach *machine)
13 const struct snd_soc_acpi_codecs *comp_ids = machine->comp_ids;
17 if (acpi_dev_present(machine->id, NULL, -1))
22 for (i = 0; i < comp_ids->num_codecs; i++) {
23 if (acpi_dev_present(comp_ids->codecs[i], NULL, -1)) {
24 strscpy(machine->id, comp_ids->codecs[i], ACPI_ID_LEN);
33 struct snd_soc_acpi_mach *
34 snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
36 struct snd_soc_acpi_mach *mach;
37 struct snd_soc_acpi_mach *mach_alt;
39 for (mach = machines; mach->id[0] || mach->comp_ids; mach++) {
40 if (snd_soc_acpi_id_present(mach)) {
41 if (mach->machine_quirk) {
42 mach_alt = mach->machine_quirk(mach);
44 continue; /* not full match, ignore */
53 EXPORT_SYMBOL_GPL(snd_soc_acpi_find_machine);
55 static acpi_status snd_soc_acpi_find_package(acpi_handle handle, u32 level,
56 void *context, void **ret)
58 struct acpi_device *adev;
60 struct snd_soc_acpi_package_context *pkg_ctx = context;
62 pkg_ctx->data_valid = false;
64 if (acpi_bus_get_device(handle, &adev))
67 if (adev->status.present && adev->status.functional) {
68 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
69 union acpi_object *myobj = NULL;
71 status = acpi_evaluate_object_typed(handle, pkg_ctx->name,
74 if (ACPI_FAILURE(status))
77 myobj = buffer.pointer;
78 if (!myobj || myobj->package.count != pkg_ctx->length) {
79 kfree(buffer.pointer);
83 status = acpi_extract_package(myobj,
84 pkg_ctx->format, pkg_ctx->state);
85 if (ACPI_FAILURE(status)) {
86 kfree(buffer.pointer);
90 kfree(buffer.pointer);
91 pkg_ctx->data_valid = true;
92 return AE_CTRL_TERMINATE;
98 bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
99 struct snd_soc_acpi_package_context *ctx)
103 status = acpi_get_devices(hid, snd_soc_acpi_find_package, ctx, NULL);
105 if (ACPI_FAILURE(status) || !ctx->data_valid)
110 EXPORT_SYMBOL_GPL(snd_soc_acpi_find_package_from_hid);
112 struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
114 struct snd_soc_acpi_mach *mach = arg;
115 struct snd_soc_acpi_codecs *codec_list =
116 (struct snd_soc_acpi_codecs *) mach->quirk_data;
119 if (mach->quirk_data == NULL)
122 for (i = 0; i < codec_list->num_codecs; i++) {
123 if (!acpi_dev_present(codec_list->codecs[i], NULL, -1))
129 EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
131 MODULE_LICENSE("GPL v2");
132 MODULE_DESCRIPTION("ALSA SoC ACPI module");