From 8129aec6b2ab39362a894f9d5f7bdd7fc3238b92 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Mon, 25 Feb 2019 15:00:17 -0800 Subject: [PATCH 1/4] ASoC: SOF: bind pcm to host comp when the dai is loaded Previously, PCM's were bound to the host component by using an explicit pipeline graph path from the PCM device to the host comp in topology. This graph route is unnecessary and it results in a duplicate connection shown for the host dapm widget from the PCM device. Instead, pcm's should be bound to the respective host comp when the dai is loaded. Signed-off-by: Ranjani Sridharan --- sound/soc/sof/core.c | 21 ++++++++++ sound/soc/sof/sof-priv.h | 2 + sound/soc/sof/topology.c | 84 ++++++++++++++++++---------------------- 3 files changed, 60 insertions(+), 47 deletions(-) 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/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..aa1c6c8a794e5f 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: @@ -2610,38 +2647,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 +2655,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 +2682,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 +2693,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; From f147f56b75c0ccc0beaf435a510cbe27f3cb19d7 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Mon, 25 Feb 2019 15:13:49 -0800 Subject: [PATCH 2/4] ASoC: dapm: set power_check callback for widgets that shouldnt be always on Currently, buffers, schedulers, src's, encoders, decoders and effect type dapm widgets remain always on as their power_check method is not set. Setting this callback allows these widgets in the audio path to be powered managed properly. Signed-off-by: Ranjani Sridharan --- sound/soc/soc-dapm.c | 7 +++++++ 1 file changed, 7 insertions(+) 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: From a044708ed57313494f9d22d820a1c5674d93d000 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Mon, 25 Feb 2019 18:57:14 -0800 Subject: [PATCH 3/4] ASoC: SOF: remove dai capabilities from dai definitions Dai capabilities/configuration are defined in topology. The capabilities defined in the dai drv for the resp platforms don't seem to be used at all. As an additional benefit, removing these cleans up the DAPM graph. Signed-off-by: Ranjani Sridharan --- sound/soc/sof/intel/bdw.c | 11 -------- sound/soc/sof/intel/byt.c | 27 ------------------- sound/soc/sof/intel/hda-dai.c | 49 ----------------------------------- sound/soc/sof/intel/hsw.c | 11 -------- 4 files changed, 98 deletions(-) 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), }, }; From ca43cb6443e80959727fe2dfba7193637fcb0259 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Tue, 26 Feb 2019 17:31:26 -0800 Subject: [PATCH 4/4] ASoC: SOF: validate SSP fsync rate and channel count in topology Validate the fsync rate and channel count for SSP before configuring the DAI. Signed-off-by: Ranjani Sridharan --- sound/soc/sof/topology.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index aa1c6c8a794e5f..cc4a08f2d4f968 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -2206,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,