Skip to content

Commit 0c52db8

Browse files
committed
ALSA: hda - Control SPDIF out pin on MacBookPro 11,2
The SPDIF output MBP11,2 requires the pin control to be set/cleared for turning on/off the optical SPDIF. The red light turns off only when the corresponding pin control is cleared (or powered to D3). Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=64401 Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent a6bc732 commit 0c52db8

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

‎sound/pci/hda/patch_cirrus.c‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ struct cs_spec {
4747
unsigned int spdif_present:1;
4848
unsigned int sense_b:1;
4949
hda_nid_t vendor_nid;
50+
51+
/* for MBP SPDIF control */
52+
int (*spdif_sw_put)(struct snd_kcontrol *kcontrol,
53+
struct snd_ctl_elem_value *ucontrol);
5054
};
5155

5256
/* available models with CS420x */
@@ -331,10 +335,21 @@ static int cs_init(struct hda_codec *codec)
331335
return 0;
332336
}
333337

338+
static int cs_build_controls(struct hda_codec *codec)
339+
{
340+
int err;
341+
342+
err = snd_hda_gen_build_controls(codec);
343+
if (err < 0)
344+
return err;
345+
snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_BUILD);
346+
return 0;
347+
}
348+
334349
#define cs_free snd_hda_gen_free
335350

336351
static const struct hda_codec_ops cs_patch_ops = {
337-
.build_controls = snd_hda_gen_build_controls,
352+
.build_controls = cs_build_controls,
338353
.build_pcms = snd_hda_gen_build_pcms,
339354
.init = cs_init,
340355
.free = cs_free,
@@ -599,12 +614,14 @@ static int patch_cs420x(struct hda_codec *codec)
599614
enum {
600615
CS4208_MAC_AUTO,
601616
CS4208_MBA6,
617+
CS4208_MBP11,
602618
CS4208_GPIO0,
603619
};
604620

605621
static const struct hda_model_fixup cs4208_models[] = {
606622
{ .id = CS4208_GPIO0, .name = "gpio0" },
607623
{ .id = CS4208_MBA6, .name = "mba6" },
624+
{ .id = CS4208_MBP11, .name = "mbp11" },
608625
{}
609626
};
610627

@@ -615,6 +632,7 @@ static const struct snd_pci_quirk cs4208_fixup_tbl[] = {
615632

616633
/* codec SSID matching */
617634
static const struct snd_pci_quirk cs4208_mac_fixup_tbl[] = {
635+
SND_PCI_QUIRK(0x106b, 0x5e00, "MacBookPro 11,2", CS4208_MBP11),
618636
SND_PCI_QUIRK(0x106b, 0x7100, "MacBookAir 6,1", CS4208_MBA6),
619637
SND_PCI_QUIRK(0x106b, 0x7200, "MacBookAir 6,2", CS4208_MBA6),
620638
{} /* terminator */
@@ -646,13 +664,49 @@ static void cs4208_fixup_mac(struct hda_codec *codec,
646664
snd_hda_apply_fixup(codec, action);
647665
}
648666

667+
static int cs4208_spdif_sw_put(struct snd_kcontrol *kcontrol,
668+
struct snd_ctl_elem_value *ucontrol)
669+
{
670+
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671+
struct cs_spec *spec = codec->spec;
672+
hda_nid_t pin = spec->gen.autocfg.dig_out_pins[0];
673+
int pinctl = ucontrol->value.integer.value[0] ? PIN_OUT : 0;
674+
675+
snd_hda_set_pin_ctl_cache(codec, pin, pinctl);
676+
return spec->spdif_sw_put(kcontrol, ucontrol);
677+
}
678+
679+
/* hook the SPDIF switch */
680+
static void cs4208_fixup_spdif_switch(struct hda_codec *codec,
681+
const struct hda_fixup *fix, int action)
682+
{
683+
if (action == HDA_FIXUP_ACT_BUILD) {
684+
struct cs_spec *spec = codec->spec;
685+
struct snd_kcontrol *kctl;
686+
687+
if (!spec->gen.autocfg.dig_out_pins[0])
688+
return;
689+
kctl = snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch");
690+
if (!kctl)
691+
return;
692+
spec->spdif_sw_put = kctl->put;
693+
kctl->put = cs4208_spdif_sw_put;
694+
}
695+
}
696+
649697
static const struct hda_fixup cs4208_fixups[] = {
650698
[CS4208_MBA6] = {
651699
.type = HDA_FIXUP_PINS,
652700
.v.pins = mba6_pincfgs,
653701
.chained = true,
654702
.chain_id = CS4208_GPIO0,
655703
},
704+
[CS4208_MBP11] = {
705+
.type = HDA_FIXUP_FUNC,
706+
.v.func = cs4208_fixup_spdif_switch,
707+
.chained = true,
708+
.chain_id = CS4208_GPIO0,
709+
},
656710
[CS4208_GPIO0] = {
657711
.type = HDA_FIXUP_FUNC,
658712
.v.func = cs4208_fixup_gpio0,

0 commit comments

Comments
 (0)