Skip to content

Commit 35a39f9

Browse files
committed
ALSA: hda/realtek - Use a common helper for hp pin reference
Replace the open-codes in many places with a new common helper for performing the same thing: referring to the primary headphone pin. This eventually fixes the potentially missing headphone pin on some weird devices, too. Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent d561aa0 commit 35a39f9

File tree

1 file changed

+24
-72
lines changed

1 file changed

+24
-72
lines changed

sound/pci/hda/patch_realtek.c

Lines changed: 24 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,15 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
515515
}
516516
}
517517

518+
/* get a primary headphone pin if available */
519+
static hda_nid_t alc_get_hp_pin(struct alc_spec *spec)
520+
{
521+
if (spec->gen.autocfg.hp_pins[0])
522+
return spec->gen.autocfg.hp_pins[0];
523+
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
524+
return spec->gen.autocfg.line_out_pins[0];
525+
return 0;
526+
}
518527

519528
/*
520529
* Realtek SSID verification
@@ -725,9 +734,7 @@ static int alc_subsystem_id(struct hda_codec *codec, const hda_nid_t *ports)
725734
* 15 : 1 --> enable the function "Mute internal speaker
726735
* when the external headphone out jack is plugged"
727736
*/
728-
if (!spec->gen.autocfg.hp_pins[0] &&
729-
!(spec->gen.autocfg.line_out_pins[0] &&
730-
spec->gen.autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
737+
if (!alc_get_hp_pin(spec)) {
731738
hda_nid_t nid;
732739
tmp = (ass >> 11) & 0x3; /* HP to chassis */
733740
nid = ports[tmp];
@@ -2959,15 +2966,10 @@ static void alc282_restore_default_value(struct hda_codec *codec)
29592966
static void alc282_init(struct hda_codec *codec)
29602967
{
29612968
struct alc_spec *spec = codec->spec;
2962-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
2969+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
29632970
bool hp_pin_sense;
29642971
int coef78;
29652972

2966-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
2967-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
2968-
hp_pin = spec->gen.autocfg.line_out_pins[0];
2969-
}
2970-
29712973
alc282_restore_default_value(codec);
29722974

29732975
if (!hp_pin)
@@ -3001,15 +3003,10 @@ static void alc282_init(struct hda_codec *codec)
30013003
static void alc282_shutup(struct hda_codec *codec)
30023004
{
30033005
struct alc_spec *spec = codec->spec;
3004-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3006+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
30053007
bool hp_pin_sense;
30063008
int coef78;
30073009

3008-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
3009-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3010-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3011-
}
3012-
30133010
if (!hp_pin) {
30143011
alc269_shutup(codec);
30153012
return;
@@ -3084,14 +3081,9 @@ static void alc283_restore_default_value(struct hda_codec *codec)
30843081
static void alc283_init(struct hda_codec *codec)
30853082
{
30863083
struct alc_spec *spec = codec->spec;
3087-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3084+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
30883085
bool hp_pin_sense;
30893086

3090-
if (!spec->gen.autocfg.hp_outs) {
3091-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3092-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3093-
}
3094-
30953087
alc283_restore_default_value(codec);
30963088

30973089
if (!hp_pin)
@@ -3125,14 +3117,9 @@ static void alc283_init(struct hda_codec *codec)
31253117
static void alc283_shutup(struct hda_codec *codec)
31263118
{
31273119
struct alc_spec *spec = codec->spec;
3128-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3120+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
31293121
bool hp_pin_sense;
31303122

3131-
if (!spec->gen.autocfg.hp_outs) {
3132-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3133-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3134-
}
3135-
31363123
if (!hp_pin) {
31373124
alc269_shutup(codec);
31383125
return;
@@ -3166,14 +3153,9 @@ static void alc283_shutup(struct hda_codec *codec)
31663153
static void alc256_init(struct hda_codec *codec)
31673154
{
31683155
struct alc_spec *spec = codec->spec;
3169-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3156+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
31703157
bool hp_pin_sense;
31713158

3172-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
3173-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3174-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3175-
}
3176-
31773159
if (!hp_pin)
31783160
return;
31793161

@@ -3207,14 +3189,9 @@ static void alc256_init(struct hda_codec *codec)
32073189
static void alc256_shutup(struct hda_codec *codec)
32083190
{
32093191
struct alc_spec *spec = codec->spec;
3210-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3192+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
32113193
bool hp_pin_sense;
32123194

3213-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
3214-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3215-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3216-
}
3217-
32183195
if (!hp_pin) {
32193196
alc269_shutup(codec);
32203197
return;
@@ -3248,14 +3225,9 @@ static void alc256_shutup(struct hda_codec *codec)
32483225
static void alc225_init(struct hda_codec *codec)
32493226
{
32503227
struct alc_spec *spec = codec->spec;
3251-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3228+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
32523229
bool hp1_pin_sense, hp2_pin_sense;
32533230

3254-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
3255-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3256-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3257-
}
3258-
32593231
if (!hp_pin)
32603232
return;
32613233

@@ -3296,14 +3268,9 @@ static void alc225_init(struct hda_codec *codec)
32963268
static void alc225_shutup(struct hda_codec *codec)
32973269
{
32983270
struct alc_spec *spec = codec->spec;
3299-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3271+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
33003272
bool hp1_pin_sense, hp2_pin_sense;
33013273

3302-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
3303-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3304-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3305-
}
3306-
33073274
if (!hp_pin) {
33083275
alc269_shutup(codec);
33093276
return;
@@ -3345,14 +3312,9 @@ static void alc225_shutup(struct hda_codec *codec)
33453312
static void alc_default_init(struct hda_codec *codec)
33463313
{
33473314
struct alc_spec *spec = codec->spec;
3348-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3315+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
33493316
bool hp_pin_sense;
33503317

3351-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
3352-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3353-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3354-
}
3355-
33563318
if (!hp_pin)
33573319
return;
33583320

@@ -3379,14 +3341,9 @@ static void alc_default_init(struct hda_codec *codec)
33793341
static void alc_default_shutup(struct hda_codec *codec)
33803342
{
33813343
struct alc_spec *spec = codec->spec;
3382-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3344+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
33833345
bool hp_pin_sense;
33843346

3385-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
3386-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3387-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3388-
}
3389-
33903347
if (!hp_pin) {
33913348
alc269_shutup(codec);
33923349
return;
@@ -3416,14 +3373,9 @@ static void alc_default_shutup(struct hda_codec *codec)
34163373
static void alc294_hp_init(struct hda_codec *codec)
34173374
{
34183375
struct alc_spec *spec = codec->spec;
3419-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
3376+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
34203377
int i, val;
34213378

3422-
if (!spec->gen.autocfg.hp_outs && spec->gen.suppress_auto_mute) {
3423-
if (spec->gen.autocfg.line_out_type == AC_JACK_HP_OUT)
3424-
hp_pin = spec->gen.autocfg.line_out_pins[0];
3425-
}
3426-
34273379
if (!hp_pin)
34283380
return;
34293381

@@ -4825,7 +4777,7 @@ static void alc_update_headset_mode(struct hda_codec *codec)
48254777
struct alc_spec *spec = codec->spec;
48264778

48274779
hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
4828-
hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
4780+
hda_nid_t hp_pin = alc_get_hp_pin(spec);
48294781

48304782
int new_headset_mode;
48314783

@@ -5104,7 +5056,7 @@ static void alc_fixup_tpt470_dock(struct hda_codec *codec,
51045056
static void alc_shutup_dell_xps13(struct hda_codec *codec)
51055057
{
51065058
struct alc_spec *spec = codec->spec;
5107-
int hp_pin = spec->gen.autocfg.hp_pins[0];
5059+
int hp_pin = alc_get_hp_pin(spec);
51085060

51095061
/* Prevent pop noises when headphones are plugged in */
51105062
snd_hda_codec_write(codec, hp_pin, 0,
@@ -5197,7 +5149,7 @@ static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
51975149

51985150
if (action == HDA_FIXUP_ACT_PROBE) {
51995151
int mic_pin = find_ext_mic_pin(codec);
5200-
int hp_pin = spec->gen.autocfg.hp_pins[0];
5152+
int hp_pin = alc_get_hp_pin(spec);
52015153

52025154
if (snd_BUG_ON(!mic_pin || !hp_pin))
52035155
return;

0 commit comments

Comments
 (0)