1 // SPDX-License-Identifier: GPL-2.0-or-later 2 3 #include <linux/init.h> 4 #include <linux/module.h> 5 #include "realtek.h" 6 7 /* bind Beep switches of both NID 0x0f and 0x10 */ 8 static int alc268_beep_switch_put(struct snd_kcontrol *kcontrol, 9 struct snd_ctl_elem_value *ucontrol) 10 { 11 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 12 unsigned long pval; 13 int err; 14 15 mutex_lock(&codec->control_mutex); 16 pval = kcontrol->private_value; 17 kcontrol->private_value = (pval & ~0xff) | 0x0f; 18 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); 19 if (err >= 0) { 20 kcontrol->private_value = (pval & ~0xff) | 0x10; 21 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); 22 } 23 kcontrol->private_value = pval; 24 mutex_unlock(&codec->control_mutex); 25 return err; 26 } 27 28 static const struct snd_kcontrol_new alc268_beep_mixer[] = { 29 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT), 30 { 31 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 32 .name = "Beep Playback Switch", 33 .subdevice = HDA_SUBDEV_AMP_FLAG, 34 .info = snd_hda_mixer_amp_switch_info, 35 .get = snd_hda_mixer_amp_switch_get, 36 .put = alc268_beep_switch_put, 37 .private_value = HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT) 38 }, 39 }; 40 41 /* set PCBEEP vol = 0, mute connections */ 42 static const struct hda_verb alc268_beep_init_verbs[] = { 43 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 44 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 45 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 46 { } 47 }; 48 49 enum { 50 ALC268_FIXUP_INV_DMIC, 51 ALC268_FIXUP_HP_EAPD, 52 ALC268_FIXUP_SPDIF, 53 }; 54 55 static const struct hda_fixup alc268_fixups[] = { 56 [ALC268_FIXUP_INV_DMIC] = { 57 .type = HDA_FIXUP_FUNC, 58 .v.func = alc_fixup_inv_dmic, 59 }, 60 [ALC268_FIXUP_HP_EAPD] = { 61 .type = HDA_FIXUP_VERBS, 62 .v.verbs = (const struct hda_verb[]) { 63 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0}, 64 {} 65 } 66 }, 67 [ALC268_FIXUP_SPDIF] = { 68 .type = HDA_FIXUP_PINS, 69 .v.pins = (const struct hda_pintbl[]) { 70 { 0x1e, 0x014b1180 }, /* enable SPDIF out */ 71 {} 72 } 73 }, 74 }; 75 76 static const struct hda_model_fixup alc268_fixup_models[] = { 77 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"}, 78 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"}, 79 {.id = ALC268_FIXUP_SPDIF, .name = "spdif"}, 80 {} 81 }; 82 83 static const struct hda_quirk alc268_fixup_tbl[] = { 84 SND_PCI_QUIRK(0x1025, 0x0139, "Acer TravelMate 6293", ALC268_FIXUP_SPDIF), 85 SND_PCI_QUIRK(0x1025, 0x015b, "Acer AOA 150 (ZG5)", ALC268_FIXUP_INV_DMIC), 86 /* below is codec SSID since multiple Toshiba laptops have the 87 * same PCI SSID 1179:ff00 88 */ 89 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD), 90 {} 91 }; 92 93 /* 94 * BIOS auto configuration 95 */ 96 static int alc268_parse_auto_config(struct hda_codec *codec) 97 { 98 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 }; 99 return alc_parse_auto_config(codec, NULL, alc268_ssids); 100 } 101 102 /* 103 */ 104 static int alc268_probe(struct hda_codec *codec, const struct hda_device_id *id) 105 { 106 struct alc_spec *spec; 107 int i, err; 108 109 /* ALC268 has no aa-loopback mixer */ 110 err = alc_alloc_spec(codec, 0); 111 if (err < 0) 112 return err; 113 114 spec = codec->spec; 115 if (has_cdefine_beep(codec)) 116 spec->gen.beep_nid = 0x01; 117 118 spec->shutup = alc_eapd_shutup; 119 120 alc_pre_init(codec); 121 122 snd_hda_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups); 123 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE); 124 125 /* automatic parse from the BIOS config */ 126 err = alc268_parse_auto_config(codec); 127 if (err < 0) 128 goto error; 129 130 if (err > 0 && !spec->gen.no_analog && 131 spec->gen.autocfg.speaker_pins[0] != 0x1d) { 132 for (i = 0; i < ARRAY_SIZE(alc268_beep_mixer); i++) { 133 if (!snd_hda_gen_add_kctl(&spec->gen, NULL, 134 &alc268_beep_mixer[i])) { 135 err = -ENOMEM; 136 goto error; 137 } 138 } 139 snd_hda_add_verbs(codec, alc268_beep_init_verbs); 140 if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) 141 /* override the amp caps for beep generator */ 142 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, 143 (0x0c << AC_AMPCAP_OFFSET_SHIFT) | 144 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | 145 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | 146 (0 << AC_AMPCAP_MUTE_SHIFT)); 147 } 148 149 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE); 150 151 return 0; 152 153 error: 154 snd_hda_gen_remove(codec); 155 return err; 156 } 157 158 static const struct hda_codec_ops alc268_codec_ops = { 159 .probe = alc268_probe, 160 .remove = snd_hda_gen_remove, 161 .build_controls = alc_build_controls, 162 .build_pcms = snd_hda_gen_build_pcms, 163 .init = alc_init, 164 .unsol_event = snd_hda_jack_unsol_event, 165 .resume = alc_resume, 166 .suspend = alc_suspend, 167 .check_power_status = snd_hda_gen_check_power_status, 168 .stream_pm = snd_hda_gen_stream_pm, 169 }; 170 171 /* 172 * driver entries 173 */ 174 static const struct hda_device_id snd_hda_id_alc268[] = { 175 HDA_CODEC_ID(0x10ec0267, "ALC267"), 176 HDA_CODEC_ID(0x10ec0268, "ALC268"), 177 {} /* terminator */ 178 }; 179 MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_alc268); 180 181 MODULE_LICENSE("GPL"); 182 MODULE_DESCRIPTION("Realtek ALC267/268 HD-audio codec"); 183 MODULE_IMPORT_NS("SND_HDA_CODEC_REALTEK"); 184 185 static struct hda_codec_driver alc268_driver = { 186 .id = snd_hda_id_alc268, 187 .ops = &alc268_codec_ops, 188 }; 189 190 module_hda_codec_driver(alc268_driver); 191