aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_realtek.c
diff options
context:
space:
mode:
authorWu Fengguang <fengguang.wu@intel.com>2009-11-17 23:38:02 -0500
committerTakashi Iwai <tiwai@suse.de>2009-11-18 01:40:57 -0500
commit864f92be7e8d4a0ba11d912e3f03d1a92a031dee (patch)
tree95de58c8f304024b99da8707df77264f644d14b4 /sound/pci/hda/patch_realtek.c
parent23ccc2bd246a5bdb1ac03dc9040a0585c1890ef3 (diff)
ALSA: hda - introduce snd_hda_jack_detect() and snd_hda_pin_sense()
This helps merge duplicate code. v2: add snd_hda_jack_detect() and comments recommended by Takashi. Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_realtek.c')
-rw-r--r--sound/pci/hda/patch_realtek.c206
1 files changed, 49 insertions, 157 deletions
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 578420523606..cbb2d326e6ad 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -961,18 +961,12 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
961static void alc_automute_pin(struct hda_codec *codec) 961static void alc_automute_pin(struct hda_codec *codec)
962{ 962{
963 struct alc_spec *spec = codec->spec; 963 struct alc_spec *spec = codec->spec;
964 unsigned int present, pincap;
965 unsigned int nid = spec->autocfg.hp_pins[0]; 964 unsigned int nid = spec->autocfg.hp_pins[0];
966 int i; 965 int i;
967 966
968 if (!nid) 967 if (!nid)
969 return; 968 return;
970 pincap = snd_hda_query_pin_caps(codec, nid); 969 spec->jack_present = snd_hda_jack_detect(codec, nid);
971 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
972 snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
973 present = snd_hda_codec_read(codec, nid, 0,
974 AC_VERB_GET_PIN_SENSE, 0);
975 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
976 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) { 970 for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
977 nid = spec->autocfg.speaker_pins[i]; 971 nid = spec->autocfg.speaker_pins[i];
978 if (!nid) 972 if (!nid)
@@ -1012,9 +1006,7 @@ static void alc_mic_automute(struct hda_codec *codec)
1012 1006
1013 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0]; 1007 cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
1014 1008
1015 present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0, 1009 present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
1016 AC_VERB_GET_PIN_SENSE, 0);
1017 present &= AC_PINSENSE_PRESENCE;
1018 if (present) { 1010 if (present) {
1019 alive = &spec->ext_mic; 1011 alive = &spec->ext_mic;
1020 dead = &spec->int_mic; 1012 dead = &spec->int_mic;
@@ -1513,7 +1505,7 @@ static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
1513static void alc_automute_amp(struct hda_codec *codec) 1505static void alc_automute_amp(struct hda_codec *codec)
1514{ 1506{
1515 struct alc_spec *spec = codec->spec; 1507 struct alc_spec *spec = codec->spec;
1516 unsigned int val, mute, pincap; 1508 unsigned int mute;
1517 hda_nid_t nid; 1509 hda_nid_t nid;
1518 int i; 1510 int i;
1519 1511
@@ -1522,13 +1514,7 @@ static void alc_automute_amp(struct hda_codec *codec)
1522 nid = spec->autocfg.hp_pins[i]; 1514 nid = spec->autocfg.hp_pins[i];
1523 if (!nid) 1515 if (!nid)
1524 break; 1516 break;
1525 pincap = snd_hda_query_pin_caps(codec, nid); 1517 if (snd_hda_jack_detect(codec, nid)) {
1526 if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1527 snd_hda_codec_read(codec, nid, 0,
1528 AC_VERB_SET_PIN_SENSE, 0);
1529 val = snd_hda_codec_read(codec, nid, 0,
1530 AC_VERB_GET_PIN_SENSE, 0);
1531 if (val & AC_PINSENSE_PRESENCE) {
1532 spec->jack_present = 1; 1518 spec->jack_present = 1;
1533 break; 1519 break;
1534 } 1520 }
@@ -2784,8 +2770,7 @@ static void alc880_uniwill_mic_automute(struct hda_codec *codec)
2784 unsigned int present; 2770 unsigned int present;
2785 unsigned char bits; 2771 unsigned char bits;
2786 2772
2787 present = snd_hda_codec_read(codec, 0x18, 0, 2773 present = snd_hda_jack_detect(codec, 0x18);
2788 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
2789 bits = present ? HDA_AMP_MUTE : 0; 2774 bits = present ? HDA_AMP_MUTE : 0;
2790 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); 2775 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
2791} 2776}
@@ -5102,11 +5087,8 @@ static struct hda_verb alc260_hp_unsol_verbs[] = {
5102static void alc260_hp_automute(struct hda_codec *codec) 5087static void alc260_hp_automute(struct hda_codec *codec)
5103{ 5088{
5104 struct alc_spec *spec = codec->spec; 5089 struct alc_spec *spec = codec->spec;
5105 unsigned int present;
5106 5090
5107 present = snd_hda_codec_read(codec, 0x10, 0, 5091 spec->jack_present = snd_hda_jack_detect(codec, 0x10);
5108 AC_VERB_GET_PIN_SENSE, 0);
5109 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5110 alc260_hp_master_update(codec, 0x0f, 0x10, 0x11); 5092 alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
5111} 5093}
5112 5094
@@ -5171,11 +5153,8 @@ static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
5171static void alc260_hp_3013_automute(struct hda_codec *codec) 5153static void alc260_hp_3013_automute(struct hda_codec *codec)
5172{ 5154{
5173 struct alc_spec *spec = codec->spec; 5155 struct alc_spec *spec = codec->spec;
5174 unsigned int present;
5175 5156
5176 present = snd_hda_codec_read(codec, 0x15, 0, 5157 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
5177 AC_VERB_GET_PIN_SENSE, 0);
5178 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
5179 alc260_hp_master_update(codec, 0x15, 0x10, 0x11); 5158 alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
5180} 5159}
5181 5160
@@ -5188,12 +5167,8 @@ static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
5188 5167
5189static void alc260_hp_3012_automute(struct hda_codec *codec) 5168static void alc260_hp_3012_automute(struct hda_codec *codec)
5190{ 5169{
5191 unsigned int present, bits; 5170 unsigned int bits = snd_hda_jack_detect(codec, 0x10) ? 0 : PIN_OUT;
5192 5171
5193 present = snd_hda_codec_read(codec, 0x10, 0,
5194 AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
5195
5196 bits = present ? 0 : PIN_OUT;
5197 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 5172 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
5198 bits); 5173 bits);
5199 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 5174 snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
@@ -5763,8 +5738,7 @@ static void alc260_replacer_672v_automute(struct hda_codec *codec)
5763 unsigned int present; 5738 unsigned int present;
5764 5739
5765 /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */ 5740 /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
5766 present = snd_hda_codec_read(codec, 0x0f, 0, 5741 present = snd_hda_jack_detect(codec, 0x0f);
5767 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
5768 if (present) { 5742 if (present) {
5769 snd_hda_codec_write_cache(codec, 0x01, 0, 5743 snd_hda_codec_write_cache(codec, 0x01, 0,
5770 AC_VERB_SET_GPIO_DATA, 1); 5744 AC_VERB_SET_GPIO_DATA, 1);
@@ -8196,12 +8170,8 @@ static void alc883_mitac_setup(struct hda_codec *codec)
8196/* 8170/*
8197static void alc883_mitac_mic_automute(struct hda_codec *codec) 8171static void alc883_mitac_mic_automute(struct hda_codec *codec)
8198{ 8172{
8199 unsigned int present; 8173 unsigned char bits = snd_hda_jack_detect(codec, 0x18) ? HDA_AMP_MUTE : 0;
8200 unsigned char bits;
8201 8174
8202 present = snd_hda_codec_read(codec, 0x18, 0,
8203 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8204 bits = present ? HDA_AMP_MUTE : 0;
8205 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); 8175 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
8206} 8176}
8207*/ 8177*/
@@ -8423,10 +8393,8 @@ static struct hda_channel_mode alc888_3st_hp_modes[3] = {
8423/* toggle front-jack and RCA according to the hp-jack state */ 8393/* toggle front-jack and RCA according to the hp-jack state */
8424static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec) 8394static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8425{ 8395{
8426 unsigned int present; 8396 unsigned int present = snd_hda_jack_detect(codec, 0x1b);
8427 8397
8428 present = snd_hda_codec_read(codec, 0x1b, 0,
8429 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8430 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8398 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8431 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8399 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8432 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8400 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
@@ -8436,10 +8404,8 @@ static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
8436/* toggle RCA according to the front-jack state */ 8404/* toggle RCA according to the front-jack state */
8437static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec) 8405static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
8438{ 8406{
8439 unsigned int present; 8407 unsigned int present = snd_hda_jack_detect(codec, 0x14);
8440 8408
8441 present = snd_hda_codec_read(codec, 0x14, 0,
8442 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8443 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8409 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8444 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8410 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8445} 8411}
@@ -8532,24 +8498,16 @@ static void alc883_haier_w66_setup(struct hda_codec *codec)
8532 8498
8533static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec) 8499static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
8534{ 8500{
8535 unsigned int present; 8501 int bits = snd_hda_jack_detect(codec, 0x14) ? HDA_AMP_MUTE : 0;
8536 unsigned char bits;
8537 8502
8538 present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
8539 & AC_PINSENSE_PRESENCE;
8540 bits = present ? HDA_AMP_MUTE : 0;
8541 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8503 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8542 HDA_AMP_MUTE, bits); 8504 HDA_AMP_MUTE, bits);
8543} 8505}
8544 8506
8545static void alc883_lenovo_101e_all_automute(struct hda_codec *codec) 8507static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
8546{ 8508{
8547 unsigned int present; 8509 int bits = snd_hda_jack_detect(codec, 0x1b) ? HDA_AMP_MUTE : 0;
8548 unsigned char bits;
8549 8510
8550 present = snd_hda_codec_read(codec, 0x1b, 0,
8551 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8552 bits = present ? HDA_AMP_MUTE : 0;
8553 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 8511 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8554 HDA_AMP_MUTE, bits); 8512 HDA_AMP_MUTE, bits);
8555 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8513 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -8700,8 +8658,7 @@ static void alc889A_mb31_automute(struct hda_codec *codec)
8700 /* Mute only in 2ch or 4ch mode */ 8658 /* Mute only in 2ch or 4ch mode */
8701 if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0) 8659 if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
8702 == 0x00) { 8660 == 0x00) {
8703 present = snd_hda_codec_read(codec, 0x15, 0, 8661 present = snd_hda_jack_detect(codec, 0x15);
8704 AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
8705 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8662 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8706 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 8663 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
8707 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, 8664 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
@@ -10044,10 +10001,8 @@ static void alc262_hp_master_update(struct hda_codec *codec)
10044static void alc262_hp_bpc_automute(struct hda_codec *codec) 10001static void alc262_hp_bpc_automute(struct hda_codec *codec)
10045{ 10002{
10046 struct alc_spec *spec = codec->spec; 10003 struct alc_spec *spec = codec->spec;
10047 unsigned int presence; 10004
10048 presence = snd_hda_codec_read(codec, 0x1b, 0, 10005 spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10049 AC_VERB_GET_PIN_SENSE, 0);
10050 spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10051 alc262_hp_master_update(codec); 10006 alc262_hp_master_update(codec);
10052} 10007}
10053 10008
@@ -10061,10 +10016,8 @@ static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
10061static void alc262_hp_wildwest_automute(struct hda_codec *codec) 10016static void alc262_hp_wildwest_automute(struct hda_codec *codec)
10062{ 10017{
10063 struct alc_spec *spec = codec->spec; 10018 struct alc_spec *spec = codec->spec;
10064 unsigned int presence; 10019
10065 presence = snd_hda_codec_read(codec, 0x15, 0, 10020 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10066 AC_VERB_GET_PIN_SENSE, 0);
10067 spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
10068 alc262_hp_master_update(codec); 10021 alc262_hp_master_update(codec);
10069} 10022}
10070 10023
@@ -10298,13 +10251,8 @@ static void alc262_hippo_automute(struct hda_codec *codec)
10298{ 10251{
10299 struct alc_spec *spec = codec->spec; 10252 struct alc_spec *spec = codec->spec;
10300 hda_nid_t hp_nid = spec->autocfg.hp_pins[0]; 10253 hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
10301 unsigned int present;
10302 10254
10303 /* need to execute and sync at first */ 10255 spec->jack_present = snd_hda_jack_detect(codec, hp_nid);
10304 snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
10305 present = snd_hda_codec_read(codec, hp_nid, 0,
10306 AC_VERB_GET_PIN_SENSE, 0);
10307 spec->jack_present = (present & 0x80000000) != 0;
10308 alc262_hippo_master_update(codec); 10256 alc262_hippo_master_update(codec);
10309} 10257}
10310 10258
@@ -10630,21 +10578,8 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
10630 unsigned int mute; 10578 unsigned int mute;
10631 10579
10632 if (force || !spec->sense_updated) { 10580 if (force || !spec->sense_updated) {
10633 unsigned int present; 10581 spec->jack_present = snd_hda_jack_detect(codec, 0x14) ||
10634 /* need to execute and sync at first */ 10582 snd_hda_jack_detect(codec, 0x1b);
10635 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
10636 /* check laptop HP jack */
10637 present = snd_hda_codec_read(codec, 0x14, 0,
10638 AC_VERB_GET_PIN_SENSE, 0);
10639 /* need to execute and sync at first */
10640 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10641 /* check docking HP jack */
10642 present |= snd_hda_codec_read(codec, 0x1b, 0,
10643 AC_VERB_GET_PIN_SENSE, 0);
10644 if (present & AC_PINSENSE_PRESENCE)
10645 spec->jack_present = 1;
10646 else
10647 spec->jack_present = 0;
10648 spec->sense_updated = 1; 10583 spec->sense_updated = 1;
10649 } 10584 }
10650 /* unmute internal speaker only if both HPs are unplugged and 10585 /* unmute internal speaker only if both HPs are unplugged and
@@ -10689,12 +10624,7 @@ static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
10689 unsigned int mute; 10624 unsigned int mute;
10690 10625
10691 if (force || !spec->sense_updated) { 10626 if (force || !spec->sense_updated) {
10692 unsigned int present_int_hp; 10627 spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
10693 /* need to execute and sync at first */
10694 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
10695 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
10696 AC_VERB_GET_PIN_SENSE, 0);
10697 spec->jack_present = (present_int_hp & 0x80000000) != 0;
10698 spec->sense_updated = 1; 10628 spec->sense_updated = 1;
10699 } 10629 }
10700 if (spec->jack_present) { 10630 if (spec->jack_present) {
@@ -10886,12 +10816,7 @@ static void alc262_ultra_automute(struct hda_codec *codec)
10886 mute = 0; 10816 mute = 0;
10887 /* auto-mute only when HP is used as HP */ 10817 /* auto-mute only when HP is used as HP */
10888 if (!spec->cur_mux[0]) { 10818 if (!spec->cur_mux[0]) {
10889 unsigned int present; 10819 spec->jack_present = snd_hda_jack_detect(codec, 0x15);
10890 /* need to execute and sync at first */
10891 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
10892 present = snd_hda_codec_read(codec, 0x15, 0,
10893 AC_VERB_GET_PIN_SENSE, 0);
10894 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
10895 if (spec->jack_present) 10820 if (spec->jack_present)
10896 mute = HDA_AMP_MUTE; 10821 mute = HDA_AMP_MUTE;
10897 } 10822 }
@@ -11933,10 +11858,7 @@ static void alc268_acer_automute(struct hda_codec *codec, int force)
11933 unsigned int mute; 11858 unsigned int mute;
11934 11859
11935 if (force || !spec->sense_updated) { 11860 if (force || !spec->sense_updated) {
11936 unsigned int present; 11861 spec->jack_present = snd_hda_jack_detect(codec, 0x14);
11937 present = snd_hda_codec_read(codec, 0x14, 0,
11938 AC_VERB_GET_PIN_SENSE, 0);
11939 spec->jack_present = (present & 0x80000000) != 0;
11940 spec->sense_updated = 1; 11862 spec->sense_updated = 1;
11941 } 11863 }
11942 if (spec->jack_present) 11864 if (spec->jack_present)
@@ -12055,8 +11977,7 @@ static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
12055 unsigned int present; 11977 unsigned int present;
12056 unsigned char bits; 11978 unsigned char bits;
12057 11979
12058 present = snd_hda_codec_read(codec, 0x15, 0, 11980 present = snd_hda_jack_detect(codec, 0x15);
12059 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
12060 bits = present ? AMP_IN_MUTE(0) : 0; 11981 bits = present ? AMP_IN_MUTE(0) : 0;
12061 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0, 11982 snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
12062 AMP_IN_MUTE(0), bits); 11983 AMP_IN_MUTE(0), bits);
@@ -13039,8 +12960,7 @@ static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
13039 unsigned int present; 12960 unsigned int present;
13040 unsigned char bits; 12961 unsigned char bits;
13041 12962
13042 present = snd_hda_codec_read(codec, 0x15, 0, 12963 present = snd_hda_jack_detect(codec, 0x15);
13043 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13044 bits = present ? AMP_IN_MUTE(0) : 0; 12964 bits = present ? AMP_IN_MUTE(0) : 0;
13045 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 12965 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13046 AMP_IN_MUTE(0), bits); 12966 AMP_IN_MUTE(0), bits);
@@ -13065,12 +12985,10 @@ static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
13065 unsigned char bits; 12985 unsigned char bits;
13066 12986
13067 /* Check laptop headphone socket */ 12987 /* Check laptop headphone socket */
13068 present = snd_hda_codec_read(codec, 0x15, 0, 12988 present = snd_hda_jack_detect(codec, 0x15);
13069 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13070 12989
13071 /* Check port replicator headphone socket */ 12990 /* Check port replicator headphone socket */
13072 present |= snd_hda_codec_read(codec, 0x1a, 0, 12991 present |= snd_hda_jack_detect(codec, 0x1a);
13073 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13074 12992
13075 bits = present ? AMP_IN_MUTE(0) : 0; 12993 bits = present ? AMP_IN_MUTE(0) : 0;
13076 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 12994 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
@@ -13094,11 +13012,8 @@ static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
13094 unsigned int present_laptop; 13012 unsigned int present_laptop;
13095 unsigned int present_dock; 13013 unsigned int present_dock;
13096 13014
13097 present_laptop = snd_hda_codec_read(codec, 0x18, 0, 13015 present_laptop = snd_hda_jack_detect(codec, 0x18);
13098 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 13016 present_dock = snd_hda_jack_detect(codec, 0x1b);
13099
13100 present_dock = snd_hda_codec_read(codec, 0x1b, 0,
13101 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13102 13017
13103 /* Laptop mic port overrides dock mic port, design decision */ 13018 /* Laptop mic port overrides dock mic port, design decision */
13104 if (present_dock) 13019 if (present_dock)
@@ -13183,8 +13098,7 @@ static void alc269_speaker_automute(struct hda_codec *codec)
13183 unsigned int present; 13098 unsigned int present;
13184 unsigned char bits; 13099 unsigned char bits;
13185 13100
13186 present = snd_hda_codec_read(codec, 0x15, 0, 13101 present = snd_hda_jack_detect(codec, 0x15);
13187 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
13188 bits = present ? AMP_IN_MUTE(0) : 0; 13102 bits = present ? AMP_IN_MUTE(0) : 0;
13189 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 13103 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
13190 AMP_IN_MUTE(0), bits); 13104 AMP_IN_MUTE(0), bits);
@@ -14162,10 +14076,8 @@ static struct hda_verb alc861_toshiba_init_verbs[] = {
14162/* toggle speaker-output according to the hp-jack state */ 14076/* toggle speaker-output according to the hp-jack state */
14163static void alc861_toshiba_automute(struct hda_codec *codec) 14077static void alc861_toshiba_automute(struct hda_codec *codec)
14164{ 14078{
14165 unsigned int present; 14079 unsigned int present = snd_hda_jack_detect(codec, 0x0f);
14166 14080
14167 present = snd_hda_codec_read(codec, 0x0f, 0,
14168 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
14169 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0, 14081 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
14170 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 14082 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
14171 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3, 14083 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
@@ -15070,9 +14982,9 @@ static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
15070 unsigned int present; 14982 unsigned int present;
15071 unsigned char bits; 14983 unsigned char bits;
15072 14984
15073 present = snd_hda_codec_read(codec, 0x18, 0, 14985 present = snd_hda_jack_detect(codec, 0x18);
15074 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
15075 bits = present ? HDA_AMP_MUTE : 0; 14986 bits = present ? HDA_AMP_MUTE : 0;
14987
15076 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, 14988 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
15077 HDA_AMP_MUTE, bits); 14989 HDA_AMP_MUTE, bits);
15078} 14990}
@@ -16383,9 +16295,9 @@ static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
16383 unsigned int present; 16295 unsigned int present;
16384 unsigned char bits; 16296 unsigned char bits;
16385 16297
16386 present = snd_hda_codec_read(codec, 0x14, 0, 16298 present = snd_hda_jack_detect(codec, 0x14);
16387 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16388 bits = present ? HDA_AMP_MUTE : 0; 16299 bits = present ? HDA_AMP_MUTE : 0;
16300
16389 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 16301 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16390 HDA_AMP_MUTE, bits); 16302 HDA_AMP_MUTE, bits);
16391} 16303}
@@ -16395,9 +16307,9 @@ static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
16395 unsigned int present; 16307 unsigned int present;
16396 unsigned char bits; 16308 unsigned char bits;
16397 16309
16398 present = snd_hda_codec_read(codec, 0x1b, 0, 16310 present = snd_hda_jack_detect(codec, 0x1b);
16399 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
16400 bits = present ? HDA_AMP_MUTE : 0; 16311 bits = present ? HDA_AMP_MUTE : 0;
16312
16401 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 16313 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16402 HDA_AMP_MUTE, bits); 16314 HDA_AMP_MUTE, bits);
16403 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 16315 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
@@ -16456,9 +16368,7 @@ static void alc663_m51va_speaker_automute(struct hda_codec *codec)
16456 unsigned int present; 16368 unsigned int present;
16457 unsigned char bits; 16369 unsigned char bits;
16458 16370
16459 present = snd_hda_codec_read(codec, 0x21, 0, 16371 present = snd_hda_jack_detect(codec, 0x21);
16460 AC_VERB_GET_PIN_SENSE, 0)
16461 & AC_PINSENSE_PRESENCE;
16462 bits = present ? HDA_AMP_MUTE : 0; 16372 bits = present ? HDA_AMP_MUTE : 0;
16463 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16373 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16464 AMP_IN_MUTE(0), bits); 16374 AMP_IN_MUTE(0), bits);
@@ -16471,9 +16381,7 @@ static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
16471 unsigned int present; 16381 unsigned int present;
16472 unsigned char bits; 16382 unsigned char bits;
16473 16383
16474 present = snd_hda_codec_read(codec, 0x21, 0, 16384 present = snd_hda_jack_detect(codec, 0x21);
16475 AC_VERB_GET_PIN_SENSE, 0)
16476 & AC_PINSENSE_PRESENCE;
16477 bits = present ? HDA_AMP_MUTE : 0; 16385 bits = present ? HDA_AMP_MUTE : 0;
16478 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16386 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16479 AMP_IN_MUTE(0), bits); 16387 AMP_IN_MUTE(0), bits);
@@ -16490,9 +16398,7 @@ static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
16490 unsigned int present; 16398 unsigned int present;
16491 unsigned char bits; 16399 unsigned char bits;
16492 16400
16493 present = snd_hda_codec_read(codec, 0x15, 0, 16401 present = snd_hda_jack_detect(codec, 0x15);
16494 AC_VERB_GET_PIN_SENSE, 0)
16495 & AC_PINSENSE_PRESENCE;
16496 bits = present ? HDA_AMP_MUTE : 0; 16402 bits = present ? HDA_AMP_MUTE : 0;
16497 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16403 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
16498 AMP_IN_MUTE(0), bits); 16404 AMP_IN_MUTE(0), bits);
@@ -16509,9 +16415,7 @@ static void alc662_f5z_speaker_automute(struct hda_codec *codec)
16509 unsigned int present; 16415 unsigned int present;
16510 unsigned char bits; 16416 unsigned char bits;
16511 16417
16512 present = snd_hda_codec_read(codec, 0x1b, 0, 16418 present = snd_hda_jack_detect(codec, 0x1b);
16513 AC_VERB_GET_PIN_SENSE, 0)
16514 & AC_PINSENSE_PRESENCE;
16515 bits = present ? 0 : PIN_OUT; 16419 bits = present ? 0 : PIN_OUT;
16516 snd_hda_codec_write(codec, 0x14, 0, 16420 snd_hda_codec_write(codec, 0x14, 0,
16517 AC_VERB_SET_PIN_WIDGET_CONTROL, bits); 16421 AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
@@ -16521,12 +16425,8 @@ static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
16521{ 16425{
16522 unsigned int present1, present2; 16426 unsigned int present1, present2;
16523 16427
16524 present1 = snd_hda_codec_read(codec, 0x21, 0, 16428 present1 = snd_hda_jack_detect(codec, 0x21);
16525 AC_VERB_GET_PIN_SENSE, 0) 16429 present2 = snd_hda_jack_detect(codec, 0x15);
16526 & AC_PINSENSE_PRESENCE;
16527 present2 = snd_hda_codec_read(codec, 0x15, 0,
16528 AC_VERB_GET_PIN_SENSE, 0)
16529 & AC_PINSENSE_PRESENCE;
16530 16430
16531 if (present1 || present2) { 16431 if (present1 || present2) {
16532 snd_hda_codec_write_cache(codec, 0x14, 0, 16432 snd_hda_codec_write_cache(codec, 0x14, 0,
@@ -16541,12 +16441,8 @@ static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
16541{ 16441{
16542 unsigned int present1, present2; 16442 unsigned int present1, present2;
16543 16443
16544 present1 = snd_hda_codec_read(codec, 0x1b, 0, 16444 present1 = snd_hda_jack_detect(codec, 0x1b);
16545 AC_VERB_GET_PIN_SENSE, 0) 16445 present2 = snd_hda_jack_detect(codec, 0x15);
16546 & AC_PINSENSE_PRESENCE;
16547 present2 = snd_hda_codec_read(codec, 0x15, 0,
16548 AC_VERB_GET_PIN_SENSE, 0)
16549 & AC_PINSENSE_PRESENCE;
16550 16446
16551 if (present1 || present2) { 16447 if (present1 || present2) {
16552 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 16448 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
@@ -16706,9 +16602,7 @@ static void alc663_g71v_hp_automute(struct hda_codec *codec)
16706 unsigned int present; 16602 unsigned int present;
16707 unsigned char bits; 16603 unsigned char bits;
16708 16604
16709 present = snd_hda_codec_read(codec, 0x21, 0, 16605 present = snd_hda_jack_detect(codec, 0x21);
16710 AC_VERB_GET_PIN_SENSE, 0)
16711 & AC_PINSENSE_PRESENCE;
16712 bits = present ? HDA_AMP_MUTE : 0; 16606 bits = present ? HDA_AMP_MUTE : 0;
16713 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 16607 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
16714 HDA_AMP_MUTE, bits); 16608 HDA_AMP_MUTE, bits);
@@ -16721,9 +16615,7 @@ static void alc663_g71v_front_automute(struct hda_codec *codec)
16721 unsigned int present; 16615 unsigned int present;
16722 unsigned char bits; 16616 unsigned char bits;
16723 16617
16724 present = snd_hda_codec_read(codec, 0x15, 0, 16618 present = snd_hda_jack_detect(codec, 0x15);
16725 AC_VERB_GET_PIN_SENSE, 0)
16726 & AC_PINSENSE_PRESENCE;
16727 bits = present ? HDA_AMP_MUTE : 0; 16619 bits = present ? HDA_AMP_MUTE : 0;
16728 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 16620 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
16729 HDA_AMP_MUTE, bits); 16621 HDA_AMP_MUTE, bits);