Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2 | // Copyright (c) 2015-2019 Intel Corporation |
| 3 | |
| 4 | #include <linux/acpi.h> |
| 5 | #include <sound/intel-nhlt.h> |
| 6 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7 | struct nhlt_acpi_table *intel_nhlt_init(struct device *dev) |
| 8 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 9 | struct nhlt_acpi_table *nhlt; |
| 10 | acpi_status status; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 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"); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 16 | return NULL; |
| 17 | } |
| 18 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 19 | return nhlt; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 20 | } |
| 21 | EXPORT_SYMBOL_GPL(intel_nhlt_init); |
| 22 | |
| 23 | void intel_nhlt_free(struct nhlt_acpi_table *nhlt) |
| 24 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame] | 25 | acpi_put_table((struct acpi_table_header *)nhlt); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 26 | } |
| 27 | EXPORT_SYMBOL_GPL(intel_nhlt_free); |
| 28 | |
| 29 | int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt) |
| 30 | { |
| 31 | struct nhlt_endpoint *epnt; |
| 32 | struct nhlt_dmic_array_config *cfg; |
| 33 | struct nhlt_vendor_dmic_array_config *cfg_vendor; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 34 | struct nhlt_fmt *fmt_configs; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 35 | unsigned int dmic_geo = 0; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 36 | u16 max_ch = 0; |
| 37 | u8 i, j; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 38 | |
| 39 | if (!nhlt) |
| 40 | return 0; |
| 41 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 42 | if (nhlt->header.length <= sizeof(struct acpi_table_header)) { |
| 43 | dev_warn(dev, "Invalid DMIC description table\n"); |
| 44 | return 0; |
| 45 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 46 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 47 | for (j = 0, epnt = nhlt->desc; j < nhlt->endpoint_count; j++, |
| 48 | epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length)) { |
| 49 | |
| 50 | if (epnt->linktype != NHLT_LINK_DMIC) |
| 51 | continue; |
| 52 | |
| 53 | cfg = (struct nhlt_dmic_array_config *)(epnt->config.caps); |
| 54 | fmt_configs = (struct nhlt_fmt *)(epnt->config.caps + epnt->config.size); |
| 55 | |
| 56 | /* find max number of channels based on format_configuration */ |
| 57 | if (fmt_configs->fmt_count) { |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 58 | struct nhlt_fmt_cfg *fmt_cfg = fmt_configs->fmt_config; |
| 59 | |
| 60 | dev_dbg(dev, "found %d format definitions\n", |
| 61 | fmt_configs->fmt_count); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 62 | |
| 63 | for (i = 0; i < fmt_configs->fmt_count; i++) { |
| 64 | struct wav_fmt_ext *fmt_ext; |
| 65 | |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 66 | fmt_ext = &fmt_cfg->fmt_ext; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 67 | |
| 68 | if (fmt_ext->fmt.channels > max_ch) |
| 69 | max_ch = fmt_ext->fmt.channels; |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 70 | |
| 71 | /* Move to the next nhlt_fmt_cfg */ |
| 72 | fmt_cfg = (struct nhlt_fmt_cfg *)(fmt_cfg->config.caps + |
| 73 | fmt_cfg->config.size); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 74 | } |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 75 | dev_dbg(dev, "max channels found %d\n", max_ch); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 76 | } else { |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 77 | dev_dbg(dev, "No format information found\n"); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | if (cfg->device_config.config_type != NHLT_CONFIG_TYPE_MIC_ARRAY) { |
| 81 | dmic_geo = max_ch; |
| 82 | } else { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 83 | switch (cfg->array_type) { |
| 84 | case NHLT_MIC_ARRAY_2CH_SMALL: |
| 85 | case NHLT_MIC_ARRAY_2CH_BIG: |
| 86 | dmic_geo = MIC_ARRAY_2CH; |
| 87 | break; |
| 88 | |
| 89 | case NHLT_MIC_ARRAY_4CH_1ST_GEOM: |
| 90 | case NHLT_MIC_ARRAY_4CH_L_SHAPED: |
| 91 | case NHLT_MIC_ARRAY_4CH_2ND_GEOM: |
| 92 | dmic_geo = MIC_ARRAY_4CH; |
| 93 | break; |
| 94 | case NHLT_MIC_ARRAY_VENDOR_DEFINED: |
| 95 | cfg_vendor = (struct nhlt_vendor_dmic_array_config *)cfg; |
| 96 | dmic_geo = cfg_vendor->nb_mics; |
| 97 | break; |
| 98 | default: |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 99 | dev_warn(dev, "%s: undefined DMIC array_type 0x%0x\n", |
| 100 | __func__, cfg->array_type); |
| 101 | } |
| 102 | |
| 103 | if (dmic_geo > 0) { |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 104 | dev_dbg(dev, "Array with %d dmics\n", dmic_geo); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 105 | } |
| 106 | if (max_ch > dmic_geo) { |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 107 | dev_dbg(dev, "max channels %d exceed dmic number %d\n", |
| 108 | max_ch, dmic_geo); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Olivier Deprez | 92d4c21 | 2022-12-06 15:05:30 +0100 | [diff] [blame] | 113 | dev_dbg(dev, "dmic number %d max_ch %d\n", dmic_geo, max_ch); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 114 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 115 | return dmic_geo; |
| 116 | } |
| 117 | EXPORT_SYMBOL_GPL(intel_nhlt_get_dmic_geo); |