Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Universal Interface for Intel High Definition Audio Codec |
| 3 | * |
Lydia Wang | 8e86597 | 2009-10-10 19:08:52 +0800 | [diff] [blame] | 4 | * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 5 | * |
Lydia Wang | 8e86597 | 2009-10-10 19:08:52 +0800 | [diff] [blame] | 6 | * (C) 2006-2009 VIA Technology, Inc. |
| 7 | * (C) 2006-2008 Takashi Iwai <tiwai@suse.de> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 8 | * |
| 9 | * This driver is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This driver is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 25 | /* */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 26 | /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 27 | /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */ |
| 28 | /* 2006-08-02 Lydia Wang Add support to VT1709 codec */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 29 | /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 30 | /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */ |
| 31 | /* 2007-09-17 Lydia Wang Add VT1708B codec support */ |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 32 | /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */ |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 33 | /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 34 | /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */ |
| 35 | /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */ |
| 36 | /* 2008-04-09 Lydia Wang Add Independent HP feature */ |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 37 | /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 38 | /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */ |
Lydia Wang | 8e86597 | 2009-10-10 19:08:52 +0800 | [diff] [blame] | 39 | /* 2009-02-16 Logan Li Add support for VT1718S */ |
| 40 | /* 2009-03-13 Logan Li Add support for VT1716S */ |
| 41 | /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */ |
| 42 | /* 2009-07-08 Lydia Wang Add support for VT2002P */ |
| 43 | /* 2009-07-21 Lydia Wang Add support for VT1812 */ |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 44 | /* 2009-09-19 Lydia Wang Add support for VT1818S */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 45 | /* */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 46 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 47 | |
| 48 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 49 | #include <linux/init.h> |
| 50 | #include <linux/delay.h> |
| 51 | #include <linux/slab.h> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 52 | #include <sound/core.h> |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 53 | #include <sound/asoundef.h> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 54 | #include "hda_codec.h" |
| 55 | #include "hda_local.h" |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 56 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 57 | /* Pin Widget NID */ |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 58 | #define VT1708_HP_PIN_NID 0x20 |
| 59 | #define VT1708_CD_PIN_NID 0x24 |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 60 | |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 61 | enum VIA_HDA_CODEC { |
| 62 | UNKNOWN = -1, |
| 63 | VT1708, |
| 64 | VT1709_10CH, |
| 65 | VT1709_6CH, |
| 66 | VT1708B_8CH, |
| 67 | VT1708B_4CH, |
| 68 | VT1708S, |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 69 | VT1708BCE, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 70 | VT1702, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 71 | VT1718S, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 72 | VT1716S, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 73 | VT2002P, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 74 | VT1812, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 75 | VT1802, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 76 | CODEC_TYPES, |
| 77 | }; |
| 78 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 79 | #define VT2002P_COMPATIBLE(spec) \ |
| 80 | ((spec)->codec_type == VT2002P ||\ |
| 81 | (spec)->codec_type == VT1812 ||\ |
| 82 | (spec)->codec_type == VT1802) |
| 83 | |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 84 | #define MAX_NID_PATH_DEPTH 5 |
| 85 | |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 86 | /* output-path: DAC -> ... -> pin |
| 87 | * idx[] contains the source index number of the next widget; |
| 88 | * e.g. idx[0] is the index of the DAC selected by path[1] widget |
| 89 | * multi[] indicates whether it's a selector widget with multi-connectors |
| 90 | * (i.e. the connection selection is mandatory) |
| 91 | * vol_ctl and mute_ctl contains the NIDs for the assigned mixers |
| 92 | */ |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 93 | struct nid_path { |
| 94 | int depth; |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 95 | hda_nid_t path[MAX_NID_PATH_DEPTH]; |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 96 | unsigned char idx[MAX_NID_PATH_DEPTH]; |
| 97 | unsigned char multi[MAX_NID_PATH_DEPTH]; |
| 98 | unsigned int vol_ctl; |
| 99 | unsigned int mute_ctl; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 100 | }; |
| 101 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 102 | /* input-path */ |
| 103 | struct via_input { |
| 104 | hda_nid_t pin; /* input-pin or aa-mix */ |
| 105 | int adc_idx; /* ADC index to be used */ |
| 106 | int mux_idx; /* MUX index (if any) */ |
| 107 | const char *label; /* input-source label */ |
| 108 | }; |
| 109 | |
Takashi Iwai | de6c74f | 2011-07-04 14:46:42 +0200 | [diff] [blame] | 110 | #define VIA_MAX_ADCS 3 |
| 111 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 112 | enum { |
| 113 | STREAM_MULTI_OUT = (1 << 0), |
| 114 | STREAM_INDEP_HP = (1 << 1), |
| 115 | }; |
| 116 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 117 | struct via_spec { |
| 118 | /* codec parameterization */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 119 | const struct snd_kcontrol_new *mixers[6]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 120 | unsigned int num_mixers; |
| 121 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 122 | const struct hda_verb *init_verbs[5]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 123 | unsigned int num_iverbs; |
| 124 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 125 | char stream_name_analog[32]; |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 126 | char stream_name_hp[32]; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 127 | const struct hda_pcm_stream *stream_analog_playback; |
| 128 | const struct hda_pcm_stream *stream_analog_capture; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 129 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 130 | char stream_name_digital[32]; |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 131 | const struct hda_pcm_stream *stream_digital_playback; |
| 132 | const struct hda_pcm_stream *stream_digital_capture; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 133 | |
| 134 | /* playback */ |
| 135 | struct hda_multi_out multiout; |
| 136 | hda_nid_t slave_dig_outs[2]; |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 137 | hda_nid_t hp_dac_nid; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 138 | hda_nid_t speaker_dac_nid; |
| 139 | int hp_indep_shared; /* indep HP-DAC is shared with side ch */ |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 140 | int opened_streams; /* STREAM_* bits */ |
| 141 | int active_streams; /* STREAM_* bits */ |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 142 | int aamix_mode; /* loopback is enabled for output-path? */ |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 143 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 144 | /* Output-paths: |
| 145 | * There are different output-paths depending on the setup. |
| 146 | * out_path, hp_path and speaker_path are primary paths. If both |
| 147 | * direct DAC and aa-loopback routes are available, these contain |
| 148 | * the former paths. Meanwhile *_mix_path contain the paths with |
| 149 | * loopback mixer. (Since the loopback is only for front channel, |
| 150 | * no out_mix_path for surround channels.) |
| 151 | * The HP output has another path, hp_indep_path, which is used in |
| 152 | * the independent-HP mode. |
| 153 | */ |
Takashi Iwai | de6c74f | 2011-07-04 14:46:42 +0200 | [diff] [blame] | 154 | struct nid_path out_path[HDA_SIDE + 1]; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 155 | struct nid_path out_mix_path; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 156 | struct nid_path hp_path; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 157 | struct nid_path hp_mix_path; |
| 158 | struct nid_path hp_indep_path; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 159 | struct nid_path speaker_path; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 160 | struct nid_path speaker_mix_path; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 161 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 162 | /* capture */ |
| 163 | unsigned int num_adc_nids; |
Takashi Iwai | de6c74f | 2011-07-04 14:46:42 +0200 | [diff] [blame] | 164 | hda_nid_t adc_nids[VIA_MAX_ADCS]; |
| 165 | hda_nid_t mux_nids[VIA_MAX_ADCS]; |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 166 | hda_nid_t aa_mix_nid; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 167 | hda_nid_t dig_in_nid; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 168 | |
| 169 | /* capture source */ |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 170 | bool dyn_adc_switch; |
| 171 | int num_inputs; |
| 172 | struct via_input inputs[AUTO_CFG_MAX_INS + 1]; |
Takashi Iwai | de6c74f | 2011-07-04 14:46:42 +0200 | [diff] [blame] | 173 | unsigned int cur_mux[VIA_MAX_ADCS]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 174 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 175 | /* dynamic DAC switching */ |
| 176 | unsigned int cur_dac_stream_tag; |
| 177 | unsigned int cur_dac_format; |
| 178 | unsigned int cur_hp_stream_tag; |
| 179 | unsigned int cur_hp_format; |
| 180 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 181 | /* dynamic ADC switching */ |
| 182 | hda_nid_t cur_adc; |
| 183 | unsigned int cur_adc_stream_tag; |
| 184 | unsigned int cur_adc_format; |
| 185 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 186 | /* PCM information */ |
| 187 | struct hda_pcm pcm_rec[3]; |
| 188 | |
| 189 | /* dynamic controls, init_verbs and input_mux */ |
| 190 | struct auto_pin_cfg autocfg; |
| 191 | struct snd_array kctls; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 192 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
| 193 | |
| 194 | /* HP mode source */ |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 195 | unsigned int hp_independent_mode; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 196 | unsigned int dmic_enabled; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 197 | unsigned int no_pin_power_ctl; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 198 | enum VIA_HDA_CODEC codec_type; |
| 199 | |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 200 | /* smart51 setup */ |
| 201 | unsigned int smart51_nums; |
| 202 | hda_nid_t smart51_pins[2]; |
| 203 | int smart51_idxs[2]; |
| 204 | const char *smart51_labels[2]; |
| 205 | unsigned int smart51_enabled; |
| 206 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 207 | /* work to check hp jack state */ |
| 208 | struct hda_codec *codec; |
| 209 | struct delayed_work vt1708_hp_work; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 210 | int vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 211 | int vt1708_hp_present; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 212 | |
| 213 | void (*set_widgets_power_state)(struct hda_codec *codec); |
| 214 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 215 | struct hda_loopback_check loopback; |
Takashi Iwai | 13af8e7 | 2011-06-20 14:05:46 +0200 | [diff] [blame] | 216 | int num_loopbacks; |
| 217 | struct hda_amp_list loopback_list[8]; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 218 | |
| 219 | /* bind capture-volume */ |
| 220 | struct hda_bind_ctls *bind_cap_vol; |
| 221 | struct hda_bind_ctls *bind_cap_sw; |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 222 | |
| 223 | struct mutex config_mutex; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 224 | }; |
| 225 | |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 226 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 227 | static struct via_spec * via_new_spec(struct hda_codec *codec) |
| 228 | { |
| 229 | struct via_spec *spec; |
| 230 | |
| 231 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 232 | if (spec == NULL) |
| 233 | return NULL; |
| 234 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 235 | mutex_init(&spec->config_mutex); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 236 | codec->spec = spec; |
| 237 | spec->codec = codec; |
Lydia Wang | 0341ccd | 2011-03-22 16:25:03 +0800 | [diff] [blame] | 238 | spec->codec_type = get_codec_type(codec); |
| 239 | /* VT1708BCE & VT1708S are almost same */ |
| 240 | if (spec->codec_type == VT1708BCE) |
| 241 | spec->codec_type = VT1708S; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 242 | return spec; |
| 243 | } |
| 244 | |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 245 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 246 | { |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 247 | u32 vendor_id = codec->vendor_id; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 248 | u16 ven_id = vendor_id >> 16; |
| 249 | u16 dev_id = vendor_id & 0xffff; |
| 250 | enum VIA_HDA_CODEC codec_type; |
| 251 | |
| 252 | /* get codec type */ |
| 253 | if (ven_id != 0x1106) |
| 254 | codec_type = UNKNOWN; |
| 255 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) |
| 256 | codec_type = VT1708; |
| 257 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) |
| 258 | codec_type = VT1709_10CH; |
| 259 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) |
| 260 | codec_type = VT1709_6CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 261 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 262 | codec_type = VT1708B_8CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 263 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
| 264 | codec_type = VT1708BCE; |
| 265 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 266 | codec_type = VT1708B_4CH; |
| 267 | else if ((dev_id & 0xfff) == 0x397 |
| 268 | && (dev_id >> 12) < 8) |
| 269 | codec_type = VT1708S; |
| 270 | else if ((dev_id & 0xfff) == 0x398 |
| 271 | && (dev_id >> 12) < 8) |
| 272 | codec_type = VT1702; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 273 | else if ((dev_id & 0xfff) == 0x428 |
| 274 | && (dev_id >> 12) < 8) |
| 275 | codec_type = VT1718S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 276 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
| 277 | codec_type = VT1716S; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 278 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
| 279 | codec_type = VT1718S; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 280 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
| 281 | codec_type = VT2002P; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 282 | else if (dev_id == 0x0448) |
| 283 | codec_type = VT1812; |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 284 | else if (dev_id == 0x0440) |
| 285 | codec_type = VT1708S; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 286 | else if ((dev_id & 0xfff) == 0x446) |
| 287 | codec_type = VT1802; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 288 | else |
| 289 | codec_type = UNKNOWN; |
| 290 | return codec_type; |
| 291 | }; |
| 292 | |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 293 | #define VIA_JACK_EVENT 0x20 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 294 | #define VIA_HP_EVENT 0x01 |
| 295 | #define VIA_GPIO_EVENT 0x02 |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 296 | #define VIA_LINE_EVENT 0x03 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 297 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 298 | enum { |
| 299 | VIA_CTL_WIDGET_VOL, |
| 300 | VIA_CTL_WIDGET_MUTE, |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 301 | VIA_CTL_WIDGET_ANALOG_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 302 | }; |
| 303 | |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 304 | static void analog_low_current_mode(struct hda_codec *codec); |
| 305 | static bool is_aa_path_mute(struct hda_codec *codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 306 | |
| 307 | static void vt1708_start_hp_work(struct via_spec *spec) |
| 308 | { |
| 309 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 310 | return; |
| 311 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 312 | !spec->vt1708_jack_detect); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 313 | if (!delayed_work_pending(&spec->vt1708_hp_work)) |
| 314 | schedule_delayed_work(&spec->vt1708_hp_work, |
| 315 | msecs_to_jiffies(100)); |
| 316 | } |
| 317 | |
| 318 | static void vt1708_stop_hp_work(struct via_spec *spec) |
| 319 | { |
| 320 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 321 | return; |
| 322 | if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 |
| 323 | && !is_aa_path_mute(spec->codec)) |
| 324 | return; |
| 325 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 326 | !spec->vt1708_jack_detect); |
Tejun Heo | 5b84ba2 | 2010-12-11 17:51:26 +0100 | [diff] [blame] | 327 | cancel_delayed_work_sync(&spec->vt1708_hp_work); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 328 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 329 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 330 | static void set_widgets_power_state(struct hda_codec *codec) |
| 331 | { |
| 332 | struct via_spec *spec = codec->spec; |
| 333 | if (spec->set_widgets_power_state) |
| 334 | spec->set_widgets_power_state(codec); |
| 335 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 336 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 337 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
| 338 | struct snd_ctl_elem_value *ucontrol) |
| 339 | { |
| 340 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 341 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 342 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 343 | set_widgets_power_state(codec); |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 344 | analog_low_current_mode(snd_kcontrol_chip(kcontrol)); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 345 | if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { |
| 346 | if (is_aa_path_mute(codec)) |
| 347 | vt1708_start_hp_work(codec->spec); |
| 348 | else |
| 349 | vt1708_stop_hp_work(codec->spec); |
| 350 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 351 | return change; |
| 352 | } |
| 353 | |
| 354 | /* modify .put = snd_hda_mixer_amp_switch_put */ |
| 355 | #define ANALOG_INPUT_MUTE \ |
| 356 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 357 | .name = NULL, \ |
| 358 | .index = 0, \ |
| 359 | .info = snd_hda_mixer_amp_switch_info, \ |
| 360 | .get = snd_hda_mixer_amp_switch_get, \ |
| 361 | .put = analog_input_switch_put, \ |
| 362 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 363 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 364 | static const struct snd_kcontrol_new via_control_templates[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 365 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 366 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 367 | ANALOG_INPUT_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 368 | }; |
| 369 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 370 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 371 | /* add dynamic controls */ |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 372 | static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec, |
| 373 | const struct snd_kcontrol_new *tmpl, |
| 374 | const char *name) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 375 | { |
| 376 | struct snd_kcontrol_new *knew; |
| 377 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 378 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
| 379 | knew = snd_array_new(&spec->kctls); |
| 380 | if (!knew) |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 381 | return NULL; |
| 382 | *knew = *tmpl; |
| 383 | if (!name) |
| 384 | name = tmpl->name; |
| 385 | if (name) { |
| 386 | knew->name = kstrdup(name, GFP_KERNEL); |
| 387 | if (!knew->name) |
| 388 | return NULL; |
| 389 | } |
| 390 | return knew; |
| 391 | } |
| 392 | |
| 393 | static int __via_add_control(struct via_spec *spec, int type, const char *name, |
| 394 | int idx, unsigned long val) |
| 395 | { |
| 396 | struct snd_kcontrol_new *knew; |
| 397 | |
| 398 | knew = __via_clone_ctl(spec, &via_control_templates[type], name); |
| 399 | if (!knew) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 400 | return -ENOMEM; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 401 | knew->index = idx; |
Jaroslav Kysela | 4d02d1b | 2009-11-12 10:15:48 +0100 | [diff] [blame] | 402 | if (get_amp_nid_(val)) |
Jaroslav Kysela | 5e26dfd | 2009-12-10 13:57:01 +0100 | [diff] [blame] | 403 | knew->subdevice = HDA_SUBDEV_AMP_FLAG; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 404 | knew->private_value = val; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 405 | return 0; |
| 406 | } |
| 407 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 408 | #define via_add_control(spec, type, name, val) \ |
| 409 | __via_add_control(spec, type, name, 0, val) |
| 410 | |
Takashi Iwai | 291c9e3 | 2011-06-17 16:15:26 +0200 | [diff] [blame] | 411 | #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 412 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 413 | static void via_free_kctls(struct hda_codec *codec) |
| 414 | { |
| 415 | struct via_spec *spec = codec->spec; |
| 416 | |
| 417 | if (spec->kctls.list) { |
| 418 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 419 | int i; |
| 420 | for (i = 0; i < spec->kctls.used; i++) |
| 421 | kfree(kctl[i].name); |
| 422 | } |
| 423 | snd_array_free(&spec->kctls); |
| 424 | } |
| 425 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 426 | /* create input playback/capture controls for the given pin */ |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 427 | static int via_new_analog_input(struct via_spec *spec, const char *ctlname, |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 428 | int type_idx, int idx, int mix_nid) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 429 | { |
| 430 | char name[32]; |
| 431 | int err; |
| 432 | |
| 433 | sprintf(name, "%s Playback Volume", ctlname); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 434 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 435 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 436 | if (err < 0) |
| 437 | return err; |
| 438 | sprintf(name, "%s Playback Switch", ctlname); |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 439 | err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 440 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 441 | if (err < 0) |
| 442 | return err; |
| 443 | return 0; |
| 444 | } |
| 445 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 446 | #define get_connection_index(codec, mux, nid) \ |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 447 | snd_hda_get_conn_index(codec, mux, nid, 0) |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 448 | |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 449 | static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, |
| 450 | unsigned int mask) |
| 451 | { |
Takashi Iwai | a934d5a | 2011-06-21 14:22:14 +0200 | [diff] [blame] | 452 | unsigned int caps; |
| 453 | if (!nid) |
| 454 | return false; |
| 455 | caps = get_wcaps(codec, nid); |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 456 | if (dir == HDA_INPUT) |
| 457 | caps &= AC_WCAP_IN_AMP; |
| 458 | else |
| 459 | caps &= AC_WCAP_OUT_AMP; |
| 460 | if (!caps) |
| 461 | return false; |
| 462 | if (query_amp_caps(codec, nid, dir) & mask) |
| 463 | return true; |
| 464 | return false; |
| 465 | } |
| 466 | |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 467 | #define have_mute(codec, nid, dir) \ |
| 468 | check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE) |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 469 | |
Lydia Wang | d69607b | 2011-07-08 14:02:52 +0800 | [diff] [blame] | 470 | /* enable/disable the output-route mixers */ |
| 471 | static void activate_output_mix(struct hda_codec *codec, struct nid_path *path, |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 472 | hda_nid_t mix_nid, int idx, bool enable) |
Lydia Wang | d69607b | 2011-07-08 14:02:52 +0800 | [diff] [blame] | 473 | { |
| 474 | int i, num, val; |
Lydia Wang | d69607b | 2011-07-08 14:02:52 +0800 | [diff] [blame] | 475 | |
| 476 | if (!path) |
| 477 | return; |
| 478 | num = snd_hda_get_conn_list(codec, mix_nid, NULL); |
Lydia Wang | d69607b | 2011-07-08 14:02:52 +0800 | [diff] [blame] | 479 | for (i = 0; i < num; i++) { |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 480 | if (i == idx) |
| 481 | val = AMP_IN_UNMUTE(i); |
| 482 | else |
| 483 | val = AMP_IN_MUTE(i); |
Lydia Wang | d69607b | 2011-07-08 14:02:52 +0800 | [diff] [blame] | 484 | snd_hda_codec_write(codec, mix_nid, 0, |
| 485 | AC_VERB_SET_AMP_GAIN_MUTE, val); |
| 486 | } |
| 487 | } |
| 488 | |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 489 | /* enable/disable the output-route */ |
| 490 | static void activate_output_path(struct hda_codec *codec, struct nid_path *path, |
| 491 | bool enable, bool force) |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 492 | { |
Lydia Wang | d69607b | 2011-07-08 14:02:52 +0800 | [diff] [blame] | 493 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 494 | int i; |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 495 | for (i = 0; i < path->depth; i++) { |
| 496 | hda_nid_t src, dst; |
| 497 | int idx = path->idx[i]; |
| 498 | src = path->path[i]; |
| 499 | if (i < path->depth - 1) |
| 500 | dst = path->path[i + 1]; |
| 501 | else |
| 502 | dst = 0; |
| 503 | if (enable && path->multi[i]) |
| 504 | snd_hda_codec_write(codec, dst, 0, |
| 505 | AC_VERB_SET_CONNECT_SEL, idx); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 506 | if (!force && (dst == spec->aa_mix_nid)) |
Lydia Wang | e5e1468 | 2011-07-01 10:55:07 +0800 | [diff] [blame] | 507 | continue; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 508 | if (have_mute(codec, dst, HDA_INPUT)) |
| 509 | activate_output_mix(codec, path, dst, idx, enable); |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 510 | if (!force && (src == path->vol_ctl || src == path->mute_ctl)) |
| 511 | continue; |
| 512 | if (have_mute(codec, src, HDA_OUTPUT)) { |
| 513 | int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE; |
| 514 | snd_hda_codec_write(codec, src, 0, |
| 515 | AC_VERB_SET_AMP_GAIN_MUTE, val); |
| 516 | } |
| 517 | } |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /* set the given pin as output */ |
| 521 | static void init_output_pin(struct hda_codec *codec, hda_nid_t pin, |
| 522 | int pin_type) |
| 523 | { |
| 524 | if (!pin) |
| 525 | return; |
| 526 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 527 | pin_type); |
| 528 | if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD) |
| 529 | snd_hda_codec_write(codec, pin, 0, |
Takashi Iwai | d3a11e6 | 2009-07-07 13:43:35 +0200 | [diff] [blame] | 530 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 533 | static void via_auto_init_output(struct hda_codec *codec, |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 534 | struct nid_path *path, int pin_type) |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 535 | { |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 536 | unsigned int caps; |
Lydia Wang | d69607b | 2011-07-08 14:02:52 +0800 | [diff] [blame] | 537 | hda_nid_t pin; |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 538 | |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 539 | if (!path->depth) |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 540 | return; |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 541 | pin = path->path[path->depth - 1]; |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 542 | |
| 543 | init_output_pin(codec, pin, pin_type); |
| 544 | caps = query_amp_caps(codec, pin, HDA_OUTPUT); |
| 545 | if (caps & AC_AMPCAP_MUTE) { |
| 546 | unsigned int val; |
| 547 | val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT; |
| 548 | snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 549 | AMP_OUT_MUTE | val); |
| 550 | } |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 551 | activate_output_path(codec, path, true, true); /* force on */ |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 552 | } |
| 553 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 554 | static void via_auto_init_multi_out(struct hda_codec *codec) |
| 555 | { |
| 556 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 557 | struct nid_path *path; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 558 | int i; |
| 559 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 560 | for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) { |
| 561 | path = &spec->out_path[i]; |
| 562 | if (!i && spec->aamix_mode && spec->out_mix_path.depth) |
| 563 | path = &spec->out_mix_path; |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 564 | via_auto_init_output(codec, path, PIN_OUT); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 565 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 566 | } |
| 567 | |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 568 | /* deactivate the inactive headphone-paths */ |
| 569 | static void deactivate_hp_paths(struct hda_codec *codec) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 570 | { |
| 571 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 572 | int shared = spec->hp_indep_shared; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 573 | |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 574 | if (spec->hp_independent_mode) { |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 575 | activate_output_path(codec, &spec->hp_path, false, false); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 576 | activate_output_path(codec, &spec->hp_mix_path, false, false); |
| 577 | if (shared) |
| 578 | activate_output_path(codec, &spec->out_path[shared], |
| 579 | false, false); |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 580 | } else if (spec->aamix_mode || !spec->hp_path.depth) { |
| 581 | activate_output_path(codec, &spec->hp_indep_path, false, false); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 582 | activate_output_path(codec, &spec->hp_path, false, false); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 583 | } else { |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 584 | activate_output_path(codec, &spec->hp_indep_path, false, false); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 585 | activate_output_path(codec, &spec->hp_mix_path, false, false); |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 586 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 587 | } |
| 588 | |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 589 | static void via_auto_init_hp_out(struct hda_codec *codec) |
| 590 | { |
| 591 | struct via_spec *spec = codec->spec; |
| 592 | |
| 593 | if (!spec->hp_path.depth) { |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 594 | via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP); |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 595 | return; |
| 596 | } |
| 597 | deactivate_hp_paths(codec); |
| 598 | if (spec->hp_independent_mode) |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 599 | via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP); |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 600 | else if (spec->aamix_mode) |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 601 | via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP); |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 602 | else |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 603 | via_auto_init_output(codec, &spec->hp_path, PIN_HP); |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 604 | } |
| 605 | |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 606 | static void via_auto_init_speaker_out(struct hda_codec *codec) |
| 607 | { |
| 608 | struct via_spec *spec = codec->spec; |
| 609 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 610 | if (!spec->autocfg.speaker_outs) |
| 611 | return; |
| 612 | if (!spec->speaker_path.depth) { |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 613 | via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 614 | return; |
| 615 | } |
| 616 | if (!spec->aamix_mode) { |
| 617 | activate_output_path(codec, &spec->speaker_mix_path, |
| 618 | false, false); |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 619 | via_auto_init_output(codec, &spec->speaker_path, PIN_OUT); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 620 | } else { |
| 621 | activate_output_path(codec, &spec->speaker_path, false, false); |
Takashi Iwai | a353fbb | 2011-07-21 14:23:35 +0200 | [diff] [blame] | 622 | via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 623 | } |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 624 | } |
| 625 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 626 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin); |
Takashi Iwai | 6e969d9 | 2011-07-11 11:28:13 +0200 | [diff] [blame] | 627 | static void via_hp_automute(struct hda_codec *codec); |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 628 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 629 | static void via_auto_init_analog_input(struct hda_codec *codec) |
| 630 | { |
| 631 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 632 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 633 | hda_nid_t conn[HDA_MAX_CONNECTIONS]; |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 634 | unsigned int ctl; |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 635 | int i, num_conns; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 636 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 637 | /* init ADCs */ |
| 638 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 639 | snd_hda_codec_write(codec, spec->adc_nids[i], 0, |
| 640 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 641 | AMP_IN_UNMUTE(0)); |
| 642 | } |
| 643 | |
| 644 | /* init pins */ |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 645 | for (i = 0; i < cfg->num_inputs; i++) { |
| 646 | hda_nid_t nid = cfg->inputs[i].pin; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 647 | if (spec->smart51_enabled && is_smart51_pins(codec, nid)) |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 648 | ctl = PIN_OUT; |
David Henningsson | 3064967 | 2011-02-21 10:23:18 +0100 | [diff] [blame] | 649 | else if (cfg->inputs[i].type == AUTO_PIN_MIC) |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 650 | ctl = PIN_VREF50; |
| 651 | else |
| 652 | ctl = PIN_IN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 653 | snd_hda_codec_write(codec, nid, 0, |
Clemens Ladisch | 32e0191 | 2010-07-12 16:28:50 +0200 | [diff] [blame] | 654 | AC_VERB_SET_PIN_WIDGET_CONTROL, ctl); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 655 | } |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 656 | |
| 657 | /* init input-src */ |
| 658 | for (i = 0; i < spec->num_adc_nids; i++) { |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 659 | int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx; |
| 660 | if (spec->mux_nids[adc_idx]) { |
| 661 | int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx; |
| 662 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, |
| 663 | AC_VERB_SET_CONNECT_SEL, |
| 664 | mux_idx); |
| 665 | } |
| 666 | if (spec->dyn_adc_switch) |
| 667 | break; /* only one input-src */ |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /* init aa-mixer */ |
| 671 | if (!spec->aa_mix_nid) |
| 672 | return; |
| 673 | num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn, |
| 674 | ARRAY_SIZE(conn)); |
| 675 | for (i = 0; i < num_conns; i++) { |
| 676 | unsigned int caps = get_wcaps(codec, conn[i]); |
| 677 | if (get_wcaps_type(caps) == AC_WID_PIN) |
| 678 | snd_hda_codec_write(codec, spec->aa_mix_nid, 0, |
| 679 | AC_VERB_SET_AMP_GAIN_MUTE, |
| 680 | AMP_IN_MUTE(i)); |
| 681 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 682 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 683 | |
| 684 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, |
| 685 | unsigned int *affected_parm) |
| 686 | { |
| 687 | unsigned parm; |
| 688 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 689 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) |
| 690 | >> AC_DEFCFG_MISC_SHIFT |
| 691 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 692 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 693 | unsigned present = 0; |
| 694 | |
| 695 | no_presence |= spec->no_pin_power_ctl; |
| 696 | if (!no_presence) |
| 697 | present = snd_hda_jack_detect(codec, nid); |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 698 | if ((spec->smart51_enabled && is_smart51_pins(codec, nid)) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 699 | || ((no_presence || present) |
| 700 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 701 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
| 702 | parm = AC_PWRST_D0; |
| 703 | } else |
| 704 | parm = AC_PWRST_D3; |
| 705 | |
| 706 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); |
| 707 | } |
| 708 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 709 | static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol, |
| 710 | struct snd_ctl_elem_info *uinfo) |
| 711 | { |
| 712 | static const char * const texts[] = { |
| 713 | "Disabled", "Enabled" |
| 714 | }; |
| 715 | |
| 716 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 717 | uinfo->count = 1; |
| 718 | uinfo->value.enumerated.items = 2; |
| 719 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 720 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 721 | strcpy(uinfo->value.enumerated.name, |
| 722 | texts[uinfo->value.enumerated.item]); |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol, |
| 727 | struct snd_ctl_elem_value *ucontrol) |
| 728 | { |
| 729 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 730 | struct via_spec *spec = codec->spec; |
| 731 | ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl; |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol, |
| 736 | struct snd_ctl_elem_value *ucontrol) |
| 737 | { |
| 738 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 739 | struct via_spec *spec = codec->spec; |
| 740 | unsigned int val = !ucontrol->value.enumerated.item[0]; |
| 741 | |
| 742 | if (val == spec->no_pin_power_ctl) |
| 743 | return 0; |
| 744 | spec->no_pin_power_ctl = val; |
| 745 | set_widgets_power_state(codec); |
| 746 | return 1; |
| 747 | } |
| 748 | |
| 749 | static const struct snd_kcontrol_new via_pin_power_ctl_enum = { |
| 750 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 751 | .name = "Dynamic Power-Control", |
| 752 | .info = via_pin_power_ctl_info, |
| 753 | .get = via_pin_power_ctl_get, |
| 754 | .put = via_pin_power_ctl_put, |
| 755 | }; |
| 756 | |
| 757 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 758 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
| 759 | struct snd_ctl_elem_info *uinfo) |
| 760 | { |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 761 | static const char * const texts[] = { "OFF", "ON" }; |
| 762 | |
| 763 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 764 | uinfo->count = 1; |
| 765 | uinfo->value.enumerated.items = 2; |
| 766 | if (uinfo->value.enumerated.item >= 2) |
| 767 | uinfo->value.enumerated.item = 1; |
| 768 | strcpy(uinfo->value.enumerated.name, |
| 769 | texts[uinfo->value.enumerated.item]); |
| 770 | return 0; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, |
| 774 | struct snd_ctl_elem_value *ucontrol) |
| 775 | { |
| 776 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 777 | struct via_spec *spec = codec->spec; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 778 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 779 | ucontrol->value.enumerated.item[0] = spec->hp_independent_mode; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 780 | return 0; |
| 781 | } |
| 782 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 783 | /* adjust spec->multiout setup according to the current flags */ |
| 784 | static void setup_playback_multi_pcm(struct via_spec *spec) |
| 785 | { |
| 786 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 787 | spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums; |
| 788 | spec->multiout.hp_nid = 0; |
| 789 | if (!spec->hp_independent_mode) { |
| 790 | if (!spec->hp_indep_shared) |
| 791 | spec->multiout.hp_nid = spec->hp_dac_nid; |
| 792 | } else { |
| 793 | if (spec->hp_indep_shared) |
| 794 | spec->multiout.num_dacs = cfg->line_outs - 1; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /* update DAC setups according to indep-HP switch; |
| 799 | * this function is called only when indep-HP is modified |
| 800 | */ |
| 801 | static void switch_indep_hp_dacs(struct hda_codec *codec) |
| 802 | { |
| 803 | struct via_spec *spec = codec->spec; |
| 804 | int shared = spec->hp_indep_shared; |
| 805 | hda_nid_t shared_dac, hp_dac; |
| 806 | |
| 807 | if (!spec->opened_streams) |
| 808 | return; |
| 809 | |
| 810 | shared_dac = shared ? spec->multiout.dac_nids[shared] : 0; |
| 811 | hp_dac = spec->hp_dac_nid; |
| 812 | if (spec->hp_independent_mode) { |
| 813 | /* switch to indep-HP mode */ |
| 814 | if (spec->active_streams & STREAM_MULTI_OUT) { |
| 815 | __snd_hda_codec_cleanup_stream(codec, hp_dac, 1); |
| 816 | __snd_hda_codec_cleanup_stream(codec, shared_dac, 1); |
| 817 | } |
| 818 | if (spec->active_streams & STREAM_INDEP_HP) |
| 819 | snd_hda_codec_setup_stream(codec, hp_dac, |
| 820 | spec->cur_hp_stream_tag, 0, |
| 821 | spec->cur_hp_format); |
| 822 | } else { |
| 823 | /* back to HP or shared-DAC */ |
| 824 | if (spec->active_streams & STREAM_INDEP_HP) |
| 825 | __snd_hda_codec_cleanup_stream(codec, hp_dac, 1); |
| 826 | if (spec->active_streams & STREAM_MULTI_OUT) { |
| 827 | hda_nid_t dac; |
| 828 | int ch; |
| 829 | if (shared_dac) { /* reset mutli-ch DAC */ |
| 830 | dac = shared_dac; |
| 831 | ch = shared * 2; |
| 832 | } else { /* reset HP DAC */ |
| 833 | dac = hp_dac; |
| 834 | ch = 0; |
| 835 | } |
| 836 | snd_hda_codec_setup_stream(codec, dac, |
| 837 | spec->cur_dac_stream_tag, ch, |
| 838 | spec->cur_dac_format); |
| 839 | } |
| 840 | } |
| 841 | setup_playback_multi_pcm(spec); |
| 842 | } |
| 843 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 844 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
| 845 | struct snd_ctl_elem_value *ucontrol) |
| 846 | { |
| 847 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 848 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 849 | int cur, shared; |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 850 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 851 | mutex_lock(&spec->config_mutex); |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 852 | cur = !!ucontrol->value.enumerated.item[0]; |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 853 | if (spec->hp_independent_mode == cur) { |
| 854 | mutex_unlock(&spec->config_mutex); |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 855 | return 0; |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 856 | } |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 857 | spec->hp_independent_mode = cur; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 858 | shared = spec->hp_indep_shared; |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 859 | deactivate_hp_paths(codec); |
| 860 | if (cur) |
| 861 | activate_output_path(codec, &spec->hp_indep_path, true, false); |
| 862 | else { |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 863 | if (shared) |
| 864 | activate_output_path(codec, &spec->out_path[shared], |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 865 | true, false); |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 866 | if (spec->aamix_mode || !spec->hp_path.depth) |
| 867 | activate_output_path(codec, &spec->hp_mix_path, |
| 868 | true, false); |
| 869 | else |
| 870 | activate_output_path(codec, &spec->hp_path, |
| 871 | true, false); |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 872 | } |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 873 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 874 | switch_indep_hp_dacs(codec); |
| 875 | mutex_unlock(&spec->config_mutex); |
| 876 | |
Lydia Wang | ce0e5a9 | 2011-03-22 16:22:37 +0800 | [diff] [blame] | 877 | /* update jack power state */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 878 | set_widgets_power_state(codec); |
Takashi Iwai | 6e969d9 | 2011-07-11 11:28:13 +0200 | [diff] [blame] | 879 | via_hp_automute(codec); |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 880 | return 1; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 881 | } |
| 882 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 883 | static const struct snd_kcontrol_new via_hp_mixer = { |
| 884 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 885 | .name = "Independent HP", |
| 886 | .info = via_independent_hp_info, |
| 887 | .get = via_independent_hp_get, |
| 888 | .put = via_independent_hp_put, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 889 | }; |
| 890 | |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 891 | static int via_hp_build(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 892 | { |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 893 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 894 | struct snd_kcontrol_new *knew; |
| 895 | hda_nid_t nid; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 896 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 897 | nid = spec->autocfg.hp_pins[0]; |
| 898 | knew = via_clone_control(spec, &via_hp_mixer); |
Takashi Iwai | 3d83e57 | 2010-04-14 14:36:23 +0200 | [diff] [blame] | 899 | if (knew == NULL) |
| 900 | return -ENOMEM; |
| 901 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 902 | knew->subdevice = HDA_SUBDEV_NID_FLAG | nid; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 903 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 904 | return 0; |
| 905 | } |
| 906 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 907 | static void notify_aa_path_ctls(struct hda_codec *codec) |
| 908 | { |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 909 | struct via_spec *spec = codec->spec; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 910 | int i; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 911 | |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 912 | for (i = 0; i < spec->smart51_nums; i++) { |
| 913 | struct snd_kcontrol *ctl; |
| 914 | struct snd_ctl_elem_id id; |
| 915 | memset(&id, 0, sizeof(id)); |
| 916 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 917 | sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]); |
Lydia Wang | 525566c | 2011-04-28 16:03:39 +0800 | [diff] [blame] | 918 | ctl = snd_hda_find_mixer_ctl(codec, id.name); |
| 919 | if (ctl) |
| 920 | snd_ctl_notify(codec->bus->card, |
| 921 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 922 | &ctl->id); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
| 926 | static void mute_aa_path(struct hda_codec *codec, int mute) |
| 927 | { |
| 928 | struct via_spec *spec = codec->spec; |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 929 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 930 | int i; |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 931 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 932 | /* check AA path's mute status */ |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 933 | for (i = 0; i < spec->smart51_nums; i++) { |
| 934 | if (spec->smart51_idxs[i] < 0) |
| 935 | continue; |
| 936 | snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid, |
| 937 | HDA_INPUT, spec->smart51_idxs[i], |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 938 | HDA_AMP_MUTE, val); |
| 939 | } |
| 940 | } |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 941 | |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 942 | static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin) |
| 943 | { |
| 944 | struct via_spec *spec = codec->spec; |
| 945 | int i; |
| 946 | |
| 947 | for (i = 0; i < spec->smart51_nums; i++) |
| 948 | if (spec->smart51_pins[i] == pin) |
| 949 | return true; |
| 950 | return false; |
| 951 | } |
| 952 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 953 | static int via_smart51_get(struct snd_kcontrol *kcontrol, |
| 954 | struct snd_ctl_elem_value *ucontrol) |
| 955 | { |
| 956 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 957 | struct via_spec *spec = codec->spec; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 958 | |
Takashi Iwai | f2b1c9f | 2011-06-21 16:52:39 +0200 | [diff] [blame] | 959 | *ucontrol->value.integer.value = spec->smart51_enabled; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | static int via_smart51_put(struct snd_kcontrol *kcontrol, |
| 964 | struct snd_ctl_elem_value *ucontrol) |
| 965 | { |
| 966 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 967 | struct via_spec *spec = codec->spec; |
| 968 | int out_in = *ucontrol->value.integer.value |
| 969 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 970 | int i; |
| 971 | |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 972 | for (i = 0; i < spec->smart51_nums; i++) { |
| 973 | hda_nid_t nid = spec->smart51_pins[i]; |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 974 | unsigned int parm; |
| 975 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 976 | parm = snd_hda_codec_read(codec, nid, 0, |
| 977 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 978 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); |
| 979 | parm |= out_in; |
| 980 | snd_hda_codec_write(codec, nid, 0, |
| 981 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 982 | parm); |
| 983 | if (out_in == AC_PINCTL_OUT_EN) { |
| 984 | mute_aa_path(codec, 1); |
| 985 | notify_aa_path_ctls(codec); |
| 986 | } |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 987 | } |
| 988 | spec->smart51_enabled = *ucontrol->value.integer.value; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 989 | set_widgets_power_state(codec); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 990 | return 1; |
| 991 | } |
| 992 | |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 993 | static const struct snd_kcontrol_new via_smart51_mixer = { |
| 994 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 995 | .name = "Smart 5.1", |
| 996 | .count = 1, |
Takashi Iwai | f2b1c9f | 2011-06-21 16:52:39 +0200 | [diff] [blame] | 997 | .info = snd_ctl_boolean_mono_info, |
Takashi Iwai | 5f4b36d | 2011-06-17 14:55:02 +0200 | [diff] [blame] | 998 | .get = via_smart51_get, |
| 999 | .put = via_smart51_put, |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1000 | }; |
| 1001 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1002 | static int via_smart51_build(struct hda_codec *codec) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1003 | { |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1004 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1005 | |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 1006 | if (!spec->smart51_nums) |
Lydia Wang | cb34c20 | 2011-04-27 17:44:16 +0800 | [diff] [blame] | 1007 | return 0; |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 1008 | if (!via_clone_control(spec, &via_smart51_mixer)) |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1009 | return -ENOMEM; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1010 | return 0; |
| 1011 | } |
| 1012 | |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1013 | /* check AA path's mute status */ |
| 1014 | static bool is_aa_path_mute(struct hda_codec *codec) |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1015 | { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1016 | struct via_spec *spec = codec->spec; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1017 | const struct hda_amp_list *p; |
| 1018 | int i, ch, v; |
| 1019 | |
| 1020 | for (i = 0; i < spec->num_loopbacks; i++) { |
| 1021 | p = &spec->loopback_list[i]; |
| 1022 | for (ch = 0; ch < 2; ch++) { |
| 1023 | v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir, |
| 1024 | p->idx); |
| 1025 | if (!(v & HDA_AMP_MUTE) && v > 0) |
| 1026 | return false; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1027 | } |
| 1028 | } |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1029 | return true; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /* enter/exit analog low-current mode */ |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1033 | static void analog_low_current_mode(struct hda_codec *codec) |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1034 | { |
| 1035 | struct via_spec *spec = codec->spec; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1036 | bool enable; |
| 1037 | unsigned int verb, parm; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1038 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1039 | enable = is_aa_path_mute(codec) && (spec->opened_streams != 0); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1040 | |
| 1041 | /* decide low current mode's verb & parameter */ |
| 1042 | switch (spec->codec_type) { |
| 1043 | case VT1708B_8CH: |
| 1044 | case VT1708B_4CH: |
| 1045 | verb = 0xf70; |
| 1046 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ |
| 1047 | break; |
| 1048 | case VT1708S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1049 | case VT1718S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1050 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1051 | verb = 0xf73; |
| 1052 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ |
| 1053 | break; |
| 1054 | case VT1702: |
| 1055 | verb = 0xf73; |
| 1056 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ |
| 1057 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1058 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1059 | case VT1812: |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 1060 | case VT1802: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1061 | verb = 0xf93; |
| 1062 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 1063 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1064 | default: |
| 1065 | return; /* other codecs are not supported */ |
| 1066 | } |
| 1067 | /* send verb */ |
| 1068 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); |
| 1069 | } |
| 1070 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1071 | /* |
| 1072 | * generic initialization of ADC, input mixers and output mixers |
| 1073 | */ |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 1074 | static const struct hda_verb vt1708_init_verbs[] = { |
Lydia Wang | aa266fc | 2011-03-24 12:41:01 +0800 | [diff] [blame] | 1075 | /* power down jack detect function */ |
| 1076 | {0x1, 0xf81, 0x1}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1077 | { } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1078 | }; |
| 1079 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1080 | static void set_stream_open(struct hda_codec *codec, int bit, bool active) |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1081 | { |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1082 | struct via_spec *spec = codec->spec; |
| 1083 | |
| 1084 | if (active) |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1085 | spec->opened_streams |= bit; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1086 | else |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1087 | spec->opened_streams &= ~bit; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1088 | analog_low_current_mode(codec); |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1091 | static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1092 | struct hda_codec *codec, |
| 1093 | struct snd_pcm_substream *substream) |
| 1094 | { |
| 1095 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 1096 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1097 | int err; |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1098 | |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 1099 | spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums; |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 1100 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1101 | set_stream_open(codec, STREAM_MULTI_OUT, true); |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1102 | err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 1103 | hinfo); |
| 1104 | if (err < 0) { |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1105 | set_stream_open(codec, STREAM_MULTI_OUT, false); |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1106 | return err; |
| 1107 | } |
| 1108 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1109 | } |
| 1110 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1111 | static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1112 | struct hda_codec *codec, |
| 1113 | struct snd_pcm_substream *substream) |
| 1114 | { |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1115 | set_stream_open(codec, STREAM_MULTI_OUT, false); |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1116 | return 0; |
| 1117 | } |
| 1118 | |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1119 | static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo, |
| 1120 | struct hda_codec *codec, |
| 1121 | struct snd_pcm_substream *substream) |
| 1122 | { |
| 1123 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1124 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1125 | if (snd_BUG_ON(!spec->hp_dac_nid)) |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1126 | return -EINVAL; |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1127 | set_stream_open(codec, STREAM_INDEP_HP, true); |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1128 | return 0; |
| 1129 | } |
| 1130 | |
| 1131 | static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo, |
| 1132 | struct hda_codec *codec, |
| 1133 | struct snd_pcm_substream *substream) |
| 1134 | { |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1135 | set_stream_open(codec, STREAM_INDEP_HP, false); |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1140 | struct hda_codec *codec, |
| 1141 | unsigned int stream_tag, |
| 1142 | unsigned int format, |
| 1143 | struct snd_pcm_substream *substream) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1144 | { |
| 1145 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1146 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1147 | mutex_lock(&spec->config_mutex); |
| 1148 | setup_playback_multi_pcm(spec); |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1149 | snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, |
| 1150 | format, substream); |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1151 | /* remember for dynamic DAC switch with indep-HP */ |
| 1152 | spec->active_streams |= STREAM_MULTI_OUT; |
| 1153 | spec->cur_dac_stream_tag = stream_tag; |
| 1154 | spec->cur_dac_format = format; |
| 1155 | mutex_unlock(&spec->config_mutex); |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1156 | vt1708_start_hp_work(spec); |
| 1157 | return 0; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1158 | } |
| 1159 | |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1160 | static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1161 | struct hda_codec *codec, |
| 1162 | unsigned int stream_tag, |
| 1163 | unsigned int format, |
| 1164 | struct snd_pcm_substream *substream) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1165 | { |
| 1166 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1167 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1168 | mutex_lock(&spec->config_mutex); |
| 1169 | if (spec->hp_independent_mode) |
| 1170 | snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, |
| 1171 | stream_tag, 0, format); |
| 1172 | spec->active_streams |= STREAM_INDEP_HP; |
| 1173 | spec->cur_hp_stream_tag = stream_tag; |
| 1174 | spec->cur_hp_format = format; |
| 1175 | mutex_unlock(&spec->config_mutex); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1176 | vt1708_start_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1181 | struct hda_codec *codec, |
| 1182 | struct snd_pcm_substream *substream) |
| 1183 | { |
| 1184 | struct via_spec *spec = codec->spec; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1185 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1186 | mutex_lock(&spec->config_mutex); |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1187 | snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1188 | spec->active_streams &= ~STREAM_MULTI_OUT; |
| 1189 | mutex_unlock(&spec->config_mutex); |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1190 | vt1708_stop_hp_work(spec); |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1195 | struct hda_codec *codec, |
| 1196 | struct snd_pcm_substream *substream) |
| 1197 | { |
| 1198 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1199 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1200 | mutex_lock(&spec->config_mutex); |
| 1201 | if (spec->hp_independent_mode) |
| 1202 | snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0); |
| 1203 | spec->active_streams &= ~STREAM_INDEP_HP; |
| 1204 | mutex_unlock(&spec->config_mutex); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1205 | vt1708_stop_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1206 | return 0; |
| 1207 | } |
| 1208 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1209 | /* |
| 1210 | * Digital out |
| 1211 | */ |
| 1212 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1213 | struct hda_codec *codec, |
| 1214 | struct snd_pcm_substream *substream) |
| 1215 | { |
| 1216 | struct via_spec *spec = codec->spec; |
| 1217 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 1218 | } |
| 1219 | |
| 1220 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 1221 | struct hda_codec *codec, |
| 1222 | struct snd_pcm_substream *substream) |
| 1223 | { |
| 1224 | struct via_spec *spec = codec->spec; |
| 1225 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 1226 | } |
| 1227 | |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1228 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1229 | struct hda_codec *codec, |
| 1230 | unsigned int stream_tag, |
| 1231 | unsigned int format, |
| 1232 | struct snd_pcm_substream *substream) |
| 1233 | { |
| 1234 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1235 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 1236 | stream_tag, format, substream); |
| 1237 | } |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1238 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1239 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1240 | struct hda_codec *codec, |
| 1241 | struct snd_pcm_substream *substream) |
| 1242 | { |
| 1243 | struct via_spec *spec = codec->spec; |
| 1244 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1245 | return 0; |
| 1246 | } |
| 1247 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1248 | /* |
| 1249 | * Analog capture |
| 1250 | */ |
| 1251 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1252 | struct hda_codec *codec, |
| 1253 | unsigned int stream_tag, |
| 1254 | unsigned int format, |
| 1255 | struct snd_pcm_substream *substream) |
| 1256 | { |
| 1257 | struct via_spec *spec = codec->spec; |
| 1258 | |
| 1259 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 1260 | stream_tag, 0, format); |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
| 1264 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1265 | struct hda_codec *codec, |
| 1266 | struct snd_pcm_substream *substream) |
| 1267 | { |
| 1268 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1269 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1270 | return 0; |
| 1271 | } |
| 1272 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1273 | /* analog capture with dynamic ADC switching */ |
| 1274 | static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1275 | struct hda_codec *codec, |
| 1276 | unsigned int stream_tag, |
| 1277 | unsigned int format, |
| 1278 | struct snd_pcm_substream *substream) |
| 1279 | { |
| 1280 | struct via_spec *spec = codec->spec; |
| 1281 | int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx; |
| 1282 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1283 | mutex_lock(&spec->config_mutex); |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1284 | spec->cur_adc = spec->adc_nids[adc_idx]; |
| 1285 | spec->cur_adc_stream_tag = stream_tag; |
| 1286 | spec->cur_adc_format = format; |
| 1287 | snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format); |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1288 | mutex_unlock(&spec->config_mutex); |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1293 | struct hda_codec *codec, |
| 1294 | struct snd_pcm_substream *substream) |
| 1295 | { |
| 1296 | struct via_spec *spec = codec->spec; |
| 1297 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1298 | mutex_lock(&spec->config_mutex); |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1299 | snd_hda_codec_cleanup_stream(codec, spec->cur_adc); |
| 1300 | spec->cur_adc = 0; |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1301 | mutex_unlock(&spec->config_mutex); |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1302 | return 0; |
| 1303 | } |
| 1304 | |
| 1305 | /* re-setup the stream if running; called from input-src put */ |
| 1306 | static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur) |
| 1307 | { |
| 1308 | struct via_spec *spec = codec->spec; |
| 1309 | int adc_idx = spec->inputs[cur].adc_idx; |
| 1310 | hda_nid_t adc = spec->adc_nids[adc_idx]; |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1311 | bool ret = false; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1312 | |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1313 | mutex_lock(&spec->config_mutex); |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1314 | if (spec->cur_adc && spec->cur_adc != adc) { |
| 1315 | /* stream is running, let's swap the current ADC */ |
| 1316 | __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1); |
| 1317 | spec->cur_adc = adc; |
| 1318 | snd_hda_codec_setup_stream(codec, adc, |
| 1319 | spec->cur_adc_stream_tag, 0, |
| 1320 | spec->cur_adc_format); |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1321 | ret = true; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1322 | } |
Takashi Iwai | 3b607e3 | 2011-07-18 16:54:40 +0200 | [diff] [blame] | 1323 | mutex_unlock(&spec->config_mutex); |
| 1324 | return ret; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1325 | } |
| 1326 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1327 | static const struct hda_pcm_stream via_pcm_analog_playback = { |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1328 | .substreams = 1, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1329 | .channels_min = 2, |
| 1330 | .channels_max = 8, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1331 | /* NID is set in via_build_pcms */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1332 | .ops = { |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1333 | .open = via_playback_multi_pcm_open, |
| 1334 | .close = via_playback_multi_pcm_close, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1335 | .prepare = via_playback_multi_pcm_prepare, |
| 1336 | .cleanup = via_playback_multi_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1337 | }, |
| 1338 | }; |
| 1339 | |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1340 | static const struct hda_pcm_stream via_pcm_hp_playback = { |
| 1341 | .substreams = 1, |
| 1342 | .channels_min = 2, |
| 1343 | .channels_max = 2, |
| 1344 | /* NID is set in via_build_pcms */ |
| 1345 | .ops = { |
| 1346 | .open = via_playback_hp_pcm_open, |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1347 | .close = via_playback_hp_pcm_close, |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1348 | .prepare = via_playback_hp_pcm_prepare, |
| 1349 | .cleanup = via_playback_hp_pcm_cleanup |
| 1350 | }, |
| 1351 | }; |
| 1352 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1353 | static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1354 | .substreams = 1, |
Takashi Iwai | bc9b562 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1355 | .channels_min = 2, |
| 1356 | .channels_max = 8, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1357 | /* NID is set in via_build_pcms */ |
Takashi Iwai | bc9b562 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1358 | /* We got noisy outputs on the right channel on VT1708 when |
| 1359 | * 24bit samples are used. Until any workaround is found, |
| 1360 | * disable the 24bit format, so far. |
| 1361 | */ |
| 1362 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1363 | .ops = { |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1364 | .open = via_playback_multi_pcm_open, |
| 1365 | .close = via_playback_multi_pcm_close, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1366 | .prepare = via_playback_multi_pcm_prepare, |
| 1367 | .cleanup = via_playback_multi_pcm_cleanup |
Takashi Iwai | bc9b562 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1368 | }, |
| 1369 | }; |
| 1370 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1371 | static const struct hda_pcm_stream via_pcm_analog_capture = { |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1372 | .substreams = 1, /* will be changed in via_build_pcms() */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1373 | .channels_min = 2, |
| 1374 | .channels_max = 2, |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1375 | /* NID is set in via_build_pcms */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1376 | .ops = { |
| 1377 | .prepare = via_capture_pcm_prepare, |
| 1378 | .cleanup = via_capture_pcm_cleanup |
| 1379 | }, |
| 1380 | }; |
| 1381 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1382 | static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = { |
| 1383 | .substreams = 1, |
| 1384 | .channels_min = 2, |
| 1385 | .channels_max = 2, |
| 1386 | /* NID is set in via_build_pcms */ |
| 1387 | .ops = { |
| 1388 | .prepare = via_dyn_adc_capture_pcm_prepare, |
| 1389 | .cleanup = via_dyn_adc_capture_pcm_cleanup, |
| 1390 | }, |
| 1391 | }; |
| 1392 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1393 | static const struct hda_pcm_stream via_pcm_digital_playback = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1394 | .substreams = 1, |
| 1395 | .channels_min = 2, |
| 1396 | .channels_max = 2, |
| 1397 | /* NID is set in via_build_pcms */ |
| 1398 | .ops = { |
| 1399 | .open = via_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 1400 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1401 | .prepare = via_dig_playback_pcm_prepare, |
| 1402 | .cleanup = via_dig_playback_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1403 | }, |
| 1404 | }; |
| 1405 | |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1406 | static const struct hda_pcm_stream via_pcm_digital_capture = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1407 | .substreams = 1, |
| 1408 | .channels_min = 2, |
| 1409 | .channels_max = 2, |
| 1410 | }; |
| 1411 | |
Takashi Iwai | 370bafb | 2011-06-20 12:47:45 +0200 | [diff] [blame] | 1412 | /* |
| 1413 | * slave controls for virtual master |
| 1414 | */ |
| 1415 | static const char * const via_slave_vols[] = { |
| 1416 | "Front Playback Volume", |
| 1417 | "Surround Playback Volume", |
| 1418 | "Center Playback Volume", |
| 1419 | "LFE Playback Volume", |
| 1420 | "Side Playback Volume", |
| 1421 | "Headphone Playback Volume", |
| 1422 | "Speaker Playback Volume", |
| 1423 | NULL, |
| 1424 | }; |
| 1425 | |
| 1426 | static const char * const via_slave_sws[] = { |
| 1427 | "Front Playback Switch", |
| 1428 | "Surround Playback Switch", |
| 1429 | "Center Playback Switch", |
| 1430 | "LFE Playback Switch", |
| 1431 | "Side Playback Switch", |
| 1432 | "Headphone Playback Switch", |
| 1433 | "Speaker Playback Switch", |
| 1434 | NULL, |
| 1435 | }; |
| 1436 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1437 | static int via_build_controls(struct hda_codec *codec) |
| 1438 | { |
| 1439 | struct via_spec *spec = codec->spec; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1440 | struct snd_kcontrol *kctl; |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1441 | int err, i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1442 | |
Takashi Iwai | 24088a5 | 2011-06-17 16:59:21 +0200 | [diff] [blame] | 1443 | if (spec->set_widgets_power_state) |
| 1444 | if (!via_clone_control(spec, &via_pin_power_ctl_enum)) |
| 1445 | return -ENOMEM; |
| 1446 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1447 | for (i = 0; i < spec->num_mixers; i++) { |
| 1448 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1449 | if (err < 0) |
| 1450 | return err; |
| 1451 | } |
| 1452 | |
| 1453 | if (spec->multiout.dig_out_nid) { |
| 1454 | err = snd_hda_create_spdif_out_ctls(codec, |
Stephen Warren | 74b654c | 2011-06-01 11:14:18 -0600 | [diff] [blame] | 1455 | spec->multiout.dig_out_nid, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1456 | spec->multiout.dig_out_nid); |
| 1457 | if (err < 0) |
| 1458 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1459 | err = snd_hda_create_spdif_share_sw(codec, |
| 1460 | &spec->multiout); |
| 1461 | if (err < 0) |
| 1462 | return err; |
| 1463 | spec->multiout.share_spdif = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1464 | } |
| 1465 | if (spec->dig_in_nid) { |
| 1466 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1467 | if (err < 0) |
| 1468 | return err; |
| 1469 | } |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1470 | |
Takashi Iwai | 370bafb | 2011-06-20 12:47:45 +0200 | [diff] [blame] | 1471 | /* if we have no master control, let's create it */ |
| 1472 | if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { |
| 1473 | unsigned int vmaster_tlv[4]; |
| 1474 | snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0], |
| 1475 | HDA_OUTPUT, vmaster_tlv); |
| 1476 | err = snd_hda_add_vmaster(codec, "Master Playback Volume", |
| 1477 | vmaster_tlv, via_slave_vols); |
| 1478 | if (err < 0) |
| 1479 | return err; |
| 1480 | } |
| 1481 | if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { |
| 1482 | err = snd_hda_add_vmaster(codec, "Master Playback Switch", |
| 1483 | NULL, via_slave_sws); |
| 1484 | if (err < 0) |
| 1485 | return err; |
| 1486 | } |
| 1487 | |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1488 | /* assign Capture Source enums to NID */ |
| 1489 | kctl = snd_hda_find_mixer_ctl(codec, "Input Source"); |
| 1490 | for (i = 0; kctl && i < kctl->count; i++) { |
Takashi Iwai | 21949f0 | 2009-12-23 08:31:59 +0100 | [diff] [blame] | 1491 | err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]); |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 1492 | if (err < 0) |
| 1493 | return err; |
| 1494 | } |
| 1495 | |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1496 | /* init power states */ |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1497 | set_widgets_power_state(codec); |
Takashi Iwai | ada509e | 2011-06-20 15:40:19 +0200 | [diff] [blame] | 1498 | analog_low_current_mode(codec); |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1499 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1500 | via_free_kctls(codec); /* no longer needed */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | static int via_build_pcms(struct hda_codec *codec) |
| 1505 | { |
| 1506 | struct via_spec *spec = codec->spec; |
| 1507 | struct hda_pcm *info = spec->pcm_rec; |
| 1508 | |
| 1509 | codec->num_pcms = 1; |
| 1510 | codec->pcm_info = info; |
| 1511 | |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 1512 | snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), |
| 1513 | "%s Analog", codec->chip_name); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1514 | info->name = spec->stream_name_analog; |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1515 | |
| 1516 | if (!spec->stream_analog_playback) |
| 1517 | spec->stream_analog_playback = &via_pcm_analog_playback; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1518 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1519 | *spec->stream_analog_playback; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1520 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1521 | spec->multiout.dac_nids[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1522 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 1523 | spec->multiout.max_channels; |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1524 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1525 | if (!spec->stream_analog_capture) { |
| 1526 | if (spec->dyn_adc_switch) |
| 1527 | spec->stream_analog_capture = |
| 1528 | &via_pcm_dyn_adc_analog_capture; |
| 1529 | else |
| 1530 | spec->stream_analog_capture = &via_pcm_analog_capture; |
| 1531 | } |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1532 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 1533 | *spec->stream_analog_capture; |
| 1534 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1535 | if (!spec->dyn_adc_switch) |
| 1536 | info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = |
| 1537 | spec->num_adc_nids; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1538 | |
| 1539 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
| 1540 | codec->num_pcms++; |
| 1541 | info++; |
Takashi Iwai | 82673bc | 2011-06-17 16:24:21 +0200 | [diff] [blame] | 1542 | snprintf(spec->stream_name_digital, |
| 1543 | sizeof(spec->stream_name_digital), |
| 1544 | "%s Digital", codec->chip_name); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1545 | info->name = spec->stream_name_digital; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 1546 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1547 | if (spec->multiout.dig_out_nid) { |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1548 | if (!spec->stream_digital_playback) |
| 1549 | spec->stream_digital_playback = |
| 1550 | &via_pcm_digital_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1551 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1552 | *spec->stream_digital_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1553 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1554 | spec->multiout.dig_out_nid; |
| 1555 | } |
| 1556 | if (spec->dig_in_nid) { |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1557 | if (!spec->stream_digital_capture) |
| 1558 | spec->stream_digital_capture = |
| 1559 | &via_pcm_digital_capture; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1560 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
Takashi Iwai | 9af7421 | 2011-06-18 16:17:45 +0200 | [diff] [blame] | 1561 | *spec->stream_digital_capture; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1562 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 1563 | spec->dig_in_nid; |
| 1564 | } |
| 1565 | } |
| 1566 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1567 | if (spec->hp_dac_nid) { |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1568 | codec->num_pcms++; |
| 1569 | info++; |
| 1570 | snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp), |
| 1571 | "%s HP", codec->chip_name); |
| 1572 | info->name = spec->stream_name_hp; |
| 1573 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback; |
| 1574 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1575 | spec->hp_dac_nid; |
Takashi Iwai | 7eb56e8 | 2011-06-18 16:40:14 +0200 | [diff] [blame] | 1576 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | static void via_free(struct hda_codec *codec) |
| 1581 | { |
| 1582 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1583 | |
| 1584 | if (!spec) |
| 1585 | return; |
| 1586 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1587 | via_free_kctls(codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1588 | vt1708_stop_hp_work(spec); |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 1589 | kfree(spec->bind_cap_vol); |
| 1590 | kfree(spec->bind_cap_sw); |
| 1591 | kfree(spec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1592 | } |
| 1593 | |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1594 | /* mute/unmute outputs */ |
| 1595 | static void toggle_output_mutes(struct hda_codec *codec, int num_pins, |
| 1596 | hda_nid_t *pins, bool mute) |
| 1597 | { |
| 1598 | int i; |
Takashi Iwai | 9499473 | 2011-07-11 11:36:44 +0200 | [diff] [blame] | 1599 | for (i = 0; i < num_pins; i++) { |
| 1600 | unsigned int parm = snd_hda_codec_read(codec, pins[i], 0, |
| 1601 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 1602 | if (parm & AC_PINCTL_IN_EN) |
| 1603 | continue; |
| 1604 | if (mute) |
| 1605 | parm &= ~AC_PINCTL_OUT_EN; |
| 1606 | else |
| 1607 | parm |= AC_PINCTL_OUT_EN; |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1608 | snd_hda_codec_write(codec, pins[i], 0, |
Takashi Iwai | 9499473 | 2011-07-11 11:36:44 +0200 | [diff] [blame] | 1609 | AC_VERB_SET_PIN_WIDGET_CONTROL, parm); |
| 1610 | } |
Takashi Iwai | 64be285 | 2011-06-17 16:51:39 +0200 | [diff] [blame] | 1611 | } |
| 1612 | |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 1613 | /* mute internal speaker if line-out is plugged */ |
| 1614 | static void via_line_automute(struct hda_codec *codec, int present) |
| 1615 | { |
| 1616 | struct via_spec *spec = codec->spec; |
| 1617 | |
| 1618 | if (!spec->autocfg.speaker_outs) |
| 1619 | return; |
| 1620 | if (!present) |
| 1621 | present = snd_hda_jack_detect(codec, |
| 1622 | spec->autocfg.line_out_pins[0]); |
| 1623 | toggle_output_mutes(codec, spec->autocfg.speaker_outs, |
| 1624 | spec->autocfg.speaker_pins, |
| 1625 | present); |
| 1626 | } |
| 1627 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1628 | /* mute internal speaker if HP is plugged */ |
| 1629 | static void via_hp_automute(struct hda_codec *codec) |
| 1630 | { |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 1631 | int present = 0; |
Takashi Iwai | 6e969d9 | 2011-07-11 11:28:13 +0200 | [diff] [blame] | 1632 | int nums; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1633 | struct via_spec *spec = codec->spec; |
| 1634 | |
Takashi Iwai | 6e969d9 | 2011-07-11 11:28:13 +0200 | [diff] [blame] | 1635 | if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 1636 | present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); |
Takashi Iwai | 6e969d9 | 2011-07-11 11:28:13 +0200 | [diff] [blame] | 1637 | |
| 1638 | if (spec->smart51_enabled) |
| 1639 | nums = spec->autocfg.line_outs + spec->smart51_nums; |
| 1640 | else |
| 1641 | nums = spec->autocfg.line_outs; |
| 1642 | toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present); |
| 1643 | |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 1644 | via_line_automute(codec, present); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1645 | } |
| 1646 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1647 | static void via_gpio_control(struct hda_codec *codec) |
| 1648 | { |
| 1649 | unsigned int gpio_data; |
| 1650 | unsigned int vol_counter; |
| 1651 | unsigned int vol; |
| 1652 | unsigned int master_vol; |
| 1653 | |
| 1654 | struct via_spec *spec = codec->spec; |
| 1655 | |
| 1656 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, |
| 1657 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; |
| 1658 | |
| 1659 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, |
| 1660 | 0xF84, 0) & 0x3F0000) >> 16; |
| 1661 | |
| 1662 | vol = vol_counter & 0x1F; |
| 1663 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, |
| 1664 | AC_VERB_GET_AMP_GAIN_MUTE, |
| 1665 | AC_AMP_GET_INPUT); |
| 1666 | |
| 1667 | if (gpio_data == 0x02) { |
| 1668 | /* unmute line out */ |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1669 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
| 1670 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1671 | PIN_OUT); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1672 | if (vol_counter & 0x20) { |
| 1673 | /* decrease volume */ |
| 1674 | if (vol > master_vol) |
| 1675 | vol = master_vol; |
| 1676 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, |
| 1677 | 0, HDA_AMP_VOLMASK, |
| 1678 | master_vol-vol); |
| 1679 | } else { |
| 1680 | /* increase volume */ |
| 1681 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, |
| 1682 | HDA_AMP_VOLMASK, |
| 1683 | ((master_vol+vol) > 0x2A) ? 0x2A : |
| 1684 | (master_vol+vol)); |
| 1685 | } |
| 1686 | } else if (!(gpio_data & 0x02)) { |
| 1687 | /* mute line out */ |
Takashi Iwai | 3e0693e | 2011-06-17 16:37:45 +0200 | [diff] [blame] | 1688 | snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0, |
| 1689 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1690 | 0); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | /* unsolicited event for jack sensing */ |
| 1695 | static void via_unsol_event(struct hda_codec *codec, |
| 1696 | unsigned int res) |
| 1697 | { |
| 1698 | res >>= 26; |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1699 | |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 1700 | if (res & VIA_JACK_EVENT) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 1701 | set_widgets_power_state(codec); |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1702 | |
| 1703 | res &= ~VIA_JACK_EVENT; |
| 1704 | |
Takashi Iwai | 21ce0b6 | 2011-07-11 10:33:47 +0200 | [diff] [blame] | 1705 | if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT) |
Lydia Wang | ec7e7e4 | 2011-03-24 12:43:44 +0800 | [diff] [blame] | 1706 | via_hp_automute(codec); |
| 1707 | else if (res == VIA_GPIO_EVENT) |
| 1708 | via_gpio_control(codec); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1709 | } |
| 1710 | |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 1711 | #ifdef CONFIG_PM |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1712 | static int via_suspend(struct hda_codec *codec, pm_message_t state) |
| 1713 | { |
| 1714 | struct via_spec *spec = codec->spec; |
| 1715 | vt1708_stop_hp_work(spec); |
| 1716 | return 0; |
| 1717 | } |
| 1718 | #endif |
| 1719 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1720 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1721 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 1722 | { |
| 1723 | struct via_spec *spec = codec->spec; |
| 1724 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 1725 | } |
| 1726 | #endif |
| 1727 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1728 | /* |
| 1729 | */ |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 1730 | |
| 1731 | static int via_init(struct hda_codec *codec); |
| 1732 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 1733 | static const struct hda_codec_ops via_patch_ops = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1734 | .build_controls = via_build_controls, |
| 1735 | .build_pcms = via_build_pcms, |
| 1736 | .init = via_init, |
| 1737 | .free = via_free, |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 1738 | .unsol_event = via_unsol_event, |
Takashi Iwai | 2a43952 | 2011-07-26 09:52:50 +0200 | [diff] [blame] | 1739 | #ifdef CONFIG_PM |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1740 | .suspend = via_suspend, |
| 1741 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 1742 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 1743 | .check_power_status = via_check_power_status, |
| 1744 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1745 | }; |
| 1746 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1747 | static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1748 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1749 | struct via_spec *spec = codec->spec; |
| 1750 | int i; |
| 1751 | |
| 1752 | for (i = 0; i < spec->multiout.num_dacs; i++) { |
| 1753 | if (spec->multiout.dac_nids[i] == dac) |
| 1754 | return false; |
| 1755 | } |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 1756 | if (spec->hp_dac_nid == dac) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1757 | return false; |
| 1758 | return true; |
| 1759 | } |
| 1760 | |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 1761 | static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1762 | hda_nid_t target_dac, int with_aa_mix, |
| 1763 | struct nid_path *path, int depth) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1764 | { |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1765 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1766 | hda_nid_t conn[8]; |
| 1767 | int i, nums; |
| 1768 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1769 | if (nid == spec->aa_mix_nid) { |
| 1770 | if (!with_aa_mix) |
| 1771 | return false; |
| 1772 | with_aa_mix = 2; /* mark aa-mix is included */ |
| 1773 | } |
| 1774 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1775 | nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn)); |
| 1776 | for (i = 0; i < nums; i++) { |
| 1777 | if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT) |
| 1778 | continue; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1779 | if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) { |
| 1780 | /* aa-mix is requested but not included? */ |
| 1781 | if (!(spec->aa_mix_nid && with_aa_mix == 1)) |
| 1782 | goto found; |
| 1783 | } |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1784 | } |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 1785 | if (depth >= MAX_NID_PATH_DEPTH) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1786 | return false; |
| 1787 | for (i = 0; i < nums; i++) { |
| 1788 | unsigned int type; |
| 1789 | type = get_wcaps_type(get_wcaps(codec, conn[i])); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1790 | if (type == AC_WID_AUD_OUT) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1791 | continue; |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 1792 | if (__parse_output_path(codec, conn[i], target_dac, |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1793 | with_aa_mix, path, depth + 1)) |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 1794 | goto found; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1795 | } |
| 1796 | return false; |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 1797 | |
| 1798 | found: |
| 1799 | path->path[path->depth] = conn[i]; |
| 1800 | path->idx[path->depth] = i; |
| 1801 | if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX) |
| 1802 | path->multi[path->depth] = 1; |
| 1803 | path->depth++; |
| 1804 | return true; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1805 | } |
| 1806 | |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 1807 | static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid, |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1808 | hda_nid_t target_dac, int with_aa_mix, |
| 1809 | struct nid_path *path) |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 1810 | { |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1811 | if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) { |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 1812 | path->path[path->depth] = nid; |
| 1813 | path->depth++; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1814 | snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n", |
| 1815 | path->depth, path->path[0], path->path[1], |
| 1816 | path->path[2], path->path[3], path->path[4]); |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 1817 | return true; |
| 1818 | } |
| 1819 | return false; |
| 1820 | } |
| 1821 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1822 | static int via_auto_fill_dac_nids(struct hda_codec *codec) |
| 1823 | { |
| 1824 | struct via_spec *spec = codec->spec; |
| 1825 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
Lydia Wang | 5c9a561 | 2011-07-08 14:03:43 +0800 | [diff] [blame] | 1826 | int i, dac_num; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1827 | hda_nid_t nid; |
| 1828 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1829 | spec->multiout.dac_nids = spec->private_dac_nids; |
Lydia Wang | 5c9a561 | 2011-07-08 14:03:43 +0800 | [diff] [blame] | 1830 | dac_num = 0; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1831 | for (i = 0; i < cfg->line_outs; i++) { |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1832 | hda_nid_t dac = 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1833 | nid = cfg->line_out_pins[i]; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1834 | if (!nid) |
| 1835 | continue; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1836 | if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i])) |
| 1837 | dac = spec->out_path[i].path[0]; |
| 1838 | if (!i && parse_output_path(codec, nid, dac, 1, |
| 1839 | &spec->out_mix_path)) |
| 1840 | dac = spec->out_mix_path.path[0]; |
| 1841 | if (dac) { |
| 1842 | spec->private_dac_nids[i] = dac; |
Lydia Wang | 5c9a561 | 2011-07-08 14:03:43 +0800 | [diff] [blame] | 1843 | dac_num++; |
| 1844 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1845 | } |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1846 | if (!spec->out_path[0].depth && spec->out_mix_path.depth) { |
| 1847 | spec->out_path[0] = spec->out_mix_path; |
| 1848 | spec->out_mix_path.depth = 0; |
| 1849 | } |
Lydia Wang | 5c9a561 | 2011-07-08 14:03:43 +0800 | [diff] [blame] | 1850 | spec->multiout.num_dacs = dac_num; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1851 | return 0; |
| 1852 | } |
| 1853 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1854 | static int create_ch_ctls(struct hda_codec *codec, const char *pfx, |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 1855 | int chs, bool check_dac, struct nid_path *path) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1856 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1857 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1858 | char name[32]; |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 1859 | hda_nid_t dac, pin, sel, nid; |
| 1860 | int err; |
Takashi Iwai | a934d5a | 2011-06-21 14:22:14 +0200 | [diff] [blame] | 1861 | |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 1862 | dac = check_dac ? path->path[0] : 0; |
| 1863 | pin = path->path[path->depth - 1]; |
| 1864 | sel = path->depth > 1 ? path->path[1] : 0; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1865 | |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 1866 | if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1867 | nid = dac; |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 1868 | else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1869 | nid = pin; |
Takashi Iwai | a934d5a | 2011-06-21 14:22:14 +0200 | [diff] [blame] | 1870 | else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS)) |
| 1871 | nid = sel; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1872 | else |
| 1873 | nid = 0; |
| 1874 | if (nid) { |
| 1875 | sprintf(name, "%s Playback Volume", pfx); |
| 1876 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Lydia Wang | a00a5fa | 2011-06-21 16:11:11 +0800 | [diff] [blame] | 1877 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1878 | if (err < 0) |
| 1879 | return err; |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 1880 | path->vol_ctl = nid; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1881 | } |
| 1882 | |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 1883 | if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE)) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1884 | nid = dac; |
Takashi Iwai | 8df2a31 | 2011-06-21 11:48:29 +0200 | [diff] [blame] | 1885 | else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE)) |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1886 | nid = pin; |
Takashi Iwai | a934d5a | 2011-06-21 14:22:14 +0200 | [diff] [blame] | 1887 | else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE)) |
| 1888 | nid = sel; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1889 | else |
| 1890 | nid = 0; |
| 1891 | if (nid) { |
| 1892 | sprintf(name, "%s Playback Switch", pfx); |
| 1893 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 1894 | HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); |
| 1895 | if (err < 0) |
| 1896 | return err; |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 1897 | path->mute_ctl = nid; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1898 | } |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1902 | static void mangle_smart51(struct hda_codec *codec) |
| 1903 | { |
| 1904 | struct via_spec *spec = codec->spec; |
| 1905 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 0f98c24 | 2011-06-21 12:51:33 +0200 | [diff] [blame] | 1906 | struct auto_pin_cfg_item *ins = cfg->inputs; |
| 1907 | int i, j, nums, attr; |
| 1908 | int pins[AUTO_CFG_MAX_INS]; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1909 | |
Takashi Iwai | 0f98c24 | 2011-06-21 12:51:33 +0200 | [diff] [blame] | 1910 | for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) { |
| 1911 | nums = 0; |
| 1912 | for (i = 0; i < cfg->num_inputs; i++) { |
| 1913 | unsigned int def; |
| 1914 | if (ins[i].type > AUTO_PIN_LINE_IN) |
| 1915 | continue; |
| 1916 | def = snd_hda_codec_get_pincfg(codec, ins[i].pin); |
| 1917 | if (snd_hda_get_input_pin_attr(def) != attr) |
| 1918 | continue; |
| 1919 | for (j = 0; j < nums; j++) |
| 1920 | if (ins[pins[j]].type < ins[i].type) { |
| 1921 | memmove(pins + j + 1, pins + j, |
Takashi Iwai | 21d45d2 | 2011-07-08 11:35:11 +0200 | [diff] [blame] | 1922 | (nums - j) * sizeof(int)); |
Takashi Iwai | 0f98c24 | 2011-06-21 12:51:33 +0200 | [diff] [blame] | 1923 | break; |
| 1924 | } |
| 1925 | pins[j] = i; |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 1926 | nums++; |
Takashi Iwai | 0f98c24 | 2011-06-21 12:51:33 +0200 | [diff] [blame] | 1927 | } |
| 1928 | if (cfg->line_outs + nums < 3) |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1929 | continue; |
Takashi Iwai | 0f98c24 | 2011-06-21 12:51:33 +0200 | [diff] [blame] | 1930 | for (i = 0; i < nums; i++) { |
| 1931 | hda_nid_t pin = ins[pins[i]].pin; |
| 1932 | spec->smart51_pins[spec->smart51_nums++] = pin; |
| 1933 | cfg->line_out_pins[cfg->line_outs++] = pin; |
| 1934 | if (cfg->line_outs == 3) |
| 1935 | break; |
| 1936 | } |
| 1937 | return; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 1941 | static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src) |
| 1942 | { |
| 1943 | dst->vol_ctl = src->vol_ctl; |
| 1944 | dst->mute_ctl = src->mute_ctl; |
| 1945 | } |
| 1946 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1947 | /* add playback controls from the parsed DAC table */ |
| 1948 | static int via_auto_create_multi_out_ctls(struct hda_codec *codec) |
| 1949 | { |
| 1950 | struct via_spec *spec = codec->spec; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1951 | struct auto_pin_cfg *cfg = &spec->autocfg; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1952 | struct nid_path *path; |
Takashi Iwai | ea73496 | 2011-01-17 11:29:34 +0100 | [diff] [blame] | 1953 | static const char * const chname[4] = { |
| 1954 | "Front", "Surround", "C/LFE", "Side" |
| 1955 | }; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1956 | int i, idx, err; |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 1957 | int old_line_outs; |
| 1958 | |
| 1959 | /* check smart51 */ |
| 1960 | old_line_outs = cfg->line_outs; |
| 1961 | if (cfg->line_outs == 1) |
| 1962 | mangle_smart51(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1963 | |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 1964 | err = via_auto_fill_dac_nids(codec); |
| 1965 | if (err < 0) |
| 1966 | return err; |
| 1967 | |
Lydia Wang | 5c9a561 | 2011-07-08 14:03:43 +0800 | [diff] [blame] | 1968 | if (spec->multiout.num_dacs < 3) { |
| 1969 | spec->smart51_nums = 0; |
| 1970 | cfg->line_outs = old_line_outs; |
| 1971 | } |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 1972 | for (i = 0; i < cfg->line_outs; i++) { |
| 1973 | hda_nid_t pin, dac; |
| 1974 | pin = cfg->line_out_pins[i]; |
| 1975 | dac = spec->multiout.dac_nids[i]; |
| 1976 | if (!pin || !dac) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1977 | continue; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1978 | path = spec->out_path + i; |
Takashi Iwai | 0fe0adf | 2011-06-19 16:27:53 +0200 | [diff] [blame] | 1979 | if (i == HDA_CLFE) { |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1980 | err = create_ch_ctls(codec, "Center", 1, true, path); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1981 | if (err < 0) |
| 1982 | return err; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1983 | err = create_ch_ctls(codec, "LFE", 2, true, path); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1984 | if (err < 0) |
| 1985 | return err; |
| 1986 | } else { |
Takashi Iwai | 6aadf41 | 2011-06-20 14:09:02 +0200 | [diff] [blame] | 1987 | const char *pfx = chname[i]; |
| 1988 | if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && |
| 1989 | cfg->line_outs == 1) |
| 1990 | pfx = "Speaker"; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 1991 | err = create_ch_ctls(codec, pfx, 3, true, path); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1992 | if (err < 0) |
| 1993 | return err; |
| 1994 | } |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 1995 | if (path != spec->out_path + i) |
| 1996 | copy_path_mixer_ctls(&spec->out_path[i], path); |
| 1997 | if (path == spec->out_path && spec->out_mix_path.depth) |
| 1998 | copy_path_mixer_ctls(&spec->out_mix_path, path); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1999 | } |
| 2000 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2001 | idx = get_connection_index(codec, spec->aa_mix_nid, |
| 2002 | spec->multiout.dac_nids[0]); |
| 2003 | if (idx >= 0) { |
| 2004 | /* add control to mixer */ |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2005 | const char *name; |
| 2006 | name = spec->out_mix_path.depth ? |
| 2007 | "PCM Loopback Playback Volume" : "PCM Playback Volume"; |
| 2008 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2009 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
| 2010 | idx, HDA_INPUT)); |
| 2011 | if (err < 0) |
| 2012 | return err; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2013 | name = spec->out_mix_path.depth ? |
| 2014 | "PCM Loopback Playback Switch" : "PCM Playback Switch"; |
| 2015 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2016 | HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3, |
| 2017 | idx, HDA_INPUT)); |
| 2018 | if (err < 0) |
| 2019 | return err; |
| 2020 | } |
| 2021 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2022 | cfg->line_outs = old_line_outs; |
| 2023 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2024 | return 0; |
| 2025 | } |
| 2026 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2027 | static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2028 | { |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2029 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 2030 | struct nid_path *path; |
Takashi Iwai | 18bd2c4 | 2011-07-04 15:55:44 +0200 | [diff] [blame] | 2031 | bool check_dac; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2032 | int i, err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2033 | |
| 2034 | if (!pin) |
| 2035 | return 0; |
| 2036 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2037 | if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) { |
| 2038 | for (i = HDA_SIDE; i >= HDA_CLFE; i--) { |
| 2039 | if (i < spec->multiout.num_dacs && |
| 2040 | parse_output_path(codec, pin, |
| 2041 | spec->multiout.dac_nids[i], 0, |
| 2042 | &spec->hp_indep_path)) { |
| 2043 | spec->hp_indep_shared = i; |
| 2044 | break; |
| 2045 | } |
| 2046 | } |
Takashi Iwai | 2525050 | 2011-06-30 17:24:47 +0200 | [diff] [blame] | 2047 | } |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2048 | if (spec->hp_indep_path.depth) { |
| 2049 | spec->hp_dac_nid = spec->hp_indep_path.path[0]; |
| 2050 | if (!spec->hp_indep_shared) |
| 2051 | spec->hp_path = spec->hp_indep_path; |
| 2052 | } |
| 2053 | /* optionally check front-path w/o AA-mix */ |
| 2054 | if (!spec->hp_path.depth) |
| 2055 | parse_output_path(codec, pin, |
| 2056 | spec->multiout.dac_nids[HDA_FRONT], 0, |
| 2057 | &spec->hp_path); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2058 | |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 2059 | if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2060 | 1, &spec->hp_mix_path) && !spec->hp_path.depth) |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 2061 | return 0; |
| 2062 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2063 | if (spec->hp_path.depth) { |
Takashi Iwai | 09a9ad69 | 2011-06-21 15:57:44 +0200 | [diff] [blame] | 2064 | path = &spec->hp_path; |
Takashi Iwai | 18bd2c4 | 2011-07-04 15:55:44 +0200 | [diff] [blame] | 2065 | check_dac = true; |
| 2066 | } else { |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2067 | path = &spec->hp_mix_path; |
Takashi Iwai | 18bd2c4 | 2011-07-04 15:55:44 +0200 | [diff] [blame] | 2068 | check_dac = false; |
| 2069 | } |
| 2070 | err = create_ch_ctls(codec, "Headphone", 3, check_dac, path); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2071 | if (err < 0) |
| 2072 | return err; |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 2073 | if (check_dac) |
| 2074 | copy_path_mixer_ctls(&spec->hp_mix_path, path); |
| 2075 | else |
| 2076 | copy_path_mixer_ctls(&spec->hp_path, path); |
| 2077 | if (spec->hp_indep_path.depth) |
| 2078 | copy_path_mixer_ctls(&spec->hp_indep_path, path); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2079 | return 0; |
| 2080 | } |
| 2081 | |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2082 | static int via_auto_create_speaker_ctls(struct hda_codec *codec) |
| 2083 | { |
| 2084 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2085 | struct nid_path *path; |
| 2086 | bool check_dac; |
Wang Shaoyan | 81c0a78 | 2011-08-05 18:51:29 +0800 | [diff] [blame] | 2087 | hda_nid_t pin, dac = 0; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2088 | int err; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2089 | |
| 2090 | pin = spec->autocfg.speaker_pins[0]; |
| 2091 | if (!spec->autocfg.speaker_outs || !pin) |
| 2092 | return 0; |
| 2093 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2094 | if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path)) |
Takashi Iwai | 8e3679d | 2011-06-21 09:01:36 +0200 | [diff] [blame] | 2095 | dac = spec->speaker_path.path[0]; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2096 | if (!dac) |
| 2097 | parse_output_path(codec, pin, |
| 2098 | spec->multiout.dac_nids[HDA_FRONT], 0, |
| 2099 | &spec->speaker_path); |
| 2100 | if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT], |
| 2101 | 1, &spec->speaker_mix_path) && !dac) |
| 2102 | return 0; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2103 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2104 | /* no AA-path for front? */ |
| 2105 | if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth) |
| 2106 | dac = 0; |
| 2107 | |
| 2108 | spec->speaker_dac_nid = dac; |
| 2109 | spec->multiout.extra_out_nid[0] = dac; |
| 2110 | if (dac) { |
| 2111 | path = &spec->speaker_path; |
| 2112 | check_dac = true; |
| 2113 | } else { |
| 2114 | path = &spec->speaker_mix_path; |
| 2115 | check_dac = false; |
| 2116 | } |
| 2117 | err = create_ch_ctls(codec, "Speaker", 3, check_dac, path); |
| 2118 | if (err < 0) |
| 2119 | return err; |
Takashi Iwai | 020066d | 2011-07-21 13:45:56 +0200 | [diff] [blame] | 2120 | if (check_dac) |
| 2121 | copy_path_mixer_ctls(&spec->speaker_mix_path, path); |
| 2122 | else |
| 2123 | copy_path_mixer_ctls(&spec->speaker_path, path); |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2124 | return 0; |
| 2125 | } |
| 2126 | |
| 2127 | #define via_aamix_ctl_info via_pin_power_ctl_info |
| 2128 | |
| 2129 | static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol, |
| 2130 | struct snd_ctl_elem_value *ucontrol) |
| 2131 | { |
| 2132 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2133 | struct via_spec *spec = codec->spec; |
| 2134 | ucontrol->value.enumerated.item[0] = spec->aamix_mode; |
| 2135 | return 0; |
| 2136 | } |
| 2137 | |
| 2138 | static void update_aamix_paths(struct hda_codec *codec, int do_mix, |
| 2139 | struct nid_path *nomix, struct nid_path *mix) |
| 2140 | { |
| 2141 | if (do_mix) { |
| 2142 | activate_output_path(codec, nomix, false, false); |
| 2143 | activate_output_path(codec, mix, true, false); |
| 2144 | } else { |
| 2145 | activate_output_path(codec, mix, false, false); |
| 2146 | activate_output_path(codec, nomix, true, false); |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol, |
| 2151 | struct snd_ctl_elem_value *ucontrol) |
| 2152 | { |
| 2153 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2154 | struct via_spec *spec = codec->spec; |
| 2155 | unsigned int val = ucontrol->value.enumerated.item[0]; |
| 2156 | |
| 2157 | if (val == spec->aamix_mode) |
| 2158 | return 0; |
| 2159 | spec->aamix_mode = val; |
| 2160 | /* update front path */ |
| 2161 | update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path); |
| 2162 | /* update HP path */ |
| 2163 | if (!spec->hp_independent_mode) { |
| 2164 | update_aamix_paths(codec, val, &spec->hp_path, |
| 2165 | &spec->hp_mix_path); |
| 2166 | } |
| 2167 | /* update speaker path */ |
| 2168 | update_aamix_paths(codec, val, &spec->speaker_path, |
| 2169 | &spec->speaker_mix_path); |
| 2170 | return 1; |
| 2171 | } |
| 2172 | |
| 2173 | static const struct snd_kcontrol_new via_aamix_ctl_enum = { |
| 2174 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2175 | .name = "Loopback Mixing", |
| 2176 | .info = via_aamix_ctl_info, |
| 2177 | .get = via_aamix_ctl_get, |
| 2178 | .put = via_aamix_ctl_put, |
| 2179 | }; |
| 2180 | |
| 2181 | static int via_auto_create_loopback_switch(struct hda_codec *codec) |
| 2182 | { |
| 2183 | struct via_spec *spec = codec->spec; |
| 2184 | |
| 2185 | if (!spec->aa_mix_nid || !spec->out_mix_path.depth) |
| 2186 | return 0; /* no loopback switching available */ |
| 2187 | if (!via_clone_control(spec, &via_aamix_ctl_enum)) |
| 2188 | return -ENOMEM; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2189 | return 0; |
| 2190 | } |
| 2191 | |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2192 | /* look for ADCs */ |
| 2193 | static int via_fill_adcs(struct hda_codec *codec) |
| 2194 | { |
| 2195 | struct via_spec *spec = codec->spec; |
| 2196 | hda_nid_t nid = codec->start_nid; |
| 2197 | int i; |
| 2198 | |
| 2199 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 2200 | unsigned int wcaps = get_wcaps(codec, nid); |
| 2201 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 2202 | continue; |
| 2203 | if (wcaps & AC_WCAP_DIGITAL) |
| 2204 | continue; |
| 2205 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 2206 | continue; |
| 2207 | if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids)) |
| 2208 | return -ENOMEM; |
| 2209 | spec->adc_nids[spec->num_adc_nids++] = nid; |
| 2210 | } |
| 2211 | return 0; |
| 2212 | } |
| 2213 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2214 | /* input-src control */ |
| 2215 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 2216 | struct snd_ctl_elem_info *uinfo) |
| 2217 | { |
| 2218 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2219 | struct via_spec *spec = codec->spec; |
| 2220 | |
| 2221 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2222 | uinfo->count = 1; |
| 2223 | uinfo->value.enumerated.items = spec->num_inputs; |
| 2224 | if (uinfo->value.enumerated.item >= spec->num_inputs) |
| 2225 | uinfo->value.enumerated.item = spec->num_inputs - 1; |
| 2226 | strcpy(uinfo->value.enumerated.name, |
| 2227 | spec->inputs[uinfo->value.enumerated.item].label); |
| 2228 | return 0; |
| 2229 | } |
| 2230 | |
| 2231 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 2232 | struct snd_ctl_elem_value *ucontrol) |
| 2233 | { |
| 2234 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2235 | struct via_spec *spec = codec->spec; |
| 2236 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 2237 | |
| 2238 | ucontrol->value.enumerated.item[0] = spec->cur_mux[idx]; |
| 2239 | return 0; |
| 2240 | } |
| 2241 | |
| 2242 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 2243 | struct snd_ctl_elem_value *ucontrol) |
| 2244 | { |
| 2245 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2246 | struct via_spec *spec = codec->spec; |
| 2247 | unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 2248 | hda_nid_t mux; |
| 2249 | int cur; |
| 2250 | |
| 2251 | cur = ucontrol->value.enumerated.item[0]; |
| 2252 | if (cur < 0 || cur >= spec->num_inputs) |
| 2253 | return -EINVAL; |
| 2254 | if (spec->cur_mux[idx] == cur) |
| 2255 | return 0; |
| 2256 | spec->cur_mux[idx] = cur; |
| 2257 | if (spec->dyn_adc_switch) { |
| 2258 | int adc_idx = spec->inputs[cur].adc_idx; |
| 2259 | mux = spec->mux_nids[adc_idx]; |
| 2260 | via_dyn_adc_pcm_resetup(codec, cur); |
| 2261 | } else { |
| 2262 | mux = spec->mux_nids[idx]; |
| 2263 | if (snd_BUG_ON(!mux)) |
| 2264 | return -EINVAL; |
| 2265 | } |
| 2266 | |
| 2267 | if (mux) { |
| 2268 | /* switch to D0 beofre change index */ |
| 2269 | if (snd_hda_codec_read(codec, mux, 0, |
| 2270 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) |
| 2271 | snd_hda_codec_write(codec, mux, 0, |
| 2272 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 2273 | snd_hda_codec_write(codec, mux, 0, |
| 2274 | AC_VERB_SET_CONNECT_SEL, |
| 2275 | spec->inputs[cur].mux_idx); |
| 2276 | } |
| 2277 | |
| 2278 | /* update jack power state */ |
| 2279 | set_widgets_power_state(codec); |
| 2280 | return 0; |
| 2281 | } |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2282 | |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 2283 | static const struct snd_kcontrol_new via_input_src_ctl = { |
| 2284 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2285 | /* The multiple "Capture Source" controls confuse alsamixer |
| 2286 | * So call somewhat different.. |
| 2287 | */ |
| 2288 | /* .name = "Capture Source", */ |
| 2289 | .name = "Input Source", |
| 2290 | .info = via_mux_enum_info, |
| 2291 | .get = via_mux_enum_get, |
| 2292 | .put = via_mux_enum_put, |
| 2293 | }; |
| 2294 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2295 | static int create_input_src_ctls(struct hda_codec *codec, int count) |
| 2296 | { |
| 2297 | struct via_spec *spec = codec->spec; |
| 2298 | struct snd_kcontrol_new *knew; |
| 2299 | |
| 2300 | if (spec->num_inputs <= 1 || !count) |
| 2301 | return 0; /* no need for single src */ |
| 2302 | |
| 2303 | knew = via_clone_control(spec, &via_input_src_ctl); |
| 2304 | if (!knew) |
| 2305 | return -ENOMEM; |
| 2306 | knew->count = count; |
| 2307 | return 0; |
| 2308 | } |
| 2309 | |
| 2310 | /* add the powersave loopback-list entry */ |
Takashi Iwai | 13af8e7 | 2011-06-20 14:05:46 +0200 | [diff] [blame] | 2311 | static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx) |
| 2312 | { |
| 2313 | struct hda_amp_list *list; |
| 2314 | |
| 2315 | if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1) |
| 2316 | return; |
| 2317 | list = spec->loopback_list + spec->num_loopbacks; |
| 2318 | list->nid = mix; |
| 2319 | list->dir = HDA_INPUT; |
| 2320 | list->idx = idx; |
| 2321 | spec->num_loopbacks++; |
| 2322 | spec->loopback.amplist = spec->loopback_list; |
| 2323 | } |
Takashi Iwai | 13af8e7 | 2011-06-20 14:05:46 +0200 | [diff] [blame] | 2324 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2325 | static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src, |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 2326 | hda_nid_t dst) |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2327 | { |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 2328 | return snd_hda_get_conn_index(codec, src, dst, 1) >= 0; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | /* add the input-route to the given pin */ |
| 2332 | static bool add_input_route(struct hda_codec *codec, hda_nid_t pin) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2333 | { |
Takashi Iwai | 10a20af | 2010-09-09 16:28:02 +0200 | [diff] [blame] | 2334 | struct via_spec *spec = codec->spec; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2335 | int c, idx; |
| 2336 | |
| 2337 | spec->inputs[spec->num_inputs].adc_idx = -1; |
| 2338 | spec->inputs[spec->num_inputs].pin = pin; |
| 2339 | for (c = 0; c < spec->num_adc_nids; c++) { |
| 2340 | if (spec->mux_nids[c]) { |
| 2341 | idx = get_connection_index(codec, spec->mux_nids[c], |
| 2342 | pin); |
| 2343 | if (idx < 0) |
| 2344 | continue; |
| 2345 | spec->inputs[spec->num_inputs].mux_idx = idx; |
| 2346 | } else { |
Takashi Iwai | 8d087c7 | 2011-06-28 12:45:47 +0200 | [diff] [blame] | 2347 | if (!is_reachable_nid(codec, spec->adc_nids[c], pin)) |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2348 | continue; |
| 2349 | } |
| 2350 | spec->inputs[spec->num_inputs].adc_idx = c; |
| 2351 | /* Can primary ADC satisfy all inputs? */ |
| 2352 | if (!spec->dyn_adc_switch && |
| 2353 | spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) { |
| 2354 | snd_printd(KERN_INFO |
| 2355 | "via: dynamic ADC switching enabled\n"); |
| 2356 | spec->dyn_adc_switch = 1; |
| 2357 | } |
| 2358 | return true; |
| 2359 | } |
| 2360 | return false; |
| 2361 | } |
| 2362 | |
| 2363 | static int get_mux_nids(struct hda_codec *codec); |
| 2364 | |
| 2365 | /* parse input-routes; fill ADCs, MUXs and input-src entries */ |
| 2366 | static int parse_analog_inputs(struct hda_codec *codec) |
| 2367 | { |
| 2368 | struct via_spec *spec = codec->spec; |
| 2369 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2370 | int i, err; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2371 | |
| 2372 | err = via_fill_adcs(codec); |
| 2373 | if (err < 0) |
| 2374 | return err; |
| 2375 | err = get_mux_nids(codec); |
| 2376 | if (err < 0) |
| 2377 | return err; |
Takashi Iwai | a766d0d | 2011-06-17 09:01:29 +0200 | [diff] [blame] | 2378 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2379 | /* fill all input-routes */ |
| 2380 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2381 | if (add_input_route(codec, cfg->inputs[i].pin)) |
| 2382 | spec->inputs[spec->num_inputs++].label = |
| 2383 | hda_get_autocfg_input_label(codec, cfg, i); |
Takashi Iwai | f326851 | 2010-08-30 11:00:19 +0200 | [diff] [blame] | 2384 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2385 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2386 | /* check for internal loopback recording */ |
| 2387 | if (spec->aa_mix_nid && |
| 2388 | add_input_route(codec, spec->aa_mix_nid)) |
| 2389 | spec->inputs[spec->num_inputs++].label = "Stereo Mixer"; |
| 2390 | |
| 2391 | return 0; |
| 2392 | } |
| 2393 | |
| 2394 | /* create analog-loopback volume/switch controls */ |
| 2395 | static int create_loopback_ctls(struct hda_codec *codec) |
| 2396 | { |
| 2397 | struct via_spec *spec = codec->spec; |
| 2398 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2399 | const char *prev_label = NULL; |
| 2400 | int type_idx = 0; |
| 2401 | int i, j, err, idx; |
| 2402 | |
| 2403 | if (!spec->aa_mix_nid) |
| 2404 | return 0; |
| 2405 | |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2406 | for (i = 0; i < cfg->num_inputs; i++) { |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2407 | hda_nid_t pin = cfg->inputs[i].pin; |
| 2408 | const char *label = hda_get_autocfg_input_label(codec, cfg, i); |
| 2409 | |
Takashi Iwai | 1e11cae | 2011-06-21 12:57:22 +0200 | [diff] [blame] | 2410 | if (prev_label && !strcmp(label, prev_label)) |
Takashi Iwai | 7b315bb | 2010-08-30 13:06:30 +0200 | [diff] [blame] | 2411 | type_idx++; |
| 2412 | else |
| 2413 | type_idx = 0; |
Takashi Iwai | 1e11cae | 2011-06-21 12:57:22 +0200 | [diff] [blame] | 2414 | prev_label = label; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2415 | idx = get_connection_index(codec, spec->aa_mix_nid, pin); |
| 2416 | if (idx >= 0) { |
Lydia Wang | 1692228 | 2011-03-22 16:24:10 +0800 | [diff] [blame] | 2417 | err = via_new_analog_input(spec, label, type_idx, |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2418 | idx, spec->aa_mix_nid); |
Takashi Iwai | 13af8e7 | 2011-06-20 14:05:46 +0200 | [diff] [blame] | 2419 | if (err < 0) |
| 2420 | return err; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2421 | add_loopback_list(spec, spec->aa_mix_nid, idx); |
Takashi Iwai | 13af8e7 | 2011-06-20 14:05:46 +0200 | [diff] [blame] | 2422 | } |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 2423 | |
| 2424 | /* remember the label for smart51 control */ |
| 2425 | for (j = 0; j < spec->smart51_nums; j++) { |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2426 | if (spec->smart51_pins[j] == pin) { |
Takashi Iwai | e3d7a14 | 2011-06-20 13:52:33 +0200 | [diff] [blame] | 2427 | spec->smart51_idxs[j] = idx; |
| 2428 | spec->smart51_labels[j] = label; |
| 2429 | break; |
| 2430 | } |
| 2431 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2432 | } |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2433 | return 0; |
| 2434 | } |
| 2435 | |
| 2436 | /* create mic-boost controls (if present) */ |
| 2437 | static int create_mic_boost_ctls(struct hda_codec *codec) |
| 2438 | { |
| 2439 | struct via_spec *spec = codec->spec; |
| 2440 | const struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2441 | int i, err; |
| 2442 | |
| 2443 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2444 | hda_nid_t pin = cfg->inputs[i].pin; |
| 2445 | unsigned int caps; |
| 2446 | const char *label; |
| 2447 | char name[32]; |
| 2448 | |
| 2449 | if (cfg->inputs[i].type != AUTO_PIN_MIC) |
| 2450 | continue; |
| 2451 | caps = query_amp_caps(codec, pin, HDA_INPUT); |
| 2452 | if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS)) |
| 2453 | continue; |
| 2454 | label = hda_get_autocfg_input_label(codec, cfg, i); |
| 2455 | snprintf(name, sizeof(name), "%s Boost Volume", label); |
| 2456 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 2457 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT)); |
| 2458 | if (err < 0) |
| 2459 | return err; |
| 2460 | } |
| 2461 | return 0; |
| 2462 | } |
| 2463 | |
| 2464 | /* create capture and input-src controls for multiple streams */ |
| 2465 | static int create_multi_adc_ctls(struct hda_codec *codec) |
| 2466 | { |
| 2467 | struct via_spec *spec = codec->spec; |
| 2468 | int i, err; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 2469 | |
| 2470 | /* create capture mixer elements */ |
| 2471 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 2472 | hda_nid_t adc = spec->adc_nids[i]; |
| 2473 | err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2474 | "Capture Volume", i, |
| 2475 | HDA_COMPOSE_AMP_VAL(adc, 3, 0, |
| 2476 | HDA_INPUT)); |
| 2477 | if (err < 0) |
| 2478 | return err; |
| 2479 | err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2480 | "Capture Switch", i, |
| 2481 | HDA_COMPOSE_AMP_VAL(adc, 3, 0, |
| 2482 | HDA_INPUT)); |
| 2483 | if (err < 0) |
| 2484 | return err; |
| 2485 | } |
| 2486 | |
| 2487 | /* input-source control */ |
| 2488 | for (i = 0; i < spec->num_adc_nids; i++) |
| 2489 | if (!spec->mux_nids[i]) |
| 2490 | break; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2491 | err = create_input_src_ctls(codec, i); |
| 2492 | if (err < 0) |
| 2493 | return err; |
| 2494 | return 0; |
| 2495 | } |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 2496 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2497 | /* bind capture volume/switch */ |
| 2498 | static struct snd_kcontrol_new via_bind_cap_vol_ctl = |
| 2499 | HDA_BIND_VOL("Capture Volume", 0); |
| 2500 | static struct snd_kcontrol_new via_bind_cap_sw_ctl = |
| 2501 | HDA_BIND_SW("Capture Switch", 0); |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 2502 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2503 | static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret, |
| 2504 | struct hda_ctl_ops *ops) |
| 2505 | { |
| 2506 | struct hda_bind_ctls *ctl; |
| 2507 | int i; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 2508 | |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2509 | ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL); |
| 2510 | if (!ctl) |
| 2511 | return -ENOMEM; |
| 2512 | ctl->ops = ops; |
| 2513 | for (i = 0; i < spec->num_adc_nids; i++) |
| 2514 | ctl->values[i] = |
| 2515 | HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT); |
| 2516 | *ctl_ret = ctl; |
| 2517 | return 0; |
| 2518 | } |
| 2519 | |
| 2520 | /* create capture and input-src controls for dynamic ADC-switch case */ |
| 2521 | static int create_dyn_adc_ctls(struct hda_codec *codec) |
| 2522 | { |
| 2523 | struct via_spec *spec = codec->spec; |
| 2524 | struct snd_kcontrol_new *knew; |
| 2525 | int err; |
| 2526 | |
| 2527 | /* set up the bind capture ctls */ |
| 2528 | err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol); |
| 2529 | if (err < 0) |
| 2530 | return err; |
| 2531 | err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw); |
| 2532 | if (err < 0) |
| 2533 | return err; |
| 2534 | |
| 2535 | /* create capture mixer elements */ |
| 2536 | knew = via_clone_control(spec, &via_bind_cap_vol_ctl); |
| 2537 | if (!knew) |
| 2538 | return -ENOMEM; |
| 2539 | knew->private_value = (long)spec->bind_cap_vol; |
| 2540 | |
| 2541 | knew = via_clone_control(spec, &via_bind_cap_sw_ctl); |
| 2542 | if (!knew) |
| 2543 | return -ENOMEM; |
| 2544 | knew->private_value = (long)spec->bind_cap_sw; |
| 2545 | |
| 2546 | /* input-source control */ |
| 2547 | err = create_input_src_ctls(codec, 1); |
| 2548 | if (err < 0) |
| 2549 | return err; |
| 2550 | return 0; |
| 2551 | } |
| 2552 | |
| 2553 | /* parse and create capture-related stuff */ |
| 2554 | static int via_auto_create_analog_input_ctls(struct hda_codec *codec) |
| 2555 | { |
| 2556 | struct via_spec *spec = codec->spec; |
| 2557 | int err; |
| 2558 | |
| 2559 | err = parse_analog_inputs(codec); |
| 2560 | if (err < 0) |
| 2561 | return err; |
| 2562 | if (spec->dyn_adc_switch) |
| 2563 | err = create_dyn_adc_ctls(codec); |
| 2564 | else |
| 2565 | err = create_multi_adc_ctls(codec); |
| 2566 | if (err < 0) |
| 2567 | return err; |
| 2568 | err = create_loopback_ctls(codec); |
| 2569 | if (err < 0) |
| 2570 | return err; |
| 2571 | err = create_mic_boost_ctls(codec); |
| 2572 | if (err < 0) |
| 2573 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2574 | return 0; |
| 2575 | } |
| 2576 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2577 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
| 2578 | { |
| 2579 | unsigned int def_conf; |
| 2580 | unsigned char seqassoc; |
| 2581 | |
Takashi Iwai | 2f334f9 | 2009-02-20 14:37:42 +0100 | [diff] [blame] | 2582 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2583 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
| 2584 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
Lydia Wang | 82ef9e4 | 2009-10-10 19:08:19 +0800 | [diff] [blame] | 2585 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
| 2586 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
| 2587 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
| 2588 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | return; |
| 2592 | } |
| 2593 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2594 | static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2595 | struct snd_ctl_elem_value *ucontrol) |
| 2596 | { |
| 2597 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2598 | struct via_spec *spec = codec->spec; |
| 2599 | |
| 2600 | if (spec->codec_type != VT1708) |
| 2601 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2602 | spec->vt1708_jack_detect = |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2603 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2604 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2605 | return 0; |
| 2606 | } |
| 2607 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2608 | static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2609 | struct snd_ctl_elem_value *ucontrol) |
| 2610 | { |
| 2611 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2612 | struct via_spec *spec = codec->spec; |
| 2613 | int change; |
| 2614 | |
| 2615 | if (spec->codec_type != VT1708) |
| 2616 | return 0; |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2617 | spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2618 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2619 | == !spec->vt1708_jack_detect; |
| 2620 | if (spec->vt1708_jack_detect) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2621 | mute_aa_path(codec, 1); |
| 2622 | notify_aa_path_ctls(codec); |
| 2623 | } |
| 2624 | return change; |
| 2625 | } |
| 2626 | |
Takashi Iwai | e06e5a2 | 2011-06-17 15:46:13 +0200 | [diff] [blame] | 2627 | static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { |
| 2628 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2629 | .name = "Jack Detect", |
| 2630 | .count = 1, |
| 2631 | .info = snd_ctl_boolean_mono_info, |
| 2632 | .get = vt1708_jack_detect_get, |
| 2633 | .put = vt1708_jack_detect_put, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2634 | }; |
| 2635 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2636 | static void fill_dig_outs(struct hda_codec *codec); |
| 2637 | static void fill_dig_in(struct hda_codec *codec); |
| 2638 | |
| 2639 | static int via_parse_auto_config(struct hda_codec *codec) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2640 | { |
| 2641 | struct via_spec *spec = codec->spec; |
| 2642 | int err; |
| 2643 | |
| 2644 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2645 | if (err < 0) |
| 2646 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2647 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
Takashi Iwai | 7f0df88 | 2011-06-18 17:33:34 +0200 | [diff] [blame] | 2648 | return -EINVAL; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2649 | |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2650 | err = via_auto_create_multi_out_ctls(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2651 | if (err < 0) |
| 2652 | return err; |
Takashi Iwai | 4a79616 | 2011-06-17 17:53:38 +0200 | [diff] [blame] | 2653 | err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2654 | if (err < 0) |
| 2655 | return err; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2656 | err = via_auto_create_speaker_ctls(codec); |
| 2657 | if (err < 0) |
| 2658 | return err; |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2659 | err = via_auto_create_loopback_switch(codec); |
| 2660 | if (err < 0) |
| 2661 | return err; |
Takashi Iwai | a86a88e | 2011-06-22 15:23:25 +0200 | [diff] [blame] | 2662 | err = via_auto_create_analog_input_ctls(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2663 | if (err < 0) |
| 2664 | return err; |
| 2665 | |
| 2666 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2667 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2668 | fill_dig_outs(codec); |
| 2669 | fill_dig_in(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2670 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2671 | if (spec->kctls.list) |
| 2672 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2673 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2674 | |
Takashi Iwai | 3214b96 | 2011-07-18 12:49:25 +0200 | [diff] [blame] | 2675 | if (spec->hp_dac_nid && spec->hp_mix_path.depth) { |
Takashi Iwai | ece8d04 | 2011-06-19 16:24:21 +0200 | [diff] [blame] | 2676 | err = via_hp_build(codec); |
| 2677 | if (err < 0) |
| 2678 | return err; |
| 2679 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2680 | |
Takashi Iwai | f4a7828 | 2011-06-17 18:46:48 +0200 | [diff] [blame] | 2681 | err = via_smart51_build(codec); |
| 2682 | if (err < 0) |
| 2683 | return err; |
| 2684 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2685 | /* assign slave outs */ |
| 2686 | if (spec->slave_dig_outs[0]) |
| 2687 | codec->slave_dig_outs = spec->slave_dig_outs; |
| 2688 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2689 | return 1; |
| 2690 | } |
| 2691 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2692 | static void via_auto_init_dig_outs(struct hda_codec *codec) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2693 | { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2694 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2695 | if (spec->multiout.dig_out_nid) |
| 2696 | init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT); |
| 2697 | if (spec->slave_dig_outs[0]) |
| 2698 | init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT); |
| 2699 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2700 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2701 | static void via_auto_init_dig_in(struct hda_codec *codec) |
| 2702 | { |
| 2703 | struct via_spec *spec = codec->spec; |
| 2704 | if (!spec->dig_in_nid) |
| 2705 | return; |
| 2706 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, |
| 2707 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); |
| 2708 | } |
| 2709 | |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2710 | /* initialize the unsolicited events */ |
| 2711 | static void via_auto_init_unsol_event(struct hda_codec *codec) |
| 2712 | { |
| 2713 | struct via_spec *spec = codec->spec; |
| 2714 | struct auto_pin_cfg *cfg = &spec->autocfg; |
| 2715 | unsigned int ev; |
| 2716 | int i; |
| 2717 | |
| 2718 | if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0])) |
| 2719 | snd_hda_codec_write(codec, cfg->hp_pins[0], 0, |
| 2720 | AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2721 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT); |
| 2722 | |
| 2723 | if (cfg->speaker_pins[0]) |
| 2724 | ev = VIA_LINE_EVENT; |
| 2725 | else |
| 2726 | ev = 0; |
| 2727 | for (i = 0; i < cfg->line_outs; i++) { |
| 2728 | if (cfg->line_out_pins[i] && |
| 2729 | is_jack_detectable(codec, cfg->line_out_pins[i])) |
Lydia Wang | 63f10d2 | 2011-06-28 17:29:10 +0800 | [diff] [blame] | 2730 | snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2731 | AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2732 | AC_USRSP_EN | ev | VIA_JACK_EVENT); |
| 2733 | } |
| 2734 | |
| 2735 | for (i = 0; i < cfg->num_inputs; i++) { |
| 2736 | if (is_jack_detectable(codec, cfg->inputs[i].pin)) |
| 2737 | snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, |
| 2738 | AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2739 | AC_USRSP_EN | VIA_JACK_EVENT); |
| 2740 | } |
| 2741 | } |
| 2742 | |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2743 | static int via_init(struct hda_codec *codec) |
| 2744 | { |
| 2745 | struct via_spec *spec = codec->spec; |
| 2746 | int i; |
| 2747 | |
| 2748 | for (i = 0; i < spec->num_iverbs; i++) |
| 2749 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 2750 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2751 | via_auto_init_multi_out(codec); |
| 2752 | via_auto_init_hp_out(codec); |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2753 | via_auto_init_speaker_out(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2754 | via_auto_init_analog_input(codec); |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 2755 | via_auto_init_dig_outs(codec); |
| 2756 | via_auto_init_dig_in(codec); |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 2757 | |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 2758 | via_auto_init_unsol_event(codec); |
| 2759 | |
| 2760 | via_hp_automute(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2761 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2762 | return 0; |
| 2763 | } |
| 2764 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2765 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
| 2766 | { |
| 2767 | struct via_spec *spec = container_of(work, struct via_spec, |
| 2768 | vt1708_hp_work.work); |
| 2769 | if (spec->codec_type != VT1708) |
| 2770 | return; |
| 2771 | /* if jack state toggled */ |
| 2772 | if (spec->vt1708_hp_present |
Takashi Iwai | d56757a | 2009-11-18 08:00:14 +0100 | [diff] [blame] | 2773 | != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2774 | spec->vt1708_hp_present ^= 1; |
| 2775 | via_hp_automute(spec->codec); |
| 2776 | } |
| 2777 | vt1708_start_hp_work(spec); |
| 2778 | } |
| 2779 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2780 | static int get_mux_nids(struct hda_codec *codec) |
| 2781 | { |
| 2782 | struct via_spec *spec = codec->spec; |
| 2783 | hda_nid_t nid, conn[8]; |
| 2784 | unsigned int type; |
| 2785 | int i, n; |
| 2786 | |
| 2787 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 2788 | nid = spec->adc_nids[i]; |
| 2789 | while (nid) { |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 2790 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2791 | if (type == AC_WID_PIN) |
| 2792 | break; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2793 | n = snd_hda_get_connections(codec, nid, conn, |
| 2794 | ARRAY_SIZE(conn)); |
| 2795 | if (n <= 0) |
| 2796 | break; |
| 2797 | if (n > 1) { |
| 2798 | spec->mux_nids[i] = nid; |
| 2799 | break; |
| 2800 | } |
| 2801 | nid = conn[0]; |
| 2802 | } |
| 2803 | } |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2804 | return 0; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2805 | } |
| 2806 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2807 | static int patch_vt1708(struct hda_codec *codec) |
| 2808 | { |
| 2809 | struct via_spec *spec; |
| 2810 | int err; |
| 2811 | |
| 2812 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2813 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2814 | if (spec == NULL) |
| 2815 | return -ENOMEM; |
| 2816 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2817 | spec->aa_mix_nid = 0x17; |
| 2818 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2819 | /* Add HP and CD pin config connect bit re-config action */ |
| 2820 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); |
| 2821 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); |
| 2822 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2823 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2824 | err = via_parse_auto_config(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2825 | if (err < 0) { |
| 2826 | via_free(codec); |
| 2827 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2828 | } |
| 2829 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2830 | /* add jack detect on/off control */ |
| 2831 | if (!via_clone_control(spec, &vt1708_jack_detect_ctl)) |
| 2832 | return -ENOMEM; |
| 2833 | |
Takashi Iwai | bc9b562 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 2834 | /* disable 32bit format on VT1708 */ |
| 2835 | if (codec->vendor_id == 0x11061708) |
| 2836 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2837 | |
Lydia Wang | e322a36 | 2011-06-29 13:52:02 +0800 | [diff] [blame] | 2838 | spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs; |
| 2839 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2840 | codec->patch_ops = via_patch_ops; |
| 2841 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2842 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2843 | return 0; |
| 2844 | } |
| 2845 | |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 2846 | static int patch_vt1709(struct hda_codec *codec) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2847 | { |
| 2848 | struct via_spec *spec; |
| 2849 | int err; |
| 2850 | |
| 2851 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2852 | spec = via_new_spec(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2853 | if (spec == NULL) |
| 2854 | return -ENOMEM; |
| 2855 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2856 | spec->aa_mix_nid = 0x18; |
| 2857 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2858 | err = via_parse_auto_config(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2859 | if (err < 0) { |
| 2860 | via_free(codec); |
| 2861 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2862 | } |
| 2863 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2864 | codec->patch_ops = via_patch_ops; |
| 2865 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2866 | return 0; |
| 2867 | } |
| 2868 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2869 | static void set_widgets_power_state_vt1708B(struct hda_codec *codec) |
| 2870 | { |
| 2871 | struct via_spec *spec = codec->spec; |
| 2872 | int imux_is_smixer; |
| 2873 | unsigned int parm; |
| 2874 | int is_8ch = 0; |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2875 | if ((spec->codec_type != VT1708B_4CH) && |
| 2876 | (codec->vendor_id != 0x11064397)) |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2877 | is_8ch = 1; |
| 2878 | |
| 2879 | /* SW0 (17h) = stereo mixer */ |
| 2880 | imux_is_smixer = |
| 2881 | (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) |
| 2882 | == ((spec->codec_type == VT1708S) ? 5 : 0)); |
| 2883 | /* inputs */ |
| 2884 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 2885 | parm = AC_PWRST_D3; |
| 2886 | set_pin_power_state(codec, 0x1a, &parm); |
| 2887 | set_pin_power_state(codec, 0x1b, &parm); |
| 2888 | set_pin_power_state(codec, 0x1e, &parm); |
| 2889 | if (imux_is_smixer) |
| 2890 | parm = AC_PWRST_D0; |
| 2891 | /* SW0 (17h), AIW 0/1 (13h/14h) */ |
| 2892 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2893 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2894 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2895 | |
| 2896 | /* outputs */ |
| 2897 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 2898 | parm = AC_PWRST_D3; |
| 2899 | set_pin_power_state(codec, 0x19, &parm); |
| 2900 | if (spec->smart51_enabled) |
| 2901 | set_pin_power_state(codec, 0x1b, &parm); |
| 2902 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2903 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2904 | |
| 2905 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ |
| 2906 | if (is_8ch) { |
| 2907 | parm = AC_PWRST_D3; |
| 2908 | set_pin_power_state(codec, 0x22, &parm); |
| 2909 | if (spec->smart51_enabled) |
| 2910 | set_pin_power_state(codec, 0x1a, &parm); |
| 2911 | snd_hda_codec_write(codec, 0x26, 0, |
| 2912 | AC_VERB_SET_POWER_STATE, parm); |
| 2913 | snd_hda_codec_write(codec, 0x24, 0, |
| 2914 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2915 | } else if (codec->vendor_id == 0x11064397) { |
| 2916 | /* PW7(23h), SW2(27h), AOW2(25h) */ |
| 2917 | parm = AC_PWRST_D3; |
| 2918 | set_pin_power_state(codec, 0x23, &parm); |
| 2919 | if (spec->smart51_enabled) |
| 2920 | set_pin_power_state(codec, 0x1a, &parm); |
| 2921 | snd_hda_codec_write(codec, 0x27, 0, |
| 2922 | AC_VERB_SET_POWER_STATE, parm); |
| 2923 | snd_hda_codec_write(codec, 0x25, 0, |
| 2924 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | /* PW 3/4/7 (1ch/1dh/23h) */ |
| 2928 | parm = AC_PWRST_D3; |
| 2929 | /* force to D0 for internal Speaker */ |
| 2930 | set_pin_power_state(codec, 0x1c, &parm); |
| 2931 | set_pin_power_state(codec, 0x1d, &parm); |
| 2932 | if (is_8ch) |
| 2933 | set_pin_power_state(codec, 0x23, &parm); |
| 2934 | |
| 2935 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ |
| 2936 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 2937 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 2938 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 2939 | if (is_8ch) { |
| 2940 | snd_hda_codec_write(codec, 0x25, 0, |
| 2941 | AC_VERB_SET_POWER_STATE, parm); |
| 2942 | snd_hda_codec_write(codec, 0x27, 0, |
| 2943 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 2944 | } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode) |
| 2945 | snd_hda_codec_write(codec, 0x25, 0, |
| 2946 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2947 | } |
| 2948 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 2949 | static int patch_vt1708S(struct hda_codec *codec); |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 2950 | static int patch_vt1708B(struct hda_codec *codec) |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2951 | { |
| 2952 | struct via_spec *spec; |
| 2953 | int err; |
| 2954 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 2955 | if (get_codec_type(codec) == VT1708BCE) |
| 2956 | return patch_vt1708S(codec); |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 2957 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2958 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 2959 | spec = via_new_spec(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2960 | if (spec == NULL) |
| 2961 | return -ENOMEM; |
| 2962 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 2963 | spec->aa_mix_nid = 0x16; |
| 2964 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2965 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 2966 | err = via_parse_auto_config(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2967 | if (err < 0) { |
| 2968 | via_free(codec); |
| 2969 | return err; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2970 | } |
| 2971 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2972 | codec->patch_ops = via_patch_ops; |
| 2973 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 2974 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
| 2975 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2976 | return 0; |
| 2977 | } |
| 2978 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2979 | /* Patch for VT1708S */ |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 2980 | static const struct hda_verb vt1708S_init_verbs[] = { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 2981 | /* Enable Mic Boost Volume backdoor */ |
| 2982 | {0x1, 0xf98, 0x1}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 2983 | /* don't bybass mixer */ |
| 2984 | {0x1, 0xf88, 0xc0}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 2985 | { } |
| 2986 | }; |
| 2987 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 2988 | /* fill out digital output widgets; one for master and one for slave outputs */ |
| 2989 | static void fill_dig_outs(struct hda_codec *codec) |
| 2990 | { |
| 2991 | struct via_spec *spec = codec->spec; |
| 2992 | int i; |
| 2993 | |
| 2994 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 2995 | hda_nid_t nid; |
| 2996 | int conn; |
| 2997 | |
| 2998 | nid = spec->autocfg.dig_out_pins[i]; |
| 2999 | if (!nid) |
| 3000 | continue; |
| 3001 | conn = snd_hda_get_connections(codec, nid, &nid, 1); |
| 3002 | if (conn < 1) |
| 3003 | continue; |
| 3004 | if (!spec->multiout.dig_out_nid) |
| 3005 | spec->multiout.dig_out_nid = nid; |
| 3006 | else { |
| 3007 | spec->slave_dig_outs[0] = nid; |
| 3008 | break; /* at most two dig outs */ |
| 3009 | } |
| 3010 | } |
| 3011 | } |
| 3012 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3013 | static void fill_dig_in(struct hda_codec *codec) |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3014 | { |
| 3015 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3016 | hda_nid_t dig_nid; |
| 3017 | int i, err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3018 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3019 | if (!spec->autocfg.dig_in_pin) |
| 3020 | return; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3021 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3022 | dig_nid = codec->start_nid; |
| 3023 | for (i = 0; i < codec->num_nodes; i++, dig_nid++) { |
| 3024 | unsigned int wcaps = get_wcaps(codec, dig_nid); |
| 3025 | if (get_wcaps_type(wcaps) != AC_WID_AUD_IN) |
| 3026 | continue; |
| 3027 | if (!(wcaps & AC_WCAP_DIGITAL)) |
| 3028 | continue; |
| 3029 | if (!(wcaps & AC_WCAP_CONN_LIST)) |
| 3030 | continue; |
| 3031 | err = get_connection_index(codec, dig_nid, |
| 3032 | spec->autocfg.dig_in_pin); |
| 3033 | if (err >= 0) { |
| 3034 | spec->dig_in_nid = dig_nid; |
| 3035 | break; |
| 3036 | } |
| 3037 | } |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3038 | } |
| 3039 | |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3040 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
| 3041 | int offset, int num_steps, int step_size) |
| 3042 | { |
| 3043 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, |
| 3044 | (offset << AC_AMPCAP_OFFSET_SHIFT) | |
| 3045 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 3046 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 3047 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 3048 | } |
| 3049 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3050 | static int patch_vt1708S(struct hda_codec *codec) |
| 3051 | { |
| 3052 | struct via_spec *spec; |
| 3053 | int err; |
| 3054 | |
| 3055 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3056 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3057 | if (spec == NULL) |
| 3058 | return -ENOMEM; |
| 3059 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3060 | spec->aa_mix_nid = 0x16; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 3061 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 3062 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3063 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3064 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3065 | err = via_parse_auto_config(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3066 | if (err < 0) { |
| 3067 | via_free(codec); |
| 3068 | return err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3069 | } |
| 3070 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3071 | spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3072 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3073 | codec->patch_ops = via_patch_ops; |
| 3074 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3075 | /* correct names for VT1708BCE */ |
| 3076 | if (get_codec_type(codec) == VT1708BCE) { |
| 3077 | kfree(codec->chip_name); |
| 3078 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); |
| 3079 | snprintf(codec->bus->card->mixername, |
| 3080 | sizeof(codec->bus->card->mixername), |
| 3081 | "%s %s", codec->vendor_name, codec->chip_name); |
Lydia Wang | 970f630 | 2011-03-22 16:25:56 +0800 | [diff] [blame] | 3082 | } |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3083 | /* correct names for VT1705 */ |
| 3084 | if (codec->vendor_id == 0x11064397) { |
| 3085 | kfree(codec->chip_name); |
| 3086 | codec->chip_name = kstrdup("VT1705", GFP_KERNEL); |
| 3087 | snprintf(codec->bus->card->mixername, |
| 3088 | sizeof(codec->bus->card->mixername), |
| 3089 | "%s %s", codec->vendor_name, codec->chip_name); |
| 3090 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3091 | spec->set_widgets_power_state = set_widgets_power_state_vt1708B; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3092 | return 0; |
| 3093 | } |
| 3094 | |
| 3095 | /* Patch for VT1702 */ |
| 3096 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3097 | static const struct hda_verb vt1702_init_verbs[] = { |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 3098 | /* mixer enable */ |
| 3099 | {0x1, 0xF88, 0x3}, |
| 3100 | /* GPIO 0~2 */ |
| 3101 | {0x1, 0xF82, 0x3F}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3102 | { } |
| 3103 | }; |
| 3104 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3105 | static void set_widgets_power_state_vt1702(struct hda_codec *codec) |
| 3106 | { |
| 3107 | int imux_is_smixer = |
| 3108 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 3109 | unsigned int parm; |
| 3110 | /* inputs */ |
| 3111 | /* PW 1/2/5 (14h/15h/18h) */ |
| 3112 | parm = AC_PWRST_D3; |
| 3113 | set_pin_power_state(codec, 0x14, &parm); |
| 3114 | set_pin_power_state(codec, 0x15, &parm); |
| 3115 | set_pin_power_state(codec, 0x18, &parm); |
| 3116 | if (imux_is_smixer) |
| 3117 | parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */ |
| 3118 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ |
| 3119 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3120 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3121 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3122 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3123 | |
| 3124 | /* outputs */ |
| 3125 | /* PW 3/4 (16h/17h) */ |
| 3126 | parm = AC_PWRST_D3; |
| 3127 | set_pin_power_state(codec, 0x17, &parm); |
| 3128 | set_pin_power_state(codec, 0x16, &parm); |
| 3129 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ |
| 3130 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, |
| 3131 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3132 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3133 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3134 | } |
| 3135 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3136 | static int patch_vt1702(struct hda_codec *codec) |
| 3137 | { |
| 3138 | struct via_spec *spec; |
| 3139 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3140 | |
| 3141 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3142 | spec = via_new_spec(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3143 | if (spec == NULL) |
| 3144 | return -ENOMEM; |
| 3145 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3146 | spec->aa_mix_nid = 0x1a; |
| 3147 | |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3148 | /* limit AA path volume to 0 dB */ |
| 3149 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, |
| 3150 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 3151 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 3152 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 3153 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
| 3154 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3155 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3156 | err = via_parse_auto_config(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3157 | if (err < 0) { |
| 3158 | via_free(codec); |
| 3159 | return err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3160 | } |
| 3161 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3162 | spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3163 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3164 | codec->patch_ops = via_patch_ops; |
| 3165 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3166 | spec->set_widgets_power_state = set_widgets_power_state_vt1702; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3167 | return 0; |
| 3168 | } |
| 3169 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3170 | /* Patch for VT1718S */ |
| 3171 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3172 | static const struct hda_verb vt1718S_init_verbs[] = { |
Lydia Wang | 4ab2d53 | 2011-03-24 12:42:03 +0800 | [diff] [blame] | 3173 | /* Enable MW0 adjust Gain 5 */ |
| 3174 | {0x1, 0xfb2, 0x10}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3175 | /* Enable Boost Volume backdoor */ |
| 3176 | {0x1, 0xf88, 0x8}, |
Takashi Iwai | 5d41762 | 2011-06-20 11:32:27 +0200 | [diff] [blame] | 3177 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3178 | { } |
| 3179 | }; |
| 3180 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3181 | static void set_widgets_power_state_vt1718S(struct hda_codec *codec) |
| 3182 | { |
| 3183 | struct via_spec *spec = codec->spec; |
| 3184 | int imux_is_smixer; |
| 3185 | unsigned int parm; |
| 3186 | /* MUX6 (1eh) = stereo mixer */ |
| 3187 | imux_is_smixer = |
| 3188 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 3189 | /* inputs */ |
| 3190 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 3191 | parm = AC_PWRST_D3; |
| 3192 | set_pin_power_state(codec, 0x29, &parm); |
| 3193 | set_pin_power_state(codec, 0x2a, &parm); |
| 3194 | set_pin_power_state(codec, 0x2b, &parm); |
| 3195 | if (imux_is_smixer) |
| 3196 | parm = AC_PWRST_D0; |
| 3197 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 3198 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3199 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3200 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3201 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3202 | |
| 3203 | /* outputs */ |
| 3204 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ |
| 3205 | parm = AC_PWRST_D3; |
| 3206 | set_pin_power_state(codec, 0x27, &parm); |
| 3207 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3208 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3209 | |
| 3210 | /* PW2 (26h), AOW2 (ah) */ |
| 3211 | parm = AC_PWRST_D3; |
| 3212 | set_pin_power_state(codec, 0x26, &parm); |
| 3213 | if (spec->smart51_enabled) |
| 3214 | set_pin_power_state(codec, 0x2b, &parm); |
| 3215 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3216 | |
| 3217 | /* PW0 (24h), AOW0 (8h) */ |
| 3218 | parm = AC_PWRST_D3; |
| 3219 | set_pin_power_state(codec, 0x24, &parm); |
| 3220 | if (!spec->hp_independent_mode) /* check for redirected HP */ |
| 3221 | set_pin_power_state(codec, 0x28, &parm); |
| 3222 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3223 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
| 3224 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, |
| 3225 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3226 | |
| 3227 | /* PW1 (25h), AOW1 (9h) */ |
| 3228 | parm = AC_PWRST_D3; |
| 3229 | set_pin_power_state(codec, 0x25, &parm); |
| 3230 | if (spec->smart51_enabled) |
| 3231 | set_pin_power_state(codec, 0x2a, &parm); |
| 3232 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3233 | |
| 3234 | if (spec->hp_independent_mode) { |
| 3235 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ |
| 3236 | parm = AC_PWRST_D3; |
| 3237 | set_pin_power_state(codec, 0x28, &parm); |
| 3238 | snd_hda_codec_write(codec, 0x1b, 0, |
| 3239 | AC_VERB_SET_POWER_STATE, parm); |
| 3240 | snd_hda_codec_write(codec, 0x34, 0, |
| 3241 | AC_VERB_SET_POWER_STATE, parm); |
| 3242 | snd_hda_codec_write(codec, 0xc, 0, |
| 3243 | AC_VERB_SET_POWER_STATE, parm); |
| 3244 | } |
| 3245 | } |
| 3246 | |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 3247 | /* Add a connection to the primary DAC from AA-mixer for some codecs |
| 3248 | * This isn't listed from the raw info, but the chip has a secret connection. |
| 3249 | */ |
| 3250 | static int add_secret_dac_path(struct hda_codec *codec) |
| 3251 | { |
| 3252 | struct via_spec *spec = codec->spec; |
| 3253 | int i, nums; |
| 3254 | hda_nid_t conn[8]; |
| 3255 | hda_nid_t nid; |
| 3256 | |
| 3257 | if (!spec->aa_mix_nid) |
| 3258 | return 0; |
| 3259 | nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn, |
| 3260 | ARRAY_SIZE(conn) - 1); |
| 3261 | for (i = 0; i < nums; i++) { |
| 3262 | if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT) |
| 3263 | return 0; |
| 3264 | } |
| 3265 | |
| 3266 | /* find the primary DAC and add to the connection list */ |
| 3267 | nid = codec->start_nid; |
| 3268 | for (i = 0; i < codec->num_nodes; i++, nid++) { |
| 3269 | unsigned int caps = get_wcaps(codec, nid); |
| 3270 | if (get_wcaps_type(caps) == AC_WID_AUD_OUT && |
| 3271 | !(caps & AC_WCAP_DIGITAL)) { |
| 3272 | conn[nums++] = nid; |
| 3273 | return snd_hda_override_conn_list(codec, |
| 3274 | spec->aa_mix_nid, |
| 3275 | nums, conn); |
| 3276 | } |
| 3277 | } |
| 3278 | return 0; |
| 3279 | } |
| 3280 | |
| 3281 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3282 | static int patch_vt1718S(struct hda_codec *codec) |
| 3283 | { |
| 3284 | struct via_spec *spec; |
| 3285 | int err; |
| 3286 | |
| 3287 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3288 | spec = via_new_spec(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3289 | if (spec == NULL) |
| 3290 | return -ENOMEM; |
| 3291 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3292 | spec->aa_mix_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 3293 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 3294 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 3295 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3296 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3297 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3298 | err = via_parse_auto_config(codec); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3299 | if (err < 0) { |
| 3300 | via_free(codec); |
| 3301 | return err; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3302 | } |
| 3303 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3304 | spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3305 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3306 | codec->patch_ops = via_patch_ops; |
| 3307 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3308 | spec->set_widgets_power_state = set_widgets_power_state_vt1718S; |
| 3309 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3310 | return 0; |
| 3311 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3312 | |
| 3313 | /* Patch for VT1716S */ |
| 3314 | |
| 3315 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, |
| 3316 | struct snd_ctl_elem_info *uinfo) |
| 3317 | { |
| 3318 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3319 | uinfo->count = 1; |
| 3320 | uinfo->value.integer.min = 0; |
| 3321 | uinfo->value.integer.max = 1; |
| 3322 | return 0; |
| 3323 | } |
| 3324 | |
| 3325 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, |
| 3326 | struct snd_ctl_elem_value *ucontrol) |
| 3327 | { |
| 3328 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3329 | int index = 0; |
| 3330 | |
| 3331 | index = snd_hda_codec_read(codec, 0x26, 0, |
| 3332 | AC_VERB_GET_CONNECT_SEL, 0); |
| 3333 | if (index != -1) |
| 3334 | *ucontrol->value.integer.value = index; |
| 3335 | |
| 3336 | return 0; |
| 3337 | } |
| 3338 | |
| 3339 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, |
| 3340 | struct snd_ctl_elem_value *ucontrol) |
| 3341 | { |
| 3342 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 3343 | struct via_spec *spec = codec->spec; |
| 3344 | int index = *ucontrol->value.integer.value; |
| 3345 | |
| 3346 | snd_hda_codec_write(codec, 0x26, 0, |
| 3347 | AC_VERB_SET_CONNECT_SEL, index); |
| 3348 | spec->dmic_enabled = index; |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3349 | set_widgets_power_state(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3350 | return 1; |
| 3351 | } |
| 3352 | |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3353 | static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3354 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
| 3355 | { |
| 3356 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3357 | .name = "Digital Mic Capture Switch", |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3358 | .subdevice = HDA_SUBDEV_NID_FLAG | 0x26, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3359 | .count = 1, |
| 3360 | .info = vt1716s_dmic_info, |
| 3361 | .get = vt1716s_dmic_get, |
| 3362 | .put = vt1716s_dmic_put, |
| 3363 | }, |
| 3364 | {} /* end */ |
| 3365 | }; |
| 3366 | |
| 3367 | |
| 3368 | /* mono-out mixer elements */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3369 | static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3370 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
| 3371 | { } /* end */ |
| 3372 | }; |
| 3373 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3374 | static const struct hda_verb vt1716S_init_verbs[] = { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3375 | /* Enable Boost Volume backdoor */ |
| 3376 | {0x1, 0xf8a, 0x80}, |
| 3377 | /* don't bybass mixer */ |
| 3378 | {0x1, 0xf88, 0xc0}, |
| 3379 | /* Enable mono output */ |
| 3380 | {0x1, 0xf90, 0x08}, |
| 3381 | { } |
| 3382 | }; |
| 3383 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3384 | static void set_widgets_power_state_vt1716S(struct hda_codec *codec) |
| 3385 | { |
| 3386 | struct via_spec *spec = codec->spec; |
| 3387 | int imux_is_smixer; |
| 3388 | unsigned int parm; |
| 3389 | unsigned int mono_out, present; |
| 3390 | /* SW0 (17h) = stereo mixer */ |
| 3391 | imux_is_smixer = |
| 3392 | (snd_hda_codec_read(codec, 0x17, 0, |
| 3393 | AC_VERB_GET_CONNECT_SEL, 0x00) == 5); |
| 3394 | /* inputs */ |
| 3395 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 3396 | parm = AC_PWRST_D3; |
| 3397 | set_pin_power_state(codec, 0x1a, &parm); |
| 3398 | set_pin_power_state(codec, 0x1b, &parm); |
| 3399 | set_pin_power_state(codec, 0x1e, &parm); |
| 3400 | if (imux_is_smixer) |
| 3401 | parm = AC_PWRST_D0; |
| 3402 | /* SW0 (17h), AIW0(13h) */ |
| 3403 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3404 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3405 | |
| 3406 | parm = AC_PWRST_D3; |
| 3407 | set_pin_power_state(codec, 0x1e, &parm); |
| 3408 | /* PW11 (22h) */ |
| 3409 | if (spec->dmic_enabled) |
| 3410 | set_pin_power_state(codec, 0x22, &parm); |
| 3411 | else |
| 3412 | snd_hda_codec_write(codec, 0x22, 0, |
| 3413 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3414 | |
| 3415 | /* SW2(26h), AIW1(14h) */ |
| 3416 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3417 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3418 | |
| 3419 | /* outputs */ |
| 3420 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 3421 | parm = AC_PWRST_D3; |
| 3422 | set_pin_power_state(codec, 0x19, &parm); |
| 3423 | /* Smart 5.1 PW2(1bh) */ |
| 3424 | if (spec->smart51_enabled) |
| 3425 | set_pin_power_state(codec, 0x1b, &parm); |
| 3426 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3427 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3428 | |
| 3429 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ |
| 3430 | parm = AC_PWRST_D3; |
| 3431 | set_pin_power_state(codec, 0x23, &parm); |
| 3432 | /* Smart 5.1 PW1(1ah) */ |
| 3433 | if (spec->smart51_enabled) |
| 3434 | set_pin_power_state(codec, 0x1a, &parm); |
| 3435 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3436 | |
| 3437 | /* Smart 5.1 PW5(1eh) */ |
| 3438 | if (spec->smart51_enabled) |
| 3439 | set_pin_power_state(codec, 0x1e, &parm); |
| 3440 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3441 | |
| 3442 | /* Mono out */ |
| 3443 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ |
| 3444 | present = snd_hda_jack_detect(codec, 0x1c); |
| 3445 | |
| 3446 | if (present) |
| 3447 | mono_out = 0; |
| 3448 | else { |
| 3449 | present = snd_hda_jack_detect(codec, 0x1d); |
| 3450 | if (!spec->hp_independent_mode && present) |
| 3451 | mono_out = 0; |
| 3452 | else |
| 3453 | mono_out = 1; |
| 3454 | } |
| 3455 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; |
| 3456 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3457 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3458 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3459 | |
| 3460 | /* PW 3/4 (1ch/1dh) */ |
| 3461 | parm = AC_PWRST_D3; |
| 3462 | set_pin_power_state(codec, 0x1c, &parm); |
| 3463 | set_pin_power_state(codec, 0x1d, &parm); |
| 3464 | /* HP Independent Mode, power on AOW3 */ |
| 3465 | if (spec->hp_independent_mode) |
| 3466 | snd_hda_codec_write(codec, 0x25, 0, |
| 3467 | AC_VERB_SET_POWER_STATE, parm); |
| 3468 | |
| 3469 | /* force to D0 for internal Speaker */ |
| 3470 | /* MW0 (16h), AOW0 (10h) */ |
| 3471 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 3472 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 3473 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 3474 | mono_out ? AC_PWRST_D0 : parm); |
| 3475 | } |
| 3476 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3477 | static int patch_vt1716S(struct hda_codec *codec) |
| 3478 | { |
| 3479 | struct via_spec *spec; |
| 3480 | int err; |
| 3481 | |
| 3482 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3483 | spec = via_new_spec(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3484 | if (spec == NULL) |
| 3485 | return -ENOMEM; |
| 3486 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3487 | spec->aa_mix_nid = 0x16; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 3488 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 3489 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3490 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3491 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3492 | err = via_parse_auto_config(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3493 | if (err < 0) { |
| 3494 | via_free(codec); |
| 3495 | return err; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3496 | } |
| 3497 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3498 | spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3499 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3500 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; |
| 3501 | spec->num_mixers++; |
| 3502 | |
| 3503 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; |
| 3504 | |
| 3505 | codec->patch_ops = via_patch_ops; |
| 3506 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3507 | spec->set_widgets_power_state = set_widgets_power_state_vt1716S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3508 | return 0; |
| 3509 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3510 | |
| 3511 | /* for vt2002P */ |
| 3512 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3513 | static const struct hda_verb vt2002P_init_verbs[] = { |
Lydia Wang | eadb9a8 | 2011-03-24 12:43:02 +0800 | [diff] [blame] | 3514 | /* Class-D speaker related verbs */ |
| 3515 | {0x1, 0xfe0, 0x4}, |
| 3516 | {0x1, 0xfe9, 0x80}, |
| 3517 | {0x1, 0xfe2, 0x22}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3518 | /* Enable Boost Volume backdoor */ |
| 3519 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3520 | /* Enable AOW0 to MW9 */ |
| 3521 | {0x1, 0xfb8, 0x88}, |
| 3522 | { } |
| 3523 | }; |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 3524 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3525 | static const struct hda_verb vt1802_init_verbs[] = { |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3526 | /* Enable Boost Volume backdoor */ |
| 3527 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3528 | /* Enable AOW0 to MW9 */ |
| 3529 | {0x1, 0xfb8, 0x88}, |
| 3530 | { } |
| 3531 | }; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3532 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3533 | static void set_widgets_power_state_vt2002P(struct hda_codec *codec) |
| 3534 | { |
| 3535 | struct via_spec *spec = codec->spec; |
| 3536 | int imux_is_smixer; |
| 3537 | unsigned int parm; |
| 3538 | unsigned int present; |
| 3539 | /* MUX9 (1eh) = stereo mixer */ |
| 3540 | imux_is_smixer = |
| 3541 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 3542 | /* inputs */ |
| 3543 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 3544 | parm = AC_PWRST_D3; |
| 3545 | set_pin_power_state(codec, 0x29, &parm); |
| 3546 | set_pin_power_state(codec, 0x2a, &parm); |
| 3547 | set_pin_power_state(codec, 0x2b, &parm); |
| 3548 | parm = AC_PWRST_D0; |
| 3549 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 3550 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3551 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3552 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3553 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3554 | |
| 3555 | /* outputs */ |
| 3556 | /* AOW0 (8h)*/ |
| 3557 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3558 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3559 | if (spec->codec_type == VT1802) { |
| 3560 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 3561 | parm = AC_PWRST_D3; |
| 3562 | set_pin_power_state(codec, 0x28, &parm); |
| 3563 | snd_hda_codec_write(codec, 0x18, 0, |
| 3564 | AC_VERB_SET_POWER_STATE, parm); |
| 3565 | snd_hda_codec_write(codec, 0x38, 0, |
| 3566 | AC_VERB_SET_POWER_STATE, parm); |
| 3567 | } else { |
| 3568 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ |
| 3569 | parm = AC_PWRST_D3; |
| 3570 | set_pin_power_state(codec, 0x26, &parm); |
| 3571 | snd_hda_codec_write(codec, 0x1c, 0, |
| 3572 | AC_VERB_SET_POWER_STATE, parm); |
| 3573 | snd_hda_codec_write(codec, 0x37, 0, |
| 3574 | AC_VERB_SET_POWER_STATE, parm); |
| 3575 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3576 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3577 | if (spec->codec_type == VT1802) { |
| 3578 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 3579 | parm = AC_PWRST_D3; |
| 3580 | set_pin_power_state(codec, 0x25, &parm); |
| 3581 | snd_hda_codec_write(codec, 0x15, 0, |
| 3582 | AC_VERB_SET_POWER_STATE, parm); |
| 3583 | snd_hda_codec_write(codec, 0x35, 0, |
| 3584 | AC_VERB_SET_POWER_STATE, parm); |
| 3585 | } else { |
| 3586 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ |
| 3587 | parm = AC_PWRST_D3; |
| 3588 | set_pin_power_state(codec, 0x25, &parm); |
| 3589 | snd_hda_codec_write(codec, 0x19, 0, |
| 3590 | AC_VERB_SET_POWER_STATE, parm); |
| 3591 | snd_hda_codec_write(codec, 0x35, 0, |
| 3592 | AC_VERB_SET_POWER_STATE, parm); |
| 3593 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3594 | |
| 3595 | if (spec->hp_independent_mode) |
| 3596 | snd_hda_codec_write(codec, 0x9, 0, |
| 3597 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3598 | |
| 3599 | /* Class-D */ |
| 3600 | /* PW0 (24h), MW0(18h/14h), MUX0(34h) */ |
| 3601 | present = snd_hda_jack_detect(codec, 0x25); |
| 3602 | |
| 3603 | parm = AC_PWRST_D3; |
| 3604 | set_pin_power_state(codec, 0x24, &parm); |
| 3605 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3606 | if (spec->codec_type == VT1802) |
| 3607 | snd_hda_codec_write(codec, 0x14, 0, |
| 3608 | AC_VERB_SET_POWER_STATE, parm); |
| 3609 | else |
| 3610 | snd_hda_codec_write(codec, 0x18, 0, |
| 3611 | AC_VERB_SET_POWER_STATE, parm); |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3612 | snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3613 | |
| 3614 | /* Mono Out */ |
| 3615 | present = snd_hda_jack_detect(codec, 0x26); |
| 3616 | |
| 3617 | parm = present ? AC_PWRST_D3 : AC_PWRST_D0; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3618 | if (spec->codec_type == VT1802) { |
| 3619 | /* PW15 (33h), MW8(1ch), MUX8(3ch) */ |
| 3620 | snd_hda_codec_write(codec, 0x33, 0, |
| 3621 | AC_VERB_SET_POWER_STATE, parm); |
| 3622 | snd_hda_codec_write(codec, 0x1c, 0, |
| 3623 | AC_VERB_SET_POWER_STATE, parm); |
| 3624 | snd_hda_codec_write(codec, 0x3c, 0, |
| 3625 | AC_VERB_SET_POWER_STATE, parm); |
| 3626 | } else { |
| 3627 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ |
| 3628 | snd_hda_codec_write(codec, 0x31, 0, |
| 3629 | AC_VERB_SET_POWER_STATE, parm); |
| 3630 | snd_hda_codec_write(codec, 0x17, 0, |
| 3631 | AC_VERB_SET_POWER_STATE, parm); |
| 3632 | snd_hda_codec_write(codec, 0x3b, 0, |
| 3633 | AC_VERB_SET_POWER_STATE, parm); |
| 3634 | } |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3635 | /* MW9 (21h) */ |
| 3636 | if (imux_is_smixer || !is_aa_path_mute(codec)) |
| 3637 | snd_hda_codec_write(codec, 0x21, 0, |
| 3638 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3639 | else |
| 3640 | snd_hda_codec_write(codec, 0x21, 0, |
| 3641 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3642 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3643 | |
| 3644 | /* patch for vt2002P */ |
| 3645 | static int patch_vt2002P(struct hda_codec *codec) |
| 3646 | { |
| 3647 | struct via_spec *spec; |
| 3648 | int err; |
| 3649 | |
| 3650 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3651 | spec = via_new_spec(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3652 | if (spec == NULL) |
| 3653 | return -ENOMEM; |
| 3654 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3655 | spec->aa_mix_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 3656 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 3657 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 3658 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3659 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3660 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3661 | err = via_parse_auto_config(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3662 | if (err < 0) { |
| 3663 | via_free(codec); |
| 3664 | return err; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3665 | } |
| 3666 | |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3667 | if (spec->codec_type == VT1802) |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 3668 | spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3669 | else |
Takashi Iwai | 4a918ff | 2011-06-20 12:39:26 +0200 | [diff] [blame] | 3670 | spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs; |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3671 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3672 | codec->patch_ops = via_patch_ops; |
| 3673 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3674 | spec->set_widgets_power_state = set_widgets_power_state_vt2002P; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3675 | return 0; |
| 3676 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3677 | |
| 3678 | /* for vt1812 */ |
| 3679 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3680 | static const struct hda_verb vt1812_init_verbs[] = { |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3681 | /* Enable Boost Volume backdoor */ |
| 3682 | {0x1, 0xfb9, 0x24}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3683 | /* Enable AOW0 to MW9 */ |
| 3684 | {0x1, 0xfb8, 0xa8}, |
| 3685 | { } |
| 3686 | }; |
| 3687 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3688 | static void set_widgets_power_state_vt1812(struct hda_codec *codec) |
| 3689 | { |
| 3690 | struct via_spec *spec = codec->spec; |
| 3691 | int imux_is_smixer = |
| 3692 | snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 3693 | unsigned int parm; |
| 3694 | unsigned int present; |
| 3695 | /* MUX10 (1eh) = stereo mixer */ |
| 3696 | imux_is_smixer = |
| 3697 | snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 3698 | /* inputs */ |
| 3699 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 3700 | parm = AC_PWRST_D3; |
| 3701 | set_pin_power_state(codec, 0x29, &parm); |
| 3702 | set_pin_power_state(codec, 0x2a, &parm); |
| 3703 | set_pin_power_state(codec, 0x2b, &parm); |
| 3704 | parm = AC_PWRST_D0; |
| 3705 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 3706 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3707 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3708 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3709 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3710 | |
| 3711 | /* outputs */ |
| 3712 | /* AOW0 (8h)*/ |
| 3713 | snd_hda_codec_write(codec, 0x8, 0, |
| 3714 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3715 | |
| 3716 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 3717 | parm = AC_PWRST_D3; |
| 3718 | set_pin_power_state(codec, 0x28, &parm); |
| 3719 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3720 | snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3721 | |
| 3722 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 3723 | parm = AC_PWRST_D3; |
| 3724 | set_pin_power_state(codec, 0x25, &parm); |
| 3725 | snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3726 | snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3727 | if (spec->hp_independent_mode) |
| 3728 | snd_hda_codec_write(codec, 0x9, 0, |
| 3729 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3730 | |
| 3731 | /* Internal Speaker */ |
| 3732 | /* PW0 (24h), MW0(14h), MUX0(34h) */ |
| 3733 | present = snd_hda_jack_detect(codec, 0x25); |
| 3734 | |
| 3735 | parm = AC_PWRST_D3; |
| 3736 | set_pin_power_state(codec, 0x24, &parm); |
| 3737 | if (present) { |
| 3738 | snd_hda_codec_write(codec, 0x14, 0, |
| 3739 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3740 | snd_hda_codec_write(codec, 0x34, 0, |
| 3741 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3742 | } else { |
| 3743 | snd_hda_codec_write(codec, 0x14, 0, |
| 3744 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3745 | snd_hda_codec_write(codec, 0x34, 0, |
| 3746 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3747 | } |
| 3748 | |
| 3749 | |
| 3750 | /* Mono Out */ |
| 3751 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ |
| 3752 | present = snd_hda_jack_detect(codec, 0x28); |
| 3753 | |
| 3754 | parm = AC_PWRST_D3; |
| 3755 | set_pin_power_state(codec, 0x31, &parm); |
| 3756 | if (present) { |
| 3757 | snd_hda_codec_write(codec, 0x1c, 0, |
| 3758 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3759 | snd_hda_codec_write(codec, 0x3c, 0, |
| 3760 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3761 | snd_hda_codec_write(codec, 0x3e, 0, |
| 3762 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 3763 | } else { |
| 3764 | snd_hda_codec_write(codec, 0x1c, 0, |
| 3765 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3766 | snd_hda_codec_write(codec, 0x3c, 0, |
| 3767 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3768 | snd_hda_codec_write(codec, 0x3e, 0, |
| 3769 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 3770 | } |
| 3771 | |
| 3772 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ |
| 3773 | parm = AC_PWRST_D3; |
| 3774 | set_pin_power_state(codec, 0x33, &parm); |
| 3775 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3776 | snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm); |
| 3777 | |
| 3778 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3779 | |
| 3780 | /* patch for vt1812 */ |
| 3781 | static int patch_vt1812(struct hda_codec *codec) |
| 3782 | { |
| 3783 | struct via_spec *spec; |
| 3784 | int err; |
| 3785 | |
| 3786 | /* create a codec specific record */ |
Jaroslav Kysela | 5b0cb1d | 2009-12-08 16:13:32 +0100 | [diff] [blame] | 3787 | spec = via_new_spec(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3788 | if (spec == NULL) |
| 3789 | return -ENOMEM; |
| 3790 | |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3791 | spec->aa_mix_nid = 0x21; |
Takashi Iwai | d7a99cc | 2011-06-18 17:24:46 +0200 | [diff] [blame] | 3792 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 3793 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Takashi Iwai | 30b4503 | 2011-07-11 17:05:04 +0200 | [diff] [blame] | 3794 | add_secret_dac_path(codec); |
Takashi Iwai | 620e2b2 | 2011-06-17 17:19:19 +0200 | [diff] [blame] | 3795 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3796 | /* automatic parse from the BIOS config */ |
Takashi Iwai | 12daef6 | 2011-06-18 17:45:49 +0200 | [diff] [blame] | 3797 | err = via_parse_auto_config(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3798 | if (err < 0) { |
| 3799 | via_free(codec); |
| 3800 | return err; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3801 | } |
| 3802 | |
Takashi Iwai | 096a885 | 2011-06-20 12:09:02 +0200 | [diff] [blame] | 3803 | spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3804 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3805 | codec->patch_ops = via_patch_ops; |
| 3806 | |
Lydia Wang | 3e95b9a | 2011-03-23 15:13:28 +0800 | [diff] [blame] | 3807 | spec->set_widgets_power_state = set_widgets_power_state_vt1812; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3808 | return 0; |
| 3809 | } |
| 3810 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3811 | /* |
| 3812 | * patch entries |
| 3813 | */ |
Takashi Iwai | 90dd48a | 2011-05-02 12:38:19 +0200 | [diff] [blame] | 3814 | static const struct hda_codec_preset snd_hda_preset_via[] = { |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3815 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
| 3816 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, |
| 3817 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, |
| 3818 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, |
| 3819 | { .id = 0x1106e710, .name = "VT1709 10-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3820 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3821 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3822 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3823 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3824 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3825 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3826 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3827 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3828 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3829 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3830 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3831 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3832 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3833 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3834 | .patch = patch_vt1709}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3835 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3836 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3837 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3838 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3839 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3840 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3841 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3842 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3843 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3844 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3845 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3846 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3847 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3848 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3849 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
Takashi Iwai | ddd304d | 2011-06-21 16:33:55 +0200 | [diff] [blame] | 3850 | .patch = patch_vt1708B}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3851 | { .id = 0x11060397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3852 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3853 | { .id = 0x11061397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3854 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3855 | { .id = 0x11062397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3856 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3857 | { .id = 0x11063397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3858 | .patch = patch_vt1708S}, |
Lydia Wang | bc92df7 | 2011-03-23 17:56:05 +0800 | [diff] [blame] | 3859 | { .id = 0x11064397, .name = "VT1705", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3860 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3861 | { .id = 0x11065397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3862 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3863 | { .id = 0x11066397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3864 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3865 | { .id = 0x11067397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3866 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3867 | { .id = 0x11060398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3868 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3869 | { .id = 0x11061398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3870 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3871 | { .id = 0x11062398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3872 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3873 | { .id = 0x11063398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3874 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3875 | { .id = 0x11064398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3876 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3877 | { .id = 0x11065398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3878 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3879 | { .id = 0x11066398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3880 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 3881 | { .id = 0x11067398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3882 | .patch = patch_vt1702}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 3883 | { .id = 0x11060428, .name = "VT1718S", |
| 3884 | .patch = patch_vt1718S}, |
| 3885 | { .id = 0x11064428, .name = "VT1718S", |
| 3886 | .patch = patch_vt1718S}, |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 3887 | { .id = 0x11060441, .name = "VT2020", |
| 3888 | .patch = patch_vt1718S}, |
| 3889 | { .id = 0x11064441, .name = "VT1828S", |
| 3890 | .patch = patch_vt1718S}, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 3891 | { .id = 0x11060433, .name = "VT1716S", |
| 3892 | .patch = patch_vt1716S}, |
| 3893 | { .id = 0x1106a721, .name = "VT1716S", |
| 3894 | .patch = patch_vt1716S}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 3895 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
| 3896 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 3897 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
Lydia Wang | 36dd5c4 | 2009-10-20 13:18:04 +0800 | [diff] [blame] | 3898 | { .id = 0x11060440, .name = "VT1818S", |
| 3899 | .patch = patch_vt1708S}, |
Lydia Wang | 11890956 | 2011-03-23 17:57:34 +0800 | [diff] [blame] | 3900 | { .id = 0x11060446, .name = "VT1802", |
| 3901 | .patch = patch_vt2002P}, |
| 3902 | { .id = 0x11068446, .name = "VT1802", |
| 3903 | .patch = patch_vt2002P}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3904 | {} /* terminator */ |
| 3905 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 3906 | |
| 3907 | MODULE_ALIAS("snd-hda-codec-id:1106*"); |
| 3908 | |
| 3909 | static struct hda_codec_preset_list via_list = { |
| 3910 | .preset = snd_hda_preset_via, |
| 3911 | .owner = THIS_MODULE, |
| 3912 | }; |
| 3913 | |
| 3914 | MODULE_LICENSE("GPL"); |
| 3915 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
| 3916 | |
| 3917 | static int __init patch_via_init(void) |
| 3918 | { |
| 3919 | return snd_hda_add_codec_preset(&via_list); |
| 3920 | } |
| 3921 | |
| 3922 | static void __exit patch_via_exit(void) |
| 3923 | { |
| 3924 | snd_hda_delete_codec_preset(&via_list); |
| 3925 | } |
| 3926 | |
| 3927 | module_init(patch_via_init) |
| 3928 | module_exit(patch_via_exit) |