ALSA: hda - implement a refcount for i915 power well switch
authorMengdong Lin <mengdong.lin@intel.com>
Wed, 29 Apr 2015 09:43:12 +0000 (17:43 +0800)
committerTakashi Iwai <tiwai@suse.de>
Wed, 29 Apr 2015 10:27:52 +0000 (12:27 +0200)
This is to check the refcount of audio driver and reduce calling to i915.

Signed-off-by: Mengdong Lin <mengdong.lin@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_i915.c
sound/pci/hda/hda_intel.h

index 52a85d87c23c58ae11cd8985d4a50d808ffe3731..b648928b641599a9c7c8a16b1cfb390056f07f33 100644 (file)
@@ -42,10 +42,15 @@ int hda_display_power(struct hda_intel *hda, bool enable)
 
        dev_dbg(&hda->chip.pci->dev, "display power %s\n",
                enable ? "enable" : "disable");
-       if (enable)
-               acomp->ops->get_power(acomp->dev);
-       else
-               acomp->ops->put_power(acomp->dev);
+
+       if (enable) {
+               if (!hda->i915_power_refcount++)
+                       acomp->ops->get_power(acomp->dev);
+       } else {
+               WARN_ON(!hda->i915_power_refcount);
+               if (!--hda->i915_power_refcount)
+                       acomp->ops->put_power(acomp->dev);
+       }
 
        return 0;
 }
@@ -183,6 +188,11 @@ out_err:
 int hda_i915_exit(struct hda_intel *hda)
 {
        struct device *dev = &hda->chip.pci->dev;
+       struct i915_audio_component *acomp = &hda->audio_component;
+
+       WARN_ON(hda->i915_power_refcount);
+       if (hda->i915_power_refcount > 0 && acomp->ops)
+               acomp->ops->put_power(acomp->dev);
 
        component_master_del(dev, &hda_component_master_ops);
 
index 206989878bc6cf5691ada0b0a833e2f830918ae8..dc1d3ffab1aae448964bed3c3e4af9e8f0a19264 100644 (file)
@@ -46,6 +46,7 @@ struct hda_intel {
 
        /* i915 component interface */
        struct i915_audio_component audio_component;
+       int i915_power_refcount;
 };
 
 #ifdef CONFIG_SND_HDA_I915