Commit 864f92be authored by Wu Fengguang's avatar Wu Fengguang Committed by 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: default avatarWu Fengguang <fengguang.wu@intel.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 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 @@ out_fail: ...@@ -309,17 +309,12 @@ out_fail:
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) ?
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment