Commit 2e5894d7 authored by Benoit Cousson's avatar Benoit Cousson Committed by Mark Brown

ASoC: pcm: Add support for DAI multicodec

Add multicodec support in soc-pcm.c
Signed-off-by: default avatarBenoit Cousson <bcousson@baylibre.com>
Signed-off-by: default avatarMisael Lopez Cruz <misael.lopez@ti.com>
Signed-off-by: default avatarFabien Parent <fparent@baylibre.com>
Tested-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Reviewed-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 88bd870f
...@@ -47,22 +47,26 @@ ...@@ -47,22 +47,26 @@
void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream)
{ {
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; int i;
lockdep_assert_held(&rtd->pcm_mutex); lockdep_assert_held(&rtd->pcm_mutex);
if (stream == SNDRV_PCM_STREAM_PLAYBACK) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
cpu_dai->playback_active++; cpu_dai->playback_active++;
codec_dai->playback_active++; for (i = 0; i < rtd->num_codecs; i++)
rtd->codec_dais[i]->playback_active++;
} else { } else {
cpu_dai->capture_active++; cpu_dai->capture_active++;
codec_dai->capture_active++; for (i = 0; i < rtd->num_codecs; i++)
rtd->codec_dais[i]->capture_active++;
} }
cpu_dai->active++; cpu_dai->active++;
codec_dai->active++;
cpu_dai->component->active++; cpu_dai->component->active++;
codec_dai->component->active++; for (i = 0; i < rtd->num_codecs; i++) {
rtd->codec_dais[i]->active++;
rtd->codec_dais[i]->component->active++;
}
} }
/** /**
...@@ -78,22 +82,26 @@ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) ...@@ -78,22 +82,26 @@ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream)
void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)
{ {
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; int i;
lockdep_assert_held(&rtd->pcm_mutex); lockdep_assert_held(&rtd->pcm_mutex);
if (stream == SNDRV_PCM_STREAM_PLAYBACK) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
cpu_dai->playback_active--; cpu_dai->playback_active--;
codec_dai->playback_active--; for (i = 0; i < rtd->num_codecs; i++)
rtd->codec_dais[i]->playback_active--;
} else { } else {
cpu_dai->capture_active--; cpu_dai->capture_active--;
codec_dai->capture_active--; for (i = 0; i < rtd->num_codecs; i++)
rtd->codec_dais[i]->capture_active--;
} }
cpu_dai->active--; cpu_dai->active--;
codec_dai->active--;
cpu_dai->component->active--; cpu_dai->component->active--;
codec_dai->component->active--; for (i = 0; i < rtd->num_codecs; i++) {
rtd->codec_dais[i]->component->active--;
rtd->codec_dais[i]->active--;
}
} }
/** /**
...@@ -107,11 +115,16 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) ...@@ -107,11 +115,16 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)
*/ */
bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd) bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd)
{ {
int i;
bool ignore = true;
if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time) if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
return true; return true;
return rtd->cpu_dai->component->ignore_pmdown_time && for (i = 0; i < rtd->num_codecs; i++)
rtd->codec_dai->component->ignore_pmdown_time; ignore &= rtd->codec_dais[i]->component->ignore_pmdown_time;
return rtd->cpu_dai->component->ignore_pmdown_time && ignore;
} }
/** /**
...@@ -222,8 +235,7 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, ...@@ -222,8 +235,7 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; unsigned int rate, channels, sample_bits, symmetry, i;
unsigned int rate, channels, sample_bits, symmetry;
rate = params_rate(params); rate = params_rate(params);
channels = params_channels(params); channels = params_channels(params);
...@@ -231,8 +243,11 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, ...@@ -231,8 +243,11 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
/* reject unmatched parameters when applying symmetry */ /* reject unmatched parameters when applying symmetry */
symmetry = cpu_dai->driver->symmetric_rates || symmetry = cpu_dai->driver->symmetric_rates ||
codec_dai->driver->symmetric_rates ||
rtd->dai_link->symmetric_rates; rtd->dai_link->symmetric_rates;
for (i = 0; i < rtd->num_codecs; i++)
symmetry |= rtd->codec_dais[i]->driver->symmetric_rates;
if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) { if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) {
dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n", dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n",
cpu_dai->rate, rate); cpu_dai->rate, rate);
...@@ -240,8 +255,11 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, ...@@ -240,8 +255,11 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
} }
symmetry = cpu_dai->driver->symmetric_channels || symmetry = cpu_dai->driver->symmetric_channels ||
codec_dai->driver->symmetric_channels ||
rtd->dai_link->symmetric_channels; rtd->dai_link->symmetric_channels;
for (i = 0; i < rtd->num_codecs; i++)
symmetry |= rtd->codec_dais[i]->driver->symmetric_channels;
if (symmetry && cpu_dai->channels && cpu_dai->channels != channels) { if (symmetry && cpu_dai->channels && cpu_dai->channels != channels) {
dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n", dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n",
cpu_dai->channels, channels); cpu_dai->channels, channels);
...@@ -249,8 +267,11 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, ...@@ -249,8 +267,11 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
} }
symmetry = cpu_dai->driver->symmetric_samplebits || symmetry = cpu_dai->driver->symmetric_samplebits ||
codec_dai->driver->symmetric_samplebits ||
rtd->dai_link->symmetric_samplebits; rtd->dai_link->symmetric_samplebits;
for (i = 0; i < rtd->num_codecs; i++)
symmetry |= rtd->codec_dais[i]->driver->symmetric_samplebits;
if (symmetry && cpu_dai->sample_bits && cpu_dai->sample_bits != sample_bits) { if (symmetry && cpu_dai->sample_bits && cpu_dai->sample_bits != sample_bits) {
dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n", dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n",
cpu_dai->sample_bits, sample_bits); cpu_dai->sample_bits, sample_bits);
...@@ -264,15 +285,20 @@ static bool soc_pcm_has_symmetry(struct snd_pcm_substream *substream) ...@@ -264,15 +285,20 @@ static bool soc_pcm_has_symmetry(struct snd_pcm_substream *substream)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai_driver *cpu_driver = rtd->cpu_dai->driver; struct snd_soc_dai_driver *cpu_driver = rtd->cpu_dai->driver;
struct snd_soc_dai_driver *codec_driver = rtd->codec_dai->driver;
struct snd_soc_dai_link *link = rtd->dai_link; struct snd_soc_dai_link *link = rtd->dai_link;
unsigned int symmetry, i;
symmetry = cpu_driver->symmetric_rates || link->symmetric_rates ||
cpu_driver->symmetric_channels || link->symmetric_channels ||
cpu_driver->symmetric_samplebits || link->symmetric_samplebits;
return cpu_driver->symmetric_rates || codec_driver->symmetric_rates || for (i = 0; i < rtd->num_codecs; i++)
link->symmetric_rates || cpu_driver->symmetric_channels || symmetry = symmetry ||
codec_driver->symmetric_channels || link->symmetric_channels || rtd->codec_dais[i]->driver->symmetric_rates ||
cpu_driver->symmetric_samplebits || rtd->codec_dais[i]->driver->symmetric_channels ||
codec_driver->symmetric_samplebits || rtd->codec_dais[i]->driver->symmetric_samplebits;
link->symmetric_samplebits;
return symmetry;
} }
/* /*
...@@ -284,9 +310,9 @@ static int sample_sizes[] = { ...@@ -284,9 +310,9 @@ static int sample_sizes[] = {
24, 32, 24, 32,
}; };
static void soc_pcm_set_msb(struct snd_pcm_substream *substream, static void soc_pcm_set_msb(struct snd_pcm_substream *substream, int bits)
struct snd_soc_dai *dai, int bits)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data;
int ret, i; int ret, i;
if (!bits) if (!bits)
...@@ -299,7 +325,7 @@ static void soc_pcm_set_msb(struct snd_pcm_substream *substream, ...@@ -299,7 +325,7 @@ static void soc_pcm_set_msb(struct snd_pcm_substream *substream,
ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0, ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0,
sample_sizes[i], bits); sample_sizes[i], bits);
if (ret != 0) if (ret != 0)
dev_warn(dai->dev, dev_warn(rtd->dev,
"ASoC: Failed to set MSB %d/%d: %d\n", "ASoC: Failed to set MSB %d/%d: %d\n",
bits, sample_sizes[i], ret); bits, sample_sizes[i], ret);
} }
...@@ -309,47 +335,95 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream) ...@@ -309,47 +335,95 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
int i;
unsigned int bits = 0, cpu_bits; unsigned int bits = 0, cpu_bits;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
bits = codec_dai->driver->playback.sig_bits; for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->playback.sig_bits == 0) {
bits = 0;
break;
}
bits = max(codec_dai->driver->playback.sig_bits, bits);
}
cpu_bits = cpu_dai->driver->playback.sig_bits; cpu_bits = cpu_dai->driver->playback.sig_bits;
} else { } else {
bits = codec_dai->driver->capture.sig_bits; for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->playback.sig_bits == 0) {
bits = 0;
break;
}
bits = max(codec_dai->driver->capture.sig_bits, bits);
}
cpu_bits = cpu_dai->driver->capture.sig_bits; cpu_bits = cpu_dai->driver->capture.sig_bits;
} }
soc_pcm_set_msb(substream, codec_dai, bits); soc_pcm_set_msb(substream, bits);
soc_pcm_set_msb(substream, cpu_dai, cpu_bits); soc_pcm_set_msb(substream, cpu_bits);
} }
static void soc_pcm_init_runtime_hw(struct snd_pcm_runtime *runtime, static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)
struct snd_soc_pcm_stream *codec_stream,
struct snd_soc_pcm_stream *cpu_stream)
{ {
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_pcm_hardware *hw = &runtime->hw; struct snd_pcm_hardware *hw = &runtime->hw;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai_driver *cpu_dai_drv = rtd->cpu_dai->driver;
struct snd_soc_dai_driver *codec_dai_drv;
struct snd_soc_pcm_stream *codec_stream;
struct snd_soc_pcm_stream *cpu_stream;
unsigned int chan_min = 0, chan_max = UINT_MAX;
unsigned int rate_min = 0, rate_max = UINT_MAX;
unsigned int rates = UINT_MAX;
u64 formats = ULLONG_MAX;
int i;
hw->channels_min = max(codec_stream->channels_min, if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
cpu_stream->channels_min); cpu_stream = &cpu_dai_drv->playback;
hw->channels_max = min(codec_stream->channels_max,
cpu_stream->channels_max);
if (hw->formats)
hw->formats &= codec_stream->formats & cpu_stream->formats;
else else
hw->formats = codec_stream->formats & cpu_stream->formats; cpu_stream = &cpu_dai_drv->capture;
hw->rates = snd_pcm_rate_mask_intersect(codec_stream->rates,
cpu_stream->rates);
hw->rate_min = 0; /* first calculate min/max only for CODECs in the DAI link */
hw->rate_max = UINT_MAX; for (i = 0; i < rtd->num_codecs; i++) {
codec_dai_drv = rtd->codec_dais[i]->driver;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
codec_stream = &codec_dai_drv->playback;
else
codec_stream = &codec_dai_drv->capture;
chan_min = max(chan_min, codec_stream->channels_min);
chan_max = min(chan_max, codec_stream->channels_max);
rate_min = max(rate_min, codec_stream->rate_min);
rate_max = min_not_zero(rate_max, codec_stream->rate_max);
formats &= codec_stream->formats;
rates = snd_pcm_rate_mask_intersect(codec_stream->rates, rates);
}
/*
* chan min/max cannot be enforced if there are multiple CODEC DAIs
* connected to a single CPU DAI, use CPU DAI's directly and let
* channel allocation be fixed up later
*/
if (rtd->num_codecs > 1) {
chan_min = cpu_stream->channels_min;
chan_max = cpu_stream->channels_max;
}
hw->channels_min = max(chan_min, cpu_stream->channels_min);
hw->channels_max = min(chan_max, cpu_stream->channels_max);
if (hw->formats)
hw->formats &= formats & cpu_stream->formats;
else
hw->formats = formats & cpu_stream->formats;
hw->rates = snd_pcm_rate_mask_intersect(rates, cpu_stream->rates);
snd_pcm_limit_hw_rates(runtime); snd_pcm_limit_hw_rates(runtime);
hw->rate_min = max(hw->rate_min, cpu_stream->rate_min); hw->rate_min = max(hw->rate_min, cpu_stream->rate_min);
hw->rate_min = max(hw->rate_min, codec_stream->rate_min); hw->rate_min = max(hw->rate_min, rate_min);
hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max); hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max);
hw->rate_max = min_not_zero(hw->rate_max, codec_stream->rate_max); hw->rate_max = min_not_zero(hw->rate_max, rate_max);
} }
/* /*
...@@ -363,15 +437,16 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ...@@ -363,15 +437,16 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver; const char *codec_dai_name = "multicodec";
struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver; int i, ret = 0;
int ret = 0;
pinctrl_pm_select_default_state(cpu_dai->dev); pinctrl_pm_select_default_state(cpu_dai->dev);
pinctrl_pm_select_default_state(codec_dai->dev); for (i = 0; i < rtd->num_codecs; i++)
pinctrl_pm_select_default_state(rtd->codec_dais[i]->dev);
pm_runtime_get_sync(cpu_dai->dev); pm_runtime_get_sync(cpu_dai->dev);
pm_runtime_get_sync(codec_dai->dev); for (i = 0; i < rtd->num_codecs; i++)
pm_runtime_get_sync(rtd->codec_dais[i]->dev);
pm_runtime_get_sync(platform->dev); pm_runtime_get_sync(platform->dev);
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
...@@ -395,15 +470,25 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ...@@ -395,15 +470,25 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
} }
} }
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops && codec_dai->driver->ops->startup) { if (codec_dai->driver->ops && codec_dai->driver->ops->startup) {
ret = codec_dai->driver->ops->startup(substream, codec_dai); ret = codec_dai->driver->ops->startup(substream,
codec_dai);
if (ret < 0) { if (ret < 0) {
dev_err(codec_dai->dev, "ASoC: can't open codec" dev_err(codec_dai->dev,
" %s: %d\n", codec_dai->name, ret); "ASoC: can't open codec %s: %d\n",
codec_dai->name, ret);
goto codec_dai_err; goto codec_dai_err;
} }
} }
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
codec_dai->tx_mask = 0;
else
codec_dai->rx_mask = 0;
}
if (rtd->dai_link->ops && rtd->dai_link->ops->startup) { if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
ret = rtd->dai_link->ops->startup(substream); ret = rtd->dai_link->ops->startup(substream);
if (ret < 0) { if (ret < 0) {
...@@ -418,13 +503,10 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ...@@ -418,13 +503,10 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
goto dynamic; goto dynamic;
/* Check that the codec and cpu DAIs are compatible */ /* Check that the codec and cpu DAIs are compatible */
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { soc_pcm_init_runtime_hw(substream);
soc_pcm_init_runtime_hw(runtime, &codec_dai_drv->playback,
&cpu_dai_drv->playback); if (rtd->num_codecs == 1)
} else { codec_dai_name = rtd->codec_dai->name;
soc_pcm_init_runtime_hw(runtime, &codec_dai_drv->capture,
&cpu_dai_drv->capture);
}
if (soc_pcm_has_symmetry(substream)) if (soc_pcm_has_symmetry(substream))
runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
...@@ -432,18 +514,18 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ...@@ -432,18 +514,18 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
ret = -EINVAL; ret = -EINVAL;
if (!runtime->hw.rates) { if (!runtime->hw.rates) {
printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n", printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n",
codec_dai->name, cpu_dai->name); codec_dai_name, cpu_dai->name);
goto config_err; goto config_err;
} }
if (!runtime->hw.formats) { if (!runtime->hw.formats) {
printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n", printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n",
codec_dai->name, cpu_dai->name); codec_dai_name, cpu_dai->name);
goto config_err; goto config_err;
} }
if (!runtime->hw.channels_min || !runtime->hw.channels_max || if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
runtime->hw.channels_min > runtime->hw.channels_max) { runtime->hw.channels_min > runtime->hw.channels_max) {
printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n", printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n",
codec_dai->name, cpu_dai->name); codec_dai_name, cpu_dai->name);
goto config_err; goto config_err;
} }
...@@ -456,14 +538,17 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ...@@ -456,14 +538,17 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
goto config_err; goto config_err;
} }
if (codec_dai->active) { for (i = 0; i < rtd->num_codecs; i++) {
ret = soc_pcm_apply_symmetry(substream, codec_dai); if (rtd->codec_dais[i]->active) {
ret = soc_pcm_apply_symmetry(substream,
rtd->codec_dais[i]);
if (ret != 0) if (ret != 0)
goto config_err; goto config_err;
} }
}
pr_debug("ASoC: %s <-> %s info:\n", pr_debug("ASoC: %s <-> %s info:\n",
codec_dai->name, cpu_dai->name); codec_dai_name, cpu_dai->name);
pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates); pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates);
pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min, pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min,
runtime->hw.channels_max); runtime->hw.channels_max);
...@@ -482,10 +567,15 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ...@@ -482,10 +567,15 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
rtd->dai_link->ops->shutdown(substream); rtd->dai_link->ops->shutdown(substream);
machine_err: machine_err:
i = rtd->num_codecs;
codec_dai_err:
while (--i >= 0) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops->shutdown) if (codec_dai->driver->ops->shutdown)
codec_dai->driver->ops->shutdown(substream, codec_dai); codec_dai->driver->ops->shutdown(substream, codec_dai);
}
codec_dai_err:
if (platform->driver->ops && platform->driver->ops->close) if (platform->driver->ops && platform->driver->ops->close)
platform->driver->ops->close(substream); platform->driver->ops->close(substream);
...@@ -496,10 +586,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ...@@ -496,10 +586,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
mutex_unlock(&rtd->pcm_mutex); mutex_unlock(&rtd->pcm_mutex);
pm_runtime_put(platform->dev); pm_runtime_put(platform->dev);
pm_runtime_put(codec_dai->dev); for (i = 0; i < rtd->num_codecs; i++)
pm_runtime_put(rtd->codec_dais[i]->dev);
pm_runtime_put(cpu_dai->dev); pm_runtime_put(cpu_dai->dev);
if (!codec_dai->active) for (i = 0; i < rtd->num_codecs; i++) {
pinctrl_pm_select_sleep_state(codec_dai->dev); if (!rtd->codec_dais[i]->active)
pinctrl_pm_select_sleep_state(rtd->codec_dais[i]->dev);
}
if (!cpu_dai->active) if (!cpu_dai->active)
pinctrl_pm_select_sleep_state(cpu_dai->dev); pinctrl_pm_select_sleep_state(cpu_dai->dev);
...@@ -515,7 +608,7 @@ static void close_delayed_work(struct work_struct *work) ...@@ -515,7 +608,7 @@ static void close_delayed_work(struct work_struct *work)
{ {
struct snd_soc_pcm_runtime *rtd = struct snd_soc_pcm_runtime *rtd =
container_of(work, struct snd_soc_pcm_runtime, delayed_work.work); container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai = rtd->codec_dais[0];
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
...@@ -544,7 +637,8 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) ...@@ -544,7 +637,8 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
int i;
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
...@@ -554,14 +648,20 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) ...@@ -554,14 +648,20 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
if (!cpu_dai->active) if (!cpu_dai->active)
cpu_dai->rate = 0; cpu_dai->rate = 0;
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (!codec_dai->active) if (!codec_dai->active)
codec_dai->rate = 0; codec_dai->rate = 0;
}
if (cpu_dai->driver->ops->shutdown) if (cpu_dai->driver->ops->shutdown)
cpu_dai->driver->ops->shutdown(substream, cpu_dai); cpu_dai->driver->ops->shutdown(substream, cpu_dai);
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops->shutdown) if (codec_dai->driver->ops->shutdown)
codec_dai->driver->ops->shutdown(substream, codec_dai); codec_dai->driver->ops->shutdown(substream, codec_dai);
}
if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown) if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
rtd->dai_link->ops->shutdown(substream); rtd->dai_link->ops->shutdown(substream);
...@@ -591,10 +691,13 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) ...@@ -591,10 +691,13 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
mutex_unlock(&rtd->pcm_mutex); mutex_unlock(&rtd->pcm_mutex);
pm_runtime_put(platform->dev); pm_runtime_put(platform->dev);
pm_runtime_put(codec_dai->dev); for (i = 0; i < rtd->num_codecs; i++)
pm_runtime_put(rtd->codec_dais[i]->dev);
pm_runtime_put(cpu_dai->dev); pm_runtime_put(cpu_dai->dev);
if (!codec_dai->active) for (i = 0; i < rtd->num_codecs; i++) {
pinctrl_pm_select_sleep_state(codec_dai->dev); if (!rtd->codec_dais[i]->active)
pinctrl_pm_select_sleep_state(rtd->codec_dais[i]->dev);
}
if (!cpu_dai->active) if (!cpu_dai->active)
pinctrl_pm_select_sleep_state(cpu_dai->dev); pinctrl_pm_select_sleep_state(cpu_dai->dev);
...@@ -611,8 +714,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) ...@@ -611,8 +714,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
int ret = 0; int i, ret = 0;
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
...@@ -634,14 +737,18 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) ...@@ -634,14 +737,18 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
} }
} }
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops && codec_dai->driver->ops->prepare) { if (codec_dai->driver->ops && codec_dai->driver->ops->prepare) {
ret = codec_dai->driver->ops->prepare(substream, codec_dai); ret = codec_dai->driver->ops->prepare(substream,
codec_dai);
if (ret < 0) { if (ret < 0) {
dev_err(codec_dai->dev, "ASoC: DAI prepare error: %d\n", dev_err(codec_dai->dev,
ret); "ASoC: DAI prepare error: %d\n", ret);
goto out; goto out;
} }
} }
}
if (cpu_dai->driver->ops && cpu_dai->driver->ops->prepare) { if (cpu_dai->driver->ops && cpu_dai->driver->ops->prepare) {
ret = cpu_dai->driver->ops->prepare(substream, cpu_dai); ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
...@@ -662,13 +769,26 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) ...@@ -662,13 +769,26 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
snd_soc_dapm_stream_event(rtd, substream->stream, snd_soc_dapm_stream_event(rtd, substream->stream,
SND_SOC_DAPM_STREAM_START); SND_SOC_DAPM_STREAM_START);
snd_soc_dai_digital_mute(codec_dai, 0, substream->stream); for (i = 0; i < rtd->num_codecs; i++)
snd_soc_dai_digital_mute(rtd->codec_dais[i], 0,
substream->stream);
out: out:
mutex_unlock(&rtd->pcm_mutex); mutex_unlock(&rtd->pcm_mutex);
return ret; return ret;
} }
static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params,
unsigned int mask)
{
struct snd_interval *interval;
int channels = hweight_long(mask);
interval = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
interval->min = channels;
interval->max = channels;
}
/* /*
* Called by ALSA when the hardware params are set by application. This * Called by ALSA when the hardware params are set by application. This
* function can also be called multiple times and can allocate buffers * function can also be called multiple times and can allocate buffers
...@@ -680,8 +800,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, ...@@ -680,8 +800,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; int i, ret = 0;
int ret = 0;
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
...@@ -698,15 +817,39 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, ...@@ -698,15 +817,39 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
} }
} }
if (codec_dai->driver->ops && codec_dai->driver->ops->hw_params) { for (i = 0; i < rtd->num_codecs; i++) {
ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai); struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
struct snd_pcm_hw_params codec_params;
/* copy params for each codec */
codec_params = *params;
/* fixup params based on TDM slot masks */
if (codec_dai->tx_mask)
soc_pcm_codec_params_fixup(&codec_params,
codec_dai->tx_mask);
if (codec_dai->rx_mask)
soc_pcm_codec_params_fixup(&codec_params,
codec_dai->rx_mask);
if (codec_dai->driver->ops &&
codec_dai->driver->ops->hw_params) {
ret = codec_dai->driver->ops->hw_params(substream,
&codec_params, codec_dai);
if (ret < 0) { if (ret < 0) {
dev_err(codec_dai->dev, "ASoC: can't set %s hw params:" dev_err(codec_dai->dev,
" %d\n", codec_dai->name, ret); "ASoC: can't set %s hw params: %d\n",
codec_dai->name, ret);
goto codec_err; goto codec_err;
} }
} }
codec_dai->rate = params_rate(&codec_params);
codec_dai->channels = params_channels(&codec_params);
codec_dai->sample_bits = snd_pcm_format_physical_width(
params_format(&codec_params));
}
if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_params) { if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_params) {
ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai); ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
if (ret < 0) { if (ret < 0) {
...@@ -731,11 +874,6 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, ...@@ -731,11 +874,6 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
cpu_dai->sample_bits = cpu_dai->sample_bits =
snd_pcm_format_physical_width(params_format(params)); snd_pcm_format_physical_width(params_format(params));
codec_dai->rate = params_rate(params);
codec_dai->channels = params_channels(params);
codec_dai->sample_bits =
snd_pcm_format_physical_width(params_format(params));
out: out:
mutex_unlock(&rtd->pcm_mutex); mutex_unlock(&rtd->pcm_mutex);
return ret; return ret;
...@@ -745,10 +883,16 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, ...@@ -745,10 +883,16 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
cpu_dai->driver->ops->hw_free(substream, cpu_dai); cpu_dai->driver->ops->hw_free(substream, cpu_dai);
interface_err: interface_err:
i = rtd->num_codecs;
codec_err:
while (--i >= 0) {
struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free) if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
codec_dai->driver->ops->hw_free(substream, codec_dai); codec_dai->driver->ops->hw_free(substream, codec_dai);
codec_dai->rate = 0;
}
codec_err:
if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free) if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
rtd->dai_link->ops->hw_free(substream); rtd->dai_link->ops->hw_free(substream);
...@@ -764,8 +908,9 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) ...@@ -764,8 +908,9 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
int i;
mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
...@@ -776,16 +921,22 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) ...@@ -776,16 +921,22 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
cpu_dai->sample_bits = 0; cpu_dai->sample_bits = 0;
} }
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->active == 1) { if (codec_dai->active == 1) {
codec_dai->rate = 0; codec_dai->rate = 0;
codec_dai->channels = 0; codec_dai->channels = 0;
codec_dai->sample_bits = 0; codec_dai->sample_bits = 0;
} }
}
/* apply codec digital mute */ /* apply codec digital mute */
if ((playback && codec_dai->playback_active == 1) || for (i = 0; i < rtd->num_codecs; i++) {
(!playback && codec_dai->capture_active == 1)) if ((playback && rtd->codec_dais[i]->playback_active == 1) ||
snd_soc_dai_digital_mute(codec_dai, 1, substream->stream); (!playback && rtd->codec_dais[i]->capture_active == 1))
snd_soc_dai_digital_mute(rtd->codec_dais[i], 1,
substream->stream);
}
/* free any machine hw params */ /* free any machine hw params */
if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free) if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
...@@ -796,8 +947,11 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) ...@@ -796,8 +947,11 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
platform->driver->ops->hw_free(substream); platform->driver->ops->hw_free(substream);
/* now free hw params for the DAIs */ /* now free hw params for the DAIs */
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free) if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
codec_dai->driver->ops->hw_free(substream, codec_dai); codec_dai->driver->ops->hw_free(substream, codec_dai);
}
if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free) if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
cpu_dai->driver->ops->hw_free(substream, cpu_dai); cpu_dai->driver->ops->hw_free(substream, cpu_dai);
...@@ -811,14 +965,18 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) ...@@ -811,14 +965,18 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
int ret; int i, ret;
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops && codec_dai->driver->ops->trigger) { if (codec_dai->driver->ops && codec_dai->driver->ops->trigger) {
ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai); ret = codec_dai->driver->ops->trigger(substream,
cmd, codec_dai);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
}
if (platform->driver->ops && platform->driver->ops->trigger) { if (platform->driver->ops && platform->driver->ops->trigger) {
ret = platform->driver->ops->trigger(substream, cmd); ret = platform->driver->ops->trigger(substream, cmd);
...@@ -847,15 +1005,19 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream, ...@@ -847,15 +1005,19 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
int ret; int i, ret;
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops && if (codec_dai->driver->ops &&
codec_dai->driver->ops->bespoke_trigger) { codec_dai->driver->ops->bespoke_trigger) {
ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai); ret = codec_dai->driver->ops->bespoke_trigger(substream,
cmd, codec_dai);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
}
if (platform->driver->bespoke_trigger) { if (platform->driver->bespoke_trigger) {
ret = platform->driver->bespoke_trigger(substream, cmd); ret = platform->driver->bespoke_trigger(substream, cmd);
...@@ -880,10 +1042,12 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) ...@@ -880,10 +1042,12 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_uframes_t offset = 0; snd_pcm_uframes_t offset = 0;
snd_pcm_sframes_t delay = 0; snd_pcm_sframes_t delay = 0;
snd_pcm_sframes_t codec_delay = 0;
int i;
if (platform->driver->ops && platform->driver->ops->pointer) if (platform->driver->ops && platform->driver->ops->pointer)
offset = platform->driver->ops->pointer(substream); offset = platform->driver->ops->pointer(substream);
...@@ -891,11 +1055,21 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) ...@@ -891,11 +1055,21 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
if (cpu_dai->driver->ops && cpu_dai->driver->ops->delay) if (cpu_dai->driver->ops && cpu_dai->driver->ops->delay)
delay += cpu_dai->driver->ops->delay(substream, cpu_dai); delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->ops && codec_dai->driver->ops->delay) if (codec_dai->driver->ops && codec_dai->driver->ops->delay)
delay += codec_dai->driver->ops->delay(substream, codec_dai); codec_delay = max(codec_delay,
codec_dai->driver->ops->delay(substream,
codec_dai));
}
delay += codec_delay;
/*
* None of the existing platform drivers implement delay(), so
* for now the codec_dai of first multicodec entry is used
*/
if (platform->driver->delay) if (platform->driver->delay)
delay += platform->driver->delay(substream, codec_dai); delay += platform->driver->delay(substream, rtd->codec_dais[0]);
runtime->delay = delay; runtime->delay = delay;
...@@ -998,7 +1172,7 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, ...@@ -998,7 +1172,7 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
struct snd_soc_dapm_widget *widget, int stream) struct snd_soc_dapm_widget *widget, int stream)
{ {
struct snd_soc_pcm_runtime *be; struct snd_soc_pcm_runtime *be;
int i; int i, j;
if (stream == SNDRV_PCM_STREAM_PLAYBACK) { if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
for (i = 0; i < card->num_links; i++) { for (i = 0; i < card->num_links; i++) {
...@@ -1007,10 +1181,15 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, ...@@ -1007,10 +1181,15 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
if (!be->dai_link->no_pcm) if (!be->dai_link->no_pcm)
continue; continue;
if (be->cpu_dai->playback_widget == widget || if (be->cpu_dai->playback_widget == widget)
be->codec_dai->playback_widget == widget) return be;
for (j = 0; j < be->num_codecs; j++) {
struct snd_soc_dai *dai = be->codec_dais[j];
if (dai->playback_widget == widget)
return be; return be;
} }
}
} else { } else {
for (i = 0; i < card->num_links; i++) { for (i = 0; i < card->num_links; i++) {
...@@ -1019,11 +1198,16 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, ...@@ -1019,11 +1198,16 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
if (!be->dai_link->no_pcm) if (!be->dai_link->no_pcm)
continue; continue;
if (be->cpu_dai->capture_widget == widget || if (be->cpu_dai->capture_widget == widget)
be->codec_dai->capture_widget == widget) return be;
for (j = 0; j < be->num_codecs; j++) {
struct snd_soc_dai *dai = be->codec_dais[j];
if (dai->capture_widget == widget)
return be; return be;
} }
} }
}
dev_err(card->dev, "ASoC: can't get %s BE for %s\n", dev_err(card->dev, "ASoC: can't get %s BE for %s\n",
stream ? "capture" : "playback", widget->name); stream ? "capture" : "playback", widget->name);
...@@ -1084,6 +1268,7 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream, ...@@ -1084,6 +1268,7 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
/* Destroy any old FE <--> BE connections */ /* Destroy any old FE <--> BE connections */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) { list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
unsigned int i;
/* is there a valid CPU DAI widget for this BE */ /* is there a valid CPU DAI widget for this BE */
widget = dai_get_widget(dpcm->be->cpu_dai, stream); widget = dai_get_widget(dpcm->be->cpu_dai, stream);
...@@ -1093,11 +1278,14 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream, ...@@ -1093,11 +1278,14 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
continue; continue;
/* is there a valid CODEC DAI widget for this BE */ /* is there a valid CODEC DAI widget for this BE */
widget = dai_get_widget(dpcm->be->codec_dai, stream); for (i = 0; i < dpcm->be->num_codecs; i++) {
struct snd_soc_dai *dai = dpcm->be->codec_dais[i];
widget = dai_get_widget(dai, stream);
/* prune the BE if it's no longer in our active list */ /* prune the BE if it's no longer in our active list */
if (widget && widget_in_list(list, widget)) if (widget && widget_in_list(list, widget))
continue; continue;
}
dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n", dev_dbg(fe->dev, "ASoC: pruning %s BE %s for %s\n",
stream ? "capture" : "playback", stream ? "capture" : "playback",
...@@ -2126,17 +2314,23 @@ int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute) ...@@ -2126,17 +2314,23 @@ int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
list_for_each_entry(dpcm, clients, list_be) { list_for_each_entry(dpcm, clients, list_be) {
struct snd_soc_pcm_runtime *be = dpcm->be; struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_soc_dai *dai = be->codec_dai; int i;
struct snd_soc_dai_driver *drv = dai->driver;
if (be->dai_link->ignore_suspend) if (be->dai_link->ignore_suspend)
continue; continue;
dev_dbg(be->dev, "ASoC: BE digital mute %s\n", be->dai_link->name); for (i = 0; i < be->num_codecs; i++) {
struct snd_soc_dai *dai = be->codec_dais[i];
struct snd_soc_dai_driver *drv = dai->driver;
dev_dbg(be->dev, "ASoC: BE digital mute %s\n",
be->dai_link->name);
if (drv->ops && drv->ops->digital_mute && dai->playback_active) if (drv->ops && drv->ops->digital_mute &&
dai->playback_active)
drv->ops->digital_mute(dai, mute); drv->ops->digital_mute(dai, mute);
} }
}
return 0; return 0;
} }
...@@ -2200,24 +2394,29 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream) ...@@ -2200,24 +2394,29 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
{ {
struct snd_soc_platform *platform = rtd->platform; struct snd_soc_platform *platform = rtd->platform;
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct snd_pcm *pcm; struct snd_pcm *pcm;
char new_name[64]; char new_name[64];
int ret = 0, playback = 0, capture = 0; int ret = 0, playback = 0, capture = 0;
int i;
if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) { if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) {
playback = rtd->dai_link->dpcm_playback; playback = rtd->dai_link->dpcm_playback;
capture = rtd->dai_link->dpcm_capture; capture = rtd->dai_link->dpcm_capture;
} else { } else {
if (codec_dai->driver->playback.channels_min && for (i = 0; i < rtd->num_codecs; i++) {
cpu_dai->driver->playback.channels_min) codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->playback.channels_min)
playback = 1; playback = 1;
if (codec_dai->driver->capture.channels_min && if (codec_dai->driver->capture.channels_min)
cpu_dai->driver->capture.channels_min)
capture = 1; capture = 1;
} }
capture = capture && cpu_dai->driver->capture.channels_min;
playback = playback && cpu_dai->driver->playback.channels_min;
}
if (rtd->dai_link->playback_only) { if (rtd->dai_link->playback_only) {
playback = 1; playback = 1;
capture = 0; capture = 0;
...@@ -2241,7 +2440,9 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) ...@@ -2241,7 +2440,9 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
rtd->dai_link->stream_name); rtd->dai_link->stream_name);
else else
snprintf(new_name, sizeof(new_name), "%s %s-%d", snprintf(new_name, sizeof(new_name), "%s %s-%d",
rtd->dai_link->stream_name, codec_dai->name, num); rtd->dai_link->stream_name,
(rtd->num_codecs > 1) ?
"multicodec" : rtd->codec_dai->name, num);
ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback, ret = snd_pcm_new(rtd->card->snd_card, new_name, num, playback,
capture, &pcm); capture, &pcm);
...@@ -2314,7 +2515,8 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) ...@@ -2314,7 +2515,8 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
pcm->private_free = platform->driver->pcm_free; pcm->private_free = platform->driver->pcm_free;
out: out:
dev_info(rtd->card->dev, "%s <-> %s mapping ok\n", codec_dai->name, dev_info(rtd->card->dev, "%s <-> %s mapping ok\n",
(rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name,
cpu_dai->name); cpu_dai->name);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment