Commit 4740860b authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Add snd_hda_get_default_vref() helper function

Add a new helper function to guess the default VREF pin control bits
for mic in.  This can be used to set the pin control value safely
matching with the actual pin capabilities.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent cdd03ced
...@@ -4795,6 +4795,33 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec, ...@@ -4795,6 +4795,33 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
} }
EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup); EXPORT_SYMBOL_HDA(snd_hda_multi_out_analog_cleanup);
/**
* snd_hda_get_default_vref - Get the default (mic) VREF pin bits
*
* Guess the suitable VREF pin bits to be set as the pin-control value.
* Note: the function doesn't set the AC_PINCTL_IN_EN bit.
*/
unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin)
{
unsigned int pincap;
unsigned int oldval;
oldval = snd_hda_codec_read(codec, pin, 0,
AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
pincap = snd_hda_query_pin_caps(codec, pin);
pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
/* Exception: if the default pin setup is vref50, we give it priority */
if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
return AC_PINCTL_VREF_80;
else if (pincap & AC_PINCAP_VREF_50)
return AC_PINCTL_VREF_50;
else if (pincap & AC_PINCAP_VREF_100)
return AC_PINCTL_VREF_100;
else if (pincap & AC_PINCAP_VREF_GRD)
return AC_PINCTL_VREF_GRD;
return AC_PINCTL_VREF_HIZ;
}
EXPORT_SYMBOL_HDA(snd_hda_get_default_vref);
int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
unsigned int val, bool cached) unsigned int val, bool cached)
{ {
......
...@@ -502,6 +502,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec, ...@@ -502,6 +502,7 @@ int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
#define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN) #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
#define PIN_HP_AMP (AC_PINCTL_HP_EN) #define PIN_HP_AMP (AC_PINCTL_HP_EN)
unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
unsigned int val, bool cached); unsigned int val, bool cached);
...@@ -517,6 +518,7 @@ int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, ...@@ -517,6 +518,7 @@ int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
* HP-drive capability, the HP bit is omitted. * HP-drive capability, the HP bit is omitted.
* *
* The function doesn't check the input VREF capability bits, though. * The function doesn't check the input VREF capability bits, though.
* Use snd_hda_get_default_vref() to guess the right value.
* Also, this function is only for analog pins, not for HDMI pins. * Also, this function is only for analog pins, not for HDMI pins.
*/ */
static inline int static inline int
......
...@@ -3155,6 +3155,7 @@ static void ad1988_auto_init_analog_input(struct hda_codec *codec) ...@@ -3155,6 +3155,7 @@ static void ad1988_auto_init_analog_input(struct hda_codec *codec)
for (i = 0; i < cfg->num_inputs; i++) { for (i = 0; i < cfg->num_inputs; i++) {
hda_nid_t nid = cfg->inputs[i].pin; hda_nid_t nid = cfg->inputs[i].pin;
int type = cfg->inputs[i].type; int type = cfg->inputs[i].type;
int val;
switch (nid) { switch (nid) {
case 0x15: /* port-C */ case 0x15: /* port-C */
snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0); snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
...@@ -3163,8 +3164,10 @@ static void ad1988_auto_init_analog_input(struct hda_codec *codec) ...@@ -3163,8 +3164,10 @@ static void ad1988_auto_init_analog_input(struct hda_codec *codec)
snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0); snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
break; break;
} }
snd_hda_set_pin_ctl(codec, nid, val = PIN_IN;
type == AUTO_PIN_MIC ? PIN_VREF80 : PIN_IN); if (type == AUTO_PIN_MIC)
val |= snd_hda_get_default_vref(codec, nid);
snd_hda_set_pin_ctl(codec, nid, val);
if (nid != AD1988_PIN_CD_NID) if (nid != AD1988_PIN_CD_NID)
snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
AMP_OUT_MUTE); AMP_OUT_MUTE);
......
...@@ -355,7 +355,8 @@ static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) ...@@ -355,7 +355,8 @@ static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
{ {
if (pin) { if (pin) {
snd_hda_set_pin_ctl(codec, pin, PIN_VREF80); snd_hda_set_pin_ctl(codec, pin, PIN_IN |
snd_hda_get_default_vref(codec, pin));
if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
snd_hda_codec_write(codec, pin, 0, snd_hda_codec_write(codec, pin, 0,
AC_VERB_SET_AMP_GAIN_MUTE, AC_VERB_SET_AMP_GAIN_MUTE,
......
...@@ -253,7 +253,8 @@ static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac) ...@@ -253,7 +253,8 @@ static void init_output(struct hda_codec *codec, hda_nid_t pin, hda_nid_t dac)
static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc) static void init_input(struct hda_codec *codec, hda_nid_t pin, hda_nid_t adc)
{ {
if (pin) { if (pin) {
snd_hda_set_pin_ctl(codec, pin, PIN_VREF80); snd_hda_set_pin_ctl(codec, pin, PIN_IN |
snd_hda_get_default_vref(codec, pin));
if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP) if (get_wcaps(codec, pin) & AC_WCAP_IN_AMP)
snd_hda_codec_write(codec, pin, 0, snd_hda_codec_write(codec, pin, 0,
AC_VERB_SET_AMP_GAIN_MUTE, AC_VERB_SET_AMP_GAIN_MUTE,
......
...@@ -1057,12 +1057,8 @@ static void init_input(struct hda_codec *codec) ...@@ -1057,12 +1057,8 @@ static void init_input(struct hda_codec *codec)
continue; continue;
/* set appropriate pin control and mute first */ /* set appropriate pin control and mute first */
ctl = PIN_IN; ctl = PIN_IN;
if (cfg->inputs[i].type == AUTO_PIN_MIC) { if (cfg->inputs[i].type == AUTO_PIN_MIC)
unsigned int caps = snd_hda_query_pin_caps(codec, pin); ctl |= snd_hda_get_default_vref(codec, pin);
caps >>= AC_PINCAP_VREF_SHIFT;
if (caps & AC_PINCAP_VREF_80)
ctl = PIN_VREF80;
}
snd_hda_set_pin_ctl(codec, pin, ctl); snd_hda_set_pin_ctl(codec, pin, ctl);
snd_hda_codec_write(codec, spec->adc_nid[i], 0, snd_hda_codec_write(codec, spec->adc_nid[i], 0,
AC_VERB_SET_AMP_GAIN_MUTE, AC_VERB_SET_AMP_GAIN_MUTE,
......
...@@ -4020,12 +4020,11 @@ static void cx_auto_init_input(struct hda_codec *codec) ...@@ -4020,12 +4020,11 @@ static void cx_auto_init_input(struct hda_codec *codec)
} }
for (i = 0; i < cfg->num_inputs; i++) { for (i = 0; i < cfg->num_inputs; i++) {
unsigned int type; hda_nid_t pin = cfg->inputs[i].pin;
unsigned int type = PIN_IN;
if (cfg->inputs[i].type == AUTO_PIN_MIC) if (cfg->inputs[i].type == AUTO_PIN_MIC)
type = PIN_VREF80; type |= snd_hda_get_default_vref(codec, pin);
else snd_hda_set_pin_ctl(codec, pin, type);
type = PIN_IN;
snd_hda_set_pin_ctl(codec, cfg->inputs[i].pin, type);
} }
if (spec->auto_mic) { if (spec->auto_mic) {
......
...@@ -325,7 +325,7 @@ static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx, ...@@ -325,7 +325,7 @@ static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
* first is the real internal mic and the second is HP jack. * first is the real internal mic and the second is HP jack.
*/ */
if (spec->cur_mux[adc_idx]) if (spec->cur_mux[adc_idx])
val = PIN_VREF80; val = snd_hda_get_default_vref(codec, pin) | PIN_IN;
else else
val = PIN_HP; val = PIN_HP;
snd_hda_set_pin_ctl(codec, pin, val); snd_hda_set_pin_ctl(codec, pin, val);
...@@ -379,24 +379,8 @@ static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid, ...@@ -379,24 +379,8 @@ static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
int auto_pin_type) int auto_pin_type)
{ {
unsigned int val = PIN_IN; unsigned int val = PIN_IN;
if (auto_pin_type == AUTO_PIN_MIC)
if (auto_pin_type == AUTO_PIN_MIC) { val |= snd_hda_get_default_vref(codec, nid);
unsigned int pincap;
unsigned int oldval;
oldval = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
pincap = snd_hda_query_pin_caps(codec, nid);
pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
/* if the default pin setup is vref50, we give it priority */
if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
val = PIN_VREF80;
else if (pincap & AC_PINCAP_VREF_50)
val = PIN_VREF50;
else if (pincap & AC_PINCAP_VREF_100)
val = PIN_VREF100;
else if (pincap & AC_PINCAP_VREF_GRD)
val = PIN_VREFGRD;
}
snd_hda_set_pin_ctl(codec, nid, val); snd_hda_set_pin_ctl(codec, nid, val);
} }
......
...@@ -2503,22 +2503,6 @@ static int stac92xx_build_pcms(struct hda_codec *codec) ...@@ -2503,22 +2503,6 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
return 0; return 0;
} }
static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
hda_nid_t nid)
{
unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
if (pincap & AC_PINCAP_VREF_100)
return AC_PINCTL_VREF_100;
if (pincap & AC_PINCAP_VREF_80)
return AC_PINCTL_VREF_80;
if (pincap & AC_PINCAP_VREF_50)
return AC_PINCTL_VREF_50;
if (pincap & AC_PINCAP_VREF_GRD)
return AC_PINCTL_VREF_GRD;
return 0;
}
static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type) static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
{ {
...@@ -2591,7 +2575,7 @@ static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol, ...@@ -2591,7 +2575,7 @@ static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
hda_nid_t nid = kcontrol->private_value; hda_nid_t nid = kcontrol->private_value;
unsigned int vref = stac92xx_vref_get(codec, nid); unsigned int vref = stac92xx_vref_get(codec, nid);
if (vref == stac92xx_get_default_vref(codec, nid)) if (vref == snd_hda_get_default_vref(codec, nid))
ucontrol->value.enumerated.item[0] = 0; ucontrol->value.enumerated.item[0] = 0;
else if (vref == AC_PINCTL_VREF_GRD) else if (vref == AC_PINCTL_VREF_GRD)
ucontrol->value.enumerated.item[0] = 1; ucontrol->value.enumerated.item[0] = 1;
...@@ -2610,7 +2594,7 @@ static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol, ...@@ -2610,7 +2594,7 @@ static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
hda_nid_t nid = kcontrol->private_value; hda_nid_t nid = kcontrol->private_value;
if (ucontrol->value.enumerated.item[0] == 0) if (ucontrol->value.enumerated.item[0] == 0)
new_vref = stac92xx_get_default_vref(codec, nid); new_vref = snd_hda_get_default_vref(codec, nid);
else if (ucontrol->value.enumerated.item[0] == 1) else if (ucontrol->value.enumerated.item[0] == 1)
new_vref = AC_PINCTL_VREF_GRD; new_vref = AC_PINCTL_VREF_GRD;
else if (ucontrol->value.enumerated.item[0] == 2) else if (ucontrol->value.enumerated.item[0] == 2)
...@@ -2676,7 +2660,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ ...@@ -2676,7 +2660,7 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
else { else {
unsigned int pinctl = AC_PINCTL_IN_EN; unsigned int pinctl = AC_PINCTL_IN_EN;
if (io_idx) /* set VREF for mic */ if (io_idx) /* set VREF for mic */
pinctl |= stac92xx_get_default_vref(codec, nid); pinctl |= snd_hda_get_default_vref(codec, nid);
stac92xx_auto_set_pinctl(codec, nid, pinctl); stac92xx_auto_set_pinctl(codec, nid, pinctl);
} }
...@@ -2844,7 +2828,7 @@ static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec, ...@@ -2844,7 +2828,7 @@ static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
char name[22]; char name[22];
if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) { 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 (snd_hda_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;
else if (snd_hda_query_pin_caps(codec, nid) else if (snd_hda_query_pin_caps(codec, nid)
...@@ -4351,7 +4335,7 @@ static int stac92xx_init(struct hda_codec *codec) ...@@ -4351,7 +4335,7 @@ static int stac92xx_init(struct hda_codec *codec)
unsigned int pinctl, conf; unsigned int pinctl, conf;
if (type == AUTO_PIN_MIC) { if (type == AUTO_PIN_MIC) {
/* for mic pins, force to initialize */ /* for mic pins, force to initialize */
pinctl = stac92xx_get_default_vref(codec, nid); pinctl = snd_hda_get_default_vref(codec, nid);
pinctl |= AC_PINCTL_IN_EN; pinctl |= AC_PINCTL_IN_EN;
stac92xx_auto_set_pinctl(codec, nid, pinctl); stac92xx_auto_set_pinctl(codec, nid, pinctl);
} else { } else {
......
...@@ -661,10 +661,11 @@ static void via_auto_init_analog_input(struct hda_codec *codec) ...@@ -661,10 +661,11 @@ static void via_auto_init_analog_input(struct hda_codec *codec)
hda_nid_t nid = cfg->inputs[i].pin; hda_nid_t nid = cfg->inputs[i].pin;
if (spec->smart51_enabled && is_smart51_pins(codec, nid)) if (spec->smart51_enabled && is_smart51_pins(codec, nid))
ctl = PIN_OUT; ctl = PIN_OUT;
else if (cfg->inputs[i].type == AUTO_PIN_MIC) else {
ctl = PIN_VREF50;
else
ctl = PIN_IN; ctl = PIN_IN;
if (cfg->inputs[i].type == AUTO_PIN_MIC)
ctl |= snd_hda_get_default_vref(codec, nid);
}
snd_hda_set_pin_ctl(codec, nid, ctl); snd_hda_set_pin_ctl(codec, nid, ctl);
} }
......
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