ASoC: soc-core: add snd_soc_rtdcom_xxx()

Current snd_soc_pcm_runtime has platform / codec pointers, and we could
use these specific pointer. But these will be replaced to more generic
"component" soon, and will need more generic method to get each
connected component pointer from rtd.

This patch adds new snd_soc_rtdcom_xxx() to connect/disconnect
component to rtd. It means same as previous "platform" / "codec"
pointer style, but more generic.
We can find necessary component pointer from rtd by using component
driver name on snd_soc_rtdcom_lookup().

Here, the reason why it uses "driver name" is that "component name"
was created by fmt_single_name() and difficult to use it from driver.
Driver of course knows its "driver name", thus, using it is more easy.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Arnaud Pouliquen <arnaud.pouliquen@st.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kuninori Morimoto 2017-08-08 06:17:47 +00:00 коммит произвёл Mark Brown
Родитель d9a02c552c
Коммит a0ac441152
2 изменённых файлов: 63 добавлений и 0 удалений

Просмотреть файл

@ -886,6 +886,18 @@ struct snd_soc_component {
#endif
};
struct snd_soc_rtdcom_list {
struct snd_soc_component *component;
struct list_head list; /* rtd::component_list */
};
struct snd_soc_component*
snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
const char *driver_name);
#define for_each_rtdcom(rtd, rtdcom) \
list_for_each_entry(rtdcom, &(rtd)->component_list, list)
#define for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2) \
list_for_each_entry_safe(rtdcom1, rtdcom2, &(rtd)->component_list, list)
/* SoC Audio Codec device */
struct snd_soc_codec {
struct device *dev;
@ -1240,6 +1252,7 @@ struct snd_soc_pcm_runtime {
unsigned int num; /* 0-based and monotonic increasing */
struct list_head list; /* rtd list of the soc card */
struct list_head component_list; /* list of connected components */
/* bit field */
unsigned int dev_registered:1;

Просмотреть файл

@ -551,6 +551,54 @@ static inline void snd_soc_debugfs_exit(void)
#endif
static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_component *component)
{
struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_rtdcom_list *new_rtdcom;
for_each_rtdcom(rtd, rtdcom) {
/* already connected */
if (rtdcom->component == component)
return 0;
}
new_rtdcom = kmalloc(sizeof(*new_rtdcom), GFP_KERNEL);
if (!new_rtdcom)
return -ENOMEM;
new_rtdcom->component = component;
INIT_LIST_HEAD(&new_rtdcom->list);
list_add_tail(&new_rtdcom->list, &rtd->component_list);
return 0;
}
static void snd_soc_rtdcom_del_all(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_rtdcom_list *rtdcom1, *rtdcom2;
for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2)
kfree(rtdcom1);
INIT_LIST_HEAD(&rtd->component_list);
}
struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
const char *driver_name)
{
struct snd_soc_rtdcom_list *rtdcom;
for_each_rtdcom(rtd, rtdcom) {
if ((rtdcom->component->driver->name == driver_name) ||
strcmp(rtdcom->component->driver->name, driver_name) == 0)
return rtdcom->component;
}
return NULL;
}
struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
const char *dai_link, int stream)
{
@ -575,6 +623,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
if (!rtd)
return NULL;
INIT_LIST_HEAD(&rtd->component_list);
rtd->card = card;
rtd->dai_link = dai_link;
rtd->codec_dais = kzalloc(sizeof(struct snd_soc_dai *) *
@ -592,6 +641,7 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
{
if (rtd && rtd->codec_dais)
kfree(rtd->codec_dais);
snd_soc_rtdcom_del_all(rtd);
kfree(rtd);
}