ASoC: expand snd_soc_dapm_mutex_lock/unlock()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thu, 6 Apr 2023 00:15:48 +0000 (00:15 +0000)
committerMark Brown <broonie@kernel.org>
Mon, 17 Apr 2023 11:57:24 +0000 (12:57 +0100)
soc.h has snd_soc_dapm_mutex_lock/unlock() definition and
many drivers are using it, but soc-dapm.c is not.

1st reason is snd_soc_dapm_mutex_lock/unlock() requests
snd_soc_dapm_context pointer as parameter (A), but sometimes soc-dapm.c
needs to use snd_soc_card (B).

(A) static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
{
mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
}    ^^^^^^^^^^

(B) mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
   ^^^^

2nd reason is it want to use SND_SOC_DAPM_CLASS_INIT for mutex_lock_nested(),
but helper is using _RUNTIME (A).

The conclusion is we want to use "dapm vs card" and "_RUNTIME vs _INIT"
for dapm lock/unlock. To enable this selfish request, this patch uses
_Generic macro. We can use snd_soc_dapm_mutex_lock/unlock() for both
dapm and card case.

snd_soc_dapm_mutex_lock(dapm); snd_soc_dapm_mutex_unlock(dapm);
snd_soc_dapm_mutex_lock(card); snd_soc_dapm_mutex_unlock(card);

Current soc-dapm.c is using both mutex_lock() and mutex_lock_nested().
This patch handles mutex_lock() as mutex_lock_nested(..., 0),
in other words, handles below as same.

mutex_lock(&card->dapm_mutex);
mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT);

Because people might misunderstand that _init() is mutex initialization,
this patch renames _INIT to _ROOT and adds new
snd_soc_dapm_mutex_lock_root() for it.

This patch also moves snd_soc_dapm_subclass definition from soc-dapm.h
to soc.h to keep related code together.

Because very complex soc.h vs soc-dapm.h relationship,
it is difficult/impossible to define these helper into soc-dapm.h.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87cz4hx3v0.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc-dapm.h
include/sound/soc.h
sound/soc/soc-dapm.c

index 64915eb..87f8e17 100644 (file)
@@ -527,11 +527,6 @@ enum snd_soc_dapm_type {
        SND_SOC_DAPM_TYPE_COUNT
 };
 
-enum snd_soc_dapm_subclass {
-       SND_SOC_DAPM_CLASS_INIT         = 0,
-       SND_SOC_DAPM_CLASS_RUNTIME      = 1,
-};
-
 /*
  * DAPM audio route definition.
  *
index 3833184..0e17e32 100644 (file)
@@ -1364,17 +1364,67 @@ extern struct dentry *snd_soc_debugfs_root;
 
 extern const struct dev_pm_ops snd_soc_pm_ops;
 
-/* Helper functions */
-static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
+/*
+ *     DAPM helper functions
+ */
+enum snd_soc_dapm_subclass {
+       SND_SOC_DAPM_CLASS_ROOT         = 0,
+       SND_SOC_DAPM_CLASS_RUNTIME      = 1,
+};
+
+static inline void _snd_soc_dapm_mutex_lock_root_c(struct snd_soc_card *card)
+{
+       mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_ROOT);
+}
+
+static inline void _snd_soc_dapm_mutex_lock_c(struct snd_soc_card *card)
+{
+       mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+}
+
+static inline void _snd_soc_dapm_mutex_unlock_c(struct snd_soc_card *card)
 {
-       mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
+       mutex_unlock(&card->dapm_mutex);
 }
 
-static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
+static inline void _snd_soc_dapm_mutex_assert_held_c(struct snd_soc_card *card)
 {
-       mutex_unlock(&dapm->card->dapm_mutex);
+       lockdep_assert_held(&card->dapm_mutex);
 }
 
+static inline void _snd_soc_dapm_mutex_lock_root_d(struct snd_soc_dapm_context *dapm)
+{
+       _snd_soc_dapm_mutex_lock_root_c(dapm->card);
+}
+
+static inline void _snd_soc_dapm_mutex_lock_d(struct snd_soc_dapm_context *dapm)
+{
+       _snd_soc_dapm_mutex_lock_c(dapm->card);
+}
+
+static inline void _snd_soc_dapm_mutex_unlock_d(struct snd_soc_dapm_context *dapm)
+{
+       _snd_soc_dapm_mutex_unlock_c(dapm->card);
+}
+
+static inline void _snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context *dapm)
+{
+       _snd_soc_dapm_mutex_assert_held_c(dapm->card);
+}
+
+#define snd_soc_dapm_mutex_lock_root(x) _Generic((x),                  \
+       struct snd_soc_card * :         _snd_soc_dapm_mutex_lock_root_c, \
+       struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_root_d)(x)
+#define snd_soc_dapm_mutex_lock(x) _Generic((x),                       \
+       struct snd_soc_card * :         _snd_soc_dapm_mutex_lock_c,     \
+       struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_d)(x)
+#define snd_soc_dapm_mutex_unlock(x) _Generic((x),                     \
+       struct snd_soc_card * :         _snd_soc_dapm_mutex_unlock_c,   \
+       struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_unlock_d)(x)
+#define snd_soc_dapm_mutex_assert_held(x) _Generic((x),                        \
+       struct snd_soc_card * :         _snd_soc_dapm_mutex_assert_held_c, \
+       struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x)
+
 #include <sound/soc-component.h>
 #include <sound/soc-card.h>
 #include <sound/soc-jack.h>
index 36e6f26..f2f04ce 100644 (file)
@@ -150,7 +150,7 @@ static int dapm_down_seq[] = {
 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));
 
@@ -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);
@@ -4499,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)
@@ -4562,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;
 }
@@ -4630,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;
 }
@@ -4674,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;
 }
@@ -4725,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;
 }
@@ -4826,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)
@@ -4851,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);
 }
 
 /*