diff options
author | Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | 2019-07-26 00:52:00 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2019-08-05 11:25:59 -0400 |
commit | 9c712e4f57229081e837d593fc1e4183b068a41c (patch) | |
tree | 997e89089cbc1a986b3ba8a310192f68b35503e1 | |
parent | 82d81f5cced36e480b581ae51c595e2deb9f2d56 (diff) |
ASoC: soc-component: add snd_soc_pcm_component_page()
Current ALSA SoC is directly using component->driver->ops->xxx,
thus, the code nested deeply, and it makes code difficult to read,
and is not good for encapsulation.
We want to implement component related function at soc-component.c,
but, some of them need to care whole snd_soc_pcm_runtime (= rtd)
connected component.
Let's call component related function which need to care with
for_each_rtdcom() loop as snd_soc_pcm_component_xxx().
This patch adds new snd_soc_pcm_component_page() and use it.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87o91h4d06.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | include/sound/soc-component.h | 2 | ||||
-rw-r--r-- | sound/soc/soc-component.c | 23 | ||||
-rw-r--r-- | sound/soc/soc-pcm.c | 26 |
3 files changed, 26 insertions, 25 deletions
diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 6b95d2467053..4cab257962a6 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h | |||
@@ -377,5 +377,7 @@ int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, | |||
377 | int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, | 377 | int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, |
378 | int channel, unsigned long pos, | 378 | int channel, unsigned long pos, |
379 | void __user *buf, unsigned long bytes); | 379 | void __user *buf, unsigned long bytes); |
380 | struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, | ||
381 | unsigned long offset); | ||
380 | 382 | ||
381 | #endif /* __SOC_COMPONENT_H */ | 383 | #endif /* __SOC_COMPONENT_H */ |
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 20897dce1bec..d503bc9b0850 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c | |||
@@ -483,3 +483,26 @@ int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, | |||
483 | 483 | ||
484 | return -EINVAL; | 484 | return -EINVAL; |
485 | } | 485 | } |
486 | |||
487 | struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream, | ||
488 | unsigned long offset) | ||
489 | { | ||
490 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
491 | struct snd_soc_rtdcom_list *rtdcom; | ||
492 | struct snd_soc_component *component; | ||
493 | struct page *page; | ||
494 | |||
495 | for_each_rtdcom(rtd, rtdcom) { | ||
496 | component = rtdcom->component; | ||
497 | |||
498 | /* FIXME. it returns 1st page now */ | ||
499 | if (component->driver->ops && | ||
500 | component->driver->ops->page) { | ||
501 | page = component->driver->ops->page(substream, offset); | ||
502 | if (page) | ||
503 | return page; | ||
504 | } | ||
505 | } | ||
506 | |||
507 | return NULL; | ||
508 | } | ||
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index b0e6ce89b012..fe34f2e5d75e 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c | |||
@@ -2818,30 +2818,6 @@ static void soc_pcm_private_free(struct snd_pcm *pcm) | |||
2818 | } | 2818 | } |
2819 | } | 2819 | } |
2820 | 2820 | ||
2821 | static struct page *soc_rtdcom_page(struct snd_pcm_substream *substream, | ||
2822 | unsigned long offset) | ||
2823 | { | ||
2824 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
2825 | struct snd_soc_rtdcom_list *rtdcom; | ||
2826 | struct snd_soc_component *component; | ||
2827 | struct page *page; | ||
2828 | |||
2829 | for_each_rtdcom(rtd, rtdcom) { | ||
2830 | component = rtdcom->component; | ||
2831 | |||
2832 | if (!component->driver->ops || | ||
2833 | !component->driver->ops->page) | ||
2834 | continue; | ||
2835 | |||
2836 | /* FIXME. it returns 1st page now */ | ||
2837 | page = component->driver->ops->page(substream, offset); | ||
2838 | if (page) | ||
2839 | return page; | ||
2840 | } | ||
2841 | |||
2842 | return NULL; | ||
2843 | } | ||
2844 | |||
2845 | static int soc_rtdcom_mmap(struct snd_pcm_substream *substream, | 2821 | static int soc_rtdcom_mmap(struct snd_pcm_substream *substream, |
2846 | struct vm_area_struct *vma) | 2822 | struct vm_area_struct *vma) |
2847 | { | 2823 | { |
@@ -2990,7 +2966,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) | |||
2990 | if (ops->copy_user) | 2966 | if (ops->copy_user) |
2991 | rtd->ops.copy_user = snd_soc_pcm_component_copy_user; | 2967 | rtd->ops.copy_user = snd_soc_pcm_component_copy_user; |
2992 | if (ops->page) | 2968 | if (ops->page) |
2993 | rtd->ops.page = soc_rtdcom_page; | 2969 | rtd->ops.page = snd_soc_pcm_component_page; |
2994 | if (ops->mmap) | 2970 | if (ops->mmap) |
2995 | rtd->ops.mmap = soc_rtdcom_mmap; | 2971 | rtd->ops.mmap = soc_rtdcom_mmap; |
2996 | } | 2972 | } |