diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index dad19e903cb92d..de847cde153867 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3651,6 +3651,13 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, case snd_soc_dapm_dac: case snd_soc_dapm_aif_in: case snd_soc_dapm_pga: + case snd_soc_dapm_buffer: + case snd_soc_dapm_scheduler: + case snd_soc_dapm_effect: + case snd_soc_dapm_src: + case snd_soc_dapm_asrc: + case snd_soc_dapm_encoder: + case snd_soc_dapm_decoder: case snd_soc_dapm_out_drv: case snd_soc_dapm_micbias: case snd_soc_dapm_line: diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c index c878c196169ce9..43017e8c6cb3cc 100644 --- a/sound/soc/sof/core.c +++ b/sound/soc/sof/core.c @@ -102,6 +102,27 @@ struct snd_sof_widget *snd_sof_find_swidget(struct snd_sof_dev *sdev, return NULL; } +/* find widget by stream name and direction */ +struct snd_sof_widget *snd_sof_find_swidget_sname(struct snd_sof_dev *sdev, + char *pcm_name, int dir) +{ + struct snd_sof_widget *swidget = NULL; + enum snd_soc_dapm_type type; + + if (dir == SNDRV_PCM_STREAM_PLAYBACK) + type = snd_soc_dapm_aif_in; + else + type = snd_soc_dapm_aif_out; + + list_for_each_entry(swidget, &sdev->widget_list, list) { + if (!strcmp(pcm_name, swidget->widget->sname) && + swidget->id == type) + return swidget; + } + + return NULL; +} + struct snd_sof_dai *snd_sof_find_dai(struct snd_sof_dev *sdev, char *name) { diff --git a/sound/soc/sof/intel/bdw.c b/sound/soc/sof/intel/bdw.c index fbaa170fc5e14a..1340ccf6fba845 100644 --- a/sound/soc/sof/intel/bdw.c +++ b/sound/soc/sof/intel/bdw.c @@ -640,24 +640,13 @@ static int bdw_probe(struct snd_sof_dev *sdev) return ret; } -#define BDW_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ - SNDRV_PCM_FMTBIT_S32_LE) - /* Broadwell DAIs */ static struct snd_soc_dai_driver bdw_dai[] = { { .name = "ssp0-port", - .playback = SOF_DAI_STREAM("ssp0 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BDW_FORMATS), - .capture = SOF_DAI_STREAM("ssp0 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BDW_FORMATS), }, { .name = "ssp1-port", - .playback = SOF_DAI_STREAM("ssp1 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BDW_FORMATS), - .capture = SOF_DAI_STREAM("ssp1 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BDW_FORMATS), }, }; diff --git a/sound/soc/sof/intel/byt.c b/sound/soc/sof/intel/byt.c index 8baf98764488b2..74a618c095df56 100644 --- a/sound/soc/sof/intel/byt.c +++ b/sound/soc/sof/intel/byt.c @@ -485,52 +485,25 @@ static int byt_reset(struct snd_sof_dev *sdev) return 0; } -#define BYT_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ - SNDRV_PCM_FMTBIT_S32_LE) - /* Baytrail DAIs */ static struct snd_soc_dai_driver byt_dai[] = { { .name = "ssp0-port", - .playback = SOF_DAI_STREAM("ssp0 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), - .capture = SOF_DAI_STREAM("ssp0 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), }, { .name = "ssp1-port", - .playback = SOF_DAI_STREAM("ssp1 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), - .capture = SOF_DAI_STREAM("ssp1 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), }, { .name = "ssp2-port", - .playback = SOF_DAI_STREAM("ssp2 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), - .capture = SOF_DAI_STREAM("ssp2 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), }, { .name = "ssp3-port", - .playback = SOF_DAI_STREAM("ssp3 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), - .capture = SOF_DAI_STREAM("ssp3 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), }, { .name = "ssp4-port", - .playback = SOF_DAI_STREAM("ssp4 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), - .capture = SOF_DAI_STREAM("ssp4 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), }, { .name = "ssp5-port", - .playback = SOF_DAI_STREAM("ssp5 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), - .capture = SOF_DAI_STREAM("ssp5 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, BYT_FORMATS), }, }; diff --git a/sound/soc/sof/intel/hda-dai.c b/sound/soc/sof/intel/hda-dai.c index f7b9771ec3cd93..5e04aba0c0518b 100644 --- a/sound/soc/sof/intel/hda-dai.c +++ b/sound/soc/sof/intel/hda-dai.c @@ -13,9 +13,6 @@ #include "../sof-priv.h" #include "hda.h" -#define SKL_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ - SNDRV_PCM_FMTBIT_S32_LE) - #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) struct hda_pipe_params { @@ -265,98 +262,52 @@ static const struct snd_soc_dai_ops hda_link_dai_ops = { struct snd_soc_dai_driver skl_dai[] = { { .name = "SSP0 Pin", - .playback = SOF_DAI_STREAM("ssp0 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("ssp0 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "SSP1 Pin", - .playback = SOF_DAI_STREAM("ssp1 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("ssp1 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "SSP2 Pin", - .playback = SOF_DAI_STREAM("ssp2 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("ssp2 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "SSP3 Pin", - .playback = SOF_DAI_STREAM("ssp3 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("ssp3 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "SSP4 Pin", - .playback = SOF_DAI_STREAM("ssp4 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("ssp4 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "SSP5 Pin", - .playback = SOF_DAI_STREAM("ssp5 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("ssp5 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "DMIC01 Pin", - .capture = SOF_DAI_STREAM("DMIC01 Rx", 1, 4, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "DMIC16k Pin", - .capture = SOF_DAI_STREAM("DMIC16k Rx", 1, 4, - SNDRV_PCM_RATE_16000, SKL_FORMATS), }, #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) { .name = "iDisp1 Pin", .ops = &hda_link_dai_ops, - .playback = SOF_DAI_STREAM("iDisp1 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "iDisp2 Pin", .ops = &hda_link_dai_ops, - .playback = SOF_DAI_STREAM("iDisp2 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "iDisp3 Pin", .ops = &hda_link_dai_ops, - .playback = SOF_DAI_STREAM("iDisp3 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "Analog CPU DAI", .ops = &hda_link_dai_ops, - .playback = SOF_DAI_STREAM("Analog CPU Playback", 1, 16, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("Analog CPU Capture", 1, 16, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "Digital CPU DAI", .ops = &hda_link_dai_ops, - .playback = SOF_DAI_STREAM("Digital CPU Playback", 1, 16, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("Digital CPU Capture", 1, 16, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, { .name = "Alt Analog CPU DAI", .ops = &hda_link_dai_ops, - .playback = SOF_DAI_STREAM("Alt Analog CPU Playback", 1, 16, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), - .capture = SOF_DAI_STREAM("Alt Analog CPU Capture", 1, 16, - SNDRV_PCM_RATE_8000_192000, SKL_FORMATS), }, #endif }; diff --git a/sound/soc/sof/intel/hsw.c b/sound/soc/sof/intel/hsw.c index 8295b4b02dd41c..09c9ab8e0f67bd 100644 --- a/sound/soc/sof/intel/hsw.c +++ b/sound/soc/sof/intel/hsw.c @@ -640,24 +640,13 @@ static int hsw_probe(struct snd_sof_dev *sdev) return ret; } -#define HSW_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ - SNDRV_PCM_FMTBIT_S32_LE) - /* Haswell DAIs */ static struct snd_soc_dai_driver hsw_dai[] = { { .name = "ssp0-port", - .playback = SOF_DAI_STREAM("ssp0 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, HSW_FORMATS), - .capture = SOF_DAI_STREAM("ssp0 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, HSW_FORMATS), }, { .name = "ssp1-port", - .playback = SOF_DAI_STREAM("ssp1 Tx", 1, 8, - SNDRV_PCM_RATE_8000_192000, HSW_FORMATS), - .capture = SOF_DAI_STREAM("ssp1 Rx", 1, 8, - SNDRV_PCM_RATE_8000_192000, HSW_FORMATS), }, }; diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index 2f38a7ce0aa77c..b443c4f5201734 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -468,6 +468,8 @@ int sof_ipc_tx_message(struct snd_sof_ipc *ipc, u32 header, size_t reply_bytes); struct snd_sof_widget *snd_sof_find_swidget(struct snd_sof_dev *sdev, char *name); +struct snd_sof_widget *snd_sof_find_swidget_sname(struct snd_sof_dev *sdev, + char *pcm_name, int dir); struct snd_sof_dai *snd_sof_find_dai(struct snd_sof_dev *sdev, char *name); struct snd_sof_pcm *snd_sof_find_spcm_dai(struct snd_sof_dev *sdev, diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index d23c6c346e3af1..cc4a08f2d4f968 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -1068,6 +1068,25 @@ static int sof_widget_load_buffer(struct snd_soc_component *scomp, int index, return ret; } +/* bind PCM ID to host component ID */ +static int spcm_bind(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm, + int dir) +{ + struct snd_sof_widget *host_widget; + + host_widget = snd_sof_find_swidget_sname(sdev, + spcm->pcm.caps[dir].name, + dir); + if (!host_widget) { + dev_err(sdev->dev, "can't find host comp to bind pcm\n"); + return -EINVAL; + } + + spcm->stream[dir].comp_id = host_widget->comp_id; + + return 0; +} + /* * PCM Topology */ @@ -1989,6 +2008,7 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, spcm->sdev = sdev; spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].comp_id = COMP_ID_UNASSIGNED; spcm->stream[SNDRV_PCM_STREAM_CAPTURE].comp_id = COMP_ID_UNASSIGNED; + if (pcm) { spcm->pcm = *pcm; dev_dbg(sdev->dev, "tplg: load pcm %s\n", pcm->dai_name); @@ -2013,6 +2033,14 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, return ret; } + /* bind pcm to host comp */ + ret = spcm_bind(sdev, spcm, stream); + if (ret) { + dev_err(sdev->dev, + "error: can't bind pcm to host\n"); + goto free_playback_tables; + } + capture: stream = SNDRV_PCM_STREAM_CAPTURE; @@ -2031,6 +2059,15 @@ static int sof_dai_load(struct snd_soc_component *scomp, int index, goto free_playback_tables; } + /* bind pcm to host comp */ + ret = spcm_bind(sdev, spcm, stream); + if (ret) { + dev_err(sdev->dev, + "error: can't bind pcm to host\n"); + snd_dma_free_pages(&spcm->stream[stream].page_table); + goto free_playback_tables; + } + return ret; free_playback_tables: @@ -2169,6 +2206,19 @@ static int sof_link_ssp_load(struct snd_soc_component *scomp, int index, config->ssp.tdm_slot_width, config->ssp.tdm_slots, config->ssp.mclk_id); + /* validate SSP fsync rate and channel count */ + if (config->ssp.fsync_rate < 8000 || config->ssp.fsync_rate > 192000) { + dev_err(sdev->dev, "error: invalid fsync rate for SSP%d\n", + config->dai_index); + return -EINVAL; + } + + if (config->ssp.tdm_slots < 1 || config->ssp.tdm_slots > 8) { + dev_err(sdev->dev, "error: invalid channel count for SSP%d\n", + config->dai_index); + return -EINVAL; + } + /* send message to DSP */ ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, size, &reply, @@ -2610,38 +2660,6 @@ static int sof_link_unload(struct snd_soc_component *scomp, return ret; } -/* bind PCM ID to host component ID */ -static int spcm_bind(struct snd_soc_component *scomp, struct snd_sof_pcm *spcm, - const char *host) -{ - struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); - struct snd_sof_widget *host_widget; - - host_widget = snd_sof_find_swidget(sdev, (char *)host); - if (!host_widget) { - dev_err(sdev->dev, "error: can't find host component %s\n", - host); - return -ENODEV; - } - - switch (host_widget->id) { - case snd_soc_dapm_aif_in: - spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].comp_id = - host_widget->comp_id; - break; - case snd_soc_dapm_aif_out: - spcm->stream[SNDRV_PCM_STREAM_CAPTURE].comp_id = - host_widget->comp_id; - break; - default: - dev_err(sdev->dev, "error: host is wrong type %d\n", - host_widget->id); - return -EINVAL; - } - - return 0; -} - /* DAI link - used for any driver specific init */ static int sof_route_load(struct snd_soc_component *scomp, int index, struct snd_soc_dapm_route *route) @@ -2650,7 +2668,6 @@ static int sof_route_load(struct snd_soc_component *scomp, int index, struct sof_ipc_pipe_comp_connect *connect; struct snd_sof_widget *source_swidget, *sink_swidget; struct snd_soc_dobj *dobj = &route->dobj; - struct snd_sof_pcm *spcm; struct snd_sof_route *sroute; struct sof_ipc_reply reply; int ret = 0; @@ -2678,13 +2695,6 @@ static int sof_route_load(struct snd_soc_component *scomp, int index, /* source component */ source_swidget = snd_sof_find_swidget(sdev, (char *)route->source); if (!source_swidget) { - /* don't send any routes to DSP that include a driver PCM */ - spcm = snd_sof_find_spcm_name(sdev, (char *)route->source); - if (spcm) { - ret = spcm_bind(scomp, spcm, route->sink); - goto err; - } - dev_err(sdev->dev, "error: source %s not found\n", route->source); ret = -EINVAL; @@ -2696,13 +2706,6 @@ static int sof_route_load(struct snd_soc_component *scomp, int index, /* sink component */ sink_swidget = snd_sof_find_swidget(sdev, (char *)route->sink); if (!sink_swidget) { - /* don't send any routes to DSP that include a driver PCM */ - spcm = snd_sof_find_spcm_name(sdev, (char *)route->sink); - if (spcm) { - ret = spcm_bind(scomp, spcm, route->source); - goto err; - } - dev_err(sdev->dev, "error: sink %s not found\n", route->sink); ret = -EINVAL;