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