aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-03-20 04:08:01 -0400
committerTakashi Iwai <tiwai@suse.de>2015-03-20 04:08:01 -0400
commitfc0daafeb4acf70839db5baf8ec4b861fff3efef (patch)
tree80d06e6afcedae7321236d8d8e900b824545225a /sound/pci
parentb24062bda7baba62781c2a67d126126ce0bc8899 (diff)
parent5ccf835cc76d89bc0d426659c63d81f609050842 (diff)
Merge branch 'topic/hda-power' into for-next
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/hda/hda_beep.c29
-rw-r--r--sound/pci/hda/hda_beep.h1
-rw-r--r--sound/pci/hda/hda_codec.c4
-rw-r--r--sound/pci/hda/hda_codec.h2
-rw-r--r--sound/pci/hda/hda_generic.c480
-rw-r--r--sound/pci/hda/hda_generic.h5
-rw-r--r--sound/pci/hda/patch_realtek.c41
-rw-r--r--sound/pci/hda/patch_sigmatel.c5
-rw-r--r--sound/pci/hda/patch_via.c662
9 files changed, 427 insertions, 802 deletions
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 581b7fdef0e3..4cdac3a71cae 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -33,30 +33,36 @@ enum {
33 DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */ 33 DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */
34}; 34};
35 35
36static void snd_hda_generate_beep(struct work_struct *work) 36/* generate or stop tone */
37static void generate_tone(struct hda_beep *beep, int tone)
37{ 38{
38 struct hda_beep *beep =
39 container_of(work, struct hda_beep, beep_work);
40 struct hda_codec *codec = beep->codec; 39 struct hda_codec *codec = beep->codec;
41 int tone;
42 40
43 if (!beep->enabled)
44 return;
45
46 tone = beep->tone;
47 if (tone && !beep->playing) { 41 if (tone && !beep->playing) {
48 snd_hda_power_up(codec); 42 snd_hda_power_up(codec);
43 if (beep->power_hook)
44 beep->power_hook(beep, true);
49 beep->playing = 1; 45 beep->playing = 1;
50 } 46 }
51 /* generate tone */
52 snd_hda_codec_write(codec, beep->nid, 0, 47 snd_hda_codec_write(codec, beep->nid, 0,
53 AC_VERB_SET_BEEP_CONTROL, tone); 48 AC_VERB_SET_BEEP_CONTROL, tone);
54 if (!tone && beep->playing) { 49 if (!tone && beep->playing) {
55 beep->playing = 0; 50 beep->playing = 0;
51 if (beep->power_hook)
52 beep->power_hook(beep, false);
56 snd_hda_power_down(codec); 53 snd_hda_power_down(codec);
57 } 54 }
58} 55}
59 56
57static void snd_hda_generate_beep(struct work_struct *work)
58{
59 struct hda_beep *beep =
60 container_of(work, struct hda_beep, beep_work);
61
62 if (beep->enabled)
63 generate_tone(beep, beep->tone);
64}
65
60/* (non-standard) Linear beep tone calculation for IDT/STAC codecs 66/* (non-standard) Linear beep tone calculation for IDT/STAC codecs
61 * 67 *
62 * The tone frequency of beep generator on IDT/STAC codecs is 68 * The tone frequency of beep generator on IDT/STAC codecs is
@@ -130,10 +136,7 @@ static void turn_off_beep(struct hda_beep *beep)
130 cancel_work_sync(&beep->beep_work); 136 cancel_work_sync(&beep->beep_work);
131 if (beep->playing) { 137 if (beep->playing) {
132 /* turn off beep */ 138 /* turn off beep */
133 snd_hda_codec_write(beep->codec, beep->nid, 0, 139 generate_tone(beep, 0);
134 AC_VERB_SET_BEEP_CONTROL, 0);
135 beep->playing = 0;
136 snd_hda_power_down(beep->codec);
137 } 140 }
138} 141}
139 142
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
index a63b5e077332..46524ff7e79e 100644
--- a/sound/pci/hda/hda_beep.h
+++ b/sound/pci/hda/hda_beep.h
@@ -40,6 +40,7 @@ struct hda_beep {
40 unsigned int playing:1; 40 unsigned int playing:1;
41 struct work_struct beep_work; /* scheduled task for beep event */ 41 struct work_struct beep_work; /* scheduled task for beep event */
42 struct mutex mutex; 42 struct mutex mutex;
43 void (*power_hook)(struct hda_beep *beep, bool on);
43}; 44};
44 45
45#ifdef CONFIG_SND_HDA_INPUT_BEEP 46#ifdef CONFIG_SND_HDA_INPUT_BEEP
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 3e4fb7a8fdcb..7e38d6f7314b 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -1502,6 +1502,8 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
1502 if (!p) 1502 if (!p)
1503 return; 1503 return;
1504 1504
1505 if (codec->patch_ops.stream_pm)
1506 codec->patch_ops.stream_pm(codec, nid, true);
1505 if (codec->pcm_format_first) 1507 if (codec->pcm_format_first)
1506 update_pcm_format(codec, p, nid, format); 1508 update_pcm_format(codec, p, nid, format);
1507 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id); 1509 update_pcm_stream_id(codec, p, nid, stream_tag, channel_id);
@@ -1570,6 +1572,8 @@ static void really_cleanup_stream(struct hda_codec *codec,
1570); 1572);
1571 memset(q, 0, sizeof(*q)); 1573 memset(q, 0, sizeof(*q));
1572 q->nid = nid; 1574 q->nid = nid;
1575 if (codec->patch_ops.stream_pm)
1576 codec->patch_ops.stream_pm(codec, nid, false);
1573} 1577}
1574 1578
1575/* clean up the all conflicting obsolete streams */ 1579/* clean up the all conflicting obsolete streams */
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 70851e6d5f10..148e84ce61cf 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -200,6 +200,7 @@ struct hda_codec_ops {
200 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid); 200 int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
201#endif 201#endif
202 void (*reboot_notify)(struct hda_codec *codec); 202 void (*reboot_notify)(struct hda_codec *codec);
203 void (*stream_pm)(struct hda_codec *codec, hda_nid_t nid, bool on);
203}; 204};
204 205
205/* record for amp information cache */ 206/* record for amp information cache */
@@ -370,6 +371,7 @@ struct hda_codec {
370 unsigned int cached_write:1; /* write only to caches */ 371 unsigned int cached_write:1; /* write only to caches */
371 unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */ 372 unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */
372 unsigned int dump_coef:1; /* dump processing coefs in codec proc file */ 373 unsigned int dump_coef:1; /* dump processing coefs in codec proc file */
374 unsigned int power_mgmt:1; /* advanced PM for each widget */
373#ifdef CONFIG_PM 375#ifdef CONFIG_PM
374 unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */ 376 unsigned int d3_stop_clk:1; /* support D3 operation without BCLK */
375 atomic_t in_pm; /* suspend/resume being performed */ 377 atomic_t in_pm; /* suspend/resume being performed */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index ebdbc023583d..d7ca388651da 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -140,6 +140,9 @@ static void parse_user_hints(struct hda_codec *codec)
140 val = snd_hda_get_bool_hint(codec, "single_adc_amp"); 140 val = snd_hda_get_bool_hint(codec, "single_adc_amp");
141 if (val >= 0) 141 if (val >= 0)
142 codec->single_adc_amp = !!val; 142 codec->single_adc_amp = !!val;
143 val = snd_hda_get_bool_hint(codec, "power_mgmt");
144 if (val >= 0)
145 codec->power_mgmt = !!val;
143 146
144 val = snd_hda_get_bool_hint(codec, "auto_mute"); 147 val = snd_hda_get_bool_hint(codec, "auto_mute");
145 if (val >= 0) 148 if (val >= 0)
@@ -648,12 +651,24 @@ static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
648 unsigned int dir, unsigned int idx) 651 unsigned int dir, unsigned int idx)
649{ 652{
650 struct hda_gen_spec *spec = codec->spec; 653 struct hda_gen_spec *spec = codec->spec;
654 int type = get_wcaps_type(get_wcaps(codec, nid));
651 int i, n; 655 int i, n;
652 656
657 if (nid == codec->afg)
658 return true;
659
653 for (n = 0; n < spec->paths.used; n++) { 660 for (n = 0; n < spec->paths.used; n++) {
654 struct nid_path *path = snd_array_elem(&spec->paths, n); 661 struct nid_path *path = snd_array_elem(&spec->paths, n);
655 if (!path->active) 662 if (!path->active)
656 continue; 663 continue;
664 if (codec->power_mgmt) {
665 if (!path->stream_enabled)
666 continue;
667 /* ignore unplugged paths except for DAC/ADC */
668 if (!path->pin_enabled &&
669 type != AC_WID_AUD_OUT && type != AC_WID_AUD_IN)
670 continue;
671 }
657 for (i = 0; i < path->depth; i++) { 672 for (i = 0; i < path->depth; i++) {
658 if (path->path[i] == nid) { 673 if (path->path[i] == nid) {
659 if (dir == HDA_OUTPUT || path->idx[i] == idx) 674 if (dir == HDA_OUTPUT || path->idx[i] == idx)
@@ -807,6 +822,44 @@ static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
807 } 822 }
808} 823}
809 824
825/* sync power of each widget in the the given path */
826static hda_nid_t path_power_update(struct hda_codec *codec,
827 struct nid_path *path,
828 bool allow_powerdown)
829{
830 hda_nid_t nid, changed = 0;
831 int i, state;
832
833 for (i = 0; i < path->depth; i++) {
834 nid = path->path[i];
835 if (nid == codec->afg)
836 continue;
837 if (!allow_powerdown || is_active_nid_for_any(codec, nid))
838 state = AC_PWRST_D0;
839 else
840 state = AC_PWRST_D3;
841 if (!snd_hda_check_power_state(codec, nid, state)) {
842 snd_hda_codec_write(codec, nid, 0,
843 AC_VERB_SET_POWER_STATE, state);
844 changed = nid;
845 /* here we assume that widget attributes (e.g. amp,
846 * pinctl connection) don't change with local power
847 * state change. If not, need to sync the cache.
848 */
849 }
850 }
851 return changed;
852}
853
854/* do sync with the last power state change */
855static void sync_power_state_change(struct hda_codec *codec, hda_nid_t nid)
856{
857 if (nid) {
858 msleep(10);
859 snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
860 }
861}
862
810/** 863/**
811 * snd_hda_activate_path - activate or deactivate the given path 864 * snd_hda_activate_path - activate or deactivate the given path
812 * @codec: the HDA codec 865 * @codec: the HDA codec
@@ -825,15 +878,13 @@ void snd_hda_activate_path(struct hda_codec *codec, struct nid_path *path,
825 if (!enable) 878 if (!enable)
826 path->active = false; 879 path->active = false;
827 880
881 /* make sure the widget is powered up */
882 if (enable && (spec->power_down_unused || codec->power_mgmt))
883 path_power_update(codec, path, codec->power_mgmt);
884
828 for (i = path->depth - 1; i >= 0; i--) { 885 for (i = path->depth - 1; i >= 0; i--) {
829 hda_nid_t nid = path->path[i]; 886 hda_nid_t nid = path->path[i];
830 if (enable && spec->power_down_unused) { 887
831 /* make sure the widget is powered up */
832 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0))
833 snd_hda_codec_write(codec, nid, 0,
834 AC_VERB_SET_POWER_STATE,
835 AC_PWRST_D0);
836 }
837 if (enable && path->multi[i]) 888 if (enable && path->multi[i])
838 snd_hda_codec_update_cache(codec, nid, 0, 889 snd_hda_codec_update_cache(codec, nid, 0,
839 AC_VERB_SET_CONNECT_SEL, 890 AC_VERB_SET_CONNECT_SEL,
@@ -853,28 +904,10 @@ EXPORT_SYMBOL_GPL(snd_hda_activate_path);
853static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path) 904static void path_power_down_sync(struct hda_codec *codec, struct nid_path *path)
854{ 905{
855 struct hda_gen_spec *spec = codec->spec; 906 struct hda_gen_spec *spec = codec->spec;
856 bool changed = false;
857 int i;
858 907
859 if (!spec->power_down_unused || path->active) 908 if (!(spec->power_down_unused || codec->power_mgmt) || path->active)
860 return; 909 return;
861 910 sync_power_state_change(codec, path_power_update(codec, path, true));
862 for (i = 0; i < path->depth; i++) {
863 hda_nid_t nid = path->path[i];
864 if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D3) &&
865 !is_active_nid_for_any(codec, nid)) {
866 snd_hda_codec_write(codec, nid, 0,
867 AC_VERB_SET_POWER_STATE,
868 AC_PWRST_D3);
869 changed = true;
870 }
871 }
872
873 if (changed) {
874 msleep(10);
875 snd_hda_codec_read(codec, path->path[0], 0,
876 AC_VERB_GET_POWER_STATE, 0);
877 }
878} 911}
879 912
880/* turn on/off EAPD on the given pin */ 913/* turn on/off EAPD on the given pin */
@@ -1574,6 +1607,7 @@ static int check_aamix_out_path(struct hda_codec *codec, int path_idx)
1574 return 0; 1607 return 0;
1575 /* print_nid_path(codec, "output-aamix", path); */ 1608 /* print_nid_path(codec, "output-aamix", path); */
1576 path->active = false; /* unused as default */ 1609 path->active = false; /* unused as default */
1610 path->pin_enabled = true; /* static route */
1577 return snd_hda_get_path_idx(codec, path); 1611 return snd_hda_get_path_idx(codec, path);
1578} 1612}
1579 1613
@@ -2998,6 +3032,7 @@ static int new_analog_input(struct hda_codec *codec, int input_idx,
2998 } 3032 }
2999 3033
3000 path->active = true; 3034 path->active = true;
3035 path->stream_enabled = true; /* no DAC/ADC involved */
3001 err = add_loopback_list(spec, mix_nid, idx); 3036 err = add_loopback_list(spec, mix_nid, idx);
3002 if (err < 0) 3037 if (err < 0)
3003 return err; 3038 return err;
@@ -3009,6 +3044,8 @@ static int new_analog_input(struct hda_codec *codec, int input_idx,
3009 if (path) { 3044 if (path) {
3010 print_nid_path(codec, "loopback-merge", path); 3045 print_nid_path(codec, "loopback-merge", path);
3011 path->active = true; 3046 path->active = true;
3047 path->pin_enabled = true; /* static route */
3048 path->stream_enabled = true; /* no DAC/ADC involved */
3012 spec->loopback_merge_path = 3049 spec->loopback_merge_path =
3013 snd_hda_get_path_idx(codec, path); 3050 snd_hda_get_path_idx(codec, path);
3014 } 3051 }
@@ -3810,6 +3847,7 @@ static void parse_digital(struct hda_codec *codec)
3810 continue; 3847 continue;
3811 print_nid_path(codec, "digout", path); 3848 print_nid_path(codec, "digout", path);
3812 path->active = true; 3849 path->active = true;
3850 path->pin_enabled = true; /* no jack detection */
3813 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path); 3851 spec->digout_paths[i] = snd_hda_get_path_idx(codec, path);
3814 set_pin_target(codec, pin, PIN_OUT, false); 3852 set_pin_target(codec, pin, PIN_OUT, false);
3815 if (!nums) { 3853 if (!nums) {
@@ -3837,6 +3875,7 @@ static void parse_digital(struct hda_codec *codec)
3837 if (path) { 3875 if (path) {
3838 print_nid_path(codec, "digin", path); 3876 print_nid_path(codec, "digin", path);
3839 path->active = true; 3877 path->active = true;
3878 path->pin_enabled = true; /* no jack */
3840 spec->dig_in_nid = dig_nid; 3879 spec->dig_in_nid = dig_nid;
3841 spec->digin_path = snd_hda_get_path_idx(codec, path); 3880 spec->digin_path = snd_hda_get_path_idx(codec, path);
3842 set_pin_target(codec, pin, PIN_IN, false); 3881 set_pin_target(codec, pin, PIN_IN, false);
@@ -3896,6 +3935,206 @@ static int mux_select(struct hda_codec *codec, unsigned int adc_idx,
3896 return 1; 3935 return 1;
3897} 3936}
3898 3937
3938/* power up/down widgets in the all paths that match with the given NID
3939 * as terminals (either start- or endpoint)
3940 *
3941 * returns the last changed NID, or zero if unchanged.
3942 */
3943static hda_nid_t set_path_power(struct hda_codec *codec, hda_nid_t nid,
3944 int pin_state, int stream_state)
3945{
3946 struct hda_gen_spec *spec = codec->spec;
3947 hda_nid_t last, changed = 0;
3948 struct nid_path *path;
3949 int n;
3950
3951 for (n = 0; n < spec->paths.used; n++) {
3952 path = snd_array_elem(&spec->paths, n);
3953 if (path->path[0] == nid ||
3954 path->path[path->depth - 1] == nid) {
3955 bool pin_old = path->pin_enabled;
3956 bool stream_old = path->stream_enabled;
3957
3958 if (pin_state >= 0)
3959 path->pin_enabled = pin_state;
3960 if (stream_state >= 0)
3961 path->stream_enabled = stream_state;
3962 if (path->pin_enabled != pin_old ||
3963 path->stream_enabled != stream_old) {
3964 last = path_power_update(codec, path, true);
3965 if (last)
3966 changed = last;
3967 }
3968 }
3969 }
3970 return changed;
3971}
3972
3973/* power up/down the paths of the given pin according to the jack state;
3974 * power = 0/1 : only power up/down if it matches with the jack state,
3975 * < 0 : force power up/down to follow the jack sate
3976 *
3977 * returns the last changed NID, or zero if unchanged.
3978 */
3979static hda_nid_t set_pin_power_jack(struct hda_codec *codec, hda_nid_t pin,
3980 int power)
3981{
3982 bool on;
3983
3984 if (!codec->power_mgmt)
3985 return 0;
3986
3987 on = snd_hda_jack_detect_state(codec, pin) != HDA_JACK_NOT_PRESENT;
3988 if (power >= 0 && on != power)
3989 return 0;
3990 return set_path_power(codec, pin, on, -1);
3991}
3992
3993static void pin_power_callback(struct hda_codec *codec,
3994 struct hda_jack_callback *jack,
3995 bool on)
3996{
3997 if (jack && jack->tbl->nid)
3998 sync_power_state_change(codec,
3999 set_pin_power_jack(codec, jack->tbl->nid, on));
4000}
4001
4002/* callback only doing power up -- called at first */
4003static void pin_power_up_callback(struct hda_codec *codec,
4004 struct hda_jack_callback *jack)
4005{
4006 pin_power_callback(codec, jack, true);
4007}
4008
4009/* callback only doing power down -- called at last */
4010static void pin_power_down_callback(struct hda_codec *codec,
4011 struct hda_jack_callback *jack)
4012{
4013 pin_power_callback(codec, jack, false);
4014}
4015
4016/* set up the power up/down callbacks */
4017static void add_pin_power_ctls(struct hda_codec *codec, int num_pins,
4018 const hda_nid_t *pins, bool on)
4019{
4020 int i;
4021 hda_jack_callback_fn cb =
4022 on ? pin_power_up_callback : pin_power_down_callback;
4023
4024 for (i = 0; i < num_pins && pins[i]; i++) {
4025 if (is_jack_detectable(codec, pins[i]))
4026 snd_hda_jack_detect_enable_callback(codec, pins[i], cb);
4027 else
4028 set_path_power(codec, pins[i], true, -1);
4029 }
4030}
4031
4032/* enabled power callback to each available I/O pin with jack detections;
4033 * the digital I/O pins are excluded because of the unreliable detectsion
4034 */
4035static void add_all_pin_power_ctls(struct hda_codec *codec, bool on)
4036{
4037 struct hda_gen_spec *spec = codec->spec;
4038 struct auto_pin_cfg *cfg = &spec->autocfg;
4039 int i;
4040
4041 if (!codec->power_mgmt)
4042 return;
4043 add_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins, on);
4044 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4045 add_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins, on);
4046 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4047 add_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins, on);
4048 for (i = 0; i < cfg->num_inputs; i++)
4049 add_pin_power_ctls(codec, 1, &cfg->inputs[i].pin, on);
4050}
4051
4052/* sync path power up/down with the jack states of given pins */
4053static void sync_pin_power_ctls(struct hda_codec *codec, int num_pins,
4054 const hda_nid_t *pins)
4055{
4056 int i;
4057
4058 for (i = 0; i < num_pins && pins[i]; i++)
4059 if (is_jack_detectable(codec, pins[i]))
4060 set_pin_power_jack(codec, pins[i], -1);
4061}
4062
4063/* sync path power up/down with pins; called at init and resume */
4064static void sync_all_pin_power_ctls(struct hda_codec *codec)
4065{
4066 struct hda_gen_spec *spec = codec->spec;
4067 struct auto_pin_cfg *cfg = &spec->autocfg;
4068 int i;
4069
4070 if (!codec->power_mgmt)
4071 return;
4072 sync_pin_power_ctls(codec, cfg->line_outs, cfg->line_out_pins);
4073 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
4074 sync_pin_power_ctls(codec, cfg->hp_outs, cfg->hp_pins);
4075 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
4076 sync_pin_power_ctls(codec, cfg->speaker_outs, cfg->speaker_pins);
4077 for (i = 0; i < cfg->num_inputs; i++)
4078 sync_pin_power_ctls(codec, 1, &cfg->inputs[i].pin);
4079}
4080
4081/* add fake paths if not present yet */
4082static int add_fake_paths(struct hda_codec *codec, hda_nid_t nid,
4083 int num_pins, const hda_nid_t *pins)
4084{
4085 struct hda_gen_spec *spec = codec->spec;
4086 struct nid_path *path;
4087 int i;
4088
4089 for (i = 0; i < num_pins; i++) {
4090 if (!pins[i])
4091 break;
4092 if (get_nid_path(codec, nid, pins[i], 0))
4093 continue;
4094 path = snd_array_new(&spec->paths);
4095 if (!path)
4096 return -ENOMEM;
4097 memset(path, 0, sizeof(*path));
4098 path->depth = 2;
4099 path->path[0] = nid;
4100 path->path[1] = pins[i];
4101 path->active = true;
4102 }
4103 return 0;
4104}
4105
4106/* create fake paths to all outputs from beep */
4107static int add_fake_beep_paths(struct hda_codec *codec)
4108{
4109 struct hda_gen_spec *spec = codec->spec;
4110 struct auto_pin_cfg *cfg = &spec->autocfg;
4111 hda_nid_t nid = spec->beep_nid;
4112 int err;
4113
4114 if (!codec->power_mgmt || !nid)
4115 return 0;
4116 err = add_fake_paths(codec, nid, cfg->line_outs, cfg->line_out_pins);
4117 if (err < 0)
4118 return err;
4119 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
4120 err = add_fake_paths(codec, nid, cfg->hp_outs, cfg->hp_pins);
4121 if (err < 0)
4122 return err;
4123 }
4124 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
4125 err = add_fake_paths(codec, nid, cfg->speaker_outs,
4126 cfg->speaker_pins);
4127 if (err < 0)
4128 return err;
4129 }
4130 return 0;
4131}
4132
4133/* power up/down beep widget and its output paths */
4134static void beep_power_hook(struct hda_beep *beep, bool on)
4135{
4136 set_path_power(beep->codec, beep->nid, -1, on);
4137}
3899 4138
3900/* 4139/*
3901 * Jack detections for HP auto-mute and mic-switch 4140 * Jack detections for HP auto-mute and mic-switch
@@ -3933,6 +4172,10 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3933 if (!nid) 4172 if (!nid)
3934 break; 4173 break;
3935 4174
4175 oldval = snd_hda_codec_get_pin_target(codec, nid);
4176 if (oldval & PIN_IN)
4177 continue; /* no mute for inputs */
4178
3936 if (spec->auto_mute_via_amp) { 4179 if (spec->auto_mute_via_amp) {
3937 struct nid_path *path; 4180 struct nid_path *path;
3938 hda_nid_t mute_nid; 4181 hda_nid_t mute_nid;
@@ -3947,29 +4190,33 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
3947 spec->mute_bits |= (1ULL << mute_nid); 4190 spec->mute_bits |= (1ULL << mute_nid);
3948 else 4191 else
3949 spec->mute_bits &= ~(1ULL << mute_nid); 4192 spec->mute_bits &= ~(1ULL << mute_nid);
3950 set_pin_eapd(codec, nid, !mute);
3951 continue; 4193 continue;
4194 } else {
4195 /* don't reset VREF value in case it's controlling
4196 * the amp (see alc861_fixup_asus_amp_vref_0f())
4197 */
4198 if (spec->keep_vref_in_automute)
4199 val = oldval & ~PIN_HP;
4200 else
4201 val = 0;
4202 if (!mute)
4203 val |= oldval;
4204 /* here we call update_pin_ctl() so that the pinctl is
4205 * changed without changing the pinctl target value;
4206 * the original target value will be still referred at
4207 * the init / resume again
4208 */
4209 update_pin_ctl(codec, nid, val);
3952 } 4210 }
3953 4211
3954 oldval = snd_hda_codec_get_pin_target(codec, nid);
3955 if (oldval & PIN_IN)
3956 continue; /* no mute for inputs */
3957 /* don't reset VREF value in case it's controlling
3958 * the amp (see alc861_fixup_asus_amp_vref_0f())
3959 */
3960 if (spec->keep_vref_in_automute)
3961 val = oldval & ~PIN_HP;
3962 else
3963 val = 0;
3964 if (!mute)
3965 val |= oldval;
3966 /* here we call update_pin_ctl() so that the pinctl is changed
3967 * without changing the pinctl target value;
3968 * the original target value will be still referred at the
3969 * init / resume again
3970 */
3971 update_pin_ctl(codec, nid, val);
3972 set_pin_eapd(codec, nid, !mute); 4212 set_pin_eapd(codec, nid, !mute);
4213 if (codec->power_mgmt) {
4214 bool on = !mute;
4215 if (on)
4216 on = snd_hda_jack_detect_state(codec, nid)
4217 != HDA_JACK_NOT_PRESENT;
4218 set_path_power(codec, nid, on, -1);
4219 }
3973 } 4220 }
3974} 4221}
3975 4222
@@ -4466,6 +4713,21 @@ static void mute_all_mixer_nid(struct hda_codec *codec, hda_nid_t mix)
4466} 4713}
4467 4714
4468/** 4715/**
4716 * snd_hda_gen_stream_pm - Stream power management callback
4717 * @codec: the HDA codec
4718 * @nid: audio widget
4719 * @on: power on/off flag
4720 *
4721 * Set this in patch_ops.stream_pm. Only valid with power_mgmt flag.
4722 */
4723void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on)
4724{
4725 if (codec->power_mgmt)
4726 set_path_power(codec, nid, -1, on);
4727}
4728EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm);
4729
4730/**
4469 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and 4731 * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and
4470 * set up the hda_gen_spec 4732 * set up the hda_gen_spec
4471 * @codec: the HDA codec 4733 * @codec: the HDA codec
@@ -4549,6 +4811,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4549 if (err < 0) 4811 if (err < 0)
4550 return err; 4812 return err;
4551 4813
4814 /* add power-down pin callbacks at first */
4815 add_all_pin_power_ctls(codec, false);
4816
4552 spec->const_channel_count = spec->ext_channel_count; 4817 spec->const_channel_count = spec->ext_channel_count;
4553 /* check the multiple speaker and headphone pins */ 4818 /* check the multiple speaker and headphone pins */
4554 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) 4819 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
@@ -4618,6 +4883,9 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4618 } 4883 }
4619 } 4884 }
4620 4885
4886 /* add power-up pin callbacks at last */
4887 add_all_pin_power_ctls(codec, true);
4888
4621 /* mute all aamix input initially */ 4889 /* mute all aamix input initially */
4622 if (spec->mixer_nid) 4890 if (spec->mixer_nid)
4623 mute_all_mixer_nid(codec, spec->mixer_nid); 4891 mute_all_mixer_nid(codec, spec->mixer_nid);
@@ -4625,13 +4893,19 @@ int snd_hda_gen_parse_auto_config(struct hda_codec *codec,
4625 dig_only: 4893 dig_only:
4626 parse_digital(codec); 4894 parse_digital(codec);
4627 4895
4628 if (spec->power_down_unused) 4896 if (spec->power_down_unused || codec->power_mgmt)
4629 codec->power_filter = snd_hda_gen_path_power_filter; 4897 codec->power_filter = snd_hda_gen_path_power_filter;
4630 4898
4631 if (!spec->no_analog && spec->beep_nid) { 4899 if (!spec->no_analog && spec->beep_nid) {
4632 err = snd_hda_attach_beep_device(codec, spec->beep_nid); 4900 err = snd_hda_attach_beep_device(codec, spec->beep_nid);
4633 if (err < 0) 4901 if (err < 0)
4634 return err; 4902 return err;
4903 if (codec->beep && codec->power_mgmt) {
4904 err = add_fake_beep_paths(codec);
4905 if (err < 0)
4906 return err;
4907 codec->beep->power_hook = beep_power_hook;
4908 }
4635 } 4909 }
4636 4910
4637 return 1; 4911 return 1;
@@ -5137,6 +5411,33 @@ static void fill_pcm_stream_name(char *str, size_t len, const char *sfx,
5137 strlcat(str, sfx, len); 5411 strlcat(str, sfx, len);
5138} 5412}
5139 5413
5414/* copy PCM stream info from @default_str, and override non-NULL entries
5415 * from @spec_str and @nid
5416 */
5417static void setup_pcm_stream(struct hda_pcm_stream *str,
5418 const struct hda_pcm_stream *default_str,
5419 const struct hda_pcm_stream *spec_str,
5420 hda_nid_t nid)
5421{
5422 *str = *default_str;
5423 if (nid)
5424 str->nid = nid;
5425 if (spec_str) {
5426 if (spec_str->substreams)
5427 str->substreams = spec_str->substreams;
5428 if (spec_str->channels_min)
5429 str->channels_min = spec_str->channels_min;
5430 if (spec_str->channels_max)
5431 str->channels_max = spec_str->channels_max;
5432 if (spec_str->rates)
5433 str->rates = spec_str->rates;
5434 if (spec_str->formats)
5435 str->formats = spec_str->formats;
5436 if (spec_str->maxbps)
5437 str->maxbps = spec_str->maxbps;
5438 }
5439}
5440
5140/** 5441/**
5141 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results 5442 * snd_hda_gen_build_pcms - build PCM streams based on the parsed results
5142 * @codec: the HDA codec 5443 * @codec: the HDA codec
@@ -5147,7 +5448,6 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5147{ 5448{
5148 struct hda_gen_spec *spec = codec->spec; 5449 struct hda_gen_spec *spec = codec->spec;
5149 struct hda_pcm *info; 5450 struct hda_pcm *info;
5150 const struct hda_pcm_stream *p;
5151 bool have_multi_adcs; 5451 bool have_multi_adcs;
5152 5452
5153 if (spec->no_analog) 5453 if (spec->no_analog)
@@ -5162,11 +5462,10 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5162 spec->pcm_rec[0] = info; 5462 spec->pcm_rec[0] = info;
5163 5463
5164 if (spec->multiout.num_dacs > 0) { 5464 if (spec->multiout.num_dacs > 0) {
5165 p = spec->stream_analog_playback; 5465 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5166 if (!p) 5466 &pcm_analog_playback,
5167 p = &pcm_analog_playback; 5467 spec->stream_analog_playback,
5168 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5468 spec->multiout.dac_nids[0]);
5169 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
5170 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 5469 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
5171 spec->multiout.max_channels; 5470 spec->multiout.max_channels;
5172 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT && 5471 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
@@ -5175,15 +5474,11 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5175 snd_pcm_2_1_chmaps; 5474 snd_pcm_2_1_chmaps;
5176 } 5475 }
5177 if (spec->num_adc_nids) { 5476 if (spec->num_adc_nids) {
5178 p = spec->stream_analog_capture; 5477 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5179 if (!p) { 5478 (spec->dyn_adc_switch ?
5180 if (spec->dyn_adc_switch) 5479 &dyn_adc_pcm_analog_capture : &pcm_analog_capture),
5181 p = &dyn_adc_pcm_analog_capture; 5480 spec->stream_analog_capture,
5182 else 5481 spec->adc_nids[0]);
5183 p = &pcm_analog_capture;
5184 }
5185 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5186 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
5187 } 5482 }
5188 5483
5189 skip_analog: 5484 skip_analog:
@@ -5202,20 +5497,16 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5202 info->pcm_type = spec->dig_out_type; 5497 info->pcm_type = spec->dig_out_type;
5203 else 5498 else
5204 info->pcm_type = HDA_PCM_TYPE_SPDIF; 5499 info->pcm_type = HDA_PCM_TYPE_SPDIF;
5205 if (spec->multiout.dig_out_nid) { 5500 if (spec->multiout.dig_out_nid)
5206 p = spec->stream_digital_playback; 5501 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5207 if (!p) 5502 &pcm_digital_playback,
5208 p = &pcm_digital_playback; 5503 spec->stream_digital_playback,
5209 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5504 spec->multiout.dig_out_nid);
5210 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 5505 if (spec->dig_in_nid)
5211 } 5506 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5212 if (spec->dig_in_nid) { 5507 &pcm_digital_capture,
5213 p = spec->stream_digital_capture; 5508 spec->stream_digital_capture,
5214 if (!p) 5509 spec->dig_in_nid);
5215 p = &pcm_digital_capture;
5216 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
5217 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
5218 }
5219 } 5510 }
5220 5511
5221 if (spec->no_analog) 5512 if (spec->no_analog)
@@ -5236,31 +5527,24 @@ int snd_hda_gen_build_pcms(struct hda_codec *codec)
5236 if (!info) 5527 if (!info)
5237 return -ENOMEM; 5528 return -ENOMEM;
5238 spec->pcm_rec[2] = info; 5529 spec->pcm_rec[2] = info;
5239 if (spec->alt_dac_nid) { 5530 if (spec->alt_dac_nid)
5240 p = spec->stream_analog_alt_playback; 5531 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5241 if (!p) 5532 &pcm_analog_alt_playback,
5242 p = &pcm_analog_alt_playback; 5533 spec->stream_analog_alt_playback,
5243 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p; 5534 spec->alt_dac_nid);
5244 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 5535 else
5245 spec->alt_dac_nid; 5536 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_PLAYBACK],
5246 } else { 5537 &pcm_null_stream, NULL, 0);
5247 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
5248 pcm_null_stream;
5249 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
5250 }
5251 if (have_multi_adcs) { 5538 if (have_multi_adcs) {
5252 p = spec->stream_analog_alt_capture; 5539 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5253 if (!p) 5540 &pcm_analog_alt_capture,
5254 p = &pcm_analog_alt_capture; 5541 spec->stream_analog_alt_capture,
5255 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p; 5542 spec->adc_nids[1]);
5256 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
5257 spec->adc_nids[1];
5258 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = 5543 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
5259 spec->num_adc_nids - 1; 5544 spec->num_adc_nids - 1;
5260 } else { 5545 } else {
5261 info->stream[SNDRV_PCM_STREAM_CAPTURE] = 5546 setup_pcm_stream(&info->stream[SNDRV_PCM_STREAM_CAPTURE],
5262 pcm_null_stream; 5547 &pcm_null_stream, NULL, 0);
5263 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
5264 } 5548 }
5265 } 5549 }
5266 5550
@@ -5468,6 +5752,8 @@ int snd_hda_gen_init(struct hda_codec *codec)
5468 5752
5469 clear_unsol_on_unused_pins(codec); 5753 clear_unsol_on_unused_pins(codec);
5470 5754
5755 sync_all_pin_power_ctls(codec);
5756
5471 /* call init functions of standard auto-mute helpers */ 5757 /* call init functions of standard auto-mute helpers */
5472 update_automute_all(codec); 5758 update_automute_all(codec);
5473 5759
diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h
index b211f889b335..54659b51fe16 100644
--- a/sound/pci/hda/hda_generic.h
+++ b/sound/pci/hda/hda_generic.h
@@ -46,7 +46,9 @@ struct nid_path {
46 unsigned char idx[MAX_NID_PATH_DEPTH]; 46 unsigned char idx[MAX_NID_PATH_DEPTH];
47 unsigned char multi[MAX_NID_PATH_DEPTH]; 47 unsigned char multi[MAX_NID_PATH_DEPTH];
48 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */ 48 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
49 bool active; 49 bool active:1; /* activated by driver */
50 bool pin_enabled:1; /* pins are enabled */
51 bool stream_enabled:1; /* stream is active */
50}; 52};
51 53
52/* mic/line-in auto switching entry */ 54/* mic/line-in auto switching entry */
@@ -340,5 +342,6 @@ int snd_hda_gen_check_power_status(struct hda_codec *codec, hda_nid_t nid);
340unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec, 342unsigned int snd_hda_gen_path_power_filter(struct hda_codec *codec,
341 hda_nid_t nid, 343 hda_nid_t nid,
342 unsigned int power_state); 344 unsigned int power_state);
345void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on);
343 346
344#endif /* __SOUND_HDA_GENERIC_H */ 347#endif /* __SOUND_HDA_GENERIC_H */
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 2a61bda8115d..124eacf67fc4 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -2602,53 +2602,12 @@ static int patch_alc268(struct hda_codec *codec)
2602 * ALC269 2602 * ALC269
2603 */ 2603 */
2604 2604
2605static int playback_pcm_open(struct hda_pcm_stream *hinfo,
2606 struct hda_codec *codec,
2607 struct snd_pcm_substream *substream)
2608{
2609 struct hda_gen_spec *spec = codec->spec;
2610 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2611 hinfo);
2612}
2613
2614static int playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2615 struct hda_codec *codec,
2616 unsigned int stream_tag,
2617 unsigned int format,
2618 struct snd_pcm_substream *substream)
2619{
2620 struct hda_gen_spec *spec = codec->spec;
2621 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2622 stream_tag, format, substream);
2623}
2624
2625static int playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2626 struct hda_codec *codec,
2627 struct snd_pcm_substream *substream)
2628{
2629 struct hda_gen_spec *spec = codec->spec;
2630 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2631}
2632
2633static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = { 2605static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
2634 .substreams = 1,
2635 .channels_min = 2,
2636 .channels_max = 8,
2637 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ 2606 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2638 /* NID is set in alc_build_pcms */
2639 .ops = {
2640 .open = playback_pcm_open,
2641 .prepare = playback_pcm_prepare,
2642 .cleanup = playback_pcm_cleanup
2643 },
2644}; 2607};
2645 2608
2646static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = { 2609static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
2647 .substreams = 1,
2648 .channels_min = 2,
2649 .channels_max = 2,
2650 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */ 2610 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
2651 /* NID is set in alc_build_pcms */
2652}; 2611};
2653 2612
2654/* different alc269-variants */ 2613/* different alc269-variants */
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 2956a6ba6bf0..86b944a6b0ed 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -4394,6 +4394,7 @@ static const struct hda_codec_ops stac_patch_ops = {
4394#ifdef CONFIG_PM 4394#ifdef CONFIG_PM
4395 .suspend = stac_suspend, 4395 .suspend = stac_suspend,
4396#endif 4396#endif
4397 .stream_pm = snd_hda_gen_stream_pm,
4397 .reboot_notify = stac_shutup, 4398 .reboot_notify = stac_shutup,
4398}; 4399};
4399 4400
@@ -4487,6 +4488,7 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4487 return err; 4488 return err;
4488 4489
4489 spec = codec->spec; 4490 spec = codec->spec;
4491 codec->power_mgmt = 1;
4490 spec->linear_tone_beep = 0; 4492 spec->linear_tone_beep = 0;
4491 spec->gen.mixer_nid = 0x1d; 4493 spec->gen.mixer_nid = 0x1d;
4492 spec->have_spdif_mux = 1; 4494 spec->have_spdif_mux = 1;
@@ -4592,6 +4594,7 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
4592 codec->epss = 0; /* longer delay needed for D3 */ 4594 codec->epss = 0; /* longer delay needed for D3 */
4593 4595
4594 spec = codec->spec; 4596 spec = codec->spec;
4597 codec->power_mgmt = 1;
4595 spec->linear_tone_beep = 0; 4598 spec->linear_tone_beep = 0;
4596 spec->gen.own_eapd_ctl = 1; 4599 spec->gen.own_eapd_ctl = 1;
4597 spec->gen.power_down_unused = 1; 4600 spec->gen.power_down_unused = 1;
@@ -4641,6 +4644,7 @@ static int patch_stac92hd95(struct hda_codec *codec)
4641 codec->epss = 0; /* longer delay needed for D3 */ 4644 codec->epss = 0; /* longer delay needed for D3 */
4642 4645
4643 spec = codec->spec; 4646 spec = codec->spec;
4647 codec->power_mgmt = 1;
4644 spec->linear_tone_beep = 0; 4648 spec->linear_tone_beep = 0;
4645 spec->gen.own_eapd_ctl = 1; 4649 spec->gen.own_eapd_ctl = 1;
4646 spec->gen.power_down_unused = 1; 4650 spec->gen.power_down_unused = 1;
@@ -4682,6 +4686,7 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
4682 return err; 4686 return err;
4683 4687
4684 spec = codec->spec; 4688 spec = codec->spec;
4689 codec->power_mgmt = 1;
4685 spec->linear_tone_beep = 0; 4690 spec->linear_tone_beep = 0;
4686 spec->gen.own_eapd_ctl = 1; 4691 spec->gen.own_eapd_ctl = 1;
4687 spec->gen.power_down_unused = 1; 4692 spec->gen.power_down_unused = 1;
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 2112fbe9e577..d5d1dca4f11b 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_mgmt = 1;
137 spec->gen.power_down_unused = 1;
141 return spec; 138 return spec;
142} 139}
143 140
@@ -229,90 +226,6 @@ static void vt1708_update_hp_work(struct hda_codec *codec)
229 vt1708_stop_hp_work(codec); 226 vt1708_stop_hp_work(codec);
230} 227}
231 228
232static void set_widgets_power_state(struct hda_codec *codec)
233{
234#if 0 /* FIXME: the assumed connections don't match always with the
235 * actual routes by the generic parser, so better to disable
236 * the control for safety.
237 */
238 struct via_spec *spec = codec->spec;
239 if (spec->set_widgets_power_state)
240 spec->set_widgets_power_state(codec);
241#endif
242}
243
244static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
245 unsigned int parm)
246{
247 if (snd_hda_check_power_state(codec, nid, parm))
248 return;
249 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
250}
251
252static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
253 unsigned int parm, unsigned int index)
254{
255 struct via_spec *spec = codec->spec;
256 unsigned int format;
257
258 if (snd_hda_check_power_state(codec, nid, parm))
259 return;
260 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
261 if (format && (spec->dac_stream_tag[index] != format))
262 spec->dac_stream_tag[index] = format;
263
264 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
265 if (parm == AC_PWRST_D0) {
266 format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
267 if (!format && (spec->dac_stream_tag[index] != format))
268 snd_hda_codec_write(codec, nid, 0,
269 AC_VERB_SET_CHANNEL_STREAMID,
270 spec->dac_stream_tag[index]);
271 }
272}
273
274static bool smart51_enabled(struct hda_codec *codec)
275{
276 struct via_spec *spec = codec->spec;
277 return spec->gen.ext_channel_count > 2;
278}
279
280static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
281{
282 struct via_spec *spec = codec->spec;
283 int i;
284
285 for (i = 0; i < spec->gen.multi_ios; i++)
286 if (spec->gen.multi_io[i].pin == pin)
287 return true;
288 return false;
289}
290
291static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
292 unsigned int *affected_parm)
293{
294 unsigned parm;
295 unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
296 unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
297 >> AC_DEFCFG_MISC_SHIFT
298 & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
299 struct via_spec *spec = codec->spec;
300 unsigned present = 0;
301
302 no_presence |= spec->no_pin_power_ctl;
303 if (!no_presence)
304 present = snd_hda_jack_detect(codec, nid);
305 if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
306 || ((no_presence || present)
307 && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
308 *affected_parm = AC_PWRST_D0; /* if it's connected */
309 parm = AC_PWRST_D0;
310 } else
311 parm = AC_PWRST_D3;
312
313 update_power_state(codec, nid, parm);
314}
315
316static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, 229static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
317 struct snd_ctl_elem_info *uinfo) 230 struct snd_ctl_elem_info *uinfo)
318{ 231{
@@ -323,8 +236,7 @@ static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
323 struct snd_ctl_elem_value *ucontrol) 236 struct snd_ctl_elem_value *ucontrol)
324{ 237{
325 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 238 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
326 struct via_spec *spec = codec->spec; 239 ucontrol->value.enumerated.item[0] = codec->power_mgmt;
327 ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
328 return 0; 240 return 0;
329} 241}
330 242
@@ -333,12 +245,12 @@ static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
333{ 245{
334 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
335 struct via_spec *spec = codec->spec; 247 struct via_spec *spec = codec->spec;
336 unsigned int val = !ucontrol->value.enumerated.item[0]; 248 bool val = !!ucontrol->value.enumerated.item[0];
337 249
338 if (val == spec->no_pin_power_ctl) 250 if (val == codec->power_mgmt)
339 return 0; 251 return 0;
340 spec->no_pin_power_ctl = val; 252 codec->power_mgmt = val;
341 set_widgets_power_state(codec); 253 spec->gen.power_down_unused = val;
342 analog_low_current_mode(codec); 254 analog_low_current_mode(codec);
343 return 1; 255 return 1;
344} 256}
@@ -383,7 +295,7 @@ static void __analog_low_current_mode(struct hda_codec *codec, bool force)
383 bool enable; 295 bool enable;
384 unsigned int verb, parm; 296 unsigned int verb, parm;
385 297
386 if (spec->no_pin_power_ctl) 298 if (!codec->power_mgmt)
387 enable = false; 299 enable = false;
388 else 300 else
389 enable = is_aa_path_mute(codec) && !spec->gen.active_streams; 301 enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
@@ -440,8 +352,7 @@ static int via_build_controls(struct hda_codec *codec)
440 if (err < 0) 352 if (err < 0)
441 return err; 353 return err;
442 354
443 if (spec->set_widgets_power_state) 355 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
444 spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
445 356
446 for (i = 0; i < spec->num_mixers; i++) { 357 for (i = 0; i < spec->num_mixers; i++) {
447 err = snd_hda_add_new_ctls(codec, spec->mixers[i]); 358 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
@@ -485,7 +396,6 @@ static int via_suspend(struct hda_codec *codec)
485static 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)
486{ 397{
487 struct via_spec *spec = codec->spec; 398 struct via_spec *spec = codec->spec;
488 set_widgets_power_state(codec);
489 analog_low_current_mode(codec); 399 analog_low_current_mode(codec);
490 vt1708_update_hp_work(codec); 400 vt1708_update_hp_work(codec);
491 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);
@@ -573,34 +483,6 @@ static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
573 {} /* terminator */ 483 {} /* terminator */
574}; 484};
575 485
576static void via_jack_powerstate_event(struct hda_codec *codec,
577 struct hda_jack_callback *tbl)
578{
579 set_widgets_power_state(codec);
580}
581
582static void via_set_jack_unsol_events(struct hda_codec *codec)
583{
584 struct via_spec *spec = codec->spec;
585 struct auto_pin_cfg *cfg = &spec->gen.autocfg;
586 hda_nid_t pin;
587 int i;
588
589 for (i = 0; i < cfg->line_outs; i++) {
590 pin = cfg->line_out_pins[i];
591 if (pin && is_jack_detectable(codec, pin))
592 snd_hda_jack_detect_enable_callback(codec, pin,
593 via_jack_powerstate_event);
594 }
595
596 for (i = 0; i < cfg->num_inputs; i++) {
597 pin = cfg->line_out_pins[i];
598 if (pin && is_jack_detectable(codec, pin))
599 snd_hda_jack_detect_enable_callback(codec, pin,
600 via_jack_powerstate_event);
601 }
602}
603
604static const struct badness_table via_main_out_badness = { 486static const struct badness_table via_main_out_badness = {
605 .no_primary_dac = 0x10000, 487 .no_primary_dac = 0x10000,
606 .no_dac = 0x4000, 488 .no_dac = 0x4000,
@@ -634,7 +516,9 @@ static int via_parse_auto_config(struct hda_codec *codec)
634 if (err < 0) 516 if (err < 0)
635 return err; 517 return err;
636 518
637 via_set_jack_unsol_events(codec); 519 /* disable widget PM at start for compatibility */
520 codec->power_mgmt = 0;
521 spec->gen.power_down_unused = 0;
638 return 0; 522 return 0;
639} 523}
640 524
@@ -647,7 +531,6 @@ static int via_init(struct hda_codec *codec)
647 snd_hda_sequence_write(codec, spec->init_verbs[i]); 531 snd_hda_sequence_write(codec, spec->init_verbs[i]);
648 532
649 /* init power states */ 533 /* init power states */
650 set_widgets_power_state(codec);
651 __analog_low_current_mode(codec, true); 534 __analog_low_current_mode(codec, true);
652 535
653 snd_hda_gen_init(codec); 536 snd_hda_gen_init(codec);
@@ -767,78 +650,6 @@ static int patch_vt1709(struct hda_codec *codec)
767 return 0; 650 return 0;
768} 651}
769 652
770static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
771{
772 struct via_spec *spec = codec->spec;
773 int imux_is_smixer;
774 unsigned int parm;
775 int is_8ch = 0;
776 if ((spec->codec_type != VT1708B_4CH) &&
777 (codec->vendor_id != 0x11064397))
778 is_8ch = 1;
779
780 /* SW0 (17h) = stereo mixer */
781 imux_is_smixer =
782 (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
783 == ((spec->codec_type == VT1708S) ? 5 : 0));
784 /* inputs */
785 /* PW 1/2/5 (1ah/1bh/1eh) */
786 parm = AC_PWRST_D3;
787 set_pin_power_state(codec, 0x1a, &parm);
788 set_pin_power_state(codec, 0x1b, &parm);
789 set_pin_power_state(codec, 0x1e, &parm);
790 if (imux_is_smixer)
791 parm = AC_PWRST_D0;
792 /* SW0 (17h), AIW 0/1 (13h/14h) */
793 update_power_state(codec, 0x17, parm);
794 update_power_state(codec, 0x13, parm);
795 update_power_state(codec, 0x14, parm);
796
797 /* outputs */
798 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
799 parm = AC_PWRST_D3;
800 set_pin_power_state(codec, 0x19, &parm);
801 if (smart51_enabled(codec))
802 set_pin_power_state(codec, 0x1b, &parm);
803 update_power_state(codec, 0x18, parm);
804 update_power_state(codec, 0x11, parm);
805
806 /* PW6 (22h), SW2 (26h), AOW2 (24h) */
807 if (is_8ch) {
808 parm = AC_PWRST_D3;
809 set_pin_power_state(codec, 0x22, &parm);
810 if (smart51_enabled(codec))
811 set_pin_power_state(codec, 0x1a, &parm);
812 update_power_state(codec, 0x26, parm);
813 update_power_state(codec, 0x24, parm);
814 } else if (codec->vendor_id == 0x11064397) {
815 /* PW7(23h), SW2(27h), AOW2(25h) */
816 parm = AC_PWRST_D3;
817 set_pin_power_state(codec, 0x23, &parm);
818 if (smart51_enabled(codec))
819 set_pin_power_state(codec, 0x1a, &parm);
820 update_power_state(codec, 0x27, parm);
821 update_power_state(codec, 0x25, parm);
822 }
823
824 /* PW 3/4/7 (1ch/1dh/23h) */
825 parm = AC_PWRST_D3;
826 /* force to D0 for internal Speaker */
827 set_pin_power_state(codec, 0x1c, &parm);
828 set_pin_power_state(codec, 0x1d, &parm);
829 if (is_8ch)
830 set_pin_power_state(codec, 0x23, &parm);
831
832 /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
833 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
834 update_power_state(codec, 0x10, parm);
835 if (is_8ch) {
836 update_power_state(codec, 0x25, parm);
837 update_power_state(codec, 0x27, parm);
838 } else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
839 update_power_state(codec, 0x25, parm);
840}
841
842static int patch_vt1708S(struct hda_codec *codec); 653static int patch_vt1708S(struct hda_codec *codec);
843static int patch_vt1708B(struct hda_codec *codec) 654static int patch_vt1708B(struct hda_codec *codec)
844{ 655{
@@ -863,9 +674,6 @@ static int patch_vt1708B(struct hda_codec *codec)
863 } 674 }
864 675
865 codec->patch_ops = via_patch_ops; 676 codec->patch_ops = via_patch_ops;
866
867 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
868
869 return 0; 677 return 0;
870} 678}
871 679
@@ -931,8 +739,6 @@ static int patch_vt1708S(struct hda_codec *codec)
931 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; 739 spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
932 740
933 codec->patch_ops = via_patch_ops; 741 codec->patch_ops = via_patch_ops;
934
935 spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
936 return 0; 742 return 0;
937} 743}
938 744
@@ -946,36 +752,6 @@ static const struct hda_verb vt1702_init_verbs[] = {
946 { } 752 { }
947}; 753};
948 754
949static void set_widgets_power_state_vt1702(struct hda_codec *codec)
950{
951 int imux_is_smixer =
952 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
953 unsigned int parm;
954 /* inputs */
955 /* PW 1/2/5 (14h/15h/18h) */
956 parm = AC_PWRST_D3;
957 set_pin_power_state(codec, 0x14, &parm);
958 set_pin_power_state(codec, 0x15, &parm);
959 set_pin_power_state(codec, 0x18, &parm);
960 if (imux_is_smixer)
961 parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
962 /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
963 update_power_state(codec, 0x13, parm);
964 update_power_state(codec, 0x12, parm);
965 update_power_state(codec, 0x1f, parm);
966 update_power_state(codec, 0x20, parm);
967
968 /* outputs */
969 /* PW 3/4 (16h/17h) */
970 parm = AC_PWRST_D3;
971 set_pin_power_state(codec, 0x17, &parm);
972 set_pin_power_state(codec, 0x16, &parm);
973 /* MW0 (1ah), AOW 0/1 (10h/1dh) */
974 update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
975 update_power_state(codec, 0x10, parm);
976 update_power_state(codec, 0x1d, parm);
977}
978
979static int patch_vt1702(struct hda_codec *codec) 755static int patch_vt1702(struct hda_codec *codec)
980{ 756{
981 struct via_spec *spec; 757 struct via_spec *spec;
@@ -1005,8 +781,6 @@ static int patch_vt1702(struct hda_codec *codec)
1005 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; 781 spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
1006 782
1007 codec->patch_ops = via_patch_ops; 783 codec->patch_ops = via_patch_ops;
1008
1009 spec->set_widgets_power_state = set_widgets_power_state_vt1702;
1010 return 0; 784 return 0;
1011} 785}
1012 786
@@ -1021,71 +795,6 @@ static const struct hda_verb vt1718S_init_verbs[] = {
1021 { } 795 { }
1022}; 796};
1023 797
1024static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
1025{
1026 struct via_spec *spec = codec->spec;
1027 int imux_is_smixer;
1028 unsigned int parm, parm2;
1029 /* MUX6 (1eh) = stereo mixer */
1030 imux_is_smixer =
1031 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
1032 /* inputs */
1033 /* PW 5/6/7 (29h/2ah/2bh) */
1034 parm = AC_PWRST_D3;
1035 set_pin_power_state(codec, 0x29, &parm);
1036 set_pin_power_state(codec, 0x2a, &parm);
1037 set_pin_power_state(codec, 0x2b, &parm);
1038 if (imux_is_smixer)
1039 parm = AC_PWRST_D0;
1040 /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1041 update_power_state(codec, 0x1e, parm);
1042 update_power_state(codec, 0x1f, parm);
1043 update_power_state(codec, 0x10, parm);
1044 update_power_state(codec, 0x11, parm);
1045
1046 /* outputs */
1047 /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
1048 parm = AC_PWRST_D3;
1049 set_pin_power_state(codec, 0x27, &parm);
1050 update_power_state(codec, 0x1a, parm);
1051 parm2 = parm; /* for pin 0x0b */
1052
1053 /* PW2 (26h), AOW2 (ah) */
1054 parm = AC_PWRST_D3;
1055 set_pin_power_state(codec, 0x26, &parm);
1056 if (smart51_enabled(codec))
1057 set_pin_power_state(codec, 0x2b, &parm);
1058 update_power_state(codec, 0xa, parm);
1059
1060 /* PW0 (24h), AOW0 (8h) */
1061 parm = AC_PWRST_D3;
1062 set_pin_power_state(codec, 0x24, &parm);
1063 if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
1064 set_pin_power_state(codec, 0x28, &parm);
1065 update_power_state(codec, 0x8, parm);
1066 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1067 parm = parm2;
1068 update_power_state(codec, 0xb, parm);
1069 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1070 update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
1071
1072 /* PW1 (25h), AOW1 (9h) */
1073 parm = AC_PWRST_D3;
1074 set_pin_power_state(codec, 0x25, &parm);
1075 if (smart51_enabled(codec))
1076 set_pin_power_state(codec, 0x2a, &parm);
1077 update_power_state(codec, 0x9, parm);
1078
1079 if (spec->gen.indep_hp_enabled) {
1080 /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
1081 parm = AC_PWRST_D3;
1082 set_pin_power_state(codec, 0x28, &parm);
1083 update_power_state(codec, 0x1b, parm);
1084 update_power_state(codec, 0x34, parm);
1085 update_power_state(codec, 0xc, parm);
1086 }
1087}
1088
1089/* 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
1090 * 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.
1091 */ 800 */
@@ -1146,9 +855,6 @@ static int patch_vt1718S(struct hda_codec *codec)
1146 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; 855 spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
1147 856
1148 codec->patch_ops = via_patch_ops; 857 codec->patch_ops = via_patch_ops;
1149
1150 spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
1151
1152 return 0; 858 return 0;
1153} 859}
1154 860
@@ -1188,7 +894,6 @@ static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
1188 snd_hda_codec_write(codec, 0x26, 0, 894 snd_hda_codec_write(codec, 0x26, 0,
1189 AC_VERB_SET_CONNECT_SEL, index); 895 AC_VERB_SET_CONNECT_SEL, index);
1190 spec->dmic_enabled = index; 896 spec->dmic_enabled = index;
1191 set_widgets_power_state(codec);
1192 return 1; 897 return 1;
1193} 898}
1194 899
@@ -1223,95 +928,6 @@ static const struct hda_verb vt1716S_init_verbs[] = {
1223 { } 928 { }
1224}; 929};
1225 930
1226static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
1227{
1228 struct via_spec *spec = codec->spec;
1229 int imux_is_smixer;
1230 unsigned int parm;
1231 unsigned int mono_out, present;
1232 /* SW0 (17h) = stereo mixer */
1233 imux_is_smixer =
1234 (snd_hda_codec_read(codec, 0x17, 0,
1235 AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
1236 /* inputs */
1237 /* PW 1/2/5 (1ah/1bh/1eh) */
1238 parm = AC_PWRST_D3;
1239 set_pin_power_state(codec, 0x1a, &parm);
1240 set_pin_power_state(codec, 0x1b, &parm);
1241 set_pin_power_state(codec, 0x1e, &parm);
1242 if (imux_is_smixer)
1243 parm = AC_PWRST_D0;
1244 /* SW0 (17h), AIW0(13h) */
1245 update_power_state(codec, 0x17, parm);
1246 update_power_state(codec, 0x13, parm);
1247
1248 parm = AC_PWRST_D3;
1249 set_pin_power_state(codec, 0x1e, &parm);
1250 /* PW11 (22h) */
1251 if (spec->dmic_enabled)
1252 set_pin_power_state(codec, 0x22, &parm);
1253 else
1254 update_power_state(codec, 0x22, AC_PWRST_D3);
1255
1256 /* SW2(26h), AIW1(14h) */
1257 update_power_state(codec, 0x26, parm);
1258 update_power_state(codec, 0x14, parm);
1259
1260 /* outputs */
1261 /* PW0 (19h), SW1 (18h), AOW1 (11h) */
1262 parm = AC_PWRST_D3;
1263 set_pin_power_state(codec, 0x19, &parm);
1264 /* Smart 5.1 PW2(1bh) */
1265 if (smart51_enabled(codec))
1266 set_pin_power_state(codec, 0x1b, &parm);
1267 update_power_state(codec, 0x18, parm);
1268 update_power_state(codec, 0x11, parm);
1269
1270 /* PW7 (23h), SW3 (27h), AOW3 (25h) */
1271 parm = AC_PWRST_D3;
1272 set_pin_power_state(codec, 0x23, &parm);
1273 /* Smart 5.1 PW1(1ah) */
1274 if (smart51_enabled(codec))
1275 set_pin_power_state(codec, 0x1a, &parm);
1276 update_power_state(codec, 0x27, parm);
1277
1278 /* Smart 5.1 PW5(1eh) */
1279 if (smart51_enabled(codec))
1280 set_pin_power_state(codec, 0x1e, &parm);
1281 update_power_state(codec, 0x25, parm);
1282
1283 /* Mono out */
1284 /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
1285 present = snd_hda_jack_detect(codec, 0x1c);
1286
1287 if (present)
1288 mono_out = 0;
1289 else {
1290 present = snd_hda_jack_detect(codec, 0x1d);
1291 if (!spec->gen.indep_hp_enabled && present)
1292 mono_out = 0;
1293 else
1294 mono_out = 1;
1295 }
1296 parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
1297 update_power_state(codec, 0x28, parm);
1298 update_power_state(codec, 0x29, parm);
1299 update_power_state(codec, 0x2a, parm);
1300
1301 /* PW 3/4 (1ch/1dh) */
1302 parm = AC_PWRST_D3;
1303 set_pin_power_state(codec, 0x1c, &parm);
1304 set_pin_power_state(codec, 0x1d, &parm);
1305 /* HP Independent Mode, power on AOW3 */
1306 if (spec->gen.indep_hp_enabled)
1307 update_power_state(codec, 0x25, parm);
1308
1309 /* force to D0 for internal Speaker */
1310 /* MW0 (16h), AOW0 (10h) */
1311 update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
1312 update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
1313}
1314
1315static int patch_vt1716S(struct hda_codec *codec) 931static int patch_vt1716S(struct hda_codec *codec)
1316{ 932{
1317 struct via_spec *spec; 933 struct via_spec *spec;
@@ -1339,8 +955,6 @@ static int patch_vt1716S(struct hda_codec *codec)
1339 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; 955 spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
1340 956
1341 codec->patch_ops = via_patch_ops; 957 codec->patch_ops = via_patch_ops;
1342
1343 spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
1344 return 0; 958 return 0;
1345} 959}
1346 960
@@ -1366,98 +980,6 @@ static const struct hda_verb vt1802_init_verbs[] = {
1366 { } 980 { }
1367}; 981};
1368 982
1369static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
1370{
1371 struct via_spec *spec = codec->spec;
1372 int imux_is_smixer;
1373 unsigned int parm;
1374 unsigned int present;
1375 /* MUX9 (1eh) = stereo mixer */
1376 imux_is_smixer =
1377 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
1378 /* inputs */
1379 /* PW 5/6/7 (29h/2ah/2bh) */
1380 parm = AC_PWRST_D3;
1381 set_pin_power_state(codec, 0x29, &parm);
1382 set_pin_power_state(codec, 0x2a, &parm);
1383 set_pin_power_state(codec, 0x2b, &parm);
1384 parm = AC_PWRST_D0;
1385 /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1386 update_power_state(codec, 0x1e, parm);
1387 update_power_state(codec, 0x1f, parm);
1388 update_power_state(codec, 0x10, parm);
1389 update_power_state(codec, 0x11, parm);
1390
1391 /* outputs */
1392 /* AOW0 (8h)*/
1393 update_power_state(codec, 0x8, parm);
1394
1395 if (spec->codec_type == VT1802) {
1396 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1397 parm = AC_PWRST_D3;
1398 set_pin_power_state(codec, 0x28, &parm);
1399 update_power_state(codec, 0x18, parm);
1400 update_power_state(codec, 0x38, parm);
1401 } else {
1402 /* PW4 (26h), MW4 (1ch), MUX4(37h) */
1403 parm = AC_PWRST_D3;
1404 set_pin_power_state(codec, 0x26, &parm);
1405 update_power_state(codec, 0x1c, parm);
1406 update_power_state(codec, 0x37, parm);
1407 }
1408
1409 if (spec->codec_type == VT1802) {
1410 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1411 parm = AC_PWRST_D3;
1412 set_pin_power_state(codec, 0x25, &parm);
1413 update_power_state(codec, 0x15, parm);
1414 update_power_state(codec, 0x35, parm);
1415 } else {
1416 /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
1417 parm = AC_PWRST_D3;
1418 set_pin_power_state(codec, 0x25, &parm);
1419 update_power_state(codec, 0x19, parm);
1420 update_power_state(codec, 0x35, parm);
1421 }
1422
1423 if (spec->gen.indep_hp_enabled)
1424 update_power_state(codec, 0x9, AC_PWRST_D0);
1425
1426 /* Class-D */
1427 /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
1428 present = snd_hda_jack_detect(codec, 0x25);
1429
1430 parm = AC_PWRST_D3;
1431 set_pin_power_state(codec, 0x24, &parm);
1432 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1433 if (spec->codec_type == VT1802)
1434 update_power_state(codec, 0x14, parm);
1435 else
1436 update_power_state(codec, 0x18, parm);
1437 update_power_state(codec, 0x34, parm);
1438
1439 /* Mono Out */
1440 present = snd_hda_jack_detect(codec, 0x26);
1441
1442 parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1443 if (spec->codec_type == VT1802) {
1444 /* PW15 (33h), MW8(1ch), MUX8(3ch) */
1445 update_power_state(codec, 0x33, parm);
1446 update_power_state(codec, 0x1c, parm);
1447 update_power_state(codec, 0x3c, parm);
1448 } else {
1449 /* PW15 (31h), MW8(17h), MUX8(3bh) */
1450 update_power_state(codec, 0x31, parm);
1451 update_power_state(codec, 0x17, parm);
1452 update_power_state(codec, 0x3b, parm);
1453 }
1454 /* MW9 (21h) */
1455 if (imux_is_smixer || !is_aa_path_mute(codec))
1456 update_power_state(codec, 0x21, AC_PWRST_D0);
1457 else
1458 update_power_state(codec, 0x21, AC_PWRST_D3);
1459}
1460
1461/* 983/*
1462 * pin fix-up 984 * pin fix-up
1463 */ 985 */
@@ -1541,8 +1063,6 @@ static int patch_vt2002P(struct hda_codec *codec)
1541 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; 1063 spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
1542 1064
1543 codec->patch_ops = via_patch_ops; 1065 codec->patch_ops = via_patch_ops;
1544
1545 spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
1546 return 0; 1066 return 0;
1547} 1067}
1548 1068
@@ -1556,81 +1076,6 @@ static const struct hda_verb vt1812_init_verbs[] = {
1556 { } 1076 { }
1557}; 1077};
1558 1078
1559static void set_widgets_power_state_vt1812(struct hda_codec *codec)
1560{
1561 struct via_spec *spec = codec->spec;
1562 unsigned int parm;
1563 unsigned int present;
1564 /* inputs */
1565 /* PW 5/6/7 (29h/2ah/2bh) */
1566 parm = AC_PWRST_D3;
1567 set_pin_power_state(codec, 0x29, &parm);
1568 set_pin_power_state(codec, 0x2a, &parm);
1569 set_pin_power_state(codec, 0x2b, &parm);
1570 parm = AC_PWRST_D0;
1571 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1572 update_power_state(codec, 0x1e, parm);
1573 update_power_state(codec, 0x1f, parm);
1574 update_power_state(codec, 0x10, parm);
1575 update_power_state(codec, 0x11, parm);
1576
1577 /* outputs */
1578 /* AOW0 (8h)*/
1579 update_power_state(codec, 0x8, AC_PWRST_D0);
1580
1581 /* PW4 (28h), MW4 (18h), MUX4(38h) */
1582 parm = AC_PWRST_D3;
1583 set_pin_power_state(codec, 0x28, &parm);
1584 update_power_state(codec, 0x18, parm);
1585 update_power_state(codec, 0x38, parm);
1586
1587 /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
1588 parm = AC_PWRST_D3;
1589 set_pin_power_state(codec, 0x25, &parm);
1590 update_power_state(codec, 0x15, parm);
1591 update_power_state(codec, 0x35, parm);
1592 if (spec->gen.indep_hp_enabled)
1593 update_power_state(codec, 0x9, AC_PWRST_D0);
1594
1595 /* Internal Speaker */
1596 /* PW0 (24h), MW0(14h), MUX0(34h) */
1597 present = snd_hda_jack_detect(codec, 0x25);
1598
1599 parm = AC_PWRST_D3;
1600 set_pin_power_state(codec, 0x24, &parm);
1601 if (present) {
1602 update_power_state(codec, 0x14, AC_PWRST_D3);
1603 update_power_state(codec, 0x34, AC_PWRST_D3);
1604 } else {
1605 update_power_state(codec, 0x14, AC_PWRST_D0);
1606 update_power_state(codec, 0x34, AC_PWRST_D0);
1607 }
1608
1609
1610 /* Mono Out */
1611 /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
1612 present = snd_hda_jack_detect(codec, 0x28);
1613
1614 parm = AC_PWRST_D3;
1615 set_pin_power_state(codec, 0x31, &parm);
1616 if (present) {
1617 update_power_state(codec, 0x1c, AC_PWRST_D3);
1618 update_power_state(codec, 0x3c, AC_PWRST_D3);
1619 update_power_state(codec, 0x3e, AC_PWRST_D3);
1620 } else {
1621 update_power_state(codec, 0x1c, AC_PWRST_D0);
1622 update_power_state(codec, 0x3c, AC_PWRST_D0);
1623 update_power_state(codec, 0x3e, AC_PWRST_D0);
1624 }
1625
1626 /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
1627 parm = AC_PWRST_D3;
1628 set_pin_power_state(codec, 0x33, &parm);
1629 update_power_state(codec, 0x1d, parm);
1630 update_power_state(codec, 0x3d, parm);
1631
1632}
1633
1634/* patch for vt1812 */ 1079/* patch for vt1812 */
1635static int patch_vt1812(struct hda_codec *codec) 1080static int patch_vt1812(struct hda_codec *codec)
1636{ 1081{
@@ -1657,8 +1102,6 @@ static int patch_vt1812(struct hda_codec *codec)
1657 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; 1102 spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
1658 1103
1659 codec->patch_ops = via_patch_ops; 1104 codec->patch_ops = via_patch_ops;
1660
1661 spec->set_widgets_power_state = set_widgets_power_state_vt1812;
1662 return 0; 1105 return 0;
1663} 1106}
1664 1107
@@ -1674,84 +1117,6 @@ static const struct hda_verb vt3476_init_verbs[] = {
1674 { } 1117 { }
1675}; 1118};
1676 1119
1677static void set_widgets_power_state_vt3476(struct hda_codec *codec)
1678{
1679 struct via_spec *spec = codec->spec;
1680 int imux_is_smixer;
1681 unsigned int parm, parm2;
1682 /* MUX10 (1eh) = stereo mixer */
1683 imux_is_smixer =
1684 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
1685 /* inputs */
1686 /* PW 5/6/7 (29h/2ah/2bh) */
1687 parm = AC_PWRST_D3;
1688 set_pin_power_state(codec, 0x29, &parm);
1689 set_pin_power_state(codec, 0x2a, &parm);
1690 set_pin_power_state(codec, 0x2b, &parm);
1691 if (imux_is_smixer)
1692 parm = AC_PWRST_D0;
1693 /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1694 update_power_state(codec, 0x1e, parm);
1695 update_power_state(codec, 0x1f, parm);
1696 update_power_state(codec, 0x10, parm);
1697 update_power_state(codec, 0x11, parm);
1698
1699 /* outputs */
1700 /* PW3 (27h), MW3(37h), AOW3 (bh) */
1701 if (spec->codec_type == VT1705CF) {
1702 parm = AC_PWRST_D3;
1703 update_power_state(codec, 0x27, parm);
1704 update_power_state(codec, 0x37, parm);
1705 } else {
1706 parm = AC_PWRST_D3;
1707 set_pin_power_state(codec, 0x27, &parm);
1708 update_power_state(codec, 0x37, parm);
1709 }
1710
1711 /* PW2 (26h), MW2(36h), AOW2 (ah) */
1712 parm = AC_PWRST_D3;
1713 set_pin_power_state(codec, 0x26, &parm);
1714 update_power_state(codec, 0x36, parm);
1715 if (smart51_enabled(codec)) {
1716 /* PW7(2bh), MW7(3bh), MUX7(1Bh) */
1717 set_pin_power_state(codec, 0x2b, &parm);
1718 update_power_state(codec, 0x3b, parm);
1719 update_power_state(codec, 0x1b, parm);
1720 }
1721 update_conv_power_state(codec, 0xa, parm, 2);
1722
1723 /* PW1 (25h), MW1(35h), AOW1 (9h) */
1724 parm = AC_PWRST_D3;
1725 set_pin_power_state(codec, 0x25, &parm);
1726 update_power_state(codec, 0x35, parm);
1727 if (smart51_enabled(codec)) {
1728 /* PW6(2ah), MW6(3ah), MUX6(1ah) */
1729 set_pin_power_state(codec, 0x2a, &parm);
1730 update_power_state(codec, 0x3a, parm);
1731 update_power_state(codec, 0x1a, parm);
1732 }
1733 update_conv_power_state(codec, 0x9, parm, 1);
1734
1735 /* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
1736 parm = AC_PWRST_D3;
1737 set_pin_power_state(codec, 0x28, &parm);
1738 update_power_state(codec, 0x38, parm);
1739 update_power_state(codec, 0x18, parm);
1740 if (spec->gen.indep_hp_enabled)
1741 update_conv_power_state(codec, 0xb, parm, 3);
1742 parm2 = parm; /* for pin 0x0b */
1743
1744 /* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
1745 parm = AC_PWRST_D3;
1746 set_pin_power_state(codec, 0x24, &parm);
1747 update_power_state(codec, 0x34, parm);
1748 if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1749 parm = parm2;
1750 update_conv_power_state(codec, 0x8, parm, 0);
1751 /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1752 update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
1753}
1754
1755static int patch_vt3476(struct hda_codec *codec) 1120static int patch_vt3476(struct hda_codec *codec)
1756{ 1121{
1757 struct via_spec *spec; 1122 struct via_spec *spec;
@@ -1775,9 +1140,6 @@ static int patch_vt3476(struct hda_codec *codec)
1775 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs; 1140 spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;
1776 1141
1777 codec->patch_ops = via_patch_ops; 1142 codec->patch_ops = via_patch_ops;
1778
1779 spec->set_widgets_power_state = set_widgets_power_state_vt3476;
1780
1781 return 0; 1143 return 0;
1782} 1144}
1783 1145