ALSA: hda - Check codec errors in snd_hda_get_connections()
[pandora-kernel.git] / sound / pci / hda / hda_codec.c
index 562403a..ec352c6 100644 (file)
@@ -316,6 +316,8 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
                /* single connection */
                parm = snd_hda_codec_read(codec, nid, 0,
                                          AC_VERB_GET_CONNECT_LIST, 0);
+               if (parm == -1 && codec->bus->rirb_error)
+                       return -EIO;
                conn_list[0] = parm & mask;
                return 1;
        }
@@ -327,9 +329,12 @@ int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
                int range_val;
                hda_nid_t val, n;
 
-               if (i % num_elems == 0)
+               if (i % num_elems == 0) {
                        parm = snd_hda_codec_read(codec, nid, 0,
                                                  AC_VERB_GET_CONNECT_LIST, i);
+                       if (parm == -1 && codec->bus->rirb_error)
+                               return -EIO;
+               }
                range_val = !!(parm & (1 << (shift-1))); /* ranges */
                val = parm & mask;
                parm >>= shift;
@@ -885,7 +890,7 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
  * Returns 0 if successful, or a negative error code.
  */
 int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
-                                   int do_init, struct hda_codec **codecp)
+                                   struct hda_codec **codecp)
 {
        struct hda_codec *codec;
        char component[31];
@@ -972,19 +977,12 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
                        snd_hda_codec_read(codec, nid, 0,
                                           AC_VERB_GET_SUBSYSTEM_ID, 0);
        }
-       if (bus->modelname)
-               codec->modelname = kstrdup(bus->modelname, GFP_KERNEL);
 
        /* power-up all before initialization */
        hda_set_power_state(codec,
                            codec->afg ? codec->afg : codec->mfg,
                            AC_PWRST_D0);
 
-       if (do_init) {
-               err = snd_hda_codec_configure(codec);
-               if (err < 0)
-                       goto error;
-       }
        snd_hda_codec_proc_new(codec);
 
        snd_hda_create_hwdep(codec);
@@ -1038,6 +1036,7 @@ int snd_hda_codec_configure(struct hda_codec *codec)
                err = init_unsol_queue(codec->bus);
        return err;
 }
+EXPORT_SYMBOL_HDA(snd_hda_codec_configure);
 
 /**
  * snd_hda_codec_setup_stream - set up the codec for streaming
@@ -2569,7 +2568,7 @@ unsigned int snd_hda_calc_stream_format(unsigned int rate,
        case 20:
        case 24:
        case 32:
-               if (maxbps >= 32)
+               if (maxbps >= 32 || format == SNDRV_PCM_FORMAT_FLOAT_LE)
                        val |= 0x40;
                else if (maxbps >= 24)
                        val |= 0x30;
@@ -2696,11 +2695,12 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
                                        bps = 20;
                        }
                }
-               else if (streams == AC_SUPFMT_FLOAT32) {
-                       /* should be exclusive */
+               if (streams & AC_SUPFMT_FLOAT32) {
                        formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
-                       bps = 32;
-               } else if (streams == AC_SUPFMT_AC3) {
+                       if (!bps)
+                               bps = 32;
+               }
+               if (streams == AC_SUPFMT_AC3) {
                        /* should be exclusive */
                        /* temporary hack: we have still no proper support
                         * for the direct AC3 stream...
@@ -3472,10 +3472,16 @@ int snd_hda_multi_out_analog_open(struct hda_codec *codec,
                }
                mutex_lock(&codec->spdif_mutex);
                if (mout->share_spdif) {
-                       runtime->hw.rates &= mout->spdif_rates;
-                       runtime->hw.formats &= mout->spdif_formats;
-                       if (mout->spdif_maxbps < hinfo->maxbps)
-                               hinfo->maxbps = mout->spdif_maxbps;
+                       if ((runtime->hw.rates & mout->spdif_rates) &&
+                           (runtime->hw.formats & mout->spdif_formats)) {
+                               runtime->hw.rates &= mout->spdif_rates;
+                               runtime->hw.formats &= mout->spdif_formats;
+                               if (mout->spdif_maxbps < hinfo->maxbps)
+                                       hinfo->maxbps = mout->spdif_maxbps;
+                       } else {
+                               mout->share_spdif = 0;
+                               /* FIXME: need notify? */
+                       }
                }
                mutex_unlock(&codec->spdif_mutex);
        }