2 * soc-apci.c - support for ACPI enumeration.
4 * Copyright (c) 2013-15, Intel Corporation.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 #include <sound/soc-acpi.h>
19 static acpi_status snd_soc_acpi_find_name(acpi_handle handle, u32 level,
20 void *context, void **ret)
22 struct acpi_device *adev;
23 const char *name = NULL;
25 if (acpi_bus_get_device(handle, &adev))
28 if (adev->status.present && adev->status.functional) {
29 name = acpi_dev_name(adev);
30 *(const char **)ret = name;
31 return AE_CTRL_TERMINATE;
37 const char *snd_soc_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN])
39 const char *name = NULL;
42 status = acpi_get_devices(hid, snd_soc_acpi_find_name, NULL,
45 if (ACPI_FAILURE(status) || name[0] == '\0')
50 EXPORT_SYMBOL_GPL(snd_soc_acpi_find_name_from_hid);
52 struct snd_soc_acpi_mach *
53 snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
55 struct snd_soc_acpi_mach *mach;
57 for (mach = machines; mach->id[0]; mach++) {
58 if (acpi_dev_present(mach->id, NULL, -1)) {
59 if (mach->machine_quirk)
60 mach = mach->machine_quirk(mach);
66 EXPORT_SYMBOL_GPL(snd_soc_acpi_find_machine);
68 static acpi_status snd_soc_acpi_find_package(acpi_handle handle, u32 level,
69 void *context, void **ret)
71 struct acpi_device *adev;
72 acpi_status status = AE_OK;
73 struct snd_soc_acpi_package_context *pkg_ctx = context;
75 pkg_ctx->data_valid = false;
77 if (acpi_bus_get_device(handle, &adev))
80 if (adev->status.present && adev->status.functional) {
81 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
82 union acpi_object *myobj = NULL;
84 status = acpi_evaluate_object_typed(handle, pkg_ctx->name,
87 if (ACPI_FAILURE(status))
90 myobj = buffer.pointer;
91 if (!myobj || myobj->package.count != pkg_ctx->length) {
92 kfree(buffer.pointer);
96 status = acpi_extract_package(myobj,
97 pkg_ctx->format, pkg_ctx->state);
98 if (ACPI_FAILURE(status)) {
99 kfree(buffer.pointer);
103 kfree(buffer.pointer);
104 pkg_ctx->data_valid = true;
105 return AE_CTRL_TERMINATE;
111 bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
112 struct snd_soc_acpi_package_context *ctx)
116 status = acpi_get_devices(hid, snd_soc_acpi_find_package, ctx, NULL);
118 if (ACPI_FAILURE(status) || !ctx->data_valid)
123 EXPORT_SYMBOL_GPL(snd_soc_acpi_find_package_from_hid);
125 struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
127 struct snd_soc_acpi_mach *mach = arg;
128 struct snd_soc_acpi_codecs *codec_list =
129 (struct snd_soc_acpi_codecs *) mach->quirk_data;
132 if (mach->quirk_data == NULL)
135 for (i = 0; i < codec_list->num_codecs; i++) {
136 if (!acpi_dev_present(codec_list->codecs[i], NULL, -1))
142 EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
144 MODULE_LICENSE("GPL v2");
145 MODULE_DESCRIPTION("ALSA SoC ACPI module");