提交 864f92be 编写于 作者: W Wu Fengguang 提交者: Takashi Iwai

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: NWu Fengguang <fengguang.wu@intel.com>
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 23ccc2bd
...@@ -1317,6 +1317,40 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid) ...@@ -1317,6 +1317,40 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
} }
EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
/**
* snd_hda_pin_sense - execute pin sense measurement
* @codec: the CODEC to sense
* @nid: the pin NID to sense
*
* Execute necessary pin sense measurement and return its Presence Detect,
* Impedance, ELD Valid etc. status bits.
*/
u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
{
u32 pincap = snd_hda_query_pin_caps(codec, nid);
if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
return snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_SENSE, 0);
}
EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
/**
* snd_hda_jack_detect - query pin Presence Detect status
* @codec: the CODEC to sense
* @nid: the pin NID to sense
*
* Query and return the pin's Presence Detect status.
*/
int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
{
u32 sense = snd_hda_pin_sense(codec, nid);
return !!(sense & AC_PINSENSE_PRESENCE);
}
EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
/* /*
* read the current volume to info * read the current volume to info
* if the cache exists, read the cache value. * if the cache exists, read the cache value.
......
...@@ -309,17 +309,12 @@ static int hdmi_update_eld(struct hdmi_eld *e, ...@@ -309,17 +309,12 @@ static int hdmi_update_eld(struct hdmi_eld *e,
return -EINVAL; return -EINVAL;
} }
static int hdmi_present_sense(struct hda_codec *codec, hda_nid_t nid)
{
return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0);
}
static int hdmi_eld_valid(struct hda_codec *codec, hda_nid_t nid) static int hdmi_eld_valid(struct hda_codec *codec, hda_nid_t nid)
{ {
int eldv; int eldv;
int present; int present;
present = hdmi_present_sense(codec, nid); present = snd_hda_pin_sense(codec, nid);
eldv = (present & AC_PINSENSE_ELDV); eldv = (present & AC_PINSENSE_ELDV);
present = (present & AC_PINSENSE_PRESENCE); present = (present & AC_PINSENSE_PRESENCE);
......
...@@ -461,6 +461,8 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction); ...@@ -461,6 +461,8 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
unsigned int caps); unsigned int caps);
u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
struct hda_nid_item { struct hda_nid_item {
struct snd_kcontrol *kctl; struct snd_kcontrol *kctl;
......
...@@ -807,7 +807,7 @@ static void cs_automute(struct hda_codec *codec) ...@@ -807,7 +807,7 @@ static void cs_automute(struct hda_codec *codec)
{ {
struct cs_spec *spec = codec->spec; struct cs_spec *spec = codec->spec;
struct auto_pin_cfg *cfg = &spec->autocfg; struct auto_pin_cfg *cfg = &spec->autocfg;
unsigned int caps, present, hp_present; unsigned int caps, hp_present;
hda_nid_t nid; hda_nid_t nid;
int i; int i;
...@@ -817,12 +817,7 @@ static void cs_automute(struct hda_codec *codec) ...@@ -817,12 +817,7 @@ static void cs_automute(struct hda_codec *codec)
caps = snd_hda_query_pin_caps(codec, nid); caps = snd_hda_query_pin_caps(codec, nid);
if (!(caps & AC_PINCAP_PRES_DETECT)) if (!(caps & AC_PINCAP_PRES_DETECT))
continue; continue;
if (caps & AC_PINCAP_TRIG_REQ) hp_present = snd_hda_jack_detect(codec, nid);
snd_hda_codec_read(codec, nid, 0,
AC_VERB_SET_PIN_SENSE, 0);
present = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_SENSE, 0);
hp_present |= (present & AC_PINSENSE_PRESENCE) != 0;
if (hp_present) if (hp_present)
break; break;
} }
...@@ -844,15 +839,11 @@ static void cs_automic(struct hda_codec *codec) ...@@ -844,15 +839,11 @@ static void cs_automic(struct hda_codec *codec)
struct cs_spec *spec = codec->spec; struct cs_spec *spec = codec->spec;
struct auto_pin_cfg *cfg = &spec->autocfg; struct auto_pin_cfg *cfg = &spec->autocfg;
hda_nid_t nid; hda_nid_t nid;
unsigned int caps, present; unsigned int present;
nid = cfg->input_pins[spec->automic_idx]; nid = cfg->input_pins[spec->automic_idx];
caps = snd_hda_query_pin_caps(codec, nid); present = snd_hda_jack_detect(codec, nid);
if (caps & AC_PINCAP_TRIG_REQ) if (present)
snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
present = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_SENSE, 0);
if (present & AC_PINSENSE_PRESENCE)
change_cur_input(codec, spec->automic_idx, 0); change_cur_input(codec, spec->automic_idx, 0);
else { else {
unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ? unsigned int imic = (spec->automic_idx == AUTO_PIN_MIC) ?
......
...@@ -961,18 +961,12 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid, ...@@ -961,18 +961,12 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
static void alc_automute_pin(struct hda_codec *codec) static void alc_automute_pin(struct hda_codec *codec)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
unsigned int present, pincap;
unsigned int nid = spec->autocfg.hp_pins[0]; unsigned int nid = spec->autocfg.hp_pins[0];
int i; int i;
if (!nid) if (!nid)
return; return;
pincap = snd_hda_query_pin_caps(codec, nid); spec->jack_present = snd_hda_jack_detect(codec, nid);
if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
snd_hda_codec_read(codec, nid, 0, AC_VERB_SET_PIN_SENSE, 0);
present = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) { for (i = 0; i < ARRAY_SIZE(spec->autocfg.speaker_pins); i++) {
nid = spec->autocfg.speaker_pins[i]; nid = spec->autocfg.speaker_pins[i];
if (!nid) if (!nid)
...@@ -1012,9 +1006,7 @@ static void alc_mic_automute(struct hda_codec *codec) ...@@ -1012,9 +1006,7 @@ static void alc_mic_automute(struct hda_codec *codec)
cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0]; cap_nid = spec->capsrc_nids ? spec->capsrc_nids[0] : spec->adc_nids[0];
present = snd_hda_codec_read(codec, spec->ext_mic.pin, 0, present = snd_hda_jack_detect(codec, spec->ext_mic.pin);
AC_VERB_GET_PIN_SENSE, 0);
present &= AC_PINSENSE_PRESENCE;
if (present) { if (present) {
alive = &spec->ext_mic; alive = &spec->ext_mic;
dead = &spec->int_mic; dead = &spec->int_mic;
...@@ -1513,7 +1505,7 @@ static struct hda_verb alc888_fujitsu_xa3530_verbs[] = { ...@@ -1513,7 +1505,7 @@ static struct hda_verb alc888_fujitsu_xa3530_verbs[] = {
static void alc_automute_amp(struct hda_codec *codec) static void alc_automute_amp(struct hda_codec *codec)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
unsigned int val, mute, pincap; unsigned int mute;
hda_nid_t nid; hda_nid_t nid;
int i; int i;
...@@ -1522,13 +1514,7 @@ static void alc_automute_amp(struct hda_codec *codec) ...@@ -1522,13 +1514,7 @@ static void alc_automute_amp(struct hda_codec *codec)
nid = spec->autocfg.hp_pins[i]; nid = spec->autocfg.hp_pins[i];
if (!nid) if (!nid)
break; break;
pincap = snd_hda_query_pin_caps(codec, nid); if (snd_hda_jack_detect(codec, nid)) {
if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
snd_hda_codec_read(codec, nid, 0,
AC_VERB_SET_PIN_SENSE, 0);
val = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_SENSE, 0);
if (val & AC_PINSENSE_PRESENCE) {
spec->jack_present = 1; spec->jack_present = 1;
break; break;
} }
...@@ -2784,8 +2770,7 @@ static void alc880_uniwill_mic_automute(struct hda_codec *codec) ...@@ -2784,8 +2770,7 @@ static void alc880_uniwill_mic_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x18, 0, present = snd_hda_jack_detect(codec, 0x18);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
} }
...@@ -5102,11 +5087,8 @@ static struct hda_verb alc260_hp_unsol_verbs[] = { ...@@ -5102,11 +5087,8 @@ static struct hda_verb alc260_hp_unsol_verbs[] = {
static void alc260_hp_automute(struct hda_codec *codec) static void alc260_hp_automute(struct hda_codec *codec)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
unsigned int present;
present = snd_hda_codec_read(codec, 0x10, 0, spec->jack_present = snd_hda_jack_detect(codec, 0x10);
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
alc260_hp_master_update(codec, 0x0f, 0x10, 0x11); alc260_hp_master_update(codec, 0x0f, 0x10, 0x11);
} }
...@@ -5171,11 +5153,8 @@ static struct hda_verb alc260_hp_3013_unsol_verbs[] = { ...@@ -5171,11 +5153,8 @@ static struct hda_verb alc260_hp_3013_unsol_verbs[] = {
static void alc260_hp_3013_automute(struct hda_codec *codec) static void alc260_hp_3013_automute(struct hda_codec *codec)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
unsigned int present;
present = snd_hda_codec_read(codec, 0x15, 0, spec->jack_present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
alc260_hp_master_update(codec, 0x15, 0x10, 0x11); alc260_hp_master_update(codec, 0x15, 0x10, 0x11);
} }
...@@ -5188,12 +5167,8 @@ static void alc260_hp_3013_unsol_event(struct hda_codec *codec, ...@@ -5188,12 +5167,8 @@ static void alc260_hp_3013_unsol_event(struct hda_codec *codec,
static void alc260_hp_3012_automute(struct hda_codec *codec) static void alc260_hp_3012_automute(struct hda_codec *codec)
{ {
unsigned int present, bits; unsigned int bits = snd_hda_jack_detect(codec, 0x10) ? 0 : PIN_OUT;
present = snd_hda_codec_read(codec, 0x10, 0,
AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
bits = present ? 0 : PIN_OUT;
snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
bits); bits);
snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 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,8 +5738,7 @@ static void alc260_replacer_672v_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
/* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */ /* speaker --> GPIO Data 0, hp or spdif --> GPIO data 1 */
present = snd_hda_codec_read(codec, 0x0f, 0, present = snd_hda_jack_detect(codec, 0x0f);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
if (present) { if (present) {
snd_hda_codec_write_cache(codec, 0x01, 0, snd_hda_codec_write_cache(codec, 0x01, 0,
AC_VERB_SET_GPIO_DATA, 1); AC_VERB_SET_GPIO_DATA, 1);
...@@ -8196,12 +8170,8 @@ static void alc883_mitac_setup(struct hda_codec *codec) ...@@ -8196,12 +8170,8 @@ static void alc883_mitac_setup(struct hda_codec *codec)
/* /*
static void alc883_mitac_mic_automute(struct hda_codec *codec) static void alc883_mitac_mic_automute(struct hda_codec *codec)
{ {
unsigned int present; unsigned char bits = snd_hda_jack_detect(codec, 0x18) ? HDA_AMP_MUTE : 0;
unsigned char bits;
present = snd_hda_codec_read(codec, 0x18, 0,
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits); snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, HDA_AMP_MUTE, bits);
} }
*/ */
...@@ -8423,10 +8393,8 @@ static struct hda_channel_mode alc888_3st_hp_modes[3] = { ...@@ -8423,10 +8393,8 @@ static struct hda_channel_mode alc888_3st_hp_modes[3] = {
/* toggle front-jack and RCA according to the hp-jack state */ /* toggle front-jack and RCA according to the hp-jack state */
static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec) static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
{ {
unsigned int present; unsigned int present = snd_hda_jack_detect(codec, 0x1b);
present = snd_hda_codec_read(codec, 0x1b, 0,
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, 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,10 +8404,8 @@ static void alc888_lenovo_ms7195_front_automute(struct hda_codec *codec)
/* toggle RCA according to the front-jack state */ /* toggle RCA according to the front-jack state */
static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec) static void alc888_lenovo_ms7195_rca_automute(struct hda_codec *codec)
{ {
unsigned int present; unsigned int present = snd_hda_jack_detect(codec, 0x14);
present = snd_hda_codec_read(codec, 0x14, 0,
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
} }
...@@ -8532,24 +8498,16 @@ static void alc883_haier_w66_setup(struct hda_codec *codec) ...@@ -8532,24 +8498,16 @@ static void alc883_haier_w66_setup(struct hda_codec *codec)
static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec) static void alc883_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
{ {
unsigned int present; int bits = snd_hda_jack_detect(codec, 0x14) ? HDA_AMP_MUTE : 0;
unsigned char bits;
present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
HDA_AMP_MUTE, bits); HDA_AMP_MUTE, bits);
} }
static void alc883_lenovo_101e_all_automute(struct hda_codec *codec) static void alc883_lenovo_101e_all_automute(struct hda_codec *codec)
{ {
unsigned int present; int bits = snd_hda_jack_detect(codec, 0x1b) ? HDA_AMP_MUTE : 0;
unsigned char bits;
present = snd_hda_codec_read(codec, 0x1b, 0,
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
HDA_AMP_MUTE, bits); HDA_AMP_MUTE, bits);
snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
...@@ -8700,8 +8658,7 @@ static void alc889A_mb31_automute(struct hda_codec *codec) ...@@ -8700,8 +8658,7 @@ static void alc889A_mb31_automute(struct hda_codec *codec)
/* Mute only in 2ch or 4ch mode */ /* Mute only in 2ch or 4ch mode */
if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0) if (snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_CONNECT_SEL, 0)
== 0x00) { == 0x00) {
present = snd_hda_codec_read(codec, 0x15, 0, present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0) & AC_PINSENSE_PRESENCE;
snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
...@@ -10044,10 +10001,8 @@ static void alc262_hp_master_update(struct hda_codec *codec) ...@@ -10044,10 +10001,8 @@ static void alc262_hp_master_update(struct hda_codec *codec)
static void alc262_hp_bpc_automute(struct hda_codec *codec) static void alc262_hp_bpc_automute(struct hda_codec *codec)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
unsigned int presence;
presence = snd_hda_codec_read(codec, 0x1b, 0, spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
alc262_hp_master_update(codec); alc262_hp_master_update(codec);
} }
...@@ -10061,10 +10016,8 @@ static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res) ...@@ -10061,10 +10016,8 @@ static void alc262_hp_bpc_unsol_event(struct hda_codec *codec, unsigned int res)
static void alc262_hp_wildwest_automute(struct hda_codec *codec) static void alc262_hp_wildwest_automute(struct hda_codec *codec)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
unsigned int presence;
presence = snd_hda_codec_read(codec, 0x15, 0, spec->jack_present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = !!(presence & AC_PINSENSE_PRESENCE);
alc262_hp_master_update(codec); alc262_hp_master_update(codec);
} }
...@@ -10298,13 +10251,8 @@ static void alc262_hippo_automute(struct hda_codec *codec) ...@@ -10298,13 +10251,8 @@ static void alc262_hippo_automute(struct hda_codec *codec)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
hda_nid_t hp_nid = spec->autocfg.hp_pins[0]; hda_nid_t hp_nid = spec->autocfg.hp_pins[0];
unsigned int present;
/* need to execute and sync at first */ spec->jack_present = snd_hda_jack_detect(codec, hp_nid);
snd_hda_codec_read(codec, hp_nid, 0, AC_VERB_SET_PIN_SENSE, 0);
present = snd_hda_codec_read(codec, hp_nid, 0,
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = (present & 0x80000000) != 0;
alc262_hippo_master_update(codec); alc262_hippo_master_update(codec);
} }
...@@ -10630,21 +10578,8 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force) ...@@ -10630,21 +10578,8 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
unsigned int mute; unsigned int mute;
if (force || !spec->sense_updated) { if (force || !spec->sense_updated) {
unsigned int present; spec->jack_present = snd_hda_jack_detect(codec, 0x14) ||
/* need to execute and sync at first */ snd_hda_jack_detect(codec, 0x1b);
snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
/* check laptop HP jack */
present = snd_hda_codec_read(codec, 0x14, 0,
AC_VERB_GET_PIN_SENSE, 0);
/* need to execute and sync at first */
snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
/* check docking HP jack */
present |= snd_hda_codec_read(codec, 0x1b, 0,
AC_VERB_GET_PIN_SENSE, 0);
if (present & AC_PINSENSE_PRESENCE)
spec->jack_present = 1;
else
spec->jack_present = 0;
spec->sense_updated = 1; spec->sense_updated = 1;
} }
/* unmute internal speaker only if both HPs are unplugged and /* 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,12 +10624,7 @@ static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
unsigned int mute; unsigned int mute;
if (force || !spec->sense_updated) { if (force || !spec->sense_updated) {
unsigned int present_int_hp; spec->jack_present = snd_hda_jack_detect(codec, 0x1b);
/* need to execute and sync at first */
snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = (present_int_hp & 0x80000000) != 0;
spec->sense_updated = 1; spec->sense_updated = 1;
} }
if (spec->jack_present) { if (spec->jack_present) {
...@@ -10886,12 +10816,7 @@ static void alc262_ultra_automute(struct hda_codec *codec) ...@@ -10886,12 +10816,7 @@ static void alc262_ultra_automute(struct hda_codec *codec)
mute = 0; mute = 0;
/* auto-mute only when HP is used as HP */ /* auto-mute only when HP is used as HP */
if (!spec->cur_mux[0]) { if (!spec->cur_mux[0]) {
unsigned int present; spec->jack_present = snd_hda_jack_detect(codec, 0x15);
/* need to execute and sync at first */
snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
present = snd_hda_codec_read(codec, 0x15, 0,
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
if (spec->jack_present) if (spec->jack_present)
mute = HDA_AMP_MUTE; mute = HDA_AMP_MUTE;
} }
...@@ -11933,10 +11858,7 @@ static void alc268_acer_automute(struct hda_codec *codec, int force) ...@@ -11933,10 +11858,7 @@ static void alc268_acer_automute(struct hda_codec *codec, int force)
unsigned int mute; unsigned int mute;
if (force || !spec->sense_updated) { if (force || !spec->sense_updated) {
unsigned int present; spec->jack_present = snd_hda_jack_detect(codec, 0x14);
present = snd_hda_codec_read(codec, 0x14, 0,
AC_VERB_GET_PIN_SENSE, 0);
spec->jack_present = (present & 0x80000000) != 0;
spec->sense_updated = 1; spec->sense_updated = 1;
} }
if (spec->jack_present) if (spec->jack_present)
...@@ -12055,8 +11977,7 @@ static void alc268_aspire_one_speaker_automute(struct hda_codec *codec) ...@@ -12055,8 +11977,7 @@ static void alc268_aspire_one_speaker_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x15, 0, present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? AMP_IN_MUTE(0) : 0; bits = present ? AMP_IN_MUTE(0) : 0;
snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0, snd_hda_codec_amp_stereo(codec, 0x0f, HDA_INPUT, 0,
AMP_IN_MUTE(0), bits); AMP_IN_MUTE(0), bits);
...@@ -13039,8 +12960,7 @@ static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec) ...@@ -13039,8 +12960,7 @@ static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x15, 0, present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? AMP_IN_MUTE(0) : 0; bits = present ? AMP_IN_MUTE(0) : 0;
snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
AMP_IN_MUTE(0), bits); AMP_IN_MUTE(0), bits);
...@@ -13065,12 +12985,10 @@ static void alc269_lifebook_speaker_automute(struct hda_codec *codec) ...@@ -13065,12 +12985,10 @@ static void alc269_lifebook_speaker_automute(struct hda_codec *codec)
unsigned char bits; unsigned char bits;
/* Check laptop headphone socket */ /* Check laptop headphone socket */
present = snd_hda_codec_read(codec, 0x15, 0, present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
/* Check port replicator headphone socket */ /* Check port replicator headphone socket */
present |= snd_hda_codec_read(codec, 0x1a, 0, present |= snd_hda_jack_detect(codec, 0x1a);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? AMP_IN_MUTE(0) : 0; bits = present ? AMP_IN_MUTE(0) : 0;
snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 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,11 +13012,8 @@ static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
unsigned int present_laptop; unsigned int present_laptop;
unsigned int present_dock; unsigned int present_dock;
present_laptop = snd_hda_codec_read(codec, 0x18, 0, present_laptop = snd_hda_jack_detect(codec, 0x18);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; present_dock = snd_hda_jack_detect(codec, 0x1b);
present_dock = snd_hda_codec_read(codec, 0x1b, 0,
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
/* Laptop mic port overrides dock mic port, design decision */ /* Laptop mic port overrides dock mic port, design decision */
if (present_dock) if (present_dock)
...@@ -13183,8 +13098,7 @@ static void alc269_speaker_automute(struct hda_codec *codec) ...@@ -13183,8 +13098,7 @@ static void alc269_speaker_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x15, 0, present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? AMP_IN_MUTE(0) : 0; bits = present ? AMP_IN_MUTE(0) : 0;
snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
AMP_IN_MUTE(0), bits); AMP_IN_MUTE(0), bits);
...@@ -14162,10 +14076,8 @@ static struct hda_verb alc861_toshiba_init_verbs[] = { ...@@ -14162,10 +14076,8 @@ static struct hda_verb alc861_toshiba_init_verbs[] = {
/* toggle speaker-output according to the hp-jack state */ /* toggle speaker-output according to the hp-jack state */
static void alc861_toshiba_automute(struct hda_codec *codec) static void alc861_toshiba_automute(struct hda_codec *codec)
{ {
unsigned int present; unsigned int present = snd_hda_jack_detect(codec, 0x0f);
present = snd_hda_codec_read(codec, 0x0f, 0,
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0, snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3, 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,9 +14982,9 @@ static void alc861vd_lenovo_mic_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x18, 0, present = snd_hda_jack_detect(codec, 0x18);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1, snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
HDA_AMP_MUTE, bits); HDA_AMP_MUTE, bits);
} }
...@@ -16383,9 +16295,9 @@ static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec) ...@@ -16383,9 +16295,9 @@ static void alc662_lenovo_101e_ispeaker_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x14, 0, present = snd_hda_jack_detect(codec, 0x14);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
HDA_AMP_MUTE, bits); HDA_AMP_MUTE, bits);
} }
...@@ -16395,9 +16307,9 @@ static void alc662_lenovo_101e_all_automute(struct hda_codec *codec) ...@@ -16395,9 +16307,9 @@ static void alc662_lenovo_101e_all_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x1b, 0, present = snd_hda_jack_detect(codec, 0x1b);
AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
HDA_AMP_MUTE, bits); HDA_AMP_MUTE, bits);
snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 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,9 +16368,7 @@ static void alc663_m51va_speaker_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x21, 0, present = snd_hda_jack_detect(codec, 0x21);
AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
AMP_IN_MUTE(0), bits); AMP_IN_MUTE(0), bits);
...@@ -16471,9 +16381,7 @@ static void alc663_21jd_two_speaker_automute(struct hda_codec *codec) ...@@ -16471,9 +16381,7 @@ static void alc663_21jd_two_speaker_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x21, 0, present = snd_hda_jack_detect(codec, 0x21);
AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
AMP_IN_MUTE(0), bits); AMP_IN_MUTE(0), bits);
...@@ -16490,9 +16398,7 @@ static void alc663_15jd_two_speaker_automute(struct hda_codec *codec) ...@@ -16490,9 +16398,7 @@ static void alc663_15jd_two_speaker_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x15, 0, present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0,
AMP_IN_MUTE(0), bits); AMP_IN_MUTE(0), bits);
...@@ -16509,9 +16415,7 @@ static void alc662_f5z_speaker_automute(struct hda_codec *codec) ...@@ -16509,9 +16415,7 @@ static void alc662_f5z_speaker_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x1b, 0, present = snd_hda_jack_detect(codec, 0x1b);
AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
bits = present ? 0 : PIN_OUT; bits = present ? 0 : PIN_OUT;
snd_hda_codec_write(codec, 0x14, 0, snd_hda_codec_write(codec, 0x14, 0,
AC_VERB_SET_PIN_WIDGET_CONTROL, bits); AC_VERB_SET_PIN_WIDGET_CONTROL, bits);
...@@ -16521,12 +16425,8 @@ static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec) ...@@ -16521,12 +16425,8 @@ static void alc663_two_hp_m1_speaker_automute(struct hda_codec *codec)
{ {
unsigned int present1, present2; unsigned int present1, present2;
present1 = snd_hda_codec_read(codec, 0x21, 0, present1 = snd_hda_jack_detect(codec, 0x21);
AC_VERB_GET_PIN_SENSE, 0) present2 = snd_hda_jack_detect(codec, 0x15);
& AC_PINSENSE_PRESENCE;
present2 = snd_hda_codec_read(codec, 0x15, 0,
AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
if (present1 || present2) { if (present1 || present2) {
snd_hda_codec_write_cache(codec, 0x14, 0, 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,12 +16441,8 @@ static void alc663_two_hp_m2_speaker_automute(struct hda_codec *codec)
{ {
unsigned int present1, present2; unsigned int present1, present2;
present1 = snd_hda_codec_read(codec, 0x1b, 0, present1 = snd_hda_jack_detect(codec, 0x1b);
AC_VERB_GET_PIN_SENSE, 0) present2 = snd_hda_jack_detect(codec, 0x15);
& AC_PINSENSE_PRESENCE;
present2 = snd_hda_codec_read(codec, 0x15, 0,
AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
if (present1 || present2) { if (present1 || present2) {
snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 0, 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,9 +16602,7 @@ static void alc663_g71v_hp_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x21, 0, present = snd_hda_jack_detect(codec, 0x21);
AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
HDA_AMP_MUTE, bits); HDA_AMP_MUTE, bits);
...@@ -16721,9 +16615,7 @@ static void alc663_g71v_front_automute(struct hda_codec *codec) ...@@ -16721,9 +16615,7 @@ static void alc663_g71v_front_automute(struct hda_codec *codec)
unsigned int present; unsigned int present;
unsigned char bits; unsigned char bits;
present = snd_hda_codec_read(codec, 0x15, 0, present = snd_hda_jack_detect(codec, 0x15);
AC_VERB_GET_PIN_SENSE, 0)
& AC_PINSENSE_PRESENCE;
bits = present ? HDA_AMP_MUTE : 0; bits = present ? HDA_AMP_MUTE : 0;
snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
HDA_AMP_MUTE, bits); HDA_AMP_MUTE, bits);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册