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;
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");
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 struct nhlt_fmt *fmt_configs;
35 unsigned int dmic_geo = 0;
42 for (j = 0, epnt = nhlt->desc; j < nhlt->endpoint_count; j++,
43 epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length)) {
45 if (epnt->linktype != NHLT_LINK_DMIC)
48 cfg = (struct nhlt_dmic_array_config *)(epnt->config.caps);
49 fmt_configs = (struct nhlt_fmt *)(epnt->config.caps + epnt->config.size);
51 /* find max number of channels based on format_configuration */
52 if (fmt_configs->fmt_count) {
53 dev_dbg(dev, "%s: found %d format definitions\n",
54 __func__, fmt_configs->fmt_count);
56 for (i = 0; i < fmt_configs->fmt_count; i++) {
57 struct wav_fmt_ext *fmt_ext;
59 fmt_ext = &fmt_configs->fmt_config[i].fmt_ext;
61 if (fmt_ext->fmt.channels > max_ch)
62 max_ch = fmt_ext->fmt.channels;
64 dev_dbg(dev, "%s: max channels found %d\n", __func__, max_ch);
66 dev_dbg(dev, "%s: No format information found\n", __func__);
69 if (cfg->device_config.config_type != NHLT_CONFIG_TYPE_MIC_ARRAY) {
72 switch (cfg->array_type) {
73 case NHLT_MIC_ARRAY_2CH_SMALL:
74 case NHLT_MIC_ARRAY_2CH_BIG:
75 dmic_geo = MIC_ARRAY_2CH;
78 case NHLT_MIC_ARRAY_4CH_1ST_GEOM:
79 case NHLT_MIC_ARRAY_4CH_L_SHAPED:
80 case NHLT_MIC_ARRAY_4CH_2ND_GEOM:
81 dmic_geo = MIC_ARRAY_4CH;
83 case NHLT_MIC_ARRAY_VENDOR_DEFINED:
84 cfg_vendor = (struct nhlt_vendor_dmic_array_config *)cfg;
85 dmic_geo = cfg_vendor->nb_mics;
88 dev_warn(dev, "%s: undefined DMIC array_type 0x%0x\n",
89 __func__, cfg->array_type);
93 dev_dbg(dev, "%s: Array with %d dmics\n", __func__, dmic_geo);
95 if (max_ch > dmic_geo) {
96 dev_dbg(dev, "%s: max channels %d exceed dmic number %d\n",
97 __func__, max_ch, dmic_geo);
102 dev_dbg(dev, "%s: dmic number %d max_ch %d\n",
103 __func__, dmic_geo, max_ch);
107 EXPORT_SYMBOL_GPL(intel_nhlt_get_dmic_geo);