Commit 4a778bdc authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: expand snd_soc_dapm_mutex_lock/unlock()

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: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87cz4hx3v0.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent fc0b096c
......@@ -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.
*
......
......@@ -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>
......
This diff is collapsed.
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