| 1 | // SPDX-License-Identifier: GPL-2.0-only
|
|---|
| 2 | // Copyright (c) 2015-2019 Intel Corporation
|
|---|
| 3 |
|
|---|
| 4 | #include <linux/acpi.h>
|
|---|
| 5 | #include <sound/intel-nhlt.h>
|
|---|
| 6 |
|
|---|
| 7 | struct nhlt_acpi_table *intel_nhlt_init(struct device *dev)
|
|---|
| 8 | {
|
|---|
| 9 | struct nhlt_acpi_table *nhlt;
|
|---|
| 10 | acpi_status status;
|
|---|
| 11 |
|
|---|
| 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;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | return nhlt;
|
|---|
| 20 | }
|
|---|
| 21 | EXPORT_SYMBOL_GPL(intel_nhlt_init);
|
|---|
| 22 |
|
|---|
| 23 | void intel_nhlt_free(struct nhlt_acpi_table *nhlt)
|
|---|
| 24 | {
|
|---|
| 25 | acpi_put_table((struct acpi_table_header *)nhlt);
|
|---|
| 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;
|
|---|
| 34 | unsigned int dmic_geo = 0;
|
|---|
| 35 | u8 j;
|
|---|
| 36 |
|
|---|
| 37 | if (!nhlt)
|
|---|
| 38 | return 0;
|
|---|
| 39 |
|
|---|
| 40 | epnt = (struct nhlt_endpoint *)nhlt->desc;
|
|---|
| 41 |
|
|---|
| 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;
|
|---|
| 51 |
|
|---|
| 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);
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | return dmic_geo;
|
|---|
| 70 | }
|
|---|
| 71 | EXPORT_SYMBOL_GPL(intel_nhlt_get_dmic_geo);
|
|---|