aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2010-09-17 08:42:34 -0400
committerTakashi Iwai <tiwai@suse.de>2010-09-17 08:42:34 -0400
commit99ae28bea984df4c38234eb6d2f29a552def6c1b (patch)
treec3005c84d8fa092bfe5cb7642a0dd2f61dca977e /sound
parent5637edb2e1c2d13b276748508ae17f319fb7f066 (diff)
ALSA: hda - Make snd_hda_get_input_pin_attr() helper
Make the helper function to give the input-pin attribute for jack connectivity and location. This simplifies checks of input-pin jacks a bit in some places. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r--sound/pci/hda/hda_codec.c62
-rw-r--r--sound/pci/hda/hda_local.h11
-rw-r--r--sound/pci/hda/patch_cirrus.c2
-rw-r--r--sound/pci/hda/patch_conexant.c11
-rw-r--r--sound/pci/hda/patch_realtek.c10
-rw-r--r--sound/pci/hda/patch_sigmatel.c30
6 files changed, 59 insertions, 67 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 9f668efbe420..e15a75751f57 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -4637,44 +4637,26 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4637} 4637}
4638EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config); 4638EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config);
4639 4639
4640enum { 4640int snd_hda_get_input_pin_attr(unsigned int def_conf)
4641 MIC_ATTR_INT,
4642 MIC_ATTR_DOCK,
4643 MIC_ATTR_NORMAL,
4644 MIC_ATTR_FRONT,
4645 MIC_ATTR_REAR,
4646};
4647
4648static int get_mic_pin_attr(unsigned int def_conf)
4649{ 4641{
4650 unsigned int loc = get_defcfg_location(def_conf); 4642 unsigned int loc = get_defcfg_location(def_conf);
4651 unsigned int conn = get_defcfg_connect(def_conf); 4643 unsigned int conn = get_defcfg_connect(def_conf);
4644 if (conn == AC_JACK_PORT_NONE)
4645 return INPUT_PIN_ATTR_UNUSED;
4652 /* Windows may claim the internal mic to be BOTH, too */ 4646 /* Windows may claim the internal mic to be BOTH, too */
4653 if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH) 4647 if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH)
4654 return MIC_ATTR_INT; 4648 return INPUT_PIN_ATTR_INT;
4655 if ((loc & 0x30) == AC_JACK_LOC_INTERNAL) 4649 if ((loc & 0x30) == AC_JACK_LOC_INTERNAL)
4656 return MIC_ATTR_INT; 4650 return INPUT_PIN_ATTR_INT;
4657 if ((loc & 0x30) == AC_JACK_LOC_SEPARATE) 4651 if ((loc & 0x30) == AC_JACK_LOC_SEPARATE)
4658 return MIC_ATTR_DOCK; 4652 return INPUT_PIN_ATTR_DOCK;
4659 if (loc == AC_JACK_LOC_REAR) 4653 if (loc == AC_JACK_LOC_REAR)
4660 return MIC_ATTR_REAR; 4654 return INPUT_PIN_ATTR_REAR;
4661 if (loc == AC_JACK_LOC_FRONT) 4655 if (loc == AC_JACK_LOC_FRONT)
4662 return MIC_ATTR_FRONT; 4656 return INPUT_PIN_ATTR_FRONT;
4663 return MIC_ATTR_NORMAL; 4657 return INPUT_PIN_ATTR_NORMAL;
4664}
4665
4666enum {
4667 LINE_ATTR_DOCK,
4668 LINE_ATTR_NORMAL,
4669};
4670
4671static int get_line_pin_attr(unsigned int def_conf)
4672{
4673 unsigned int loc = get_defcfg_location(def_conf);
4674 if ((loc & 0xf0) == AC_JACK_LOC_SEPARATE)
4675 return LINE_ATTR_DOCK;
4676 return LINE_ATTR_NORMAL;
4677} 4658}
4659EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr);
4678 4660
4679/** 4661/**
4680 * hda_get_input_pin_label - Give a label for the given input pin 4662 * hda_get_input_pin_label - Give a label for the given input pin
@@ -4691,9 +4673,7 @@ const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
4691 static const char *mic_names[] = { 4673 static const char *mic_names[] = {
4692 "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic", 4674 "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic",
4693 }; 4675 };
4694 static const char *line_names[] = { 4676 int attr;
4695 "Dock Line", "Line",
4696 };
4697 4677
4698 def_conf = snd_hda_codec_get_pincfg(codec, pin); 4678 def_conf = snd_hda_codec_get_pincfg(codec, pin);
4699 4679
@@ -4701,11 +4681,19 @@ const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
4701 case AC_JACK_MIC_IN: 4681 case AC_JACK_MIC_IN:
4702 if (!check_location) 4682 if (!check_location)
4703 return "Mic"; 4683 return "Mic";
4704 return mic_names[get_mic_pin_attr(def_conf)]; 4684 attr = snd_hda_get_input_pin_attr(def_conf);
4685 if (!attr)
4686 return "None";
4687 return mic_names[attr - 1];
4705 case AC_JACK_LINE_IN: 4688 case AC_JACK_LINE_IN:
4706 if (!check_location) 4689 if (!check_location)
4707 return "Line"; 4690 return "Line";
4708 return line_names[get_line_pin_attr(def_conf)]; 4691 attr = snd_hda_get_input_pin_attr(def_conf);
4692 if (!attr)
4693 return "None";
4694 if (attr == INPUT_PIN_ATTR_DOCK)
4695 return "Dock Line";
4696 return "Line";
4709 case AC_JACK_AUX: 4697 case AC_JACK_AUX:
4710 return "Aux"; 4698 return "Aux";
4711 case AC_JACK_CD: 4699 case AC_JACK_CD:
@@ -4732,16 +4720,16 @@ static int check_mic_location_need(struct hda_codec *codec,
4732 int i, attr, attr2; 4720 int i, attr, attr2;
4733 4721
4734 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin); 4722 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin);
4735 attr = get_mic_pin_attr(defc); 4723 attr = snd_hda_get_input_pin_attr(defc);
4736 /* for internal or docking mics, we need locations */ 4724 /* for internal or docking mics, we need locations */
4737 if (attr <= MIC_ATTR_NORMAL) 4725 if (attr <= INPUT_PIN_ATTR_NORMAL)
4738 return 1; 4726 return 1;
4739 4727
4740 attr = 0; 4728 attr = 0;
4741 for (i = 0; i < cfg->num_inputs; i++) { 4729 for (i = 0; i < cfg->num_inputs; i++) {
4742 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin); 4730 defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin);
4743 attr2 = get_mic_pin_attr(defc); 4731 attr2 = snd_hda_get_input_pin_attr(defc);
4744 if (attr2 >= MIC_ATTR_NORMAL) { 4732 if (attr2 >= INPUT_PIN_ATTR_NORMAL) {
4745 if (attr && attr != attr2) 4733 if (attr && attr != attr2)
4746 return 1; /* different locations found */ 4734 return 1; /* different locations found */
4747 attr = attr2; 4735 attr = attr2;
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 6943efc78f66..d7dfa547e2d8 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -395,6 +395,17 @@ const char *hda_get_autocfg_input_label(struct hda_codec *codec,
395int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label, 395int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
396 int index, int *type_index_ret); 396 int index, int *type_index_ret);
397 397
398enum {
399 INPUT_PIN_ATTR_UNUSED, /* pin not connected */
400 INPUT_PIN_ATTR_INT, /* internal mic/line-in */
401 INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */
402 INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */
403 INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */
404 INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */
405};
406
407int snd_hda_get_input_pin_attr(unsigned int def_conf);
408
398struct auto_pin_cfg { 409struct auto_pin_cfg {
399 int line_outs; 410 int line_outs;
400 /* sorted in the order of Front/Surr/CLFE/Side */ 411 /* sorted in the order of Front/Surr/CLFE/Side */
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index ae75283a5583..483c3f2d8d39 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -334,7 +334,7 @@ static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
334 if (!(val & AC_PINCAP_PRES_DETECT)) 334 if (!(val & AC_PINCAP_PRES_DETECT))
335 return 0; 335 return 0;
336 val = snd_hda_codec_get_pincfg(codec, pin); 336 val = snd_hda_codec_get_pincfg(codec, pin);
337 return (get_defcfg_connect(val) == AC_JACK_PORT_COMPLEX); 337 return (snd_hda_get_input_pin_attr(val) != INPUT_PIN_ATTR_INT);
338} 338}
339 339
340static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin, 340static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index e501a85b5612..09d573c59bef 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -3462,19 +3462,12 @@ static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
3462 } 3462 }
3463} 3463}
3464 3464
3465static int is_int_mic_conn(unsigned int def_conf)
3466{
3467 unsigned int loc = get_defcfg_location(def_conf);
3468 return get_defcfg_connect(def_conf) == AC_JACK_PORT_FIXED ||
3469 (loc & 0x30) == AC_JACK_LOC_INTERNAL;
3470}
3471
3472/* return true if it's an internal-mic pin */ 3465/* return true if it's an internal-mic pin */
3473static int is_int_mic(struct hda_codec *codec, hda_nid_t pin) 3466static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
3474{ 3467{
3475 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3468 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3476 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 3469 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3477 is_int_mic_conn(def_conf); 3470 snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
3478} 3471}
3479 3472
3480/* return true if it's an external-mic pin */ 3473/* return true if it's an external-mic pin */
@@ -3482,7 +3475,7 @@ static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
3482{ 3475{
3483 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); 3476 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
3484 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && 3477 return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
3485 !is_int_mic_conn(def_conf); 3478 snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT;
3486} 3479}
3487 3480
3488/* check whether the pin config is suitable for auto-mic switching; 3481/* check whether the pin config is suitable for auto-mic switching;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 5df88798895b..6045f281b225 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -1403,19 +1403,19 @@ static void alc_init_auto_mic(struct hda_codec *codec)
1403 hda_nid_t nid = cfg->inputs[i].pin; 1403 hda_nid_t nid = cfg->inputs[i].pin;
1404 unsigned int defcfg; 1404 unsigned int defcfg;
1405 defcfg = snd_hda_codec_get_pincfg(codec, nid); 1405 defcfg = snd_hda_codec_get_pincfg(codec, nid);
1406 switch (get_defcfg_connect(defcfg)) { 1406 switch (snd_hda_get_input_pin_attr(defcfg)) {
1407 case AC_JACK_PORT_FIXED: 1407 case INPUT_PIN_ATTR_INT:
1408 if (fixed) 1408 if (fixed)
1409 return; /* already occupied */ 1409 return; /* already occupied */
1410 fixed = nid; 1410 fixed = nid;
1411 break; 1411 break;
1412 case AC_JACK_PORT_COMPLEX: 1412 case INPUT_PIN_ATTR_UNUSED:
1413 return; /* invalid entry */
1414 default:
1413 if (ext) 1415 if (ext)
1414 return; /* already occupied */ 1416 return; /* already occupied */
1415 ext = nid; 1417 ext = nid;
1416 break; 1418 break;
1417 default:
1418 return; /* invalid entry */
1419 } 1419 }
1420 } 1420 }
1421 if (!ext || !fixed) 1421 if (!ext || !fixed)
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 7eb359a030de..6bfbc2fe46ed 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -2778,7 +2778,7 @@ static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2778 struct sigmatel_spec *spec = codec->spec; 2778 struct sigmatel_spec *spec = codec->spec;
2779 char name[22]; 2779 char name[22];
2780 2780
2781 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) { 2781 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2782 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD 2782 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2783 && nid == spec->line_switch) 2783 && nid == spec->line_switch)
2784 control = STAC_CTL_WIDGET_IO_SWITCH; 2784 control = STAC_CTL_WIDGET_IO_SWITCH;
@@ -2857,7 +2857,7 @@ static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
2857 def_conf = snd_hda_codec_get_pincfg(codec, nid); 2857 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2858 /* some laptops have an internal analog microphone 2858 /* some laptops have an internal analog microphone
2859 * which can't be used as a output */ 2859 * which can't be used as a output */
2860 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) { 2860 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
2861 pincap = snd_hda_query_pin_caps(codec, nid); 2861 pincap = snd_hda_query_pin_caps(codec, nid);
2862 if (pincap & AC_PINCAP_OUT) { 2862 if (pincap & AC_PINCAP_OUT) {
2863 *dac = get_unassigned_dac(codec, nid); 2863 *dac = get_unassigned_dac(codec, nid);
@@ -3496,23 +3496,23 @@ static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3496 if (!nid) 3496 if (!nid)
3497 return 0; 3497 return 0;
3498 cfg = snd_hda_codec_get_pincfg(codec, nid); 3498 cfg = snd_hda_codec_get_pincfg(codec, nid);
3499 switch (get_defcfg_connect(cfg)) { 3499 switch (snd_hda_get_input_pin_attr(cfg)) {
3500 case AC_JACK_PORT_BOTH: 3500 case INPUT_PIN_ATTR_INT:
3501 case AC_JACK_PORT_FIXED:
3502 if (*fixed) 3501 if (*fixed)
3503 return 1; /* already occupied */ 3502 return 1; /* already occupied */
3504 *fixed = nid; 3503 *fixed = nid;
3505 break; 3504 break;
3506 case AC_JACK_PORT_COMPLEX: 3505 case INPUT_PIN_ATTR_UNUSED:
3507 if ((get_defcfg_location(cfg) & 0xF0) == AC_JACK_LOC_SEPARATE) { 3506 break;
3508 if (*dock) 3507 case INPUT_PIN_ATTR_DOCK:
3509 return 1; /* already occupied */ 3508 if (*dock)
3510 *dock = nid; 3509 return 1; /* already occupied */
3511 } else { 3510 *dock = nid;
3512 if (*ext) 3511 break;
3513 return 1; /* already occupied */ 3512 default:
3514 *ext = nid; 3513 if (*ext)
3515 } 3514 return 1; /* already occupied */
3515 *ext = nid;
3516 break; 3516 break;
3517 } 3517 }
3518 return 0; 3518 return 0;