2 * sst_match_apci.c - SST (LPE) match 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
19 static acpi_status sst_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 *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN])
39 const char *name = NULL;
42 status = acpi_get_devices(hid, sst_acpi_find_name, NULL,
45 if (ACPI_FAILURE(status) || name[0] == '\0')
50 EXPORT_SYMBOL_GPL(sst_acpi_find_name_from_hid);
52 static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level,
53 void *context, void **ret)
55 unsigned long long sta;
58 *(bool *)context = true;
59 status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
60 if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_PRESENT))
61 *(bool *)context = false;
66 bool sst_acpi_check_hid(const u8 hid[ACPI_ID_LEN])
71 status = acpi_get_devices(hid, sst_acpi_mach_match, &found, NULL);
73 if (ACPI_FAILURE(status))
78 EXPORT_SYMBOL_GPL(sst_acpi_check_hid);
80 struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines)
82 struct sst_acpi_mach *mach;
84 for (mach = machines; mach->id[0]; mach++) {
85 if (sst_acpi_check_hid(mach->id) == true) {
86 if (mach->machine_quirk)
87 mach = mach->machine_quirk(mach);
93 EXPORT_SYMBOL_GPL(sst_acpi_find_machine);
95 static acpi_status sst_acpi_find_package(acpi_handle handle, u32 level,
96 void *context, void **ret)
98 struct acpi_device *adev;
99 acpi_status status = AE_OK;
100 struct sst_acpi_package_context *pkg_ctx = context;
102 pkg_ctx->data_valid = false;
104 if (acpi_bus_get_device(handle, &adev))
107 if (adev->status.present && adev->status.functional) {
108 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
109 union acpi_object *myobj = NULL;
111 status = acpi_evaluate_object_typed(handle, pkg_ctx->name,
114 if (ACPI_FAILURE(status))
117 myobj = buffer.pointer;
118 if (!myobj || myobj->package.count != pkg_ctx->length) {
119 kfree(buffer.pointer);
123 status = acpi_extract_package(myobj,
124 pkg_ctx->format, pkg_ctx->state);
125 if (ACPI_FAILURE(status)) {
126 kfree(buffer.pointer);
130 kfree(buffer.pointer);
131 pkg_ctx->data_valid = true;
132 return AE_CTRL_TERMINATE;
138 bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
139 struct sst_acpi_package_context *ctx)
143 status = acpi_get_devices(hid, sst_acpi_find_package, ctx, NULL);
145 if (ACPI_FAILURE(status) || !ctx->data_valid)
150 EXPORT_SYMBOL_GPL(sst_acpi_find_package_from_hid);
152 struct sst_acpi_mach *sst_acpi_codec_list(void *arg)
154 struct sst_acpi_mach *mach = arg;
155 struct sst_codecs *codec_list = (struct sst_codecs *) mach->quirk_data;
158 if (mach->quirk_data == NULL)
161 for (i = 0; i < codec_list->num_codecs; i++) {
162 if (sst_acpi_check_hid(codec_list->codecs[i]) != true)
168 EXPORT_SYMBOL_GPL(sst_acpi_codec_list);
170 MODULE_LICENSE("GPL v2");
171 MODULE_DESCRIPTION("Intel Common ACPI Match module");