Commit e2cb4a14 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-core: merge snd_pcm_ops member to component driver

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

	--- ALSA SoC  ---
	...
	if (component->driver->ops &&
	    component->driver->ops->open)
(1)		return component->driver->ops->open(substream);
	...

	--- driver ---
(2)	static int xxx_open(struct snd_pcm_substream *substream)
	{
		struct snd_soc_pcm_runtime *rtd = substream->private_data;
(3)		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 components which
have same driver name.

To solve this issue, each callback needs to be called with component.
We already have many component driver callback.
This patch copies each snd_pcm_ops member under component driver,
and having "component" as parameter.

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

	--- driver ---
=>	static int xxx_open(struct snd_soc_component *component,
			    struct snd_pcm_substream *substream)
	{
		...
	}

*Note*

Only Intel skl-pcm has .get_time_info implementation, but ALSA SoC
framework doesn't call it so far.
To keep its implementation, this patch keeps .get_time_info,
but it is still not called.
Intel guy need to support it in the future.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87tv8raf3r.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 9e985503
...@@ -70,6 +70,40 @@ struct snd_soc_component_driver { ...@@ -70,6 +70,40 @@ struct snd_soc_component_driver {
int (*set_bias_level)(struct snd_soc_component *component, int (*set_bias_level)(struct snd_soc_component *component,
enum snd_soc_bias_level level); enum snd_soc_bias_level level);
int (*open)(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int (*close)(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int (*ioctl)(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
unsigned int cmd, void *arg);
int (*hw_params)(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params);
int (*hw_free)(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int (*prepare)(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int (*trigger)(struct snd_soc_component *component,
struct snd_pcm_substream *substream, int cmd);
snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
struct snd_pcm_substream *substream);
int (*get_time_info)(struct snd_soc_component *component,
struct snd_pcm_substream *substream, struct timespec *system_ts,
struct timespec *audio_ts,
struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
int (*copy_user)(struct snd_soc_component *component,
struct snd_pcm_substream *substream, int channel,
unsigned long pos, void __user *buf,
unsigned long bytes);
struct page *(*page)(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
unsigned long offset);
int (*mmap)(struct snd_soc_component *component,
struct snd_pcm_substream *substream,
struct vm_area_struct *vma);
const struct snd_pcm_ops *ops; const struct snd_pcm_ops *ops;
const struct snd_compr_ops *compr_ops; const struct snd_compr_ops *compr_ops;
......
...@@ -314,6 +314,10 @@ void snd_soc_component_module_put(struct snd_soc_component *component, ...@@ -314,6 +314,10 @@ void snd_soc_component_module_put(struct snd_soc_component *component,
int snd_soc_component_open(struct snd_soc_component *component, int snd_soc_component_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
if (component->driver->open)
return component->driver->open(component, substream);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->open) component->driver->ops->open)
return component->driver->ops->open(substream); return component->driver->ops->open(substream);
...@@ -324,6 +328,10 @@ int snd_soc_component_open(struct snd_soc_component *component, ...@@ -324,6 +328,10 @@ int snd_soc_component_open(struct snd_soc_component *component,
int snd_soc_component_close(struct snd_soc_component *component, int snd_soc_component_close(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
if (component->driver->close)
return component->driver->close(component, substream);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->close) component->driver->ops->close)
return component->driver->ops->close(substream); return component->driver->ops->close(substream);
...@@ -334,6 +342,10 @@ int snd_soc_component_close(struct snd_soc_component *component, ...@@ -334,6 +342,10 @@ int snd_soc_component_close(struct snd_soc_component *component,
int snd_soc_component_prepare(struct snd_soc_component *component, int snd_soc_component_prepare(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
if (component->driver->prepare)
return component->driver->prepare(component, substream);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->prepare) component->driver->ops->prepare)
return component->driver->ops->prepare(substream); return component->driver->ops->prepare(substream);
...@@ -345,6 +357,11 @@ int snd_soc_component_hw_params(struct snd_soc_component *component, ...@@ -345,6 +357,11 @@ int snd_soc_component_hw_params(struct snd_soc_component *component,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
if (component->driver->hw_params)
return component->driver->hw_params(component,
substream, params);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->hw_params) component->driver->ops->hw_params)
return component->driver->ops->hw_params(substream, params); return component->driver->ops->hw_params(substream, params);
...@@ -355,6 +372,10 @@ int snd_soc_component_hw_params(struct snd_soc_component *component, ...@@ -355,6 +372,10 @@ int snd_soc_component_hw_params(struct snd_soc_component *component,
int snd_soc_component_hw_free(struct snd_soc_component *component, int snd_soc_component_hw_free(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
if (component->driver->hw_free)
return component->driver->hw_free(component, substream);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->hw_free) component->driver->ops->hw_free)
return component->driver->ops->hw_free(substream); return component->driver->ops->hw_free(substream);
...@@ -366,6 +387,10 @@ int snd_soc_component_trigger(struct snd_soc_component *component, ...@@ -366,6 +387,10 @@ int snd_soc_component_trigger(struct snd_soc_component *component,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
int cmd) int cmd)
{ {
if (component->driver->trigger)
return component->driver->trigger(component, substream, cmd);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->trigger) component->driver->ops->trigger)
return component->driver->ops->trigger(substream, cmd); return component->driver->ops->trigger(substream, cmd);
...@@ -435,6 +460,10 @@ int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream) ...@@ -435,6 +460,10 @@ int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
component = rtdcom->component; component = rtdcom->component;
/* FIXME: use 1st pointer */ /* FIXME: use 1st pointer */
if (component->driver->pointer)
return component->driver->pointer(component, substream);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->pointer) component->driver->ops->pointer)
return component->driver->ops->pointer(substream); return component->driver->ops->pointer(substream);
...@@ -454,6 +483,11 @@ int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, ...@@ -454,6 +483,11 @@ int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
component = rtdcom->component; component = rtdcom->component;
/* FIXME: use 1st ioctl */ /* FIXME: use 1st ioctl */
if (component->driver->ioctl)
return component->driver->ioctl(component, substream,
cmd, arg);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->ioctl) component->driver->ops->ioctl)
return component->driver->ops->ioctl(substream, return component->driver->ops->ioctl(substream,
...@@ -475,6 +509,11 @@ int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, ...@@ -475,6 +509,11 @@ int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
component = rtdcom->component; component = rtdcom->component;
/* FIXME. it returns 1st copy now */ /* FIXME. it returns 1st copy now */
if (component->driver->copy_user)
return component->driver->copy_user(
component, substream, channel, pos, buf, bytes);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->copy_user) component->driver->ops->copy_user)
return component->driver->ops->copy_user( return component->driver->ops->copy_user(
...@@ -496,6 +535,14 @@ struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, ...@@ -496,6 +535,14 @@ struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
component = rtdcom->component; component = rtdcom->component;
/* FIXME. it returns 1st page now */ /* FIXME. it returns 1st page now */
if (component->driver->page) {
page = component->driver->page(component,
substream, offset);
if (page)
return page;
}
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->page) { component->driver->ops->page) {
page = component->driver->ops->page(substream, offset); page = component->driver->ops->page(substream, offset);
...@@ -518,6 +565,11 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, ...@@ -518,6 +565,11 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
component = rtdcom->component; component = rtdcom->component;
/* FIXME. it returns 1st mmap now */ /* FIXME. it returns 1st mmap now */
if (component->driver->mmap)
return component->driver->mmap(component,
substream, vma);
/* remove me */
if (component->driver->ops && if (component->driver->ops &&
component->driver->ops->mmap) component->driver->ops->mmap)
return component->driver->ops->mmap(substream, vma); return component->driver->ops->mmap(substream, vma);
......
...@@ -2987,16 +2987,17 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) ...@@ -2987,16 +2987,17 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
} }
for_each_rtdcom(rtd, rtdcom) { for_each_rtdcom(rtd, rtdcom) {
const struct snd_pcm_ops *ops = rtdcom->component->driver->ops; const struct snd_soc_component_driver *drv = rtdcom->component->driver;
const struct snd_pcm_ops *ops = drv->ops;
if (!ops) if (!ops)
continue; continue;
if (ops->copy_user) if (ops->copy_user || drv->copy_user)
rtd->ops.copy_user = snd_soc_pcm_component_copy_user; rtd->ops.copy_user = snd_soc_pcm_component_copy_user;
if (ops->page) if (ops->page || drv->page)
rtd->ops.page = snd_soc_pcm_component_page; rtd->ops.page = snd_soc_pcm_component_page;
if (ops->mmap) if (ops->mmap || drv->mmap)
rtd->ops.mmap = snd_soc_pcm_component_mmap; rtd->ops.mmap = snd_soc_pcm_component_mmap;
} }
......
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