ASoC: soc-compress: add snd_compress_ops

Current snd_soc_component_driver has compr_ops, and each driver can
have callback via it. But, it is mainly created for ALSA, thus, it
doesn't have "component" as parameter.
Thus, each callback can't know it is called for which component.
Each callback currently is getting "component" by using
snd_soc_rtdcom_lookup() with driver name.

	--- ALSA SoC  ---
	...
	if (component->driver->compr_ops &&
	    component->driver->compr_ops->open)
=>		return component->driver->compr_ops->open(stream);
	...

	--- driver ---
	static int xxx_open(struct snd_compr_stream *stream)
	{
		struct snd_soc_pcm_runtime *rtd = stream->private_data;
=>		struct snd_soc_component *component = snd_soc_rtdcom_lookup(..);
		...
	}

It works today, but, will not work in the future if we support multi
CPU/Codec/Platform, because 1 rtd might have multiple same driver
name component.

To solve this issue, each callback need to be called with component.
We already have many component driver callbacks.
This patch adds new snd_compress_ops, and call it with "component".

	--- ALSA SoC  ---
	...
	if (component->driver->compress_ops->open)
=>		return component->driver->compress_ops->open(
			component, substream);
			~~~~~~~~~
	...

	--- driver ---
	static int xxx_open(struct snd_soc_component *component,
			    struct snd_compr_stream *stream)
	{
=>		/* it don't need to use snd_soc_rtdcom_lookup() */
		...
	}

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87v9luvdmh.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kuninori Morimoto 2020-04-20 16:07:50 +09:00 committed by Mark Brown
parent e48e83d15b
commit c6cb522c14
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 192 additions and 1 deletions

View File

@ -25,6 +25,44 @@
order++) order++)
/* component interface */ /* component interface */
struct snd_compress_ops {
int (*open)(struct snd_soc_component *component,
struct snd_compr_stream *stream);
int (*free)(struct snd_soc_component *component,
struct snd_compr_stream *stream);
int (*set_params)(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_compr_params *params);
int (*get_params)(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_codec *params);
int (*set_metadata)(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_compr_metadata *metadata);
int (*get_metadata)(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_compr_metadata *metadata);
int (*trigger)(struct snd_soc_component *component,
struct snd_compr_stream *stream, int cmd);
int (*pointer)(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_compr_tstamp *tstamp);
int (*copy)(struct snd_soc_component *component,
struct snd_compr_stream *stream, char __user *buf,
size_t count);
int (*mmap)(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct vm_area_struct *vma);
int (*ack)(struct snd_soc_component *component,
struct snd_compr_stream *stream, size_t bytes);
int (*get_caps)(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_compr_caps *caps);
int (*get_codec_caps)(struct snd_soc_component *component,
struct snd_compr_stream *stream,
struct snd_compr_codec_caps *codec);
};
struct snd_soc_component_driver { struct snd_soc_component_driver {
const char *name; const char *name;
@ -108,7 +146,8 @@ struct snd_soc_component_driver {
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
struct vm_area_struct *vma); struct vm_area_struct *vma);
const struct snd_compr_ops *compr_ops; const struct snd_compr_ops *compr_ops; /* remove me */
const struct snd_compress_ops *compress_ops;
/* probe ordering - for components with runtime dependencies */ /* probe ordering - for components with runtime dependencies */
int probe_order; int probe_order;

View File

@ -28,6 +28,23 @@ static int soc_compr_components_open(struct snd_compr_stream *cstream,
struct snd_soc_component *component; struct snd_soc_component *component;
int i, ret; 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;
}
}
/* remvoe me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->open) !component->driver->compr_ops->open)
@ -55,6 +72,18 @@ static int soc_compr_components_free(struct snd_compr_stream *cstream,
struct snd_soc_component *component; struct snd_soc_component *component;
int i; 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);
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (component == last) if (component == last)
break; break;
@ -327,6 +356,18 @@ static int soc_compr_components_trigger(struct snd_compr_stream *cstream,
struct snd_soc_component *component; struct snd_soc_component *component;
int i, ret; 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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->trigger) !component->driver->compr_ops->trigger)
@ -429,6 +470,18 @@ static int soc_compr_components_set_params(struct snd_compr_stream *cstream,
struct snd_soc_component *component; struct snd_soc_component *component;
int i, ret; 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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->set_params) !component->driver->compr_ops->set_params)
@ -569,6 +622,17 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
goto err; 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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->get_params) !component->driver->compr_ops->get_params)
@ -592,6 +656,17 @@ static int soc_compr_get_caps(struct snd_compr_stream *cstream,
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->get_caps) !component->driver->compr_ops->get_caps)
@ -614,6 +689,17 @@ static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream,
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->get_codec_caps) !component->driver->compr_ops->get_codec_caps)
@ -643,6 +729,18 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
goto err; 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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->ack) !component->driver->compr_ops->ack)
@ -671,6 +769,17 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer) if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer)
cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai); cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai);
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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->pointer) !component->driver->compr_ops->pointer)
@ -693,6 +802,17 @@ static int soc_compr_copy(struct snd_compr_stream *cstream,
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->copy) !component->driver->compr_ops->copy)
@ -720,6 +840,18 @@ static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
return ret; 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;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->set_metadata) !component->driver->compr_ops->set_metadata)
@ -748,6 +880,16 @@ static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
return ret; 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);
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->get_metadata) !component->driver->compr_ops->get_metadata)
@ -878,6 +1020,16 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
} }
for_each_rtd_components(rtd, i, component) {
if (!component->driver->compress_ops ||
!component->driver->compress_ops->copy)
continue;
compr->ops->copy = soc_compr_copy;
break;
}
/* remove me */
for_each_rtd_components(rtd, i, component) { for_each_rtd_components(rtd, i, component) {
if (!component->driver->compr_ops || if (!component->driver->compr_ops ||
!component->driver->compr_ops->copy) !component->driver->compr_ops->copy)