From: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
To: alsa-devel@alsa-project.org
Cc: liam.r.girdwood@linux.intel.com, mengdong.lin@linux.intel.com,
vinod.koul@intel.com,
Vaibhav Agarwal <vaibhav.agarwal@linaro.org>,
peter.ujfalusi@ti.com, broonie@kernel.org
Subject: [RFC 1/4] ASoc: Use ref_count for soc DAI & component
Date: Mon, 15 Feb 2016 17:49:29 +0530 [thread overview]
Message-ID: <1455538772-24926-2-git-send-email-vaibhav.agarwal@linaro.org> (raw)
In-Reply-To: <1455538772-24926-1-git-send-email-vaibhav.agarwal@linaro.org>
This is preperation to allow dynamic DAI link insertion &
removal.
Currently, DAI links are added/removed once during soc-card
instatiate & removal. Thus, irrespective of usage count by multiple
DAI links, DAIs and components are probed or removed only once
while maintaining 'probed' flag.
However, in case of dynamic DAI link insertion/removal we need to
ensure DAI/components are not unnecessarily probed multiple & not
removed mistakenly while in use by any other existing DAI link.
Thus, ref_count is used to maintain their usage count.
Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
---
include/sound/soc-dai.h | 1 +
include/sound/soc.h | 2 ++
sound/soc/soc-core.c | 47 ++++++++++++++++++++++++++++++-----------------
3 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index 964b7de..03c2c7a 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -270,6 +270,7 @@ struct snd_soc_dai {
unsigned int symmetric_samplebits:1;
unsigned int active;
unsigned char probed:1;
+ int ref_count;
struct snd_soc_dapm_widget *playback_widget;
struct snd_soc_dapm_widget *capture_widget;
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 7afb72c..3dda0c4 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -822,6 +822,8 @@ struct snd_soc_component {
struct dentry *debugfs_root;
#endif
+ int ref_count;
+
/*
* DO NOT use any of the fields below in drivers, they are temporary and
* are going to be removed again soon. If you use them in driver code the
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 790ee2b..2b83814 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1060,6 +1060,11 @@ static void soc_remove_component(struct snd_soc_component *component)
if (!component->card)
return;
+ component->ref_count--;
+
+ if (component->ref_count)
+ return;
+
/* This is a HACK and will be removed soon */
if (component->codec)
list_del(&component->codec->card_list);
@@ -1080,14 +1085,17 @@ static void soc_remove_dai(struct snd_soc_dai *dai, int order)
if (dai && dai->probed &&
dai->driver->remove_order == order) {
- if (dai->driver->remove) {
- err = dai->driver->remove(dai);
- if (err < 0)
- dev_err(dai->dev,
- "ASoC: failed to remove %s: %d\n",
- dai->name, err);
+ dai->ref_count--;
+ if (!dai->ref_count) {
+ if (dai->driver->remove) {
+ err = dai->driver->remove(dai);
+ if (err < 0)
+ dev_err(dai->dev,
+ "ASoC: failed to remove %s: %d\n",
+ dai->name, err);
+ }
+ dai->probed = 0;
}
- dai->probed = 0;
}
}
@@ -1367,6 +1375,7 @@ static int soc_probe_component(struct snd_soc_card *card,
card->name, component->card->name);
return -ENODEV;
}
+ component->ref_count++;
return 0;
}
@@ -1436,6 +1445,7 @@ static int soc_probe_component(struct snd_soc_card *card,
if (component->codec)
list_add(&component->codec->card_list, &card->codec_dev_list);
+ component->ref_count++;
return 0;
err_probe:
@@ -1523,18 +1533,21 @@ static int soc_probe_dai(struct snd_soc_dai *dai, int order)
{
int ret;
- if (!dai->probed && dai->driver->probe_order == order) {
- if (dai->driver->probe) {
- ret = dai->driver->probe(dai);
- if (ret < 0) {
- dev_err(dai->dev,
- "ASoC: failed to probe DAI %s: %d\n",
- dai->name, ret);
- return ret;
+ if (dai->driver->probe_order == order) {
+ if (!dai->probed) {
+ if (dai->driver->probe) {
+ ret = dai->driver->probe(dai);
+ if (ret < 0) {
+ dev_err(dai->dev,
+ "ASoC: failed to probe DAI %s: %d\n",
+ dai->name, ret);
+ return ret;
+ }
}
- }
- dai->probed = 1;
+ dai->probed = 1;
+ }
+ dai->ref_count++;
}
return 0;
--
2.1.4
next prev parent reply other threads:[~2016-02-15 12:19 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-15 12:19 [RFC 0/4] Add support for DAI link addition dynamically Vaibhav Agarwal
2016-02-15 12:19 ` Vaibhav Agarwal [this message]
2016-02-15 13:59 ` [RFC 1/4] ASoc: Use ref_count for soc DAI & component Mark Brown
2016-02-16 13:27 ` Vaibhav Agarwal
2016-02-15 12:19 ` [RFC 2/4] alsa: add locked variant for snd_ctl_remove_id Vaibhav Agarwal
2016-02-15 14:02 ` Mark Brown
2016-02-16 13:54 ` Vaibhav Agarwal
2016-02-16 14:13 ` Takashi Iwai
2016-02-16 14:15 ` Vaibhav Agarwal
2016-02-15 12:19 ` [RFC 3/4] ASoC: Enable dynamic DAIlink insertion & removal Vaibhav Agarwal
2016-02-15 17:02 ` Mark Brown
2016-02-16 14:34 ` Vaibhav Agarwal
2016-02-16 19:03 ` Mark Brown
2016-02-15 12:19 ` [RFC 4/4] ASoC: Change soc-card codec_conf array to a list Vaibhav Agarwal
2016-02-15 17:11 ` Mark Brown
2016-02-15 14:22 ` [RFC 0/4] Add support for DAI link addition dynamically Lars-Peter Clausen
2016-02-17 5:52 ` Mengdong Lin
2016-02-17 8:25 ` Mengdong Lin
2016-02-17 9:31 ` Vaibhav Agarwal
2016-02-18 5:23 ` Mengdong Lin
2016-02-18 7:57 ` Vaibhav Agarwal
2016-02-18 13:39 ` Mark Brown
2016-02-22 8:51 ` Mengdong Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455538772-24926-2-git-send-email-vaibhav.agarwal@linaro.org \
--to=vaibhav.agarwal@linaro.org \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=liam.r.girdwood@linux.intel.com \
--cc=mengdong.lin@linux.intel.com \
--cc=peter.ujfalusi@ti.com \
--cc=vinod.koul@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).