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