12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322 |
- #include <linux/init.h>
- #include <linux/delay.h>
- #include <linux/slab.h>
- #include <linux/module.h>
- #include <sound/core.h>
- #include <sound/asoundef.h>
- #include "hda_codec.h"
- #include "hda_local.h"
- #include "hda_auto_parser.h"
- #include "hda_jack.h"
- #include "hda_generic.h"
- #define VT1708_HP_PIN_NID 0x20
- #define VT1708_CD_PIN_NID 0x24
- enum VIA_HDA_CODEC {
- UNKNOWN = -1,
- VT1708,
- VT1709_10CH,
- VT1709_6CH,
- VT1708B_8CH,
- VT1708B_4CH,
- VT1708S,
- VT1708BCE,
- VT1702,
- VT1718S,
- VT1716S,
- VT2002P,
- VT1812,
- VT1802,
- VT1705CF,
- VT1808,
- CODEC_TYPES,
- };
- #define VT2002P_COMPATIBLE(spec) \
- ((spec)->codec_type == VT2002P ||\
- (spec)->codec_type == VT1812 ||\
- (spec)->codec_type == VT1802)
- struct via_spec {
- struct hda_gen_spec gen;
-
- const struct snd_kcontrol_new *mixers[6];
- unsigned int num_mixers;
- const struct hda_verb *init_verbs[5];
- unsigned int num_iverbs;
-
- unsigned int dmic_enabled;
- enum VIA_HDA_CODEC codec_type;
-
- bool alc_mode;
-
- int hp_work_active;
- int vt1708_jack_detect;
- unsigned int beep_amp;
- };
- static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
- static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
- struct hda_codec *codec,
- struct snd_pcm_substream *substream,
- int action);
- static const struct hda_codec_ops via_patch_ops;
- static struct via_spec *via_new_spec(struct hda_codec *codec)
- {
- struct via_spec *spec;
- spec = kzalloc(sizeof(*spec), GFP_KERNEL);
- if (spec == NULL)
- return NULL;
- codec->spec = spec;
- snd_hda_gen_spec_init(&spec->gen);
- spec->codec_type = get_codec_type(codec);
-
- if (spec->codec_type == VT1708BCE)
- spec->codec_type = VT1708S;
- spec->gen.indep_hp = 1;
- spec->gen.keep_eapd_on = 1;
- spec->gen.pcm_playback_hook = via_playback_pcm_hook;
- spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
- codec->power_save_node = 1;
- spec->gen.power_down_unused = 1;
- codec->patch_ops = via_patch_ops;
- return spec;
- }
- static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
- {
- u32 vendor_id = codec->core.vendor_id;
- u16 ven_id = vendor_id >> 16;
- u16 dev_id = vendor_id & 0xffff;
- enum VIA_HDA_CODEC codec_type;
-
- if (ven_id != 0x1106)
- codec_type = UNKNOWN;
- else if (dev_id >= 0x1708 && dev_id <= 0x170b)
- codec_type = VT1708;
- else if (dev_id >= 0xe710 && dev_id <= 0xe713)
- codec_type = VT1709_10CH;
- else if (dev_id >= 0xe714 && dev_id <= 0xe717)
- codec_type = VT1709_6CH;
- else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
- codec_type = VT1708B_8CH;
- if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
- codec_type = VT1708BCE;
- } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
- codec_type = VT1708B_4CH;
- else if ((dev_id & 0xfff) == 0x397
- && (dev_id >> 12) < 8)
- codec_type = VT1708S;
- else if ((dev_id & 0xfff) == 0x398
- && (dev_id >> 12) < 8)
- codec_type = VT1702;
- else if ((dev_id & 0xfff) == 0x428
- && (dev_id >> 12) < 8)
- codec_type = VT1718S;
- else if (dev_id == 0x0433 || dev_id == 0xa721)
- codec_type = VT1716S;
- else if (dev_id == 0x0441 || dev_id == 0x4441)
- codec_type = VT1718S;
- else if (dev_id == 0x0438 || dev_id == 0x4438)
- codec_type = VT2002P;
- else if (dev_id == 0x0448)
- codec_type = VT1812;
- else if (dev_id == 0x0440)
- codec_type = VT1708S;
- else if ((dev_id & 0xfff) == 0x446)
- codec_type = VT1802;
- else if (dev_id == 0x4760)
- codec_type = VT1705CF;
- else if (dev_id == 0x4761 || dev_id == 0x4762)
- codec_type = VT1808;
- else
- codec_type = UNKNOWN;
- return codec_type;
- };
- static void analog_low_current_mode(struct hda_codec *codec);
- static bool is_aa_path_mute(struct hda_codec *codec);
- #define hp_detect_with_aa(codec) \
- (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
- !is_aa_path_mute(codec))
- static void vt1708_stop_hp_work(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
- return;
- if (spec->hp_work_active) {
- snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
- codec->jackpoll_interval = 0;
- cancel_delayed_work_sync(&codec->jackpoll_work);
- spec->hp_work_active = false;
- }
- }
- static void vt1708_update_hp_work(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
- return;
- if (spec->vt1708_jack_detect) {
- if (!spec->hp_work_active) {
- codec->jackpoll_interval = msecs_to_jiffies(100);
- snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
- schedule_delayed_work(&codec->jackpoll_work, 0);
- spec->hp_work_active = true;
- }
- } else if (!hp_detect_with_aa(codec))
- vt1708_stop_hp_work(codec);
- }
- static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
- }
- static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
- struct via_spec *spec = codec->spec;
- ucontrol->value.enumerated.item[0] = spec->gen.power_down_unused;
- return 0;
- }
- static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
- struct via_spec *spec = codec->spec;
- bool val = !!ucontrol->value.enumerated.item[0];
- if (val == spec->gen.power_down_unused)
- return 0;
-
- spec->gen.power_down_unused = val;
- analog_low_current_mode(codec);
- return 1;
- }
- static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Dynamic Power-Control",
- .info = via_pin_power_ctl_info,
- .get = via_pin_power_ctl_get,
- .put = via_pin_power_ctl_put,
- },
- {}
- };
- #ifdef CONFIG_SND_HDA_INPUT_BEEP
- static inline void set_beep_amp(struct via_spec *spec, hda_nid_t nid,
- int idx, int dir)
- {
- spec->gen.beep_nid = nid;
- spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
- }
- static const struct snd_kcontrol_new cxt_beep_mixer[] = {
- HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
- HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
- { }
- };
- static int add_beep_ctls(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- int err;
- if (spec->beep_amp) {
- const struct snd_kcontrol_new *knew;
- for (knew = cxt_beep_mixer; knew->name; knew++) {
- struct snd_kcontrol *kctl;
- kctl = snd_ctl_new1(knew, codec);
- if (!kctl)
- return -ENOMEM;
- kctl->private_value = spec->beep_amp;
- err = snd_hda_ctl_add(codec, 0, kctl);
- if (err < 0)
- return err;
- }
- }
- return 0;
- }
- static void auto_parse_beep(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- hda_nid_t nid;
- for_each_hda_codec_node(nid, codec)
- if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
- set_beep_amp(spec, nid, 0, HDA_OUTPUT);
- break;
- }
- }
- #else
- #define set_beep_amp(spec, nid, idx, dir)
- #define add_beep_ctls(codec) 0
- #define auto_parse_beep(codec)
- #endif
- static bool is_aa_path_mute(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- const struct hda_amp_list *p;
- int ch, v;
- p = spec->gen.loopback.amplist;
- if (!p)
- return true;
- for (; p->nid; p++) {
- for (ch = 0; ch < 2; ch++) {
- v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
- p->idx);
- if (!(v & HDA_AMP_MUTE) && v > 0)
- return false;
- }
- }
- return true;
- }
- static void __analog_low_current_mode(struct hda_codec *codec, bool force)
- {
- struct via_spec *spec = codec->spec;
- bool enable;
- unsigned int verb, parm;
- if (!codec->power_save_node)
- enable = false;
- else
- enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
- if (enable == spec->alc_mode && !force)
- return;
- spec->alc_mode = enable;
-
- switch (spec->codec_type) {
- case VT1708B_8CH:
- case VT1708B_4CH:
- verb = 0xf70;
- parm = enable ? 0x02 : 0x00;
- break;
- case VT1708S:
- case VT1718S:
- case VT1716S:
- verb = 0xf73;
- parm = enable ? 0x51 : 0xe1;
- break;
- case VT1702:
- verb = 0xf73;
- parm = enable ? 0x01 : 0x1d;
- break;
- case VT2002P:
- case VT1812:
- case VT1802:
- verb = 0xf93;
- parm = enable ? 0x00 : 0xe0;
- break;
- case VT1705CF:
- case VT1808:
- verb = 0xf82;
- parm = enable ? 0x00 : 0xe0;
- break;
- default:
- return;
- }
-
- snd_hda_codec_write(codec, codec->core.afg, 0, verb, parm);
- }
- static void analog_low_current_mode(struct hda_codec *codec)
- {
- return __analog_low_current_mode(codec, false);
- }
- static int via_build_controls(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- int err, i;
- err = snd_hda_gen_build_controls(codec);
- if (err < 0)
- return err;
- err = add_beep_ctls(codec);
- if (err < 0)
- return err;
- spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
- for (i = 0; i < spec->num_mixers; i++) {
- err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
- if (err < 0)
- return err;
- }
- return 0;
- }
- static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
- struct hda_codec *codec,
- struct snd_pcm_substream *substream,
- int action)
- {
- analog_low_current_mode(codec);
- vt1708_update_hp_work(codec);
- }
- static void via_free(struct hda_codec *codec)
- {
- vt1708_stop_hp_work(codec);
- snd_hda_gen_free(codec);
- }
- #ifdef CONFIG_PM
- static int via_suspend(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- vt1708_stop_hp_work(codec);
-
- if (spec->codec_type == VT1802)
- snd_hda_shutup_pins(codec);
- return 0;
- }
- static int via_resume(struct hda_codec *codec)
- {
-
- msleep(10);
- codec->patch_ops.init(codec);
- regcache_sync(codec->core.regmap);
- return 0;
- }
- #endif
- #ifdef CONFIG_PM
- static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
- {
- struct via_spec *spec = codec->spec;
- analog_low_current_mode(codec);
- vt1708_update_hp_work(codec);
- return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
- }
- #endif
- static int via_init(struct hda_codec *codec);
- static const struct hda_codec_ops via_patch_ops = {
- .build_controls = via_build_controls,
- .build_pcms = snd_hda_gen_build_pcms,
- .init = via_init,
- .free = via_free,
- .unsol_event = snd_hda_jack_unsol_event,
- #ifdef CONFIG_PM
- .suspend = via_suspend,
- .resume = via_resume,
- .check_power_status = via_check_power_status,
- #endif
- };
- static const struct hda_verb vt1708_init_verbs[] = {
-
- {0x1, 0xf81, 0x1},
- { }
- };
- static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
- {
- unsigned int def_conf;
- unsigned char seqassoc;
- def_conf = snd_hda_codec_get_pincfg(codec, nid);
- seqassoc = (unsigned char) get_defcfg_association(def_conf);
- seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
- if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
- && (seqassoc == 0xf0 || seqassoc == 0xff)) {
- def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
- snd_hda_codec_set_pincfg(codec, nid, def_conf);
- }
- return;
- }
- static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
- struct via_spec *spec = codec->spec;
- if (spec->codec_type != VT1708)
- return 0;
- ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
- return 0;
- }
- static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
- struct via_spec *spec = codec->spec;
- int val;
- if (spec->codec_type != VT1708)
- return 0;
- val = !!ucontrol->value.integer.value[0];
- if (spec->vt1708_jack_detect == val)
- return 0;
- spec->vt1708_jack_detect = val;
- vt1708_update_hp_work(codec);
- return 1;
- }
- static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Jack Detect",
- .count = 1,
- .info = snd_ctl_boolean_mono_info,
- .get = vt1708_jack_detect_get,
- .put = vt1708_jack_detect_put,
- },
- {}
- };
- static const struct badness_table via_main_out_badness = {
- .no_primary_dac = 0x10000,
- .no_dac = 0x4000,
- .shared_primary = 0x10000,
- .shared_surr = 0x20,
- .shared_clfe = 0x20,
- .shared_surr_main = 0x20,
- };
- static const struct badness_table via_extra_out_badness = {
- .no_primary_dac = 0x4000,
- .no_dac = 0x4000,
- .shared_primary = 0x12,
- .shared_surr = 0x20,
- .shared_clfe = 0x20,
- .shared_surr_main = 0x10,
- };
- static int via_parse_auto_config(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- int err;
- spec->gen.main_out_badness = &via_main_out_badness;
- spec->gen.extra_out_badness = &via_extra_out_badness;
- err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
- if (err < 0)
- return err;
- auto_parse_beep(codec);
- err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
- if (err < 0)
- return err;
-
- codec->power_save_node = 0;
- spec->gen.power_down_unused = 0;
- return 0;
- }
- static int via_init(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- int i;
- for (i = 0; i < spec->num_iverbs; i++)
- snd_hda_sequence_write(codec, spec->init_verbs[i]);
-
- __analog_low_current_mode(codec, true);
- snd_hda_gen_init(codec);
- vt1708_update_hp_work(codec);
- return 0;
- }
- static int vt1708_build_controls(struct hda_codec *codec)
- {
-
- int err;
- int old_interval = codec->jackpoll_interval;
- codec->jackpoll_interval = msecs_to_jiffies(100);
- err = via_build_controls(codec);
- codec->jackpoll_interval = old_interval;
- return err;
- }
- static int vt1708_build_pcms(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- int i, err;
- err = snd_hda_gen_build_pcms(codec);
- if (err < 0 || codec->core.vendor_id != 0x11061708)
- return err;
-
- for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) {
- struct hda_pcm *info = spec->gen.pcm_rec[i];
- if (!info)
- continue;
- if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
- info->pcm_type != HDA_PCM_TYPE_AUDIO)
- continue;
- info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
- SNDRV_PCM_FMTBIT_S16_LE;
- }
- return 0;
- }
- static int patch_vt1708(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
-
- codec->patch_ops.build_controls = vt1708_build_controls;
- codec->patch_ops.build_pcms = vt1708_build_pcms;
- spec->gen.mixer_nid = 0x17;
-
- codec->jackpoll_interval = msecs_to_jiffies(100);
- spec->vt1708_jack_detect = 1;
-
-
- spec->gen.suppress_auto_mic = 1;
-
- spec->gen.auto_mute_via_amp = 1;
-
- vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
- vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
-
- spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
- spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
-
- codec->jackpoll_interval = 0;
- return 0;
- }
- static int patch_vt1709(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x18;
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- return 0;
- }
- static int patch_vt1708S(struct hda_codec *codec);
- static int patch_vt1708B(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
- if (get_codec_type(codec) == VT1708BCE)
- return patch_vt1708S(codec);
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x16;
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- return 0;
- }
- static const struct hda_verb vt1708S_init_verbs[] = {
-
- {0x1, 0xf98, 0x1},
-
- {0x1, 0xf88, 0xc0},
- { }
- };
- static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
- int offset, int num_steps, int step_size)
- {
- snd_hda_override_wcaps(codec, pin,
- get_wcaps(codec, pin) | AC_WCAP_IN_AMP);
- snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
- (offset << AC_AMPCAP_OFFSET_SHIFT) |
- (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
- (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
- (0 << AC_AMPCAP_MUTE_SHIFT));
- }
- static int patch_vt1708S(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x16;
- override_mic_boost(codec, 0x1a, 0, 3, 40);
- override_mic_boost(codec, 0x1e, 0, 3, 40);
-
- if (get_codec_type(codec) == VT1708BCE) {
- kfree(codec->core.chip_name);
- codec->core.chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
- snprintf(codec->card->mixername,
- sizeof(codec->card->mixername),
- "%s %s", codec->core.vendor_name, codec->core.chip_name);
- }
-
- if (codec->core.vendor_id == 0x11064397) {
- kfree(codec->core.chip_name);
- codec->core.chip_name = kstrdup("VT1705", GFP_KERNEL);
- snprintf(codec->card->mixername,
- sizeof(codec->card->mixername),
- "%s %s", codec->core.vendor_name, codec->core.chip_name);
- }
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
- return 0;
- }
- static const struct hda_verb vt1702_init_verbs[] = {
-
- {0x1, 0xF88, 0x3},
-
- {0x1, 0xF82, 0x3F},
- { }
- };
- static int patch_vt1702(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x1a;
-
- snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
- (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
- (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
- (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
- (1 << AC_AMPCAP_MUTE_SHIFT));
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
- return 0;
- }
- static const struct hda_verb vt1718S_init_verbs[] = {
-
- {0x1, 0xfb2, 0x10},
-
- {0x1, 0xf88, 0x8},
- { }
- };
- static int add_secret_dac_path(struct hda_codec *codec)
- {
- struct via_spec *spec = codec->spec;
- int i, nums;
- hda_nid_t conn[8];
- hda_nid_t nid;
- if (!spec->gen.mixer_nid)
- return 0;
- nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
- ARRAY_SIZE(conn) - 1);
- for (i = 0; i < nums; i++) {
- if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
- return 0;
- }
-
- for_each_hda_codec_node(nid, codec) {
- unsigned int caps = get_wcaps(codec, nid);
- if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
- !(caps & AC_WCAP_DIGITAL)) {
- conn[nums++] = nid;
- return snd_hda_override_conn_list(codec,
- spec->gen.mixer_nid,
- nums, conn);
- }
- }
- return 0;
- }
- static int patch_vt1718S(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x21;
- override_mic_boost(codec, 0x2b, 0, 3, 40);
- override_mic_boost(codec, 0x29, 0, 3, 40);
- add_secret_dac_path(codec);
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
- return 0;
- }
- static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_info *uinfo)
- {
- uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
- uinfo->count = 1;
- uinfo->value.integer.min = 0;
- uinfo->value.integer.max = 1;
- return 0;
- }
- static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
- int index = 0;
- index = snd_hda_codec_read(codec, 0x26, 0,
- AC_VERB_GET_CONNECT_SEL, 0);
- if (index != -1)
- *ucontrol->value.integer.value = index;
- return 0;
- }
- static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
- {
- struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
- struct via_spec *spec = codec->spec;
- int index = *ucontrol->value.integer.value;
- snd_hda_codec_write(codec, 0x26, 0,
- AC_VERB_SET_CONNECT_SEL, index);
- spec->dmic_enabled = index;
- return 1;
- }
- static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
- HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
- {
- .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
- .name = "Digital Mic Capture Switch",
- .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
- .count = 1,
- .info = vt1716s_dmic_info,
- .get = vt1716s_dmic_get,
- .put = vt1716s_dmic_put,
- },
- {}
- };
- static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
- HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
- { }
- };
- static const struct hda_verb vt1716S_init_verbs[] = {
-
- {0x1, 0xf8a, 0x80},
-
- {0x1, 0xf88, 0xc0},
-
- {0x1, 0xf90, 0x08},
- { }
- };
- static int patch_vt1716S(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x16;
- override_mic_boost(codec, 0x1a, 0, 3, 40);
- override_mic_boost(codec, 0x1e, 0, 3, 40);
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
- spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
- spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
- return 0;
- }
- static const struct hda_verb vt2002P_init_verbs[] = {
-
- {0x1, 0xfe0, 0x4},
- {0x1, 0xfe9, 0x80},
- {0x1, 0xfe2, 0x22},
-
- {0x1, 0xfb9, 0x24},
-
- {0x1, 0xfb8, 0x88},
- { }
- };
- static const struct hda_verb vt1802_init_verbs[] = {
-
- {0x1, 0xfb9, 0x24},
-
- {0x1, 0xfb8, 0x88},
- { }
- };
- enum {
- VIA_FIXUP_INTMIC_BOOST,
- VIA_FIXUP_ASUS_G75,
- };
- static void via_fixup_intmic_boost(struct hda_codec *codec,
- const struct hda_fixup *fix, int action)
- {
- if (action == HDA_FIXUP_ACT_PRE_PROBE)
- override_mic_boost(codec, 0x30, 0, 2, 40);
- }
- static const struct hda_fixup via_fixups[] = {
- [VIA_FIXUP_INTMIC_BOOST] = {
- .type = HDA_FIXUP_FUNC,
- .v.func = via_fixup_intmic_boost,
- },
- [VIA_FIXUP_ASUS_G75] = {
- .type = HDA_FIXUP_PINS,
- .v.pins = (const struct hda_pintbl[]) {
-
- { 0x24, 0x991301f0 },
- { 0x33, 0x991301f1 },
- { }
- }
- },
- };
- static const struct snd_pci_quirk vt2002p_fixups[] = {
- SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
- SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
- {}
- };
- static void fix_vt1802_connections(struct hda_codec *codec)
- {
- static hda_nid_t conn_24[] = { 0x14, 0x1c };
- static hda_nid_t conn_33[] = { 0x1c };
- snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
- snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
- }
- static int patch_vt2002P(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x21;
- override_mic_boost(codec, 0x2b, 0, 3, 40);
- override_mic_boost(codec, 0x29, 0, 3, 40);
- if (spec->codec_type == VT1802)
- fix_vt1802_connections(codec);
- add_secret_dac_path(codec);
- snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
- snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- if (spec->codec_type == VT1802)
- spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
- else
- spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
- return 0;
- }
- static const struct hda_verb vt1812_init_verbs[] = {
-
- {0x1, 0xfb9, 0x24},
-
- {0x1, 0xfb8, 0xa8},
- { }
- };
- static int patch_vt1812(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x21;
- override_mic_boost(codec, 0x2b, 0, 3, 40);
- override_mic_boost(codec, 0x29, 0, 3, 40);
- add_secret_dac_path(codec);
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
- return 0;
- }
- static const struct hda_verb vt3476_init_verbs[] = {
-
- {0x1, 0xF7B, 0x30},
-
- {0x1, 0xFB9, 0x20},
-
- {0x1, 0xFB8, 0x10},
- { }
- };
- static int patch_vt3476(struct hda_codec *codec)
- {
- struct via_spec *spec;
- int err;
-
- spec = via_new_spec(codec);
- if (spec == NULL)
- return -ENOMEM;
- spec->gen.mixer_nid = 0x3f;
- add_secret_dac_path(codec);
-
- err = via_parse_auto_config(codec);
- if (err < 0) {
- via_free(codec);
- return err;
- }
- spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
- return 0;
- }
- static const struct hda_codec_preset snd_hda_preset_via[] = {
- { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
- { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
- { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
- { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
- { .id = 0x1106e710, .name = "VT1709 10-Ch",
- .patch = patch_vt1709},
- { .id = 0x1106e711, .name = "VT1709 10-Ch",
- .patch = patch_vt1709},
- { .id = 0x1106e712, .name = "VT1709 10-Ch",
- .patch = patch_vt1709},
- { .id = 0x1106e713, .name = "VT1709 10-Ch",
- .patch = patch_vt1709},
- { .id = 0x1106e714, .name = "VT1709 6-Ch",
- .patch = patch_vt1709},
- { .id = 0x1106e715, .name = "VT1709 6-Ch",
- .patch = patch_vt1709},
- { .id = 0x1106e716, .name = "VT1709 6-Ch",
- .patch = patch_vt1709},
- { .id = 0x1106e717, .name = "VT1709 6-Ch",
- .patch = patch_vt1709},
- { .id = 0x1106e720, .name = "VT1708B 8-Ch",
- .patch = patch_vt1708B},
- { .id = 0x1106e721, .name = "VT1708B 8-Ch",
- .patch = patch_vt1708B},
- { .id = 0x1106e722, .name = "VT1708B 8-Ch",
- .patch = patch_vt1708B},
- { .id = 0x1106e723, .name = "VT1708B 8-Ch",
- .patch = patch_vt1708B},
- { .id = 0x1106e724, .name = "VT1708B 4-Ch",
- .patch = patch_vt1708B},
- { .id = 0x1106e725, .name = "VT1708B 4-Ch",
- .patch = patch_vt1708B},
- { .id = 0x1106e726, .name = "VT1708B 4-Ch",
- .patch = patch_vt1708B},
- { .id = 0x1106e727, .name = "VT1708B 4-Ch",
- .patch = patch_vt1708B},
- { .id = 0x11060397, .name = "VT1708S",
- .patch = patch_vt1708S},
- { .id = 0x11061397, .name = "VT1708S",
- .patch = patch_vt1708S},
- { .id = 0x11062397, .name = "VT1708S",
- .patch = patch_vt1708S},
- { .id = 0x11063397, .name = "VT1708S",
- .patch = patch_vt1708S},
- { .id = 0x11064397, .name = "VT1705",
- .patch = patch_vt1708S},
- { .id = 0x11065397, .name = "VT1708S",
- .patch = patch_vt1708S},
- { .id = 0x11066397, .name = "VT1708S",
- .patch = patch_vt1708S},
- { .id = 0x11067397, .name = "VT1708S",
- .patch = patch_vt1708S},
- { .id = 0x11060398, .name = "VT1702",
- .patch = patch_vt1702},
- { .id = 0x11061398, .name = "VT1702",
- .patch = patch_vt1702},
- { .id = 0x11062398, .name = "VT1702",
- .patch = patch_vt1702},
- { .id = 0x11063398, .name = "VT1702",
- .patch = patch_vt1702},
- { .id = 0x11064398, .name = "VT1702",
- .patch = patch_vt1702},
- { .id = 0x11065398, .name = "VT1702",
- .patch = patch_vt1702},
- { .id = 0x11066398, .name = "VT1702",
- .patch = patch_vt1702},
- { .id = 0x11067398, .name = "VT1702",
- .patch = patch_vt1702},
- { .id = 0x11060428, .name = "VT1718S",
- .patch = patch_vt1718S},
- { .id = 0x11064428, .name = "VT1718S",
- .patch = patch_vt1718S},
- { .id = 0x11060441, .name = "VT2020",
- .patch = patch_vt1718S},
- { .id = 0x11064441, .name = "VT1828S",
- .patch = patch_vt1718S},
- { .id = 0x11060433, .name = "VT1716S",
- .patch = patch_vt1716S},
- { .id = 0x1106a721, .name = "VT1716S",
- .patch = patch_vt1716S},
- { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
- { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
- { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
- { .id = 0x11060440, .name = "VT1818S",
- .patch = patch_vt1708S},
- { .id = 0x11060446, .name = "VT1802",
- .patch = patch_vt2002P},
- { .id = 0x11068446, .name = "VT1802",
- .patch = patch_vt2002P},
- { .id = 0x11064760, .name = "VT1705CF",
- .patch = patch_vt3476},
- { .id = 0x11064761, .name = "VT1708SCE",
- .patch = patch_vt3476},
- { .id = 0x11064762, .name = "VT1808",
- .patch = patch_vt3476},
- {}
- };
- MODULE_ALIAS("snd-hda-codec-id:1106*");
- static struct hda_codec_driver via_driver = {
- .preset = snd_hda_preset_via,
- };
- MODULE_LICENSE("GPL");
- MODULE_DESCRIPTION("VIA HD-audio codec");
- module_hda_codec_driver(via_driver);
|