]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/pci/hda/hda_generic.c
ALSA: hda - Add forgotten module alias for Nvidia MCP67 HDMI
[linux-2.6-omap-h63xx.git] / sound / pci / hda / hda_generic.c
index d5f1180115ce98e983020e4a59a1915d2a38d67f..65745e96dc701d91cb5bcbf31b883e80f53791e9 100644 (file)
@@ -20,7 +20,6 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-#include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <sound/core.h>
@@ -70,6 +69,13 @@ struct hda_gspec {
        struct hda_pcm pcm_rec;         /* PCM information */
 
        struct list_head nid_list;      /* list of widgets */
+
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+#define MAX_LOOPBACK_AMPS      7
+       struct hda_loopback_check loopback;
+       int num_loopbacks;
+       struct hda_amp_list loopback_list[MAX_LOOPBACK_AMPS + 1];
+#endif
 };
 
 /*
@@ -88,13 +94,12 @@ struct hda_gspec {
 static void snd_hda_generic_free(struct hda_codec *codec)
 {
        struct hda_gspec *spec = codec->spec;
-       struct list_head *p, *n;
+       struct hda_gnode *node, *n;
 
        if (! spec)
                return;
        /* free all widgets */
-       list_for_each_safe(p, n, &spec->nid_list) {
-               struct hda_gnode *node = list_entry(p, struct hda_gnode, list);
+       list_for_each_entry_safe(node, n, &spec->nid_list, list) {
                if (node->conn_list != node->slist)
                        kfree(node->conn_list);
                kfree(node);
@@ -169,7 +174,8 @@ static int build_afg_tree(struct hda_codec *codec)
        int i, nodes, err;
        hda_nid_t nid;
 
-       snd_assert(spec, return -EINVAL);
+       if (snd_BUG_ON(!spec))
+               return -EINVAL;
 
        spec->def_amp_out_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_OUT_CAP);
        spec->def_amp_in_caps = snd_hda_param_read(codec, codec->afg, AC_PAR_AMP_IN_CAP);
@@ -196,11 +202,9 @@ static int build_afg_tree(struct hda_codec *codec)
 /* FIXME: should avoid the braindead linear search */
 static struct hda_gnode *hda_get_node(struct hda_gspec *spec, hda_nid_t nid)
 {
-       struct list_head *p;
        struct hda_gnode *node;
 
-       list_for_each(p, &spec->nid_list) {
-               node = list_entry(p, struct hda_gnode, list);
+       list_for_each_entry(node, &spec->nid_list, list) {
                if (node->nid == nid)
                        return node;
        }
@@ -218,8 +222,7 @@ static int unmute_output(struct hda_codec *codec, struct hda_gnode *node)
        ofs = (node->amp_out_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
        if (val >= ofs)
                val -= ofs;
-       snd_hda_codec_amp_update(codec, node->nid, 0, HDA_OUTPUT, 0, 0xff, val);
-       snd_hda_codec_amp_update(codec, node->nid, 0, HDA_OUTPUT, 1, 0xff, val);
+       snd_hda_codec_amp_stereo(codec, node->nid, HDA_OUTPUT, 0, 0xff, val);
        return 0;
 }
 
@@ -234,10 +237,7 @@ static int unmute_input(struct hda_codec *codec, struct hda_gnode *node, unsigne
        ofs = (node->amp_in_caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
        if (val >= ofs)
                val -= ofs;
-       snd_hda_codec_amp_update(codec, node->nid, 0, HDA_INPUT, index,
-                                0xff, val);
-       snd_hda_codec_amp_update(codec, node->nid, 1, HDA_INPUT, index,
-                                0xff, val);
+       snd_hda_codec_amp_stereo(codec, node->nid, HDA_INPUT, index, 0xff, val);
        return 0;
 }
 
@@ -257,11 +257,9 @@ static int select_input_connection(struct hda_codec *codec, struct hda_gnode *no
  */
 static void clear_check_flags(struct hda_gspec *spec)
 {
-       struct list_head *p;
        struct hda_gnode *node;
 
-       list_for_each(p, &spec->nid_list) {
-               node = list_entry(p, struct hda_gnode, list);
+       list_for_each_entry(node, &spec->nid_list, list) {
                node->checked = 0;
        }
 }
@@ -344,12 +342,10 @@ static struct hda_gnode *parse_output_jack(struct hda_codec *codec,
                                           struct hda_gspec *spec,
                                           int jack_type)
 {
-       struct list_head *p;
        struct hda_gnode *node;
        int err;
 
-       list_for_each(p, &spec->nid_list) {
-               node = list_entry(p, struct hda_gnode, list);
+       list_for_each_entry(node, &spec->nid_list, list) {
                if (node->type != AC_WID_PIN)
                        continue;
                /* output capable? */
@@ -661,7 +657,6 @@ static int parse_input_path(struct hda_codec *codec, struct hda_gnode *adc_node)
 static int parse_input(struct hda_codec *codec)
 {
        struct hda_gspec *spec = codec->spec;
-       struct list_head *p;
        struct hda_gnode *node;
        int err;
 
@@ -670,8 +665,7 @@ static int parse_input(struct hda_codec *codec)
         * If it reaches to certain input PINs, we take it as the
         * input path.
         */
-       list_for_each(p, &spec->nid_list) {
-               node = list_entry(p, struct hda_gnode, list);
+       list_for_each_entry(node, &spec->nid_list, list) {
                if (node->wid_caps & AC_WCAP_DIGITAL)
                        continue; /* skip SPDIF */
                if (node->type == AC_WID_AUD_IN) {
@@ -686,11 +680,33 @@ static int parse_input(struct hda_codec *codec)
        return 0;
 }
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static void add_input_loopback(struct hda_codec *codec, hda_nid_t nid,
+                              int dir, int idx)
+{
+       struct hda_gspec *spec = codec->spec;
+       struct hda_amp_list *p;
+
+       if (spec->num_loopbacks >= MAX_LOOPBACK_AMPS) {
+               snd_printk(KERN_ERR "hda_generic: Too many loopback ctls\n");
+               return;
+       }
+       p = &spec->loopback_list[spec->num_loopbacks++];
+       p->nid = nid;
+       p->dir = dir;
+       p->idx = idx;
+       spec->loopback.amplist = spec->loopback_list;
+}
+#else
+#define add_input_loopback(codec,nid,dir,idx)
+#endif
+
 /*
  * create mixer controls if possible
  */
 static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
-                       unsigned int index, const char *type, const char *dir_sfx)
+                       unsigned int index, const char *type,
+                       const char *dir_sfx, int is_loopback)
 {
        char name[32];
        int err;
@@ -704,15 +720,21 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
        if ((node->wid_caps & AC_WCAP_IN_AMP) &&
            (node->amp_in_caps & AC_AMPCAP_MUTE)) {
                knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, index, HDA_INPUT);
+               if (is_loopback)
+                       add_input_loopback(codec, node->nid, HDA_INPUT, index);
                snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
-               if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
+               err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
+               if (err < 0)
                        return err;
                created = 1;
        } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
                   (node->amp_out_caps & AC_AMPCAP_MUTE)) {
                knew = (struct snd_kcontrol_new)HDA_CODEC_MUTE(name, node->nid, 0, HDA_OUTPUT);
+               if (is_loopback)
+                       add_input_loopback(codec, node->nid, HDA_OUTPUT, 0);
                snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
-               if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
+               err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
+               if (err < 0)
                        return err;
                created = 1;
        }
@@ -725,14 +747,16 @@ static int create_mixer(struct hda_codec *codec, struct hda_gnode *node,
            (node->amp_in_caps & AC_AMPCAP_NUM_STEPS)) {
                knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, index, HDA_INPUT);
                snd_printdd("[%s] NID=0x%x, DIR=IN, IDX=0x%x\n", name, node->nid, index);
-               if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
+               err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
+               if (err < 0)
                        return err;
                created = 1;
        } else if ((node->wid_caps & AC_WCAP_OUT_AMP) &&
                   (node->amp_out_caps & AC_AMPCAP_NUM_STEPS)) {
                knew = (struct snd_kcontrol_new)HDA_CODEC_VOLUME(name, node->nid, 0, HDA_OUTPUT);
                snd_printdd("[%s] NID=0x%x, DIR=OUT\n", name, node->nid);
-               if ((err = snd_ctl_add(codec->bus->card, snd_ctl_new1(&knew, codec))) < 0)
+               err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
+               if (err < 0)
                        return err;
                created = 1;
        }
@@ -769,7 +793,7 @@ static int create_output_mixers(struct hda_codec *codec, const char **names)
        for (i = 0; i < spec->pcm_vol_nodes; i++) {
                err = create_mixer(codec, spec->pcm_vol[i].node,
                                   spec->pcm_vol[i].index,
-                                  names[i], "Playback");
+                                  names[i], "Playback", 0);
                if (err < 0)
                        return err;
        }
@@ -786,7 +810,7 @@ static int build_output_controls(struct hda_codec *codec)
        case 1:
                return create_mixer(codec, spec->pcm_vol[0].node,
                                    spec->pcm_vol[0].index,
-                                   "Master", "Playback");
+                                   "Master", "Playback", 0);
        case 2:
                if (defcfg_type(spec->out_pin_node[0]) == AC_JACK_SPEAKER)
                        return create_output_mixers(codec, types_speaker);
@@ -822,15 +846,15 @@ static int build_input_controls(struct hda_codec *codec)
        if (spec->input_mux.num_items == 1) {
                err = create_mixer(codec, adc_node,
                                   spec->input_mux.items[0].index,
-                                  NULL, "Capture");
+                                  NULL, "Capture", 0);
                if (err < 0)
                        return err;
                return 0;
        }
 
        /* create input MUX if multiple sources are available */
-       if ((err = snd_ctl_add(codec->bus->card,
-                              snd_ctl_new1(&cap_sel, codec))) < 0)
+       err = snd_hda_ctl_add(codec, snd_ctl_new1(&cap_sel, codec));
+       if (err < 0)
                return err;
 
        /* no volume control? */
@@ -847,8 +871,8 @@ static int build_input_controls(struct hda_codec *codec)
                        HDA_CODEC_VOLUME(name, adc_node->nid,
                                         spec->input_mux.items[i].index,
                                         HDA_INPUT);
-               if ((err = snd_ctl_add(codec->bus->card,
-                                      snd_ctl_new1(&knew, codec))) < 0)
+               err = snd_hda_ctl_add(codec, snd_ctl_new1(&knew, codec));
+               if (err < 0)
                        return err;
        }
 
@@ -888,7 +912,8 @@ static int parse_loopback_path(struct hda_codec *codec, struct hda_gspec *spec,
                        return err;
                else if (err >= 1) {
                        if (err == 1) {
-                               err = create_mixer(codec, node, i, type, "Playback");
+                               err = create_mixer(codec, node, i, type,
+                                                  "Playback", 1);
                                if (err < 0)
                                        return err;
                                if (err > 0)
@@ -913,7 +938,6 @@ static int parse_loopback_path(struct hda_codec *codec, struct hda_gspec *spec,
 static int build_loopback_controls(struct hda_codec *codec)
 {
        struct hda_gspec *spec = codec->spec;
-       struct list_head *p;
        struct hda_gnode *node;
        int err;
        const char *type;
@@ -921,8 +945,7 @@ static int build_loopback_controls(struct hda_codec *codec)
        if (! spec->out_pin_node[0])
                return 0;
 
-       list_for_each(p, &spec->nid_list) {
-               node = list_entry(p, struct hda_gnode, list);
+       list_for_each_entry(node, &spec->nid_list, list) {
                if (node->type != AC_WID_PIN)
                        continue;
                /* input capable? */
@@ -989,8 +1012,8 @@ static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo,
 {
        struct hda_gspec *spec = codec->spec;
 
-       snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0);
-       snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, 0, 0, 0);
+       snd_hda_codec_cleanup_stream(codec, hinfo->nid);
+       snd_hda_codec_cleanup_stream(codec, spec->dac_node[1]->nid);
        return 0;
 }
 
@@ -1024,6 +1047,14 @@ static int build_generic_pcms(struct hda_codec *codec)
        return 0;
 }
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static int generic_check_power_status(struct hda_codec *codec, hda_nid_t nid)
+{
+       struct hda_gspec *spec = codec->spec;
+       return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
+}
+#endif
+
 
 /*
  */
@@ -1031,6 +1062,9 @@ static struct hda_codec_ops generic_patch_ops = {
        .build_controls = build_generic_controls,
        .build_pcms = build_generic_pcms,
        .free = snd_hda_generic_free,
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       .check_power_status = generic_check_power_status,
+#endif
 };
 
 /*
@@ -1067,3 +1101,4 @@ int snd_hda_parse_generic_codec(struct hda_codec *codec)
        snd_hda_generic_free(codec);
        return err;
 }
+EXPORT_SYMBOL(snd_hda_parse_generic_codec);