ALSA: hda - Reduce click noise at power-saving
[pandora-kernel.git] / sound / pci / hda / hda_codec.c
index ec352c6..3ecb45d 100644 (file)
@@ -150,7 +150,14 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
 {
        u32 val;
 
-       val = (u32)(codec->addr & 0x0f) << 28;
+       if ((codec->addr & ~0xf) || (direct & ~1) || (nid & ~0x7f) ||
+           (verb & ~0xfff) || (parm & ~0xffff)) {
+               printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n",
+                      codec->addr, direct, nid, verb, parm);
+               return ~0;
+       }
+
+       val = (u32)codec->addr << 28;
        val |= (u32)direct << 27;
        val |= (u32)nid << 20;
        val |= verb << 8;
@@ -167,6 +174,9 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
        struct hda_bus *bus = codec->bus;
        int err;
 
+       if (cmd == ~0)
+               return -1;
+
        if (res)
                *res = -1;
  again:
@@ -337,6 +347,12 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
                }
                range_val = !!(parm & (1 << (shift-1))); /* ranges */
                val = parm & mask;
+               if (val == 0) {
+                       snd_printk(KERN_WARNING "hda_codec: "
+                                  "invalid CONNECT_LIST verb %x[%i]:%x\n",
+                                   nid, i, parm);
+                       return 0;
+               }
                parm >>= shift;
                if (range_val) {
                        /* ranges between the previous and this one */
@@ -2351,9 +2367,14 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
        hda_nid_t nid;
        int i;
 
-       snd_hda_codec_write(codec, fg, 0, AC_VERB_SET_POWER_STATE,
+       /* this delay seems necessary to avoid click noise at power-down */
+       if (power_state == AC_PWRST_D3)
+               msleep(100);
+       snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
                            power_state);
-       msleep(10); /* partial workaround for "azx_get_response timeout" */
+       /* partial workaround for "azx_get_response timeout" */
+       if (power_state == AC_PWRST_D0)
+               msleep(10);
 
        nid = codec->start_nid;
        for (i = 0; i < codec->num_nodes; i++, nid++) {