[coreboot-gerrit] Patch set updated for coreboot: lib/nhlt: Add common NHLT audio for Intel platforms

Saurabh Satija (saurabh.satija@intel.com) gerrit at coreboot.org
Fri Jun 24 03:32:59 CEST 2016


Saurabh Satija (saurabh.satija at intel.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15023

-gerrit

commit 66824c622aa2150a78b84ea2a1a0c7ed511dc5ba
Author: Saurabh Satija <saurabh.satija at intel.com>
Date:   Thu Jun 23 14:46:27 2016 -0700

    lib/nhlt: Add common NHLT audio for Intel platforms
    
    The use of a NHLT table is required to make audio work
    on the Intel SoCs employing the internal DSP. The table
    describes the audio endpoints (render vs capture) along with
    their supported formats. These formats are not only dependent
    on the audio peripheral but also hardware interfaces. As such
    each format has an associated blob of DSP settings to make
    the peripheral work. Lastly, each of these settings are provided
    by Intel and need to be generated for each device's hardware
    connection plus mode/format it supports. This patch does not
    include the DSP setting blobs.
    
    Change-Id: I3c75d3537288c47d29e8949ca253ea8c5c1a387d
    Signed-off-by: Saurabh Satija <saurabh.satija at intel.com>
---
 src/Kconfig           |  2 ++
 src/include/nhlt.h    | 25 ++++++++++++++++
 src/lib/Kconfig       | 55 +++++++++++++++++++++++++++++++++++
 src/lib/Makefile.inc  | 44 +++++++++++++++++++++++++++-
 src/lib/audio_codec.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lib/dmic.c        | 52 +++++++++++++++++++++++++++++++++
 src/lib/nhlt.c        | 69 ++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 325 insertions(+), 1 deletion(-)

diff --git a/src/Kconfig b/src/Kconfig
index 1cb55c9..9b6cfe5 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -435,6 +435,8 @@ source "src/superio/*/Kconfig"
 comment "Embedded Controllers"
 source "src/ec/acpi/Kconfig"
 source "src/ec/*/*/Kconfig"
+comment "lib"
+source "src/lib/Kconfig"
 # FIXME move to vendorcode
 source "src/drivers/intel/fsp1_0/Kconfig"
 
diff --git a/src/include/nhlt.h b/src/include/nhlt.h
index f0b3b6f..c2d2e03 100644
--- a/src/include/nhlt.h
+++ b/src/include/nhlt.h
@@ -148,6 +148,16 @@ uintptr_t nhlt_soc_serialize(struct nhlt *nhlt, uintptr_t acpi_addr);
 uintptr_t nhlt_soc_serialize_oem_overrides(struct nhlt *nhlt,
 	uintptr_t acpi_addr, const char *oem_id, const char *oem_table_id);
 
+/*
+ * NHLT device and hardware link types. These values are used with
+ * nhlt_soc_add_endpoint().
+ */
+enum {
+	AUDIO_DEV_I2S,
+	AUDIO_DEV_DMIC,
+	AUDIO_DEV_BT,
+};
+
 /* Link and device types. */
 enum {
 	NHLT_LINK_HDA,
@@ -298,4 +308,19 @@ enum {
 	NHLT_MIC_ARRAY_VENDOR_DEFINED = 0xf,
 };
 
+/*
+ * Add a dmic array composed of the provided number of channels.
+ * Returns 0 on success, < 0 on error.
+ */
+int nhlt_soc_add_dmic_array(struct nhlt *nhlt, int num_channels,
+        const struct nhlt_format_config *dmic_ch_config, int num_fmt);
+
+/*
+ * Add audio codec on provided SSP link. Return 0 on succes, < 0 on error.
+ */
+int nhlt_soc_add_codec_on_ssp(struct nhlt *nhlt, int hwlink,
+                const struct nhlt_format_config *render_cfg, int r_num_fmt,
+                const struct nhlt_format_config *capture_cfg, int c_num_fmt,
+                struct nhlt_tdm_config *tdm_config, size_t tdm_size);
+
 #endif
diff --git a/src/lib/Kconfig b/src/lib/Kconfig
new file mode 100644
index 0000000..ceb414c
--- /dev/null
+++ b/src/lib/Kconfig
@@ -0,0 +1,55 @@
+config USE_COMMON_NHLT
+	bool
+	default n
+	help
+	  Build support for drivers audio code, common to Intel
+	  platforms that use NHLT.
+
+config NHLT_DMIC_2CH_16B
+	bool
+	depends on USE_COMMON_NHLT
+	default n
+	help
+	  Include DSP firmware settings for 2 channel 16B DMIC array.
+
+config NHLT_DMIC_2CH_32B
+	bool
+	depends on USE_COMMON_NHLT
+	default n
+	help
+	  Include DSP firmware settings for 2 channel 32B DMIC array.
+
+config NHLT_DMIC_4CH_16B
+	bool
+	depends on USE_COMMON_NHLT
+	default n
+	help
+	  Include DSP firmware settings for 4 channel 16B DMIC array.
+
+config NHLT_DMIC_4CH_32B
+	bool
+	depends on USE_COMMON_NHLT
+	default n
+	help
+	  Include DSP firmware settings for 4 channel 32B DMIC array.
+
+config NHLT_HEADSET
+	bool
+	depends on USE_COMMON_NHLT
+	default n
+	help
+	  Include DSP firmware settings for headset codec.
+
+config NHLT_SPEAKER_RENDER
+	bool
+	depends on USE_COMMON_NHLT
+	default n
+	help
+	  Include DSP firmware settings for speaker-render amplifier.
+
+config NHLT_SPEAKER_CAPTURE
+	bool
+	depends on USE_COMMON_NHLT
+	default n
+	help
+	  Include DSP firmware settings for speaker-capture amplifier.
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 49720a7..383bc3e 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -128,7 +128,49 @@ ramstage-$(CONFIG_TIMER_QUEUE) += timer_queue.c
 ramstage-$(CONFIG_GENERIC_GPIO_LIB) += gpio.c
 ramstage-$(CONFIG_GENERIC_UDELAY) += timer.c
 ramstage-y += b64_decode.c
-ramstage-$(CONFIG_ACPI_NHLT) += nhlt.c
+ramstage-$(CONFIG_USE_COMMON_NHLT) += nhlt.c
+ramstage-$(CONFIG_USE_COMMON_NHLT) += dmic.c
+ramstage-$(CONFIG_USE_COMMON_NHLT) += audio_codec.c
+
+# DSP firmware settings files.
+NHLT_BLOB_PATH = 3rdparty/blobs/soc/intel/common/nhlt-blobs
+DMIC_2CH_48KHZ_16B = dmic-2ch-48khz-16b.bin
+DMIC_2CH_48KHZ_32B = dmic-2ch-48khz-32b.bin
+DMIC_4CH_48KHZ_16B = dmic-4ch-48khz-16b.bin
+DMIC_4CH_48KHZ_32B = dmic-4ch-48khz-32b.bin
+
+HEADSET = headset.bin
+
+SPEAKER_RENDER = speaker-render.bin
+SPEAKER_CAPTURE = speaker-capture.bin
+
+cbfs-files-$(CONFIG_AUDIO_DMIC_2CH_16B) += $(DMIC_2CH_48KHZ_16B)
+$(DMIC_2CH_48KHZ_16B)-file := $(NHLT_BLOB_PATH)/$(DMIC_2CH_48KHZ_16B)
+$(DMIC_2CH_48KHZ_16B)-type := raw
+
+cbfs-files-$(CONFIG_AUDIO_DMIC_2CH_32B) += $(DMIC_2CH_48KHZ_32B)
+$(DMIC_2CH_48KHZ_32B)-file := $(NHLT_BLOB_PATH)/$(DMIC_2CH_48KHZ_32B)
+$(DMIC_2CH_48KHZ_32B)-type := raw
+
+cbfs-files-$(CONFIG_AUDIO_DMIC_4CH_16B) += $(DMIC_4CH_48KHZ_16B)
+$(DMIC_4CH_48KHZ_16B)-file := $(NHLT_BLOB_PATH)/$(DMIC_4CH_48KHZ_16B)
+$(DMIC_4CH_48KHZ_16B)-type := raw
+
+cbfs-files-$(CONFIG_AUDIO_DMIC_4CH_32B) += $(DMIC_4CH_48KHZ_32B)
+$(DMIC_4CH_48KHZ_32B)-file := $(NHLT_BLOB_PATH)/$(DMIC_4CH_48KHZ_32B)
+$(DMIC_4CH_48KHZ_32B)-type := raw
+
+cbfs-files-$(CONFIG_AUDIO_HEADSET) += $(HEADSET)
+$(HEADSET)-file := $(NHLT_BLOB_PATH)/$(HEADSET)
+$(HEADSET)-type := raw
+
+cbfs-files-$(CONFIG_AUDIO_SPEAKER_RENDER) += $(SPEAKER_RENDER)
+$(SPEAKER_RENDER)-file := $(NHLT_BLOB_PATH)/$(SPEAKER_RENDER)
+$(SPEAKER_RENDER)-type := raw
+
+cbfs-files-$(CONFIG_AUDIO_SPEAKER_CAPTURE) += $(SPEAKER_CAPTURE)
+$(SPEAKER_CAPTURE)-file := $(NHLT_BLOB_PATH)/$(SPEAKER_CAPTURE)
+$(SPEAKER_CAPTURE)-type := raw
 
 romstage-y += cbmem_common.c
 romstage-y += imd_cbmem.c
diff --git a/src/lib/audio_codec.c b/src/lib/audio_codec.c
new file mode 100644
index 0000000..15fd265
--- /dev/null
+++ b/src/lib/audio_codec.c
@@ -0,0 +1,79 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <console/console.h>
+#include <nhlt.h>
+
+/* The same DSP firmware settings can be used for both the capture and render
+ * endpoints in some cases. Most of the smart amps use different DSP firmware
+ * settings for capture and render endpoints.
+ *
+ * render_cfg, capture_cfg: These are the audio codec configuration defined
+ * in mainboard souce code.
+ * cfg_size: This is the number of configurations defined in codec config.
+ * Each configuration is added as an endpoint.
+ * tdm_config: This is also board specific and defined in mainboard.c
+ * hwlink: This is the SSP hardware port number.
+ * direction: This can be Render only, Capture only or Bi-directional.
+ */
+int nhlt_soc_add_codec_on_ssp(struct nhlt *nhlt, int hwlink,
+		const struct nhlt_format_config *render_cfg, int r_num_fmt,
+		const struct nhlt_format_config *capture_cfg, int c_num_fmt,
+		struct nhlt_tdm_config *tdm_config, size_t tdm_size)
+{
+	struct nhlt_endpoint *endp;
+
+	/* For Bi-directional amplifiers, both capture and render
+	 * configuratoins are needed.
+	 */
+	if (render_cfg == NULL && capture_cfg == NULL)
+		return -1;
+
+	/* Render Endpoint */
+	if (render_cfg != NULL) {
+		endp = nhlt_soc_add_endpoint(nhlt, hwlink, AUDIO_DEV_I2S,
+					NHLT_DIR_RENDER);
+		if (endp == NULL)
+			return -1;
+
+		if (tdm_config != NULL) {
+			if (nhlt_endpoint_append_config(endp, tdm_config, tdm_size))
+				return -1;
+		}
+
+		if (nhlt_endpoint_add_formats(endp, render_cfg, r_num_fmt))
+			return -1;
+	}
+
+	/* Capture Endpoint */
+	if (capture_cfg != NULL) {
+		endp = nhlt_soc_add_endpoint(nhlt, hwlink, AUDIO_DEV_I2S,
+					NHLT_DIR_CAPTURE);
+		if (endp == NULL)
+			return -1;
+
+		if (tdm_config != NULL) {
+			if (nhlt_endpoint_append_config(endp, tdm_config, tdm_size))
+				return -1;
+		}
+
+		if (nhlt_endpoint_add_formats(endp, capture_cfg, c_num_fmt))
+			return -1;
+	}
+
+	nhlt_next_instance(nhlt, NHLT_LINK_SSP);
+
+	return 0;
+}
diff --git a/src/lib/dmic.c b/src/lib/dmic.c
new file mode 100644
index 0000000..6af6237
--- /dev/null
+++ b/src/lib/dmic.c
@@ -0,0 +1,52 @@
+ /*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <nhlt.h>
+#include <soc/nhlt.h>
+#include <string.h>
+
+int nhlt_soc_add_dmic_array(struct nhlt *nhlt, int num_channels,
+		const struct nhlt_format_config *dmic_ch_cfg, int num_fmt)
+{
+	struct nhlt_endpoint *endp;
+	struct nhlt_dmic_array_config mic_config;
+
+	if (num_channels != 2 && num_channels != 4)
+		return -1;
+
+	endp = nhlt_soc_add_endpoint(nhlt, AUDIO_LINK_DMIC, AUDIO_DEV_DMIC,
+				     NHLT_DIR_CAPTURE);
+
+	if (endp == NULL)
+		return -1;
+
+	memset(&mic_config, 0, sizeof(mic_config));
+	mic_config.tdm_config.config_type = NHLT_TDM_MIC_ARRAY;
+
+	switch (num_channels) {
+	case 2:
+		mic_config.array_type = NHLT_MIC_ARRAY_2CH_SMALL;
+		break;
+	case 4:
+		mic_config.array_type = NHLT_MIC_ARRAY_4CH_L_SHAPED;
+		break;
+	}
+
+	if (nhlt_endpoint_append_config(endp, &mic_config, sizeof(mic_config)))
+		return -1;
+
+	return nhlt_endpoint_add_formats(endp, dmic_ch_cfg, num_fmt);
+}
+
diff --git a/src/lib/nhlt.c b/src/lib/nhlt.c
index 11a397c..92fed2e 100644
--- a/src/lib/nhlt.c
+++ b/src/lib/nhlt.c
@@ -15,9 +15,12 @@
 
 #include <arch/acpi.h>
 #include <cbfs.h>
+#include <cbmem.h>
 #include <commonlib/endian.h>
 #include <console/console.h>
 #include <nhlt.h>
+#include <soc/nvs.h>
+#include <soc/nhlt.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -437,3 +440,69 @@ uintptr_t nhlt_serialize_oem_overrides(struct nhlt *nhlt,
 
 	return acpi_addr;
 }
+
+struct nhlt_endpoint *nhlt_soc_add_endpoint(struct nhlt *nhlt, int soc_hwintf,
+                                                int soc_devtype, int dir)
+{
+	int nhlt_link_type;
+	int nhlt_dev_type;
+	uint16_t did;
+	struct nhlt_endpoint *endp;
+
+	nhlt_link_type = nhlt_get_link_type(soc_hwintf, soc_devtype);
+
+	if (nhlt_link_type == -1)
+		return NULL;
+
+	switch (soc_devtype) {
+	case AUDIO_DEV_I2S:
+		nhlt_dev_type = NHLT_SSP_DEV_I2S;
+		did = NHLT_DID_SSP;
+		break;
+	case AUDIO_DEV_DMIC:
+		nhlt_dev_type = NHLT_PDM_DEV;
+		did = NHLT_DID_DMIC;
+		break;
+	case AUDIO_DEV_BT:
+		nhlt_dev_type = NHLT_SSP_DEV_BT;
+		did = NHLT_DID_BT;
+		break;
+	default:
+		return NULL;
+	}
+
+	endp = nhlt_add_endpoint(nhlt, nhlt_link_type, nhlt_dev_type, dir,
+                                NHLT_VID, did);
+
+	if (endp == NULL)
+		return NULL;
+
+	/* Virtual bus id of SSP link is the hardware port id. */
+	if (nhlt_link_type == NHLT_LINK_SSP)
+		endp->virtual_bus_id = soc_hwintf;
+
+	return endp;
+}
+
+uintptr_t nhlt_soc_serialize(struct nhlt *nhlt, uintptr_t acpi_addr)
+{
+	return nhlt_soc_serialize_oem_overrides(nhlt, acpi_addr, NULL, NULL);
+}
+
+uintptr_t nhlt_soc_serialize_oem_overrides(struct nhlt *nhlt,
+	uintptr_t acpi_addr, const char *oem_id, const char *oem_table_id)
+{
+	struct global_nvs_t *gnvs;
+
+	gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
+
+	if (gnvs == NULL)
+		return acpi_addr;
+
+	/* Update NHLT GNVS Data */
+	gnvs->nhla = (uintptr_t)acpi_addr;
+	gnvs->nhll = nhlt_current_size(nhlt);
+
+	return nhlt_serialize_oem_overrides(nhlt, acpi_addr, oem_id,
+					    oem_table_id);
+}



More information about the coreboot-gerrit mailing list