]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ALSA: hda - Handle Headphone Mic jack more generic
authorDavid Henningsson <david.henningsson@canonical.com>
Thu, 11 Apr 2013 09:30:30 +0000 (11:30 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 11 Apr 2013 09:59:41 +0000 (11:59 +0200)
Now that we have a flag for headphone mics, we can use that flag
in the jack creation instead of creating the jack manually.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_generic.c
sound/pci/hda/hda_jack.c

index cc22d754843cbe38a3066cbd5f9b8f589e152a7a..29be37f9f5a2c4fa6a033190918879f2f5fcb21c 100644 (file)
@@ -4366,17 +4366,6 @@ int snd_hda_gen_build_controls(struct hda_codec *codec)
 
        free_kctls(spec); /* no longer needed */
 
-       if (spec->hp_mic_pin) {
-               int err;
-               int nid = spec->hp_mic_pin;
-               err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
-               if (err < 0)
-                       return err;
-               err = snd_hda_jack_detect_enable(codec, nid, 0);
-               if (err < 0)
-                       return err;
-       }
-
        err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
index 1d035efeff4fc606294eae02ca2cbe10e24b1dd9..9e0a95288f46fcca24fa0944fc99cd134e0d7c2e 100644 (file)
@@ -394,7 +394,8 @@ static int get_unique_index(struct hda_codec *codec, const char *name, int idx)
 }
 
 static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
-                        const struct auto_pin_cfg *cfg)
+                        const struct auto_pin_cfg *cfg,
+                        const char *base_name)
 {
        unsigned int def_conf, conn;
        char name[44];
@@ -410,7 +411,11 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,
        phantom_jack = (conn != AC_JACK_PORT_COMPLEX) ||
                       !is_jack_detectable(codec, nid);
 
-       snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx);
+       if (base_name) {
+               strlcpy(name, base_name, sizeof(name));
+               idx = 0;
+       } else
+               snd_hda_get_pin_label(codec, nid, cfg, name, sizeof(name), &idx);
        if (phantom_jack)
                /* Example final name: "Internal Mic Phantom Jack" */
                strncat(name, " Phantom", sizeof(name) - strlen(name) - 1);
@@ -433,39 +438,51 @@ int snd_hda_jack_add_kctls(struct hda_codec *codec,
        const hda_nid_t *p;
        int i, err;
 
+       for (i = 0; i < cfg->num_inputs; i++) {
+               /* If we have headphone mics; make sure they get the right name
+                  before grabbed by output pins */
+               if (cfg->inputs[i].is_headphone_mic) {
+                       if (auto_cfg_hp_outs(cfg) == 1)
+                               err = add_jack_kctl(codec, auto_cfg_hp_pins(cfg)[0],
+                                                   cfg, "Headphone Mic");
+                       else
+                               err = add_jack_kctl(codec, cfg->inputs[i].pin,
+                                                   cfg, "Headphone Mic");
+               } else
+                       err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg,
+                                           NULL);
+               if (err < 0)
+                       return err;
+       }
+
        for (i = 0, p = cfg->line_out_pins; i < cfg->line_outs; i++, p++) {
-               err = add_jack_kctl(codec, *p, cfg);
+               err = add_jack_kctl(codec, *p, cfg, NULL);
                if (err < 0)
                        return err;
        }
        for (i = 0, p = cfg->hp_pins; i < cfg->hp_outs; i++, p++) {
                if (*p == *cfg->line_out_pins) /* might be duplicated */
                        break;
-               err = add_jack_kctl(codec, *p, cfg);
+               err = add_jack_kctl(codec, *p, cfg, NULL);
                if (err < 0)
                        return err;
        }
        for (i = 0, p = cfg->speaker_pins; i < cfg->speaker_outs; i++, p++) {
                if (*p == *cfg->line_out_pins) /* might be duplicated */
                        break;
-               err = add_jack_kctl(codec, *p, cfg);
-               if (err < 0)
-                       return err;
-       }
-       for (i = 0; i < cfg->num_inputs; i++) {
-               err = add_jack_kctl(codec, cfg->inputs[i].pin, cfg);
+               err = add_jack_kctl(codec, *p, cfg, NULL);
                if (err < 0)
                        return err;
        }
        for (i = 0, p = cfg->dig_out_pins; i < cfg->dig_outs; i++, p++) {
-               err = add_jack_kctl(codec, *p, cfg);
+               err = add_jack_kctl(codec, *p, cfg, NULL);
                if (err < 0)
                        return err;
        }
-       err = add_jack_kctl(codec, cfg->dig_in_pin, cfg);
+       err = add_jack_kctl(codec, cfg->dig_in_pin, cfg, NULL);
        if (err < 0)
                return err;
-       err = add_jack_kctl(codec, cfg->mono_out_pin, cfg);
+       err = add_jack_kctl(codec, cfg->mono_out_pin, cfg, NULL);
        if (err < 0)
                return err;
        return 0;