blob: 3d7e1ff7913931cd762ba44346e899db7f4ca40d [file] [log] [blame]
Vinod Koul95f09802015-11-05 21:34:11 +05301/*
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05002 * soc-apci.c - support for ACPI enumeration.
Vinod Koul95f09802015-11-05 21:34:11 +05303 *
4 * Copyright (c) 2013-15, Intel Corporation.
5 *
6 *
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.
10 *
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
14 * more details.
15 */
Vinod Koul95f09802015-11-05 21:34:11 +053016
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050017#include <sound/soc-acpi.h>
Vinod Koul95f09802015-11-05 21:34:11 +053018
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050019struct snd_soc_acpi_mach *
20snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
Vinod Koul95f09802015-11-05 21:34:11 +053021{
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050022 struct snd_soc_acpi_mach *mach;
Vinod Koul95f09802015-11-05 21:34:11 +053023
Naveen M7827d662017-05-15 13:42:14 +053024 for (mach = machines; mach->id[0]; mach++) {
Jeremy Cline0d5ea122018-01-05 14:55:34 -060025 if (acpi_dev_present(mach->id, NULL, -1)) {
Pierre-Louis Bossart5c256042018-01-05 14:55:33 -060026 if (mach->machine_quirk)
27 mach = mach->machine_quirk(mach);
28 return mach;
Naveen M7827d662017-05-15 13:42:14 +053029 }
30 }
Vinod Koul95f09802015-11-05 21:34:11 +053031 return NULL;
32}
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050033EXPORT_SYMBOL_GPL(snd_soc_acpi_find_machine);
Vinod Koul8ceffd22016-02-08 10:45:39 +053034
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050035static acpi_status snd_soc_acpi_find_package(acpi_handle handle, u32 level,
36 void *context, void **ret)
Pierre-Louis Bossart34218942016-11-12 18:07:44 -060037{
38 struct acpi_device *adev;
39 acpi_status status = AE_OK;
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050040 struct snd_soc_acpi_package_context *pkg_ctx = context;
Pierre-Louis Bossart34218942016-11-12 18:07:44 -060041
42 pkg_ctx->data_valid = false;
43
44 if (acpi_bus_get_device(handle, &adev))
45 return AE_OK;
46
47 if (adev->status.present && adev->status.functional) {
48 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
49 union acpi_object *myobj = NULL;
50
51 status = acpi_evaluate_object_typed(handle, pkg_ctx->name,
52 NULL, &buffer,
53 ACPI_TYPE_PACKAGE);
54 if (ACPI_FAILURE(status))
55 return AE_OK;
56
57 myobj = buffer.pointer;
58 if (!myobj || myobj->package.count != pkg_ctx->length) {
59 kfree(buffer.pointer);
60 return AE_OK;
61 }
62
63 status = acpi_extract_package(myobj,
64 pkg_ctx->format, pkg_ctx->state);
65 if (ACPI_FAILURE(status)) {
66 kfree(buffer.pointer);
67 return AE_OK;
68 }
69
70 kfree(buffer.pointer);
71 pkg_ctx->data_valid = true;
72 return AE_CTRL_TERMINATE;
73 }
74
75 return AE_OK;
76}
77
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050078bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
79 struct snd_soc_acpi_package_context *ctx)
Pierre-Louis Bossart34218942016-11-12 18:07:44 -060080{
81 acpi_status status;
82
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050083 status = acpi_get_devices(hid, snd_soc_acpi_find_package, ctx, NULL);
Pierre-Louis Bossart34218942016-11-12 18:07:44 -060084
85 if (ACPI_FAILURE(status) || !ctx->data_valid)
86 return false;
87
88 return true;
89}
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050090EXPORT_SYMBOL_GPL(snd_soc_acpi_find_package_from_hid);
Pierre-Louis Bossart34218942016-11-12 18:07:44 -060091
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050092struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
Naveen M54746da2017-05-15 13:42:15 +053093{
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050094 struct snd_soc_acpi_mach *mach = arg;
95 struct snd_soc_acpi_codecs *codec_list =
96 (struct snd_soc_acpi_codecs *) mach->quirk_data;
Naveen M54746da2017-05-15 13:42:15 +053097 int i;
98
99 if (mach->quirk_data == NULL)
100 return mach;
101
102 for (i = 0; i < codec_list->num_codecs; i++) {
Jeremy Cline0d5ea122018-01-05 14:55:34 -0600103 if (!acpi_dev_present(codec_list->codecs[i], NULL, -1))
Naveen M54746da2017-05-15 13:42:15 +0530104 return NULL;
105 }
106
107 return mach;
108}
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -0500109EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
Naveen M54746da2017-05-15 13:42:15 +0530110
Vinod Koul8ceffd22016-02-08 10:45:39 +0530111MODULE_LICENSE("GPL v2");
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -0500112MODULE_DESCRIPTION("ALSA SoC ACPI module");