Merge tag 'usb-ci-v5.5-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/peter...
[linux/fpc-iii.git] / sound / hda / intel-nhlt.c
blobdaede96f28ee31dbd9debca853b9b301b0a89f02
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2015-2019 Intel Corporation
4 #include <linux/acpi.h>
5 #include <sound/intel-nhlt.h>
7 #define NHLT_ACPI_HEADER_SIG "NHLT"
9 /* Unique identification for getting NHLT blobs */
10 static guid_t osc_guid =
11 GUID_INIT(0xA69F886E, 0x6CEB, 0x4594,
12 0xA4, 0x1F, 0x7B, 0x5D, 0xCE, 0x24, 0xC5, 0x53);
14 struct nhlt_acpi_table *intel_nhlt_init(struct device *dev)
16 acpi_handle handle;
17 union acpi_object *obj;
18 struct nhlt_resource_desc *nhlt_ptr;
19 struct nhlt_acpi_table *nhlt_table = NULL;
21 handle = ACPI_HANDLE(dev);
22 if (!handle) {
23 dev_err(dev, "Didn't find ACPI_HANDLE\n");
24 return NULL;
27 obj = acpi_evaluate_dsm(handle, &osc_guid, 1, 1, NULL);
29 if (!obj)
30 return NULL;
32 if (obj->type != ACPI_TYPE_BUFFER) {
33 dev_dbg(dev, "No NHLT table found\n");
34 ACPI_FREE(obj);
35 return NULL;
38 nhlt_ptr = (struct nhlt_resource_desc *)obj->buffer.pointer;
39 if (nhlt_ptr->length)
40 nhlt_table = (struct nhlt_acpi_table *)
41 memremap(nhlt_ptr->min_addr, nhlt_ptr->length,
42 MEMREMAP_WB);
43 ACPI_FREE(obj);
44 if (nhlt_table &&
45 (strncmp(nhlt_table->header.signature,
46 NHLT_ACPI_HEADER_SIG,
47 strlen(NHLT_ACPI_HEADER_SIG)) != 0)) {
48 memunmap(nhlt_table);
49 dev_err(dev, "NHLT ACPI header signature incorrect\n");
50 return NULL;
52 return nhlt_table;
54 EXPORT_SYMBOL_GPL(intel_nhlt_init);
56 void intel_nhlt_free(struct nhlt_acpi_table *nhlt)
58 memunmap((void *)nhlt);
60 EXPORT_SYMBOL_GPL(intel_nhlt_free);
62 int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt)
64 struct nhlt_endpoint *epnt;
65 struct nhlt_dmic_array_config *cfg;
66 struct nhlt_vendor_dmic_array_config *cfg_vendor;
67 unsigned int dmic_geo = 0;
68 u8 j;
70 if (!nhlt)
71 return 0;
73 epnt = (struct nhlt_endpoint *)nhlt->desc;
75 for (j = 0; j < nhlt->endpoint_count; j++) {
76 if (epnt->linktype == NHLT_LINK_DMIC) {
77 cfg = (struct nhlt_dmic_array_config *)
78 (epnt->config.caps);
79 switch (cfg->array_type) {
80 case NHLT_MIC_ARRAY_2CH_SMALL:
81 case NHLT_MIC_ARRAY_2CH_BIG:
82 dmic_geo = MIC_ARRAY_2CH;
83 break;
85 case NHLT_MIC_ARRAY_4CH_1ST_GEOM:
86 case NHLT_MIC_ARRAY_4CH_L_SHAPED:
87 case NHLT_MIC_ARRAY_4CH_2ND_GEOM:
88 dmic_geo = MIC_ARRAY_4CH;
89 break;
90 case NHLT_MIC_ARRAY_VENDOR_DEFINED:
91 cfg_vendor = (struct nhlt_vendor_dmic_array_config *)cfg;
92 dmic_geo = cfg_vendor->nb_mics;
93 break;
94 default:
95 dev_warn(dev, "undefined DMIC array_type 0x%0x\n",
96 cfg->array_type);
99 epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
102 return dmic_geo;
104 EXPORT_SYMBOL_GPL(intel_nhlt_get_dmic_geo);
106 MODULE_LICENSE("GPL v2");
107 MODULE_DESCRIPTION("Intel NHLT driver");