Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
[linux-2.6-block.git] / sound / soc / soc-acpi.c
CommitLineData
7730bb13
KM
1// SPDX-License-Identifier: GPL-2.0
2//
3// soc-apci.c - support for ACPI enumeration.
4//
5// Copyright (c) 2013-15, Intel Corporation.
95f09801 6
261e9082
PG
7#include <linux/export.h>
8#include <linux/module.h>
7feb2f78 9#include <sound/soc-acpi.h>
95f09801 10
7feb2f78
PLB
11struct snd_soc_acpi_mach *
12snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
95f09801 13{
7feb2f78 14 struct snd_soc_acpi_mach *mach;
a3e620f8 15 struct snd_soc_acpi_mach *mach_alt;
95f09801 16
7827d669 17 for (mach = machines; mach->id[0]; mach++) {
0d5ea120 18 if (acpi_dev_present(mach->id, NULL, -1)) {
a3e620f8
KJ
19 if (mach->machine_quirk) {
20 mach_alt = mach->machine_quirk(mach);
21 if (!mach_alt)
22 continue; /* not full match, ignore */
23 mach = mach_alt;
24 }
25
5c256045 26 return mach;
7827d669
N
27 }
28 }
95f09801
VK
29 return NULL;
30}
7feb2f78 31EXPORT_SYMBOL_GPL(snd_soc_acpi_find_machine);
8ceffd22 32
7feb2f78
PLB
33static acpi_status snd_soc_acpi_find_package(acpi_handle handle, u32 level,
34 void *context, void **ret)
34218947
PLB
35{
36 struct acpi_device *adev;
37 acpi_status status = AE_OK;
7feb2f78 38 struct snd_soc_acpi_package_context *pkg_ctx = context;
34218947
PLB
39
40 pkg_ctx->data_valid = false;
41
42 if (acpi_bus_get_device(handle, &adev))
43 return AE_OK;
44
45 if (adev->status.present && adev->status.functional) {
46 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
47 union acpi_object *myobj = NULL;
48
49 status = acpi_evaluate_object_typed(handle, pkg_ctx->name,
50 NULL, &buffer,
51 ACPI_TYPE_PACKAGE);
52 if (ACPI_FAILURE(status))
53 return AE_OK;
54
55 myobj = buffer.pointer;
56 if (!myobj || myobj->package.count != pkg_ctx->length) {
57 kfree(buffer.pointer);
58 return AE_OK;
59 }
60
61 status = acpi_extract_package(myobj,
62 pkg_ctx->format, pkg_ctx->state);
63 if (ACPI_FAILURE(status)) {
64 kfree(buffer.pointer);
65 return AE_OK;
66 }
67
68 kfree(buffer.pointer);
69 pkg_ctx->data_valid = true;
70 return AE_CTRL_TERMINATE;
71 }
72
73 return AE_OK;
74}
75
7feb2f78
PLB
76bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
77 struct snd_soc_acpi_package_context *ctx)
34218947
PLB
78{
79 acpi_status status;
80
7feb2f78 81 status = acpi_get_devices(hid, snd_soc_acpi_find_package, ctx, NULL);
34218947
PLB
82
83 if (ACPI_FAILURE(status) || !ctx->data_valid)
84 return false;
85
86 return true;
87}
7feb2f78 88EXPORT_SYMBOL_GPL(snd_soc_acpi_find_package_from_hid);
34218947 89
7feb2f78 90struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
54746dab 91{
7feb2f78
PLB
92 struct snd_soc_acpi_mach *mach = arg;
93 struct snd_soc_acpi_codecs *codec_list =
94 (struct snd_soc_acpi_codecs *) mach->quirk_data;
54746dab
N
95 int i;
96
97 if (mach->quirk_data == NULL)
98 return mach;
99
100 for (i = 0; i < codec_list->num_codecs; i++) {
0d5ea120 101 if (!acpi_dev_present(codec_list->codecs[i], NULL, -1))
54746dab
N
102 return NULL;
103 }
104
105 return mach;
106}
7feb2f78 107EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
54746dab 108
8ceffd22 109MODULE_LICENSE("GPL v2");
7feb2f78 110MODULE_DESCRIPTION("ALSA SoC ACPI module");