summaryrefslogtreecommitdiff
path: root/sound/soc/soc-dapm.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/soc-dapm.c')
-rw-r--r--sound/soc/soc-dapm.c324
1 files changed, 171 insertions, 153 deletions
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 5d9a671e50f1..f2f04ce693a1 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -99,58 +99,58 @@ static int dapm_up_seq[] = {
[snd_soc_dapm_adc] = 11,
[snd_soc_dapm_out_drv] = 12,
[snd_soc_dapm_hp] = 12,
- [snd_soc_dapm_spk] = 12,
[snd_soc_dapm_line] = 12,
[snd_soc_dapm_sink] = 12,
- [snd_soc_dapm_kcontrol] = 13,
- [snd_soc_dapm_post] = 14,
+ [snd_soc_dapm_spk] = 13,
+ [snd_soc_dapm_kcontrol] = 14,
+ [snd_soc_dapm_post] = 15,
};
static int dapm_down_seq[] = {
[snd_soc_dapm_pre] = 1,
[snd_soc_dapm_kcontrol] = 2,
[snd_soc_dapm_adc] = 3,
- [snd_soc_dapm_hp] = 4,
[snd_soc_dapm_spk] = 4,
- [snd_soc_dapm_line] = 4,
- [snd_soc_dapm_out_drv] = 4,
- [snd_soc_dapm_sink] = 4,
- [snd_soc_dapm_pga] = 5,
- [snd_soc_dapm_buffer] = 5,
- [snd_soc_dapm_scheduler] = 5,
- [snd_soc_dapm_effect] = 5,
- [snd_soc_dapm_src] = 5,
- [snd_soc_dapm_asrc] = 5,
- [snd_soc_dapm_encoder] = 5,
- [snd_soc_dapm_decoder] = 5,
- [snd_soc_dapm_switch] = 6,
- [snd_soc_dapm_mixer_named_ctl] = 6,
- [snd_soc_dapm_mixer] = 6,
- [snd_soc_dapm_dac] = 7,
- [snd_soc_dapm_mic] = 8,
- [snd_soc_dapm_siggen] = 8,
- [snd_soc_dapm_input] = 8,
- [snd_soc_dapm_output] = 8,
- [snd_soc_dapm_micbias] = 9,
- [snd_soc_dapm_vmid] = 9,
- [snd_soc_dapm_mux] = 10,
- [snd_soc_dapm_demux] = 10,
- [snd_soc_dapm_aif_in] = 11,
- [snd_soc_dapm_aif_out] = 11,
- [snd_soc_dapm_dai_in] = 11,
- [snd_soc_dapm_dai_out] = 11,
- [snd_soc_dapm_dai_link] = 12,
- [snd_soc_dapm_supply] = 13,
- [snd_soc_dapm_clock_supply] = 14,
- [snd_soc_dapm_pinctrl] = 14,
- [snd_soc_dapm_regulator_supply] = 14,
- [snd_soc_dapm_post] = 15,
+ [snd_soc_dapm_hp] = 5,
+ [snd_soc_dapm_line] = 5,
+ [snd_soc_dapm_out_drv] = 5,
+ [snd_soc_dapm_sink] = 6,
+ [snd_soc_dapm_pga] = 6,
+ [snd_soc_dapm_buffer] = 6,
+ [snd_soc_dapm_scheduler] = 6,
+ [snd_soc_dapm_effect] = 6,
+ [snd_soc_dapm_src] = 6,
+ [snd_soc_dapm_asrc] = 6,
+ [snd_soc_dapm_encoder] = 6,
+ [snd_soc_dapm_decoder] = 6,
+ [snd_soc_dapm_switch] = 7,
+ [snd_soc_dapm_mixer_named_ctl] = 7,
+ [snd_soc_dapm_mixer] = 7,
+ [snd_soc_dapm_dac] = 8,
+ [snd_soc_dapm_mic] = 9,
+ [snd_soc_dapm_siggen] = 9,
+ [snd_soc_dapm_input] = 9,
+ [snd_soc_dapm_output] = 9,
+ [snd_soc_dapm_micbias] = 10,
+ [snd_soc_dapm_vmid] = 10,
+ [snd_soc_dapm_mux] = 11,
+ [snd_soc_dapm_demux] = 11,
+ [snd_soc_dapm_aif_in] = 12,
+ [snd_soc_dapm_aif_out] = 12,
+ [snd_soc_dapm_dai_in] = 12,
+ [snd_soc_dapm_dai_out] = 12,
+ [snd_soc_dapm_dai_link] = 13,
+ [snd_soc_dapm_supply] = 14,
+ [snd_soc_dapm_clock_supply] = 15,
+ [snd_soc_dapm_pinctrl] = 15,
+ [snd_soc_dapm_regulator_supply] = 15,
+ [snd_soc_dapm_post] = 16,
};
static void dapm_assert_locked(struct snd_soc_dapm_context *dapm)
{
if (snd_soc_card_is_instantiated(dapm->card))
- lockdep_assert_held(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_assert_held(dapm);
}
static void pop_wait(u32 pop_time)
@@ -302,7 +302,7 @@ void dapm_mark_endpoints_dirty(struct snd_soc_card *card)
{
struct snd_soc_dapm_widget *w;
- mutex_lock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_lock_root(card);
for_each_card_widgets(card, w) {
if (w->is_ep) {
@@ -314,7 +314,7 @@ void dapm_mark_endpoints_dirty(struct snd_soc_card *card)
}
}
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
}
EXPORT_SYMBOL_GPL(dapm_mark_endpoints_dirty);
@@ -604,7 +604,7 @@ static void dapm_reset(struct snd_soc_card *card)
{
struct snd_soc_dapm_widget *w;
- lockdep_assert_held(&card->dapm_mutex);
+ snd_soc_dapm_mutex_assert_held(card);
memset(&card->dapm_stats, 0, sizeof(card->dapm_stats));
@@ -1075,7 +1075,7 @@ static int dapm_new_dai_link(struct snd_soc_dapm_widget *w)
struct snd_soc_pcm_runtime *rtd = w->priv;
/* create control for links with > 1 config */
- if (rtd->dai_link->num_params <= 1)
+ if (rtd->dai_link->num_c2c_params <= 1)
return 0;
/* add kcontrol */
@@ -1302,7 +1302,7 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
int paths;
int ret;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(card);
if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
invalidate_paths_ep(w, SND_SOC_DAPM_DIR_OUT);
@@ -1322,7 +1322,7 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
paths = ret;
trace_snd_soc_dapm_connected(paths, stream);
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
return paths;
}
@@ -1952,7 +1952,7 @@ static int dapm_power_widgets(struct snd_soc_card *card, int event)
enum snd_soc_bias_level bias;
int ret;
- lockdep_assert_held(&card->dapm_mutex);
+ snd_soc_dapm_mutex_assert_held(card);
trace_snd_soc_dapm_start(card);
@@ -2090,7 +2090,6 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
size_t count, loff_t *ppos)
{
struct snd_soc_dapm_widget *w = file->private_data;
- struct snd_soc_card *card = w->dapm->card;
enum snd_soc_dapm_direction dir, rdir;
char *buf;
int in, out;
@@ -2101,7 +2100,7 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
if (!buf)
return -ENOMEM;
- mutex_lock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_lock_root(w->dapm);
/* Supply widgets are not handled by is_connected_{input,output}_ep() */
if (w->is_supply) {
@@ -2145,7 +2144,7 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
}
}
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(w->dapm);
ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
@@ -2266,7 +2265,7 @@ static int soc_dapm_mux_update_power(struct snd_soc_card *card,
int found = 0;
bool connect;
- lockdep_assert_held(&card->dapm_mutex);
+ snd_soc_dapm_mutex_assert_held(card);
/* find dapm widget path assoc with kcontrol */
dapm_kcontrol_for_each_path(path, kcontrol) {
@@ -2293,11 +2292,11 @@ int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm,
struct snd_soc_card *card = dapm->card;
int ret;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(card);
card->update = update;
ret = soc_dapm_mux_update_power(card, kcontrol, mux, e);
card->update = NULL;
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
if (ret > 0)
snd_soc_dpcm_runtime_update(card);
return ret;
@@ -2312,7 +2311,7 @@ static int soc_dapm_mixer_update_power(struct snd_soc_card *card,
struct snd_soc_dapm_path *path;
int found = 0;
- lockdep_assert_held(&card->dapm_mutex);
+ snd_soc_dapm_mutex_assert_held(card);
/* find dapm widget path assoc with kcontrol */
dapm_kcontrol_for_each_path(path, kcontrol) {
@@ -2358,11 +2357,11 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm,
struct snd_soc_card *card = dapm->card;
int ret;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(card);
card->update = update;
ret = soc_dapm_mixer_update_power(card, kcontrol, connect, -1);
card->update = NULL;
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
if (ret > 0)
snd_soc_dpcm_runtime_update(card);
return ret;
@@ -2441,7 +2440,7 @@ static ssize_t dapm_widget_show(struct device *dev,
struct snd_soc_dai *codec_dai;
int i, count = 0;
- mutex_lock(&rtd->card->dapm_mutex);
+ snd_soc_dapm_mutex_lock_root(rtd->card);
for_each_rtd_codec_dais(rtd, i, codec_dai) {
struct snd_soc_component *cmpnt = codec_dai->component;
@@ -2449,7 +2448,7 @@ static ssize_t dapm_widget_show(struct device *dev,
count = dapm_widget_show_component(cmpnt, buf, count);
}
- mutex_unlock(&rtd->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(rtd->card);
return count;
}
@@ -2632,9 +2631,9 @@ int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
{
int ret;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
ret = snd_soc_dapm_sync_unlocked(dapm);
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
@@ -2703,9 +2702,9 @@ int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
int ret;
- mutex_lock_nested(&rtd->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(rtd->card);
ret = dapm_update_dai_unlocked(substream, params, dai);
- mutex_unlock(&rtd->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(rtd->card);
return ret;
}
@@ -3090,14 +3089,14 @@ int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
{
int i, ret = 0;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
for (i = 0; i < num; i++) {
int r = snd_soc_dapm_add_route(dapm, route);
if (r < 0)
ret = r;
route++;
}
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return ret;
}
@@ -3116,12 +3115,12 @@ int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
{
int i;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
for (i = 0; i < num; i++) {
snd_soc_dapm_del_route(dapm, route);
route++;
}
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return 0;
}
@@ -3194,14 +3193,14 @@ int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm,
int i;
int ret = 0;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
+ snd_soc_dapm_mutex_lock_root(dapm);
for (i = 0; i < num; i++) {
int err = snd_soc_dapm_weak_route(dapm, route);
if (err)
ret = err;
route++;
}
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return ret;
}
@@ -3220,7 +3219,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card)
struct snd_soc_dapm_widget *w;
unsigned int val;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
+ snd_soc_dapm_mutex_lock_root(card);
for_each_card_widgets(card, w)
{
@@ -3232,7 +3231,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card)
sizeof(struct snd_kcontrol *),
GFP_KERNEL);
if (!w->kcontrols) {
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
return -ENOMEM;
}
}
@@ -3275,7 +3274,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card)
}
dapm_power_widgets(card, SND_SOC_DAPM_STREAM_NOP);
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
@@ -3293,7 +3292,6 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
- struct snd_soc_card *card = dapm->card;
struct soc_mixer_control *mc =
(struct soc_mixer_control *)kcontrol->private_value;
int reg = mc->reg;
@@ -3304,7 +3302,7 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
unsigned int invert = mc->invert;
unsigned int reg_val, val, rval = 0;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
if (dapm_kcontrol_is_powered(kcontrol) && reg != SND_SOC_NOPM) {
reg_val = soc_dapm_read(dapm, reg);
val = (reg_val >> shift) & mask;
@@ -3321,7 +3319,7 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
if (snd_soc_volsw_is_stereo(mc))
rval = (reg_val >> width) & mask;
}
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
if (invert)
ucontrol->value.integer.value[0] = max - val;
@@ -3379,7 +3377,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
rval = max - rval;
}
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(card);
/* This assumes field width < (bits in unsigned int / 2) */
if (width > sizeof(unsigned int) * 8 / 2)
@@ -3421,7 +3419,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
card->update = NULL;
}
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
if (ret > 0)
snd_soc_dpcm_runtime_update(card);
@@ -3443,17 +3441,16 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol);
- struct snd_soc_card *card = dapm->card;
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
unsigned int reg_val, val;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
if (e->reg != SND_SOC_NOPM && dapm_kcontrol_is_powered(kcontrol)) {
reg_val = soc_dapm_read(dapm, e->reg);
} else {
reg_val = dapm_kcontrol_get_value(kcontrol);
}
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
val = (reg_val >> e->shift_l) & e->mask;
ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val);
@@ -3500,7 +3497,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
mask |= e->mask << e->shift_r;
}
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(card);
change = dapm_kcontrol_set_value(kcontrol, val);
@@ -3521,7 +3518,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
card->update = NULL;
}
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
if (ret > 0)
snd_soc_dpcm_runtime_update(card);
@@ -3562,12 +3559,12 @@ int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
const char *pin = (const char *)kcontrol->private_value;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(card);
ucontrol->value.integer.value[0] =
snd_soc_dapm_get_pin_status(&card->dapm, pin);
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
return 0;
}
@@ -3586,10 +3583,10 @@ int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
const char *pin = (const char *)kcontrol->private_value;
int ret;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(card);
ret = __snd_soc_dapm_set_pin(&card->dapm, pin,
!!ucontrol->value.integer.value[0]);
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
snd_soc_dapm_sync(&card->dapm);
return ret;
@@ -3762,9 +3759,9 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
{
struct snd_soc_dapm_widget *w;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
w = snd_soc_dapm_new_control_unlocked(dapm, widget);
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return w;
}
@@ -3787,7 +3784,7 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
int i;
int ret = 0;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);
+ snd_soc_dapm_mutex_lock_root(dapm);
for (i = 0; i < num; i++) {
struct snd_soc_dapm_widget *w = snd_soc_dapm_new_control_unlocked(dapm, widget);
if (IS_ERR(w)) {
@@ -3796,7 +3793,7 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
}
widget++;
}
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
@@ -3864,7 +3861,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
* either party on the link to alter the configuration if
* necessary
*/
- config = rtd->dai_link->params + rtd->params_select;
+ config = rtd->dai_link->c2c_params + rtd->c2c_params_select;
if (!config) {
dev_err(w->dapm->dev, "ASoC: link config missing\n");
ret = -EINVAL;
@@ -4010,7 +4007,7 @@ static int snd_soc_dapm_dai_link_get(struct snd_kcontrol *kcontrol,
struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol);
struct snd_soc_pcm_runtime *rtd = w->priv;
- ucontrol->value.enumerated.item[0] = rtd->params_select;
+ ucontrol->value.enumerated.item[0] = rtd->c2c_params_select;
return 0;
}
@@ -4025,13 +4022,13 @@ static int snd_soc_dapm_dai_link_put(struct snd_kcontrol *kcontrol,
if (w->power)
return -EBUSY;
- if (ucontrol->value.enumerated.item[0] == rtd->params_select)
+ if (ucontrol->value.enumerated.item[0] == rtd->c2c_params_select)
return 0;
- if (ucontrol->value.enumerated.item[0] >= rtd->dai_link->num_params)
+ if (ucontrol->value.enumerated.item[0] >= rtd->dai_link->num_c2c_params)
return -EINVAL;
- rtd->params_select = ucontrol->value.enumerated.item[0];
+ rtd->c2c_params_select = ucontrol->value.enumerated.item[0];
return 1;
}
@@ -4039,7 +4036,7 @@ static int snd_soc_dapm_dai_link_put(struct snd_kcontrol *kcontrol,
static void
snd_soc_dapm_free_kcontrol(struct snd_soc_card *card,
unsigned long *private_value,
- int num_params,
+ int num_c2c_params,
const char **w_param_text)
{
int count;
@@ -4049,7 +4046,7 @@ snd_soc_dapm_free_kcontrol(struct snd_soc_card *card,
if (!w_param_text)
return;
- for (count = 0 ; count < num_params; count++)
+ for (count = 0 ; count < num_c2c_params; count++)
devm_kfree(card->dev, (void *)w_param_text[count]);
devm_kfree(card->dev, w_param_text);
}
@@ -4057,8 +4054,8 @@ snd_soc_dapm_free_kcontrol(struct snd_soc_card *card,
static struct snd_kcontrol_new *
snd_soc_dapm_alloc_kcontrol(struct snd_soc_card *card,
char *link_name,
- const struct snd_soc_pcm_stream *params,
- int num_params, const char **w_param_text,
+ const struct snd_soc_pcm_stream *c2c_params,
+ int num_c2c_params, const char **w_param_text,
unsigned long *private_value)
{
struct soc_enum w_param_enum[] = {
@@ -4070,10 +4067,10 @@ snd_soc_dapm_alloc_kcontrol(struct snd_soc_card *card,
snd_soc_dapm_dai_link_put),
};
struct snd_kcontrol_new *kcontrol_news;
- const struct snd_soc_pcm_stream *config = params;
+ const struct snd_soc_pcm_stream *config = c2c_params;
int count;
- for (count = 0 ; count < num_params; count++) {
+ for (count = 0 ; count < num_c2c_params; count++) {
if (!config->stream_name) {
dev_warn(card->dapm.dev,
"ASoC: anonymous config %d for dai link %s\n",
@@ -4093,7 +4090,7 @@ snd_soc_dapm_alloc_kcontrol(struct snd_soc_card *card,
config++;
}
- w_param_enum[0].items = num_params;
+ w_param_enum[0].items = num_c2c_params;
w_param_enum[0].texts = w_param_text;
*private_value =
@@ -4118,7 +4115,7 @@ snd_soc_dapm_alloc_kcontrol(struct snd_soc_card *card,
return kcontrol_news;
outfree_w_param:
- snd_soc_dapm_free_kcontrol(card, private_value, num_params, w_param_text);
+ snd_soc_dapm_free_kcontrol(card, private_value, num_c2c_params, w_param_text);
return NULL;
}
@@ -4146,17 +4143,17 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card,
w_param_text = NULL;
kcontrol_news = NULL;
num_kcontrols = 0;
- if (rtd->dai_link->num_params > 1) {
+ if (rtd->dai_link->num_c2c_params > 1) {
w_param_text = devm_kcalloc(card->dev,
- rtd->dai_link->num_params,
+ rtd->dai_link->num_c2c_params,
sizeof(char *), GFP_KERNEL);
if (!w_param_text)
goto param_fail;
num_kcontrols = 1;
kcontrol_news = snd_soc_dapm_alloc_kcontrol(card, link_name,
- rtd->dai_link->params,
- rtd->dai_link->num_params,
+ rtd->dai_link->c2c_params,
+ rtd->dai_link->num_c2c_params,
w_param_text, &private_value);
if (!kcontrol_news)
goto param_fail;
@@ -4187,7 +4184,7 @@ snd_soc_dapm_new_dai(struct snd_soc_card *card,
outfree_kcontrol_news:
devm_kfree(card->dev, (void *)template.kcontrol_news);
snd_soc_dapm_free_kcontrol(card, &private_value,
- rtd->dai_link->num_params, w_param_text);
+ rtd->dai_link->num_c2c_params, w_param_text);
param_fail:
devm_kfree(card->dev, link_name);
name_fail:
@@ -4325,60 +4322,81 @@ static void dapm_connect_dai_routes(struct snd_soc_dapm_context *dapm,
snd_soc_dapm_add_path(dapm, src, sink, NULL, NULL);
}
+static int get_stream_cpu(struct snd_soc_dai_link *dai_link, int stream)
+{
+ /*
+ * [Normal]
+ *
+ * Playback
+ * CPU : SNDRV_PCM_STREAM_PLAYBACK
+ * Codec: SNDRV_PCM_STREAM_PLAYBACK
+ *
+ * Playback
+ * CPU : SNDRV_PCM_STREAM_CAPTURE
+ * Codec: SNDRV_PCM_STREAM_CAPTURE
+ */
+ if (!dai_link->c2c_params)
+ return stream;
+
+ /*
+ * [Codec2Codec]
+ *
+ * Playback
+ * CPU : SNDRV_PCM_STREAM_CAPTURE
+ * Codec: SNDRV_PCM_STREAM_PLAYBACK
+ *
+ * Capture
+ * CPU : SNDRV_PCM_STREAM_PLAYBACK
+ * Codec: SNDRV_PCM_STREAM_CAPTURE
+ */
+ if (stream == SNDRV_PCM_STREAM_CAPTURE)
+ return SNDRV_PCM_STREAM_PLAYBACK;
+
+ return SNDRV_PCM_STREAM_CAPTURE;
+}
+
static void dapm_connect_dai_pair(struct snd_soc_card *card,
struct snd_soc_pcm_runtime *rtd,
struct snd_soc_dai *codec_dai,
struct snd_soc_dai *cpu_dai)
{
struct snd_soc_dai_link *dai_link = rtd->dai_link;
- struct snd_soc_dapm_widget *dai, *codec, *playback_cpu, *capture_cpu;
- struct snd_pcm_substream *substream;
- struct snd_pcm_str *streams = rtd->pcm->streams;
+ struct snd_soc_dapm_widget *codec, *cpu;
+ struct snd_soc_dai *src_dai[] = { cpu_dai, codec_dai };
+ struct snd_soc_dai *sink_dai[] = { codec_dai, cpu_dai };
+ struct snd_soc_dapm_widget **src[] = { &cpu, &codec };
+ struct snd_soc_dapm_widget **sink[] = { &codec, &cpu };
+ char *widget_name[] = { "playback", "capture" };
int stream;
- if (dai_link->params) {
- playback_cpu = snd_soc_dai_get_widget_capture(cpu_dai);
- capture_cpu = snd_soc_dai_get_widget_playback(cpu_dai);
- } else {
- playback_cpu = snd_soc_dai_get_widget_playback(cpu_dai);
- capture_cpu = snd_soc_dai_get_widget_capture(cpu_dai);
- }
+ for_each_pcm_streams(stream) {
+ int stream_cpu, stream_codec;
- /* connect BE DAI playback if widgets are valid */
- stream = SNDRV_PCM_STREAM_PLAYBACK;
- codec = snd_soc_dai_get_widget(codec_dai, stream);
+ stream_cpu = get_stream_cpu(dai_link, stream);
+ stream_codec = stream;
- if (playback_cpu && codec) {
- if (dai_link->params && !rtd->c2c_widget[stream]) {
- substream = streams[stream].substream;
- dai = snd_soc_dapm_new_dai(card, substream, "playback");
- if (IS_ERR(dai))
- goto capture;
- rtd->c2c_widget[stream] = dai;
- }
+ /* connect BE DAI playback if widgets are valid */
+ cpu = snd_soc_dai_get_widget(cpu_dai, stream_cpu);
+ codec = snd_soc_dai_get_widget(codec_dai, stream_codec);
- dapm_connect_dai_routes(&card->dapm, cpu_dai, playback_cpu,
- rtd->c2c_widget[stream],
- codec_dai, codec);
- }
+ if (!cpu || !codec)
+ continue;
-capture:
- /* connect BE DAI capture if widgets are valid */
- stream = SNDRV_PCM_STREAM_CAPTURE;
- codec = snd_soc_dai_get_widget(codec_dai, stream);
+ /* special handling for [Codec2Codec] */
+ if (dai_link->c2c_params && !rtd->c2c_widget[stream]) {
+ struct snd_pcm_substream *substream = rtd->pcm->streams[stream].substream;
+ struct snd_soc_dapm_widget *dai = snd_soc_dapm_new_dai(card, substream,
+ widget_name[stream]);
- if (codec && capture_cpu) {
- if (dai_link->params && !rtd->c2c_widget[stream]) {
- substream = streams[stream].substream;
- dai = snd_soc_dapm_new_dai(card, substream, "capture");
if (IS_ERR(dai))
- return;
+ continue;
+
rtd->c2c_widget[stream] = dai;
}
- dapm_connect_dai_routes(&card->dapm, codec_dai, codec,
+ dapm_connect_dai_routes(&card->dapm, src_dai[stream], *src[stream],
rtd->c2c_widget[stream],
- cpu_dai, capture_cpu);
+ sink_dai[stream], *sink[stream]);
}
}
@@ -4478,9 +4496,9 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
{
struct snd_soc_card *card = rtd->card;
- mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(card);
soc_dapm_stream_event(rtd, stream, event);
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
}
void snd_soc_dapm_stream_stop(struct snd_soc_pcm_runtime *rtd, int stream)
@@ -4541,11 +4559,11 @@ int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
{
int ret;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
ret = snd_soc_dapm_set_pin(dapm, pin, 1);
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return ret;
}
@@ -4609,11 +4627,11 @@ int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
{
int ret;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return ret;
}
@@ -4653,11 +4671,11 @@ int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
{
int ret;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
ret = snd_soc_dapm_set_pin(dapm, pin, 0);
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return ret;
}
@@ -4704,11 +4722,11 @@ int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
{
int ret;
- mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+ snd_soc_dapm_mutex_lock(dapm);
ret = snd_soc_dapm_set_pin(dapm, pin, 0);
- mutex_unlock(&dapm->card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(dapm);
return ret;
}
@@ -4805,7 +4823,7 @@ static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context *dapm)
LIST_HEAD(down_list);
int powerdown = 0;
- mutex_lock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_lock_root(card);
for_each_card_widgets(dapm->card, w) {
if (w->dapm != dapm)
@@ -4830,7 +4848,7 @@ static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context *dapm)
SND_SOC_BIAS_STANDBY);
}
- mutex_unlock(&card->dapm_mutex);
+ snd_soc_dapm_mutex_unlock(card);
}
/*