aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_via.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-03-23 08:14:02 -0400
committerTakashi Iwai <tiwai@suse.de>2015-03-23 08:14:02 -0400
commit3372dbdd8ca11f51be8c6a30b2bc79eb04c4a902 (patch)
treed4499bf5a5665b4820ffaf96bce55bf6b895195e /sound/pci/hda/patch_via.c
parentbc465aa9d045feb0e13b4a8f32cc33c1943f62d6 (diff)
parent967b1307b69b8ada8b331e01046ad1ef83742e99 (diff)
Merge branch 'for-next' into topic/hda-core
Diffstat (limited to 'sound/pci/hda/patch_via.c')
-rw-r--r--sound/pci/hda/patch_via.c695
1 files changed, 23 insertions, 672 deletions
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 3de6d3d779c9..485663bb9101 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -99,7 +99,6 @@ struct via_spec {
99 99
100 /* HP mode source */ 100 /* HP mode source */
101 unsigned int dmic_enabled; 101 unsigned int dmic_enabled;
102 unsigned int no_pin_power_ctl;
103 enum VIA_HDA_CODEC codec_type; 102 enum VIA_HDA_CODEC codec_type;
104 103
105 /* analog low-power control */ 104 /* analog low-power control */
@@ -108,9 +107,6 @@ struct via_spec {
108 /* work to check hp jack state */ 107 /* work to check hp jack state */
109 int hp_work_active; 108 int hp_work_active;
110 int vt1708_jack_detect; 109 int vt1708_jack_detect;
111
112 void (*set_widgets_power_state)(struct hda_codec *codec);
113 unsigned int dac_stream_tag[4];
114}; 110};
115 111
116static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); 112static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
@@ -133,11 +129,12 @@ static struct via_spec *via_new_spec(struct hda_codec *codec)
133 /* VT1708BCE & VT1708S are almost same */ 129 /* VT1708BCE & VT1708S are almost same */
134 if (spec->codec_type == VT1708BCE) 130 if (spec->codec_type == VT1708BCE)
135 spec->codec_type = VT1708S; 131 spec->codec_type = VT1708S;
136 spec->no_pin_power_ctl = 1;
137 spec->gen.indep_hp = 1; 132 spec->gen.indep_hp = 1;
138 spec->gen.keep_eapd_on = 1; 133 spec->gen.keep_eapd_on = 1;
139 spec->gen.pcm_playback_hook = via_playback_pcm_hook; 134 spec->gen.pcm_playback_hook = via_playback_pcm_hook;
140 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO; 135 spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
136 codec->power_save_node = 1;
137 spec->gen.power_down_unused = 1;
141 return spec; 138 return spec;
142} 139}
143 140
@@ -222,98 +219,13 @@ static void vt1708_update_hp_work(struct hda_codec *codec)
222 if (!spec->hp_work_active) { 219 if (!spec->hp_work_active) {
223 codec->jackpoll_interval = msecs_to_jiffies(100); 220 codec->jackpoll_interval = msecs_to_jiffies(100);
224 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0); 221 snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
225 queue_delayed_work(codec->bus->workq, 222 schedule_delayed_work(&codec->jackpoll_work, 0);
226 &codec->jackpoll_work, 0);
227 spec->hp_work_active = true; 223 spec->hp_work_active = true;
228 } 224 }
229 } else if (!hp_detect_with_aa(codec)) 225 } else if (!hp_detect_with_aa(codec))
230 vt1708_stop_hp_work(codec); 226 vt1708_stop_hp_work(codec);
231} 227}
232 228
233static void set_widgets_power_state(struct hda_codec *codec)
234{
235#if 0 /* FIXME: the assumed connections don't match always with the
236 * actual routes by the generic parser, so better to disable
237 * the control for safety.
238 */
239 struct via_spec *spec = codec->spec;
240 if (spec->set_widgets_power_state)
241 spec->set_widgets_power_state(codec);
242#endif
243}
244
245static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
246 unsigned int parm)
247{
248 if (snd_hda_check_power_state(codec, nid, parm))
249 return;
250 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
251}
252
253static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
254 unsigned int parm, unsigned int index)
255{
256 struct via_spec *spec = codec->spec;
257 unsigned int format;
258
259 if (snd_hda_check_power_state(codec, nid, parm))
260 return;
261 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
262 if (format && (spec->dac_stream_tag[index] != format))
263 spec->dac_stream_tag[index] = format;
264
265 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
266 if (parm == AC_PWRST_D0) {
267 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
268 if (!format && (spec->dac_stream_tag[index] != format))
269 snd_hda_codec_write(codec, nid, 0,
270 AC_VERB_SET_CHANNEL_STREAMID,
271 spec->dac_stream_tag[index]);
272 }
273}
274
275static bool smart51_enabled(struct hda_codec *codec)
276{
277 struct via_spec *spec = codec->spec;
278 return spec->gen.ext_channel_count > 2;
279}
280
281static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
282{
283 struct via_spec *spec = codec->spec;
284 int i;
285
286 for (i = 0; i < spec->gen.multi_ios; i++)
287 if (spec->gen.multi_io[i].pin == pin)
288 return true;
289 return false;
290}
291
292static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
293 unsigned int *affected_parm)
294{
295 unsigned parm;
296 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
297 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
298 >> AC_DEFCFG_MISC_SHIFT
299 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
300 struct via_spec *spec = codec->spec;
301 unsigned present = 0;
302
303 no_presence |= spec->no_pin_power_ctl;
304 if (!no_presence)
305 present = snd_hda_jack_detect(codec, nid);
306 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
307 || ((no_presence || present)
308 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
309 *affected_parm = AC_PWRST_D0; /* if it's connected */
310 parm = AC_PWRST_D0;
311 } else
312 parm = AC_PWRST_D3;
313
314 update_power_state(codec, nid, parm);
315}
316
317static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, 229static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
318 struct snd_ctl_elem_info *uinfo) 230 struct snd_ctl_elem_info *uinfo)
319{ 231{
@@ -324,8 +236,7 @@ static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
324 struct snd_ctl_elem_value *ucontrol) 236 struct snd_ctl_elem_value *ucontrol)
325{ 237{
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct via_spec *spec = codec->spec; 239 ucontrol->value.enumerated.item[0] = codec->power_save_node;
328 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
329 return 0; 240 return 0;
330} 241}
331 242
@@ -334,12 +245,12 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
334{ 245{
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 struct via_spec *spec = codec->spec; 247 struct via_spec *spec = codec->spec;
337 unsigned int val = !ucontrol->value.enumerated.item[0]; 248 bool val = !!ucontrol->value.enumerated.item[0];
338 249
339 if (val == spec->no_pin_power_ctl) 250 if (val == codec->power_save_node)
340 return 0; 251 return 0;
341 spec->no_pin_power_ctl = val; 252 codec->power_save_node = val;
342 set_widgets_power_state(codec); 253 spec->gen.power_down_unused = val;
343 analog_low_current_mode(codec); 254 analog_low_current_mode(codec);
344 return 1; 255 return 1;
345} 256}
@@ -384,7 +295,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force)
384 bool enable; 295 bool enable;
385 unsigned int verb, parm; 296 unsigned int verb, parm;
386 297
387 if (spec->no_pin_power_ctl) 298 if (!codec->power_save_node)
388 enable = false; 299 enable = false;
389 else 300 else
390 enable = is_aa_path_mute(codec) && !spec->gen.active_streams; 301 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
@@ -441,8 +352,7 @@ static int via_build_controls(struct hda_codec *codec)
441 if (err < 0) 352 if (err < 0)
442 return err; 353 return err;
443 354
444 if (spec->set_widgets_power_state) 355 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
445 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
446 356
447 for (i = 0; i < spec->num_mixers; i++) { 357 for (i = 0; i < spec->num_mixers; i++) {
448 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 358 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
@@ -486,7 +396,6 @@ static int via_suspend(struct hda_codec *codec)
486static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) 396static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
487{ 397{
488 struct via_spec *spec = codec->spec; 398 struct via_spec *spec = codec->spec;
489 set_widgets_power_state(codec);
490 analog_low_current_mode(codec); 399 analog_low_current_mode(codec);
491 vt1708_update_hp_work(codec); 400 vt1708_update_hp_work(codec);
492 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid); 401 return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
@@ -574,34 +483,6 @@ static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
574 {} /* terminator */ 483 {} /* terminator */
575}; 484};
576 485
577static void via_jack_powerstate_event(struct hda_codec *codec,
578 struct hda_jack_callback *tbl)
579{
580 set_widgets_power_state(codec);
581}
582
583static void via_set_jack_unsol_events(struct hda_codec *codec)
584{
585 struct via_spec *spec = codec->spec;
586 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
587 hda_nid_t pin;
588 int i;
589
590 for (i = 0; i < cfg->line_outs; i++) {
591 pin = cfg->line_out_pins[i];
592 if (pin && is_jack_detectable(codec, pin))
593 snd_hda_jack_detect_enable_callback(codec, pin,
594 via_jack_powerstate_event);
595 }
596
597 for (i = 0; i < cfg->num_inputs; i++) {
598 pin = cfg->line_out_pins[i];
599 if (pin && is_jack_detectable(codec, pin))
600 snd_hda_jack_detect_enable_callback(codec, pin,
601 via_jack_powerstate_event);
602 }
603}
604
605static const struct badness_table via_main_out_badness = { 486static const struct badness_table via_main_out_badness = {
606 .no_primary_dac = 0x10000, 487 .no_primary_dac = 0x10000,
607 .no_dac = 0x4000, 488 .no_dac = 0x4000,
@@ -635,7 +516,9 @@ static int via_parse_auto_config(struct hda_codec *codec)
635 if (err < 0) 516 if (err < 0)
636 return err; 517 return err;
637 518
638 via_set_jack_unsol_events(codec); 519 /* disable widget PM at start for compatibility */
520 codec->power_save_node = 0;
521 spec->gen.power_down_unused = 0;
639 return 0; 522 return 0;
640} 523}
641 524
@@ -648,7 +531,6 @@ static int via_init(struct hda_codec *codec)
648 snd_hda_sequence_write(codec, spec->init_verbs[i]); 531 snd_hda_sequence_write(codec, spec->init_verbs[i]);
649 532
650 /* init power states */ 533 /* init power states */
651 set_widgets_power_state(codec);
652 __analog_low_current_mode(codec, true); 534 __analog_low_current_mode(codec, true);
653 535
654 snd_hda_gen_init(codec); 536 snd_hda_gen_init(codec);
@@ -683,8 +565,10 @@ static int vt1708_build_pcms(struct hda_codec *codec)
683 * 24bit samples are used. Until any workaround is found, 565 * 24bit samples are used. Until any workaround is found,
684 * disable the 24bit format, so far. 566 * disable the 24bit format, so far.
685 */ 567 */
686 for (i = 0; i < codec->num_pcms; i++) { 568 for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) {
687 struct hda_pcm *info = &spec->gen.pcm_rec[i]; 569 struct hda_pcm *info = spec->gen.pcm_rec[i];
570 if (!info)
571 continue;
688 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams || 572 if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
689 info->pcm_type != HDA_PCM_TYPE_AUDIO) 573 info->pcm_type != HDA_PCM_TYPE_AUDIO)
690 continue; 574 continue;
@@ -766,78 +650,6 @@ static int patch_vt1709(struct hda_codec *codec)
766 return 0; 650 return 0;
767} 651}
768 652
769static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
770{
771 struct via_spec *spec = codec->spec;
772 int imux_is_smixer;
773 unsigned int parm;
774 int is_8ch = 0;
775 if ((spec->codec_type != VT1708B_4CH) &&
776 (codec->vendor_id != 0x11064397))
777 is_8ch = 1;
778
779 /* SW0 (17h) = stereo mixer */
780 imux_is_smixer =
781 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
782 == ((spec->codec_type == VT1708S) ? 5 : 0));
783 /* inputs */
784 /* PW 1/2/5 (1ah/1bh/1eh) */
785 parm = AC_PWRST_D3;
786 set_pin_power_state(codec, 0x1a, &parm);
787 set_pin_power_state(codec, 0x1b, &parm);
788 set_pin_power_state(codec, 0x1e, &parm);
789 if (imux_is_smixer)
790 parm = AC_PWRST_D0;
791 /* SW0 (17h), AIW 0/1 (13h/14h) */
792 update_power_state(codec, 0x17, parm);
793 update_power_state(codec, 0x13, parm);
794 update_power_state(codec, 0x14, parm);
795
796 /* outputs */
797 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
798 parm = AC_PWRST_D3;
799 set_pin_power_state(codec, 0x19, &parm);
800 if (smart51_enabled(codec))
801 set_pin_power_state(codec, 0x1b, &parm);
802 update_power_state(codec, 0x18, parm);
803 update_power_state(codec, 0x11, parm);
804
805 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
806 if (is_8ch) {
807 parm = AC_PWRST_D3;
808 set_pin_power_state(codec, 0x22, &parm);
809 if (smart51_enabled(codec))
810 set_pin_power_state(codec, 0x1a, &parm);
811 update_power_state(codec, 0x26, parm);
812 update_power_state(codec, 0x24, parm);
813 } else if (codec->vendor_id == 0x11064397) {
814 /* PW7(23h), SW2(27h), AOW2(25h) */
815 parm = AC_PWRST_D3;
816 set_pin_power_state(codec, 0x23, &parm);
817 if (smart51_enabled(codec))
818 set_pin_power_state(codec, 0x1a, &parm);
819 update_power_state(codec, 0x27, parm);
820 update_power_state(codec, 0x25, parm);
821 }
822
823 /* PW 3/4/7 (1ch/1dh/23h) */
824 parm = AC_PWRST_D3;
825 /* force to D0 for internal Speaker */
826 set_pin_power_state(codec, 0x1c, &parm);
827 set_pin_power_state(codec, 0x1d, &parm);
828 if (is_8ch)
829 set_pin_power_state(codec, 0x23, &parm);
830
831 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
832 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
833 update_power_state(codec, 0x10, parm);
834 if (is_8ch) {
835 update_power_state(codec, 0x25, parm);
836 update_power_state(codec, 0x27, parm);
837 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
838 update_power_state(codec, 0x25, parm);
839}
840
841static int patch_vt1708S(struct hda_codec *codec); 653static int patch_vt1708S(struct hda_codec *codec);
842static int patch_vt1708B(struct hda_codec *codec) 654static int patch_vt1708B(struct hda_codec *codec)
843{ 655{
@@ -862,9 +674,6 @@ static int patch_vt1708B(struct hda_codec *codec)
862 } 674 }
863 675
864 codec->patch_ops = via_patch_ops; 676 codec->patch_ops = via_patch_ops;
865
866 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
867
868 return 0; 677 return 0;
869} 678}
870 679
@@ -907,16 +716,16 @@ static int patch_vt1708S(struct hda_codec *codec)
907 if (get_codec_type(codec) == VT1708BCE) { 716 if (get_codec_type(codec) == VT1708BCE) {
908 kfree(codec->chip_name); 717 kfree(codec->chip_name);
909 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); 718 codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
910 snprintf(codec->bus->card->mixername, 719 snprintf(codec->card->mixername,
911 sizeof(codec->bus->card->mixername), 720 sizeof(codec->card->mixername),
912 "%s %s", codec->vendor_name, codec->chip_name); 721 "%s %s", codec->vendor_name, codec->chip_name);
913 } 722 }
914 /* correct names for VT1705 */ 723 /* correct names for VT1705 */
915 if (codec->vendor_id == 0x11064397) { 724 if (codec->vendor_id == 0x11064397) {
916 kfree(codec->chip_name); 725 kfree(codec->chip_name);
917 codec->chip_name = kstrdup("VT1705", GFP_KERNEL); 726 codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
918 snprintf(codec->bus->card->mixername, 727 snprintf(codec->card->mixername,
919 sizeof(codec->bus->card->mixername), 728 sizeof(codec->card->mixername),
920 "%s %s", codec->vendor_name, codec->chip_name); 729 "%s %s", codec->vendor_name, codec->chip_name);
921 } 730 }
922 731
@@ -930,8 +739,6 @@ static int patch_vt1708S(struct hda_codec *codec)
930 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; 739 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
931 740
932 codec->patch_ops = via_patch_ops; 741 codec->patch_ops = via_patch_ops;
933
934 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
935 return 0; 742 return 0;
936} 743}
937 744
@@ -945,36 +752,6 @@ static const struct hda_verb vt1702_init_verbs[] = {
945 { } 752 { }
946}; 753};
947 754
948static void set_widgets_power_state_vt1702(struct hda_codec *codec)
949{
950 int imux_is_smixer =
951 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
952 unsigned int parm;
953 /* inputs */
954 /* PW 1/2/5 (14h/15h/18h) */
955 parm = AC_PWRST_D3;
956 set_pin_power_state(codec, 0x14, &parm);
957 set_pin_power_state(codec, 0x15, &parm);
958 set_pin_power_state(codec, 0x18, &parm);
959 if (imux_is_smixer)
960 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
961 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
962 update_power_state(codec, 0x13, parm);
963 update_power_state(codec, 0x12, parm);
964 update_power_state(codec, 0x1f, parm);
965 update_power_state(codec, 0x20, parm);
966
967 /* outputs */
968 /* PW 3/4 (16h/17h) */
969 parm = AC_PWRST_D3;
970 set_pin_power_state(codec, 0x17, &parm);
971 set_pin_power_state(codec, 0x16, &parm);
972 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
973 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
974 update_power_state(codec, 0x10, parm);
975 update_power_state(codec, 0x1d, parm);
976}
977
978static int patch_vt1702(struct hda_codec *codec) 755static int patch_vt1702(struct hda_codec *codec)
979{ 756{
980 struct via_spec *spec; 757 struct via_spec *spec;
@@ -1004,8 +781,6 @@ static int patch_vt1702(struct hda_codec *codec)
1004 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; 781 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
1005 782
1006 codec->patch_ops = via_patch_ops; 783 codec->patch_ops = via_patch_ops;
1007
1008 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
1009 return 0; 784 return 0;
1010} 785}
1011 786
@@ -1020,71 +795,6 @@ static const struct hda_verb vt1718S_init_verbs[] = {
1020 { } 795 { }
1021}; 796};
1022 797
1023static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1024{
1025 struct via_spec *spec = codec->spec;
1026 int imux_is_smixer;
1027 unsigned int parm, parm2;
1028 /* MUX6 (1eh) = stereo mixer */
1029 imux_is_smixer =
1030 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1031 /* inputs */
1032 /* PW 5/6/7 (29h/2ah/2bh) */
1033 parm = AC_PWRST_D3;
1034 set_pin_power_state(codec, 0x29, &parm);
1035 set_pin_power_state(codec, 0x2a, &parm);
1036 set_pin_power_state(codec, 0x2b, &parm);
1037 if (imux_is_smixer)
1038 parm = AC_PWRST_D0;
1039 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1040 update_power_state(codec, 0x1e, parm);
1041 update_power_state(codec, 0x1f, parm);
1042 update_power_state(codec, 0x10, parm);
1043 update_power_state(codec, 0x11, parm);
1044
1045 /* outputs */
1046 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1047 parm = AC_PWRST_D3;
1048 set_pin_power_state(codec, 0x27, &parm);
1049 update_power_state(codec, 0x1a, parm);
1050 parm2 = parm; /* for pin 0x0b */
1051
1052 /* PW2 (26h), AOW2 (ah) */
1053 parm = AC_PWRST_D3;
1054 set_pin_power_state(codec, 0x26, &parm);
1055 if (smart51_enabled(codec))
1056 set_pin_power_state(codec, 0x2b, &parm);
1057 update_power_state(codec, 0xa, parm);
1058
1059 /* PW0 (24h), AOW0 (8h) */
1060 parm = AC_PWRST_D3;
1061 set_pin_power_state(codec, 0x24, &parm);
1062 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
1063 set_pin_power_state(codec, 0x28, &parm);
1064 update_power_state(codec, 0x8, parm);
1065 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1066 parm = parm2;
1067 update_power_state(codec, 0xb, parm);
1068 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1069 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
1070
1071 /* PW1 (25h), AOW1 (9h) */
1072 parm = AC_PWRST_D3;
1073 set_pin_power_state(codec, 0x25, &parm);
1074 if (smart51_enabled(codec))
1075 set_pin_power_state(codec, 0x2a, &parm);
1076 update_power_state(codec, 0x9, parm);
1077
1078 if (spec->gen.indep_hp_enabled) {
1079 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1080 parm = AC_PWRST_D3;
1081 set_pin_power_state(codec, 0x28, &parm);
1082 update_power_state(codec, 0x1b, parm);
1083 update_power_state(codec, 0x34, parm);
1084 update_power_state(codec, 0xc, parm);
1085 }
1086}
1087
1088/* Add a connection to the primary DAC from AA-mixer for some codecs 798/* Add a connection to the primary DAC from AA-mixer for some codecs
1089 * This isn't listed from the raw info, but the chip has a secret connection. 799 * This isn't listed from the raw info, but the chip has a secret connection.
1090 */ 800 */
@@ -1145,9 +855,6 @@ static int patch_vt1718S(struct hda_codec *codec)
1145 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; 855 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
1146 856
1147 codec->patch_ops = via_patch_ops; 857 codec->patch_ops = via_patch_ops;
1148
1149 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1150
1151 return 0; 858 return 0;
1152} 859}
1153 860
@@ -1187,7 +894,6 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1187 snd_hda_codec_write(codec, 0x26, 0, 894 snd_hda_codec_write(codec, 0x26, 0,
1188 AC_VERB_SET_CONNECT_SEL, index); 895 AC_VERB_SET_CONNECT_SEL, index);
1189 spec->dmic_enabled = index; 896 spec->dmic_enabled = index;
1190 set_widgets_power_state(codec);
1191 return 1; 897 return 1;
1192} 898}
1193 899
@@ -1222,95 +928,6 @@ static const struct hda_verb vt1716S_init_verbs[] = {
1222 { } 928 { }
1223}; 929};
1224 930
1225static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1226{
1227 struct via_spec *spec = codec->spec;
1228 int imux_is_smixer;
1229 unsigned int parm;
1230 unsigned int mono_out, present;
1231 /* SW0 (17h) = stereo mixer */
1232 imux_is_smixer =
1233 (snd_hda_codec_read(codec, 0x17, 0,
1234 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1235 /* inputs */
1236 /* PW 1/2/5 (1ah/1bh/1eh) */
1237 parm = AC_PWRST_D3;
1238 set_pin_power_state(codec, 0x1a, &parm);
1239 set_pin_power_state(codec, 0x1b, &parm);
1240 set_pin_power_state(codec, 0x1e, &parm);
1241 if (imux_is_smixer)
1242 parm = AC_PWRST_D0;
1243 /* SW0 (17h), AIW0(13h) */
1244 update_power_state(codec, 0x17, parm);
1245 update_power_state(codec, 0x13, parm);
1246
1247 parm = AC_PWRST_D3;
1248 set_pin_power_state(codec, 0x1e, &parm);
1249 /* PW11 (22h) */
1250 if (spec->dmic_enabled)
1251 set_pin_power_state(codec, 0x22, &parm);
1252 else
1253 update_power_state(codec, 0x22, AC_PWRST_D3);
1254
1255 /* SW2(26h), AIW1(14h) */
1256 update_power_state(codec, 0x26, parm);
1257 update_power_state(codec, 0x14, parm);
1258
1259 /* outputs */
1260 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1261 parm = AC_PWRST_D3;
1262 set_pin_power_state(codec, 0x19, &parm);
1263 /* Smart 5.1 PW2(1bh) */
1264 if (smart51_enabled(codec))
1265 set_pin_power_state(codec, 0x1b, &parm);
1266 update_power_state(codec, 0x18, parm);
1267 update_power_state(codec, 0x11, parm);
1268
1269 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1270 parm = AC_PWRST_D3;
1271 set_pin_power_state(codec, 0x23, &parm);
1272 /* Smart 5.1 PW1(1ah) */
1273 if (smart51_enabled(codec))
1274 set_pin_power_state(codec, 0x1a, &parm);
1275 update_power_state(codec, 0x27, parm);
1276
1277 /* Smart 5.1 PW5(1eh) */
1278 if (smart51_enabled(codec))
1279 set_pin_power_state(codec, 0x1e, &parm);
1280 update_power_state(codec, 0x25, parm);
1281
1282 /* Mono out */
1283 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1284 present = snd_hda_jack_detect(codec, 0x1c);
1285
1286 if (present)
1287 mono_out = 0;
1288 else {
1289 present = snd_hda_jack_detect(codec, 0x1d);
1290 if (!spec->gen.indep_hp_enabled && present)
1291 mono_out = 0;
1292 else
1293 mono_out = 1;
1294 }
1295 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
1296 update_power_state(codec, 0x28, parm);
1297 update_power_state(codec, 0x29, parm);
1298 update_power_state(codec, 0x2a, parm);
1299
1300 /* PW 3/4 (1ch/1dh) */
1301 parm = AC_PWRST_D3;
1302 set_pin_power_state(codec, 0x1c, &parm);
1303 set_pin_power_state(codec, 0x1d, &parm);
1304 /* HP Independent Mode, power on AOW3 */
1305 if (spec->gen.indep_hp_enabled)
1306 update_power_state(codec, 0x25, parm);
1307
1308 /* force to D0 for internal Speaker */
1309 /* MW0 (16h), AOW0 (10h) */
1310 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1311 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
1312}
1313
1314static int patch_vt1716S(struct hda_codec *codec) 931static int patch_vt1716S(struct hda_codec *codec)
1315{ 932{
1316 struct via_spec *spec; 933 struct via_spec *spec;
@@ -1338,8 +955,6 @@ static int patch_vt1716S(struct hda_codec *codec)
1338 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; 955 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1339 956
1340 codec->patch_ops = via_patch_ops; 957 codec->patch_ops = via_patch_ops;
1341
1342 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
1343 return 0; 958 return 0;
1344} 959}
1345 960
@@ -1365,98 +980,6 @@ static const struct hda_verb vt1802_init_verbs[] = {
1365 { } 980 { }
1366}; 981};
1367 982
1368static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1369{
1370 struct via_spec *spec = codec->spec;
1371 int imux_is_smixer;
1372 unsigned int parm;
1373 unsigned int present;
1374 /* MUX9 (1eh) = stereo mixer */
1375 imux_is_smixer =
1376 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1377 /* inputs */
1378 /* PW 5/6/7 (29h/2ah/2bh) */
1379 parm = AC_PWRST_D3;
1380 set_pin_power_state(codec, 0x29, &parm);
1381 set_pin_power_state(codec, 0x2a, &parm);
1382 set_pin_power_state(codec, 0x2b, &parm);
1383 parm = AC_PWRST_D0;
1384 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1385 update_power_state(codec, 0x1e, parm);
1386 update_power_state(codec, 0x1f, parm);
1387 update_power_state(codec, 0x10, parm);
1388 update_power_state(codec, 0x11, parm);
1389
1390 /* outputs */
1391 /* AOW0 (8h)*/
1392 update_power_state(codec, 0x8, parm);
1393
1394 if (spec->codec_type == VT1802) {
1395 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1396 parm = AC_PWRST_D3;
1397 set_pin_power_state(codec, 0x28, &parm);
1398 update_power_state(codec, 0x18, parm);
1399 update_power_state(codec, 0x38, parm);
1400 } else {
1401 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1402 parm = AC_PWRST_D3;
1403 set_pin_power_state(codec, 0x26, &parm);
1404 update_power_state(codec, 0x1c, parm);
1405 update_power_state(codec, 0x37, parm);
1406 }
1407
1408 if (spec->codec_type == VT1802) {
1409 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1410 parm = AC_PWRST_D3;
1411 set_pin_power_state(codec, 0x25, &parm);
1412 update_power_state(codec, 0x15, parm);
1413 update_power_state(codec, 0x35, parm);
1414 } else {
1415 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1416 parm = AC_PWRST_D3;
1417 set_pin_power_state(codec, 0x25, &parm);
1418 update_power_state(codec, 0x19, parm);
1419 update_power_state(codec, 0x35, parm);
1420 }
1421
1422 if (spec->gen.indep_hp_enabled)
1423 update_power_state(codec, 0x9, AC_PWRST_D0);
1424
1425 /* Class-D */
1426 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1427 present = snd_hda_jack_detect(codec, 0x25);
1428
1429 parm = AC_PWRST_D3;
1430 set_pin_power_state(codec, 0x24, &parm);
1431 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1432 if (spec->codec_type == VT1802)
1433 update_power_state(codec, 0x14, parm);
1434 else
1435 update_power_state(codec, 0x18, parm);
1436 update_power_state(codec, 0x34, parm);
1437
1438 /* Mono Out */
1439 present = snd_hda_jack_detect(codec, 0x26);
1440
1441 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1442 if (spec->codec_type == VT1802) {
1443 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
1444 update_power_state(codec, 0x33, parm);
1445 update_power_state(codec, 0x1c, parm);
1446 update_power_state(codec, 0x3c, parm);
1447 } else {
1448 /* PW15 (31h), MW8(17h), MUX8(3bh) */
1449 update_power_state(codec, 0x31, parm);
1450 update_power_state(codec, 0x17, parm);
1451 update_power_state(codec, 0x3b, parm);
1452 }
1453 /* MW9 (21h) */
1454 if (imux_is_smixer || !is_aa_path_mute(codec))
1455 update_power_state(codec, 0x21, AC_PWRST_D0);
1456 else
1457 update_power_state(codec, 0x21, AC_PWRST_D3);
1458}
1459
1460/* 983/*
1461 * pin fix-up 984 * pin fix-up
1462 */ 985 */
@@ -1540,8 +1063,6 @@ static int patch_vt2002P(struct hda_codec *codec)
1540 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; 1063 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
1541 1064
1542 codec->patch_ops = via_patch_ops; 1065 codec->patch_ops = via_patch_ops;
1543
1544 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
1545 return 0; 1066 return 0;
1546} 1067}
1547 1068
@@ -1555,81 +1076,6 @@ static const struct hda_verb vt1812_init_verbs[] = {
1555 { } 1076 { }
1556}; 1077};
1557 1078
1558static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1559{
1560 struct via_spec *spec = codec->spec;
1561 unsigned int parm;
1562 unsigned int present;
1563 /* inputs */
1564 /* PW 5/6/7 (29h/2ah/2bh) */
1565 parm = AC_PWRST_D3;
1566 set_pin_power_state(codec, 0x29, &parm);
1567 set_pin_power_state(codec, 0x2a, &parm);
1568 set_pin_power_state(codec, 0x2b, &parm);
1569 parm = AC_PWRST_D0;
1570 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1571 update_power_state(codec, 0x1e, parm);
1572 update_power_state(codec, 0x1f, parm);
1573 update_power_state(codec, 0x10, parm);
1574 update_power_state(codec, 0x11, parm);
1575
1576 /* outputs */
1577 /* AOW0 (8h)*/
1578 update_power_state(codec, 0x8, AC_PWRST_D0);
1579
1580 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1581 parm = AC_PWRST_D3;
1582 set_pin_power_state(codec, 0x28, &parm);
1583 update_power_state(codec, 0x18, parm);
1584 update_power_state(codec, 0x38, parm);
1585
1586 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1587 parm = AC_PWRST_D3;
1588 set_pin_power_state(codec, 0x25, &parm);
1589 update_power_state(codec, 0x15, parm);
1590 update_power_state(codec, 0x35, parm);
1591 if (spec->gen.indep_hp_enabled)
1592 update_power_state(codec, 0x9, AC_PWRST_D0);
1593
1594 /* Internal Speaker */
1595 /* PW0 (24h), MW0(14h), MUX0(34h) */
1596 present = snd_hda_jack_detect(codec, 0x25);
1597
1598 parm = AC_PWRST_D3;
1599 set_pin_power_state(codec, 0x24, &parm);
1600 if (present) {
1601 update_power_state(codec, 0x14, AC_PWRST_D3);
1602 update_power_state(codec, 0x34, AC_PWRST_D3);
1603 } else {
1604 update_power_state(codec, 0x14, AC_PWRST_D0);
1605 update_power_state(codec, 0x34, AC_PWRST_D0);
1606 }
1607
1608
1609 /* Mono Out */
1610 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1611 present = snd_hda_jack_detect(codec, 0x28);
1612
1613 parm = AC_PWRST_D3;
1614 set_pin_power_state(codec, 0x31, &parm);
1615 if (present) {
1616 update_power_state(codec, 0x1c, AC_PWRST_D3);
1617 update_power_state(codec, 0x3c, AC_PWRST_D3);
1618 update_power_state(codec, 0x3e, AC_PWRST_D3);
1619 } else {
1620 update_power_state(codec, 0x1c, AC_PWRST_D0);
1621 update_power_state(codec, 0x3c, AC_PWRST_D0);
1622 update_power_state(codec, 0x3e, AC_PWRST_D0);
1623 }
1624
1625 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1626 parm = AC_PWRST_D3;
1627 set_pin_power_state(codec, 0x33, &parm);
1628 update_power_state(codec, 0x1d, parm);
1629 update_power_state(codec, 0x3d, parm);
1630
1631}
1632
1633/* patch for vt1812 */ 1079/* patch for vt1812 */
1634static int patch_vt1812(struct hda_codec *codec) 1080static int patch_vt1812(struct hda_codec *codec)
1635{ 1081{
@@ -1656,8 +1102,6 @@ static int patch_vt1812(struct hda_codec *codec)
1656 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; 1102 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
1657 1103
1658 codec->patch_ops = via_patch_ops; 1104 codec->patch_ops = via_patch_ops;
1659
1660 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
1661 return 0; 1105 return 0;
1662} 1106}
1663 1107
@@ -1673,84 +1117,6 @@ static const struct hda_verb vt3476_init_verbs[] = {
1673 { } 1117 { }
1674}; 1118};
1675 1119
1676static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1677{
1678 struct via_spec *spec = codec->spec;
1679 int imux_is_smixer;
1680 unsigned int parm, parm2;
1681 /* MUX10 (1eh) = stereo mixer */
1682 imux_is_smixer =
1683 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1684 /* inputs */
1685 /* PW 5/6/7 (29h/2ah/2bh) */
1686 parm = AC_PWRST_D3;
1687 set_pin_power_state(codec, 0x29, &parm);
1688 set_pin_power_state(codec, 0x2a, &parm);
1689 set_pin_power_state(codec, 0x2b, &parm);
1690 if (imux_is_smixer)
1691 parm = AC_PWRST_D0;
1692 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1693 update_power_state(codec, 0x1e, parm);
1694 update_power_state(codec, 0x1f, parm);
1695 update_power_state(codec, 0x10, parm);
1696 update_power_state(codec, 0x11, parm);
1697
1698 /* outputs */
1699 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1700 if (spec->codec_type == VT1705CF) {
1701 parm = AC_PWRST_D3;
1702 update_power_state(codec, 0x27, parm);
1703 update_power_state(codec, 0x37, parm);
1704 } else {
1705 parm = AC_PWRST_D3;
1706 set_pin_power_state(codec, 0x27, &parm);
1707 update_power_state(codec, 0x37, parm);
1708 }
1709
1710 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1711 parm = AC_PWRST_D3;
1712 set_pin_power_state(codec, 0x26, &parm);
1713 update_power_state(codec, 0x36, parm);
1714 if (smart51_enabled(codec)) {
1715 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1716 set_pin_power_state(codec, 0x2b, &parm);
1717 update_power_state(codec, 0x3b, parm);
1718 update_power_state(codec, 0x1b, parm);
1719 }
1720 update_conv_power_state(codec, 0xa, parm, 2);
1721
1722 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1723 parm = AC_PWRST_D3;
1724 set_pin_power_state(codec, 0x25, &parm);
1725 update_power_state(codec, 0x35, parm);
1726 if (smart51_enabled(codec)) {
1727 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1728 set_pin_power_state(codec, 0x2a, &parm);
1729 update_power_state(codec, 0x3a, parm);
1730 update_power_state(codec, 0x1a, parm);
1731 }
1732 update_conv_power_state(codec, 0x9, parm, 1);
1733
1734 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1735 parm = AC_PWRST_D3;
1736 set_pin_power_state(codec, 0x28, &parm);
1737 update_power_state(codec, 0x38, parm);
1738 update_power_state(codec, 0x18, parm);
1739 if (spec->gen.indep_hp_enabled)
1740 update_conv_power_state(codec, 0xb, parm, 3);
1741 parm2 = parm; /* for pin 0x0b */
1742
1743 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1744 parm = AC_PWRST_D3;
1745 set_pin_power_state(codec, 0x24, &parm);
1746 update_power_state(codec, 0x34, parm);
1747 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1748 parm = parm2;
1749 update_conv_power_state(codec, 0x8, parm, 0);
1750 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1751 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1752}
1753
1754static int patch_vt3476(struct hda_codec *codec) 1120static int patch_vt3476(struct hda_codec *codec)
1755{ 1121{
1756 struct via_spec *spec; 1122 struct via_spec *spec;
@@ -1774,9 +1140,6 @@ static int patch_vt3476(struct hda_codec *codec)
1774 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs; 1140 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1775 1141
1776 codec->patch_ops = via_patch_ops; 1142 codec->patch_ops = via_patch_ops;
1777
1778 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1779
1780 return 0; 1143 return 0;
1781} 1144}
1782 1145
@@ -1884,23 +1247,11 @@ static const struct hda_codec_preset snd_hda_preset_via[] = {
1884 1247
1885MODULE_ALIAS("snd-hda-codec-id:1106*"); 1248MODULE_ALIAS("snd-hda-codec-id:1106*");
1886 1249
1887static struct hda_codec_preset_list via_list = { 1250static struct hda_codec_driver via_driver = {
1888 .preset = snd_hda_preset_via, 1251 .preset = snd_hda_preset_via,
1889 .owner = THIS_MODULE,
1890}; 1252};
1891 1253
1892MODULE_LICENSE("GPL"); 1254MODULE_LICENSE("GPL");
1893MODULE_DESCRIPTION("VIA HD-audio codec"); 1255MODULE_DESCRIPTION("VIA HD-audio codec");
1894 1256
1895static int __init patch_via_init(void) 1257module_hda_codec_driver(via_driver);
1896{
1897 return snd_hda_add_codec_preset(&via_list);
1898}
1899
1900static void __exit patch_via_exit(void)
1901{
1902 snd_hda_delete_codec_preset(&via_list);
1903}
1904
1905module_init(patch_via_init)
1906module_exit(patch_via_exit)