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