[Intel-gfx] [PATCH 3/3] ALSA: hda - Support deferred i915 audio component binding

Takashi Iwai tiwai at suse.de
Thu Apr 7 10:57:24 UTC 2016


Since we have the reliable way to detect the availability of i915
audio component, the HD-audio driver may wait for the binding safely.

This patch puts a simple completion call in the binding callback and
let snd_hdac_i915_init() waiting until the i915 component gets bound
or it notifies.

The wait for binding has a timeout of 60 seconds, in case where the
i915 module isn't present on the media by some reason.  Such a
situation is rather the system error, but it's still safe to get a
timeout and indicate user about that.

The explicit call of request_module() is still kept in this patch in
order to avoid regression even for a system without the implicit
driver loading.  But now it's called in the condition only when no ops
is found, so it's slightly optimized.

The pin-down of i915 module is still kept, too, as the dynamic
unbinding is still problematic.  It may be racy and lead to the
refcount unbalance.

Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
 sound/hda/hdac_i915.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sound/hda/hdac_i915.c b/sound/hda/hdac_i915.c
index 812777f9af1f..6455d239a928 100644
--- a/sound/hda/hdac_i915.c
+++ b/sound/hda/hdac_i915.c
@@ -22,6 +22,7 @@
 #include <sound/hda_i915.h>
 
 static struct i915_audio_component *hdac_acomp;
+static DECLARE_COMPLETION(bind_comp);
 
 /**
  * snd_hdac_set_codec_wakeup - Enable / disable HDMI/DP codec wakeup
@@ -248,10 +249,12 @@ static int hdac_component_master_bind(struct device *dev)
 		goto out_unbind;
 	}
 
+	complete_all(&bind_comp);
 	return 0;
 
 out_unbind:
 	component_unbind_all(dev, acomp);
+	complete_all(&bind_comp);
 
 	return ret;
 }
@@ -339,6 +342,7 @@ int snd_hdac_i915_init(struct hdac_bus *bus)
 		return -ENOMEM;
 	bus->audio_component = acomp;
 	hdac_acomp = acomp;
+	init_completion(&bind_comp);
 
 	component_match_add(dev, &match, hdac_component_master_match, bus);
 	ret = component_master_add_with_match(dev, &hdac_component_master_ops,
@@ -346,12 +350,10 @@ int snd_hdac_i915_init(struct hdac_bus *bus)
 	if (ret < 0)
 		goto out_err;
 
-	/*
-	 * Atm, we don't support deferring the component binding, so make sure
-	 * i915 is loaded and that the binding successfully completes.
-	 */
-	request_module("i915");
+	if (!acomp->ops)
+		request_module("i915");
 
+	wait_for_completion_timeout(&bind_comp, msecs_to_jiffies(60 * 1000));
 	if (!acomp->ops || acomp->ops->disabled) {
 		ret = -ENODEV;
 		goto out_master_del;
-- 
2.8.1



More information about the Intel-gfx mailing list