Skip to contentSkip to conversation

ALSA: hda - power setting error check

PATCH In review Wang Xingchao 3 participants 3 messages Jun 7, 2012 Sound

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ALSA: hda - power setting error check

codec may reject power state transition requests(reporting PS-ERROR set), in that case we re-issue a power state setting and check error bit again.

---
 sound/pci/hda/hda_codec.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
sound/pci/hda/hda_codec.c +14 -3
index d0ca370..a93c7ca 100644
@@ -3526,6 +3526,7 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg
 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 				unsigned int power_state)
 {
+	int state, count = 0;
 	if (codec->patch_ops.set_power_state) {
 		codec->patch_ops.set_power_state(codec, fg, power_state);
 		return;
@@ -3537,9 +3538,19 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 		bool epss = snd_hda_codec_get_supported_ps(codec, fg, AC_PWRST_EPSS);
 		msleep(epss? 10:100);
 	}
-	snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
-			    power_state);
-	snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
+
+	/* repeat power states setting at most 10 times*/
+	while (count++ > 10) {
+		snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
+				    power_state);
+		snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
+		state = snd_hda_codec_read(codec, fg, 0,
+					   AC_VERB_GET_POWER_STATE, 0);
+		if (!(state & AC_PWRST_ERROR))
+			break;
+	}
+	if (count > 10)
+		snd_printk(KERN_WARNING "Power states transition reject!\n");
 }
 
 /* modem wake on ring: transition from D2 to D0 in less than 2ms. For modems,
Signature · 1 line
1.7.9.5
#1 lore raw

Xingchao,

Quoted 2 lines · Wang Xingchao

codec may reject power state transition requests(reporting PS-ERROR set), in that case we re-issue a power state setting and check error bit again.

Is this patch based on real errors observed? And tested to fix the issue?

Quoted 10 lines
---
 sound/pci/hda/hda_codec.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
sound/pci/hda/hda_codec.c +0 -0
index d0ca370..a93c7ca 100644

sound/pci/hda/hda_codec.c static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg · line 3529

Quoted 4 lines
sound/pci/hda/hda_codec.c +1 -0
@@ -3526,6 +3526,7 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg
 static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 				unsigned int power_state)
 {
+	int state, count = 0;

nit pick: break that into two lines?

state should be unsigned int.

sound/pci/hda/hda_codec.c static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, · line 3543

Quoted 13 lines
sound/pci/hda/hda_codec.c +3 -3
 	if (codec->patch_ops.set_power_state) {
 		codec->patch_ops.set_power_state(codec, fg, power_state);
 		return;
@@ -3537,9 +3538,19 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 		bool epss = snd_hda_codec_get_supported_ps(codec, fg, AC_PWRST_EPSS);
 		msleep(epss? 10:100);
 	}
-	snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
-			    power_state);
-	snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
+
+	/* repeat power states setting at most 10 times*/
+	while (count++ > 10) {

< 10?

for(;;) looks slightly better, by putting the initialization together with test and increase.

sound/pci/hda/hda_codec.c static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, · line 3550

Quoted 7 lines
sound/pci/hda/hda_codec.c +7 -0
+		snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
+				    power_state);
+		snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
+		state = snd_hda_codec_read(codec, fg, 0,
+					   AC_VERB_GET_POWER_STATE, 0);
+		if (!(state & AC_PWRST_ERROR))
+			break;

Do you have any clue the condition of success? For example, is it time based (the codec takes some time to respond) or retry count based?

sound/pci/hda/hda_codec.c static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, · line 3553

Quoted 3 lines
sound/pci/hda/hda_codec.c +3 -0
+	}
+	if (count > 10)
+		snd_printk(KERN_WARNING "Power states transition reject!\n");

Power state transition rejected

Hmm, if some codec always rejects it, the user may get lots of these warnings..

Thanks,
Fengguang

#2 lore raw

PATCH v2 1/1 ALSA: hda - power setting error check

Hi fengguang,

2012/6/7 Fengguang Wu <[email protected]>:

Quoted 8 lines

Xingchao,

Quoted 2 lines · Wang Xingchao

codec may reject power state transition requests(reporting PS-ERROR set), in that case we re-issue a power state setting and check error bit again.

Is this patch based on real errors observed? And tested to fix the issue?

Not exactly, i tested the patch on my netbook with codec ALC269 and didnot meet regression. It's not based on real error but from the HDA spec description about PowerStates setting part. The spec said PS-ERROR bit indicates the power states transition rejection so we'd better check the status when try to set codec power state.

Quoted 35 lines
Quoted 10 lines

---
 sound/pci/hda/hda_codec.c |   17 ++++++++++++++---

 1 file changed, 14 insertions(+), 3 deletions(-)
sound/pci/hda/hda_codec.c +0 -0
index d0ca370..a93c7ca 100644

sound/pci/hda/hda_codec.c static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg · line 3529

Quoted 4 lines
sound/pci/hda/hda_codec.c +1 -0
@@ -3526,6 +3526,7 @@ static bool snd_hda_codec_get_supported_ps(struct hda_codec *codec, hda_nid_t fg
  static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
                               unsigned int power_state)
  {
+     int state, count = 0;

nit pick: break that into two lines?

state should be unsigned int.

sound/pci/hda/hda_codec.c static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, · line 3543

Quoted 13 lines
sound/pci/hda/hda_codec.c +3 -3
       if (codec->patch_ops.set_power_state) {
               codec->patch_ops.set_power_state(codec, fg, power_state);
               return;
@@ -3537,9 +3538,19 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
               bool epss = snd_hda_codec_get_supported_ps(codec, fg, AC_PWRST_EPSS);
               msleep(epss? 10:100);
       }
-     snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
-                         power_state);
-     snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
+
+     /* repeat power states setting at most 10 times*/
+     while (count++ > 10) {

< 10?

Quoted 3 lines

for(;;) looks slightly better, by putting the initialization together with test and increase.

thanks your review above, i will fix these errors.

Quoted 11 lines

sound/pci/hda/hda_codec.c static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, · line 3550

Quoted 7 lines
sound/pci/hda/hda_codec.c +7 -0
+             snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
+                                 power_state);
+             snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
+             state = snd_hda_codec_read(codec, fg, 0,
+                                        AC_VERB_GET_POWER_STATE, 0);
+             if (!(state & AC_PWRST_ERROR))
+                     break;

Do you have any clue the condition of success? For example, is it time based (the codec takes some time to respond) or retry count based?

Good question. snd_hda_codec_read() will send the command and get the response, but power setting verb id (705h) acturally has response "0" all the time. As the spec said, if the node remain in its previous power states, it sets PS-ERROR bit immediately. If the node doesnot set PS-Error bit after it received the Set Power State Verb, that means the transition is successful. That's why i didnot add some time delay to wait for the response here.

Quoted 8 lines

sound/pci/hda/hda_codec.c static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg, · line 3553

Quoted 3 lines
sound/pci/hda/hda_codec.c +3 -0
+     }
+     if (count > 10)
+             snd_printk(KERN_WARNING "Power states transition reject!\n");

Power state transition rejected

Hmm, if some codec always rejects it, the user may get lots of these warnings..

Will remove the warning message here.

--thanks
xingchao