BACKPORT: ALSA: hda - More robustify the power-up/down sequence
authorTakashi Iwai <tiwai@suse.de>
Wed, 9 May 2012 10:36:22 +0000 (12:36 +0200)
committerGerrit <chrome-bot@google.com>
Sat, 16 Jun 2012 02:49:03 +0000 (19:49 -0700)
Check the power_transition up/down state instead of boolean bit, so
that the power-up sequence can cancel the pending power-down work
properly.  Also, by moving cancel_delayed_work_sync() before the
actual power-up sequence, make sure that the delayed power-down is
completed.

BUG=chrome-os-partner:10399
TEST=suspend and resume hda codec.

Change-Id: I5273d41369a5f0e2676e6024a5584105062ec9a6
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Dylan Reid <dgreid@chromium.org>
(cherry picked from commit a2d96e778d1b15d2213f3b7737aa86fd8eda44cb)
Reviewed-on: https://gerrit.chromium.org/gerrit/25324
Reviewed-by: Olof Johansson <olofj@chromium.org>
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_codec.h

index 2dc6869..8ee4162 100644 (file)
@@ -2265,7 +2265,7 @@ int snd_hda_codec_reset(struct hda_codec *codec)
        /* OK, let it free */
 
 #ifdef CONFIG_SND_HDA_POWER_SAVE
-       cancel_delayed_work(&codec->power_work);
+       cancel_delayed_work_sync(&codec->power_work);
        codec->power_on = 0;
        codec->power_transition = 0;
        codec->power_jiffies = jiffies;
@@ -3491,11 +3491,14 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
                            codec->afg ? codec->afg : codec->mfg,
                            AC_PWRST_D3);
 #ifdef CONFIG_SND_HDA_POWER_SAVE
-       snd_hda_update_power_acct(codec);
        cancel_delayed_work(&codec->power_work);
+       spin_lock(&codec->power_lock);
+       snd_hda_update_power_acct(codec);
+       trace_hda_power_down(codec);
        codec->power_on = 0;
        codec->power_transition = 0;
        codec->power_jiffies = jiffies;
+       spin_unlock(&codec->power_lock);
 #endif
 }
 
@@ -4294,13 +4297,15 @@ static void hda_power_work(struct work_struct *work)
        struct hda_bus *bus = codec->bus;
 
        spin_lock(&codec->power_lock);
+       if (codec->power_transition > 0) { /* during power-up sequence? */
+               spin_unlock(&codec->power_lock);
+               return;
+       }
        if (!codec->power_on || codec->power_count) {
                codec->power_transition = 0;
                spin_unlock(&codec->power_lock);
                return;
        }
-
-       trace_hda_power_down(codec);
        spin_unlock(&codec->power_lock);
 
        hda_call_codec_suspend(codec);
@@ -4341,11 +4346,15 @@ void snd_hda_power_up(struct hda_codec *codec)
 
        spin_lock(&codec->power_lock);
        codec->power_count++;
-       if (codec->power_on || codec->power_transition) {
+       if (codec->power_on || codec->power_transition > 0) {
                spin_unlock(&codec->power_lock);
                return;
        }
+       spin_unlock(&codec->power_lock);
 
+       cancel_delayed_work_sync(&codec->power_work);
+
+       spin_lock(&codec->power_lock);
        trace_hda_power_up(codec);
        snd_hda_update_power_acct(codec);
        codec->power_on = 1;
@@ -4358,7 +4367,6 @@ void snd_hda_power_up(struct hda_codec *codec)
        hda_call_codec_resume(codec);
 
        spin_lock(&codec->power_lock);
-       cancel_delayed_work(&codec->power_work);
        codec->power_transition = 0;
        spin_unlock(&codec->power_lock);
 }
@@ -4383,7 +4391,7 @@ void snd_hda_power_down(struct hda_codec *codec)
                return;
        }
        if (power_save(codec)) {
-               codec->power_transition = 1; /* avoid reentrance */
+               codec->power_transition = -1; /* avoid reentrance */
                queue_delayed_work(codec->bus->workq, &codec->power_work,
                                msecs_to_jiffies(power_save(codec) * 1000));
        }
index 77cd995..0a43fee 100644 (file)
@@ -861,7 +861,7 @@ struct hda_codec {
        unsigned int no_jack_detect:1;  /* Machine has no jack-detection */
 #ifdef CONFIG_SND_HDA_POWER_SAVE
        unsigned int power_on :1;       /* current (global) power-state */
-       unsigned int power_transition :1; /* power-state in transition */
+       int power_transition;   /* power-state in transition */
        int power_count;        /* current (global) power refcount */
        struct delayed_work power_work; /* delayed task for powerdown */
        unsigned long power_on_acct;