Merge "This patch includes updated scripts for modifying function names and to optimi...
[kvmfornfv.git] / kernel / sound / pci / hda / hda_generic.c
index ac0db16..dc2fa57 100644 (file)
@@ -671,7 +671,8 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
                }
                for (i = 0; i < path->depth; i++) {
                        if (path->path[i] == nid) {
-                               if (dir == HDA_OUTPUT || path->idx[i] == idx)
+                               if (dir == HDA_OUTPUT || idx == -1 ||
+                                   path->idx[i] == idx)
                                        return true;
                                break;
                        }
@@ -682,7 +683,7 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
 
 /* check whether the NID is referred by any active paths */
 #define is_active_nid_for_any(codec, nid) \
-       is_active_nid(codec, nid, HDA_OUTPUT, 0)
+       is_active_nid(codec, nid, HDA_OUTPUT, -1)
 
 /* get the default amp value for the target state */
 static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
@@ -770,9 +771,6 @@ static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
        unsigned int caps;
        unsigned int mask, val;
 
-       if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
-               return;
-
        caps = query_amp_caps(codec, nid, dir);
        val = get_amp_val_to_activate(codec, nid, dir, caps, enable);
        mask = get_amp_mask_to_modify(codec, nid, dir, idx_to_check, caps);
@@ -783,12 +781,22 @@ static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
        update_amp(codec, nid, dir, idx, mask, val);
 }
 
+static void check_and_activate_amp(struct hda_codec *codec, hda_nid_t nid,
+                                  int dir, int idx, int idx_to_check,
+                                  bool enable)
+{
+       /* check whether the given amp is still used by others */
+       if (!enable && is_active_nid(codec, nid, dir, idx_to_check))
+               return;
+       activate_amp(codec, nid, dir, idx, idx_to_check, enable);
+}
+
 static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
                             int i, bool enable)
 {
        hda_nid_t nid = path->path[i];
        init_amp(codec, nid, HDA_OUTPUT, 0);
-       activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
+       check_and_activate_amp(codec, nid, HDA_OUTPUT, 0, 0, enable);
 }
 
 static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
@@ -816,9 +824,16 @@ static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
         * when aa-mixer is available, we need to enable the path as well
         */
        for (n = 0; n < nums; n++) {
-               if (n != idx && (!add_aamix || conn[n] != spec->mixer_merge_nid))
-                       continue;
-               activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
+               if (n != idx) {
+                       if (conn[n] != spec->mixer_merge_nid)
+                               continue;
+                       /* when aamix is disabled, force to off */
+                       if (!add_aamix) {
+                               activate_amp(codec, nid, HDA_INPUT, n, n, false);
+                               continue;
+                       }
+               }
+               check_and_activate_amp(codec, nid, HDA_INPUT, n, idx, enable);
        }
 }
 
@@ -828,7 +843,7 @@ static hda_nid_t path_power_update(struct hda_codec *codec,
                                   bool allow_powerdown)
 {
        hda_nid_t nid, changed = 0;
-       int i, state;
+       int i, state, power;
 
        for (i = 0; i < path->depth; i++) {
                nid = path->path[i];
@@ -840,7 +855,9 @@ static hda_nid_t path_power_update(struct hda_codec *codec,
                        state = AC_PWRST_D0;
                else
                        state = AC_PWRST_D3;
-               if (!snd_hda_check_power_state(codec, nid, state)) {
+               power = snd_hda_codec_read(codec, nid, 0,
+                                          AC_VERB_GET_POWER_STATE, 0);
+               if (power != (state | (state << 4))) {
                        snd_hda_codec_write(codec, nid, 0,
                                            AC_VERB_SET_POWER_STATE, state);
                        changed = nid;
@@ -883,8 +900,7 @@ void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
        struct hda_gen_spec *spec = codec->spec;
        int i;
 
-       if (!enable)
-               path->active = false;
+       path->active = enable;
 
        /* make sure the widget is powered up */
        if (enable && (spec->power_down_unused || codec->power_save_node))
@@ -902,9 +918,6 @@ void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
                if (has_amp_out(codec, path, i))
                        activate_amp_out(codec, path, i, enable);
        }
-
-       if (enable)
-               path->active = true;
 }
 EXPORT_SYMBOL_GPL(snd_hda_activate_path);
 
@@ -1583,6 +1596,12 @@ static bool map_singles(struct hda_codec *codec, int outs,
        return found;
 }
 
+static inline bool has_aamix_out_paths(struct hda_gen_spec *spec)
+{
+       return spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
+               spec->aamix_out_paths[2];
+}
+
 /* create a new path including aamix if available, and return its index */
 static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
 {
@@ -2425,25 +2444,51 @@ static void update_aamix_paths(struct hda_codec *codec, bool do_mix,
        }
 }
 
+/* re-initialize the output paths; only called from loopback_mixing_put() */
+static void update_output_paths(struct hda_codec *codec, int num_outs,
+                               const int *paths)
+{
+       struct hda_gen_spec *spec = codec->spec;
+       struct nid_path *path;
+       int i;
+
+       for (i = 0; i < num_outs; i++) {
+               path = snd_hda_get_path_from_idx(codec, paths[i]);
+               if (path)
+                       snd_hda_activate_path(codec, path, path->active,
+                                             spec->aamix_mode);
+       }
+}
+
 static int loopback_mixing_put(struct snd_kcontrol *kcontrol,
                               struct snd_ctl_elem_value *ucontrol)
 {
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
        struct hda_gen_spec *spec = codec->spec;
+       const struct auto_pin_cfg *cfg = &spec->autocfg;
        unsigned int val = ucontrol->value.enumerated.item[0];
 
        if (val == spec->aamix_mode)
                return 0;
        spec->aamix_mode = val;
-       update_aamix_paths(codec, val, spec->out_paths[0],
-                          spec->aamix_out_paths[0],
-                          spec->autocfg.line_out_type);
-       update_aamix_paths(codec, val, spec->hp_paths[0],
-                          spec->aamix_out_paths[1],
-                          AUTO_PIN_HP_OUT);
-       update_aamix_paths(codec, val, spec->speaker_paths[0],
-                          spec->aamix_out_paths[2],
-                          AUTO_PIN_SPEAKER_OUT);
+       if (has_aamix_out_paths(spec)) {
+               update_aamix_paths(codec, val, spec->out_paths[0],
+                                  spec->aamix_out_paths[0],
+                                  cfg->line_out_type);
+               update_aamix_paths(codec, val, spec->hp_paths[0],
+                                  spec->aamix_out_paths[1],
+                                  AUTO_PIN_HP_OUT);
+               update_aamix_paths(codec, val, spec->speaker_paths[0],
+                                  spec->aamix_out_paths[2],
+                                  AUTO_PIN_SPEAKER_OUT);
+       } else {
+               update_output_paths(codec, cfg->line_outs, spec->out_paths);
+               if (cfg->line_out_type != AUTO_PIN_HP_OUT)
+                       update_output_paths(codec, cfg->hp_outs, spec->hp_paths);
+               if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
+                       update_output_paths(codec, cfg->speaker_outs,
+                                           spec->speaker_paths);
+       }
        return 1;
 }
 
@@ -2461,12 +2506,13 @@ static int create_loopback_mixing_ctl(struct hda_codec *codec)
 
        if (!spec->mixer_nid)
                return 0;
-       if (!(spec->aamix_out_paths[0] || spec->aamix_out_paths[1] ||
-             spec->aamix_out_paths[2]))
-               return 0;
        if (!snd_hda_gen_add_kctl(spec, NULL, &loopback_mixing_enum))
                return -ENOMEM;
        spec->have_aamix_ctl = 1;
+       /* if no explicit aamix path is present (e.g. for Realtek codecs),
+        * enable aamix as default -- just for compatibility
+        */
+       spec->aamix_mode = !has_aamix_out_paths(spec);
        return 0;
 }
 
@@ -3948,6 +3994,8 @@ static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
 
        for (n = 0; n < spec->paths.used; n++) {
                path = snd_array_elem(&spec->paths, n);
+               if (!path->depth)
+                       continue;
                if (path->path[0] == nid ||
                    path->path[path->depth - 1] == nid) {
                        bool pin_old = path->pin_enabled;
@@ -4001,9 +4049,9 @@ static void pin_power_callback(struct hda_codec *codec,
                               struct hda_jack_callback *jack,
                               bool on)
 {
-       if (jack && jack->tbl->nid)
+       if (jack && jack->nid)
                sync_power_state_change(codec,
-                                       set_pin_power_jack(codec, jack->tbl->nid, on));
+                                       set_pin_power_jack(codec, jack->nid, on));
 }
 
 /* callback only doing power up -- called at first */
@@ -5175,7 +5223,7 @@ static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
        int err = 0;
 
        mutex_lock(&spec->pcm_mutex);
-       if (!spec->indep_hp_enabled)
+       if (spec->indep_hp && !spec->indep_hp_enabled)
                err = -EBUSY;
        else
                spec->active_streams |= 1 << STREAM_INDEP_HP;
@@ -5667,6 +5715,8 @@ static void init_aamix_paths(struct hda_codec *codec)
 
        if (!spec->have_aamix_ctl)
                return;
+       if (!has_aamix_out_paths(spec))
+               return;
        update_aamix_paths(codec, spec->aamix_mode, spec->out_paths[0],
                           spec->aamix_out_paths[0],
                           spec->autocfg.line_out_type);
@@ -5880,13 +5930,14 @@ error:
        return err;
 }
 
-static const struct hda_codec_preset snd_hda_preset_generic[] = {
-       { .id = HDA_CODEC_ID_GENERIC, .patch = snd_hda_parse_generic_codec },
+static const struct hda_device_id snd_hda_id_generic[] = {
+       HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC, "Generic", snd_hda_parse_generic_codec),
        {} /* terminator */
 };
+MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_generic);
 
 static struct hda_codec_driver generic_driver = {
-       .preset = snd_hda_preset_generic,
+       .id = snd_hda_id_generic,
 };
 
 module_hda_codec_driver(generic_driver);