mm, compaction: make capture control handling safe wrt interrupts
[linux/fpc-iii.git] / sound / hda / intel-nhlt.c
blob059aaf04f536afe24070a6540f8a08391a66e491
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2015-2019 Intel Corporation
4 #include <linux/acpi.h>
5 #include <sound/intel-nhlt.h>
7 struct nhlt_acpi_table *intel_nhlt_init(struct device *dev)
9 struct nhlt_acpi_table *nhlt;
10 acpi_status status;
12 status = acpi_get_table(ACPI_SIG_NHLT, 0,
13 (struct acpi_table_header **)&nhlt);
14 if (ACPI_FAILURE(status)) {
15 dev_warn(dev, "NHLT table not found\n");
16 return NULL;
19 return nhlt;
21 EXPORT_SYMBOL_GPL(intel_nhlt_init);
23 void intel_nhlt_free(struct nhlt_acpi_table *nhlt)
25 acpi_put_table((struct acpi_table_header *)nhlt);
27 EXPORT_SYMBOL_GPL(intel_nhlt_free);
29 int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt)
31 struct nhlt_endpoint *epnt;
32 struct nhlt_dmic_array_config *cfg;
33 struct nhlt_vendor_dmic_array_config *cfg_vendor;
34 unsigned int dmic_geo = 0;
35 u8 j;
37 if (!nhlt)
38 return 0;
40 epnt = (struct nhlt_endpoint *)nhlt->desc;
42 for (j = 0; j < nhlt->endpoint_count; j++) {
43 if (epnt->linktype == NHLT_LINK_DMIC) {
44 cfg = (struct nhlt_dmic_array_config *)
45 (epnt->config.caps);
46 switch (cfg->array_type) {
47 case NHLT_MIC_ARRAY_2CH_SMALL:
48 case NHLT_MIC_ARRAY_2CH_BIG:
49 dmic_geo = MIC_ARRAY_2CH;
50 break;
52 case NHLT_MIC_ARRAY_4CH_1ST_GEOM:
53 case NHLT_MIC_ARRAY_4CH_L_SHAPED:
54 case NHLT_MIC_ARRAY_4CH_2ND_GEOM:
55 dmic_geo = MIC_ARRAY_4CH;
56 break;
57 case NHLT_MIC_ARRAY_VENDOR_DEFINED:
58 cfg_vendor = (struct nhlt_vendor_dmic_array_config *)cfg;
59 dmic_geo = cfg_vendor->nb_mics;
60 break;
61 default:
62 dev_warn(dev, "undefined DMIC array_type 0x%0x\n",
63 cfg->array_type);
66 epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
69 return dmic_geo;
71 EXPORT_SYMBOL_GPL(intel_nhlt_get_dmic_geo);