Commit 01e4a275 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda/realtek - Simplify mute LED GPIO handling

Now we can simplify the mute LED GPIO handling as well.  Each fixup
dealing with GPIO for the mute LED controls defined the static init
verbs, and they are converted to the common GPIO bit fields with the
new helper, alc_fixup_hp_gpio_led().
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 215c850c
...@@ -3731,44 +3731,38 @@ static void alc_gpio_micmute_update(struct hda_codec *codec) ...@@ -3731,44 +3731,38 @@ static void alc_gpio_micmute_update(struct hda_codec *codec)
spec->gen.micmute_led.led_value); spec->gen.micmute_led.led_value);
} }
static void alc269_fixup_hp_gpio_led(struct hda_codec *codec, /* setup mute and mic-mute GPIO bits, add hooks appropriately */
const struct hda_fixup *fix, int action) static void alc_fixup_hp_gpio_led(struct hda_codec *codec,
int action,
unsigned int mute_mask,
unsigned int micmute_mask)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
static const struct hda_verb gpio_init[] = {
{ 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
{}
};
if (action == HDA_FIXUP_ACT_PRE_PROBE) { alc_fixup_gpio(codec, action, mute_mask | micmute_mask);
if (action != HDA_FIXUP_ACT_PRE_PROBE)
return;
if (mute_mask) {
spec->gpio_mute_led_mask = mute_mask;
spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook; spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
spec->mute_led_polarity = 0; }
spec->gpio_mute_led_mask = 0x08; if (micmute_mask) {
spec->gpio_mic_led_mask = 0x10; spec->gpio_mic_led_mask = micmute_mask;
snd_hda_add_verbs(codec, gpio_init);
snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update); snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
} }
} }
static void alc286_fixup_hp_gpio_led(struct hda_codec *codec, static void alc269_fixup_hp_gpio_led(struct hda_codec *codec,
const struct hda_fixup *fix, int action) const struct hda_fixup *fix, int action)
{ {
struct alc_spec *spec = codec->spec; alc_fixup_hp_gpio_led(codec, action, 0x08, 0x10);
static const struct hda_verb gpio_init[] = { }
{ 0x01, AC_VERB_SET_GPIO_MASK, 0x22 },
{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x22 },
{}
};
if (action == HDA_FIXUP_ACT_PRE_PROBE) { static void alc286_fixup_hp_gpio_led(struct hda_codec *codec,
spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook; const struct hda_fixup *fix, int action)
spec->mute_led_polarity = 0; {
spec->gpio_mute_led_mask = 0x02; alc_fixup_hp_gpio_led(codec, action, 0x02, 0x20);
spec->gpio_mic_led_mask = 0x20;
snd_hda_add_verbs(codec, gpio_init);
snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
}
} }
/* turn on/off mic-mute LED per capture hook */ /* turn on/off mic-mute LED per capture hook */
...@@ -3792,18 +3786,15 @@ static void alc269_fixup_hp_gpio_mic1_led(struct hda_codec *codec, ...@@ -3792,18 +3786,15 @@ static void alc269_fixup_hp_gpio_mic1_led(struct hda_codec *codec,
const struct hda_fixup *fix, int action) const struct hda_fixup *fix, int action)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
static const struct hda_verb gpio_init[] = {
{ 0x01, AC_VERB_SET_GPIO_MASK, 0x08 },
{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x08 },
{}
};
alc_fixup_hp_gpio_led(codec, action, 0x08, 0);
if (action == HDA_FIXUP_ACT_PRE_PROBE) { if (action == HDA_FIXUP_ACT_PRE_PROBE) {
spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook; /* Like hp_gpio_mic1_led, but also needs GPIO4 low to
spec->mute_led_polarity = 0; * enable headphone amp
spec->gpio_mute_led_mask = 0x08; */
spec->gpio_mask |= 0x10;
spec->gpio_dir |= 0x10;
spec->cap_mute_led_nid = 0x18; spec->cap_mute_led_nid = 0x18;
snd_hda_add_verbs(codec, gpio_init);
snd_hda_gen_add_micmute_led(codec, alc_cap_micmute_update); snd_hda_gen_add_micmute_led(codec, alc_cap_micmute_update);
codec->power_filter = led_power_filter; codec->power_filter = led_power_filter;
} }
...@@ -3812,20 +3803,11 @@ static void alc269_fixup_hp_gpio_mic1_led(struct hda_codec *codec, ...@@ -3812,20 +3803,11 @@ static void alc269_fixup_hp_gpio_mic1_led(struct hda_codec *codec,
static void alc280_fixup_hp_gpio4(struct hda_codec *codec, static void alc280_fixup_hp_gpio4(struct hda_codec *codec,
const struct hda_fixup *fix, int action) const struct hda_fixup *fix, int action)
{ {
/* Like hp_gpio_mic1_led, but also needs GPIO4 low to enable headphone amp */
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
static const struct hda_verb gpio_init[] = {
{ 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
{}
};
alc_fixup_hp_gpio_led(codec, action, 0x08, 0);
if (action == HDA_FIXUP_ACT_PRE_PROBE) { if (action == HDA_FIXUP_ACT_PRE_PROBE) {
spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
spec->mute_led_polarity = 0;
spec->gpio_mute_led_mask = 0x08;
spec->cap_mute_led_nid = 0x18; spec->cap_mute_led_nid = 0x18;
snd_hda_add_verbs(codec, gpio_init);
snd_hda_gen_add_micmute_led(codec, alc_cap_micmute_update); snd_hda_gen_add_micmute_led(codec, alc_cap_micmute_update);
codec->power_filter = led_power_filter; codec->power_filter = led_power_filter;
} }
...@@ -3876,38 +3858,29 @@ static int alc_register_micmute_input_device(struct hda_codec *codec) ...@@ -3876,38 +3858,29 @@ static int alc_register_micmute_input_device(struct hda_codec *codec)
return 0; return 0;
} }
/* GPIO1 = set according to SKU external amp
* GPIO2 = mic mute hotkey
* GPIO3 = mute LED
* GPIO4 = mic mute LED
*/
static void alc280_fixup_hp_gpio2_mic_hotkey(struct hda_codec *codec, static void alc280_fixup_hp_gpio2_mic_hotkey(struct hda_codec *codec,
const struct hda_fixup *fix, int action) const struct hda_fixup *fix, int action)
{ {
/* GPIO1 = set according to SKU external amp
GPIO2 = mic mute hotkey
GPIO3 = mute LED
GPIO4 = mic mute LED */
static const struct hda_verb gpio_init[] = {
{ 0x01, AC_VERB_SET_GPIO_MASK, 0x1e },
{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x1a },
{ 0x01, AC_VERB_SET_GPIO_DATA, 0x02 },
{}
};
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
alc_fixup_hp_gpio_led(codec, action, 0x08, 0x10);
if (action == HDA_FIXUP_ACT_PRE_PROBE) { if (action == HDA_FIXUP_ACT_PRE_PROBE) {
spec->init_amp = ALC_INIT_DEFAULT; spec->init_amp = ALC_INIT_DEFAULT;
if (alc_register_micmute_input_device(codec) != 0) if (alc_register_micmute_input_device(codec) != 0)
return; return;
snd_hda_add_verbs(codec, gpio_init); spec->gpio_mask |= 0x06;
spec->gpio_dir |= 0x02;
spec->gpio_data |= 0x02;
snd_hda_codec_write_cache(codec, codec->core.afg, 0, snd_hda_codec_write_cache(codec, codec->core.afg, 0,
AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x04); AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x04);
snd_hda_jack_detect_enable_callback(codec, codec->core.afg, snd_hda_jack_detect_enable_callback(codec, codec->core.afg,
gpio2_mic_hotkey_event); gpio2_mic_hotkey_event);
spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
spec->mute_led_polarity = 0;
spec->gpio_mute_led_mask = 0x08;
spec->gpio_mic_led_mask = 0x10;
snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
return; return;
} }
...@@ -3921,31 +3894,22 @@ static void alc280_fixup_hp_gpio2_mic_hotkey(struct hda_codec *codec, ...@@ -3921,31 +3894,22 @@ static void alc280_fixup_hp_gpio2_mic_hotkey(struct hda_codec *codec,
} }
} }
/* Line2 = mic mute hotkey
* GPIO2 = mic mute LED
*/
static void alc233_fixup_lenovo_line2_mic_hotkey(struct hda_codec *codec, static void alc233_fixup_lenovo_line2_mic_hotkey(struct hda_codec *codec,
const struct hda_fixup *fix, int action) const struct hda_fixup *fix, int action)
{ {
/* Line2 = mic mute hotkey
GPIO2 = mic mute LED */
static const struct hda_verb gpio_init[] = {
{ 0x01, AC_VERB_SET_GPIO_MASK, 0x04 },
{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04 },
{}
};
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
alc_fixup_hp_gpio_led(codec, action, 0, 0x04);
if (action == HDA_FIXUP_ACT_PRE_PROBE) { if (action == HDA_FIXUP_ACT_PRE_PROBE) {
spec->init_amp = ALC_INIT_DEFAULT; spec->init_amp = ALC_INIT_DEFAULT;
if (alc_register_micmute_input_device(codec) != 0) if (alc_register_micmute_input_device(codec) != 0)
return; return;
snd_hda_add_verbs(codec, gpio_init);
snd_hda_jack_detect_enable_callback(codec, 0x1b, snd_hda_jack_detect_enable_callback(codec, 0x1b,
gpio2_mic_hotkey_event); gpio2_mic_hotkey_event);
spec->mute_led_polarity = 0;
spec->gpio_mic_led_mask = 0x04;
snd_hda_gen_add_micmute_led(codec, alc_gpio_micmute_update);
return; return;
} }
...@@ -5306,27 +5270,13 @@ static void alc280_fixup_hp_9480m(struct hda_codec *codec, ...@@ -5306,27 +5270,13 @@ static void alc280_fixup_hp_9480m(struct hda_codec *codec,
int action) int action)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
static const struct hda_verb gpio_init[] = {
{ 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
{}
};
alc_fixup_hp_gpio_led(codec, action, 0x08, 0);
if (action == HDA_FIXUP_ACT_PRE_PROBE) { if (action == HDA_FIXUP_ACT_PRE_PROBE) {
/* Set the hooks to turn the headphone amp on/off /* amp at GPIO4; toggled via alc280_hp_gpio4_automute_hook() */
* as needed spec->gpio_mask |= 0x10;
*/ spec->gpio_dir |= 0x10;
spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
spec->gen.hp_automute_hook = alc280_hp_gpio4_automute_hook; spec->gen.hp_automute_hook = alc280_hp_gpio4_automute_hook;
/* GPIO3 is connected to the output mute LED,
* high is on, low is off
*/
spec->mute_led_polarity = 0;
spec->gpio_mute_led_mask = 0x08;
/* Initialize GPIO configuration */
snd_hda_add_verbs(codec, gpio_init);
} }
} }
...@@ -7552,17 +7502,10 @@ static void alc662_fixup_led_gpio1(struct hda_codec *codec, ...@@ -7552,17 +7502,10 @@ static void alc662_fixup_led_gpio1(struct hda_codec *codec,
const struct hda_fixup *fix, int action) const struct hda_fixup *fix, int action)
{ {
struct alc_spec *spec = codec->spec; struct alc_spec *spec = codec->spec;
static const struct hda_verb gpio_init[] = {
{ 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
{ 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
{}
};
alc_fixup_hp_gpio_led(codec, action, 0x01, 0);
if (action == HDA_FIXUP_ACT_PRE_PROBE) { if (action == HDA_FIXUP_ACT_PRE_PROBE) {
spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
spec->mute_led_polarity = 1; spec->mute_led_polarity = 1;
spec->gpio_mute_led_mask = 0x01;
snd_hda_add_verbs(codec, gpio_init);
codec->power_filter = gpio_led_power_filter; codec->power_filter = gpio_led_power_filter;
} }
} }
......
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