Commit 99ae28be authored by Takashi Iwai's avatar Takashi Iwai

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: default avatarTakashi Iwai <tiwai@suse.de>
parent 5637edb2
...@@ -4637,44 +4637,26 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec, ...@@ -4637,44 +4637,26 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
} }
EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config); EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config);
enum { int snd_hda_get_input_pin_attr(unsigned int def_conf)
MIC_ATTR_INT,
MIC_ATTR_DOCK,
MIC_ATTR_NORMAL,
MIC_ATTR_FRONT,
MIC_ATTR_REAR,
};
static int get_mic_pin_attr(unsigned int def_conf)
{ {
unsigned int loc = get_defcfg_location(def_conf); unsigned int loc = get_defcfg_location(def_conf);
unsigned int conn = get_defcfg_connect(def_conf); unsigned int conn = get_defcfg_connect(def_conf);
if (conn == AC_JACK_PORT_NONE)
return INPUT_PIN_ATTR_UNUSED;
/* Windows may claim the internal mic to be BOTH, too */ /* Windows may claim the internal mic to be BOTH, too */
if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH) if (conn == AC_JACK_PORT_FIXED || conn == AC_JACK_PORT_BOTH)
return MIC_ATTR_INT; return INPUT_PIN_ATTR_INT;
if ((loc & 0x30) == AC_JACK_LOC_INTERNAL) if ((loc & 0x30) == AC_JACK_LOC_INTERNAL)
return MIC_ATTR_INT; return INPUT_PIN_ATTR_INT;
if ((loc & 0x30) == AC_JACK_LOC_SEPARATE) if ((loc & 0x30) == AC_JACK_LOC_SEPARATE)
return MIC_ATTR_DOCK; return INPUT_PIN_ATTR_DOCK;
if (loc == AC_JACK_LOC_REAR) if (loc == AC_JACK_LOC_REAR)
return MIC_ATTR_REAR; return INPUT_PIN_ATTR_REAR;
if (loc == AC_JACK_LOC_FRONT) if (loc == AC_JACK_LOC_FRONT)
return MIC_ATTR_FRONT; return INPUT_PIN_ATTR_FRONT;
return MIC_ATTR_NORMAL; return INPUT_PIN_ATTR_NORMAL;
}
enum {
LINE_ATTR_DOCK,
LINE_ATTR_NORMAL,
};
static int get_line_pin_attr(unsigned int def_conf)
{
unsigned int loc = get_defcfg_location(def_conf);
if ((loc & 0xf0) == AC_JACK_LOC_SEPARATE)
return LINE_ATTR_DOCK;
return LINE_ATTR_NORMAL;
} }
EXPORT_SYMBOL_HDA(snd_hda_get_input_pin_attr);
/** /**
* hda_get_input_pin_label - Give a label for the given input pin * 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,9 +4673,7 @@ const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
static const char *mic_names[] = { static const char *mic_names[] = {
"Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic", "Internal Mic", "Dock Mic", "Mic", "Front Mic", "Rear Mic",
}; };
static const char *line_names[] = { int attr;
"Dock Line", "Line",
};
def_conf = snd_hda_codec_get_pincfg(codec, pin); def_conf = snd_hda_codec_get_pincfg(codec, pin);
...@@ -4701,11 +4681,19 @@ const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin, ...@@ -4701,11 +4681,19 @@ const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
case AC_JACK_MIC_IN: case AC_JACK_MIC_IN:
if (!check_location) if (!check_location)
return "Mic"; return "Mic";
return mic_names[get_mic_pin_attr(def_conf)]; attr = snd_hda_get_input_pin_attr(def_conf);
if (!attr)
return "None";
return mic_names[attr - 1];
case AC_JACK_LINE_IN: case AC_JACK_LINE_IN:
if (!check_location) if (!check_location)
return "Line"; return "Line";
return line_names[get_line_pin_attr(def_conf)]; attr = snd_hda_get_input_pin_attr(def_conf);
if (!attr)
return "None";
if (attr == INPUT_PIN_ATTR_DOCK)
return "Dock Line";
return "Line";
case AC_JACK_AUX: case AC_JACK_AUX:
return "Aux"; return "Aux";
case AC_JACK_CD: case AC_JACK_CD:
...@@ -4732,16 +4720,16 @@ static int check_mic_location_need(struct hda_codec *codec, ...@@ -4732,16 +4720,16 @@ static int check_mic_location_need(struct hda_codec *codec,
int i, attr, attr2; int i, attr, attr2;
defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin); defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[input].pin);
attr = get_mic_pin_attr(defc); attr = snd_hda_get_input_pin_attr(defc);
/* for internal or docking mics, we need locations */ /* for internal or docking mics, we need locations */
if (attr <= MIC_ATTR_NORMAL) if (attr <= INPUT_PIN_ATTR_NORMAL)
return 1; return 1;
attr = 0; attr = 0;
for (i = 0; i < cfg->num_inputs; i++) { for (i = 0; i < cfg->num_inputs; i++) {
defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin); defc = snd_hda_codec_get_pincfg(codec, cfg->inputs[i].pin);
attr2 = get_mic_pin_attr(defc); attr2 = snd_hda_get_input_pin_attr(defc);
if (attr2 >= MIC_ATTR_NORMAL) { if (attr2 >= INPUT_PIN_ATTR_NORMAL) {
if (attr && attr != attr2) if (attr && attr != attr2)
return 1; /* different locations found */ return 1; /* different locations found */
attr = attr2; attr = attr2;
......
...@@ -395,6 +395,17 @@ const char *hda_get_autocfg_input_label(struct hda_codec *codec, ...@@ -395,6 +395,17 @@ const char *hda_get_autocfg_input_label(struct hda_codec *codec,
int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label, int snd_hda_add_imux_item(struct hda_input_mux *imux, const char *label,
int index, int *type_index_ret); int index, int *type_index_ret);
enum {
INPUT_PIN_ATTR_UNUSED, /* pin not connected */
INPUT_PIN_ATTR_INT, /* internal mic/line-in */
INPUT_PIN_ATTR_DOCK, /* docking mic/line-in */
INPUT_PIN_ATTR_NORMAL, /* mic/line-in jack */
INPUT_PIN_ATTR_FRONT, /* mic/line-in jack in front */
INPUT_PIN_ATTR_REAR, /* mic/line-in jack in rear */
};
int snd_hda_get_input_pin_attr(unsigned int def_conf);
struct auto_pin_cfg { struct auto_pin_cfg {
int line_outs; int line_outs;
/* sorted in the order of Front/Surr/CLFE/Side */ /* sorted in the order of Front/Surr/CLFE/Side */
......
...@@ -334,7 +334,7 @@ static int is_ext_mic(struct hda_codec *codec, unsigned int idx) ...@@ -334,7 +334,7 @@ static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
if (!(val & AC_PINCAP_PRES_DETECT)) if (!(val & AC_PINCAP_PRES_DETECT))
return 0; return 0;
val = snd_hda_codec_get_pincfg(codec, pin); val = snd_hda_codec_get_pincfg(codec, pin);
return (get_defcfg_connect(val) == AC_JACK_PORT_COMPLEX); return (snd_hda_get_input_pin_attr(val) != INPUT_PIN_ATTR_INT);
} }
static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin, static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
......
...@@ -3462,19 +3462,12 @@ static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) ...@@ -3462,19 +3462,12 @@ static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
} }
} }
static int is_int_mic_conn(unsigned int def_conf)
{
unsigned int loc = get_defcfg_location(def_conf);
return get_defcfg_connect(def_conf) == AC_JACK_PORT_FIXED ||
(loc & 0x30) == AC_JACK_LOC_INTERNAL;
}
/* return true if it's an internal-mic pin */ /* return true if it's an internal-mic pin */
static int is_int_mic(struct hda_codec *codec, hda_nid_t pin) static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
{ {
unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
is_int_mic_conn(def_conf); snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
} }
/* return true if it's an external-mic pin */ /* 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,7 +3475,7 @@ static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
{ {
unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin); unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
return get_defcfg_device(def_conf) == AC_JACK_MIC_IN && return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
!is_int_mic_conn(def_conf); snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT;
} }
/* check whether the pin config is suitable for auto-mic switching; /* check whether the pin config is suitable for auto-mic switching;
......
...@@ -1403,19 +1403,19 @@ static void alc_init_auto_mic(struct hda_codec *codec) ...@@ -1403,19 +1403,19 @@ static void alc_init_auto_mic(struct hda_codec *codec)
hda_nid_t nid = cfg->inputs[i].pin; hda_nid_t nid = cfg->inputs[i].pin;
unsigned int defcfg; unsigned int defcfg;
defcfg = snd_hda_codec_get_pincfg(codec, nid); defcfg = snd_hda_codec_get_pincfg(codec, nid);
switch (get_defcfg_connect(defcfg)) { switch (snd_hda_get_input_pin_attr(defcfg)) {
case AC_JACK_PORT_FIXED: case INPUT_PIN_ATTR_INT:
if (fixed) if (fixed)
return; /* already occupied */ return; /* already occupied */
fixed = nid; fixed = nid;
break; break;
case AC_JACK_PORT_COMPLEX: case INPUT_PIN_ATTR_UNUSED:
return; /* invalid entry */
default:
if (ext) if (ext)
return; /* already occupied */ return; /* already occupied */
ext = nid; ext = nid;
break; break;
default:
return; /* invalid entry */
} }
} }
if (!ext || !fixed) if (!ext || !fixed)
......
...@@ -2778,7 +2778,7 @@ static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec, ...@@ -2778,7 +2778,7 @@ static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
struct sigmatel_spec *spec = codec->spec; struct sigmatel_spec *spec = codec->spec;
char name[22]; char name[22];
if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) { if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
&& nid == spec->line_switch) && nid == spec->line_switch)
control = STAC_CTL_WIDGET_IO_SWITCH; 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,7 +2857,7 @@ static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
def_conf = snd_hda_codec_get_pincfg(codec, nid); def_conf = snd_hda_codec_get_pincfg(codec, nid);
/* some laptops have an internal analog microphone /* some laptops have an internal analog microphone
* which can't be used as a output */ * which can't be used as a output */
if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) { if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
pincap = snd_hda_query_pin_caps(codec, nid); pincap = snd_hda_query_pin_caps(codec, nid);
if (pincap & AC_PINCAP_OUT) { if (pincap & AC_PINCAP_OUT) {
*dac = get_unassigned_dac(codec, nid); *dac = get_unassigned_dac(codec, nid);
...@@ -3496,23 +3496,23 @@ static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid, ...@@ -3496,23 +3496,23 @@ static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
if (!nid) if (!nid)
return 0; return 0;
cfg = snd_hda_codec_get_pincfg(codec, nid); cfg = snd_hda_codec_get_pincfg(codec, nid);
switch (get_defcfg_connect(cfg)) { switch (snd_hda_get_input_pin_attr(cfg)) {
case AC_JACK_PORT_BOTH: case INPUT_PIN_ATTR_INT:
case AC_JACK_PORT_FIXED:
if (*fixed) if (*fixed)
return 1; /* already occupied */ return 1; /* already occupied */
*fixed = nid; *fixed = nid;
break; break;
case AC_JACK_PORT_COMPLEX: case INPUT_PIN_ATTR_UNUSED:
if ((get_defcfg_location(cfg) & 0xF0) == AC_JACK_LOC_SEPARATE) { break;
case INPUT_PIN_ATTR_DOCK:
if (*dock) if (*dock)
return 1; /* already occupied */ return 1; /* already occupied */
*dock = nid; *dock = nid;
} else { break;
default:
if (*ext) if (*ext)
return 1; /* already occupied */ return 1; /* already occupied */
*ext = nid; *ext = nid;
}
break; break;
} }
return 0; return 0;
......
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