[alsa-devel] [RFC][PATCH 2/x] ASoC: snd_soc_component_driver has snd_compr_ops

Kuninori Morimoto kuninori.morimoto.gx at renesas.com
Tue Jun 20 04:27:01 CEST 2017


snd_soc_platform_driver has snd_compr_ops,
and it will be replaced into snd_soc_component_driver in the future.
To prepare it, component driver has it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
 include/sound/soc.h      |   1 +
 sound/soc/soc-compress.c | 116 +++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 97 insertions(+), 20 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 341a958..8ebfb53 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -810,6 +810,7 @@ struct snd_soc_component_driver {
 	int (*stream_event)(struct snd_soc_component *, int event);
 
 	const struct snd_pcm_ops *ops;
+	const struct snd_compr_ops *compr_ops;
 
 	/* probe ordering - for components with runtime dependencies */
 	int probe_order;
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index bfd71b8..61ebc1e 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -30,6 +30,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	int ret = 0;
 
@@ -44,7 +45,14 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
 		}
 	}
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->open) {
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->open) {
+		ret = platform_com->driver->compr_ops->open(cstream);
+		if (ret < 0) {
+			pr_err("compress asoc: can't open platform %s\n",
+			       platform_com->name);
+			goto plat_err;
+		}
+	} else if (platform->driver->compr_ops && platform->driver->compr_ops->open) {
 		ret = platform->driver->compr_ops->open(cstream);
 		if (ret < 0) {
 			pr_err("compress asoc: can't open platform %s\n",
@@ -68,7 +76,9 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
 	return 0;
 
 machine_err:
-	if (platform->driver->compr_ops && platform->driver->compr_ops->free)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->free)
+		platform_com->driver->compr_ops->free(cstream);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->free)
 		platform->driver->compr_ops->free(cstream);
 plat_err:
 	if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
@@ -83,6 +93,7 @@ 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[0].substream;
 	struct snd_soc_platform *platform = fe->platform;
+	struct snd_soc_component *platform_com = fe->platform_com;
 	struct snd_soc_dai *cpu_dai = fe->cpu_dai;
 	struct snd_soc_dpcm *dpcm;
 	struct snd_soc_dapm_widget_list *list;
@@ -106,7 +117,14 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
 	}
 
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->open) {
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->open) {
+		ret = platform_com->driver->compr_ops->open(cstream);
+		if (ret < 0) {
+			pr_err("compress asoc: can't open platform %s\n",
+			       platform_com->name);
+			goto plat_err;
+		}
+	} else if (platform->driver->compr_ops && platform->driver->compr_ops->open) {
 		ret = platform->driver->compr_ops->open(cstream);
 		if (ret < 0) {
 			pr_err("compress asoc: can't open platform %s\n",
@@ -166,7 +184,9 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
 	if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
 		fe->dai_link->compr_ops->shutdown(cstream);
 machine_err:
-	if (platform->driver->compr_ops && platform->driver->compr_ops->free)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->free)
+		platform_com->driver->compr_ops->free(cstream);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->free)
 		platform->driver->compr_ops->free(cstream);
 plat_err:
 	if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
@@ -209,6 +229,7 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
 	int stream;
@@ -234,7 +255,9 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
 	if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown)
 		rtd->dai_link->compr_ops->shutdown(cstream);
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->free)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->free)
+		platform_com->driver->compr_ops->free(cstream);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->free)
 		platform->driver->compr_ops->free(cstream);
 
 	if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
@@ -266,6 +289,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
 {
 	struct snd_soc_pcm_runtime *fe = cstream->private_data;
 	struct snd_soc_platform *platform = fe->platform;
+	struct snd_soc_component *platform_com = fe->platform_com;
 	struct snd_soc_dai *cpu_dai = fe->cpu_dai;
 	struct snd_soc_dpcm *dpcm;
 	int stream, ret;
@@ -303,7 +327,9 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
 	if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
 		fe->dai_link->compr_ops->shutdown(cstream);
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->free)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->free)
+		platform_com->driver->compr_ops->free(cstream);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->free)
 		platform->driver->compr_ops->free(cstream);
 
 	if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
@@ -318,13 +344,18 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
 
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	int ret = 0;
 
 	mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) {
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->trigger) {
+		ret = platform_com->driver->compr_ops->trigger(cstream, cmd);
+		if (ret < 0)
+			goto out;
+	} else if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) {
 		ret = platform->driver->compr_ops->trigger(cstream, cmd);
 		if (ret < 0)
 			goto out;
@@ -352,13 +383,18 @@ 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_platform *platform = fe->platform;
+	struct snd_soc_component *platform_com = fe->platform_com;
 	struct snd_soc_dai *cpu_dai = fe->cpu_dai;
 	int ret = 0, stream;
 
 	if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
 		cmd == SND_COMPR_TRIGGER_DRAIN) {
 
-		if (platform->driver->compr_ops &&
+		if (platform_com->driver->compr_ops &&
+		    platform_com->driver->compr_ops->trigger)
+			return platform_com->driver->compr_ops->trigger(cstream,
+									cmd);
+		else if (platform->driver->compr_ops &&
 		    platform->driver->compr_ops->trigger)
 			return platform->driver->compr_ops->trigger(cstream,
 								    cmd);
@@ -378,7 +414,11 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
 			goto out;
 	}
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) {
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->trigger) {
+		ret = platform_com->driver->compr_ops->trigger(cstream, cmd);
+		if (ret < 0)
+			goto out;
+	} else 	if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) {
 		ret = platform->driver->compr_ops->trigger(cstream, cmd);
 		if (ret < 0)
 			goto out;
@@ -414,6 +454,7 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	int ret = 0;
 
@@ -431,7 +472,11 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
 			goto err;
 	}
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) {
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->set_params) {
+		ret = platform_com->driver->compr_ops->set_params(cstream, params);
+		if (ret < 0)
+			goto err;
+	} else 	if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) {
 		ret = platform->driver->compr_ops->set_params(cstream, params);
 		if (ret < 0)
 			goto err;
@@ -469,6 +514,7 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
 	struct snd_soc_pcm_runtime *fe = cstream->private_data;
 	struct snd_pcm_substream *fe_substream = fe->pcm->streams[0].substream;
 	struct snd_soc_platform *platform = fe->platform;
+	struct snd_soc_component *platform_com = fe->platform_com;
 	struct snd_soc_dai *cpu_dai = fe->cpu_dai;
 	int ret = 0, stream;
 
@@ -485,7 +531,11 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
 			goto out;
 	}
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) {
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->set_params) {
+		ret = platform_com->driver->compr_ops->set_params(cstream, params);
+		if (ret < 0)
+			goto out;
+	} else 	if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) {
 		ret = platform->driver->compr_ops->set_params(cstream, params);
 		if (ret < 0)
 			goto out;
@@ -529,6 +579,7 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	int ret = 0;
 
@@ -540,7 +591,9 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
 			goto err;
 	}
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->get_params)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->get_params)
+		ret = platform_com->driver->compr_ops->get_params(cstream, params);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->get_params)
 		ret = platform->driver->compr_ops->get_params(cstream, params);
 
 err:
@@ -553,11 +606,14 @@ static int soc_compr_get_caps(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	int ret = 0;
 
 	mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->get_caps)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->get_caps)
+		ret = platform_com->driver->compr_ops->get_caps(cstream, caps);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->get_caps)
 		ret = platform->driver->compr_ops->get_caps(cstream, caps);
 
 	mutex_unlock(&rtd->pcm_mutex);
@@ -569,11 +625,14 @@ static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	int ret = 0;
 
 	mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->get_codec_caps)
+		ret = platform_com->driver->compr_ops->get_codec_caps(cstream, codec);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps)
 		ret = platform->driver->compr_ops->get_codec_caps(cstream, codec);
 
 	mutex_unlock(&rtd->pcm_mutex);
@@ -584,6 +643,7 @@ 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_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	int ret = 0;
 
@@ -595,7 +655,9 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
 			goto err;
 	}
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->ack)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->ack)
+		ret = platform_com->driver->compr_ops->ack(cstream, bytes);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->ack)
 		ret = platform->driver->compr_ops->ack(cstream, bytes);
 
 err:
@@ -608,6 +670,7 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	int ret = 0;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 
@@ -616,7 +679,9 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
 	if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer)
 		cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai);
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->pointer)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->pointer)
+		ret = platform_com->driver->compr_ops->pointer(cstream, tstamp);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->pointer)
 		ret = platform->driver->compr_ops->pointer(cstream, tstamp);
 
 	mutex_unlock(&rtd->pcm_mutex);
@@ -628,11 +693,14 @@ static int soc_compr_copy(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	int ret = 0;
 
 	mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->copy)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->copy)
+		ret = platform_com->driver->compr_ops->copy(cstream, buf, count);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->copy)
 		ret = platform->driver->compr_ops->copy(cstream, buf, count);
 
 	mutex_unlock(&rtd->pcm_mutex);
@@ -644,6 +712,7 @@ static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	int ret = 0;
 
@@ -653,7 +722,9 @@ static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
 			return ret;
 	}
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->set_metadata)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->set_metadata)
+		ret = platform_com->driver->compr_ops->set_metadata(cstream, metadata);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->set_metadata)
 		ret = platform->driver->compr_ops->set_metadata(cstream, metadata);
 
 	return ret;
@@ -664,6 +735,7 @@ static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
 {
 	struct snd_soc_pcm_runtime *rtd = cstream->private_data;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	int ret = 0;
 
@@ -673,7 +745,9 @@ static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
 			return ret;
 	}
 
-	if (platform->driver->compr_ops && platform->driver->compr_ops->get_metadata)
+	if (platform_com->driver->compr_ops && platform_com->driver->compr_ops->get_metadata)
+		ret = platform_com->driver->compr_ops->get_metadata(cstream, metadata);
+	else if (platform->driver->compr_ops && platform->driver->compr_ops->get_metadata)
 		ret = platform->driver->compr_ops->get_metadata(cstream, metadata);
 
 	return ret;
@@ -721,6 +795,7 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
 {
 	struct snd_soc_codec *codec = rtd->codec;
 	struct snd_soc_platform *platform = rtd->platform;
+	struct snd_soc_component *platform_com = rtd->platform_com;
 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
 	struct snd_compr *compr;
@@ -799,7 +874,8 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
 		memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
 
 	/* Add copy callback for not memory mapped DSPs */
-	if (platform->driver->compr_ops && platform->driver->compr_ops->copy)
+	if ((platform_com->driver->compr_ops && platform_com->driver->compr_ops->copy) ||
+	    (platform->driver->compr_ops && platform->driver->compr_ops->copy))
 		compr->ops->copy = soc_compr_copy;
 
 	mutex_init(&compr->lock);
-- 
1.9.1



More information about the Alsa-devel mailing list