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 struct snd_soc_acpi_mach *
20 snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
22 struct snd_soc_acpi_mach *mach;
24 for (mach = machines; mach->id[0]; mach++) {
25 if (acpi_dev_present(mach->id, NULL, -1)) {
26 if (mach->machine_quirk)
27 mach = mach->machine_quirk(mach);
33 EXPORT_SYMBOL_GPL(snd_soc_acpi_find_machine);
35 static acpi_status snd_soc_acpi_find_package(acpi_handle handle, u32 level,
36 void *context, void **ret)
38 struct acpi_device *adev;
39 acpi_status status = AE_OK;
40 struct snd_soc_acpi_package_context *pkg_ctx = context;
42 pkg_ctx->data_valid = false;
44 if (acpi_bus_get_device(handle, &adev))
47 if (adev->status.present && adev->status.functional) {
48 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
49 union acpi_object *myobj = NULL;
51 status = acpi_evaluate_object_typed(handle, pkg_ctx->name,
54 if (ACPI_FAILURE(status))
57 myobj = buffer.pointer;
58 if (!myobj || myobj->package.count != pkg_ctx->length) {
59 kfree(buffer.pointer);
63 status = acpi_extract_package(myobj,
64 pkg_ctx->format, pkg_ctx->state);
65 if (ACPI_FAILURE(status)) {
66 kfree(buffer.pointer);
70 kfree(buffer.pointer);
71 pkg_ctx->data_valid = true;
72 return AE_CTRL_TERMINATE;
78 bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
79 struct snd_soc_acpi_package_context *ctx)
83 status = acpi_get_devices(hid, snd_soc_acpi_find_package, ctx, NULL);
85 if (ACPI_FAILURE(status) || !ctx->data_valid)
90 EXPORT_SYMBOL_GPL(snd_soc_acpi_find_package_from_hid);
92 struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
94 struct snd_soc_acpi_mach *mach = arg;
95 struct snd_soc_acpi_codecs *codec_list =
96 (struct snd_soc_acpi_codecs *) mach->quirk_data;
99 if (mach->quirk_data == NULL)
102 for (i = 0; i < codec_list->num_codecs; i++) {
103 if (!acpi_dev_present(codec_list->codecs[i], NULL, -1))
109 EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
111 MODULE_LICENSE("GPL v2");
112 MODULE_DESCRIPTION("ALSA SoC ACPI module");