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