Skip to content

Commit b073ed4

Browse files
morimotobroonie
authored andcommitted
ASoC: soc-pcm: DPCM cares BE format
Current DPCM is caring only FE format. but it will be no sound if FE/BE was below style, and user selects S24_LE format. FE: S16_LE/S24_LE BE: S16_LE DPCM can rewrite the format, so basically we don't want to constrain with the BE constraints. But sometimes it will be trouble. This patch adds new .dpcm_merged_format on struct snd_soc_dai_link. DPCM will use FE / BE merged format if .struct snd_soc_dai_link has it. We can have other .dpcm_merged_xxx in the future .dpcm_merged_foramt .dpcm_merged_rate .dpcm_merged_chan Signed-off-by: Kuninori Morimoto <[email protected]> Tested-by: Keita Kobayashi <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 2dc0f16 commit b073ed4

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

include/sound/soc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,9 @@ struct snd_soc_dai_link {
985985
unsigned int dpcm_capture:1;
986986
unsigned int dpcm_playback:1;
987987

988+
/* DPCM used FE & BE merged format */
989+
unsigned int dpcm_merged_format:1;
990+
988991
/* pmdown_time is ignored at stop */
989992
unsigned int ignore_pmdown_time:1;
990993
};

sound/soc/soc-pcm.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,30 +1485,67 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
14851485
}
14861486

14871487
static void dpcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
1488-
struct snd_soc_pcm_stream *stream)
1488+
struct snd_soc_pcm_stream *stream,
1489+
u64 formats)
14891490
{
14901491
runtime->hw.rate_min = stream->rate_min;
14911492
runtime->hw.rate_max = stream->rate_max;
14921493
runtime->hw.channels_min = stream->channels_min;
14931494
runtime->hw.channels_max = stream->channels_max;
14941495
if (runtime->hw.formats)
1495-
runtime->hw.formats &= stream->formats;
1496+
runtime->hw.formats &= formats & stream->formats;
14961497
else
1497-
runtime->hw.formats = stream->formats;
1498+
runtime->hw.formats = formats & stream->formats;
14981499
runtime->hw.rates = stream->rates;
14991500
}
15001501

1502+
static u64 dpcm_runtime_base_format(struct snd_pcm_substream *substream)
1503+
{
1504+
struct snd_soc_pcm_runtime *fe = substream->private_data;
1505+
struct snd_soc_dpcm *dpcm;
1506+
u64 formats = ULLONG_MAX;
1507+
int stream = substream->stream;
1508+
1509+
if (!fe->dai_link->dpcm_merged_format)
1510+
return formats;
1511+
1512+
/*
1513+
* It returns merged BE codec format
1514+
* if FE want to use it (= dpcm_merged_format)
1515+
*/
1516+
1517+
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
1518+
struct snd_soc_pcm_runtime *be = dpcm->be;
1519+
struct snd_soc_dai_driver *codec_dai_drv;
1520+
struct snd_soc_pcm_stream *codec_stream;
1521+
int i;
1522+
1523+
for (i = 0; i < be->num_codecs; i++) {
1524+
codec_dai_drv = be->codec_dais[i]->driver;
1525+
if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1526+
codec_stream = &codec_dai_drv->playback;
1527+
else
1528+
codec_stream = &codec_dai_drv->capture;
1529+
1530+
formats &= codec_stream->formats;
1531+
}
1532+
}
1533+
1534+
return formats;
1535+
}
1536+
15011537
static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
15021538
{
15031539
struct snd_pcm_runtime *runtime = substream->runtime;
15041540
struct snd_soc_pcm_runtime *rtd = substream->private_data;
15051541
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
15061542
struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
1543+
u64 format = dpcm_runtime_base_format(substream);
15071544

15081545
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1509-
dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback);
1546+
dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback, format);
15101547
else
1511-
dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture);
1548+
dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture, format);
15121549
}
15131550

15141551
static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd);

0 commit comments

Comments
 (0)