mirror of
https://github.com/hardkernel/linux.git
synced 2026-03-25 20:10:23 +09:00
BACKPORT: ASoC: expand snd_soc_dpcm_mutex_lock/unlock()
soc-pcm.c has snd_soc_dpcm_mutex_lock/unlock(),
but other files can't use it because it is static function.
It requests snd_soc_pcm_runtime as parameter (A), but sometimes we
want to use it by snd_soc_card (B).
(A) static inline void snd_soc_dpcm_mutex_lock(struct snd_soc_pcm_runtime *rtd)
{
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
} ^^^^^^^^^
(B) mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
^^^^
We want to use it with both "rtd" and "card" for dapm lock/unlock.
To enable it, this patch uses _Generic macro.
This patch makes snd_soc_dpcm_mutex_{un}lock() global function, and use it on
each files.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87bkk1x3ud.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Bug: 303236405
(cherry picked from commit 38e42f6d6c)
[ Yixuan Jiang: Fix minor conflict ]
Change-Id: I6cd7fc467b9ec23d6b051d3d531695568996f7a5
Signed-off-by: Yixuan Jiang <yixuanjiang@google.com>
This commit is contained in:
committed by
Todd Kjos
parent
2721efad0a
commit
8cdc41d9b8
@@ -1413,6 +1413,51 @@ static inline void _snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context
|
||||
struct snd_soc_card * : _snd_soc_dapm_mutex_assert_held_c, \
|
||||
struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x)
|
||||
|
||||
/*
|
||||
* PCM helper functions
|
||||
*/
|
||||
static inline void _snd_soc_dpcm_mutex_lock_c(struct snd_soc_card *card)
|
||||
{
|
||||
mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_unlock_c(struct snd_soc_card *card)
|
||||
{
|
||||
mutex_unlock(&card->pcm_mutex);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card *card)
|
||||
{
|
||||
lockdep_assert_held(&card->pcm_mutex);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_lock_r(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
_snd_soc_dpcm_mutex_lock_c(rtd->card);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_unlock_r(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
_snd_soc_dpcm_mutex_unlock_c(rtd->card);
|
||||
}
|
||||
|
||||
static inline void _snd_soc_dpcm_mutex_assert_held_r(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
_snd_soc_dpcm_mutex_assert_held_c(rtd->card);
|
||||
}
|
||||
|
||||
#define snd_soc_dpcm_mutex_lock(x) _Generic((x), \
|
||||
struct snd_soc_card * : _snd_soc_dpcm_mutex_lock_c, \
|
||||
struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_lock_r)(x)
|
||||
|
||||
#define snd_soc_dpcm_mutex_unlock(x) _Generic((x), \
|
||||
struct snd_soc_card * : _snd_soc_dpcm_mutex_unlock_c, \
|
||||
struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_unlock_r)(x)
|
||||
|
||||
#define snd_soc_dpcm_mutex_assert_held(x) _Generic((x), \
|
||||
struct snd_soc_card * : _snd_soc_dpcm_mutex_assert_held_c, \
|
||||
struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_assert_held_r)(x)
|
||||
|
||||
#include <sound/soc-component.h>
|
||||
#include <sound/soc-card.h>
|
||||
#include <sound/soc-jack.h>
|
||||
|
||||
@@ -533,7 +533,7 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
|
||||
struct snd_soc_component *component;
|
||||
int i, ret = 0;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
for_each_rtd_components(rtd, i, component) {
|
||||
if (component->driver->compress_ops &&
|
||||
@@ -544,7 +544,7 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
return soc_component_ret(component, ret);
|
||||
}
|
||||
@@ -557,7 +557,7 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
|
||||
struct snd_soc_component *component;
|
||||
int i, ret = 0;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
for_each_rtd_components(rtd, i, component) {
|
||||
if (component->driver->compress_ops &&
|
||||
@@ -568,7 +568,7 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
return soc_component_ret(component, ret);
|
||||
}
|
||||
@@ -621,7 +621,7 @@ int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
|
||||
struct snd_soc_component *component;
|
||||
int i, ret = 0;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
for_each_rtd_components(rtd, i, component) {
|
||||
if (component->driver->compress_ops &&
|
||||
@@ -632,7 +632,7 @@ int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
|
||||
}
|
||||
}
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
return soc_component_ret(component, ret);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
|
||||
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
|
||||
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
if (!rollback)
|
||||
snd_soc_runtime_deactivate(rtd, stream);
|
||||
@@ -51,7 +51,7 @@ static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
|
||||
if (!rollback)
|
||||
snd_soc_dapm_stream_stop(rtd, stream);
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
snd_soc_pcm_component_pm_runtime_put(rtd, cstream, rollback);
|
||||
|
||||
@@ -74,7 +74,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
|
||||
if (ret < 0)
|
||||
goto err_no_lock;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_dai_compr_startup(cpu_dai, cstream);
|
||||
if (ret < 0)
|
||||
@@ -90,7 +90,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
|
||||
|
||||
snd_soc_runtime_activate(rtd, stream);
|
||||
err:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
err_no_lock:
|
||||
if (ret < 0)
|
||||
soc_compr_clean(cstream, 1);
|
||||
@@ -116,7 +116,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
|
||||
if (ret < 0)
|
||||
goto be_err;
|
||||
|
||||
mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(fe);
|
||||
|
||||
/* calculate valid and active FE <-> BE dpcms */
|
||||
dpcm_process_paths(fe, stream, &list, 1);
|
||||
@@ -154,7 +154,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
|
||||
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
|
||||
|
||||
snd_soc_runtime_activate(fe, stream);
|
||||
mutex_unlock(&fe->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(fe);
|
||||
|
||||
mutex_unlock(&fe->card->mutex);
|
||||
|
||||
@@ -181,7 +181,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
|
||||
|
||||
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
|
||||
|
||||
mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(fe);
|
||||
snd_soc_runtime_deactivate(fe, stream);
|
||||
|
||||
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
|
||||
@@ -201,7 +201,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
|
||||
|
||||
dpcm_be_disconnect(fe, stream);
|
||||
|
||||
mutex_unlock(&fe->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(fe);
|
||||
|
||||
fe->dpcm[stream].runtime = NULL;
|
||||
|
||||
@@ -223,7 +223,7 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
|
||||
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
|
||||
int ret;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_component_compr_trigger(cstream, cmd);
|
||||
if (ret < 0)
|
||||
@@ -243,7 +243,7 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
|
||||
}
|
||||
|
||||
out:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
|
||||
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
|
||||
int ret;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
/*
|
||||
* First we call set_params for the CPU DAI, then the component
|
||||
@@ -326,14 +326,14 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
|
||||
|
||||
/* cancel any delayed stream shutdown that is pending */
|
||||
rtd->pop_wait = 0;
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
|
||||
cancel_delayed_work_sync(&rtd->delayed_work);
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -378,9 +378,9 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
|
||||
ret = snd_soc_link_compr_set_params(cstream);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(fe);
|
||||
dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START);
|
||||
mutex_unlock(&fe->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(fe);
|
||||
fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
|
||||
|
||||
out:
|
||||
@@ -396,7 +396,7 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
|
||||
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params);
|
||||
if (ret < 0)
|
||||
@@ -404,7 +404,7 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
|
||||
|
||||
ret = snd_soc_component_compr_get_params(cstream, params);
|
||||
err:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
|
||||
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
|
||||
int ret;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes);
|
||||
if (ret < 0)
|
||||
@@ -422,7 +422,7 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
|
||||
|
||||
ret = snd_soc_component_compr_ack(cstream, bytes);
|
||||
err:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
|
||||
int ret;
|
||||
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp);
|
||||
if (ret < 0)
|
||||
@@ -441,7 +441,7 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
|
||||
|
||||
ret = snd_soc_component_compr_pointer(cstream, tstamp);
|
||||
out:
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -367,7 +367,7 @@ void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
|
||||
struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
|
||||
int playback = SNDRV_PCM_STREAM_PLAYBACK;
|
||||
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(rtd);
|
||||
|
||||
dev_dbg(rtd->dev,
|
||||
"ASoC: pop wq checking: %s status: %s waiting: %s\n",
|
||||
@@ -383,7 +383,7 @@ void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
|
||||
SND_SOC_DAPM_STREAM_STOP);
|
||||
}
|
||||
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(rtd);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_soc_close_delayed_work);
|
||||
|
||||
|
||||
@@ -27,19 +27,6 @@
|
||||
#include <sound/soc-link.h>
|
||||
#include <sound/initval.h>
|
||||
|
||||
static inline void snd_soc_dpcm_mutex_lock(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
|
||||
}
|
||||
|
||||
static inline void snd_soc_dpcm_mutex_unlock(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
mutex_unlock(&rtd->card->pcm_mutex);
|
||||
}
|
||||
|
||||
#define snd_soc_dpcm_mutex_assert_held(rtd) \
|
||||
lockdep_assert_held(&(rtd)->card->pcm_mutex)
|
||||
|
||||
static inline void snd_soc_dpcm_stream_lock_irq(struct snd_soc_pcm_runtime *rtd,
|
||||
int stream)
|
||||
{
|
||||
@@ -2659,7 +2646,7 @@ int snd_soc_dpcm_runtime_update(struct snd_soc_card *card)
|
||||
struct snd_soc_pcm_runtime *fe;
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
|
||||
snd_soc_dpcm_mutex_lock(card);
|
||||
/* shutdown all old paths first */
|
||||
for_each_card_rtds(card, fe) {
|
||||
ret = soc_dpcm_fe_runtime_update(fe, 0);
|
||||
@@ -2675,7 +2662,7 @@ int snd_soc_dpcm_runtime_update(struct snd_soc_card *card)
|
||||
}
|
||||
|
||||
out:
|
||||
mutex_unlock(&card->pcm_mutex);
|
||||
snd_soc_dpcm_mutex_unlock(card);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(snd_soc_dpcm_runtime_update);
|
||||
|
||||
Reference in New Issue
Block a user