Skip to content

Commit

Permalink
ASoC: count activity via TX/RX base instead of Playback/Capture.
Browse files Browse the repository at this point in the history
Current ASoC is counting DAI activity via Playback/Capture base,
but it will be more flexible if we count it via TX/RX base.

This patch removes current stream_active from snd_soc_dai,
and adds new txrx_active instead.
We can get TX/RX direction from Playback/Capture and rtd.

To unify variable naming, this patch uses "txrx" for TX/RX,
"stream" for Playback/Capture.

	Digital         Bus            Analog
	        +------+        +-----+
	dTX  dRX| CPU  |bTX  bRX|Codec|aTX
	-------------------------------------> playback
	<------------------------------------- capture
	dRX  dTX|      |bRX  bTX|     |aRX
	        +------+        +-----+
	         <CPU>          <Codec>

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  • Loading branch information
morimoto committed Jun 30, 2022
1 parent ea993ad commit 13230e8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
5 changes: 5 additions & 0 deletions include/sound/pcm.h
Expand Up @@ -669,6 +669,11 @@ void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
stream <= SNDRV_PCM_STREAM_LAST; \
stream++)

#define for_each_pcm_txrx(txrx) \
for (txrx = SNDRV_DIR_TX; \
txrx <= SNDRV_DIR_RX; \
txrx++)

/**
* snd_pcm_running - Check whether the substream is in a running state
* @substream: substream to check
Expand Down
24 changes: 16 additions & 8 deletions include/sound/soc-dai.h
Expand Up @@ -223,17 +223,17 @@ bool snd_soc_dai_valid_via_txrx(struct snd_soc_dai *dai, enum snd_soc_dir txrx);
bool snd_soc_dai_valid_via_stream(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_dai *dai, int stream);
void snd_soc_dai_link_set_capabilities(struct snd_soc_dai_link *dai_link);
void snd_soc_dai_action(struct snd_soc_dai *dai,
void snd_soc_dai_action(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai,
int stream, int action);
static inline void snd_soc_dai_activate(struct snd_soc_dai *dai,
static inline void snd_soc_dai_activate(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai,
int stream)
{
snd_soc_dai_action(dai, stream, 1);
snd_soc_dai_action(rtd, dai, stream, 1);
}
static inline void snd_soc_dai_deactivate(struct snd_soc_dai *dai,
static inline void snd_soc_dai_deactivate(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai,
int stream)
{
snd_soc_dai_action(dai, stream, -1);
snd_soc_dai_action(rtd, dai, stream, -1);
}
int snd_soc_dai_active(struct snd_soc_dai *dai);

Expand Down Expand Up @@ -461,7 +461,7 @@ struct snd_soc_dai {
struct snd_soc_dai_driver *driver;

/* DAI runtime info */
unsigned int stream_active[SNDRV_PCM_STREAM_LAST + 1]; /* usage count */
unsigned int txrx_active[SNDRV_DIR_MAX]; /* usage count */

struct snd_soc_dapm_widget *playback_widget;
struct snd_soc_dapm_widget *capture_widget;
Expand Down Expand Up @@ -597,9 +597,17 @@ static inline void *snd_soc_dai_get_stream(struct snd_soc_dai *dai,
}

static inline unsigned int
snd_soc_dai_stream_active(struct snd_soc_dai *dai, int stream)
snd_soc_dai_txrx_active(struct snd_soc_dai *dai, enum snd_soc_dir txrx)
{
return dai->stream_active[stream];
return dai->txrx_active[txrx];
}

static inline unsigned int
snd_soc_dai_stream_active(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai, int stream)
{
enum snd_soc_dir txrx = snd_soc_convert_stream_to_txrx_via_dai(rtd, dai, stream);

return snd_soc_dai_txrx_active(dai, txrx);
}

#endif
15 changes: 8 additions & 7 deletions sound/soc/soc-core.c
Expand Up @@ -370,21 +370,22 @@ EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
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;
int stream = SNDRV_PCM_STREAM_PLAYBACK;
enum snd_soc_dir txrx = snd_soc_convert_stream_to_txrx_for_codec(stream);

mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);

dev_dbg(rtd->dev,
"ASoC: pop wq checking: %s status: %s waiting: %s\n",
codec_dai->driver->playback.stream_name,
snd_soc_dai_stream_active(codec_dai, playback) ?
codec_dai->driver->stream_info[txrx].stream_name,
snd_soc_dai_txrx_active(codec_dai, txrx) ?
"active" : "inactive",
rtd->pop_wait ? "yes" : "no");

/* are we waiting on this codec DAI stream */
if (rtd->pop_wait == 1) {
rtd->pop_wait = 0;
snd_soc_dapm_stream_event(rtd, playback,
snd_soc_dapm_stream_event(rtd, stream,
SND_SOC_DAPM_STREAM_STOP);
}

Expand Down Expand Up @@ -539,7 +540,7 @@ static void soc_playback_digital_mute(struct snd_soc_card *card, int mute)
{
struct snd_soc_pcm_runtime *rtd;
struct snd_soc_dai *dai;
int playback = SNDRV_PCM_STREAM_PLAYBACK;
int stream = SNDRV_PCM_STREAM_PLAYBACK;
int i;

for_each_card_rtds(card, rtd) {
Expand All @@ -548,8 +549,8 @@ static void soc_playback_digital_mute(struct snd_soc_card *card, int mute)
continue;

for_each_rtd_dais(rtd, i, dai) {
if (snd_soc_dai_stream_active(dai, playback))
snd_soc_dai_digital_mute(dai, mute, playback);
if (snd_soc_dai_stream_active(rtd, dai, stream))
snd_soc_dai_digital_mute(dai, mute, stream);
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions sound/soc/soc-dai.c
Expand Up @@ -562,11 +562,13 @@ void snd_soc_dai_link_set_capabilities(struct snd_soc_dai_link *dai_link)
}
EXPORT_SYMBOL_GPL(snd_soc_dai_link_set_capabilities);

void snd_soc_dai_action(struct snd_soc_dai *dai,
void snd_soc_dai_action(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai,
int stream, int action)
{
/* see snd_soc_dai_stream_active() */
dai->stream_active[stream] += action;
enum snd_soc_dir txrx = snd_soc_convert_stream_to_txrx_via_dai(rtd, dai, stream);

/* see snd_soc_dai_txrx_active() */
dai->txrx_active[txrx] += action;

/* see snd_soc_component_active() */
dai->component->active += action;
Expand All @@ -575,11 +577,11 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_action);

int snd_soc_dai_active(struct snd_soc_dai *dai)
{
int stream, active;
int txrx, active;

active = 0;
for_each_pcm_streams(stream)
active += dai->stream_active[stream];
for_each_pcm_txrx(txrx)
active += dai->txrx_active[txrx];

return active;
}
Expand Down
9 changes: 5 additions & 4 deletions sound/soc/soc-dapm.c
Expand Up @@ -3860,7 +3860,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
if (ret < 0)
goto out;

snd_soc_dai_activate(source, substream->stream);
snd_soc_dai_activate(rtd, source, substream->stream);
}

substream->stream = SNDRV_PCM_STREAM_PLAYBACK;
Expand All @@ -3871,7 +3871,7 @@ snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
if (ret < 0)
goto out;

snd_soc_dai_activate(sink, substream->stream);
snd_soc_dai_activate(rtd, sink, substream->stream);
}

substream->hw_opened = 1;
Expand Down Expand Up @@ -3948,6 +3948,7 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
struct snd_soc_dapm_path *path;
struct snd_soc_dai *source, *sink;
struct snd_pcm_substream *substream = w->priv;
struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
int ret = 0, saved_stream = substream->stream;

if (WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) ||
Expand Down Expand Up @@ -3994,14 +3995,14 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
substream->stream = SNDRV_PCM_STREAM_CAPTURE;
snd_soc_dapm_widget_for_each_source_path(w, path) {
source = path->source->priv;
snd_soc_dai_deactivate(source, substream->stream);
snd_soc_dai_deactivate(rtd, source, substream->stream);
snd_soc_dai_shutdown(source, substream, 0);
}

substream->stream = SNDRV_PCM_STREAM_PLAYBACK;
snd_soc_dapm_widget_for_each_sink_path(w, path) {
sink = path->sink->priv;
snd_soc_dai_deactivate(sink, substream->stream);
snd_soc_dai_deactivate(rtd, sink, substream->stream);
snd_soc_dai_shutdown(sink, substream, 0);
}
break;
Expand Down
8 changes: 4 additions & 4 deletions sound/soc/soc-pcm.c
Expand Up @@ -289,7 +289,7 @@ void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
snd_soc_dpcm_mutex_assert_held(rtd);

for_each_rtd_dais(rtd, i, dai)
snd_soc_dai_action(dai, stream, action);
snd_soc_dai_action(rtd, dai, stream, action);
}
EXPORT_SYMBOL_GPL(snd_soc_runtime_action);

Expand Down Expand Up @@ -945,7 +945,7 @@ static int soc_pcm_hw_clean(struct snd_soc_pcm_runtime *rtd,
if (snd_soc_dai_active(dai) == 1)
soc_pcm_set_dai_params(dai, NULL);

if (snd_soc_dai_stream_active(dai, substream->stream) == 1)
if (snd_soc_dai_stream_active(rtd, dai, substream->stream) == 1)
snd_soc_dai_digital_mute(dai, 1, substream->stream);
}

Expand Down Expand Up @@ -2642,8 +2642,8 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
continue;

/* skip if FE isn't currently playing/capturing */
if (!snd_soc_dai_stream_active(asoc_rtd_to_cpu(fe, 0), stream) ||
!snd_soc_dai_stream_active(asoc_rtd_to_codec(fe, 0), stream))
if (!snd_soc_dai_stream_active(fe, asoc_rtd_to_cpu(fe, 0), stream) ||
!snd_soc_dai_stream_active(fe, asoc_rtd_to_codec(fe, 0), stream))
continue;

paths = dpcm_path_get(fe, stream, &list);
Expand Down

0 comments on commit 13230e8

Please sign in to comment.