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