Skip to content
5 changes: 5 additions & 0 deletions sound/soc/codecs/hdac_hda.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ static int hdac_hda_dai_hw_params(struct snd_pcm_substream *substream,
unsigned int format_val;
unsigned int maxbps;

dev_info(component->dev, "plb: %s: start dai %s\n", __func__, dai->name);

if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
maxbps = dai->driver->playback.sig_bits;
else
Expand All @@ -229,6 +231,9 @@ static int hdac_hda_dai_hw_params(struct snd_pcm_substream *substream,
}

hda_pvt->pcm[dai->id].format_val[substream->stream] = format_val;

dev_info(component->dev, "plb: %s: done %s\n", __func__, dai->name);

return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions sound/soc/soc-dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,13 @@ int snd_soc_dai_hw_params(struct snd_soc_dai *dai,

if (dai->driver->ops &&
dai->driver->ops->hw_params) {
dev_info(dai->dev, "%s: plb before snd_soc_link_be_hw_params_fixup\n", __func__);

/* perform any topology hw_params fixups before DAI */
ret = snd_soc_link_be_hw_params_fixup(rtd, params);
if (ret < 0)
goto end;
dev_info(dai->dev, "%s: plb after snd_soc_link_be_hw_params_fixup\n", __func__);

ret = dai->driver->ops->hw_params(substream, params, dai);
}
Expand Down
65 changes: 34 additions & 31 deletions sound/soc/soc-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,16 +453,6 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
int i;
unsigned int bits = 0, cpu_bits = 0;

for_each_rtd_codec_dais(rtd, i, codec_dai) {
struct snd_soc_pcm_stream *pcm_codec = snd_soc_dai_get_pcm_stream(codec_dai, stream);

if (pcm_codec->sig_bits == 0) {
bits = 0;
break;
}
bits = max(pcm_codec->sig_bits, bits);
}

for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
struct snd_soc_pcm_stream *pcm_cpu = snd_soc_dai_get_pcm_stream(cpu_dai, stream);

Expand All @@ -472,9 +462,18 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
}
cpu_bits = max(pcm_cpu->sig_bits, cpu_bits);
}
soc_pcm_set_msb(substream, cpu_bits);

for_each_rtd_codec_dais(rtd, i, codec_dai) {
struct snd_soc_pcm_stream *pcm_codec = snd_soc_dai_get_pcm_stream(codec_dai, stream);

if (pcm_codec->sig_bits == 0) {
bits = 0;
break;
}
bits = max(pcm_codec->sig_bits, bits);
}
soc_pcm_set_msb(substream, bits);
soc_pcm_set_msb(substream, cpu_bits);
}

static void soc_pcm_hw_init(struct snd_pcm_hardware *hw)
Expand Down Expand Up @@ -940,6 +939,23 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
if (ret < 0)
goto out;

for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
/*
* Skip CPUs which don't support the current stream
* type. See soc_pcm_init_runtime_hw() for more details
*/
if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
continue;

ret = snd_soc_dai_hw_params(cpu_dai, substream, params);
Copy link

@RanderWang RanderWang Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snd_soc_dai_hw_params will call snd_soc_link_be_hw_params_fixup to change the params.
In original sequence, codec_params will use default params. With this commit, it will use the params fixed up by cpu_dai. This may be a risk.

 /* copy params for each codec */
		codec_params = *params;

Or we can copy this method and do it like " cpu_params = *params", then use cpu_params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the order change in my last version, not worth the effort.

if (ret < 0)
goto out;

/* store the parameters for each DAI */
soc_pcm_set_dai_params(cpu_dai, params);
snd_soc_dapm_update_dai(substream, params, cpu_dai);
}

for_each_rtd_codec_dais(rtd, i, codec_dai) {
struct snd_pcm_hw_params codec_params;

Expand All @@ -965,9 +981,11 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,

/* fixup params based on TDM slot masks */
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
codec_dai->tx_mask)
soc_pcm_codec_params_fixup(&codec_params,
codec_dai->tx_mask);
codec_dai->tx_mask) {
dev_info(codec_dai->dev, "%s: plb: stream tag is %d, ignored\n", __func__, codec_dai->tx_mask);
//soc_pcm_codec_params_fixup(&codec_params,
// codec_dai->tx_mask);
}

if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
codec_dai->rx_mask)
Expand All @@ -983,23 +1001,6 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
snd_soc_dapm_update_dai(substream, &codec_params, codec_dai);
}

for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
/*
* Skip CPUs which don't support the current stream
* type. See soc_pcm_init_runtime_hw() for more details
*/
if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
continue;

ret = snd_soc_dai_hw_params(cpu_dai, substream, params);
if (ret < 0)
goto out;

/* store the parameters for each DAI */
soc_pcm_set_dai_params(cpu_dai, params);
snd_soc_dapm_update_dai(substream, params, cpu_dai);
}

ret = snd_soc_pcm_component_hw_params(substream, params);
out:
mutex_unlock(&rtd->card->pcm_mutex);
Expand Down Expand Up @@ -1901,9 +1902,11 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
sizeof(struct snd_pcm_hw_params));

/* perform any hw_params fixups */
dev_info(be->dev, "%s: plb before snd_soc_link_be_hw_params_fixup\n", __func__);
ret = snd_soc_link_be_hw_params_fixup(be, &dpcm->hw_params);
if (ret < 0)
goto unwind;
dev_info(be->dev, "%s: plb after snd_soc_link_be_hw_params_fixup\n", __func__);

/* copy the fixed-up hw params for BE dai */
memcpy(&be->dpcm[stream].hw_params, &dpcm->hw_params,
Expand Down
Loading