Commit cca46db7 authored by Mark Brown's avatar Mark Brown

Merge series "ASoC: compress: Support module_get on stream open" from Peter...

Merge series "ASoC: compress: Support module_get on stream open" from Peter Ujfalusi <peter.ujfalusi@linux.intel.com>:

Hi,

SOF is marking all componet drivers with module_get_upon_open = 1 which works
fine with normal PCM streams, however on compressed side the module get upon
open is not supported. The module_get works when module_get_upon_open is not set
becasue the snd_soc_component_module_get_when_probe() will pass NULL for the
substream parameter of snd_soc_component_module_get().

In order to re-use the existing infrastructure for module_get, the proposal is
to convert the mark_module to void pointer (like the pm mark) and implement
matching code for the compressed open/free to pcm open/close.

Regards,
Peter
---
Peter Ujfalusi (2):
  ASoC: soc-component: Convert the mark_module to void*
  ASoC: compress/component: Use module_get_when_open/put_when_close for
    cstream

 include/sound/soc-component.h | 14 ++++----
 sound/soc/soc-component.c     | 61 +++++++++++++++--------------------
 sound/soc/soc-compress.c      | 43 +++++++++++++++++++++---
 3 files changed, 71 insertions(+), 47 deletions(-)

--
2.33.0
parents 2a07ef63 cd46f382
...@@ -220,7 +220,7 @@ struct snd_soc_component { ...@@ -220,7 +220,7 @@ struct snd_soc_component {
int (*init)(struct snd_soc_component *component); int (*init)(struct snd_soc_component *component);
/* function mark */ /* function mark */
struct snd_pcm_substream *mark_module; void *mark_module;
struct snd_pcm_substream *mark_open; struct snd_pcm_substream *mark_open;
struct snd_pcm_substream *mark_hw_params; struct snd_pcm_substream *mark_hw_params;
struct snd_pcm_substream *mark_trigger; struct snd_pcm_substream *mark_trigger;
...@@ -391,15 +391,13 @@ void snd_soc_component_exit_regmap(struct snd_soc_component *component); ...@@ -391,15 +391,13 @@ void snd_soc_component_exit_regmap(struct snd_soc_component *component);
#define snd_soc_component_module_get_when_open(component, substream) \ #define snd_soc_component_module_get_when_open(component, substream) \
snd_soc_component_module_get(component, substream, 1) snd_soc_component_module_get(component, substream, 1)
int snd_soc_component_module_get(struct snd_soc_component *component, int snd_soc_component_module_get(struct snd_soc_component *component,
struct snd_pcm_substream *substream, void *mark, int upon_open);
int upon_open);
#define snd_soc_component_module_put_when_remove(component) \ #define snd_soc_component_module_put_when_remove(component) \
snd_soc_component_module_put(component, NULL, 0, 0) snd_soc_component_module_put(component, NULL, 0, 0)
#define snd_soc_component_module_put_when_close(component, substream, rollback) \ #define snd_soc_component_module_put_when_close(component, substream, rollback) \
snd_soc_component_module_put(component, substream, 1, rollback) snd_soc_component_module_put(component, substream, 1, rollback)
void snd_soc_component_module_put(struct snd_soc_component *component, void snd_soc_component_module_put(struct snd_soc_component *component,
struct snd_pcm_substream *substream, void *mark, int upon_open, int rollback);
int upon_open, int rollback);
static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c, static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
void *data) void *data)
...@@ -455,8 +453,10 @@ int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, ...@@ -455,8 +453,10 @@ 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, int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
const struct of_phandle_args *args, const struct of_phandle_args *args,
const char **dai_name); const char **dai_name);
int snd_soc_component_compr_open(struct snd_compr_stream *cstream); int snd_soc_component_compr_open(struct snd_soc_component *component,
void snd_soc_component_compr_free(struct snd_compr_stream *cstream, struct snd_compr_stream *cstream);
void snd_soc_component_compr_free(struct snd_soc_component *component,
struct snd_compr_stream *cstream,
int rollback); int rollback);
int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd); 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, int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
......
...@@ -251,8 +251,7 @@ int snd_soc_component_set_jack(struct snd_soc_component *component, ...@@ -251,8 +251,7 @@ int snd_soc_component_set_jack(struct snd_soc_component *component,
EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
int snd_soc_component_module_get(struct snd_soc_component *component, int snd_soc_component_module_get(struct snd_soc_component *component,
struct snd_pcm_substream *substream, void *mark, int upon_open)
int upon_open)
{ {
int ret = 0; int ret = 0;
...@@ -260,25 +259,24 @@ int snd_soc_component_module_get(struct snd_soc_component *component, ...@@ -260,25 +259,24 @@ int snd_soc_component_module_get(struct snd_soc_component *component,
!try_module_get(component->dev->driver->owner)) !try_module_get(component->dev->driver->owner))
ret = -ENODEV; ret = -ENODEV;
/* mark substream if succeeded */ /* mark module if succeeded */
if (ret == 0) if (ret == 0)
soc_component_mark_push(component, substream, module); soc_component_mark_push(component, mark, module);
return soc_component_ret(component, ret); return soc_component_ret(component, ret);
} }
void snd_soc_component_module_put(struct snd_soc_component *component, void snd_soc_component_module_put(struct snd_soc_component *component,
struct snd_pcm_substream *substream, void *mark, int upon_open, int rollback)
int upon_open, int rollback)
{ {
if (rollback && !soc_component_mark_match(component, substream, module)) if (rollback && !soc_component_mark_match(component, mark, module))
return; return;
if (component->driver->module_get_upon_open == !!upon_open) if (component->driver->module_get_upon_open == !!upon_open)
module_put(component->dev->driver->owner); module_put(component->dev->driver->owner);
/* remove marked substream */ /* remove the mark from module */
soc_component_mark_pop(component, substream, module); soc_component_mark_pop(component, mark, module);
} }
int snd_soc_component_open(struct snd_soc_component *component, int snd_soc_component_open(struct snd_soc_component *component,
...@@ -425,43 +423,36 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); ...@@ -425,43 +423,36 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
#endif #endif
int snd_soc_component_compr_open(struct snd_compr_stream *cstream) int snd_soc_component_compr_open(struct snd_soc_component *component,
struct snd_compr_stream *cstream)
{ {
struct snd_soc_pcm_runtime *rtd = cstream->private_data; int ret = 0;
struct snd_soc_component *component;
int i, ret;
for_each_rtd_components(rtd, i, component) { if (component->driver->compress_ops &&
if (component->driver->compress_ops && component->driver->compress_ops->open)
component->driver->compress_ops->open) { ret = component->driver->compress_ops->open(component, cstream);
ret = component->driver->compress_ops->open(component, cstream);
if (ret < 0) /* mark substream if succeeded */
return soc_component_ret(component, ret); if (ret == 0)
}
soc_component_mark_push(component, cstream, compr_open); soc_component_mark_push(component, cstream, compr_open);
}
return 0; return soc_component_ret(component, ret);
} }
EXPORT_SYMBOL_GPL(snd_soc_component_compr_open); EXPORT_SYMBOL_GPL(snd_soc_component_compr_open);
void snd_soc_component_compr_free(struct snd_compr_stream *cstream, void snd_soc_component_compr_free(struct snd_soc_component *component,
struct snd_compr_stream *cstream,
int rollback) int rollback)
{ {
struct snd_soc_pcm_runtime *rtd = cstream->private_data; if (rollback && !soc_component_mark_match(component, cstream, compr_open))
struct snd_soc_component *component; return;
int i;
for_each_rtd_components(rtd, i, component) { if (component->driver->compress_ops &&
if (rollback && !soc_component_mark_match(component, cstream, compr_open)) component->driver->compress_ops->free)
continue; component->driver->compress_ops->free(component, cstream);
if (component->driver->compress_ops && /* remove marked substream */
component->driver->compress_ops->free) soc_component_mark_pop(component, cstream, compr_open);
component->driver->compress_ops->free(component, cstream);
soc_component_mark_pop(component, cstream, compr_open);
}
} }
EXPORT_SYMBOL_GPL(snd_soc_component_compr_free); EXPORT_SYMBOL_GPL(snd_soc_component_compr_free);
......
...@@ -22,6 +22,39 @@ ...@@ -22,6 +22,39 @@
#include <sound/soc-link.h> #include <sound/soc-link.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
static int snd_soc_compr_components_open(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_component *component;
int ret = 0;
int i;
for_each_rtd_components(rtd, i, component) {
ret = snd_soc_component_module_get_when_open(component, cstream);
if (ret < 0)
break;
ret = snd_soc_component_compr_open(component, cstream);
if (ret < 0)
break;
}
return ret;
}
static void snd_soc_compr_components_free(struct snd_compr_stream *cstream,
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) {
snd_soc_component_compr_free(component, cstream, rollback);
snd_soc_component_module_put_when_close(component, cstream, rollback);
}
}
static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback) static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
{ {
struct snd_soc_pcm_runtime *rtd = cstream->private_data; struct snd_soc_pcm_runtime *rtd = cstream->private_data;
...@@ -44,7 +77,7 @@ static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback) ...@@ -44,7 +77,7 @@ static int soc_compr_clean(struct snd_compr_stream *cstream, int rollback)
snd_soc_link_compr_shutdown(cstream, rollback); snd_soc_link_compr_shutdown(cstream, rollback);
snd_soc_component_compr_free(cstream, rollback); snd_soc_compr_components_free(cstream, rollback);
snd_soc_dai_compr_shutdown(cpu_dai, cstream, rollback); snd_soc_dai_compr_shutdown(cpu_dai, cstream, rollback);
...@@ -80,7 +113,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream) ...@@ -80,7 +113,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
if (ret < 0) if (ret < 0)
goto err; goto err;
ret = snd_soc_component_compr_open(cstream); ret = snd_soc_compr_components_open(cstream);
if (ret < 0) if (ret < 0)
goto err; goto err;
...@@ -137,7 +170,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) ...@@ -137,7 +170,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = snd_soc_component_compr_open(cstream); ret = snd_soc_compr_components_open(cstream);
if (ret < 0) if (ret < 0)
goto open_err; goto open_err;
...@@ -160,7 +193,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) ...@@ -160,7 +193,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
return 0; return 0;
machine_err: machine_err:
snd_soc_component_compr_free(cstream, 1); snd_soc_compr_components_free(cstream, 1);
open_err: open_err:
snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1); snd_soc_dai_compr_shutdown(cpu_dai, cstream, 1);
out: out:
...@@ -205,7 +238,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream) ...@@ -205,7 +238,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
snd_soc_link_compr_shutdown(cstream, 0); snd_soc_link_compr_shutdown(cstream, 0);
snd_soc_component_compr_free(cstream, 0); snd_soc_compr_components_free(cstream, 0);
snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0); snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment