summaryrefslogtreecommitdiff
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>2020-01-10 11:35:21 +0900
committerMark Brown <broonie@kernel.org>2020-01-10 13:31:22 +0000
commit613fb50059cf19aa6acbc503a00265d9151c0b09 (patch)
tree65c16095cdfbbef874c085d6ad552983fea255c6 /sound/soc/soc-core.c
parenta84188eced6109983af54f9435a26d21eac3f8cc (diff)
ASoC: soc-core: remove snd_soc_rtdcom_list
Current ALSA SoC is using struct snd_soc_rtdcom_list to connecting component to rtd by using list_head. struct snd_soc_rtdcom_list { struct snd_soc_component *component; struct list_head list; /* rtd::component_list */ }; struct snd_soc_pcm_runtime { ... struct list_head component_list; /* list of connected components */ ... }; The CPU/Codec/Platform component which will be connected to rtd (a) is indicated via dai_link at snd_soc_add_pcm_runtime() int snd_soc_add_pcm_runtime(...) { ... /* Find CPU from registered CPUs */ rtd->cpu_dai = snd_soc_find_dai(dai_link->cpus); ... (a) snd_soc_rtdcom_add(rtd, rtd->cpu_dai->component); ... /* Find CODEC from registered CODECs */ (b) for_each_link_codecs(dai_link, i, codec) { rtd->codec_dais[i] = snd_soc_find_dai(codec); ... (a) snd_soc_rtdcom_add(rtd, rtd->codec_dais[i]->component); } ... /* Find PLATFORM from registered PLATFORMs */ (b) for_each_link_platforms(dai_link, i, platform) { for_each_component(component) { ... (a) snd_soc_rtdcom_add(rtd, component); } } } It shows, it is possible to know how many components will be connected to rtd by using dai_link->num_cpus dai_link->num_codecs dai_link->num_platforms If so, we can use component pointer array instead of list_head, in such case, code can be more simple. This patch removes struct snd_soc_rtdcom_list that is only of temporary value, and convert to pointer array. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Reviewed-By: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> Link: https://lore.kernel.org/r/87a76wt4wm.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c56
1 files changed, 21 insertions, 35 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 55b98e82a978..c9daa63a339b 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -261,34 +261,18 @@ static inline void snd_soc_debugfs_exit(void)
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_component *comp;
+ int i;
- for_each_rtd_components(rtd, rtdcom, comp) {
+ for_each_rtd_components(rtd, i, comp) {
/* already connected */
if (comp == component)
return 0;
}
- /*
- * created rtdcom here will be freed when rtd->dev was freed.
- * see
- * soc_free_pcm_runtime() :: device_unregister(rtd->dev)
- */
- rtdcom = devm_kzalloc(rtd->dev, sizeof(*rtdcom), GFP_KERNEL);
- if (!rtdcom)
- return -ENOMEM;
-
- rtdcom->component = component;
- INIT_LIST_HEAD(&rtdcom->list);
-
- /*
- * When rtd was freed, created rtdcom here will be
- * also freed.
- * And we don't need to call list_del(&rtdcom->list)
- * when freed, because rtd is also freed.
- */
- list_add_tail(&rtdcom->list, &rtd->component_list);
+ /* see for_each_rtd_components */
+ rtd->components[rtd->num_components] = component;
+ rtd->num_components++;
return 0;
}
@@ -296,8 +280,8 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
const char *driver_name)
{
- struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_component *component;
+ int i;
if (!driver_name)
return NULL;
@@ -310,7 +294,7 @@ struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
* But, if many components which have same driver name are connected
* to 1 rtd, this function will return 1st found component.
*/
- for_each_rtd_components(rtd, rtdcom, component) {
+ for_each_rtd_components(rtd, i, component) {
const char *component_name = component->driver->name;
if (!component_name)
@@ -318,7 +302,7 @@ struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
if ((component_name == driver_name) ||
strcmp(component_name, driver_name) == 0)
- return rtdcom->component;
+ return component;
}
return NULL;
@@ -418,6 +402,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
{
struct snd_soc_pcm_runtime *rtd;
+ struct snd_soc_component *component;
struct device *dev;
int ret;
@@ -443,13 +428,17 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
/*
* for rtd
*/
- rtd = devm_kzalloc(dev, sizeof(*rtd), GFP_KERNEL);
+ rtd = devm_kzalloc(dev,
+ sizeof(*rtd) +
+ sizeof(*component) * (dai_link->num_cpus +
+ dai_link->num_codecs +
+ dai_link->num_platforms),
+ GFP_KERNEL);
if (!rtd)
goto free_rtd;
rtd->dev = dev;
INIT_LIST_HEAD(&rtd->list);
- INIT_LIST_HEAD(&rtd->component_list);
INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
@@ -1108,9 +1097,8 @@ static int soc_init_pcm_runtime(struct snd_soc_card *card,
{
struct snd_soc_dai_link *dai_link = rtd->dai_link;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
- struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_component *component;
- int ret, num;
+ int ret, num, i;
/* set default power off timeout */
rtd->pmdown_time = pmdown_time;
@@ -1141,7 +1129,7 @@ static int soc_init_pcm_runtime(struct snd_soc_card *card,
* topology based drivers can use the DAI link id field to set PCM
* device number and then use rtd + a base offset of the BEs.
*/
- for_each_rtd_components(rtd, rtdcom, component) {
+ for_each_rtd_components(rtd, i, component) {
if (!component->driver->use_dai_pcm_id)
continue;
@@ -1406,12 +1394,11 @@ static void soc_remove_link_components(struct snd_soc_card *card)
{
struct snd_soc_component *component;
struct snd_soc_pcm_runtime *rtd;
- struct snd_soc_rtdcom_list *rtdcom;
- int order;
+ int i, order;
for_each_comp_order(order) {
for_each_card_rtds(card, rtd) {
- for_each_rtd_components(rtd, rtdcom, component) {
+ for_each_rtd_components(rtd, i, component) {
if (component->driver->remove_order != order)
continue;
@@ -1425,12 +1412,11 @@ static int soc_probe_link_components(struct snd_soc_card *card)
{
struct snd_soc_component *component;
struct snd_soc_pcm_runtime *rtd;
- struct snd_soc_rtdcom_list *rtdcom;
- int ret, order;
+ int i, ret, order;
for_each_comp_order(order) {
for_each_card_rtds(card, rtd) {
- for_each_rtd_components(rtd, rtdcom, component) {
+ for_each_rtd_components(rtd, i, component) {
if (component->driver->probe_order != order)
continue;