Skip to content

Commit

Permalink
ASoC: add for_each_dpcm_be() macro
Browse files Browse the repository at this point in the history
To be more readable code, this patch adds
new for_each_dpcm_be() macro, and replace existing code to it.

Signed-off-by: Kuninori Morimoto <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
morimoto authored and broonie committed Sep 20, 2018
1 parent d2e24d6 commit 8d6258a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
7 changes: 7 additions & 0 deletions include/sound/soc-dpcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ struct snd_soc_dpcm_runtime {
#define for_each_dpcm_fe(be, stream, dpcm) \
list_for_each_entry(dpcm, &(be)->dpcm[stream].fe_clients, list_fe)

#define for_each_dpcm_be(fe, stream, dpcm) \
list_for_each_entry(dpcm, &(fe)->dpcm[stream].be_clients, list_be)
#define for_each_dpcm_be_safe(fe, stream, dpcm, _dpcm) \
list_for_each_entry_safe(dpcm, _dpcm, &(fe)->dpcm[stream].be_clients, list_be)
#define for_each_dpcm_be_rollback(fe, stream, dpcm) \
list_for_each_entry_continue_reverse(dpcm, &(fe)->dpcm[stream].be_clients, list_be)

/* can this BE stop and free */
int snd_soc_dpcm_can_be_free_stop(struct snd_soc_pcm_runtime *fe,
struct snd_soc_pcm_runtime *be, int stream);
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/fsl/fsl_asrc_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int fsl_asrc_dma_hw_params(struct snd_pcm_substream *substream,
int ret;

/* Fetch the Back-End dma_data from DPCM */
list_for_each_entry(dpcm, &rtd->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(rtd, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *substream_be;
struct snd_soc_dai *dai = be->cpu_dai;
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/sh/rcar/ctu.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static int rsnd_ctu_hw_params(struct rsnd_mod *mod,
struct snd_pcm_hw_params *be_params;
int stream = substream->stream;

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
be_params = &dpcm->hw_params;
if (params_channels(fe_params) != params_channels(be_params))
ctu->channels = params_channels(be_params);
Expand Down
2 changes: 1 addition & 1 deletion sound/soc/sh/rcar/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ static int rsnd_src_hw_params(struct rsnd_mod *mod,
struct snd_soc_dpcm *dpcm;
struct snd_pcm_hw_params *be_params;

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
be_params = &dpcm->hw_params;

if (params_rate(fe_params) != params_rate(be_params))
Expand Down
4 changes: 2 additions & 2 deletions sound/soc/soc-compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
ret = dpcm_be_dai_startup(fe, stream);
if (ret < 0) {
/* clean up all links */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
for_each_dpcm_be(fe, stream, dpcm)
dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;

dpcm_be_disconnect(fe, stream);
Expand Down Expand Up @@ -321,7 +321,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
ret = dpcm_be_dai_shutdown(fe, stream);

/* mark FE's links ready to prune */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
for_each_dpcm_be(fe, stream, dpcm)
dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;

dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
Expand Down
48 changes: 23 additions & 25 deletions sound/soc/soc-pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ int dpcm_dapm_stream_event(struct snd_soc_pcm_runtime *fe, int dir,
{
struct snd_soc_dpcm *dpcm;

list_for_each_entry(dpcm, &fe->dpcm[dir].be_clients, list_be) {
for_each_dpcm_be(fe, dir, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;

Expand Down Expand Up @@ -1211,7 +1211,7 @@ static int dpcm_be_connect(struct snd_soc_pcm_runtime *fe,
struct snd_soc_dpcm *dpcm;

/* only add new dpcms */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
if (dpcm->be == be && dpcm->fe == fe)
return 0;
}
Expand Down Expand Up @@ -1272,7 +1272,7 @@ void dpcm_be_disconnect(struct snd_soc_pcm_runtime *fe, int stream)
{
struct snd_soc_dpcm *dpcm, *d;

list_for_each_entry_safe(dpcm, d, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be_safe(fe, stream, dpcm, d) {
dev_dbg(fe->dev, "ASoC: BE %s disconnect check for %s\n",
stream ? "capture" : "playback",
dpcm->be->dai_link->name);
Expand Down Expand Up @@ -1438,7 +1438,7 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
int prune = 0;

/* Destroy any old FE <--> BE connections */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
unsigned int i;

/* is there a valid CPU DAI widget for this BE */
Expand Down Expand Up @@ -1544,7 +1544,7 @@ void dpcm_clear_pending_state(struct snd_soc_pcm_runtime *fe, int stream)
{
struct snd_soc_dpcm *dpcm;

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
for_each_dpcm_be(fe, stream, dpcm)
dpcm->be->dpcm[stream].runtime_update =
SND_SOC_DPCM_UPDATE_NO;
}
Expand All @@ -1555,7 +1555,7 @@ static void dpcm_be_dai_startup_unwind(struct snd_soc_pcm_runtime *fe,
struct snd_soc_dpcm *dpcm;

/* disable any enabled and non active backends */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
Expand Down Expand Up @@ -1584,7 +1584,7 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
int err, count = 0;

/* only startup BE DAIs that are either sinks or sources to this FE DAI */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
Expand Down Expand Up @@ -1638,7 +1638,7 @@ int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)

unwind:
/* disable any enabled and non active backends */
list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be_rollback(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
snd_soc_dpcm_get_substream(be, stream);
Expand Down Expand Up @@ -1695,7 +1695,7 @@ static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream,
* if FE want to use it (= dpcm_merged_format)
*/

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_soc_dai_driver *codec_dai_drv;
struct snd_soc_pcm_stream *codec_stream;
Expand Down Expand Up @@ -1736,7 +1736,7 @@ static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,
* if FE want to use it (= dpcm_merged_chan)
*/

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_soc_dai_driver *cpu_dai_drv = be->cpu_dai->driver;
struct snd_soc_dai_driver *codec_dai_drv;
Expand Down Expand Up @@ -1788,7 +1788,7 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,
* if FE want to use it (= dpcm_merged_chan)
*/

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_soc_dai_driver *cpu_dai_drv = be->cpu_dai->driver;
struct snd_soc_dai_driver *codec_dai_drv;
Expand Down Expand Up @@ -1891,7 +1891,7 @@ static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
}

/* apply symmetry for BE */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
snd_soc_dpcm_get_substream(be, stream);
Expand Down Expand Up @@ -1976,7 +1976,7 @@ int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
struct snd_soc_dpcm *dpcm;

/* only shutdown BEs that are either sinks or sources to this FE DAI */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
Expand Down Expand Up @@ -2040,7 +2040,7 @@ int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)

/* only hw_params backends that are either sinks or sources
* to this frontend DAI */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
Expand Down Expand Up @@ -2109,7 +2109,7 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)
struct snd_soc_dpcm *dpcm;
int ret;

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
Expand Down Expand Up @@ -2160,7 +2160,7 @@ int dpcm_be_dai_hw_params(struct snd_soc_pcm_runtime *fe, int stream)

unwind:
/* disable any enabled and non active backends */
list_for_each_entry_continue_reverse(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be_rollback(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
snd_soc_dpcm_get_substream(be, stream);
Expand Down Expand Up @@ -2240,7 +2240,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
struct snd_soc_dpcm *dpcm;
int ret = 0;

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
Expand Down Expand Up @@ -2426,7 +2426,7 @@ int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
struct snd_soc_dpcm *dpcm;
int ret = 0;

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;
struct snd_pcm_substream *be_substream =
Expand Down Expand Up @@ -2636,7 +2636,7 @@ static int dpcm_run_update_startup(struct snd_soc_pcm_runtime *fe, int stream)
dpcm_be_dai_shutdown(fe, stream);
disconnect:
/* disconnect any non started BEs */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;
Expand Down Expand Up @@ -2781,11 +2781,9 @@ int soc_dpcm_runtime_update(struct snd_soc_card *card)
int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
{
struct snd_soc_dpcm *dpcm;
struct list_head *clients =
&fe->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients;
struct snd_soc_dai *dai;

list_for_each_entry(dpcm, clients, list_be) {
for_each_dpcm_be(fe, SNDRV_PCM_STREAM_PLAYBACK, dpcm) {

struct snd_soc_pcm_runtime *be = dpcm->be;
int i;
Expand Down Expand Up @@ -2834,7 +2832,7 @@ static int dpcm_fe_dai_open(struct snd_pcm_substream *fe_substream)
ret = dpcm_fe_dai_startup(fe_substream);
if (ret < 0) {
/* clean up all links */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
for_each_dpcm_be(fe, stream, dpcm)
dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;

dpcm_be_disconnect(fe, stream);
Expand All @@ -2857,7 +2855,7 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
ret = dpcm_fe_dai_shutdown(fe_substream);

/* mark FE's links ready to prune */
list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be)
for_each_dpcm_be(fe, stream, dpcm)
dpcm->state = SND_SOC_DPCM_LINK_STATE_FREE;

dpcm_be_disconnect(fe, stream);
Expand Down Expand Up @@ -3326,7 +3324,7 @@ static ssize_t dpcm_show_state(struct snd_soc_pcm_runtime *fe,
goto out;
}

list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
for_each_dpcm_be(fe, stream, dpcm) {
struct snd_soc_pcm_runtime *be = dpcm->be;
params = &dpcm->hw_params;

Expand Down

0 comments on commit 8d6258a

Please sign in to comment.