From eb84959ab8c0ca2897e69575110bdaaf2d532eb7 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 30 Oct 2020 10:01:15 +0900 Subject: ASoC: soc-compress: tidyup STREAM vs COMPRESS snd_soc_runtime_activate() and snd_soc_dai_digital_mute() need SNDRV_PCM_STREAM_xxx instead of SND_COMPRESS_xxx. These are bug but nothing happen because these are same value. enum { SNDRV_PCM_STREAM_PLAYBACK = 0, SNDRV_PCM_STREAM_CAPTURE, ... }; enum snd_compr_direction { SND_COMPRESS_PLAYBACK = 0, SND_COMPRESS_CAPTURE }; This patch tidyup it. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/874kmcmsyn.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-compress.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 3a6a60215e81..52544a85725d 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -75,8 +75,14 @@ static int soc_compr_open(struct snd_compr_stream *cstream) struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_component *component = NULL; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); + int stream; int ret; + if (cstream->direction == SND_COMPRESS_PLAYBACK) + stream = SNDRV_PCM_STREAM_PLAYBACK; + else + stream = SNDRV_PCM_STREAM_CAPTURE; + ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream); if (ret < 0) goto pm_err; @@ -95,7 +101,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) if (ret < 0) goto machine_err; - snd_soc_runtime_activate(rtd, cstream->direction); + snd_soc_runtime_activate(rtd, stream); mutex_unlock(&rtd->card->pcm_mutex); @@ -208,7 +214,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream) snd_soc_runtime_deactivate(rtd, stream); - snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); + snd_soc_dai_digital_mute(codec_dai, 1, stream); if (!snd_soc_dai_active(cpu_dai)) cpu_dai->rate = 0; @@ -304,10 +310,16 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); + int stream; int ret; mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + if (cstream->direction == SND_COMPRESS_PLAYBACK) + stream = SNDRV_PCM_STREAM_PLAYBACK; + else + stream = SNDRV_PCM_STREAM_CAPTURE; + ret = soc_compr_components_trigger(cstream, cmd); if (ret < 0) goto out; @@ -318,10 +330,10 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) switch (cmd) { case SNDRV_PCM_TRIGGER_START: - snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction); + snd_soc_dai_digital_mute(codec_dai, 0, stream); break; case SNDRV_PCM_TRIGGER_STOP: - snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction); + snd_soc_dai_digital_mute(codec_dai, 1, stream); break; } -- cgit v1.2.3 From 7428d8c8bd7936840b4615df674cee5fce1eb385 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 30 Oct 2020 10:01:22 +0900 Subject: ASoC: soc-compress: assume SNDRV_PCM_STREAM_xxx and SND_COMPRESS_xxx are same soc-compress.c is using both SND_COMPRESS_xxx and SND_PCM_STREAM_xxx. These are defined as UAPI, and has same value. enum { SNDRV_PCM_STREAM_PLAYBACK = 0, SNDRV_PCM_STREAM_CAPTURE, ... }; enum snd_compr_direction { SND_COMPRESS_PLAYBACK = 0, SND_COMPRESS_CAPTURE }; Essentially both COMPRESS and PCM_STREAM definitions are identical, and can be never different because of ABI compatibility, which means it's safe to mix both variants in the code. This patch checks it by BUILD_BUG_ON(), and merge to use. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87361wmsyg.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-compress.c | 67 ++++++++++++++---------------------------------- 1 file changed, 19 insertions(+), 48 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 52544a85725d..c7ad52a21a29 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -75,14 +75,9 @@ static int soc_compr_open(struct snd_compr_stream *cstream) struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_component *component = NULL; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); - int stream; + int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ int ret; - if (cstream->direction == SND_COMPRESS_PLAYBACK) - stream = SNDRV_PCM_STREAM_PLAYBACK; - else - stream = SNDRV_PCM_STREAM_CAPTURE; - ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream); if (ret < 0) goto pm_err; @@ -128,14 +123,9 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); struct snd_soc_dpcm *dpcm; struct snd_soc_dapm_widget_list *list; - int stream; + int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ int ret; - if (cstream->direction == SND_COMPRESS_PLAYBACK) - stream = SNDRV_PCM_STREAM_PLAYBACK; - else - stream = SNDRV_PCM_STREAM_CAPTURE; - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); fe->dpcm[stream].runtime = fe_substream->runtime; @@ -203,15 +193,10 @@ static int soc_compr_free(struct snd_compr_stream *cstream) struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); - int stream; + 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); - if (cstream->direction == SND_COMPRESS_PLAYBACK) - stream = SNDRV_PCM_STREAM_PLAYBACK; - else - stream = SNDRV_PCM_STREAM_CAPTURE; - snd_soc_runtime_deactivate(rtd, stream); snd_soc_dai_digital_mute(codec_dai, 1, stream); @@ -242,15 +227,11 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) struct snd_soc_pcm_runtime *fe = cstream->private_data; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); struct snd_soc_dpcm *dpcm; - int stream, ret; + int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ + int ret; mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); - if (cstream->direction == SND_COMPRESS_PLAYBACK) - stream = SNDRV_PCM_STREAM_PLAYBACK; - else - stream = SNDRV_PCM_STREAM_CAPTURE; - snd_soc_runtime_deactivate(fe, stream); fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; @@ -310,16 +291,11 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); - int stream; + 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); - if (cstream->direction == SND_COMPRESS_PLAYBACK) - stream = SNDRV_PCM_STREAM_PLAYBACK; - else - stream = SNDRV_PCM_STREAM_CAPTURE; - ret = soc_compr_components_trigger(cstream, cmd); if (ret < 0) goto out; @@ -346,17 +322,13 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) { struct snd_soc_pcm_runtime *fe = cstream->private_data; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); - int ret, stream; + int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ + int ret; if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || cmd == SND_COMPR_TRIGGER_DRAIN) return soc_compr_components_trigger(cstream, cmd); - if (cstream->direction == SND_COMPRESS_PLAYBACK) - stream = SNDRV_PCM_STREAM_PLAYBACK; - else - stream = SNDRV_PCM_STREAM_CAPTURE; - mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd); @@ -418,6 +390,7 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream, { struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); + 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); @@ -441,12 +414,7 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream, if (ret < 0) goto err; - if (cstream->direction == SND_COMPRESS_PLAYBACK) - snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, - SND_SOC_DAPM_STREAM_START); - else - snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_CAPTURE, - SND_SOC_DAPM_STREAM_START); + snd_soc_dapm_stream_event(rtd, stream, SND_SOC_DAPM_STREAM_START); /* cancel any delayed stream shutdown that is pending */ rtd->pop_wait = 0; @@ -468,12 +436,8 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, struct snd_pcm_substream *fe_substream = fe->pcm->streams[cstream->direction].substream; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); - int ret, stream; - - if (cstream->direction == SND_COMPRESS_PLAYBACK) - stream = SNDRV_PCM_STREAM_PLAYBACK; - else - stream = SNDRV_PCM_STREAM_CAPTURE; + int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ + int ret; mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); @@ -771,6 +735,13 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) int playback = 0, capture = 0; int i; + /* + * make sure these are same value, + * and then use these as equally + */ + BUILD_BUG_ON((int)SNDRV_PCM_STREAM_PLAYBACK != (int)SND_COMPRESS_PLAYBACK); + BUILD_BUG_ON((int)SNDRV_PCM_STREAM_CAPTURE != (int)SND_COMPRESS_CAPTURE); + if (rtd->num_cpus > 1 || rtd->num_codecs > 1) { dev_err(rtd->card->dev, -- cgit v1.2.3 From a4e427c59a266dc3eb0eb5d52879b067a6f6e73b Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:15:20 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_open() component related function should be implemented at soc-component.c. This patch moves soc-compress soc_compr_components_open() to soc-component as snd_soc_component_compr_open(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87ft5d7v7x.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 23 +++++++++++++++++++++++ sound/soc/soc-compress.c | 31 ++----------------------------- 3 files changed, 27 insertions(+), 29 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 21f1d120b68e..0d79a0b30aba 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -444,6 +444,8 @@ int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, struct of_phandle_args *args, const char **dai_name); +int snd_soc_component_compr_open(struct snd_compr_stream *cstream, + struct snd_soc_component **last); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 6d719c2db92e..a711bee11712 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -421,6 +421,29 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); #endif +int snd_soc_component_compr_open(struct snd_compr_stream *cstream, + struct snd_soc_component **last) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->open) { + ret = component->driver->compress_ops->open(component, cstream); + if (ret < 0) { + *last = component; + return soc_component_ret(component, ret); + } + } + } + + *last = NULL; + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_open); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index c7ad52a21a29..d55ea0db7901 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -22,33 +22,6 @@ #include #include -static int soc_compr_components_open(struct snd_compr_stream *cstream, - struct snd_soc_component **last) -{ - struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; - int i, ret; - - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->open) - continue; - - ret = component->driver->compress_ops->open(component, cstream); - if (ret < 0) { - dev_err(component->dev, - "Compress ASoC: can't open platform %s: %d\n", - component->name, ret); - - *last = component; - return ret; - } - } - - *last = NULL; - return 0; -} - static int soc_compr_components_free(struct snd_compr_stream *cstream, struct snd_soc_component *last) { @@ -88,7 +61,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) if (ret < 0) goto out; - ret = soc_compr_components_open(cstream, &component); + ret = snd_soc_component_compr_open(cstream, &component); if (ret < 0) goto machine_err; @@ -156,7 +129,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) if (ret < 0) goto out; - ret = soc_compr_components_open(cstream, &component); + ret = snd_soc_component_compr_open(cstream, &component); if (ret < 0) goto open_err; -- cgit v1.2.3 From dbde5e21140cd2ad9d9e8eeeb104755f5294ce9f Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:15:26 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_free() component related function should be implemented at soc-component.c. This patch moves soc-compress soc_compr_components_free() to soc-component as snd_soc_component_compr_free(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87eekx7v7r.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 18 ++++++++++++++++++ sound/soc/soc-compress.c | 29 ++++------------------------- 3 files changed, 24 insertions(+), 25 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 0d79a0b30aba..1b2ed4a463b2 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -446,6 +446,8 @@ int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, const char **dai_name); int snd_soc_component_compr_open(struct snd_compr_stream *cstream, struct snd_soc_component **last); +void snd_soc_component_compr_free(struct snd_compr_stream *cstream, + struct snd_soc_component *last); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index a711bee11712..5dcbdfe411f6 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -444,6 +444,24 @@ int snd_soc_component_compr_open(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_open); +void snd_soc_component_compr_free(struct snd_compr_stream *cstream, + struct snd_soc_component *last) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i; + + for_each_rtd_components(rtd, i, component) { + if (component == last) + break; + + if (component->driver->compress_ops && + component->driver->compress_ops->free) + component->driver->compress_ops->free(component, cstream); + } +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_free); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index d55ea0db7901..4517baf0e62c 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -22,27 +22,6 @@ #include #include -static int soc_compr_components_free(struct snd_compr_stream *cstream, - struct snd_soc_component *last) -{ - struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; - int i; - - for_each_rtd_components(rtd, i, component) { - if (component == last) - break; - - if (!component->driver->compress_ops || - !component->driver->compress_ops->free) - continue; - - component->driver->compress_ops->free(component, cstream); - } - - return 0; -} - static int soc_compr_open(struct snd_compr_stream *cstream) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; @@ -76,7 +55,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) return 0; machine_err: - soc_compr_components_free(cstream, component); + snd_soc_component_compr_free(cstream, component); snd_soc_dai_compr_shutdown(cpu_dai, cstream); out: @@ -150,7 +129,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) return 0; machine_err: - soc_compr_components_free(cstream, component); + snd_soc_component_compr_free(cstream, component); open_err: snd_soc_dai_compr_shutdown(cpu_dai, cstream); out: @@ -182,7 +161,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream) snd_soc_link_compr_shutdown(cstream); - soc_compr_components_free(cstream, NULL); + snd_soc_component_compr_free(cstream, NULL); snd_soc_dai_compr_shutdown(cpu_dai, cstream); @@ -230,7 +209,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) snd_soc_link_compr_shutdown(cstream); - soc_compr_components_free(cstream, NULL); + snd_soc_component_compr_free(cstream, NULL); snd_soc_dai_compr_shutdown(cpu_dai, cstream); -- cgit v1.2.3 From 08aee25114426ba988ccb27af057dcf7faaa61ac Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:15:33 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_trigger() component related function should be implemented at soc-component.c. This patch moves soc-compress soc_compr_components_trigger() to soc-component as snd_soc_component_compr_trigger(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87d00h7v7k.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 1 + sound/soc/soc-component.c | 20 ++++++++++++++++++++ sound/soc/soc-compress.c | 27 +++------------------------ 3 files changed, 24 insertions(+), 24 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 1b2ed4a463b2..6cb4a6a0bc39 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -448,6 +448,7 @@ int snd_soc_component_compr_open(struct snd_compr_stream *cstream, struct snd_soc_component **last); void snd_soc_component_compr_free(struct snd_compr_stream *cstream, struct snd_soc_component *last); +int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 5dcbdfe411f6..cf34545f4108 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -462,6 +462,26 @@ void snd_soc_component_compr_free(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_free); +int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->trigger) { + ret = component->driver->compress_ops->trigger( + component, cstream, cmd); + if (ret < 0) + return soc_component_ret(component, ret); + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_trigger); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 4517baf0e62c..d85bd1d1c119 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -217,27 +217,6 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) return 0; } -static int soc_compr_components_trigger(struct snd_compr_stream *cstream, - int cmd) -{ - struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; - int i, ret; - - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->trigger) - continue; - - ret = component->driver->compress_ops->trigger( - component, cstream, cmd); - if (ret < 0) - return ret; - } - - return 0; -} - static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; @@ -248,7 +227,7 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); - ret = soc_compr_components_trigger(cstream, cmd); + ret = snd_soc_component_compr_trigger(cstream, cmd); if (ret < 0) goto out; @@ -279,7 +258,7 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || cmd == SND_COMPR_TRIGGER_DRAIN) - return soc_compr_components_trigger(cstream, cmd); + return snd_soc_component_compr_trigger(cstream, cmd); mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); @@ -287,7 +266,7 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd) if (ret < 0) goto out; - ret = soc_compr_components_trigger(cstream, cmd); + ret = snd_soc_component_compr_trigger(cstream, cmd); if (ret < 0) goto out; -- cgit v1.2.3 From ff08cf80addacbf42d419c2ef5561562f765bda3 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:15:49 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_set_params() component related function should be implemented at soc-component.c. This patch moves soc-compress soc_compr_components_set_params() to soc-component as snd_soc_component_compr_set_params(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87blg17v74.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 21 +++++++++++++++++++++ sound/soc/soc-compress.c | 25 ++----------------------- 3 files changed, 25 insertions(+), 23 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 6cb4a6a0bc39..d18a16a0881b 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -449,6 +449,8 @@ int snd_soc_component_compr_open(struct snd_compr_stream *cstream, void snd_soc_component_compr_free(struct snd_compr_stream *cstream, struct snd_soc_component *last); int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd); +int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, + struct snd_compr_params *params); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index cf34545f4108..4afd63223724 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -482,6 +482,27 @@ int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd) } EXPORT_SYMBOL_GPL(snd_soc_component_compr_trigger); +int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, + struct snd_compr_params *params) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->set_params) { + ret = component->driver->compress_ops->set_params( + component, cstream, params); + if (ret < 0) + return soc_component_ret(component, ret); + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_params); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index d85bd1d1c119..437ccd121b99 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -295,27 +295,6 @@ out: return ret; } -static int soc_compr_components_set_params(struct snd_compr_stream *cstream, - struct snd_compr_params *params) -{ - struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; - int i, ret; - - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->set_params) - continue; - - ret = component->driver->compress_ops->set_params( - component, cstream, params); - if (ret < 0) - return ret; - } - - return 0; -} - static int soc_compr_set_params(struct snd_compr_stream *cstream, struct snd_compr_params *params) { @@ -337,7 +316,7 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream, if (ret < 0) goto err; - ret = soc_compr_components_set_params(cstream, params); + ret = snd_soc_component_compr_set_params(cstream, params); if (ret < 0) goto err; @@ -394,7 +373,7 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream, if (ret < 0) goto out; - ret = soc_compr_components_set_params(cstream, params); + ret = snd_soc_component_compr_set_params(cstream, params); if (ret < 0) goto out; -- cgit v1.2.3 From 77c221ecfed8762f65d17f3a6ee7b4f2cec61ae4 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:15:56 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_get_params() component related function should be implemented at soc-component.c. This patch adds snd_soc_component_compr_get_params(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87a6vl7v6x.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 20 ++++++++++++++++++++ sound/soc/soc-compress.c | 14 ++------------ 3 files changed, 24 insertions(+), 12 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index d18a16a0881b..6841c3037548 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -451,6 +451,8 @@ void snd_soc_component_compr_free(struct snd_compr_stream *cstream, int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd); int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, struct snd_compr_params *params); +int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream, + struct snd_codec *params); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 4afd63223724..f87071c6edb0 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -503,6 +503,26 @@ int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_params); +int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream, + struct snd_codec *params) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->get_params) { + ret = component->driver->compress_ops->get_params( + component, cstream, params); + return soc_component_ret(component, ret); + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_params); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 437ccd121b99..a98defdecad7 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -394,9 +394,8 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream, struct snd_codec *params) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); - int i, ret = 0; + int ret = 0; mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); @@ -404,16 +403,7 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream, if (ret < 0) goto err; - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->get_params) - continue; - - ret = component->driver->compress_ops->get_params( - component, cstream, params); - break; - } - + ret = snd_soc_component_compr_get_params(cstream, params); err: mutex_unlock(&rtd->card->pcm_mutex); return ret; -- cgit v1.2.3 From d67fcb2d8f15df6f98698f411d9cb8c221ab6c91 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:16:03 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_get_caps() component related function should be implemented at soc-component.c. This patch adds snd_soc_component_compr_get_caps(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/878sb57v6q.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 24 ++++++++++++++++++++++++ sound/soc/soc-compress.c | 27 ++------------------------- 3 files changed, 28 insertions(+), 25 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 6841c3037548..7fd45462963e 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -453,6 +453,8 @@ int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, struct snd_compr_params *params); int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream, struct snd_codec *params); +int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream, + struct snd_compr_caps *caps); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index f87071c6edb0..b885e96cc8ae 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -523,6 +523,30 @@ int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_params); +int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream, + struct snd_compr_caps *caps) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret = 0; + + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->get_caps) { + ret = component->driver->compress_ops->get_caps( + component, cstream, caps); + break; + } + } + + mutex_unlock(&rtd->card->pcm_mutex); + + return soc_component_ret(component, ret); +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_caps); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index a98defdecad7..e7530712ab91 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -409,29 +409,6 @@ err: return ret; } -static int soc_compr_get_caps(struct snd_compr_stream *cstream, - struct snd_compr_caps *caps) -{ - struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; - int i, ret = 0; - - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); - - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->get_caps) - continue; - - ret = component->driver->compress_ops->get_caps( - component, cstream, caps); - break; - } - - mutex_unlock(&rtd->card->pcm_mutex); - return ret; -} - static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream, struct snd_compr_codec_caps *codec) { @@ -596,7 +573,7 @@ static struct snd_compr_ops soc_compr_ops = { .trigger = soc_compr_trigger, .pointer = soc_compr_pointer, .ack = soc_compr_ack, - .get_caps = soc_compr_get_caps, + .get_caps = snd_soc_component_compr_get_caps, .get_codec_caps = soc_compr_get_codec_caps }; @@ -611,7 +588,7 @@ static struct snd_compr_ops soc_compr_dyn_ops = { .trigger = soc_compr_trigger_fe, .pointer = soc_compr_pointer, .ack = soc_compr_ack, - .get_caps = soc_compr_get_caps, + .get_caps = snd_soc_component_compr_get_caps, .get_codec_caps = soc_compr_get_codec_caps }; -- cgit v1.2.3 From 0f6fe09720a3f307ab9f218f052d40b7d4e42b4c Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:16:11 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_get_codec_caps() component related function should be implemented at soc-component.c. This patch adds snd_soc_component_compr_get_codec_caps(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/877dqp7v6i.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 24 ++++++++++++++++++++++++ sound/soc/soc-compress.c | 27 ++------------------------- 3 files changed, 28 insertions(+), 25 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 7fd45462963e..d91e0eb1546d 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -455,6 +455,8 @@ int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream, struct snd_codec *params); int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream, struct snd_compr_caps *caps); +int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, + struct snd_compr_codec_caps *codec); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index b885e96cc8ae..8fba1a395f1e 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -547,6 +547,30 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_caps); +int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, + struct snd_compr_codec_caps *codec) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret = 0; + + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->get_codec_caps) { + ret = component->driver->compress_ops->get_codec_caps( + component, cstream, codec); + break; + } + } + + mutex_unlock(&rtd->card->pcm_mutex); + + return soc_component_ret(component, ret); +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_codec_caps); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index e7530712ab91..a82bd02d5519 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -409,29 +409,6 @@ err: return ret; } -static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream, - struct snd_compr_codec_caps *codec) -{ - struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; - int i, ret = 0; - - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); - - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->get_codec_caps) - continue; - - ret = component->driver->compress_ops->get_codec_caps( - component, cstream, codec); - break; - } - - mutex_unlock(&rtd->card->pcm_mutex); - return ret; -} - static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; @@ -574,7 +551,7 @@ static struct snd_compr_ops soc_compr_ops = { .pointer = soc_compr_pointer, .ack = soc_compr_ack, .get_caps = snd_soc_component_compr_get_caps, - .get_codec_caps = soc_compr_get_codec_caps + .get_codec_caps = snd_soc_component_compr_get_codec_caps, }; /* ASoC Dynamic Compress operations */ @@ -589,7 +566,7 @@ static struct snd_compr_ops soc_compr_dyn_ops = { .pointer = soc_compr_pointer, .ack = soc_compr_ack, .get_caps = snd_soc_component_compr_get_caps, - .get_codec_caps = soc_compr_get_codec_caps + .get_codec_caps = snd_soc_component_compr_get_codec_caps, }; /** -- cgit v1.2.3 From 0506b88503645e71c18152693caee9cfa1dbf093 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:16:17 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_ack() component related function should be implemented at soc-component.c. This patch adds snd_soc_component_compr_ack(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/875z697v6c.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 1 + sound/soc/soc-component.c | 20 ++++++++++++++++++++ sound/soc/soc-compress.c | 15 ++------------- 3 files changed, 23 insertions(+), 13 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index d91e0eb1546d..ba0eb49f8885 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -457,6 +457,7 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream, struct snd_compr_caps *caps); int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, struct snd_compr_codec_caps *codec); +int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 8fba1a395f1e..832177e5094e 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -571,6 +571,26 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_codec_caps); +int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->ack) { + ret = component->driver->compress_ops->ack( + component, cstream, bytes); + if (ret < 0) + return soc_component_ret(component, ret); + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_ack); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index a82bd02d5519..234e1506ed43 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -412,9 +412,8 @@ err: static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); - int i, ret = 0; + int ret; mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); @@ -422,17 +421,7 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes) if (ret < 0) goto err; - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->ack) - continue; - - ret = component->driver->compress_ops->ack( - component, cstream, bytes); - if (ret < 0) - goto err; - } - + ret = snd_soc_component_compr_ack(cstream, bytes); err: mutex_unlock(&rtd->card->pcm_mutex); return ret; -- cgit v1.2.3 From 03ecea64e0ae26d7a8b53bce05a39b78022e1312 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:16:24 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_pointer() component related function should be implemented at soc-component.c. This patch adds snd_soc_component_compr_pointer(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/874klt7v65.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 20 ++++++++++++++++++++ sound/soc/soc-compress.c | 13 ++----------- 3 files changed, 24 insertions(+), 11 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index ba0eb49f8885..d4e396cc75c2 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -458,6 +458,8 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream, int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, struct snd_compr_codec_caps *codec); int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes); +int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream, + struct snd_compr_tstamp *tstamp); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 832177e5094e..3ff2f227b99e 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -591,6 +591,26 @@ int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes) } EXPORT_SYMBOL_GPL(snd_soc_component_compr_ack); +int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream, + struct snd_compr_tstamp *tstamp) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->pointer) { + ret = component->driver->compress_ops->pointer( + component, cstream, tstamp); + return soc_component_ret(component, ret); + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_pointer); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 234e1506ed43..eb5cb2f1823e 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -431,8 +431,7 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream, struct snd_compr_tstamp *tstamp) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; - int i, ret = 0; + 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); @@ -441,15 +440,7 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream, if (ret < 0) goto out; - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->pointer) - continue; - - ret = component->driver->compress_ops->pointer( - component, cstream, tstamp); - break; - } + ret = snd_soc_component_compr_pointer(cstream, tstamp); out: mutex_unlock(&rtd->card->pcm_mutex); return ret; -- cgit v1.2.3 From b5852e66b115172dc3a88cb476b99c21ac6ffed8 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:16:30 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_copy() component related function should be implemented at soc-component.c. This patch adds snd_soc_component_compr_copy(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87361d7v5z.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 24 ++++++++++++++++++++++++ sound/soc/soc-compress.c | 25 +------------------------ 3 files changed, 27 insertions(+), 24 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index d4e396cc75c2..535f22502e1e 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -460,6 +460,8 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream, int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes); int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream, struct snd_compr_tstamp *tstamp); +int snd_soc_component_compr_copy(struct snd_compr_stream *cstream, + char __user *buf, size_t count); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 3ff2f227b99e..77fcb6fc42fb 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -611,6 +611,30 @@ int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_pointer); +int snd_soc_component_compr_copy(struct snd_compr_stream *cstream, + char __user *buf, size_t count) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret = 0; + + mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->copy) { + ret = component->driver->compress_ops->copy( + component, cstream, buf, count); + break; + } + } + + mutex_unlock(&rtd->card->pcm_mutex); + + return soc_component_ret(component, ret); +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_copy); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index eb5cb2f1823e..4a202478a8d6 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -446,29 +446,6 @@ out: return ret; } -static int soc_compr_copy(struct snd_compr_stream *cstream, - char __user *buf, size_t count) -{ - struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; - int i, ret = 0; - - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); - - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->copy) - continue; - - ret = component->driver->compress_ops->copy( - component, cstream, buf, count); - break; - } - - mutex_unlock(&rtd->card->pcm_mutex); - return ret; -} - static int soc_compr_set_metadata(struct snd_compr_stream *cstream, struct snd_compr_metadata *metadata) { @@ -649,7 +626,7 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) !component->driver->compress_ops->copy) continue; - compr->ops->copy = soc_compr_copy; + compr->ops->copy = snd_soc_component_compr_copy; break; } -- cgit v1.2.3 From 1b308fb138eba8dd57198b25235d8369a42af293 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:16:36 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_set_metadata() component related function should be implemented at soc-component.c. This patch adds snd_soc_component_compr_set_metadata(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/871rgx7v5t.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 21 +++++++++++++++++++++ sound/soc/soc-compress.c | 16 ++-------------- 3 files changed, 25 insertions(+), 14 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 535f22502e1e..d23ebd5ce617 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -462,6 +462,8 @@ int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream, struct snd_compr_tstamp *tstamp); int snd_soc_component_compr_copy(struct snd_compr_stream *cstream, char __user *buf, size_t count); +int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream, + struct snd_compr_metadata *metadata); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 77fcb6fc42fb..ef2b97631748 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -635,6 +635,27 @@ int snd_soc_component_compr_copy(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_copy); +int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream, + struct snd_compr_metadata *metadata) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->set_metadata) { + ret = component->driver->compress_ops->set_metadata( + component, cstream, metadata); + if (ret < 0) + return soc_component_ret(component, ret); + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_metadata); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 4a202478a8d6..3d29b41cf96f 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -450,26 +450,14 @@ static int soc_compr_set_metadata(struct snd_compr_stream *cstream, struct snd_compr_metadata *metadata) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); - int i, ret; + int ret; ret = snd_soc_dai_compr_set_metadata(cpu_dai, cstream, metadata); if (ret < 0) return ret; - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->set_metadata) - continue; - - ret = component->driver->compress_ops->set_metadata( - component, cstream, metadata); - if (ret < 0) - return ret; - } - - return 0; + return snd_soc_component_compr_set_metadata(cstream, metadata); } static int soc_compr_get_metadata(struct snd_compr_stream *cstream, -- cgit v1.2.3 From bab78c238025c89df771631c54f6229f6c56fb26 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Fri, 13 Nov 2020 13:16:41 +0900 Subject: ASoC: soc-component: add snd_soc_component_compr_get_metadata() component related function should be implemented at soc-component.c. This patch adds snd_soc_component_compr_get_metadata(). Signed-off-by: Kuninori Morimoto Reviewed-by: Ranjani Sridharan Link: https://lore.kernel.org/r/87zh3l6gl8.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 2 ++ sound/soc/soc-component.c | 20 ++++++++++++++++++++ sound/soc/soc-compress.c | 14 ++------------ 3 files changed, 24 insertions(+), 12 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index d23ebd5ce617..984dd7353066 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -464,6 +464,8 @@ int snd_soc_component_compr_copy(struct snd_compr_stream *cstream, char __user *buf, size_t count); int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream, struct snd_compr_metadata *metadata); +int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream, + struct snd_compr_metadata *metadata); int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index ef2b97631748..5d3a8dcd8d49 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -656,6 +656,26 @@ int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream, } EXPORT_SYMBOL_GPL(snd_soc_component_compr_set_metadata); +int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream, + struct snd_compr_metadata *metadata) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_component *component; + int i, ret; + + for_each_rtd_components(rtd, i, component) { + if (component->driver->compress_ops && + component->driver->compress_ops->get_metadata) { + ret = component->driver->compress_ops->get_metadata( + component, cstream, metadata); + return soc_component_ret(component, ret); + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_component_compr_get_metadata); + static unsigned int soc_component_read_no_lock( struct snd_soc_component *component, unsigned int reg) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 3d29b41cf96f..5a751d5d3847 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -464,24 +464,14 @@ static int soc_compr_get_metadata(struct snd_compr_stream *cstream, struct snd_compr_metadata *metadata) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); - int i, ret; + int ret; ret = snd_soc_dai_compr_get_metadata(cpu_dai, cstream, metadata); if (ret < 0) return ret; - for_each_rtd_components(rtd, i, component) { - if (!component->driver->compress_ops || - !component->driver->compress_ops->get_metadata) - continue; - - return component->driver->compress_ops->get_metadata( - component, cstream, metadata); - } - - return 0; + return snd_soc_component_compr_get_metadata(cstream, metadata); } /* ASoC Compress operations */ -- cgit v1.2.3 From 15a7b8c13653cc88de2db89af486e904aedc75ec Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 19 Nov 2020 08:49:57 +0900 Subject: ASoC: soc-compress: move soc_compr_free() next to soc_compr_open() This patch moves soc_compr_free() next to soc_compr_open(). This is prepare for soc_compr_open() cleanup. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87o8ju5iwv.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-compress.c | 68 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 5a751d5d3847..792c2aa1a3c0 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -22,6 +22,40 @@ #include #include +static int soc_compr_free(struct snd_compr_stream *cstream) +{ + struct snd_soc_pcm_runtime *rtd = cstream->private_data; + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); + 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_runtime_deactivate(rtd, stream); + + snd_soc_dai_digital_mute(codec_dai, 1, stream); + + if (!snd_soc_dai_active(cpu_dai)) + cpu_dai->rate = 0; + + if (!snd_soc_dai_active(codec_dai)) + codec_dai->rate = 0; + + snd_soc_link_compr_shutdown(cstream); + + snd_soc_component_compr_free(cstream, NULL); + + snd_soc_dai_compr_shutdown(cpu_dai, cstream); + + snd_soc_dapm_stream_stop(rtd, stream); + + mutex_unlock(&rtd->card->pcm_mutex); + + snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 0); + + return 0; +} + static int soc_compr_open(struct snd_compr_stream *cstream) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; @@ -140,40 +174,6 @@ be_err: return ret; } -static int soc_compr_free(struct snd_compr_stream *cstream) -{ - struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); - 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_runtime_deactivate(rtd, stream); - - snd_soc_dai_digital_mute(codec_dai, 1, stream); - - if (!snd_soc_dai_active(cpu_dai)) - cpu_dai->rate = 0; - - if (!snd_soc_dai_active(codec_dai)) - codec_dai->rate = 0; - - snd_soc_link_compr_shutdown(cstream); - - snd_soc_component_compr_free(cstream, NULL); - - snd_soc_dai_compr_shutdown(cpu_dai, cstream); - - snd_soc_dapm_stream_stop(rtd, stream); - - mutex_unlock(&rtd->card->pcm_mutex); - - snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 0); - - return 0; -} - static int soc_compr_free_fe(struct snd_compr_stream *cstream) { struct snd_soc_pcm_runtime *fe = cstream->private_data; -- cgit v1.2.3 From 1e6a93cf74979e167cef8d29f6689705d9ec6735 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 19 Nov 2020 08:50:04 +0900 Subject: ASoC: soc-dai: add mark for snd_soc_dai_compr_startup/shutdown() soc_compr_open() does rollback when failed (A), but, it is almost same as soc_compr_free(). static int soc_compr_open(xxx) { ... if (ret < 0) goto xxx_err; ... return 0; ^ machine_err: | ... | out: (A) ... | pm_err: | ... v return ret; } The difference is soc_compr_free() is for all dai/component/substream, rollback is for succeeded part only. This kind of duplicated code can be a hotbed of bugs, thus, we want to share soc_compr_free() and rollback. => 1) snd_soc_dai_compr_startup/shutdown() 2) snd_soc_component_compr_open/free() 3) snd_soc_link_compr_startup/shutdown() This patch is for 1) snd_soc_dai_compr_startup/shutdown(), and adds new cstream mark. It will mark cstream when startup() was suceeded. If rollback happen *after* that, it will check rollback flag and marked cstream. It cares *previous* startup() only now, but we might want to check *whole* marked cstream in the future. This patch is using macro so that it can be easily adjust to it. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87mtze5iwp.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-dai.h | 4 +++- sound/soc/soc-compress.c | 8 ++++---- sound/soc/soc-dai.c | 13 ++++++++++++- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index 4bf759f025d2..6f54401d3de9 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -196,7 +196,8 @@ int snd_soc_pcm_dai_bespoke_trigger(struct snd_pcm_substream *substream, int snd_soc_dai_compr_startup(struct snd_soc_dai *dai, struct snd_compr_stream *cstream); void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai, - struct snd_compr_stream *cstream); + struct snd_compr_stream *cstream, + int rollback); int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai, struct snd_compr_stream *cstream, int cmd); int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai, @@ -400,6 +401,7 @@ struct snd_soc_dai { /* function mark */ struct snd_pcm_substream *mark_startup; struct snd_pcm_substream *mark_hw_params; + struct snd_compr_stream *mark_compr_startup; /* bit field */ unsigned int probed:1; diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 792c2aa1a3c0..d85b6b174006 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -45,7 +45,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream) snd_soc_component_compr_free(cstream, NULL); - snd_soc_dai_compr_shutdown(cpu_dai, cstream); + snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0); snd_soc_dapm_stream_stop(rtd, stream); @@ -91,7 +91,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) machine_err: snd_soc_component_compr_free(cstream, component); - snd_soc_dai_compr_shutdown(cpu_dai, cstream); + snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1); out: mutex_unlock(&rtd->card->pcm_mutex); pm_err: @@ -165,7 +165,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) machine_err: snd_soc_component_compr_free(cstream, component); open_err: - snd_soc_dai_compr_shutdown(cpu_dai, cstream); + snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1); out: dpcm_path_put(&list); be_err: @@ -211,7 +211,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) snd_soc_component_compr_free(cstream, NULL); - snd_soc_dai_compr_shutdown(cpu_dai, cstream); + snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0); mutex_unlock(&fe->card->mutex); return 0; diff --git a/sound/soc/soc-dai.c b/sound/soc/soc-dai.c index 2686a566649b..9afc6e8c3f9f 100644 --- a/sound/soc/soc-dai.c +++ b/sound/soc/soc-dai.c @@ -612,16 +612,27 @@ int snd_soc_dai_compr_startup(struct snd_soc_dai *dai, dai->driver->cops->startup) ret = dai->driver->cops->startup(cstream, dai); + /* mark cstream if succeeded */ + if (ret == 0) + soc_dai_mark_push(dai, cstream, compr_startup); + return soc_dai_ret(dai, ret); } EXPORT_SYMBOL_GPL(snd_soc_dai_compr_startup); void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai, - struct snd_compr_stream *cstream) + struct snd_compr_stream *cstream, + int rollback) { + if (rollback && !soc_dai_mark_match(dai, cstream, compr_startup)) + return; + if (dai->driver->cops && dai->driver->cops->shutdown) dai->driver->cops->shutdown(cstream, dai); + + /* remove marked cstream */ + soc_dai_mark_pop(dai, cstream, compr_startup); } EXPORT_SYMBOL_GPL(snd_soc_dai_compr_shutdown); -- cgit v1.2.3 From f94ba9ac20fab9af08240fde3741edf73655411d Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 19 Nov 2020 08:50:09 +0900 Subject: ASoC: soc-component: add mark for snd_soc_component_compr_open/free() soc_compr_open() does rollback when failed (A), but, it is almost same as soc_compr_free(). static int soc_compr_open(xxx) { ... if (ret < 0) goto xxx_err; ... return 0; ^ machine_err: | ... | out: (A) ... | pm_err: | ... v return ret; } The difference is soc_compr_free() is for all dai/component/substream, rollback is for succeeded part only. This kind of duplicated code can be a hotbed of bugs, thus, we want to share soc_compr_free() and rollback. 1) snd_soc_dai_compr_startup/shutdown() => 2) snd_soc_component_compr_open/free() 3) snd_soc_link_compr_startup/shutdown() This patch is for 2) snd_soc_component_compr_open/free(), and adds new cstream mark. It will mark cstream when startup() was suceeded. If rollback happen *after* that, it will check rollback flag and marked cstream. It cares *previous* startup() only now, but we might want to check *whole* marked cstream in the future. This patch is using macro so that it can be easily adjust to it. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87lfey5iwk.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-component.h | 6 +++--- sound/soc/soc-component.c | 17 ++++++++--------- sound/soc/soc-compress.c | 14 ++++++-------- 3 files changed, 17 insertions(+), 20 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 984dd7353066..9140b5fa19a4 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -221,6 +221,7 @@ struct snd_soc_component { struct snd_pcm_substream *mark_module; struct snd_pcm_substream *mark_open; struct snd_pcm_substream *mark_hw_params; + struct snd_compr_stream *mark_compr_open; void *mark_pm; #ifdef CONFIG_DEBUG_FS @@ -444,10 +445,9 @@ int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, struct of_phandle_args *args, const char **dai_name); -int snd_soc_component_compr_open(struct snd_compr_stream *cstream, - struct snd_soc_component **last); +int snd_soc_component_compr_open(struct snd_compr_stream *cstream); void snd_soc_component_compr_free(struct snd_compr_stream *cstream, - struct snd_soc_component *last); + int rollback); int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd); int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream, struct snd_compr_params *params); diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 5d3a8dcd8d49..434987a64353 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -421,8 +421,7 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); #endif -int snd_soc_component_compr_open(struct snd_compr_stream *cstream, - struct snd_soc_component **last) +int snd_soc_component_compr_open(struct snd_compr_stream *cstream) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_component *component; @@ -432,32 +431,32 @@ int snd_soc_component_compr_open(struct snd_compr_stream *cstream, if (component->driver->compress_ops && component->driver->compress_ops->open) { ret = component->driver->compress_ops->open(component, cstream); - if (ret < 0) { - *last = component; + if (ret < 0) return soc_component_ret(component, ret); - } } + soc_component_mark_push(component, cstream, compr_open); } - *last = NULL; return 0; } EXPORT_SYMBOL_GPL(snd_soc_component_compr_open); void snd_soc_component_compr_free(struct snd_compr_stream *cstream, - struct snd_soc_component *last) + int rollback) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_component *component; int i; for_each_rtd_components(rtd, i, component) { - if (component == last) - break; + if (rollback && !soc_component_mark_match(component, cstream, compr_open)) + continue; if (component->driver->compress_ops && component->driver->compress_ops->free) component->driver->compress_ops->free(component, cstream); + + soc_component_mark_pop(component, cstream, compr_open); } } EXPORT_SYMBOL_GPL(snd_soc_component_compr_free); diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index d85b6b174006..8b6a6bd482d1 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -43,7 +43,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream) snd_soc_link_compr_shutdown(cstream); - snd_soc_component_compr_free(cstream, NULL); + snd_soc_component_compr_free(cstream, 0); snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0); @@ -59,7 +59,6 @@ static int soc_compr_free(struct snd_compr_stream *cstream) static int soc_compr_open(struct snd_compr_stream *cstream) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; - struct snd_soc_component *component = NULL; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ int ret; @@ -74,7 +73,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) if (ret < 0) goto out; - ret = snd_soc_component_compr_open(cstream, &component); + ret = snd_soc_component_compr_open(cstream); if (ret < 0) goto machine_err; @@ -89,7 +88,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) return 0; machine_err: - snd_soc_component_compr_free(cstream, component); + snd_soc_component_compr_free(cstream, 1); snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1); out: @@ -105,7 +104,6 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) struct snd_soc_pcm_runtime *fe = cstream->private_data; struct snd_pcm_substream *fe_substream = fe->pcm->streams[cstream->direction].substream; - struct snd_soc_component *component; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(fe, 0); struct snd_soc_dpcm *dpcm; struct snd_soc_dapm_widget_list *list; @@ -142,7 +140,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) if (ret < 0) goto out; - ret = snd_soc_component_compr_open(cstream, &component); + ret = snd_soc_component_compr_open(cstream); if (ret < 0) goto open_err; @@ -163,7 +161,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) return 0; machine_err: - snd_soc_component_compr_free(cstream, component); + snd_soc_component_compr_free(cstream, 1); open_err: snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1); out: @@ -209,7 +207,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) snd_soc_link_compr_shutdown(cstream); - snd_soc_component_compr_free(cstream, NULL); + snd_soc_component_compr_free(cstream, 0); snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0); -- cgit v1.2.3 From cd7c7d10e8f4ab1dac0bdb2019abc0fad995a788 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 19 Nov 2020 08:50:14 +0900 Subject: ASoC: soc-component: add mark for snd_soc_link_compr_startup/shutdown() soc_compr_open() does rollback when failed (A), but, it is almost same as soc_compr_free(). static int soc_compr_open(xxx) { ... if (ret < 0) goto xxx_err; ... return 0; ^ machine_err: | ... | out: (A) ... | pm_err: | ... v return ret; } The difference is soc_compr_free() is for all dai/component/substream, rollback is for succeeded part only. This kind of duplicated code can be a hotbed of bugs, thus, we want to share soc_compr_free() and rollback. 1) snd_soc_dai_compr_startup/shutdown() 2) snd_soc_component_compr_open/free() => 3) snd_soc_link_compr_startup/shutdown() This patch is for 3) snd_soc_link_compr_startup/shutdown() and adds new cstream mark. It will mark cstream when startup() was suceeded. If rollback happen *after* that, it will check rollback flag and marked cstream. It cares *previous* startup() only now, but we might want to check *whole* marked cstream in the future. This patch is using macro so that it can be easily adjust to it. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87k0ui5iwf.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- include/sound/soc-link.h | 3 ++- include/sound/soc.h | 1 + sound/soc/soc-compress.c | 4 ++-- sound/soc/soc-link.c | 11 ++++++++++- 4 files changed, 15 insertions(+), 4 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/include/sound/soc-link.h b/include/sound/soc-link.h index eff34fc7d3d3..4c68b06d6fe6 100644 --- a/include/sound/soc-link.h +++ b/include/sound/soc-link.h @@ -24,7 +24,8 @@ void snd_soc_link_hw_free(struct snd_pcm_substream *substream, int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd); int snd_soc_link_compr_startup(struct snd_compr_stream *cstream); -void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream); +void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream, + int rollback); int snd_soc_link_compr_set_params(struct snd_compr_stream *cstream); #endif /* __SOC_LINK_H */ diff --git a/include/sound/soc.h b/include/sound/soc.h index 4a9958b9b532..33c289f6097c 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1163,6 +1163,7 @@ struct snd_soc_pcm_runtime { /* function mark */ struct snd_pcm_substream *mark_startup; struct snd_pcm_substream *mark_hw_params; + struct snd_compr_stream *mark_compr_startup; /* bit field */ unsigned int pop_wait:1; diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 8b6a6bd482d1..6de22b2f8197 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -41,7 +41,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream) if (!snd_soc_dai_active(codec_dai)) codec_dai->rate = 0; - snd_soc_link_compr_shutdown(cstream); + snd_soc_link_compr_shutdown(cstream, 0); snd_soc_component_compr_free(cstream, 0); @@ -205,7 +205,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) fe->dpcm[stream].runtime = NULL; - snd_soc_link_compr_shutdown(cstream); + snd_soc_link_compr_shutdown(cstream, 0); snd_soc_component_compr_free(cstream, 0); diff --git a/sound/soc/soc-link.c b/sound/soc/soc-link.c index 409ae4940da3..26cc60f8dcfb 100644 --- a/sound/soc/soc-link.c +++ b/sound/soc/soc-link.c @@ -162,17 +162,26 @@ int snd_soc_link_compr_startup(struct snd_compr_stream *cstream) rtd->dai_link->compr_ops->startup) ret = rtd->dai_link->compr_ops->startup(cstream); + if (ret == 0) + soc_link_mark_push(rtd, cstream, compr_startup); + return soc_link_ret(rtd, ret); } EXPORT_SYMBOL_GPL(snd_soc_link_compr_startup); -void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream) +void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream, + int rollback) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; + if (rollback && !soc_link_mark_match(rtd, cstream, compr_startup)) + return; + if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown) rtd->dai_link->compr_ops->shutdown(cstream); + + soc_link_mark_pop(rtd, cstream, compr_startup); } EXPORT_SYMBOL_GPL(snd_soc_link_compr_shutdown); -- cgit v1.2.3 From 453d32c2f7f7375c223eaf3a0a32efbb71bbd3f3 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Thu, 19 Nov 2020 08:50:19 +0900 Subject: ASoC: soc-compress: add soc_compr_clean() and call it from soc_compr_open/free() soc_compr_open() does rollback when failed (A), but, it is almost same as soc_compr_free(). static int soc_compr_open(xxx) { ... if (ret < 0) goto xxx_err; ... return 0; ^ machine_err: | ... | out: (A) ... | pm_err: | ... v return ret; } The difference is soc_compr_free() is for all dai/component/substream, rollback is for succeeded part only. This kind of duplicated code can be a hotbed of bugs, thus, we want to share soc_compr_free() and rollback. Now, soc_compr_open/free() are handling 1) snd_soc_dai_compr_startup/shutdown() 2) snd_soc_component_compr_open/free() 3) snd_soc_link_compr_startup/shutdown() Now, 1) to 3) are handled. This patch adds new soc_compr_clean() and call it from soc_compr_open() as rollback, and from soc_compr_free_free() as normal close handler. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87ima25iwa.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-compress.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'sound/soc/soc-compress.c') diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 6de22b2f8197..246a5e32e22a 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -22,7 +22,7 @@ #include #include -static int soc_compr_free(struct snd_compr_stream *cstream) +static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); @@ -31,7 +31,8 @@ static int soc_compr_free(struct snd_compr_stream *cstream) mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); - snd_soc_runtime_deactivate(rtd, stream); + if (!rollback) + snd_soc_runtime_deactivate(rtd, stream); snd_soc_dai_digital_mute(codec_dai, 1, stream); @@ -41,21 +42,27 @@ static int soc_compr_free(struct snd_compr_stream *cstream) if (!snd_soc_dai_active(codec_dai)) codec_dai->rate = 0; - snd_soc_link_compr_shutdown(cstream, 0); + snd_soc_link_compr_shutdown(cstream, rollback); - snd_soc_component_compr_free(cstream, 0); + snd_soc_component_compr_free(cstream, rollback); - snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0); + snd_soc_dai_compr_shutdown(cpu_dai, cstream, rollback); - snd_soc_dapm_stream_stop(rtd, stream); + if (!rollback) + snd_soc_dapm_stream_stop(rtd, stream); mutex_unlock(&rtd->card->pcm_mutex); - snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 0); + snd_soc_pcm_component_pm_runtime_put(rtd, cstream, rollback); return 0; } +static int soc_compr_free(struct snd_compr_stream *cstream) +{ + return soc_compr_clean(cstream, 0); +} + static int soc_compr_open(struct snd_compr_stream *cstream) { struct snd_soc_pcm_runtime *rtd = cstream->private_data; @@ -65,36 +72,28 @@ static int soc_compr_open(struct snd_compr_stream *cstream) ret = snd_soc_pcm_component_pm_runtime_get(rtd, cstream); if (ret < 0) - goto pm_err; + goto err_no_lock; mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); ret = snd_soc_dai_compr_startup(cpu_dai, cstream); if (ret < 0) - goto out; + goto err; ret = snd_soc_component_compr_open(cstream); if (ret < 0) - goto machine_err; + goto err; ret = snd_soc_link_compr_startup(cstream); if (ret < 0) - goto machine_err; + goto err; snd_soc_runtime_activate(rtd, stream); - - mutex_unlock(&rtd->card->pcm_mutex); - - return 0; - -machine_err: - snd_soc_component_compr_free(cstream, 1); - - snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1); -out: +err: mutex_unlock(&rtd->card->pcm_mutex); -pm_err: - snd_soc_pcm_component_pm_runtime_put(rtd, cstream, 1); +err_no_lock: + if (ret < 0) + soc_compr_clean(cstream, 1); return ret; } -- cgit v1.2.3