ASoC: SOF: IPC4: Add topology, control and PCM ops
Merge series from Ranjani Sridharan <ranjani.sridharan@linux.intel.com>: This set of patches includes changes to add the topology, control and PCM ops for IPC4. It also includes a couple of patches to set the IPC4 BE DAI trigger ops for SSP/DMIC/HDA type DAI's.
This commit is contained in:
commit
6062ecda5b
@ -138,6 +138,7 @@ struct sof_dev_desc {
|
||||
|
||||
struct snd_sof_dsp_ops *ops;
|
||||
int (*ops_init)(struct snd_sof_dev *sdev);
|
||||
void (*ops_free)(struct snd_sof_dev *sdev);
|
||||
};
|
||||
|
||||
int sof_dai_get_mclk(struct snd_soc_pcm_runtime *rtd);
|
||||
|
@ -24,6 +24,8 @@
|
||||
#ifndef __INCLUDE_UAPI_SOUND_SOF_ABI_H__
|
||||
#define __INCLUDE_UAPI_SOUND_SOF_ABI_H__
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
/* SOF ABI version major, minor and patch numbers */
|
||||
#define SOF_ABI_MAJOR 3
|
||||
#define SOF_ABI_MINOR 21
|
||||
|
@ -26,4 +26,34 @@ struct sof_abi_hdr {
|
||||
__u32 data[0]; /**< Component data - opaque to core */
|
||||
} __packed;
|
||||
|
||||
#define SOF_MANIFEST_DATA_TYPE_NHLT 1
|
||||
|
||||
/**
|
||||
* struct sof_manifest_tlv - SOF manifest TLV data
|
||||
* @type: type of data
|
||||
* @size: data size (not including the size of this struct)
|
||||
* @data: payload data
|
||||
*/
|
||||
struct sof_manifest_tlv {
|
||||
__le32 type;
|
||||
__le32 size;
|
||||
__u8 data[];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_manifest - SOF topology manifest
|
||||
* @abi_major: Major ABI version
|
||||
* @abi_minor: Minor ABI version
|
||||
* @abi_patch: ABI patch
|
||||
* @count: count of tlv items
|
||||
* @items: consecutive variable size tlv items
|
||||
*/
|
||||
struct sof_manifest {
|
||||
__le16 abi_major;
|
||||
__le16 abi_minor;
|
||||
__le16 abi_patch;
|
||||
__le16 count;
|
||||
struct sof_manifest_tlv items[];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -52,11 +52,17 @@
|
||||
#define SOF_TKN_SCHED_FRAMES 204
|
||||
#define SOF_TKN_SCHED_TIME_DOMAIN 205
|
||||
#define SOF_TKN_SCHED_DYNAMIC_PIPELINE 206
|
||||
#define SOF_TKN_SCHED_LP_MODE 207
|
||||
#define SOF_TKN_SCHED_MEM_USAGE 208
|
||||
|
||||
/* volume */
|
||||
#define SOF_TKN_VOLUME_RAMP_STEP_TYPE 250
|
||||
#define SOF_TKN_VOLUME_RAMP_STEP_MS 251
|
||||
|
||||
#define SOF_TKN_GAIN_RAMP_TYPE 260
|
||||
#define SOF_TKN_GAIN_RAMP_DURATION 261
|
||||
#define SOF_TKN_GAIN_VAL 262
|
||||
|
||||
/* SRC */
|
||||
#define SOF_TKN_SRC_RATE_IN 300
|
||||
#define SOF_TKN_SRC_RATE_OUT 301
|
||||
@ -79,6 +85,9 @@
|
||||
*/
|
||||
#define SOF_TKN_COMP_CORE_ID 404
|
||||
#define SOF_TKN_COMP_UUID 405
|
||||
#define SOF_TKN_COMP_CPC 406
|
||||
#define SOF_TKN_COMP_IS_PAGES 409
|
||||
#define SOF_TKN_COMP_NUM_AUDIO_FORMATS 410
|
||||
|
||||
/* SSP */
|
||||
#define SOF_TKN_INTEL_SSP_CLKS_CONTROL 500
|
||||
@ -145,4 +154,35 @@
|
||||
#define SOF_TKN_MEDIATEK_AFE_CH 1601
|
||||
#define SOF_TKN_MEDIATEK_AFE_FORMAT 1602
|
||||
|
||||
/* MIXER */
|
||||
#define SOF_TKN_MIXER_TYPE 1700
|
||||
|
||||
/* CAVS AUDIO FORMAT */
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_RATE 1900
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_BIT_DEPTH 1901
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_VALID_BIT 1902
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_CHANNELS 1903
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_CH_MAP 1904
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_CH_CFG 1905
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_INTERLEAVING_STYLE 1906
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_FMT_CFG 1907
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IN_SAMPLE_TYPE 1908
|
||||
/* intentional token numbering discontinuity, reserved for future use */
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_RATE 1930
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_BIT_DEPTH 1931
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_VALID_BIT 1932
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_CHANNELS 1933
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_CH_MAP 1934
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_CH_CFG 1935
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_INTERLEAVING_STYLE 1936
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_FMT_CFG 1937
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OUT_SAMPLE_TYPE 1938
|
||||
/* intentional token numbering discontinuity, reserved for future use */
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_IBS 1970
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_OBS 1971
|
||||
#define SOF_TKN_CAVS_AUDIO_FORMAT_DMA_BUFFER_SIZE 1972
|
||||
|
||||
/* COPIER */
|
||||
#define SOF_TKN_INTEL_COPIER_NODE_TYPE 1980
|
||||
|
||||
#endif
|
||||
|
@ -4,7 +4,7 @@ snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
|
||||
control.o trace.o iomem-utils.o sof-audio.o stream-ipc.o\
|
||||
ipc3-topology.o ipc3-control.o ipc3.o ipc3-pcm.o ipc3-loader.o\
|
||||
ipc3-dtrace.o\
|
||||
ipc4.o ipc4-loader.o
|
||||
ipc4.o ipc4-loader.o ipc4-topology.o ipc4-control.o ipc4-pcm.o
|
||||
ifneq ($(CONFIG_SND_SOC_SOF_CLIENT),)
|
||||
snd-sof-objs += sof-client.o
|
||||
endif
|
||||
|
@ -189,7 +189,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
|
||||
ret = snd_sof_probe(sdev);
|
||||
if (ret < 0) {
|
||||
dev_err(sdev->dev, "error: failed to probe DSP %d\n", ret);
|
||||
return ret;
|
||||
goto probe_err;
|
||||
}
|
||||
|
||||
sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
|
||||
@ -317,6 +317,8 @@ dbg_err:
|
||||
snd_sof_free_debug(sdev);
|
||||
dsp_err:
|
||||
snd_sof_remove(sdev);
|
||||
probe_err:
|
||||
sof_ops_free(sdev);
|
||||
|
||||
/* all resources freed, update state to match */
|
||||
sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
|
||||
@ -374,6 +376,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
|
||||
!sof_ops(sdev)->block_read || !sof_ops(sdev)->block_write ||
|
||||
!sof_ops(sdev)->send_msg || !sof_ops(sdev)->load_firmware ||
|
||||
!sof_ops(sdev)->ipc_msg_data) {
|
||||
sof_ops_free(sdev);
|
||||
dev_err(dev, "error: missing mandatory ops\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -457,6 +460,8 @@ int snd_sof_device_remove(struct device *dev)
|
||||
snd_sof_remove(sdev);
|
||||
}
|
||||
|
||||
sof_ops_free(sdev);
|
||||
|
||||
/* release firmware */
|
||||
snd_sof_fw_unload(sdev);
|
||||
|
||||
|
@ -10,10 +10,23 @@
|
||||
|
||||
#include <sound/pcm_params.h>
|
||||
#include <sound/hdaudio_ext.h>
|
||||
#include <sound/intel-nhlt.h>
|
||||
#include <sound/sof/ipc4/header.h>
|
||||
#include <uapi/sound/sof/header.h>
|
||||
#include "../ipc4-priv.h"
|
||||
#include "../ipc4-topology.h"
|
||||
#include "../sof-priv.h"
|
||||
#include "../sof-audio.h"
|
||||
#include "hda.h"
|
||||
|
||||
/*
|
||||
* The default method is to fetch NHLT from BIOS. With this parameter set
|
||||
* it is possible to override that with NHLT in the SOF topology manifest.
|
||||
*/
|
||||
static bool hda_use_tplg_nhlt;
|
||||
module_param_named(sof_use_tplg_nhlt, hda_use_tplg_nhlt, bool, 0444);
|
||||
MODULE_PARM_DESC(sof_use_tplg_nhlt, "SOF topology nhlt override");
|
||||
|
||||
#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
|
||||
|
||||
struct hda_pipe_params {
|
||||
@ -369,8 +382,7 @@ static int hda_dai_config_pause_push_ipc(struct snd_soc_dapm_widget *w)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ipc3_hda_dai_prepare(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_dai *dai)
|
||||
static int hda_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai)
|
||||
{
|
||||
struct hdac_ext_stream *hext_stream =
|
||||
snd_soc_dai_get_dma_data(dai, substream);
|
||||
@ -438,6 +450,91 @@ static int ipc3_hda_dai_trigger(struct snd_pcm_substream *substream,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* In contrast to IPC3, the dai trigger in IPC4 mixes pipeline state changes
|
||||
* (over IPC channel) and DMA state change (direct host register changes).
|
||||
*/
|
||||
static int ipc4_hda_dai_trigger(struct snd_pcm_substream *substream,
|
||||
int cmd, struct snd_soc_dai *dai)
|
||||
{
|
||||
struct hdac_ext_stream *hext_stream = snd_soc_dai_get_dma_data(dai, substream);
|
||||
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(dai->component);
|
||||
struct snd_soc_pcm_runtime *rtd;
|
||||
struct snd_sof_widget *swidget;
|
||||
struct snd_soc_dapm_widget *w;
|
||||
struct snd_soc_dai *codec_dai;
|
||||
struct hdac_stream *hstream;
|
||||
struct snd_soc_dai *cpu_dai;
|
||||
int ret;
|
||||
|
||||
dev_dbg(dai->dev, "%s: cmd=%d dai %s direction %d\n", __func__, cmd,
|
||||
dai->name, substream->stream);
|
||||
|
||||
hstream = substream->runtime->private_data;
|
||||
rtd = asoc_substream_to_rtd(substream);
|
||||
cpu_dai = asoc_rtd_to_cpu(rtd, 0);
|
||||
codec_dai = asoc_rtd_to_codec(rtd, 0);
|
||||
|
||||
w = snd_soc_dai_get_widget(dai, substream->stream);
|
||||
swidget = w->dobj.private;
|
||||
|
||||
switch (cmd) {
|
||||
case SNDRV_PCM_TRIGGER_START:
|
||||
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
||||
snd_hdac_ext_link_stream_start(hext_stream);
|
||||
break;
|
||||
case SNDRV_PCM_TRIGGER_SUSPEND:
|
||||
case SNDRV_PCM_TRIGGER_STOP:
|
||||
{
|
||||
struct snd_sof_widget *pipe_widget = swidget->pipe_widget;
|
||||
struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
|
||||
|
||||
ret = sof_ipc4_set_pipeline_state(sdev, swidget->pipeline_id,
|
||||
SOF_IPC4_PIPE_PAUSED);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
pipeline->state = SOF_IPC4_PIPE_PAUSED;
|
||||
|
||||
snd_hdac_ext_link_stream_clear(hext_stream);
|
||||
|
||||
ret = sof_ipc4_set_pipeline_state(sdev, swidget->pipeline_id,
|
||||
SOF_IPC4_PIPE_RESET);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
pipeline->state = SOF_IPC4_PIPE_RESET;
|
||||
|
||||
ret = hda_link_dma_cleanup(substream, hstream, cpu_dai, codec_dai, false);
|
||||
if (ret < 0) {
|
||||
dev_err(sdev->dev, "%s: failed to clean up link DMA\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
||||
{
|
||||
struct snd_sof_widget *pipe_widget = swidget->pipe_widget;
|
||||
struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
|
||||
|
||||
ret = sof_ipc4_set_pipeline_state(sdev, swidget->pipeline_id,
|
||||
SOF_IPC4_PIPE_PAUSED);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
pipeline->state = SOF_IPC4_PIPE_PAUSED;
|
||||
|
||||
snd_hdac_ext_link_stream_clear(hext_stream);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dev_err(sdev->dev, "%s: unknown trigger command %d\n", __func__, cmd);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hda_dai_hw_free(struct snd_pcm_substream *substream,
|
||||
struct snd_soc_dai *dai)
|
||||
{
|
||||
@ -454,7 +551,7 @@ static const struct snd_soc_dai_ops ipc3_hda_dai_ops = {
|
||||
.hw_params = hda_dai_hw_params,
|
||||
.hw_free = hda_dai_hw_free,
|
||||
.trigger = ipc3_hda_dai_trigger,
|
||||
.prepare = ipc3_hda_dai_prepare,
|
||||
.prepare = hda_dai_prepare,
|
||||
};
|
||||
|
||||
static int hda_dai_suspend(struct hdac_bus *bus)
|
||||
@ -497,6 +594,14 @@ static int hda_dai_suspend(struct hdac_bus *bus)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct snd_soc_dai_ops ipc4_hda_dai_ops = {
|
||||
.hw_params = hda_dai_hw_params,
|
||||
.hw_free = hda_dai_hw_free,
|
||||
.trigger = ipc4_hda_dai_trigger,
|
||||
.prepare = hda_dai_prepare,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* only one flag used so far to harden hw_params/hw_free/trigger/prepare */
|
||||
@ -608,6 +713,59 @@ static const struct snd_soc_dai_ops ipc3_ssp_dai_ops = {
|
||||
.shutdown = ssp_dai_shutdown,
|
||||
};
|
||||
|
||||
static int ipc4_be_dai_trigger(struct snd_pcm_substream *substream,
|
||||
int cmd, struct snd_soc_dai *dai)
|
||||
{
|
||||
struct snd_sof_widget *pipe_widget;
|
||||
struct sof_ipc4_pipeline *pipeline;
|
||||
struct snd_sof_widget *swidget;
|
||||
struct snd_soc_dapm_widget *w;
|
||||
struct snd_sof_dev *sdev;
|
||||
int ret;
|
||||
|
||||
w = snd_soc_dai_get_widget(dai, substream->stream);
|
||||
swidget = w->dobj.private;
|
||||
pipe_widget = swidget->pipe_widget;
|
||||
pipeline = pipe_widget->private;
|
||||
sdev = snd_soc_component_get_drvdata(swidget->scomp);
|
||||
|
||||
switch (cmd) {
|
||||
case SNDRV_PCM_TRIGGER_SUSPEND:
|
||||
case SNDRV_PCM_TRIGGER_STOP:
|
||||
ret = sof_ipc4_set_pipeline_state(sdev, swidget->pipeline_id,
|
||||
SOF_IPC4_PIPE_PAUSED);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
pipeline->state = SOF_IPC4_PIPE_PAUSED;
|
||||
|
||||
ret = sof_ipc4_set_pipeline_state(sdev, swidget->pipeline_id,
|
||||
SOF_IPC4_PIPE_RESET);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
pipeline->state = SOF_IPC4_PIPE_RESET;
|
||||
break;
|
||||
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
||||
ret = sof_ipc4_set_pipeline_state(sdev, swidget->pipeline_id,
|
||||
SOF_IPC4_PIPE_PAUSED);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
pipeline->state = SOF_IPC4_PIPE_PAUSED;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct snd_soc_dai_ops ipc4_dmic_dai_ops = {
|
||||
.trigger = ipc4_be_dai_trigger,
|
||||
};
|
||||
|
||||
static const struct snd_soc_dai_ops ipc4_ssp_dai_ops = {
|
||||
.trigger = ipc4_be_dai_trigger,
|
||||
};
|
||||
|
||||
void hda_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops)
|
||||
{
|
||||
int i;
|
||||
@ -627,11 +785,48 @@ void hda_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops)
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case SOF_INTEL_IPC4:
|
||||
{
|
||||
struct sof_ipc4_fw_data *ipc4_data = sdev->private;
|
||||
|
||||
for (i = 0; i < ops->num_drv; i++) {
|
||||
if (strstr(ops->drv[i].name, "DMIC")) {
|
||||
ops->drv[i].ops = &ipc4_dmic_dai_ops;
|
||||
continue;
|
||||
}
|
||||
if (strstr(ops->drv[i].name, "SSP")) {
|
||||
ops->drv[i].ops = &ipc4_ssp_dai_ops;
|
||||
continue;
|
||||
}
|
||||
#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
|
||||
if (strstr(ops->drv[i].name, "iDisp") ||
|
||||
strstr(ops->drv[i].name, "Analog") ||
|
||||
strstr(ops->drv[i].name, "Digital"))
|
||||
ops->drv[i].ops = &ipc4_hda_dai_ops;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!hda_use_tplg_nhlt)
|
||||
ipc4_data->nhlt = intel_nhlt_init(sdev->dev);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void hda_ops_free(struct snd_sof_dev *sdev)
|
||||
{
|
||||
if (sdev->pdata->ipc_type == SOF_INTEL_IPC4) {
|
||||
struct sof_ipc4_fw_data *ipc4_data = sdev->private;
|
||||
|
||||
if (!hda_use_tplg_nhlt)
|
||||
intel_nhlt_free(ipc4_data->nhlt);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_NS(hda_ops_free, SND_SOC_SOF_INTEL_HDA_COMMON);
|
||||
|
||||
/*
|
||||
* common dai driver for skl+ platforms.
|
||||
* some products who use this DAI array only physically have a subset of
|
||||
|
@ -763,6 +763,7 @@ int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w, unsigned int quirk_f
|
||||
extern int sof_hda_position_quirk;
|
||||
|
||||
void hda_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops);
|
||||
void hda_ops_free(struct snd_sof_dev *sdev);
|
||||
|
||||
/* IPC4 */
|
||||
irqreturn_t cnl_ipc4_irq_thread(int irq, void *context);
|
||||
|
@ -44,6 +44,7 @@ static const struct sof_dev_desc bxt_desc = {
|
||||
.nocodec_tplg_filename = "sof-apl-nocodec.tplg",
|
||||
.ops = &sof_apl_ops,
|
||||
.ops_init = sof_apl_ops_init,
|
||||
.ops_free = hda_ops_free,
|
||||
};
|
||||
|
||||
static const struct sof_dev_desc glk_desc = {
|
||||
|
@ -73,6 +73,7 @@ static const struct sof_dev_desc cfl_desc = {
|
||||
.nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
|
||||
.ops = &sof_cnl_ops,
|
||||
.ops_init = sof_cnl_ops_init,
|
||||
.ops_free = hda_ops_free,
|
||||
};
|
||||
|
||||
static const struct sof_dev_desc cml_desc = {
|
||||
|
@ -45,6 +45,7 @@ static const struct sof_dev_desc icl_desc = {
|
||||
.nocodec_tplg_filename = "sof-icl-nocodec.tplg",
|
||||
.ops = &sof_icl_ops,
|
||||
.ops_init = sof_icl_ops_init,
|
||||
.ops_free = hda_ops_free,
|
||||
};
|
||||
|
||||
static const struct sof_dev_desc jsl_desc = {
|
||||
|
@ -73,6 +73,7 @@ static const struct sof_dev_desc tglh_desc = {
|
||||
.nocodec_tplg_filename = "sof-tgl-nocodec.tplg",
|
||||
.ops = &sof_tgl_ops,
|
||||
.ops_init = sof_tgl_ops_init,
|
||||
.ops_free = hda_ops_free,
|
||||
};
|
||||
|
||||
static const struct sof_dev_desc ehl_desc = {
|
||||
|
@ -17,6 +17,9 @@
|
||||
/* Full volume for default values */
|
||||
#define VOL_ZERO_DB BIT(VOLUME_FWL)
|
||||
|
||||
/* size of tplg ABI in bytes */
|
||||
#define SOF_IPC3_TPLG_ABI_SIZE 3
|
||||
|
||||
struct sof_widget_data {
|
||||
int ctrl_type;
|
||||
int ipc_cmd;
|
||||
@ -2303,6 +2306,50 @@ static int sof_ipc3_dai_get_clk(struct snd_sof_dev *sdev, struct snd_sof_dai *da
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int sof_ipc3_parse_manifest(struct snd_soc_component *scomp, int index,
|
||||
struct snd_soc_tplg_manifest *man)
|
||||
{
|
||||
u32 size = le32_to_cpu(man->priv.size);
|
||||
u32 abi_version;
|
||||
|
||||
/* backward compatible with tplg without ABI info */
|
||||
if (!size) {
|
||||
dev_dbg(scomp->dev, "No topology ABI info\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size != SOF_IPC3_TPLG_ABI_SIZE) {
|
||||
dev_err(scomp->dev, "%s: Invalid topology ABI size: %u\n",
|
||||
__func__, size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dev_info(scomp->dev,
|
||||
"Topology: ABI %d:%d:%d Kernel ABI %hhu:%hhu:%hhu\n",
|
||||
man->priv.data[0], man->priv.data[1], man->priv.data[2],
|
||||
SOF_ABI_MAJOR, SOF_ABI_MINOR, SOF_ABI_PATCH);
|
||||
|
||||
abi_version = SOF_ABI_VER(man->priv.data[0], man->priv.data[1], man->priv.data[2]);
|
||||
|
||||
if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, abi_version)) {
|
||||
dev_err(scomp->dev, "%s: Incompatible topology ABI version\n", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (SOF_ABI_VERSION_MINOR(abi_version) > SOF_ABI_MINOR) {
|
||||
if (!IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS)) {
|
||||
dev_warn(scomp->dev, "%s: Topology ABI is more recent than kernel\n",
|
||||
__func__);
|
||||
} else {
|
||||
dev_err(scomp->dev, "%s: Topology ABI is more recent than kernel\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* token list for each topology object */
|
||||
static enum sof_tokens host_token_list[] = {
|
||||
SOF_CORE_TOKENS,
|
||||
@ -2413,4 +2460,5 @@ const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
|
||||
.dai_get_clk = sof_ipc3_dai_get_clk,
|
||||
.set_up_all_pipelines = sof_ipc3_set_up_all_pipelines,
|
||||
.tear_down_all_pipelines = sof_ipc3_tear_down_all_pipelines,
|
||||
.parse_manifest = sof_ipc3_parse_manifest,
|
||||
};
|
||||
|
216
sound/soc/sof/ipc4-control.c
Normal file
216
sound/soc/sof/ipc4-control.c
Normal file
@ -0,0 +1,216 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
|
||||
//
|
||||
// This file is provided under a dual BSD/GPLv2 license. When using or
|
||||
// redistributing this file, you may do so under either license.
|
||||
//
|
||||
// Copyright(c) 2022 Intel Corporation. All rights reserved.
|
||||
//
|
||||
//
|
||||
|
||||
#include "sof-priv.h"
|
||||
#include "sof-audio.h"
|
||||
#include "ipc4-priv.h"
|
||||
#include "ipc4-topology.h"
|
||||
|
||||
static int sof_ipc4_set_get_kcontrol_data(struct snd_sof_control *scontrol, bool set)
|
||||
{
|
||||
struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
|
||||
struct snd_soc_component *scomp = scontrol->scomp;
|
||||
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
|
||||
const struct sof_ipc_ops *iops = sdev->ipc->ops;
|
||||
struct sof_ipc4_msg *msg = &cdata->msg;
|
||||
struct snd_sof_widget *swidget;
|
||||
bool widget_found = false;
|
||||
|
||||
/* find widget associated with the control */
|
||||
list_for_each_entry(swidget, &sdev->widget_list, list) {
|
||||
if (swidget->comp_id == scontrol->comp_id) {
|
||||
widget_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!widget_found) {
|
||||
dev_err(scomp->dev, "Failed to find widget for kcontrol %s\n", scontrol->name);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Volatile controls should always be part of static pipelines and the widget use_count
|
||||
* would always be > 0 in this case. For the others, just return the cached value if the
|
||||
* widget is not set up.
|
||||
*/
|
||||
if (!swidget->use_count)
|
||||
return 0;
|
||||
|
||||
msg->primary &= ~SOF_IPC4_MOD_INSTANCE_MASK;
|
||||
msg->primary |= SOF_IPC4_MOD_INSTANCE(swidget->instance_id);
|
||||
|
||||
return iops->set_get_data(sdev, msg, msg->data_size, set);
|
||||
}
|
||||
|
||||
static int
|
||||
sof_ipc4_set_volume_data(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
|
||||
struct snd_sof_control *scontrol)
|
||||
{
|
||||
struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
|
||||
struct sof_ipc4_gain *gain = swidget->private;
|
||||
struct sof_ipc4_msg *msg = &cdata->msg;
|
||||
struct sof_ipc4_gain_data data;
|
||||
bool all_channels_equal = true;
|
||||
u32 value;
|
||||
int ret, i;
|
||||
|
||||
/* check if all channel values are equal */
|
||||
value = cdata->chanv[0].value;
|
||||
for (i = 1; i < scontrol->num_channels; i++) {
|
||||
if (cdata->chanv[i].value != value) {
|
||||
all_channels_equal = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* notify DSP with a single IPC message if all channel values are equal. Otherwise send
|
||||
* a separate IPC for each channel.
|
||||
*/
|
||||
for (i = 0; i < scontrol->num_channels; i++) {
|
||||
if (all_channels_equal) {
|
||||
data.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
|
||||
data.init_val = cdata->chanv[0].value;
|
||||
} else {
|
||||
data.channels = cdata->chanv[i].channel;
|
||||
data.init_val = cdata->chanv[i].value;
|
||||
}
|
||||
|
||||
/* set curve type and duration from topology */
|
||||
data.curve_duration = gain->data.curve_duration;
|
||||
data.curve_type = gain->data.curve_type;
|
||||
|
||||
msg->data_ptr = &data;
|
||||
msg->data_size = sizeof(data);
|
||||
|
||||
ret = sof_ipc4_set_get_kcontrol_data(scontrol, true);
|
||||
msg->data_ptr = NULL;
|
||||
msg->data_size = 0;
|
||||
if (ret < 0) {
|
||||
dev_err(sdev->dev, "Failed to set volume update for %s\n",
|
||||
scontrol->name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (all_channels_equal)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool sof_ipc4_volume_put(struct snd_sof_control *scontrol,
|
||||
struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
|
||||
struct snd_soc_component *scomp = scontrol->scomp;
|
||||
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
|
||||
unsigned int channels = scontrol->num_channels;
|
||||
struct snd_sof_widget *swidget;
|
||||
bool widget_found = false;
|
||||
bool change = false;
|
||||
unsigned int i;
|
||||
int ret;
|
||||
|
||||
/* update each channel */
|
||||
for (i = 0; i < channels; i++) {
|
||||
u32 value = mixer_to_ipc(ucontrol->value.integer.value[i],
|
||||
scontrol->volume_table, scontrol->max + 1);
|
||||
|
||||
change = change || (value != cdata->chanv[i].value);
|
||||
cdata->chanv[i].channel = i;
|
||||
cdata->chanv[i].value = value;
|
||||
}
|
||||
|
||||
if (!pm_runtime_active(scomp->dev))
|
||||
return change;
|
||||
|
||||
/* find widget associated with the control */
|
||||
list_for_each_entry(swidget, &sdev->widget_list, list) {
|
||||
if (swidget->comp_id == scontrol->comp_id) {
|
||||
widget_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!widget_found) {
|
||||
dev_err(scomp->dev, "Failed to find widget for kcontrol %s\n", scontrol->name);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
ret = sof_ipc4_set_volume_data(sdev, swidget, scontrol);
|
||||
if (ret < 0)
|
||||
return false;
|
||||
|
||||
return change;
|
||||
}
|
||||
|
||||
static int sof_ipc4_volume_get(struct snd_sof_control *scontrol,
|
||||
struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
|
||||
unsigned int channels = scontrol->num_channels;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < channels; i++)
|
||||
ucontrol->value.integer.value[i] = ipc_to_mixer(cdata->chanv[i].value,
|
||||
scontrol->volume_table,
|
||||
scontrol->max + 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set up all controls for the widget */
|
||||
static int sof_ipc4_widget_kcontrol_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
|
||||
{
|
||||
struct snd_sof_control *scontrol;
|
||||
int ret;
|
||||
|
||||
list_for_each_entry(scontrol, &sdev->kcontrol_list, list)
|
||||
if (scontrol->comp_id == swidget->comp_id) {
|
||||
ret = sof_ipc4_set_volume_data(sdev, swidget, scontrol);
|
||||
if (ret < 0) {
|
||||
dev_err(sdev->dev, "%s: kcontrol %d set up failed for widget %s\n",
|
||||
__func__, scontrol->comp_id, swidget->widget->name);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sof_ipc4_set_up_volume_table(struct snd_sof_control *scontrol, int tlv[SOF_TLV_ITEMS], int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* init the volume table */
|
||||
scontrol->volume_table = kcalloc(size, sizeof(u32), GFP_KERNEL);
|
||||
if (!scontrol->volume_table)
|
||||
return -ENOMEM;
|
||||
|
||||
/* populate the volume table */
|
||||
for (i = 0; i < size ; i++) {
|
||||
u32 val = vol_compute_gain(i, tlv);
|
||||
u64 q31val = ((u64)val) << 15; /* Can be over Q1.31, need to saturate */
|
||||
|
||||
scontrol->volume_table[i] = q31val > SOF_IPC4_VOL_ZERO_DB ?
|
||||
SOF_IPC4_VOL_ZERO_DB : q31val;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct sof_ipc_tplg_control_ops tplg_ipc4_control_ops = {
|
||||
.volume_put = sof_ipc4_volume_put,
|
||||
.volume_get = sof_ipc4_volume_get,
|
||||
.widget_kcontrol_setup = sof_ipc4_widget_kcontrol_setup,
|
||||
.set_up_volume_table = sof_ipc4_set_up_volume_table,
|
||||
};
|
230
sound/soc/sof/ipc4-pcm.c
Normal file
230
sound/soc/sof/ipc4-pcm.c
Normal file
@ -0,0 +1,230 @@
|
||||
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
|
||||
//
|
||||
// This file is provided under a dual BSD/GPLv2 license. When using or
|
||||
// redistributing this file, you may do so under either license.
|
||||
//
|
||||
// Copyright(c) 2022 Intel Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
#include <sound/pcm_params.h>
|
||||
#include <sound/sof/ipc4/header.h>
|
||||
#include "sof-audio.h"
|
||||
#include "sof-priv.h"
|
||||
#include "ipc4-priv.h"
|
||||
#include "ipc4-topology.h"
|
||||
|
||||
int sof_ipc4_set_pipeline_state(struct snd_sof_dev *sdev, u32 id, u32 state)
|
||||
{
|
||||
struct sof_ipc4_msg msg = {{ 0 }};
|
||||
u32 primary;
|
||||
|
||||
dev_dbg(sdev->dev, "ipc4 set pipeline %d state %d", id, state);
|
||||
|
||||
primary = state;
|
||||
primary |= SOF_IPC4_GLB_PIPE_STATE_ID(id);
|
||||
primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_GLB_SET_PIPELINE_STATE);
|
||||
primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
|
||||
primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_FW_GEN_MSG);
|
||||
|
||||
msg.primary = primary;
|
||||
|
||||
return sof_ipc_tx_message(sdev->ipc, &msg, 0, NULL, 0);
|
||||
}
|
||||
EXPORT_SYMBOL(sof_ipc4_set_pipeline_state);
|
||||
|
||||
static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,
|
||||
struct snd_pcm_substream *substream, int state)
|
||||
{
|
||||
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
||||
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
|
||||
struct snd_sof_widget *pipeline_widget;
|
||||
struct snd_soc_dapm_widget_list *list;
|
||||
struct snd_soc_dapm_widget *widget;
|
||||
struct sof_ipc4_pipeline *pipeline;
|
||||
struct snd_sof_widget *swidget;
|
||||
struct snd_sof_pcm *spcm;
|
||||
int ret = 0;
|
||||
int num_widgets;
|
||||
|
||||
spcm = snd_sof_find_spcm_dai(component, rtd);
|
||||
if (!spcm)
|
||||
return -EINVAL;
|
||||
|
||||
list = spcm->stream[substream->stream].list;
|
||||
|
||||
for_each_dapm_widgets(list, num_widgets, widget) {
|
||||
swidget = widget->dobj.private;
|
||||
|
||||
if (!swidget)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* set pipeline state for both FE and BE pipelines for RUNNING state.
|
||||
* For PAUSE/RESET, set the pipeline state only for the FE pipeline.
|
||||
*/
|
||||
switch (state) {
|
||||
case SOF_IPC4_PIPE_PAUSED:
|
||||
case SOF_IPC4_PIPE_RESET:
|
||||
if (!WIDGET_IS_AIF(swidget->id))
|
||||
continue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* find pipeline widget for the pipeline that this widget belongs to */
|
||||
pipeline_widget = swidget->pipe_widget;
|
||||
pipeline = (struct sof_ipc4_pipeline *)pipeline_widget->private;
|
||||
|
||||
if (pipeline->state == state)
|
||||
continue;
|
||||
|
||||
/* first set the pipeline to PAUSED state */
|
||||
if (pipeline->state != SOF_IPC4_PIPE_PAUSED) {
|
||||
ret = sof_ipc4_set_pipeline_state(sdev, swidget->pipeline_id,
|
||||
SOF_IPC4_PIPE_PAUSED);
|
||||
if (ret < 0) {
|
||||
dev_err(sdev->dev, "failed to pause pipeline %d\n",
|
||||
swidget->pipeline_id);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
pipeline->state = SOF_IPC4_PIPE_PAUSED;
|
||||
|
||||
if (pipeline->state == state)
|
||||
continue;
|
||||
|
||||
/* then set the final state */
|
||||
ret = sof_ipc4_set_pipeline_state(sdev, swidget->pipeline_id, state);
|
||||
if (ret < 0) {
|
||||
dev_err(sdev->dev, "failed to set state %d for pipeline %d\n",
|
||||
state, swidget->pipeline_id);
|
||||
break;
|
||||
}
|
||||
|
||||
pipeline->state = state;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sof_ipc4_pcm_trigger(struct snd_soc_component *component,
|
||||
struct snd_pcm_substream *substream, int cmd)
|
||||
{
|
||||
int state;
|
||||
|
||||
/* determine the pipeline state */
|
||||
switch (cmd) {
|
||||
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
||||
state = SOF_IPC4_PIPE_PAUSED;
|
||||
break;
|
||||
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
||||
case SNDRV_PCM_TRIGGER_RESUME:
|
||||
case SNDRV_PCM_TRIGGER_START:
|
||||
state = SOF_IPC4_PIPE_RUNNING;
|
||||
break;
|
||||
case SNDRV_PCM_TRIGGER_SUSPEND:
|
||||
case SNDRV_PCM_TRIGGER_STOP:
|
||||
state = SOF_IPC4_PIPE_PAUSED;
|
||||
break;
|
||||
default:
|
||||
dev_err(component->dev, "%s: unhandled trigger cmd %d\n", __func__, cmd);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* set the pipeline state */
|
||||
return sof_ipc4_trigger_pipelines(component, substream, state);
|
||||
}
|
||||
|
||||
static int sof_ipc4_pcm_hw_free(struct snd_soc_component *component,
|
||||
struct snd_pcm_substream *substream)
|
||||
{
|
||||
return sof_ipc4_trigger_pipelines(component, substream, SOF_IPC4_PIPE_RESET);
|
||||
}
|
||||
|
||||
static void ipc4_ssp_dai_config_pcm_params_match(struct snd_sof_dev *sdev, const char *link_name,
|
||||
struct snd_pcm_hw_params *params)
|
||||
{
|
||||
struct snd_sof_dai_link *slink;
|
||||
struct snd_sof_dai *dai;
|
||||
bool dai_link_found = false;
|
||||
int i;
|
||||
|
||||
list_for_each_entry(slink, &sdev->dai_link_list, list) {
|
||||
if (!strcmp(slink->link->name, link_name)) {
|
||||
dai_link_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dai_link_found)
|
||||
return;
|
||||
|
||||
for (i = 0; i < slink->num_hw_configs; i++) {
|
||||
struct snd_soc_tplg_hw_config *hw_config = &slink->hw_configs[i];
|
||||
|
||||
if (params_rate(params) == le32_to_cpu(hw_config->fsync_rate)) {
|
||||
/* set current config for all DAI's with matching name */
|
||||
list_for_each_entry(dai, &sdev->dai_list, list)
|
||||
if (!strcmp(slink->link->name, dai->name))
|
||||
dai->current_config = le32_to_cpu(hw_config->id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int sof_ipc4_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
|
||||
struct snd_pcm_hw_params *params)
|
||||
{
|
||||
struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
|
||||
struct snd_sof_dai *dai = snd_sof_find_dai(component, rtd->dai_link->name);
|
||||
struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
|
||||
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
|
||||
struct sof_ipc4_copier *ipc4_copier;
|
||||
struct snd_soc_dpcm *dpcm;
|
||||
|
||||
if (!dai) {
|
||||
dev_err(component->dev, "%s: No DAI found with name %s\n", __func__,
|
||||
rtd->dai_link->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ipc4_copier = dai->private;
|
||||
if (!ipc4_copier) {
|
||||
dev_err(component->dev, "%s: No private data found for DAI %s\n",
|
||||
__func__, rtd->dai_link->name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* always set BE format to 32-bits for both playback and capture */
|
||||
snd_mask_none(fmt);
|
||||
snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S32_LE);
|
||||
|
||||
/*
|
||||
* Set trigger order for capture to SND_SOC_DPCM_TRIGGER_PRE. This is required
|
||||
* to ensure that the BE DAI pipeline gets stopped/suspended before the FE DAI
|
||||
* pipeline gets triggered and the pipeline widgets are freed.
|
||||
*/
|
||||
for_each_dpcm_fe(rtd, SNDRV_PCM_STREAM_CAPTURE, dpcm) {
|
||||
struct snd_soc_pcm_runtime *fe = dpcm->fe;
|
||||
|
||||
fe->dai_link->trigger[SNDRV_PCM_STREAM_CAPTURE] = SND_SOC_DPCM_TRIGGER_PRE;
|
||||
}
|
||||
|
||||
switch (ipc4_copier->dai_type) {
|
||||
case SOF_DAI_INTEL_SSP:
|
||||
ipc4_ssp_dai_config_pcm_params_match(sdev, (char *)rtd->dai_link->name, params);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct sof_ipc_pcm_ops ipc4_pcm_ops = {
|
||||
.trigger = sof_ipc4_pcm_trigger,
|
||||
.hw_free = sof_ipc4_pcm_hw_free,
|
||||
.dai_link_fixup = sof_ipc4_pcm_dai_link_fixup,
|
||||
};
|
@ -18,11 +18,13 @@
|
||||
* @manifest_fw_hdr_offset: FW header offset in the manifest
|
||||
* @num_fw_modules : Number of modules in base FW
|
||||
* @fw_modules: Array of base FW modules
|
||||
* @nhlt: NHLT table either from the BIOS or the topology manifest
|
||||
*/
|
||||
struct sof_ipc4_fw_data {
|
||||
u32 manifest_fw_hdr_offset;
|
||||
int num_fw_modules;
|
||||
void *fw_modules;
|
||||
void *nhlt;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -40,5 +42,10 @@ struct sof_ipc4_fw_module {
|
||||
};
|
||||
|
||||
extern const struct sof_ipc_fw_loader_ops ipc4_loader_ops;
|
||||
extern const struct sof_ipc_tplg_ops ipc4_tplg_ops;
|
||||
extern const struct sof_ipc_tplg_control_ops tplg_ipc4_control_ops;
|
||||
extern const struct sof_ipc_pcm_ops ipc4_pcm_ops;
|
||||
|
||||
int sof_ipc4_set_pipeline_state(struct snd_sof_dev *sdev, u32 id, u32 state);
|
||||
|
||||
#endif
|
||||
|
1702
sound/soc/sof/ipc4-topology.c
Normal file
1702
sound/soc/sof/ipc4-topology.c
Normal file
File diff suppressed because it is too large
Load Diff
234
sound/soc/sof/ipc4-topology.h
Normal file
234
sound/soc/sof/ipc4-topology.h
Normal file
@ -0,0 +1,234 @@
|
||||
/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
|
||||
/*
|
||||
* This file is provided under a dual BSD/GPLv2 license. When using or
|
||||
* redistributing this file, you may do so under either license.
|
||||
*
|
||||
* Copyright(c) 2022 Intel Corporation. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __INCLUDE_SOUND_SOF_IPC4_TOPOLOGY_H__
|
||||
#define __INCLUDE_SOUND_SOF_IPC4_TOPOLOGY_H__
|
||||
|
||||
#include <sound/sof/ipc4/header.h>
|
||||
|
||||
#define SOF_IPC4_FW_PAGE_SIZE BIT(12)
|
||||
#define SOF_IPC4_FW_PAGE(x) ((((x) + BIT(12) - 1) & ~(BIT(12) - 1)) >> 12)
|
||||
#define SOF_IPC4_FW_ROUNDUP(x) (((x) + BIT(6) - 1) & (~(BIT(6) - 1)))
|
||||
|
||||
#define SOF_IPC4_MODULE_LL BIT(5)
|
||||
#define SOF_IPC4_MODULE_INSTANCE_LIST_ITEM_SIZE 12
|
||||
#define SOF_IPC4_PIPELINE_OBJECT_SIZE 448
|
||||
#define SOF_IPC4_DATA_QUEUE_OBJECT_SIZE 128
|
||||
#define SOF_IPC4_LL_TASK_OBJECT_SIZE 72
|
||||
#define SOF_IPC4_DP_TASK_OBJECT_SIZE 104
|
||||
#define SOF_IPC4_DP_TASK_LIST_SIZE (12 + 8)
|
||||
#define SOF_IPC4_LL_TASK_LIST_ITEM_SIZE 12
|
||||
#define SOF_IPC4_FW_MAX_PAGE_COUNT 20
|
||||
#define SOF_IPC4_FW_MAX_QUEUE_COUNT 8
|
||||
|
||||
/* Node index and mask applicable for host copier and ALH/HDA type DAI copiers */
|
||||
#define SOF_IPC4_NODE_INDEX_MASK 0xFF
|
||||
#define SOF_IPC4_NODE_INDEX(x) ((x) & SOF_IPC4_NODE_INDEX_MASK)
|
||||
#define SOF_IPC4_NODE_TYPE(x) ((x) << 8)
|
||||
|
||||
/* Node ID for SSP type DAI copiers */
|
||||
#define SOF_IPC4_NODE_INDEX_INTEL_SSP(x) (((x) & 0xf) << 4)
|
||||
|
||||
/* Node ID for DMIC type DAI copiers */
|
||||
#define SOF_IPC4_NODE_INDEX_INTEL_DMIC(x) (((x) & 0x7) << 5)
|
||||
|
||||
#define SOF_IPC4_GAIN_ALL_CHANNELS_MASK 0xffffffff
|
||||
#define SOF_IPC4_VOL_ZERO_DB 0x7fffffff
|
||||
|
||||
#define ALH_MAX_NUMBER_OF_GTW 16
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_pipeline - pipeline config data
|
||||
* @priority: Priority of this pipeline
|
||||
* @lp_mode: Low power mode
|
||||
* @mem_usage: Memory usage
|
||||
* @state: Pipeline state
|
||||
* @msg: message structure for pipeline
|
||||
*/
|
||||
struct sof_ipc4_pipeline {
|
||||
uint32_t priority;
|
||||
uint32_t lp_mode;
|
||||
uint32_t mem_usage;
|
||||
int state;
|
||||
struct sof_ipc4_msg msg;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_available_audio_format - Available audio formats
|
||||
* @base_config: Available base config
|
||||
* @out_audio_fmt: Available output audio format
|
||||
* @ref_audio_fmt: Reference audio format to match runtime audio format
|
||||
* @dma_buffer_size: Available Gateway DMA buffer size (in bytes)
|
||||
* @audio_fmt_num: Number of available audio formats
|
||||
*/
|
||||
struct sof_ipc4_available_audio_format {
|
||||
struct sof_ipc4_base_module_cfg *base_config;
|
||||
struct sof_ipc4_audio_format *out_audio_fmt;
|
||||
struct sof_ipc4_audio_format *ref_audio_fmt;
|
||||
u32 *dma_buffer_size;
|
||||
int audio_fmt_num;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_copier_gateway_cfg - IPC gateway configuration
|
||||
* @node_id: ID of Gateway Node
|
||||
* @dma_buffer_size: Preferred Gateway DMA buffer size (in bytes)
|
||||
* @config_length: Length of gateway node configuration blob specified in #config_data
|
||||
* config_data: Gateway node configuration blob
|
||||
*/
|
||||
struct sof_copier_gateway_cfg {
|
||||
uint32_t node_id;
|
||||
uint32_t dma_buffer_size;
|
||||
uint32_t config_length;
|
||||
uint32_t config_data[];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_copier_data - IPC data for copier
|
||||
* @base_config: Base configuration including input audio format
|
||||
* @out_format: Output audio format
|
||||
* @copier_feature_mask: Copier feature mask
|
||||
* @gtw_cfg: Gateway configuration
|
||||
*/
|
||||
struct sof_ipc4_copier_data {
|
||||
struct sof_ipc4_base_module_cfg base_config;
|
||||
struct sof_ipc4_audio_format out_format;
|
||||
uint32_t copier_feature_mask;
|
||||
struct sof_copier_gateway_cfg gtw_cfg;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_gtw_attributes: Gateway attributes
|
||||
* @lp_buffer_alloc: Gateway data requested in low power memory
|
||||
* @alloc_from_reg_file: Gateway data requested in register file memory
|
||||
* @rsvd: reserved for future use
|
||||
*/
|
||||
struct sof_ipc4_gtw_attributes {
|
||||
uint32_t lp_buffer_alloc : 1;
|
||||
uint32_t alloc_from_reg_file : 1;
|
||||
uint32_t rsvd : 30;
|
||||
};
|
||||
|
||||
/** struct sof_ipc4_alh_multi_gtw_cfg: ALH gateway cfg data
|
||||
* @count: Number of streams (valid items in mapping array)
|
||||
* @alh_id: ALH stream id of a single ALH stream aggregated
|
||||
* @channel_mask: Channel mask
|
||||
* @mapping: ALH streams
|
||||
*/
|
||||
struct sof_ipc4_alh_multi_gtw_cfg {
|
||||
uint32_t count;
|
||||
struct {
|
||||
uint32_t alh_id;
|
||||
uint32_t channel_mask;
|
||||
} mapping[ALH_MAX_NUMBER_OF_GTW];
|
||||
} __packed;
|
||||
|
||||
/** struct sof_ipc4_alh_configuration_blob: ALH blob
|
||||
* @gw_attr: Gateway attributes
|
||||
* @alh_cfg: ALH configuration data
|
||||
*/
|
||||
struct sof_ipc4_alh_configuration_blob {
|
||||
struct sof_ipc4_gtw_attributes gw_attr;
|
||||
struct sof_ipc4_alh_multi_gtw_cfg alh_cfg;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_copier - copier config data
|
||||
* @data: IPC copier data
|
||||
* @copier_config: Copier + blob
|
||||
* @ipc_config_size: Size of copier_config
|
||||
* @available_fmt: Available audio format
|
||||
* @frame_fmt: frame format
|
||||
* @msg: message structure for copier
|
||||
* @gtw_attr: Gateway attributes for copier blob
|
||||
* @dai_type: DAI type
|
||||
* @dai_index: DAI index
|
||||
*/
|
||||
struct sof_ipc4_copier {
|
||||
struct sof_ipc4_copier_data data;
|
||||
u32 *copier_config;
|
||||
uint32_t ipc_config_size;
|
||||
void *ipc_config_data;
|
||||
struct sof_ipc4_available_audio_format available_fmt;
|
||||
u32 frame_fmt;
|
||||
struct sof_ipc4_msg msg;
|
||||
struct sof_ipc4_gtw_attributes *gtw_attr;
|
||||
u32 dai_type;
|
||||
int dai_index;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_ctrl_value_chan: generic channel mapped value data
|
||||
* @channel: Channel ID
|
||||
* @value: gain value
|
||||
*/
|
||||
struct sof_ipc4_ctrl_value_chan {
|
||||
u32 channel;
|
||||
u32 value;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_control_data - IPC data for kcontrol IO
|
||||
* @msg: message structure for kcontrol IO
|
||||
* @index: pipeline ID
|
||||
* @chanv: channel ID and value array used by volume type controls
|
||||
* @data: data for binary kcontrols
|
||||
*/
|
||||
struct sof_ipc4_control_data {
|
||||
struct sof_ipc4_msg msg;
|
||||
int index;
|
||||
|
||||
union {
|
||||
struct sof_ipc4_ctrl_value_chan chanv[0];
|
||||
struct sof_abi_hdr data[0];
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_gain_data - IPC gain blob
|
||||
* @channels: Channels
|
||||
* @init_val: Initial value
|
||||
* @curve_type: Curve type
|
||||
* @reserved: reserved for future use
|
||||
* @curve_duration: Curve duration
|
||||
*/
|
||||
struct sof_ipc4_gain_data {
|
||||
uint32_t channels;
|
||||
uint32_t init_val;
|
||||
uint32_t curve_type;
|
||||
uint32_t reserved;
|
||||
uint32_t curve_duration;
|
||||
} __aligned(8);
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_gain - gain config data
|
||||
* @base_config: IPC base config data
|
||||
* @data: IPC gain blob
|
||||
* @available_fmt: Available audio format
|
||||
* @msg: message structure for gain
|
||||
*/
|
||||
struct sof_ipc4_gain {
|
||||
struct sof_ipc4_base_module_cfg base_config;
|
||||
struct sof_ipc4_gain_data data;
|
||||
struct sof_ipc4_available_audio_format available_fmt;
|
||||
struct sof_ipc4_msg msg;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct sof_ipc4_mixer - mixer config data
|
||||
* @base_config: IPC base config data
|
||||
* @available_fmt: Available audio format
|
||||
* @msg: IPC4 message struct containing header and data info
|
||||
*/
|
||||
struct sof_ipc4_mixer {
|
||||
struct sof_ipc4_base_module_cfg base_config;
|
||||
struct sof_ipc4_available_audio_format available_fmt;
|
||||
struct sof_ipc4_msg msg;
|
||||
};
|
||||
|
||||
#endif
|
@ -644,4 +644,6 @@ const struct sof_ipc_ops ipc4_ops = {
|
||||
.get_reply = sof_ipc4_get_reply,
|
||||
.pm = &ipc4_pm_ops,
|
||||
.fw_loader = &ipc4_loader_ops,
|
||||
.tplg = &ipc4_tplg_ops,
|
||||
.pcm = &ipc4_pcm_ops,
|
||||
};
|
||||
|
@ -29,6 +29,12 @@ static inline int sof_ops_init(struct snd_sof_dev *sdev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void sof_ops_free(struct snd_sof_dev *sdev)
|
||||
{
|
||||
if (sdev->pdata->desc->ops_free)
|
||||
sdev->pdata->desc->ops_free(sdev);
|
||||
}
|
||||
|
||||
/* Mandatory operations are verified during probing */
|
||||
|
||||
/* init */
|
||||
|
@ -168,6 +168,7 @@ struct sof_ipc_tplg_widget_ops {
|
||||
* @dai_get_clk: Function pointer for getting the DAI clock setting
|
||||
* @set_up_all_pipelines: Function pointer for setting up all topology pipelines
|
||||
* @tear_down_all_pipelines: Function pointer for tearing down all topology pipelines
|
||||
* @parse_manifest: Optional function pointer for ipc4 specific parsing of topology manifest
|
||||
*/
|
||||
struct sof_ipc_tplg_ops {
|
||||
const struct sof_ipc_tplg_widget_ops *widget;
|
||||
@ -185,6 +186,8 @@ struct sof_ipc_tplg_ops {
|
||||
int (*dai_get_clk)(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int clk_type);
|
||||
int (*set_up_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
|
||||
int (*tear_down_all_pipelines)(struct snd_sof_dev *sdev, bool verify);
|
||||
int (*parse_manifest)(struct snd_soc_component *scomp, int index,
|
||||
struct snd_soc_tplg_manifest *man);
|
||||
};
|
||||
|
||||
/** struct snd_sof_tuple - Tuple info
|
||||
@ -225,6 +228,14 @@ enum sof_tokens {
|
||||
SOF_AFE_TOKENS,
|
||||
SOF_CORE_TOKENS,
|
||||
SOF_COMP_EXT_TOKENS,
|
||||
SOF_IN_AUDIO_FORMAT_TOKENS,
|
||||
SOF_OUT_AUDIO_FORMAT_TOKENS,
|
||||
SOF_AUDIO_FORMAT_BUFFER_SIZE_TOKENS,
|
||||
SOF_COPIER_GATEWAY_CFG_TOKENS,
|
||||
SOF_COPIER_TOKENS,
|
||||
SOF_AUDIO_FMT_NUM_TOKENS,
|
||||
SOF_COPIER_FORMAT_TOKENS,
|
||||
SOF_GAIN_TOKENS,
|
||||
|
||||
/* this should be the last */
|
||||
SOF_TOKEN_COUNT,
|
||||
|
@ -36,9 +36,6 @@
|
||||
#define TLV_STEP 1
|
||||
#define TLV_MUTE 2
|
||||
|
||||
/* size of tplg abi in byte */
|
||||
#define SOF_TPLG_ABI_SIZE 3
|
||||
|
||||
/**
|
||||
* sof_update_ipc_object - Parse multiple sets of tokens within the token array associated with the
|
||||
* token ID.
|
||||
@ -1141,6 +1138,21 @@ static int spcm_bind(struct snd_soc_component *scomp, struct snd_sof_pcm *spcm,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sof_get_token_value(u32 token_id, struct snd_sof_tuple *tuples, int num_tuples)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!tuples)
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < num_tuples; i++) {
|
||||
if (tuples[i].token == token_id)
|
||||
return tuples[i].value.v;
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_sof_widget *swidget,
|
||||
struct snd_soc_tplg_dapm_widget *tw,
|
||||
enum sof_tokens *object_token_list, int count)
|
||||
@ -1168,6 +1180,8 @@ static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_s
|
||||
|
||||
/* parse token list for widget */
|
||||
for (i = 0; i < count; i++) {
|
||||
int num_sets = 1;
|
||||
|
||||
if (object_token_list[i] >= SOF_TOKEN_COUNT) {
|
||||
dev_err(scomp->dev, "Invalid token id %d for widget %s\n",
|
||||
object_token_list[i], swidget->widget->name);
|
||||
@ -1175,8 +1189,9 @@ static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_s
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* parse and save UUID in swidget */
|
||||
if (object_token_list[i] == SOF_COMP_EXT_TOKENS) {
|
||||
switch (object_token_list[i]) {
|
||||
case SOF_COMP_EXT_TOKENS:
|
||||
/* parse and save UUID in swidget */
|
||||
ret = sof_parse_tokens(scomp, swidget,
|
||||
token_list[object_token_list[i]].tokens,
|
||||
token_list[object_token_list[i]].count,
|
||||
@ -1189,11 +1204,41 @@ static int sof_widget_parse_tokens(struct snd_soc_component *scomp, struct snd_s
|
||||
}
|
||||
|
||||
continue;
|
||||
case SOF_IN_AUDIO_FORMAT_TOKENS:
|
||||
case SOF_OUT_AUDIO_FORMAT_TOKENS:
|
||||
case SOF_COPIER_GATEWAY_CFG_TOKENS:
|
||||
case SOF_AUDIO_FORMAT_BUFFER_SIZE_TOKENS:
|
||||
num_sets = sof_get_token_value(SOF_TKN_COMP_NUM_AUDIO_FORMATS,
|
||||
swidget->tuples, swidget->num_tuples);
|
||||
|
||||
if (num_sets < 0) {
|
||||
dev_err(sdev->dev, "Invalid audio format count for %s\n",
|
||||
swidget->widget->name);
|
||||
ret = num_sets;
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (num_sets > 1) {
|
||||
struct snd_sof_tuple *new_tuples;
|
||||
|
||||
num_tuples += token_list[object_token_list[i]].count * num_sets;
|
||||
new_tuples = krealloc(swidget->tuples,
|
||||
sizeof(*new_tuples) * num_tuples, GFP_KERNEL);
|
||||
if (!new_tuples) {
|
||||
ret = -ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
|
||||
swidget->tuples = new_tuples;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* copy one set of tuples per token ID into swidget->tuples */
|
||||
ret = sof_copy_tuples(sdev, private->array, le32_to_cpu(private->size),
|
||||
object_token_list[i], 1, swidget->tuples,
|
||||
object_token_list[i], num_sets, swidget->tuples,
|
||||
num_tuples, &swidget->num_tuples);
|
||||
if (ret < 0) {
|
||||
dev_err(scomp->dev, "Failed parsing %s for widget %s err: %d\n",
|
||||
@ -1208,21 +1253,6 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int sof_get_token_value(u32 token_id, struct snd_sof_tuple *tuples, int num_tuples)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!tuples)
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < num_tuples; i++) {
|
||||
if (tuples[i].token == token_id)
|
||||
return tuples[i].value.v;
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* external widget init - used for any driver specific init */
|
||||
static int sof_widget_ready(struct snd_soc_component *scomp, int index,
|
||||
struct snd_soc_dapm_widget *w,
|
||||
@ -1987,45 +2017,11 @@ static int sof_complete(struct snd_soc_component *scomp)
|
||||
static int sof_manifest(struct snd_soc_component *scomp, int index,
|
||||
struct snd_soc_tplg_manifest *man)
|
||||
{
|
||||
u32 size;
|
||||
u32 abi_version;
|
||||
struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
|
||||
const struct sof_ipc_tplg_ops *ipc_tplg_ops = sdev->ipc->ops->tplg;
|
||||
|
||||
size = le32_to_cpu(man->priv.size);
|
||||
|
||||
/* backward compatible with tplg without ABI info */
|
||||
if (!size) {
|
||||
dev_dbg(scomp->dev, "No topology ABI info\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (size != SOF_TPLG_ABI_SIZE) {
|
||||
dev_err(scomp->dev, "error: invalid topology ABI size\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dev_info(scomp->dev,
|
||||
"Topology: ABI %d:%d:%d Kernel ABI %d:%d:%d\n",
|
||||
man->priv.data[0], man->priv.data[1],
|
||||
man->priv.data[2], SOF_ABI_MAJOR, SOF_ABI_MINOR,
|
||||
SOF_ABI_PATCH);
|
||||
|
||||
abi_version = SOF_ABI_VER(man->priv.data[0],
|
||||
man->priv.data[1],
|
||||
man->priv.data[2]);
|
||||
|
||||
if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, abi_version)) {
|
||||
dev_err(scomp->dev, "error: incompatible topology ABI version\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (SOF_ABI_VERSION_MINOR(abi_version) > SOF_ABI_MINOR) {
|
||||
if (!IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS)) {
|
||||
dev_warn(scomp->dev, "warn: topology ABI is more recent than kernel\n");
|
||||
} else {
|
||||
dev_err(scomp->dev, "error: topology ABI is more recent than kernel\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
if (ipc_tplg_ops->parse_manifest)
|
||||
return ipc_tplg_ops->parse_manifest(scomp, index, man);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user