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 | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 44 | /* */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 45 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 46 | |
| 47 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 48 | #include <linux/init.h> |
| 49 | #include <linux/delay.h> |
| 50 | #include <linux/slab.h> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 51 | #include <sound/core.h> |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 52 | #include <sound/asoundef.h> |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 53 | #include "hda_codec.h" |
| 54 | #include "hda_local.h" |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 55 | |
| 56 | /* amp values */ |
| 57 | #define AMP_VAL_IDX_SHIFT 19 |
| 58 | #define AMP_VAL_IDX_MASK (0x0f<<19) |
| 59 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 60 | /* Pin Widget NID */ |
| 61 | #define VT1708_HP_NID 0x13 |
| 62 | #define VT1708_DIGOUT_NID 0x14 |
| 63 | #define VT1708_DIGIN_NID 0x16 |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 64 | #define VT1708_DIGIN_PIN 0x26 |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 65 | #define VT1708_HP_PIN_NID 0x20 |
| 66 | #define VT1708_CD_PIN_NID 0x24 |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 67 | |
| 68 | #define VT1709_HP_DAC_NID 0x28 |
| 69 | #define VT1709_DIGOUT_NID 0x13 |
| 70 | #define VT1709_DIGIN_NID 0x17 |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 71 | #define VT1709_DIGIN_PIN 0x25 |
| 72 | |
| 73 | #define VT1708B_HP_NID 0x25 |
| 74 | #define VT1708B_DIGOUT_NID 0x12 |
| 75 | #define VT1708B_DIGIN_NID 0x15 |
| 76 | #define VT1708B_DIGIN_PIN 0x21 |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 77 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 78 | #define VT1708S_HP_NID 0x25 |
| 79 | #define VT1708S_DIGOUT_NID 0x12 |
| 80 | |
| 81 | #define VT1702_HP_NID 0x17 |
| 82 | #define VT1702_DIGOUT_NID 0x11 |
| 83 | |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 84 | enum VIA_HDA_CODEC { |
| 85 | UNKNOWN = -1, |
| 86 | VT1708, |
| 87 | VT1709_10CH, |
| 88 | VT1709_6CH, |
| 89 | VT1708B_8CH, |
| 90 | VT1708B_4CH, |
| 91 | VT1708S, |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 92 | VT1708BCE, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 93 | VT1702, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 94 | VT1718S, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 95 | VT1716S, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 96 | VT2002P, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 97 | VT1812, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 98 | CODEC_TYPES, |
| 99 | }; |
| 100 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 101 | struct via_spec { |
| 102 | /* codec parameterization */ |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 103 | struct snd_kcontrol_new *mixers[6]; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 104 | unsigned int num_mixers; |
| 105 | |
| 106 | struct hda_verb *init_verbs[5]; |
| 107 | unsigned int num_iverbs; |
| 108 | |
| 109 | char *stream_name_analog; |
| 110 | struct hda_pcm_stream *stream_analog_playback; |
| 111 | struct hda_pcm_stream *stream_analog_capture; |
| 112 | |
| 113 | char *stream_name_digital; |
| 114 | struct hda_pcm_stream *stream_digital_playback; |
| 115 | struct hda_pcm_stream *stream_digital_capture; |
| 116 | |
| 117 | /* playback */ |
| 118 | struct hda_multi_out multiout; |
| 119 | hda_nid_t slave_dig_outs[2]; |
| 120 | |
| 121 | /* capture */ |
| 122 | unsigned int num_adc_nids; |
| 123 | hda_nid_t *adc_nids; |
| 124 | hda_nid_t mux_nids[3]; |
| 125 | hda_nid_t dig_in_nid; |
| 126 | hda_nid_t dig_in_pin; |
| 127 | |
| 128 | /* capture source */ |
| 129 | const struct hda_input_mux *input_mux; |
| 130 | unsigned int cur_mux[3]; |
| 131 | |
| 132 | /* PCM information */ |
| 133 | struct hda_pcm pcm_rec[3]; |
| 134 | |
| 135 | /* dynamic controls, init_verbs and input_mux */ |
| 136 | struct auto_pin_cfg autocfg; |
| 137 | struct snd_array kctls; |
| 138 | struct hda_input_mux private_imux[2]; |
| 139 | hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; |
| 140 | |
| 141 | /* HP mode source */ |
| 142 | const struct hda_input_mux *hp_mux; |
| 143 | unsigned int hp_independent_mode; |
| 144 | unsigned int hp_independent_mode_index; |
| 145 | unsigned int smart51_enabled; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 146 | unsigned int dmic_enabled; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 147 | enum VIA_HDA_CODEC codec_type; |
| 148 | |
| 149 | /* work to check hp jack state */ |
| 150 | struct hda_codec *codec; |
| 151 | struct delayed_work vt1708_hp_work; |
| 152 | int vt1708_jack_detectect; |
| 153 | int vt1708_hp_present; |
| 154 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 155 | struct hda_loopback_check loopback; |
| 156 | #endif |
| 157 | }; |
| 158 | |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 159 | static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 160 | { |
Lydia Wang | 744ff5f | 2009-10-10 19:07:26 +0800 | [diff] [blame] | 161 | u32 vendor_id = codec->vendor_id; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 162 | u16 ven_id = vendor_id >> 16; |
| 163 | u16 dev_id = vendor_id & 0xffff; |
| 164 | enum VIA_HDA_CODEC codec_type; |
| 165 | |
| 166 | /* get codec type */ |
| 167 | if (ven_id != 0x1106) |
| 168 | codec_type = UNKNOWN; |
| 169 | else if (dev_id >= 0x1708 && dev_id <= 0x170b) |
| 170 | codec_type = VT1708; |
| 171 | else if (dev_id >= 0xe710 && dev_id <= 0xe713) |
| 172 | codec_type = VT1709_10CH; |
| 173 | else if (dev_id >= 0xe714 && dev_id <= 0xe717) |
| 174 | codec_type = VT1709_6CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 175 | else if (dev_id >= 0xe720 && dev_id <= 0xe723) { |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 176 | codec_type = VT1708B_8CH; |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 177 | if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7) |
| 178 | codec_type = VT1708BCE; |
| 179 | } else if (dev_id >= 0xe724 && dev_id <= 0xe727) |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 180 | codec_type = VT1708B_4CH; |
| 181 | else if ((dev_id & 0xfff) == 0x397 |
| 182 | && (dev_id >> 12) < 8) |
| 183 | codec_type = VT1708S; |
| 184 | else if ((dev_id & 0xfff) == 0x398 |
| 185 | && (dev_id >> 12) < 8) |
| 186 | codec_type = VT1702; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 187 | else if ((dev_id & 0xfff) == 0x428 |
| 188 | && (dev_id >> 12) < 8) |
| 189 | codec_type = VT1718S; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 190 | else if (dev_id == 0x0433 || dev_id == 0xa721) |
| 191 | codec_type = VT1716S; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 192 | else if (dev_id == 0x0441 || dev_id == 0x4441) |
| 193 | codec_type = VT1718S; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 194 | else if (dev_id == 0x0438 || dev_id == 0x4438) |
| 195 | codec_type = VT2002P; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 196 | else if (dev_id == 0x0448) |
| 197 | codec_type = VT1812; |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 198 | else |
| 199 | codec_type = UNKNOWN; |
| 200 | return codec_type; |
| 201 | }; |
| 202 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 203 | #define VIA_HP_EVENT 0x01 |
| 204 | #define VIA_GPIO_EVENT 0x02 |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 205 | #define VIA_JACK_EVENT 0x04 |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 206 | #define VIA_MONO_EVENT 0x08 |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 207 | #define VIA_SPEAKER_EVENT 0x10 |
| 208 | #define VIA_BIND_HP_EVENT 0x20 |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 209 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 210 | enum { |
| 211 | VIA_CTL_WIDGET_VOL, |
| 212 | VIA_CTL_WIDGET_MUTE, |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 213 | VIA_CTL_WIDGET_ANALOG_MUTE, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 214 | VIA_CTL_WIDGET_BIND_PIN_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | enum { |
Harald Welte | eb14a46 | 2008-09-09 15:40:38 +0800 | [diff] [blame] | 218 | AUTO_SEQ_FRONT = 0, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 219 | AUTO_SEQ_SURROUND, |
| 220 | AUTO_SEQ_CENLFE, |
| 221 | AUTO_SEQ_SIDE |
| 222 | }; |
| 223 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 224 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle); |
| 225 | static void set_jack_power_state(struct hda_codec *codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 226 | static int is_aa_path_mute(struct hda_codec *codec); |
| 227 | |
| 228 | static void vt1708_start_hp_work(struct via_spec *spec) |
| 229 | { |
| 230 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 231 | return; |
| 232 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
| 233 | !spec->vt1708_jack_detectect); |
| 234 | if (!delayed_work_pending(&spec->vt1708_hp_work)) |
| 235 | schedule_delayed_work(&spec->vt1708_hp_work, |
| 236 | msecs_to_jiffies(100)); |
| 237 | } |
| 238 | |
| 239 | static void vt1708_stop_hp_work(struct via_spec *spec) |
| 240 | { |
| 241 | if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) |
| 242 | return; |
| 243 | if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 |
| 244 | && !is_aa_path_mute(spec->codec)) |
| 245 | return; |
| 246 | snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, |
| 247 | !spec->vt1708_jack_detectect); |
| 248 | cancel_delayed_work(&spec->vt1708_hp_work); |
| 249 | flush_scheduled_work(); |
| 250 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 251 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 252 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 253 | static int analog_input_switch_put(struct snd_kcontrol *kcontrol, |
| 254 | struct snd_ctl_elem_value *ucontrol) |
| 255 | { |
| 256 | int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol); |
| 257 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 258 | |
| 259 | set_jack_power_state(codec); |
| 260 | analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 261 | if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { |
| 262 | if (is_aa_path_mute(codec)) |
| 263 | vt1708_start_hp_work(codec->spec); |
| 264 | else |
| 265 | vt1708_stop_hp_work(codec->spec); |
| 266 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 267 | return change; |
| 268 | } |
| 269 | |
| 270 | /* modify .put = snd_hda_mixer_amp_switch_put */ |
| 271 | #define ANALOG_INPUT_MUTE \ |
| 272 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 273 | .name = NULL, \ |
| 274 | .index = 0, \ |
| 275 | .info = snd_hda_mixer_amp_switch_info, \ |
| 276 | .get = snd_hda_mixer_amp_switch_get, \ |
| 277 | .put = analog_input_switch_put, \ |
| 278 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 279 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 280 | static void via_hp_bind_automute(struct hda_codec *codec); |
| 281 | |
| 282 | static int bind_pin_switch_put(struct snd_kcontrol *kcontrol, |
| 283 | struct snd_ctl_elem_value *ucontrol) |
| 284 | { |
| 285 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 286 | struct via_spec *spec = codec->spec; |
| 287 | int i; |
| 288 | int change = 0; |
| 289 | |
| 290 | long *valp = ucontrol->value.integer.value; |
| 291 | int lmute, rmute; |
| 292 | if (strstr(kcontrol->id.name, "Switch") == NULL) { |
| 293 | snd_printd("Invalid control!\n"); |
| 294 | return change; |
| 295 | } |
| 296 | change = snd_hda_mixer_amp_switch_put(kcontrol, |
| 297 | ucontrol); |
| 298 | /* Get mute value */ |
| 299 | lmute = *valp ? 0 : HDA_AMP_MUTE; |
| 300 | valp++; |
| 301 | rmute = *valp ? 0 : HDA_AMP_MUTE; |
| 302 | |
| 303 | /* Set hp pins */ |
| 304 | if (!spec->hp_independent_mode) { |
| 305 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
| 306 | snd_hda_codec_amp_update( |
| 307 | codec, spec->autocfg.hp_pins[i], |
| 308 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 309 | lmute); |
| 310 | snd_hda_codec_amp_update( |
| 311 | codec, spec->autocfg.hp_pins[i], |
| 312 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 313 | rmute); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (!lmute && !rmute) { |
| 318 | /* Line Outs */ |
| 319 | for (i = 0; i < spec->autocfg.line_outs; i++) |
| 320 | snd_hda_codec_amp_stereo( |
| 321 | codec, spec->autocfg.line_out_pins[i], |
| 322 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 323 | /* Speakers */ |
| 324 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 325 | snd_hda_codec_amp_stereo( |
| 326 | codec, spec->autocfg.speaker_pins[i], |
| 327 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 328 | /* unmute */ |
| 329 | via_hp_bind_automute(codec); |
| 330 | |
| 331 | } else { |
| 332 | if (lmute) { |
| 333 | /* Mute all left channels */ |
| 334 | for (i = 1; i < spec->autocfg.line_outs; i++) |
| 335 | snd_hda_codec_amp_update( |
| 336 | codec, |
| 337 | spec->autocfg.line_out_pins[i], |
| 338 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 339 | lmute); |
| 340 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 341 | snd_hda_codec_amp_update( |
| 342 | codec, |
| 343 | spec->autocfg.speaker_pins[i], |
| 344 | 0, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 345 | lmute); |
| 346 | } |
| 347 | if (rmute) { |
| 348 | /* mute all right channels */ |
| 349 | for (i = 1; i < spec->autocfg.line_outs; i++) |
| 350 | snd_hda_codec_amp_update( |
| 351 | codec, |
| 352 | spec->autocfg.line_out_pins[i], |
| 353 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 354 | rmute); |
| 355 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 356 | snd_hda_codec_amp_update( |
| 357 | codec, |
| 358 | spec->autocfg.speaker_pins[i], |
| 359 | 1, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 360 | rmute); |
| 361 | } |
| 362 | } |
| 363 | return change; |
| 364 | } |
| 365 | |
| 366 | #define BIND_PIN_MUTE \ |
| 367 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 368 | .name = NULL, \ |
| 369 | .index = 0, \ |
| 370 | .info = snd_hda_mixer_amp_switch_info, \ |
| 371 | .get = snd_hda_mixer_amp_switch_get, \ |
| 372 | .put = bind_pin_switch_put, \ |
| 373 | .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) } |
| 374 | |
Lydia Wang | 71eb7dc | 2009-10-10 19:08:49 +0800 | [diff] [blame] | 375 | static struct snd_kcontrol_new via_control_templates[] = { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 376 | HDA_CODEC_VOLUME(NULL, 0, 0, 0), |
| 377 | HDA_CODEC_MUTE(NULL, 0, 0, 0), |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 378 | ANALOG_INPUT_MUTE, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 379 | BIND_PIN_MUTE, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 380 | }; |
| 381 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 382 | static hda_nid_t vt1708_adc_nids[2] = { |
| 383 | /* ADC1-2 */ |
| 384 | 0x15, 0x27 |
| 385 | }; |
| 386 | |
| 387 | static hda_nid_t vt1709_adc_nids[3] = { |
| 388 | /* ADC1-2 */ |
| 389 | 0x14, 0x15, 0x16 |
| 390 | }; |
| 391 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 392 | static hda_nid_t vt1708B_adc_nids[2] = { |
| 393 | /* ADC1-2 */ |
| 394 | 0x13, 0x14 |
| 395 | }; |
| 396 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 397 | static hda_nid_t vt1708S_adc_nids[2] = { |
| 398 | /* ADC1-2 */ |
| 399 | 0x13, 0x14 |
| 400 | }; |
| 401 | |
| 402 | static hda_nid_t vt1702_adc_nids[3] = { |
| 403 | /* ADC1-2 */ |
| 404 | 0x12, 0x20, 0x1F |
| 405 | }; |
| 406 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 407 | static hda_nid_t vt1718S_adc_nids[2] = { |
| 408 | /* ADC1-2 */ |
| 409 | 0x10, 0x11 |
| 410 | }; |
| 411 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 412 | static hda_nid_t vt1716S_adc_nids[2] = { |
| 413 | /* ADC1-2 */ |
| 414 | 0x13, 0x14 |
| 415 | }; |
| 416 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 417 | static hda_nid_t vt2002P_adc_nids[2] = { |
| 418 | /* ADC1-2 */ |
| 419 | 0x10, 0x11 |
| 420 | }; |
| 421 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 422 | static hda_nid_t vt1812_adc_nids[2] = { |
| 423 | /* ADC1-2 */ |
| 424 | 0x10, 0x11 |
| 425 | }; |
| 426 | |
| 427 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 428 | /* add dynamic controls */ |
| 429 | static int via_add_control(struct via_spec *spec, int type, const char *name, |
| 430 | unsigned long val) |
| 431 | { |
| 432 | struct snd_kcontrol_new *knew; |
| 433 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 434 | snd_array_init(&spec->kctls, sizeof(*knew), 32); |
| 435 | knew = snd_array_new(&spec->kctls); |
| 436 | if (!knew) |
| 437 | return -ENOMEM; |
Lydia Wang | 71eb7dc | 2009-10-10 19:08:49 +0800 | [diff] [blame] | 438 | *knew = via_control_templates[type]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 439 | knew->name = kstrdup(name, GFP_KERNEL); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 440 | if (!knew->name) |
| 441 | return -ENOMEM; |
| 442 | knew->private_value = val; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 443 | return 0; |
| 444 | } |
| 445 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 446 | static void via_free_kctls(struct hda_codec *codec) |
| 447 | { |
| 448 | struct via_spec *spec = codec->spec; |
| 449 | |
| 450 | if (spec->kctls.list) { |
| 451 | struct snd_kcontrol_new *kctl = spec->kctls.list; |
| 452 | int i; |
| 453 | for (i = 0; i < spec->kctls.used; i++) |
| 454 | kfree(kctl[i].name); |
| 455 | } |
| 456 | snd_array_free(&spec->kctls); |
| 457 | } |
| 458 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 459 | /* create input playback/capture controls for the given pin */ |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 460 | static int via_new_analog_input(struct via_spec *spec, const char *ctlname, |
| 461 | int idx, int mix_nid) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 462 | { |
| 463 | char name[32]; |
| 464 | int err; |
| 465 | |
| 466 | sprintf(name, "%s Playback Volume", ctlname); |
| 467 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 468 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 469 | if (err < 0) |
| 470 | return err; |
| 471 | sprintf(name, "%s Playback Switch", ctlname); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 472 | err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 473 | HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT)); |
| 474 | if (err < 0) |
| 475 | return err; |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static void via_auto_set_output_and_unmute(struct hda_codec *codec, |
| 480 | hda_nid_t nid, int pin_type, |
| 481 | int dac_idx) |
| 482 | { |
| 483 | /* set as output */ |
| 484 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 485 | pin_type); |
| 486 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 487 | AMP_OUT_UNMUTE); |
Takashi Iwai | d3a11e6 | 2009-07-07 13:43:35 +0200 | [diff] [blame] | 488 | if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD) |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 489 | snd_hda_codec_write(codec, nid, 0, |
Takashi Iwai | d3a11e6 | 2009-07-07 13:43:35 +0200 | [diff] [blame] | 490 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | |
| 494 | static void via_auto_init_multi_out(struct hda_codec *codec) |
| 495 | { |
| 496 | struct via_spec *spec = codec->spec; |
| 497 | int i; |
| 498 | |
| 499 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 500 | hda_nid_t nid = spec->autocfg.line_out_pins[i]; |
| 501 | if (nid) |
| 502 | via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | static void via_auto_init_hp_out(struct hda_codec *codec) |
| 507 | { |
| 508 | struct via_spec *spec = codec->spec; |
| 509 | hda_nid_t pin; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 510 | int i; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 511 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 512 | for (i = 0; i < spec->autocfg.hp_outs; i++) { |
| 513 | pin = spec->autocfg.hp_pins[i]; |
| 514 | if (pin) /* connect to front */ |
| 515 | via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); |
| 516 | } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | static void via_auto_init_analog_input(struct hda_codec *codec) |
| 520 | { |
| 521 | struct via_spec *spec = codec->spec; |
| 522 | int i; |
| 523 | |
| 524 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 525 | hda_nid_t nid = spec->autocfg.input_pins[i]; |
| 526 | |
| 527 | snd_hda_codec_write(codec, nid, 0, |
| 528 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 529 | (i <= AUTO_PIN_FRONT_MIC ? |
| 530 | PIN_VREF50 : PIN_IN)); |
| 531 | |
| 532 | } |
| 533 | } |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 534 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 535 | static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin); |
| 536 | |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 537 | static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid, |
| 538 | unsigned int *affected_parm) |
| 539 | { |
| 540 | unsigned parm; |
| 541 | unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid); |
| 542 | unsigned no_presence = (def_conf & AC_DEFCFG_MISC) |
| 543 | >> AC_DEFCFG_MISC_SHIFT |
| 544 | & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */ |
| 545 | unsigned present = snd_hda_codec_read(codec, nid, 0, |
| 546 | AC_VERB_GET_PIN_SENSE, 0) >> 31; |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 547 | struct via_spec *spec = codec->spec; |
| 548 | if ((spec->smart51_enabled && is_smart51_pins(spec, nid)) |
| 549 | || ((no_presence || present) |
| 550 | && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) { |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 551 | *affected_parm = AC_PWRST_D0; /* if it's connected */ |
| 552 | parm = AC_PWRST_D0; |
| 553 | } else |
| 554 | parm = AC_PWRST_D3; |
| 555 | |
| 556 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm); |
| 557 | } |
| 558 | |
| 559 | static void set_jack_power_state(struct hda_codec *codec) |
| 560 | { |
| 561 | struct via_spec *spec = codec->spec; |
| 562 | int imux_is_smixer; |
| 563 | unsigned int parm; |
| 564 | |
| 565 | if (spec->codec_type == VT1702) { |
| 566 | imux_is_smixer = snd_hda_codec_read( |
| 567 | codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 568 | /* inputs */ |
| 569 | /* PW 1/2/5 (14h/15h/18h) */ |
| 570 | parm = AC_PWRST_D3; |
| 571 | set_pin_power_state(codec, 0x14, &parm); |
| 572 | set_pin_power_state(codec, 0x15, &parm); |
| 573 | set_pin_power_state(codec, 0x18, &parm); |
| 574 | if (imux_is_smixer) |
| 575 | parm = AC_PWRST_D0; /* SW0 = stereo mixer (idx 3) */ |
| 576 | /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */ |
| 577 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, |
| 578 | parm); |
| 579 | snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, |
| 580 | parm); |
| 581 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, |
| 582 | parm); |
| 583 | snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, |
| 584 | parm); |
| 585 | |
| 586 | /* outputs */ |
| 587 | /* PW 3/4 (16h/17h) */ |
| 588 | parm = AC_PWRST_D3; |
| 589 | set_pin_power_state(codec, 0x16, &parm); |
| 590 | set_pin_power_state(codec, 0x17, &parm); |
| 591 | /* MW0 (1ah), AOW 0/1 (10h/1dh) */ |
| 592 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, |
| 593 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 594 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 595 | parm); |
| 596 | snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, |
| 597 | parm); |
| 598 | } else if (spec->codec_type == VT1708B_8CH |
| 599 | || spec->codec_type == VT1708B_4CH |
| 600 | || spec->codec_type == VT1708S) { |
| 601 | /* SW0 (17h) = stereo mixer */ |
| 602 | int is_8ch = spec->codec_type != VT1708B_4CH; |
| 603 | imux_is_smixer = snd_hda_codec_read( |
| 604 | codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) |
| 605 | == ((spec->codec_type == VT1708S) ? 5 : 0); |
| 606 | /* inputs */ |
| 607 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 608 | parm = AC_PWRST_D3; |
| 609 | set_pin_power_state(codec, 0x1a, &parm); |
| 610 | set_pin_power_state(codec, 0x1b, &parm); |
| 611 | set_pin_power_state(codec, 0x1e, &parm); |
| 612 | if (imux_is_smixer) |
| 613 | parm = AC_PWRST_D0; |
| 614 | /* SW0 (17h), AIW 0/1 (13h/14h) */ |
| 615 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, |
| 616 | parm); |
| 617 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, |
| 618 | parm); |
| 619 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, |
| 620 | parm); |
| 621 | |
| 622 | /* outputs */ |
| 623 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 624 | parm = AC_PWRST_D3; |
| 625 | set_pin_power_state(codec, 0x19, &parm); |
| 626 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, |
| 627 | parm); |
| 628 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, |
| 629 | parm); |
| 630 | |
| 631 | /* PW6 (22h), SW2 (26h), AOW2 (24h) */ |
| 632 | if (is_8ch) { |
| 633 | parm = AC_PWRST_D3; |
| 634 | set_pin_power_state(codec, 0x22, &parm); |
| 635 | snd_hda_codec_write(codec, 0x26, 0, |
| 636 | AC_VERB_SET_POWER_STATE, parm); |
| 637 | snd_hda_codec_write(codec, 0x24, 0, |
| 638 | AC_VERB_SET_POWER_STATE, parm); |
| 639 | } |
| 640 | |
| 641 | /* PW 3/4/7 (1ch/1dh/23h) */ |
| 642 | parm = AC_PWRST_D3; |
| 643 | /* force to D0 for internal Speaker */ |
| 644 | set_pin_power_state(codec, 0x1c, &parm); |
| 645 | set_pin_power_state(codec, 0x1d, &parm); |
| 646 | if (is_8ch) |
| 647 | set_pin_power_state(codec, 0x23, &parm); |
| 648 | /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */ |
| 649 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 650 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 651 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 652 | parm); |
| 653 | if (is_8ch) { |
| 654 | snd_hda_codec_write(codec, 0x25, 0, |
| 655 | AC_VERB_SET_POWER_STATE, parm); |
| 656 | snd_hda_codec_write(codec, 0x27, 0, |
| 657 | AC_VERB_SET_POWER_STATE, parm); |
| 658 | } |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 659 | } else if (spec->codec_type == VT1718S) { |
| 660 | /* MUX6 (1eh) = stereo mixer */ |
| 661 | imux_is_smixer = snd_hda_codec_read( |
| 662 | codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 663 | /* inputs */ |
| 664 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 665 | parm = AC_PWRST_D3; |
| 666 | set_pin_power_state(codec, 0x29, &parm); |
| 667 | set_pin_power_state(codec, 0x2a, &parm); |
| 668 | set_pin_power_state(codec, 0x2b, &parm); |
| 669 | if (imux_is_smixer) |
| 670 | parm = AC_PWRST_D0; |
| 671 | /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 672 | snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, |
| 673 | parm); |
| 674 | snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, |
| 675 | parm); |
| 676 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 677 | parm); |
| 678 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, |
| 679 | parm); |
| 680 | |
| 681 | /* outputs */ |
| 682 | /* PW3 (27h), MW2 (1ah), AOW3 (bh) */ |
| 683 | parm = AC_PWRST_D3; |
| 684 | set_pin_power_state(codec, 0x27, &parm); |
| 685 | snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, |
| 686 | parm); |
| 687 | snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, |
| 688 | parm); |
| 689 | |
| 690 | /* PW2 (26h), AOW2 (ah) */ |
| 691 | parm = AC_PWRST_D3; |
| 692 | set_pin_power_state(codec, 0x26, &parm); |
| 693 | snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, |
| 694 | parm); |
| 695 | |
| 696 | /* PW0/1 (24h/25h) */ |
| 697 | parm = AC_PWRST_D3; |
| 698 | set_pin_power_state(codec, 0x24, &parm); |
| 699 | set_pin_power_state(codec, 0x25, &parm); |
| 700 | if (!spec->hp_independent_mode) /* check for redirected HP */ |
| 701 | set_pin_power_state(codec, 0x28, &parm); |
| 702 | snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, |
| 703 | parm); |
| 704 | snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, |
| 705 | parm); |
| 706 | /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */ |
| 707 | snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE, |
| 708 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 709 | if (spec->hp_independent_mode) { |
| 710 | /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */ |
| 711 | parm = AC_PWRST_D3; |
| 712 | set_pin_power_state(codec, 0x28, &parm); |
| 713 | snd_hda_codec_write(codec, 0x1b, 0, |
| 714 | AC_VERB_SET_POWER_STATE, parm); |
| 715 | snd_hda_codec_write(codec, 0x34, 0, |
| 716 | AC_VERB_SET_POWER_STATE, parm); |
| 717 | snd_hda_codec_write(codec, 0xc, 0, |
| 718 | AC_VERB_SET_POWER_STATE, parm); |
| 719 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 720 | } else if (spec->codec_type == VT1716S) { |
| 721 | unsigned int mono_out, present; |
| 722 | /* SW0 (17h) = stereo mixer */ |
| 723 | imux_is_smixer = snd_hda_codec_read( |
| 724 | codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 725 | /* inputs */ |
| 726 | /* PW 1/2/5 (1ah/1bh/1eh) */ |
| 727 | parm = AC_PWRST_D3; |
| 728 | set_pin_power_state(codec, 0x1a, &parm); |
| 729 | set_pin_power_state(codec, 0x1b, &parm); |
| 730 | set_pin_power_state(codec, 0x1e, &parm); |
| 731 | if (imux_is_smixer) |
| 732 | parm = AC_PWRST_D0; |
| 733 | /* SW0 (17h), AIW0(13h) */ |
| 734 | snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, |
| 735 | parm); |
| 736 | snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, |
| 737 | parm); |
| 738 | |
| 739 | parm = AC_PWRST_D3; |
| 740 | set_pin_power_state(codec, 0x1e, &parm); |
| 741 | /* PW11 (22h) */ |
| 742 | if (spec->dmic_enabled) |
| 743 | set_pin_power_state(codec, 0x22, &parm); |
| 744 | else |
| 745 | snd_hda_codec_write( |
| 746 | codec, 0x22, 0, |
| 747 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 748 | |
| 749 | /* SW2(26h), AIW1(14h) */ |
| 750 | snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, |
| 751 | parm); |
| 752 | snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, |
| 753 | parm); |
| 754 | |
| 755 | /* outputs */ |
| 756 | /* PW0 (19h), SW1 (18h), AOW1 (11h) */ |
| 757 | parm = AC_PWRST_D3; |
| 758 | set_pin_power_state(codec, 0x19, &parm); |
| 759 | /* Smart 5.1 PW2(1bh) */ |
| 760 | if (spec->smart51_enabled) |
| 761 | set_pin_power_state(codec, 0x1b, &parm); |
| 762 | snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, |
| 763 | parm); |
| 764 | snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, |
| 765 | parm); |
| 766 | |
| 767 | /* PW7 (23h), SW3 (27h), AOW3 (25h) */ |
| 768 | parm = AC_PWRST_D3; |
| 769 | set_pin_power_state(codec, 0x23, &parm); |
| 770 | /* Smart 5.1 PW1(1ah) */ |
| 771 | if (spec->smart51_enabled) |
| 772 | set_pin_power_state(codec, 0x1a, &parm); |
| 773 | snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, |
| 774 | parm); |
| 775 | |
| 776 | /* Smart 5.1 PW5(1eh) */ |
| 777 | if (spec->smart51_enabled) |
| 778 | set_pin_power_state(codec, 0x1e, &parm); |
| 779 | snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, |
| 780 | parm); |
| 781 | |
| 782 | /* Mono out */ |
| 783 | /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/ |
| 784 | present = snd_hda_codec_read( |
| 785 | codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 786 | if (present) |
| 787 | mono_out = 0; |
| 788 | else { |
| 789 | present = snd_hda_codec_read( |
| 790 | codec, 0x1d, 0, AC_VERB_GET_PIN_SENSE, 0) |
| 791 | & 0x80000000; |
| 792 | if (!spec->hp_independent_mode && present) |
| 793 | mono_out = 0; |
| 794 | else |
| 795 | mono_out = 1; |
| 796 | } |
| 797 | parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3; |
| 798 | snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, |
| 799 | parm); |
| 800 | snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, |
| 801 | parm); |
| 802 | snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, |
| 803 | parm); |
| 804 | |
| 805 | /* PW 3/4 (1ch/1dh) */ |
| 806 | parm = AC_PWRST_D3; |
| 807 | set_pin_power_state(codec, 0x1c, &parm); |
| 808 | set_pin_power_state(codec, 0x1d, &parm); |
| 809 | /* HP Independent Mode, power on AOW3 */ |
| 810 | if (spec->hp_independent_mode) |
| 811 | snd_hda_codec_write(codec, 0x25, 0, |
| 812 | AC_VERB_SET_POWER_STATE, parm); |
| 813 | |
| 814 | /* force to D0 for internal Speaker */ |
| 815 | /* MW0 (16h), AOW0 (10h) */ |
| 816 | snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE, |
| 817 | imux_is_smixer ? AC_PWRST_D0 : parm); |
| 818 | snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, |
| 819 | mono_out ? AC_PWRST_D0 : parm); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 820 | } else if (spec->codec_type == VT2002P) { |
| 821 | unsigned int present; |
| 822 | /* MUX9 (1eh) = stereo mixer */ |
| 823 | imux_is_smixer = snd_hda_codec_read( |
| 824 | codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3; |
| 825 | /* inputs */ |
| 826 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 827 | parm = AC_PWRST_D3; |
| 828 | set_pin_power_state(codec, 0x29, &parm); |
| 829 | set_pin_power_state(codec, 0x2a, &parm); |
| 830 | set_pin_power_state(codec, 0x2b, &parm); |
| 831 | if (imux_is_smixer) |
| 832 | parm = AC_PWRST_D0; |
| 833 | /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 834 | snd_hda_codec_write(codec, 0x1e, 0, |
| 835 | AC_VERB_SET_POWER_STATE, parm); |
| 836 | snd_hda_codec_write(codec, 0x1f, 0, |
| 837 | AC_VERB_SET_POWER_STATE, parm); |
| 838 | snd_hda_codec_write(codec, 0x10, 0, |
| 839 | AC_VERB_SET_POWER_STATE, parm); |
| 840 | snd_hda_codec_write(codec, 0x11, 0, |
| 841 | AC_VERB_SET_POWER_STATE, parm); |
| 842 | |
| 843 | /* outputs */ |
| 844 | /* AOW0 (8h)*/ |
| 845 | snd_hda_codec_write(codec, 0x8, 0, |
| 846 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 847 | |
| 848 | /* PW4 (26h), MW4 (1ch), MUX4(37h) */ |
| 849 | parm = AC_PWRST_D3; |
| 850 | set_pin_power_state(codec, 0x26, &parm); |
| 851 | snd_hda_codec_write(codec, 0x1c, 0, |
| 852 | AC_VERB_SET_POWER_STATE, parm); |
| 853 | snd_hda_codec_write(codec, 0x37, |
| 854 | 0, AC_VERB_SET_POWER_STATE, parm); |
| 855 | |
| 856 | /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */ |
| 857 | parm = AC_PWRST_D3; |
| 858 | set_pin_power_state(codec, 0x25, &parm); |
| 859 | snd_hda_codec_write(codec, 0x19, 0, |
| 860 | AC_VERB_SET_POWER_STATE, parm); |
| 861 | snd_hda_codec_write(codec, 0x35, 0, |
| 862 | AC_VERB_SET_POWER_STATE, parm); |
| 863 | if (spec->hp_independent_mode) { |
| 864 | snd_hda_codec_write(codec, 0x9, 0, |
| 865 | AC_VERB_SET_POWER_STATE, parm); |
| 866 | } |
| 867 | |
| 868 | /* Class-D */ |
| 869 | /* PW0 (24h), MW0(18h), MUX0(34h) */ |
| 870 | present = snd_hda_codec_read( |
| 871 | codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 872 | parm = AC_PWRST_D3; |
| 873 | set_pin_power_state(codec, 0x24, &parm); |
| 874 | if (present) { |
| 875 | snd_hda_codec_write( |
| 876 | codec, 0x18, 0, |
| 877 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 878 | snd_hda_codec_write( |
| 879 | codec, 0x34, 0, |
| 880 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 881 | } else { |
| 882 | snd_hda_codec_write( |
| 883 | codec, 0x18, 0, |
| 884 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 885 | snd_hda_codec_write( |
| 886 | codec, 0x34, 0, |
| 887 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 888 | } |
| 889 | |
| 890 | /* Mono Out */ |
| 891 | /* PW15 (31h), MW8(17h), MUX8(3bh) */ |
| 892 | present = snd_hda_codec_read( |
| 893 | codec, 0x26, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 894 | parm = AC_PWRST_D3; |
| 895 | set_pin_power_state(codec, 0x31, &parm); |
| 896 | if (present) { |
| 897 | snd_hda_codec_write( |
| 898 | codec, 0x17, 0, |
| 899 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 900 | snd_hda_codec_write( |
| 901 | codec, 0x3b, 0, |
| 902 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 903 | } else { |
| 904 | snd_hda_codec_write( |
| 905 | codec, 0x17, 0, |
| 906 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 907 | snd_hda_codec_write( |
| 908 | codec, 0x3b, 0, |
| 909 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 910 | } |
| 911 | |
| 912 | /* MW9 (21h) */ |
| 913 | if (imux_is_smixer || !is_aa_path_mute(codec)) |
| 914 | snd_hda_codec_write( |
| 915 | codec, 0x21, 0, |
| 916 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 917 | else |
| 918 | snd_hda_codec_write( |
| 919 | codec, 0x21, 0, |
| 920 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 921 | } else if (spec->codec_type == VT1812) { |
| 922 | unsigned int present; |
| 923 | /* MUX10 (1eh) = stereo mixer */ |
| 924 | imux_is_smixer = snd_hda_codec_read( |
| 925 | codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5; |
| 926 | /* inputs */ |
| 927 | /* PW 5/6/7 (29h/2ah/2bh) */ |
| 928 | parm = AC_PWRST_D3; |
| 929 | set_pin_power_state(codec, 0x29, &parm); |
| 930 | set_pin_power_state(codec, 0x2a, &parm); |
| 931 | set_pin_power_state(codec, 0x2b, &parm); |
| 932 | if (imux_is_smixer) |
| 933 | parm = AC_PWRST_D0; |
| 934 | /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */ |
| 935 | snd_hda_codec_write(codec, 0x1e, 0, |
| 936 | AC_VERB_SET_POWER_STATE, parm); |
| 937 | snd_hda_codec_write(codec, 0x1f, 0, |
| 938 | AC_VERB_SET_POWER_STATE, parm); |
| 939 | snd_hda_codec_write(codec, 0x10, 0, |
| 940 | AC_VERB_SET_POWER_STATE, parm); |
| 941 | snd_hda_codec_write(codec, 0x11, 0, |
| 942 | AC_VERB_SET_POWER_STATE, parm); |
| 943 | |
| 944 | /* outputs */ |
| 945 | /* AOW0 (8h)*/ |
| 946 | snd_hda_codec_write(codec, 0x8, 0, |
| 947 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 948 | |
| 949 | /* PW4 (28h), MW4 (18h), MUX4(38h) */ |
| 950 | parm = AC_PWRST_D3; |
| 951 | set_pin_power_state(codec, 0x28, &parm); |
| 952 | snd_hda_codec_write(codec, 0x18, 0, |
| 953 | AC_VERB_SET_POWER_STATE, parm); |
| 954 | snd_hda_codec_write(codec, 0x38, 0, |
| 955 | AC_VERB_SET_POWER_STATE, parm); |
| 956 | |
| 957 | /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */ |
| 958 | parm = AC_PWRST_D3; |
| 959 | set_pin_power_state(codec, 0x25, &parm); |
| 960 | snd_hda_codec_write(codec, 0x15, 0, |
| 961 | AC_VERB_SET_POWER_STATE, parm); |
| 962 | snd_hda_codec_write(codec, 0x35, 0, |
| 963 | AC_VERB_SET_POWER_STATE, parm); |
| 964 | if (spec->hp_independent_mode) { |
| 965 | snd_hda_codec_write(codec, 0x9, 0, |
| 966 | AC_VERB_SET_POWER_STATE, parm); |
| 967 | } |
| 968 | |
| 969 | /* Internal Speaker */ |
| 970 | /* PW0 (24h), MW0(14h), MUX0(34h) */ |
| 971 | present = snd_hda_codec_read( |
| 972 | codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 973 | parm = AC_PWRST_D3; |
| 974 | set_pin_power_state(codec, 0x24, &parm); |
| 975 | if (present) { |
| 976 | snd_hda_codec_write(codec, 0x14, 0, |
| 977 | AC_VERB_SET_POWER_STATE, |
| 978 | AC_PWRST_D3); |
| 979 | snd_hda_codec_write(codec, 0x34, 0, |
| 980 | AC_VERB_SET_POWER_STATE, |
| 981 | AC_PWRST_D3); |
| 982 | } else { |
| 983 | snd_hda_codec_write(codec, 0x14, 0, |
| 984 | AC_VERB_SET_POWER_STATE, |
| 985 | AC_PWRST_D0); |
| 986 | snd_hda_codec_write(codec, 0x34, 0, |
| 987 | AC_VERB_SET_POWER_STATE, |
| 988 | AC_PWRST_D0); |
| 989 | } |
| 990 | /* Mono Out */ |
| 991 | /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */ |
| 992 | present = snd_hda_codec_read( |
| 993 | codec, 0x28, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 994 | parm = AC_PWRST_D3; |
| 995 | set_pin_power_state(codec, 0x31, &parm); |
| 996 | if (present) { |
| 997 | snd_hda_codec_write(codec, 0x1c, 0, |
| 998 | AC_VERB_SET_POWER_STATE, |
| 999 | AC_PWRST_D3); |
| 1000 | snd_hda_codec_write(codec, 0x3c, 0, |
| 1001 | AC_VERB_SET_POWER_STATE, |
| 1002 | AC_PWRST_D3); |
| 1003 | snd_hda_codec_write(codec, 0x3e, 0, |
| 1004 | AC_VERB_SET_POWER_STATE, |
| 1005 | AC_PWRST_D3); |
| 1006 | } else { |
| 1007 | snd_hda_codec_write(codec, 0x1c, 0, |
| 1008 | AC_VERB_SET_POWER_STATE, |
| 1009 | AC_PWRST_D0); |
| 1010 | snd_hda_codec_write(codec, 0x3c, 0, |
| 1011 | AC_VERB_SET_POWER_STATE, |
| 1012 | AC_PWRST_D0); |
| 1013 | snd_hda_codec_write(codec, 0x3e, 0, |
| 1014 | AC_VERB_SET_POWER_STATE, |
| 1015 | AC_PWRST_D0); |
| 1016 | } |
| 1017 | |
| 1018 | /* PW15 (33h), MW15 (1dh), MUX15(3dh) */ |
| 1019 | parm = AC_PWRST_D3; |
| 1020 | set_pin_power_state(codec, 0x33, &parm); |
| 1021 | snd_hda_codec_write(codec, 0x1d, 0, |
| 1022 | AC_VERB_SET_POWER_STATE, parm); |
| 1023 | snd_hda_codec_write(codec, 0x3d, 0, |
| 1024 | AC_VERB_SET_POWER_STATE, parm); |
| 1025 | |
| 1026 | /* MW9 (21h) */ |
| 1027 | if (imux_is_smixer || !is_aa_path_mute(codec)) |
| 1028 | snd_hda_codec_write( |
| 1029 | codec, 0x21, 0, |
| 1030 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 1031 | else |
| 1032 | snd_hda_codec_write( |
| 1033 | codec, 0x21, 0, |
| 1034 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1038 | /* |
| 1039 | * input MUX handling |
| 1040 | */ |
| 1041 | static int via_mux_enum_info(struct snd_kcontrol *kcontrol, |
| 1042 | struct snd_ctl_elem_info *uinfo) |
| 1043 | { |
| 1044 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1045 | struct via_spec *spec = codec->spec; |
| 1046 | return snd_hda_input_mux_info(spec->input_mux, uinfo); |
| 1047 | } |
| 1048 | |
| 1049 | static int via_mux_enum_get(struct snd_kcontrol *kcontrol, |
| 1050 | struct snd_ctl_elem_value *ucontrol) |
| 1051 | { |
| 1052 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1053 | struct via_spec *spec = codec->spec; |
| 1054 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 1055 | |
| 1056 | ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx]; |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | static int via_mux_enum_put(struct snd_kcontrol *kcontrol, |
| 1061 | struct snd_ctl_elem_value *ucontrol) |
| 1062 | { |
| 1063 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1064 | struct via_spec *spec = codec->spec; |
| 1065 | unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1066 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 1067 | if (!spec->mux_nids[adc_idx]) |
| 1068 | return -EINVAL; |
Lydia Wang | a80e6e3 | 2009-10-10 19:07:55 +0800 | [diff] [blame] | 1069 | /* switch to D0 beofre change index */ |
| 1070 | if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0, |
| 1071 | AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0) |
| 1072 | snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0, |
| 1073 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 1074 | /* update jack power state */ |
| 1075 | set_jack_power_state(codec); |
| 1076 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 1077 | return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, |
| 1078 | spec->mux_nids[adc_idx], |
| 1079 | &spec->cur_mux[adc_idx]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1080 | } |
| 1081 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1082 | static int via_independent_hp_info(struct snd_kcontrol *kcontrol, |
| 1083 | struct snd_ctl_elem_info *uinfo) |
| 1084 | { |
| 1085 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1086 | struct via_spec *spec = codec->spec; |
| 1087 | return snd_hda_input_mux_info(spec->hp_mux, uinfo); |
| 1088 | } |
| 1089 | |
| 1090 | static int via_independent_hp_get(struct snd_kcontrol *kcontrol, |
| 1091 | struct snd_ctl_elem_value *ucontrol) |
| 1092 | { |
| 1093 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1094 | struct via_spec *spec = codec->spec; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1095 | hda_nid_t nid; |
| 1096 | unsigned int pinsel; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1097 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1098 | switch (spec->codec_type) { |
| 1099 | case VT1718S: |
| 1100 | nid = 0x34; |
| 1101 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1102 | case VT2002P: |
| 1103 | nid = 0x35; |
| 1104 | break; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1105 | case VT1812: |
| 1106 | nid = 0x3d; |
| 1107 | break; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1108 | default: |
| 1109 | nid = spec->autocfg.hp_pins[0]; |
| 1110 | break; |
| 1111 | } |
| 1112 | /* use !! to translate conn sel 2 for VT1718S */ |
| 1113 | pinsel = !!snd_hda_codec_read(codec, nid, 0, |
| 1114 | AC_VERB_GET_CONNECT_SEL, |
| 1115 | 0x00); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1116 | ucontrol->value.enumerated.item[0] = pinsel; |
| 1117 | |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 1121 | static void activate_ctl(struct hda_codec *codec, const char *name, int active) |
| 1122 | { |
| 1123 | struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name); |
| 1124 | if (ctl) { |
| 1125 | ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 1126 | ctl->vd[0].access |= active |
| 1127 | ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 1128 | snd_ctl_notify(codec->bus->card, |
| 1129 | SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id); |
| 1130 | } |
| 1131 | } |
| 1132 | |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 1133 | static int update_side_mute_status(struct hda_codec *codec) |
| 1134 | { |
| 1135 | /* mute side channel */ |
| 1136 | struct via_spec *spec = codec->spec; |
| 1137 | unsigned int parm = spec->hp_independent_mode |
| 1138 | ? AMP_OUT_MUTE : AMP_OUT_UNMUTE; |
| 1139 | hda_nid_t sw3; |
| 1140 | |
| 1141 | switch (spec->codec_type) { |
| 1142 | case VT1708: |
| 1143 | sw3 = 0x1b; |
| 1144 | break; |
| 1145 | case VT1709_10CH: |
| 1146 | sw3 = 0x29; |
| 1147 | break; |
| 1148 | case VT1708B_8CH: |
| 1149 | case VT1708S: |
| 1150 | sw3 = 0x27; |
| 1151 | break; |
| 1152 | default: |
| 1153 | sw3 = 0; |
| 1154 | break; |
| 1155 | } |
| 1156 | |
| 1157 | if (sw3) |
| 1158 | snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE, |
| 1159 | parm); |
| 1160 | return 0; |
| 1161 | } |
| 1162 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1163 | static int via_independent_hp_put(struct snd_kcontrol *kcontrol, |
| 1164 | struct snd_ctl_elem_value *ucontrol) |
| 1165 | { |
| 1166 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1167 | struct via_spec *spec = codec->spec; |
| 1168 | hda_nid_t nid = spec->autocfg.hp_pins[0]; |
| 1169 | unsigned int pinsel = ucontrol->value.enumerated.item[0]; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 1170 | /* Get Independent Mode index of headphone pin widget */ |
| 1171 | spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel |
| 1172 | ? 1 : 0; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1173 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1174 | switch (spec->codec_type) { |
| 1175 | case VT1718S: |
| 1176 | nid = 0x34; |
| 1177 | pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */ |
| 1178 | spec->multiout.num_dacs = 4; |
| 1179 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1180 | case VT2002P: |
| 1181 | nid = 0x35; |
| 1182 | break; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1183 | case VT1812: |
| 1184 | nid = 0x3d; |
| 1185 | break; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1186 | default: |
| 1187 | nid = spec->autocfg.hp_pins[0]; |
| 1188 | break; |
| 1189 | } |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 1190 | snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1191 | |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 1192 | if (spec->multiout.hp_nid && spec->multiout.hp_nid |
| 1193 | != spec->multiout.dac_nids[HDA_FRONT]) |
| 1194 | snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid, |
| 1195 | 0, 0, 0); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1196 | |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 1197 | update_side_mute_status(codec); |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 1198 | /* update HP volume/swtich active state */ |
| 1199 | if (spec->codec_type == VT1708S |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1200 | || spec->codec_type == VT1702 |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1201 | || spec->codec_type == VT1718S |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1202 | || spec->codec_type == VT1716S |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1203 | || spec->codec_type == VT2002P |
| 1204 | || spec->codec_type == VT1812) { |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 1205 | activate_ctl(codec, "Headphone Playback Volume", |
| 1206 | spec->hp_independent_mode); |
| 1207 | activate_ctl(codec, "Headphone Playback Switch", |
| 1208 | spec->hp_independent_mode); |
| 1209 | } |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1210 | return 0; |
| 1211 | } |
| 1212 | |
| 1213 | static struct snd_kcontrol_new via_hp_mixer[] = { |
| 1214 | { |
| 1215 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1216 | .name = "Independent HP", |
| 1217 | .count = 1, |
| 1218 | .info = via_independent_hp_info, |
| 1219 | .get = via_independent_hp_get, |
| 1220 | .put = via_independent_hp_put, |
| 1221 | }, |
| 1222 | { } /* end */ |
| 1223 | }; |
| 1224 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1225 | static void notify_aa_path_ctls(struct hda_codec *codec) |
| 1226 | { |
| 1227 | int i; |
| 1228 | struct snd_ctl_elem_id id; |
| 1229 | const char *labels[] = {"Mic", "Front Mic", "Line"}; |
| 1230 | |
| 1231 | memset(&id, 0, sizeof(id)); |
| 1232 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 1233 | for (i = 0; i < ARRAY_SIZE(labels); i++) { |
| 1234 | sprintf(id.name, "%s Playback Volume", labels[i]); |
| 1235 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 1236 | &id); |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | static void mute_aa_path(struct hda_codec *codec, int mute) |
| 1241 | { |
| 1242 | struct via_spec *spec = codec->spec; |
| 1243 | hda_nid_t nid_mixer; |
| 1244 | int start_idx; |
| 1245 | int end_idx; |
| 1246 | int i; |
| 1247 | /* get nid of MW0 and start & end index */ |
| 1248 | switch (spec->codec_type) { |
| 1249 | case VT1708: |
| 1250 | nid_mixer = 0x17; |
| 1251 | start_idx = 2; |
| 1252 | end_idx = 4; |
| 1253 | break; |
| 1254 | case VT1709_10CH: |
| 1255 | case VT1709_6CH: |
| 1256 | nid_mixer = 0x18; |
| 1257 | start_idx = 2; |
| 1258 | end_idx = 4; |
| 1259 | break; |
| 1260 | case VT1708B_8CH: |
| 1261 | case VT1708B_4CH: |
| 1262 | case VT1708S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1263 | case VT1716S: |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1264 | nid_mixer = 0x16; |
| 1265 | start_idx = 2; |
| 1266 | end_idx = 4; |
| 1267 | break; |
| 1268 | default: |
| 1269 | return; |
| 1270 | } |
| 1271 | /* check AA path's mute status */ |
| 1272 | for (i = start_idx; i <= end_idx; i++) { |
| 1273 | int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE; |
| 1274 | snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i, |
| 1275 | HDA_AMP_MUTE, val); |
| 1276 | } |
| 1277 | } |
| 1278 | static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin) |
| 1279 | { |
| 1280 | int res = 0; |
| 1281 | int index; |
| 1282 | for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) { |
| 1283 | if (pin == spec->autocfg.input_pins[index]) { |
| 1284 | res = 1; |
| 1285 | break; |
| 1286 | } |
| 1287 | } |
| 1288 | return res; |
| 1289 | } |
| 1290 | |
| 1291 | static int via_smart51_info(struct snd_kcontrol *kcontrol, |
| 1292 | struct snd_ctl_elem_info *uinfo) |
| 1293 | { |
| 1294 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1295 | uinfo->count = 1; |
| 1296 | uinfo->value.integer.min = 0; |
| 1297 | uinfo->value.integer.max = 1; |
| 1298 | return 0; |
| 1299 | } |
| 1300 | |
| 1301 | static int via_smart51_get(struct snd_kcontrol *kcontrol, |
| 1302 | struct snd_ctl_elem_value *ucontrol) |
| 1303 | { |
| 1304 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1305 | struct via_spec *spec = codec->spec; |
| 1306 | int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE }; |
| 1307 | int on = 1; |
| 1308 | int i; |
| 1309 | |
| 1310 | for (i = 0; i < ARRAY_SIZE(index); i++) { |
| 1311 | hda_nid_t nid = spec->autocfg.input_pins[index[i]]; |
| 1312 | if (nid) { |
| 1313 | int ctl = |
| 1314 | snd_hda_codec_read(codec, nid, 0, |
| 1315 | AC_VERB_GET_PIN_WIDGET_CONTROL, |
| 1316 | 0); |
| 1317 | if (i == AUTO_PIN_FRONT_MIC |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1318 | && spec->hp_independent_mode |
| 1319 | && spec->codec_type != VT1718S) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1320 | continue; /* ignore FMic for independent HP */ |
| 1321 | if (ctl & AC_PINCTL_IN_EN |
| 1322 | && !(ctl & AC_PINCTL_OUT_EN)) |
| 1323 | on = 0; |
| 1324 | } |
| 1325 | } |
| 1326 | *ucontrol->value.integer.value = on; |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
| 1330 | static int via_smart51_put(struct snd_kcontrol *kcontrol, |
| 1331 | struct snd_ctl_elem_value *ucontrol) |
| 1332 | { |
| 1333 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1334 | struct via_spec *spec = codec->spec; |
| 1335 | int out_in = *ucontrol->value.integer.value |
| 1336 | ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN; |
| 1337 | int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE }; |
| 1338 | int i; |
| 1339 | |
| 1340 | for (i = 0; i < ARRAY_SIZE(index); i++) { |
| 1341 | hda_nid_t nid = spec->autocfg.input_pins[index[i]]; |
| 1342 | if (i == AUTO_PIN_FRONT_MIC |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1343 | && spec->hp_independent_mode |
| 1344 | && spec->codec_type != VT1718S) |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1345 | continue; /* don't retask FMic for independent HP */ |
| 1346 | if (nid) { |
| 1347 | unsigned int parm = snd_hda_codec_read( |
| 1348 | codec, nid, 0, |
| 1349 | AC_VERB_GET_PIN_WIDGET_CONTROL, 0); |
| 1350 | parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); |
| 1351 | parm |= out_in; |
| 1352 | snd_hda_codec_write(codec, nid, 0, |
| 1353 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
| 1354 | parm); |
| 1355 | if (out_in == AC_PINCTL_OUT_EN) { |
| 1356 | mute_aa_path(codec, 1); |
| 1357 | notify_aa_path_ctls(codec); |
| 1358 | } |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1359 | if (spec->codec_type == VT1718S) |
| 1360 | snd_hda_codec_amp_stereo( |
| 1361 | codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 1362 | HDA_AMP_UNMUTE); |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1363 | } |
| 1364 | if (i == AUTO_PIN_FRONT_MIC) { |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1365 | if (spec->codec_type == VT1708S |
| 1366 | || spec->codec_type == VT1716S) { |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 1367 | /* input = index 1 (AOW3) */ |
| 1368 | snd_hda_codec_write( |
| 1369 | codec, nid, 0, |
| 1370 | AC_VERB_SET_CONNECT_SEL, 1); |
| 1371 | snd_hda_codec_amp_stereo( |
| 1372 | codec, nid, HDA_OUTPUT, |
| 1373 | 0, HDA_AMP_MUTE, HDA_AMP_UNMUTE); |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | spec->smart51_enabled = *ucontrol->value.integer.value; |
| 1378 | set_jack_power_state(codec); |
| 1379 | return 1; |
| 1380 | } |
| 1381 | |
| 1382 | static struct snd_kcontrol_new via_smart51_mixer[] = { |
| 1383 | { |
| 1384 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1385 | .name = "Smart 5.1", |
| 1386 | .count = 1, |
| 1387 | .info = via_smart51_info, |
| 1388 | .get = via_smart51_get, |
| 1389 | .put = via_smart51_put, |
| 1390 | }, |
| 1391 | {} /* end */ |
| 1392 | }; |
| 1393 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1394 | /* capture mixer elements */ |
| 1395 | static struct snd_kcontrol_new vt1708_capture_mixer[] = { |
| 1396 | HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT), |
| 1397 | HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT), |
| 1398 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT), |
| 1399 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT), |
| 1400 | { |
| 1401 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1402 | /* The multiple "Capture Source" controls confuse alsamixer |
| 1403 | * So call somewhat different.. |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1404 | */ |
| 1405 | /* .name = "Capture Source", */ |
| 1406 | .name = "Input Source", |
| 1407 | .count = 1, |
| 1408 | .info = via_mux_enum_info, |
| 1409 | .get = via_mux_enum_get, |
| 1410 | .put = via_mux_enum_put, |
| 1411 | }, |
| 1412 | { } /* end */ |
| 1413 | }; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1414 | |
| 1415 | /* check AA path's mute statue */ |
| 1416 | static int is_aa_path_mute(struct hda_codec *codec) |
| 1417 | { |
| 1418 | int mute = 1; |
| 1419 | hda_nid_t nid_mixer; |
| 1420 | int start_idx; |
| 1421 | int end_idx; |
| 1422 | int i; |
| 1423 | struct via_spec *spec = codec->spec; |
| 1424 | /* get nid of MW0 and start & end index */ |
| 1425 | switch (spec->codec_type) { |
| 1426 | case VT1708B_8CH: |
| 1427 | case VT1708B_4CH: |
| 1428 | case VT1708S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1429 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1430 | nid_mixer = 0x16; |
| 1431 | start_idx = 2; |
| 1432 | end_idx = 4; |
| 1433 | break; |
| 1434 | case VT1702: |
| 1435 | nid_mixer = 0x1a; |
| 1436 | start_idx = 1; |
| 1437 | end_idx = 3; |
| 1438 | break; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1439 | case VT1718S: |
| 1440 | nid_mixer = 0x21; |
| 1441 | start_idx = 1; |
| 1442 | end_idx = 3; |
| 1443 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1444 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1445 | case VT1812: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1446 | nid_mixer = 0x21; |
| 1447 | start_idx = 0; |
| 1448 | end_idx = 2; |
| 1449 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1450 | default: |
| 1451 | return 0; |
| 1452 | } |
| 1453 | /* check AA path's mute status */ |
| 1454 | for (i = start_idx; i <= end_idx; i++) { |
| 1455 | unsigned int con_list = snd_hda_codec_read( |
| 1456 | codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4); |
| 1457 | int shift = 8 * (i % 4); |
| 1458 | hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift; |
| 1459 | unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin); |
| 1460 | if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) { |
| 1461 | /* check mute status while the pin is connected */ |
| 1462 | int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0, |
| 1463 | HDA_INPUT, i) >> 7; |
| 1464 | int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1, |
| 1465 | HDA_INPUT, i) >> 7; |
| 1466 | if (!mute_l || !mute_r) { |
| 1467 | mute = 0; |
| 1468 | break; |
| 1469 | } |
| 1470 | } |
| 1471 | } |
| 1472 | return mute; |
| 1473 | } |
| 1474 | |
| 1475 | /* enter/exit analog low-current mode */ |
| 1476 | static void analog_low_current_mode(struct hda_codec *codec, int stream_idle) |
| 1477 | { |
| 1478 | struct via_spec *spec = codec->spec; |
| 1479 | static int saved_stream_idle = 1; /* saved stream idle status */ |
| 1480 | int enable = is_aa_path_mute(codec); |
| 1481 | unsigned int verb = 0; |
| 1482 | unsigned int parm = 0; |
| 1483 | |
| 1484 | if (stream_idle == -1) /* stream status did not change */ |
| 1485 | enable = enable && saved_stream_idle; |
| 1486 | else { |
| 1487 | enable = enable && stream_idle; |
| 1488 | saved_stream_idle = stream_idle; |
| 1489 | } |
| 1490 | |
| 1491 | /* decide low current mode's verb & parameter */ |
| 1492 | switch (spec->codec_type) { |
| 1493 | case VT1708B_8CH: |
| 1494 | case VT1708B_4CH: |
| 1495 | verb = 0xf70; |
| 1496 | parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */ |
| 1497 | break; |
| 1498 | case VT1708S: |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1499 | case VT1718S: |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1500 | case VT1716S: |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1501 | verb = 0xf73; |
| 1502 | parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */ |
| 1503 | break; |
| 1504 | case VT1702: |
| 1505 | verb = 0xf73; |
| 1506 | parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */ |
| 1507 | break; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1508 | case VT2002P: |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 1509 | case VT1812: |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 1510 | verb = 0xf93; |
| 1511 | parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */ |
| 1512 | break; |
Lydia Wang | f527110 | 2009-10-10 19:07:35 +0800 | [diff] [blame] | 1513 | default: |
| 1514 | return; /* other codecs are not supported */ |
| 1515 | } |
| 1516 | /* send verb */ |
| 1517 | snd_hda_codec_write(codec, codec->afg, 0, verb, parm); |
| 1518 | } |
| 1519 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1520 | /* |
| 1521 | * generic initialization of ADC, input mixers and output mixers |
| 1522 | */ |
| 1523 | static struct hda_verb vt1708_volume_init_verbs[] = { |
| 1524 | /* |
| 1525 | * Unmute ADC0-1 and set the default input to mic-in |
| 1526 | */ |
| 1527 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1528 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1529 | |
| 1530 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1531 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1532 | * mixer widget |
| 1533 | */ |
| 1534 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1535 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 1536 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 1537 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 1538 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 1539 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1540 | |
| 1541 | /* |
| 1542 | * Set up output mixers (0x19 - 0x1b) |
| 1543 | */ |
| 1544 | /* set vol=0 to output mixers */ |
| 1545 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 1546 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 1547 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1548 | |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 1549 | /* Setup default input MW0 to PW4 */ |
| 1550 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1551 | /* PW9 Output enable */ |
| 1552 | {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 1553 | { } |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1554 | }; |
| 1555 | |
| 1556 | static int via_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1557 | struct hda_codec *codec, |
| 1558 | struct snd_pcm_substream *substream) |
| 1559 | { |
| 1560 | struct via_spec *spec = codec->spec; |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1561 | int idle = substream->pstr->substream_opened == 1 |
| 1562 | && substream->ref_count == 0; |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1563 | analog_low_current_mode(codec, idle); |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1564 | return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, |
| 1565 | hinfo); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1568 | static void playback_multi_pcm_prep_0(struct hda_codec *codec, |
| 1569 | unsigned int stream_tag, |
| 1570 | unsigned int format, |
| 1571 | struct snd_pcm_substream *substream) |
| 1572 | { |
| 1573 | struct via_spec *spec = codec->spec; |
| 1574 | struct hda_multi_out *mout = &spec->multiout; |
| 1575 | hda_nid_t *nids = mout->dac_nids; |
| 1576 | int chs = substream->runtime->channels; |
| 1577 | int i; |
| 1578 | |
| 1579 | mutex_lock(&codec->spdif_mutex); |
| 1580 | if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { |
| 1581 | if (chs == 2 && |
| 1582 | snd_hda_is_supported_format(codec, mout->dig_out_nid, |
| 1583 | format) && |
| 1584 | !(codec->spdif_status & IEC958_AES0_NONAUDIO)) { |
| 1585 | mout->dig_out_used = HDA_DIG_ANALOG_DUP; |
| 1586 | /* turn off SPDIF once; otherwise the IEC958 bits won't |
| 1587 | * be updated */ |
| 1588 | if (codec->spdif_ctls & AC_DIG1_ENABLE) |
| 1589 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
| 1590 | AC_VERB_SET_DIGI_CONVERT_1, |
| 1591 | codec->spdif_ctls & |
| 1592 | ~AC_DIG1_ENABLE & 0xff); |
| 1593 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1594 | stream_tag, 0, format); |
| 1595 | /* turn on again (if needed) */ |
| 1596 | if (codec->spdif_ctls & AC_DIG1_ENABLE) |
| 1597 | snd_hda_codec_write(codec, mout->dig_out_nid, 0, |
| 1598 | AC_VERB_SET_DIGI_CONVERT_1, |
| 1599 | codec->spdif_ctls & 0xff); |
| 1600 | } else { |
| 1601 | mout->dig_out_used = 0; |
| 1602 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1603 | 0, 0, 0); |
| 1604 | } |
| 1605 | } |
| 1606 | mutex_unlock(&codec->spdif_mutex); |
| 1607 | |
| 1608 | /* front */ |
| 1609 | snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag, |
| 1610 | 0, format); |
| 1611 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 1612 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] |
| 1613 | && !spec->hp_independent_mode) |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1614 | /* headphone out will just decode front left/right (stereo) */ |
| 1615 | snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, |
| 1616 | 0, format); |
| 1617 | |
| 1618 | /* extra outputs copied from front */ |
| 1619 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 1620 | if (mout->extra_out_nid[i]) |
| 1621 | snd_hda_codec_setup_stream(codec, |
| 1622 | mout->extra_out_nid[i], |
| 1623 | stream_tag, 0, format); |
| 1624 | |
| 1625 | /* surrounds */ |
| 1626 | for (i = 1; i < mout->num_dacs; i++) { |
| 1627 | if (chs >= (i + 1) * 2) /* independent out */ |
| 1628 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 1629 | i * 2, format); |
| 1630 | else /* copy front */ |
| 1631 | snd_hda_codec_setup_stream(codec, nids[i], stream_tag, |
| 1632 | 0, format); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1637 | struct hda_codec *codec, |
| 1638 | unsigned int stream_tag, |
| 1639 | unsigned int format, |
| 1640 | struct snd_pcm_substream *substream) |
| 1641 | { |
| 1642 | struct via_spec *spec = codec->spec; |
| 1643 | struct hda_multi_out *mout = &spec->multiout; |
| 1644 | hda_nid_t *nids = mout->dac_nids; |
| 1645 | |
| 1646 | if (substream->number == 0) |
| 1647 | playback_multi_pcm_prep_0(codec, stream_tag, format, |
| 1648 | substream); |
| 1649 | else { |
| 1650 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && |
| 1651 | spec->hp_independent_mode) |
| 1652 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1653 | stream_tag, 0, format); |
| 1654 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1655 | vt1708_start_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1660 | struct hda_codec *codec, |
| 1661 | struct snd_pcm_substream *substream) |
| 1662 | { |
| 1663 | struct via_spec *spec = codec->spec; |
| 1664 | struct hda_multi_out *mout = &spec->multiout; |
| 1665 | hda_nid_t *nids = mout->dac_nids; |
| 1666 | int i; |
| 1667 | |
| 1668 | if (substream->number == 0) { |
| 1669 | for (i = 0; i < mout->num_dacs; i++) |
| 1670 | snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); |
| 1671 | |
| 1672 | if (mout->hp_nid && !spec->hp_independent_mode) |
| 1673 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1674 | 0, 0, 0); |
| 1675 | |
| 1676 | for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) |
| 1677 | if (mout->extra_out_nid[i]) |
| 1678 | snd_hda_codec_setup_stream(codec, |
| 1679 | mout->extra_out_nid[i], |
| 1680 | 0, 0, 0); |
| 1681 | mutex_lock(&codec->spdif_mutex); |
| 1682 | if (mout->dig_out_nid && |
| 1683 | mout->dig_out_used == HDA_DIG_ANALOG_DUP) { |
| 1684 | snd_hda_codec_setup_stream(codec, mout->dig_out_nid, |
| 1685 | 0, 0, 0); |
| 1686 | mout->dig_out_used = 0; |
| 1687 | } |
| 1688 | mutex_unlock(&codec->spdif_mutex); |
| 1689 | } else { |
| 1690 | if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] && |
| 1691 | spec->hp_independent_mode) |
| 1692 | snd_hda_codec_setup_stream(codec, mout->hp_nid, |
| 1693 | 0, 0, 0); |
| 1694 | } |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1695 | vt1708_stop_hp_work(spec); |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1696 | return 0; |
| 1697 | } |
| 1698 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1699 | /* |
| 1700 | * Digital out |
| 1701 | */ |
| 1702 | static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo, |
| 1703 | struct hda_codec *codec, |
| 1704 | struct snd_pcm_substream *substream) |
| 1705 | { |
| 1706 | struct via_spec *spec = codec->spec; |
| 1707 | return snd_hda_multi_out_dig_open(codec, &spec->multiout); |
| 1708 | } |
| 1709 | |
| 1710 | static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, |
| 1711 | struct hda_codec *codec, |
| 1712 | struct snd_pcm_substream *substream) |
| 1713 | { |
| 1714 | struct via_spec *spec = codec->spec; |
| 1715 | return snd_hda_multi_out_dig_close(codec, &spec->multiout); |
| 1716 | } |
| 1717 | |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1718 | static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo, |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1719 | struct hda_codec *codec, |
| 1720 | unsigned int stream_tag, |
| 1721 | unsigned int format, |
| 1722 | struct snd_pcm_substream *substream) |
| 1723 | { |
| 1724 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1725 | return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, |
| 1726 | stream_tag, format, substream); |
| 1727 | } |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 1728 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1729 | static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1730 | struct hda_codec *codec, |
| 1731 | struct snd_pcm_substream *substream) |
| 1732 | { |
| 1733 | struct via_spec *spec = codec->spec; |
| 1734 | snd_hda_multi_out_dig_cleanup(codec, &spec->multiout); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 1735 | return 0; |
| 1736 | } |
| 1737 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1738 | /* |
| 1739 | * Analog capture |
| 1740 | */ |
| 1741 | static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo, |
| 1742 | struct hda_codec *codec, |
| 1743 | unsigned int stream_tag, |
| 1744 | unsigned int format, |
| 1745 | struct snd_pcm_substream *substream) |
| 1746 | { |
| 1747 | struct via_spec *spec = codec->spec; |
| 1748 | |
| 1749 | snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], |
| 1750 | stream_tag, 0, format); |
| 1751 | return 0; |
| 1752 | } |
| 1753 | |
| 1754 | static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo, |
| 1755 | struct hda_codec *codec, |
| 1756 | struct snd_pcm_substream *substream) |
| 1757 | { |
| 1758 | struct via_spec *spec = codec->spec; |
Takashi Iwai | 888afa1 | 2008-03-18 09:57:50 +0100 | [diff] [blame] | 1759 | snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | static struct hda_pcm_stream vt1708_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1764 | .substreams = 2, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1765 | .channels_min = 2, |
| 1766 | .channels_max = 8, |
| 1767 | .nid = 0x10, /* NID to query formats and rates */ |
| 1768 | .ops = { |
| 1769 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 1770 | .prepare = via_playback_multi_pcm_prepare, |
| 1771 | .cleanup = via_playback_multi_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1772 | }, |
| 1773 | }; |
| 1774 | |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1775 | static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = { |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1776 | .substreams = 2, |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1777 | .channels_min = 2, |
| 1778 | .channels_max = 8, |
| 1779 | .nid = 0x10, /* NID to query formats and rates */ |
| 1780 | /* We got noisy outputs on the right channel on VT1708 when |
| 1781 | * 24bit samples are used. Until any workaround is found, |
| 1782 | * disable the 24bit format, so far. |
| 1783 | */ |
| 1784 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1785 | .ops = { |
| 1786 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 1787 | .prepare = via_playback_multi_pcm_prepare, |
| 1788 | .cleanup = via_playback_multi_pcm_cleanup |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 1789 | }, |
| 1790 | }; |
| 1791 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1792 | static struct hda_pcm_stream vt1708_pcm_analog_capture = { |
| 1793 | .substreams = 2, |
| 1794 | .channels_min = 2, |
| 1795 | .channels_max = 2, |
| 1796 | .nid = 0x15, /* NID to query formats and rates */ |
| 1797 | .ops = { |
| 1798 | .prepare = via_capture_pcm_prepare, |
| 1799 | .cleanup = via_capture_pcm_cleanup |
| 1800 | }, |
| 1801 | }; |
| 1802 | |
| 1803 | static struct hda_pcm_stream vt1708_pcm_digital_playback = { |
| 1804 | .substreams = 1, |
| 1805 | .channels_min = 2, |
| 1806 | .channels_max = 2, |
| 1807 | /* NID is set in via_build_pcms */ |
| 1808 | .ops = { |
| 1809 | .open = via_dig_playback_pcm_open, |
Takashi Iwai | 6b97eb4 | 2007-04-05 14:51:48 +0200 | [diff] [blame] | 1810 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 1811 | .prepare = via_dig_playback_pcm_prepare, |
| 1812 | .cleanup = via_dig_playback_pcm_cleanup |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1813 | }, |
| 1814 | }; |
| 1815 | |
| 1816 | static struct hda_pcm_stream vt1708_pcm_digital_capture = { |
| 1817 | .substreams = 1, |
| 1818 | .channels_min = 2, |
| 1819 | .channels_max = 2, |
| 1820 | }; |
| 1821 | |
| 1822 | static int via_build_controls(struct hda_codec *codec) |
| 1823 | { |
| 1824 | struct via_spec *spec = codec->spec; |
| 1825 | int err; |
| 1826 | int i; |
| 1827 | |
| 1828 | for (i = 0; i < spec->num_mixers; i++) { |
| 1829 | err = snd_hda_add_new_ctls(codec, spec->mixers[i]); |
| 1830 | if (err < 0) |
| 1831 | return err; |
| 1832 | } |
| 1833 | |
| 1834 | if (spec->multiout.dig_out_nid) { |
| 1835 | err = snd_hda_create_spdif_out_ctls(codec, |
| 1836 | spec->multiout.dig_out_nid); |
| 1837 | if (err < 0) |
| 1838 | return err; |
Takashi Iwai | 9a08160 | 2008-02-12 18:37:26 +0100 | [diff] [blame] | 1839 | err = snd_hda_create_spdif_share_sw(codec, |
| 1840 | &spec->multiout); |
| 1841 | if (err < 0) |
| 1842 | return err; |
| 1843 | spec->multiout.share_spdif = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1844 | } |
| 1845 | if (spec->dig_in_nid) { |
| 1846 | err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); |
| 1847 | if (err < 0) |
| 1848 | return err; |
| 1849 | } |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 1850 | |
| 1851 | /* init power states */ |
| 1852 | set_jack_power_state(codec); |
| 1853 | analog_low_current_mode(codec, 1); |
| 1854 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1855 | via_free_kctls(codec); /* no longer needed */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1856 | return 0; |
| 1857 | } |
| 1858 | |
| 1859 | static int via_build_pcms(struct hda_codec *codec) |
| 1860 | { |
| 1861 | struct via_spec *spec = codec->spec; |
| 1862 | struct hda_pcm *info = spec->pcm_rec; |
| 1863 | |
| 1864 | codec->num_pcms = 1; |
| 1865 | codec->pcm_info = info; |
| 1866 | |
| 1867 | info->name = spec->stream_name_analog; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 1868 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 1869 | *(spec->stream_analog_playback); |
| 1870 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1871 | spec->multiout.dac_nids[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1872 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture); |
| 1873 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0]; |
| 1874 | |
| 1875 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = |
| 1876 | spec->multiout.max_channels; |
| 1877 | |
| 1878 | if (spec->multiout.dig_out_nid || spec->dig_in_nid) { |
| 1879 | codec->num_pcms++; |
| 1880 | info++; |
| 1881 | info->name = spec->stream_name_digital; |
Takashi Iwai | 7ba72ba | 2008-02-06 14:03:20 +0100 | [diff] [blame] | 1882 | info->pcm_type = HDA_PCM_TYPE_SPDIF; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1883 | if (spec->multiout.dig_out_nid) { |
| 1884 | info->stream[SNDRV_PCM_STREAM_PLAYBACK] = |
| 1885 | *(spec->stream_digital_playback); |
| 1886 | info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = |
| 1887 | spec->multiout.dig_out_nid; |
| 1888 | } |
| 1889 | if (spec->dig_in_nid) { |
| 1890 | info->stream[SNDRV_PCM_STREAM_CAPTURE] = |
| 1891 | *(spec->stream_digital_capture); |
| 1892 | info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = |
| 1893 | spec->dig_in_nid; |
| 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | return 0; |
| 1898 | } |
| 1899 | |
| 1900 | static void via_free(struct hda_codec *codec) |
| 1901 | { |
| 1902 | struct via_spec *spec = codec->spec; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1903 | |
| 1904 | if (!spec) |
| 1905 | return; |
| 1906 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 1907 | via_free_kctls(codec); |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 1908 | vt1708_stop_hp_work(spec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 1909 | kfree(codec->spec); |
| 1910 | } |
| 1911 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1912 | /* mute internal speaker if HP is plugged */ |
| 1913 | static void via_hp_automute(struct hda_codec *codec) |
| 1914 | { |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1915 | unsigned int present = 0; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1916 | struct via_spec *spec = codec->spec; |
| 1917 | |
| 1918 | present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, |
| 1919 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
Lydia Wang | dcf34c8 | 2009-10-10 19:08:15 +0800 | [diff] [blame] | 1920 | |
| 1921 | if (!spec->hp_independent_mode) { |
| 1922 | struct snd_ctl_elem_id id; |
| 1923 | /* auto mute */ |
| 1924 | snd_hda_codec_amp_stereo( |
| 1925 | codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0, |
| 1926 | HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); |
| 1927 | /* notify change */ |
| 1928 | memset(&id, 0, sizeof(id)); |
| 1929 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 1930 | strcpy(id.name, "Front Playback Switch"); |
| 1931 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 1932 | &id); |
| 1933 | } |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1934 | } |
| 1935 | |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 1936 | /* mute mono out if HP or Line out is plugged */ |
| 1937 | static void via_mono_automute(struct hda_codec *codec) |
| 1938 | { |
| 1939 | unsigned int hp_present, lineout_present; |
| 1940 | struct via_spec *spec = codec->spec; |
| 1941 | |
| 1942 | if (spec->codec_type != VT1716S) |
| 1943 | return; |
| 1944 | |
| 1945 | lineout_present = snd_hda_codec_read( |
| 1946 | codec, spec->autocfg.line_out_pins[0], 0, |
| 1947 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 1948 | |
| 1949 | /* Mute Mono Out if Line Out is plugged */ |
| 1950 | if (lineout_present) { |
| 1951 | snd_hda_codec_amp_stereo( |
| 1952 | codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE); |
| 1953 | return; |
| 1954 | } |
| 1955 | |
| 1956 | hp_present = snd_hda_codec_read( |
| 1957 | codec, spec->autocfg.hp_pins[0], 0, |
| 1958 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 1959 | |
| 1960 | if (!spec->hp_independent_mode) |
| 1961 | snd_hda_codec_amp_stereo( |
| 1962 | codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 1963 | hp_present ? HDA_AMP_MUTE : 0); |
| 1964 | } |
| 1965 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 1966 | static void via_gpio_control(struct hda_codec *codec) |
| 1967 | { |
| 1968 | unsigned int gpio_data; |
| 1969 | unsigned int vol_counter; |
| 1970 | unsigned int vol; |
| 1971 | unsigned int master_vol; |
| 1972 | |
| 1973 | struct via_spec *spec = codec->spec; |
| 1974 | |
| 1975 | gpio_data = snd_hda_codec_read(codec, codec->afg, 0, |
| 1976 | AC_VERB_GET_GPIO_DATA, 0) & 0x03; |
| 1977 | |
| 1978 | vol_counter = (snd_hda_codec_read(codec, codec->afg, 0, |
| 1979 | 0xF84, 0) & 0x3F0000) >> 16; |
| 1980 | |
| 1981 | vol = vol_counter & 0x1F; |
| 1982 | master_vol = snd_hda_codec_read(codec, 0x1A, 0, |
| 1983 | AC_VERB_GET_AMP_GAIN_MUTE, |
| 1984 | AC_AMP_GET_INPUT); |
| 1985 | |
| 1986 | if (gpio_data == 0x02) { |
| 1987 | /* unmute line out */ |
| 1988 | snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0], |
| 1989 | HDA_OUTPUT, 0, HDA_AMP_MUTE, 0); |
| 1990 | |
| 1991 | if (vol_counter & 0x20) { |
| 1992 | /* decrease volume */ |
| 1993 | if (vol > master_vol) |
| 1994 | vol = master_vol; |
| 1995 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, |
| 1996 | 0, HDA_AMP_VOLMASK, |
| 1997 | master_vol-vol); |
| 1998 | } else { |
| 1999 | /* increase volume */ |
| 2000 | snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0, |
| 2001 | HDA_AMP_VOLMASK, |
| 2002 | ((master_vol+vol) > 0x2A) ? 0x2A : |
| 2003 | (master_vol+vol)); |
| 2004 | } |
| 2005 | } else if (!(gpio_data & 0x02)) { |
| 2006 | /* mute line out */ |
| 2007 | snd_hda_codec_amp_stereo(codec, |
| 2008 | spec->autocfg.line_out_pins[0], |
| 2009 | HDA_OUTPUT, 0, HDA_AMP_MUTE, |
| 2010 | HDA_AMP_MUTE); |
| 2011 | } |
| 2012 | } |
| 2013 | |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2014 | /* mute Internal-Speaker if HP is plugged */ |
| 2015 | static void via_speaker_automute(struct hda_codec *codec) |
| 2016 | { |
| 2017 | unsigned int hp_present; |
| 2018 | struct via_spec *spec = codec->spec; |
| 2019 | |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 2020 | if (spec->codec_type != VT2002P && spec->codec_type != VT1812) |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2021 | return; |
| 2022 | |
| 2023 | hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, |
| 2024 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 2025 | |
| 2026 | if (!spec->hp_independent_mode) { |
| 2027 | struct snd_ctl_elem_id id; |
| 2028 | snd_hda_codec_amp_stereo( |
| 2029 | codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0, |
| 2030 | HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); |
| 2031 | /* notify change */ |
| 2032 | memset(&id, 0, sizeof(id)); |
| 2033 | id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 2034 | strcpy(id.name, "Speaker Playback Switch"); |
| 2035 | snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 2036 | &id); |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | /* mute line-out and internal speaker if HP is plugged */ |
| 2041 | static void via_hp_bind_automute(struct hda_codec *codec) |
| 2042 | { |
| 2043 | unsigned int hp_present, present = 0; |
| 2044 | struct via_spec *spec = codec->spec; |
| 2045 | int i; |
| 2046 | |
| 2047 | if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0]) |
| 2048 | return; |
| 2049 | |
| 2050 | hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0, |
| 2051 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 2052 | |
| 2053 | present = snd_hda_codec_read(codec, spec->autocfg.line_out_pins[0], 0, |
| 2054 | AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; |
| 2055 | |
| 2056 | if (!spec->hp_independent_mode) { |
| 2057 | /* Mute Line-Outs */ |
| 2058 | for (i = 0; i < spec->autocfg.line_outs; i++) |
| 2059 | snd_hda_codec_amp_stereo( |
| 2060 | codec, spec->autocfg.line_out_pins[i], |
| 2061 | HDA_OUTPUT, 0, |
| 2062 | HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0); |
| 2063 | if (hp_present) |
| 2064 | present = hp_present; |
| 2065 | } |
| 2066 | /* Speakers */ |
| 2067 | for (i = 0; i < spec->autocfg.speaker_outs; i++) |
| 2068 | snd_hda_codec_amp_stereo( |
| 2069 | codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0, |
| 2070 | HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); |
| 2071 | } |
| 2072 | |
| 2073 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2074 | /* unsolicited event for jack sensing */ |
| 2075 | static void via_unsol_event(struct hda_codec *codec, |
| 2076 | unsigned int res) |
| 2077 | { |
| 2078 | res >>= 26; |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2079 | if (res & VIA_HP_EVENT) |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2080 | via_hp_automute(codec); |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2081 | if (res & VIA_GPIO_EVENT) |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2082 | via_gpio_control(codec); |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2083 | if (res & VIA_JACK_EVENT) |
| 2084 | set_jack_power_state(codec); |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 2085 | if (res & VIA_MONO_EVENT) |
| 2086 | via_mono_automute(codec); |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2087 | if (res & VIA_SPEAKER_EVENT) |
| 2088 | via_speaker_automute(codec); |
| 2089 | if (res & VIA_BIND_HP_EVENT) |
| 2090 | via_hp_bind_automute(codec); |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2091 | } |
| 2092 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2093 | static int via_init(struct hda_codec *codec) |
| 2094 | { |
| 2095 | struct via_spec *spec = codec->spec; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2096 | int i; |
| 2097 | for (i = 0; i < spec->num_iverbs; i++) |
| 2098 | snd_hda_sequence_write(codec, spec->init_verbs[i]); |
| 2099 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 2100 | spec->codec_type = get_codec_type(codec); |
| 2101 | if (spec->codec_type == VT1708BCE) |
| 2102 | spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost |
| 2103 | same */ |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2104 | /* Lydia Add for EAPD enable */ |
| 2105 | if (!spec->dig_in_nid) { /* No Digital In connection */ |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2106 | if (spec->dig_in_pin) { |
| 2107 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2108 | AC_VERB_SET_PIN_WIDGET_CONTROL, |
Takashi Iwai | 12b74c8 | 2008-01-15 12:39:38 +0100 | [diff] [blame] | 2109 | PIN_OUT); |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2110 | snd_hda_codec_write(codec, spec->dig_in_pin, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2111 | AC_VERB_SET_EAPD_BTLENABLE, 0x02); |
| 2112 | } |
Takashi Iwai | 12b74c8 | 2008-01-15 12:39:38 +0100 | [diff] [blame] | 2113 | } else /* enable SPDIF-input pin */ |
| 2114 | snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0, |
| 2115 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2116 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 2117 | /* assign slave outs */ |
| 2118 | if (spec->slave_dig_outs[0]) |
| 2119 | codec->slave_dig_outs = spec->slave_dig_outs; |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 2120 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2121 | return 0; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2122 | } |
| 2123 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2124 | #ifdef SND_HDA_NEEDS_RESUME |
| 2125 | static int via_suspend(struct hda_codec *codec, pm_message_t state) |
| 2126 | { |
| 2127 | struct via_spec *spec = codec->spec; |
| 2128 | vt1708_stop_hp_work(spec); |
| 2129 | return 0; |
| 2130 | } |
| 2131 | #endif |
| 2132 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2133 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2134 | static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid) |
| 2135 | { |
| 2136 | struct via_spec *spec = codec->spec; |
| 2137 | return snd_hda_check_amp_list_power(codec, &spec->loopback, nid); |
| 2138 | } |
| 2139 | #endif |
| 2140 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2141 | /* |
| 2142 | */ |
| 2143 | static struct hda_codec_ops via_patch_ops = { |
| 2144 | .build_controls = via_build_controls, |
| 2145 | .build_pcms = via_build_pcms, |
| 2146 | .init = via_init, |
| 2147 | .free = via_free, |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2148 | #ifdef SND_HDA_NEEDS_RESUME |
| 2149 | .suspend = via_suspend, |
| 2150 | #endif |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2151 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2152 | .check_power_status = via_check_power_status, |
| 2153 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2154 | }; |
| 2155 | |
| 2156 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 2157 | static int vt1708_auto_fill_dac_nids(struct via_spec *spec, |
| 2158 | const struct auto_pin_cfg *cfg) |
| 2159 | { |
| 2160 | int i; |
| 2161 | hda_nid_t nid; |
| 2162 | |
| 2163 | spec->multiout.num_dacs = cfg->line_outs; |
| 2164 | |
| 2165 | spec->multiout.dac_nids = spec->private_dac_nids; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2166 | |
| 2167 | for (i = 0; i < 4; i++) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2168 | nid = cfg->line_out_pins[i]; |
| 2169 | if (nid) { |
| 2170 | /* config dac list */ |
| 2171 | switch (i) { |
| 2172 | case AUTO_SEQ_FRONT: |
| 2173 | spec->multiout.dac_nids[i] = 0x10; |
| 2174 | break; |
| 2175 | case AUTO_SEQ_CENLFE: |
| 2176 | spec->multiout.dac_nids[i] = 0x12; |
| 2177 | break; |
| 2178 | case AUTO_SEQ_SURROUND: |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 2179 | spec->multiout.dac_nids[i] = 0x11; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2180 | break; |
| 2181 | case AUTO_SEQ_SIDE: |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 2182 | spec->multiout.dac_nids[i] = 0x13; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2183 | break; |
| 2184 | } |
| 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | return 0; |
| 2189 | } |
| 2190 | |
| 2191 | /* add playback controls from the parsed DAC table */ |
| 2192 | static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec, |
| 2193 | const struct auto_pin_cfg *cfg) |
| 2194 | { |
| 2195 | char name[32]; |
| 2196 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; |
Lydia Wang | 9645c20 | 2009-10-10 19:08:27 +0800 | [diff] [blame] | 2197 | hda_nid_t nid, nid_vol, nid_vols[] = {0x17, 0x19, 0x1a, 0x1b}; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2198 | int i, err; |
| 2199 | |
| 2200 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 2201 | nid = cfg->line_out_pins[i]; |
| 2202 | |
| 2203 | if (!nid) |
| 2204 | continue; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2205 | |
Lydia Wang | 9645c20 | 2009-10-10 19:08:27 +0800 | [diff] [blame] | 2206 | nid_vol = nid_vols[i]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2207 | |
| 2208 | if (i == AUTO_SEQ_CENLFE) { |
| 2209 | /* Center/LFE */ |
| 2210 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2211 | "Center Playback Volume", |
| 2212 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 2213 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2214 | if (err < 0) |
| 2215 | return err; |
| 2216 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2217 | "LFE Playback Volume", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2218 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 2219 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2220 | if (err < 0) |
| 2221 | return err; |
| 2222 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2223 | "Center Playback Switch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2224 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 2225 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2226 | if (err < 0) |
| 2227 | return err; |
| 2228 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2229 | "LFE Playback Switch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2230 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 2231 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2232 | if (err < 0) |
| 2233 | return err; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2234 | } else if (i == AUTO_SEQ_FRONT) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2235 | /* add control to mixer index 0 */ |
| 2236 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2237 | "Master Front Playback Volume", |
Lydia Wang | 9645c20 | 2009-10-10 19:08:27 +0800 | [diff] [blame] | 2238 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2239 | HDA_INPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2240 | if (err < 0) |
| 2241 | return err; |
| 2242 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2243 | "Master Front Playback Switch", |
Lydia Wang | 9645c20 | 2009-10-10 19:08:27 +0800 | [diff] [blame] | 2244 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2245 | HDA_INPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2246 | if (err < 0) |
| 2247 | return err; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2248 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2249 | /* add control to PW3 */ |
| 2250 | sprintf(name, "%s Playback Volume", chname[i]); |
| 2251 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2252 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 2253 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2254 | if (err < 0) |
| 2255 | return err; |
| 2256 | sprintf(name, "%s Playback Switch", chname[i]); |
| 2257 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2258 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 2259 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2260 | if (err < 0) |
| 2261 | return err; |
| 2262 | } else { |
| 2263 | sprintf(name, "%s Playback Volume", chname[i]); |
| 2264 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2265 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 2266 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2267 | if (err < 0) |
| 2268 | return err; |
| 2269 | sprintf(name, "%s Playback Switch", chname[i]); |
| 2270 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2271 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 2272 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2273 | if (err < 0) |
| 2274 | return err; |
| 2275 | } |
| 2276 | } |
| 2277 | |
| 2278 | return 0; |
| 2279 | } |
| 2280 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2281 | static void create_hp_imux(struct via_spec *spec) |
| 2282 | { |
| 2283 | int i; |
| 2284 | struct hda_input_mux *imux = &spec->private_imux[1]; |
| 2285 | static const char *texts[] = { "OFF", "ON", NULL}; |
| 2286 | |
| 2287 | /* for hp mode select */ |
| 2288 | i = 0; |
| 2289 | while (texts[i] != NULL) { |
| 2290 | imux->items[imux->num_items].label = texts[i]; |
| 2291 | imux->items[imux->num_items].index = i; |
| 2292 | imux->num_items++; |
| 2293 | i++; |
| 2294 | } |
| 2295 | |
| 2296 | spec->hp_mux = &spec->private_imux[1]; |
| 2297 | } |
| 2298 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2299 | static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 2300 | { |
| 2301 | int err; |
| 2302 | |
| 2303 | if (!pin) |
| 2304 | return 0; |
| 2305 | |
| 2306 | spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */ |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 2307 | spec->hp_independent_mode_index = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2308 | |
| 2309 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2310 | "Headphone Playback Volume", |
| 2311 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 2312 | if (err < 0) |
| 2313 | return err; |
| 2314 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2315 | "Headphone Playback Switch", |
| 2316 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 2317 | if (err < 0) |
| 2318 | return err; |
| 2319 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2320 | create_hp_imux(spec); |
| 2321 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2322 | return 0; |
| 2323 | } |
| 2324 | |
| 2325 | /* create playback/capture controls for input pins */ |
| 2326 | static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec, |
| 2327 | const struct auto_pin_cfg *cfg) |
| 2328 | { |
| 2329 | static char *labels[] = { |
| 2330 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 2331 | }; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2332 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2333 | int i, err, idx = 0; |
| 2334 | |
| 2335 | /* for internal loopback recording select */ |
| 2336 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 2337 | imux->items[imux->num_items].index = idx; |
| 2338 | imux->num_items++; |
| 2339 | |
| 2340 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 2341 | if (!cfg->input_pins[i]) |
| 2342 | continue; |
| 2343 | |
| 2344 | switch (cfg->input_pins[i]) { |
| 2345 | case 0x1d: /* Mic */ |
| 2346 | idx = 2; |
| 2347 | break; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2348 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2349 | case 0x1e: /* Line In */ |
| 2350 | idx = 3; |
| 2351 | break; |
| 2352 | |
| 2353 | case 0x21: /* Front Mic */ |
| 2354 | idx = 4; |
| 2355 | break; |
| 2356 | |
| 2357 | case 0x24: /* CD */ |
| 2358 | idx = 1; |
| 2359 | break; |
| 2360 | } |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 2361 | err = via_new_analog_input(spec, labels[i], idx, 0x17); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2362 | if (err < 0) |
| 2363 | return err; |
| 2364 | imux->items[imux->num_items].label = labels[i]; |
| 2365 | imux->items[imux->num_items].index = idx; |
| 2366 | imux->num_items++; |
| 2367 | } |
| 2368 | return 0; |
| 2369 | } |
| 2370 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2371 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2372 | static struct hda_amp_list vt1708_loopbacks[] = { |
| 2373 | { 0x17, HDA_INPUT, 1 }, |
| 2374 | { 0x17, HDA_INPUT, 2 }, |
| 2375 | { 0x17, HDA_INPUT, 3 }, |
| 2376 | { 0x17, HDA_INPUT, 4 }, |
| 2377 | { } /* end */ |
| 2378 | }; |
| 2379 | #endif |
| 2380 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2381 | static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid) |
| 2382 | { |
| 2383 | unsigned int def_conf; |
| 2384 | unsigned char seqassoc; |
| 2385 | |
Takashi Iwai | 2f334f9 | 2009-02-20 14:37:42 +0100 | [diff] [blame] | 2386 | def_conf = snd_hda_codec_get_pincfg(codec, nid); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2387 | seqassoc = (unsigned char) get_defcfg_association(def_conf); |
| 2388 | seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); |
Lydia Wang | 82ef9e4 | 2009-10-10 19:08:19 +0800 | [diff] [blame] | 2389 | if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE |
| 2390 | && (seqassoc == 0xf0 || seqassoc == 0xff)) { |
| 2391 | def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); |
| 2392 | snd_hda_codec_set_pincfg(codec, nid, def_conf); |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | return; |
| 2396 | } |
| 2397 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2398 | static int vt1708_jack_detectect_get(struct snd_kcontrol *kcontrol, |
| 2399 | struct snd_ctl_elem_value *ucontrol) |
| 2400 | { |
| 2401 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2402 | struct via_spec *spec = codec->spec; |
| 2403 | |
| 2404 | if (spec->codec_type != VT1708) |
| 2405 | return 0; |
| 2406 | spec->vt1708_jack_detectect = |
| 2407 | !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1); |
| 2408 | ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect; |
| 2409 | return 0; |
| 2410 | } |
| 2411 | |
| 2412 | static int vt1708_jack_detectect_put(struct snd_kcontrol *kcontrol, |
| 2413 | struct snd_ctl_elem_value *ucontrol) |
| 2414 | { |
| 2415 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2416 | struct via_spec *spec = codec->spec; |
| 2417 | int change; |
| 2418 | |
| 2419 | if (spec->codec_type != VT1708) |
| 2420 | return 0; |
| 2421 | spec->vt1708_jack_detectect = ucontrol->value.integer.value[0]; |
| 2422 | change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) |
| 2423 | == !spec->vt1708_jack_detectect; |
| 2424 | if (spec->vt1708_jack_detectect) { |
| 2425 | mute_aa_path(codec, 1); |
| 2426 | notify_aa_path_ctls(codec); |
| 2427 | } |
| 2428 | return change; |
| 2429 | } |
| 2430 | |
| 2431 | static struct snd_kcontrol_new vt1708_jack_detectect[] = { |
| 2432 | { |
| 2433 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2434 | .name = "Jack Detect", |
| 2435 | .count = 1, |
| 2436 | .info = snd_ctl_boolean_mono_info, |
| 2437 | .get = vt1708_jack_detectect_get, |
| 2438 | .put = vt1708_jack_detectect_put, |
| 2439 | }, |
| 2440 | {} /* end */ |
| 2441 | }; |
| 2442 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2443 | static int vt1708_parse_auto_config(struct hda_codec *codec) |
| 2444 | { |
| 2445 | struct via_spec *spec = codec->spec; |
| 2446 | int err; |
| 2447 | |
Harald Welte | 76d9b0d | 2008-09-09 15:50:37 +0800 | [diff] [blame] | 2448 | /* Add HP and CD pin config connect bit re-config action */ |
| 2449 | vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID); |
| 2450 | vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID); |
| 2451 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2452 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2453 | if (err < 0) |
| 2454 | return err; |
| 2455 | err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg); |
| 2456 | if (err < 0) |
| 2457 | return err; |
| 2458 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2459 | return 0; /* can't find valid BIOS pin config */ |
| 2460 | |
| 2461 | err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 2462 | if (err < 0) |
| 2463 | return err; |
| 2464 | err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 2465 | if (err < 0) |
| 2466 | return err; |
| 2467 | err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 2468 | if (err < 0) |
| 2469 | return err; |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2470 | /* add jack detect on/off control */ |
| 2471 | err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect); |
| 2472 | if (err < 0) |
| 2473 | return err; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2474 | |
| 2475 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 2476 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 2477 | if (spec->autocfg.dig_outs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2478 | spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 2479 | spec->dig_in_pin = VT1708_DIGIN_PIN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2480 | if (spec->autocfg.dig_in_pin) |
| 2481 | spec->dig_in_nid = VT1708_DIGIN_NID; |
| 2482 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 2483 | if (spec->kctls.list) |
| 2484 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2485 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2486 | spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2487 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2488 | spec->input_mux = &spec->private_imux[0]; |
| 2489 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 2490 | if (spec->hp_mux) |
| 2491 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2492 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 2493 | spec->mixers[spec->num_mixers++] = via_smart51_mixer; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2494 | return 1; |
| 2495 | } |
| 2496 | |
| 2497 | /* init callback for auto-configuration model -- overriding the default init */ |
| 2498 | static int via_auto_init(struct hda_codec *codec) |
| 2499 | { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2500 | struct via_spec *spec = codec->spec; |
| 2501 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2502 | via_init(codec); |
| 2503 | via_auto_init_multi_out(codec); |
| 2504 | via_auto_init_hp_out(codec); |
| 2505 | via_auto_init_analog_input(codec); |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 2506 | if (spec->codec_type == VT2002P || spec->codec_type == VT1812) { |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 2507 | via_hp_bind_automute(codec); |
| 2508 | } else { |
| 2509 | via_hp_automute(codec); |
| 2510 | via_speaker_automute(codec); |
| 2511 | } |
| 2512 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2513 | return 0; |
| 2514 | } |
| 2515 | |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2516 | static void vt1708_update_hp_jack_state(struct work_struct *work) |
| 2517 | { |
| 2518 | struct via_spec *spec = container_of(work, struct via_spec, |
| 2519 | vt1708_hp_work.work); |
| 2520 | if (spec->codec_type != VT1708) |
| 2521 | return; |
| 2522 | /* if jack state toggled */ |
| 2523 | if (spec->vt1708_hp_present |
| 2524 | != (snd_hda_codec_read(spec->codec, spec->autocfg.hp_pins[0], 0, |
| 2525 | AC_VERB_GET_PIN_SENSE, 0) >> 31)) { |
| 2526 | spec->vt1708_hp_present ^= 1; |
| 2527 | via_hp_automute(spec->codec); |
| 2528 | } |
| 2529 | vt1708_start_hp_work(spec); |
| 2530 | } |
| 2531 | |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2532 | static int get_mux_nids(struct hda_codec *codec) |
| 2533 | { |
| 2534 | struct via_spec *spec = codec->spec; |
| 2535 | hda_nid_t nid, conn[8]; |
| 2536 | unsigned int type; |
| 2537 | int i, n; |
| 2538 | |
| 2539 | for (i = 0; i < spec->num_adc_nids; i++) { |
| 2540 | nid = spec->adc_nids[i]; |
| 2541 | while (nid) { |
Takashi Iwai | a22d543 | 2009-07-27 12:54:26 +0200 | [diff] [blame] | 2542 | type = get_wcaps_type(get_wcaps(codec, nid)); |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2543 | if (type == AC_WID_PIN) |
| 2544 | break; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2545 | n = snd_hda_get_connections(codec, nid, conn, |
| 2546 | ARRAY_SIZE(conn)); |
| 2547 | if (n <= 0) |
| 2548 | break; |
| 2549 | if (n > 1) { |
| 2550 | spec->mux_nids[i] = nid; |
| 2551 | break; |
| 2552 | } |
| 2553 | nid = conn[0]; |
| 2554 | } |
| 2555 | } |
Takashi Iwai | 1c55d52 | 2009-07-08 07:45:46 +0200 | [diff] [blame] | 2556 | return 0; |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 2557 | } |
| 2558 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2559 | static int patch_vt1708(struct hda_codec *codec) |
| 2560 | { |
| 2561 | struct via_spec *spec; |
| 2562 | int err; |
| 2563 | |
| 2564 | /* create a codec specific record */ |
Harald Welte | eb14a46 | 2008-09-09 15:40:38 +0800 | [diff] [blame] | 2565 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2566 | if (spec == NULL) |
| 2567 | return -ENOMEM; |
| 2568 | |
| 2569 | codec->spec = spec; |
| 2570 | |
| 2571 | /* automatic parse from the BIOS config */ |
| 2572 | err = vt1708_parse_auto_config(codec); |
| 2573 | if (err < 0) { |
| 2574 | via_free(codec); |
| 2575 | return err; |
| 2576 | } else if (!err) { |
| 2577 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 2578 | "from BIOS. Using genenic mode...\n"); |
| 2579 | } |
| 2580 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2581 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2582 | spec->stream_name_analog = "VT1708 Analog"; |
| 2583 | spec->stream_analog_playback = &vt1708_pcm_analog_playback; |
Takashi Iwai | bc9b56238 | 2008-05-23 17:50:27 +0200 | [diff] [blame] | 2584 | /* disable 32bit format on VT1708 */ |
| 2585 | if (codec->vendor_id == 0x11061708) |
| 2586 | spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2587 | spec->stream_analog_capture = &vt1708_pcm_analog_capture; |
| 2588 | |
| 2589 | spec->stream_name_digital = "VT1708 Digital"; |
| 2590 | spec->stream_digital_playback = &vt1708_pcm_digital_playback; |
| 2591 | spec->stream_digital_capture = &vt1708_pcm_digital_capture; |
| 2592 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2593 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2594 | if (!spec->adc_nids && spec->input_mux) { |
| 2595 | spec->adc_nids = vt1708_adc_nids; |
| 2596 | spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids); |
Takashi Iwai | 0f67a61 | 2009-08-31 08:12:29 +0200 | [diff] [blame] | 2597 | get_mux_nids(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2598 | spec->mixers[spec->num_mixers] = vt1708_capture_mixer; |
| 2599 | spec->num_mixers++; |
| 2600 | } |
| 2601 | |
| 2602 | codec->patch_ops = via_patch_ops; |
| 2603 | |
| 2604 | codec->patch_ops.init = via_auto_init; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 2605 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 2606 | spec->loopback.amplist = vt1708_loopbacks; |
| 2607 | #endif |
Lydia Wang | 1f2e99f | 2009-10-10 19:08:17 +0800 | [diff] [blame] | 2608 | spec->codec = codec; |
| 2609 | INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2610 | return 0; |
| 2611 | } |
| 2612 | |
| 2613 | /* capture mixer elements */ |
| 2614 | static struct snd_kcontrol_new vt1709_capture_mixer[] = { |
| 2615 | HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT), |
| 2616 | HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT), |
| 2617 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT), |
| 2618 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT), |
| 2619 | HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT), |
| 2620 | HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT), |
| 2621 | { |
| 2622 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2623 | /* The multiple "Capture Source" controls confuse alsamixer |
| 2624 | * So call somewhat different.. |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2625 | */ |
| 2626 | /* .name = "Capture Source", */ |
| 2627 | .name = "Input Source", |
| 2628 | .count = 1, |
| 2629 | .info = via_mux_enum_info, |
| 2630 | .get = via_mux_enum_get, |
| 2631 | .put = via_mux_enum_put, |
| 2632 | }, |
| 2633 | { } /* end */ |
| 2634 | }; |
| 2635 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2636 | static struct hda_verb vt1709_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 2637 | {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 2638 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 2639 | { } |
| 2640 | }; |
| 2641 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2642 | /* |
| 2643 | * generic initialization of ADC, input mixers and output mixers |
| 2644 | */ |
| 2645 | static struct hda_verb vt1709_10ch_volume_init_verbs[] = { |
| 2646 | /* |
| 2647 | * Unmute ADC0-2 and set the default input to mic-in |
| 2648 | */ |
| 2649 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2650 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2651 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2652 | |
| 2653 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2654 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2655 | * mixer widget |
| 2656 | */ |
| 2657 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2658 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 2659 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 2660 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 2661 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 2662 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2663 | |
| 2664 | /* |
| 2665 | * Set up output selector (0x1a, 0x1b, 0x29) |
| 2666 | */ |
| 2667 | /* set vol=0 to output mixers */ |
| 2668 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2669 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2670 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2671 | |
| 2672 | /* |
| 2673 | * Unmute PW3 and PW4 |
| 2674 | */ |
| 2675 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2676 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 2677 | |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 2678 | /* Set input of PW4 as MW0 */ |
| 2679 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2680 | /* PW9 Output enable */ |
| 2681 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 2682 | { } |
| 2683 | }; |
| 2684 | |
| 2685 | static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = { |
| 2686 | .substreams = 1, |
| 2687 | .channels_min = 2, |
| 2688 | .channels_max = 10, |
| 2689 | .nid = 0x10, /* NID to query formats and rates */ |
| 2690 | .ops = { |
| 2691 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 2692 | .prepare = via_playback_multi_pcm_prepare, |
| 2693 | .cleanup = via_playback_multi_pcm_cleanup, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2694 | }, |
| 2695 | }; |
| 2696 | |
| 2697 | static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = { |
| 2698 | .substreams = 1, |
| 2699 | .channels_min = 2, |
| 2700 | .channels_max = 6, |
| 2701 | .nid = 0x10, /* NID to query formats and rates */ |
| 2702 | .ops = { |
| 2703 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 2704 | .prepare = via_playback_multi_pcm_prepare, |
| 2705 | .cleanup = via_playback_multi_pcm_cleanup, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2706 | }, |
| 2707 | }; |
| 2708 | |
| 2709 | static struct hda_pcm_stream vt1709_pcm_analog_capture = { |
| 2710 | .substreams = 2, |
| 2711 | .channels_min = 2, |
| 2712 | .channels_max = 2, |
| 2713 | .nid = 0x14, /* NID to query formats and rates */ |
| 2714 | .ops = { |
| 2715 | .prepare = via_capture_pcm_prepare, |
| 2716 | .cleanup = via_capture_pcm_cleanup |
| 2717 | }, |
| 2718 | }; |
| 2719 | |
| 2720 | static struct hda_pcm_stream vt1709_pcm_digital_playback = { |
| 2721 | .substreams = 1, |
| 2722 | .channels_min = 2, |
| 2723 | .channels_max = 2, |
| 2724 | /* NID is set in via_build_pcms */ |
| 2725 | .ops = { |
| 2726 | .open = via_dig_playback_pcm_open, |
| 2727 | .close = via_dig_playback_pcm_close |
| 2728 | }, |
| 2729 | }; |
| 2730 | |
| 2731 | static struct hda_pcm_stream vt1709_pcm_digital_capture = { |
| 2732 | .substreams = 1, |
| 2733 | .channels_min = 2, |
| 2734 | .channels_max = 2, |
| 2735 | }; |
| 2736 | |
| 2737 | static int vt1709_auto_fill_dac_nids(struct via_spec *spec, |
| 2738 | const struct auto_pin_cfg *cfg) |
| 2739 | { |
| 2740 | int i; |
| 2741 | hda_nid_t nid; |
| 2742 | |
| 2743 | if (cfg->line_outs == 4) /* 10 channels */ |
| 2744 | spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */ |
| 2745 | else if (cfg->line_outs == 3) /* 6 channels */ |
| 2746 | spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */ |
| 2747 | |
| 2748 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 2749 | |
| 2750 | if (cfg->line_outs == 4) { /* 10 channels */ |
| 2751 | for (i = 0; i < cfg->line_outs; i++) { |
| 2752 | nid = cfg->line_out_pins[i]; |
| 2753 | if (nid) { |
| 2754 | /* config dac list */ |
| 2755 | switch (i) { |
| 2756 | case AUTO_SEQ_FRONT: |
| 2757 | /* AOW0 */ |
| 2758 | spec->multiout.dac_nids[i] = 0x10; |
| 2759 | break; |
| 2760 | case AUTO_SEQ_CENLFE: |
| 2761 | /* AOW2 */ |
| 2762 | spec->multiout.dac_nids[i] = 0x12; |
| 2763 | break; |
| 2764 | case AUTO_SEQ_SURROUND: |
| 2765 | /* AOW3 */ |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 2766 | spec->multiout.dac_nids[i] = 0x11; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2767 | break; |
| 2768 | case AUTO_SEQ_SIDE: |
| 2769 | /* AOW1 */ |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 2770 | spec->multiout.dac_nids[i] = 0x27; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2771 | break; |
| 2772 | default: |
| 2773 | break; |
| 2774 | } |
| 2775 | } |
| 2776 | } |
| 2777 | spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */ |
| 2778 | |
| 2779 | } else if (cfg->line_outs == 3) { /* 6 channels */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2780 | for (i = 0; i < cfg->line_outs; i++) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2781 | nid = cfg->line_out_pins[i]; |
| 2782 | if (nid) { |
| 2783 | /* config dac list */ |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2784 | switch (i) { |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2785 | case AUTO_SEQ_FRONT: |
| 2786 | /* AOW0 */ |
| 2787 | spec->multiout.dac_nids[i] = 0x10; |
| 2788 | break; |
| 2789 | case AUTO_SEQ_CENLFE: |
| 2790 | /* AOW2 */ |
| 2791 | spec->multiout.dac_nids[i] = 0x12; |
| 2792 | break; |
| 2793 | case AUTO_SEQ_SURROUND: |
| 2794 | /* AOW1 */ |
| 2795 | spec->multiout.dac_nids[i] = 0x11; |
| 2796 | break; |
| 2797 | default: |
| 2798 | break; |
| 2799 | } |
| 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | return 0; |
| 2805 | } |
| 2806 | |
| 2807 | /* add playback controls from the parsed DAC table */ |
| 2808 | static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec, |
| 2809 | const struct auto_pin_cfg *cfg) |
| 2810 | { |
| 2811 | char name[32]; |
| 2812 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2813 | hda_nid_t nid, nid_vol, nid_vols[] = {0x18, 0x1a, 0x1b, 0x29}; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2814 | int i, err; |
| 2815 | |
| 2816 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 2817 | nid = cfg->line_out_pins[i]; |
| 2818 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2819 | if (!nid) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2820 | continue; |
| 2821 | |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2822 | nid_vol = nid_vols[i]; |
| 2823 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2824 | if (i == AUTO_SEQ_CENLFE) { |
| 2825 | /* Center/LFE */ |
| 2826 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2827 | "Center Playback Volume", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2828 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2829 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2830 | if (err < 0) |
| 2831 | return err; |
| 2832 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2833 | "LFE Playback Volume", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2834 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2835 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2836 | if (err < 0) |
| 2837 | return err; |
| 2838 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2839 | "Center Playback Switch", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2840 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2841 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2842 | if (err < 0) |
| 2843 | return err; |
| 2844 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2845 | "LFE Playback Switch", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2846 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2847 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2848 | if (err < 0) |
| 2849 | return err; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2850 | } else if (i == AUTO_SEQ_FRONT) { |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2851 | /* ADD control to mixer index 0 */ |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2852 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2853 | "Master Front Playback Volume", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2854 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2855 | HDA_INPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2856 | if (err < 0) |
| 2857 | return err; |
| 2858 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2859 | "Master Front Playback Switch", |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2860 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2861 | HDA_INPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2862 | if (err < 0) |
| 2863 | return err; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2864 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2865 | /* add control to PW3 */ |
| 2866 | sprintf(name, "%s Playback Volume", chname[i]); |
| 2867 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2868 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 2869 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2870 | if (err < 0) |
| 2871 | return err; |
| 2872 | sprintf(name, "%s Playback Switch", chname[i]); |
| 2873 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2874 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 2875 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2876 | if (err < 0) |
| 2877 | return err; |
| 2878 | } else if (i == AUTO_SEQ_SURROUND) { |
| 2879 | sprintf(name, "%s Playback Volume", chname[i]); |
| 2880 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2881 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2882 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2883 | if (err < 0) |
| 2884 | return err; |
| 2885 | sprintf(name, "%s Playback Switch", chname[i]); |
| 2886 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2887 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2888 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2889 | if (err < 0) |
| 2890 | return err; |
| 2891 | } else if (i == AUTO_SEQ_SIDE) { |
| 2892 | sprintf(name, "%s Playback Volume", chname[i]); |
| 2893 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2894 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2895 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2896 | if (err < 0) |
| 2897 | return err; |
| 2898 | sprintf(name, "%s Playback Switch", chname[i]); |
| 2899 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
Lydia Wang | 4483a2f | 2009-10-10 19:08:29 +0800 | [diff] [blame] | 2900 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 2901 | HDA_OUTPUT)); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2902 | if (err < 0) |
| 2903 | return err; |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | return 0; |
| 2908 | } |
| 2909 | |
| 2910 | static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 2911 | { |
| 2912 | int err; |
| 2913 | |
| 2914 | if (!pin) |
| 2915 | return 0; |
| 2916 | |
| 2917 | if (spec->multiout.num_dacs == 5) /* 10 channels */ |
| 2918 | spec->multiout.hp_nid = VT1709_HP_DAC_NID; |
| 2919 | else if (spec->multiout.num_dacs == 3) /* 6 channels */ |
| 2920 | spec->multiout.hp_nid = 0; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 2921 | spec->hp_independent_mode_index = 1; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2922 | |
| 2923 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 2924 | "Headphone Playback Volume", |
| 2925 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 2926 | if (err < 0) |
| 2927 | return err; |
| 2928 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 2929 | "Headphone Playback Switch", |
| 2930 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 2931 | if (err < 0) |
| 2932 | return err; |
| 2933 | |
| 2934 | return 0; |
| 2935 | } |
| 2936 | |
| 2937 | /* create playback/capture controls for input pins */ |
| 2938 | static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec, |
| 2939 | const struct auto_pin_cfg *cfg) |
| 2940 | { |
| 2941 | static char *labels[] = { |
| 2942 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 2943 | }; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 2944 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2945 | int i, err, idx = 0; |
| 2946 | |
| 2947 | /* for internal loopback recording select */ |
| 2948 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 2949 | imux->items[imux->num_items].index = idx; |
| 2950 | imux->num_items++; |
| 2951 | |
| 2952 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 2953 | if (!cfg->input_pins[i]) |
| 2954 | continue; |
| 2955 | |
| 2956 | switch (cfg->input_pins[i]) { |
| 2957 | case 0x1d: /* Mic */ |
| 2958 | idx = 2; |
| 2959 | break; |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 2960 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2961 | case 0x1e: /* Line In */ |
| 2962 | idx = 3; |
| 2963 | break; |
| 2964 | |
| 2965 | case 0x21: /* Front Mic */ |
| 2966 | idx = 4; |
| 2967 | break; |
| 2968 | |
| 2969 | case 0x23: /* CD */ |
| 2970 | idx = 1; |
| 2971 | break; |
| 2972 | } |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 2973 | err = via_new_analog_input(spec, labels[i], idx, 0x18); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 2974 | if (err < 0) |
| 2975 | return err; |
| 2976 | imux->items[imux->num_items].label = labels[i]; |
| 2977 | imux->items[imux->num_items].index = idx; |
| 2978 | imux->num_items++; |
| 2979 | } |
| 2980 | return 0; |
| 2981 | } |
| 2982 | |
| 2983 | static int vt1709_parse_auto_config(struct hda_codec *codec) |
| 2984 | { |
| 2985 | struct via_spec *spec = codec->spec; |
| 2986 | int err; |
| 2987 | |
| 2988 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 2989 | if (err < 0) |
| 2990 | return err; |
| 2991 | err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg); |
| 2992 | if (err < 0) |
| 2993 | return err; |
| 2994 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 2995 | return 0; /* can't find valid BIOS pin config */ |
| 2996 | |
| 2997 | err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 2998 | if (err < 0) |
| 2999 | return err; |
| 3000 | err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 3001 | if (err < 0) |
| 3002 | return err; |
| 3003 | err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 3004 | if (err < 0) |
| 3005 | return err; |
| 3006 | |
| 3007 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3008 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 3009 | if (spec->autocfg.dig_outs) |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3010 | spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 3011 | spec->dig_in_pin = VT1709_DIGIN_PIN; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3012 | if (spec->autocfg.dig_in_pin) |
| 3013 | spec->dig_in_nid = VT1709_DIGIN_NID; |
| 3014 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3015 | if (spec->kctls.list) |
| 3016 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3017 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3018 | spec->input_mux = &spec->private_imux[0]; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3019 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 3020 | if (spec->hp_mux) |
| 3021 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
| 3022 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 3023 | spec->mixers[spec->num_mixers++] = via_smart51_mixer; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3024 | return 1; |
| 3025 | } |
| 3026 | |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3027 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3028 | static struct hda_amp_list vt1709_loopbacks[] = { |
| 3029 | { 0x18, HDA_INPUT, 1 }, |
| 3030 | { 0x18, HDA_INPUT, 2 }, |
| 3031 | { 0x18, HDA_INPUT, 3 }, |
| 3032 | { 0x18, HDA_INPUT, 4 }, |
| 3033 | { } /* end */ |
| 3034 | }; |
| 3035 | #endif |
| 3036 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3037 | static int patch_vt1709_10ch(struct hda_codec *codec) |
| 3038 | { |
| 3039 | struct via_spec *spec; |
| 3040 | int err; |
| 3041 | |
| 3042 | /* create a codec specific record */ |
Harald Welte | eb14a46 | 2008-09-09 15:40:38 +0800 | [diff] [blame] | 3043 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3044 | if (spec == NULL) |
| 3045 | return -ENOMEM; |
| 3046 | |
| 3047 | codec->spec = spec; |
| 3048 | |
| 3049 | err = vt1709_parse_auto_config(codec); |
| 3050 | if (err < 0) { |
| 3051 | via_free(codec); |
| 3052 | return err; |
| 3053 | } else if (!err) { |
| 3054 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " |
| 3055 | "Using genenic mode...\n"); |
| 3056 | } |
| 3057 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3058 | spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs; |
| 3059 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3060 | |
| 3061 | spec->stream_name_analog = "VT1709 Analog"; |
| 3062 | spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback; |
| 3063 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; |
| 3064 | |
| 3065 | spec->stream_name_digital = "VT1709 Digital"; |
| 3066 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; |
| 3067 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; |
| 3068 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 3069 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3070 | if (!spec->adc_nids && spec->input_mux) { |
| 3071 | spec->adc_nids = vt1709_adc_nids; |
| 3072 | spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 3073 | get_mux_nids(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3074 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
| 3075 | spec->num_mixers++; |
| 3076 | } |
| 3077 | |
| 3078 | codec->patch_ops = via_patch_ops; |
| 3079 | |
| 3080 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3081 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3082 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3083 | spec->loopback.amplist = vt1709_loopbacks; |
| 3084 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3085 | |
| 3086 | return 0; |
| 3087 | } |
| 3088 | /* |
| 3089 | * generic initialization of ADC, input mixers and output mixers |
| 3090 | */ |
| 3091 | static struct hda_verb vt1709_6ch_volume_init_verbs[] = { |
| 3092 | /* |
| 3093 | * Unmute ADC0-2 and set the default input to mic-in |
| 3094 | */ |
| 3095 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3096 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3097 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3098 | |
| 3099 | |
| 3100 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3101 | * mixer widget |
| 3102 | */ |
| 3103 | /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3104 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3105 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3106 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3107 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3108 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 3109 | |
| 3110 | /* |
| 3111 | * Set up output selector (0x1a, 0x1b, 0x29) |
| 3112 | */ |
| 3113 | /* set vol=0 to output mixers */ |
| 3114 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3115 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3116 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3117 | |
| 3118 | /* |
| 3119 | * Unmute PW3 and PW4 |
| 3120 | */ |
| 3121 | {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3122 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3123 | |
| 3124 | /* Set input of PW4 as MW0 */ |
| 3125 | {0x20, AC_VERB_SET_CONNECT_SEL, 0}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3126 | /* PW9 Output enable */ |
| 3127 | {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3128 | { } |
| 3129 | }; |
| 3130 | |
| 3131 | static int patch_vt1709_6ch(struct hda_codec *codec) |
| 3132 | { |
| 3133 | struct via_spec *spec; |
| 3134 | int err; |
| 3135 | |
| 3136 | /* create a codec specific record */ |
Harald Welte | eb14a46 | 2008-09-09 15:40:38 +0800 | [diff] [blame] | 3137 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3138 | if (spec == NULL) |
| 3139 | return -ENOMEM; |
| 3140 | |
| 3141 | codec->spec = spec; |
| 3142 | |
| 3143 | err = vt1709_parse_auto_config(codec); |
| 3144 | if (err < 0) { |
| 3145 | via_free(codec); |
| 3146 | return err; |
| 3147 | } else if (!err) { |
| 3148 | printk(KERN_INFO "hda_codec: Cannot set up configuration. " |
| 3149 | "Using genenic mode...\n"); |
| 3150 | } |
| 3151 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3152 | spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs; |
| 3153 | spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs; |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3154 | |
| 3155 | spec->stream_name_analog = "VT1709 Analog"; |
| 3156 | spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback; |
| 3157 | spec->stream_analog_capture = &vt1709_pcm_analog_capture; |
| 3158 | |
| 3159 | spec->stream_name_digital = "VT1709 Digital"; |
| 3160 | spec->stream_digital_playback = &vt1709_pcm_digital_playback; |
| 3161 | spec->stream_digital_capture = &vt1709_pcm_digital_capture; |
| 3162 | |
Lydia Wang | 377ff31 | 2009-10-10 19:08:55 +0800 | [diff] [blame] | 3163 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3164 | if (!spec->adc_nids && spec->input_mux) { |
| 3165 | spec->adc_nids = vt1709_adc_nids; |
| 3166 | spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids); |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 3167 | get_mux_nids(codec); |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3168 | spec->mixers[spec->num_mixers] = vt1709_capture_mixer; |
| 3169 | spec->num_mixers++; |
| 3170 | } |
| 3171 | |
| 3172 | codec->patch_ops = via_patch_ops; |
| 3173 | |
| 3174 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3175 | codec->patch_ops.unsol_event = via_unsol_event; |
Takashi Iwai | cb53c62 | 2007-08-10 17:21:45 +0200 | [diff] [blame] | 3176 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3177 | spec->loopback.amplist = vt1709_loopbacks; |
| 3178 | #endif |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3179 | return 0; |
| 3180 | } |
| 3181 | |
| 3182 | /* capture mixer elements */ |
| 3183 | static struct snd_kcontrol_new vt1708B_capture_mixer[] = { |
| 3184 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 3185 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 3186 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 3187 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
| 3188 | { |
| 3189 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3190 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3191 | * So call somewhat different.. |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3192 | */ |
| 3193 | /* .name = "Capture Source", */ |
| 3194 | .name = "Input Source", |
| 3195 | .count = 1, |
| 3196 | .info = via_mux_enum_info, |
| 3197 | .get = via_mux_enum_get, |
| 3198 | .put = via_mux_enum_put, |
| 3199 | }, |
| 3200 | { } /* end */ |
| 3201 | }; |
| 3202 | /* |
| 3203 | * generic initialization of ADC, input mixers and output mixers |
| 3204 | */ |
| 3205 | static struct hda_verb vt1708B_8ch_volume_init_verbs[] = { |
| 3206 | /* |
| 3207 | * Unmute ADC0-1 and set the default input to mic-in |
| 3208 | */ |
| 3209 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3210 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3211 | |
| 3212 | |
| 3213 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3214 | * mixer widget |
| 3215 | */ |
| 3216 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3217 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3218 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3219 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3220 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3221 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 3222 | |
| 3223 | /* |
| 3224 | * Set up output mixers |
| 3225 | */ |
| 3226 | /* set vol=0 to output mixers */ |
| 3227 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3228 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3229 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3230 | |
| 3231 | /* Setup default input to PW4 */ |
Lydia Wang | bfdc675 | 2009-10-10 19:08:50 +0800 | [diff] [blame] | 3232 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0}, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3233 | /* PW9 Output enable */ |
| 3234 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3235 | /* PW10 Input enable */ |
| 3236 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, |
| 3237 | { } |
| 3238 | }; |
| 3239 | |
| 3240 | static struct hda_verb vt1708B_4ch_volume_init_verbs[] = { |
| 3241 | /* |
| 3242 | * Unmute ADC0-1 and set the default input to mic-in |
| 3243 | */ |
| 3244 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3245 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3246 | |
| 3247 | |
| 3248 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 3249 | * mixer widget |
| 3250 | */ |
| 3251 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3252 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3253 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3254 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3255 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3256 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 3257 | |
| 3258 | /* |
| 3259 | * Set up output mixers |
| 3260 | */ |
| 3261 | /* set vol=0 to output mixers */ |
| 3262 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3263 | {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3264 | {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, |
| 3265 | |
| 3266 | /* Setup default input of PW4 to MW0 */ |
| 3267 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 3268 | /* PW9 Output enable */ |
| 3269 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 3270 | /* PW10 Input enable */ |
| 3271 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, |
| 3272 | { } |
| 3273 | }; |
| 3274 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3275 | static struct hda_verb vt1708B_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 3276 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3277 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3278 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3279 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3280 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3281 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3282 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3283 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3284 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3285 | { } |
| 3286 | }; |
| 3287 | |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3288 | static int via_pcm_open_close(struct hda_pcm_stream *hinfo, |
| 3289 | struct hda_codec *codec, |
| 3290 | struct snd_pcm_substream *substream) |
| 3291 | { |
| 3292 | int idle = substream->pstr->substream_opened == 1 |
| 3293 | && substream->ref_count == 0; |
| 3294 | |
| 3295 | analog_low_current_mode(codec, idle); |
| 3296 | return 0; |
| 3297 | } |
| 3298 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3299 | static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3300 | .substreams = 2, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3301 | .channels_min = 2, |
| 3302 | .channels_max = 8, |
| 3303 | .nid = 0x10, /* NID to query formats and rates */ |
| 3304 | .ops = { |
| 3305 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3306 | .prepare = via_playback_multi_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3307 | .cleanup = via_playback_multi_pcm_cleanup, |
| 3308 | .close = via_pcm_open_close |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3309 | }, |
| 3310 | }; |
| 3311 | |
| 3312 | static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3313 | .substreams = 2, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3314 | .channels_min = 2, |
| 3315 | .channels_max = 4, |
| 3316 | .nid = 0x10, /* NID to query formats and rates */ |
| 3317 | .ops = { |
| 3318 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3319 | .prepare = via_playback_multi_pcm_prepare, |
| 3320 | .cleanup = via_playback_multi_pcm_cleanup |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3321 | }, |
| 3322 | }; |
| 3323 | |
| 3324 | static struct hda_pcm_stream vt1708B_pcm_analog_capture = { |
| 3325 | .substreams = 2, |
| 3326 | .channels_min = 2, |
| 3327 | .channels_max = 2, |
| 3328 | .nid = 0x13, /* NID to query formats and rates */ |
| 3329 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3330 | .open = via_pcm_open_close, |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3331 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3332 | .cleanup = via_capture_pcm_cleanup, |
| 3333 | .close = via_pcm_open_close |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3334 | }, |
| 3335 | }; |
| 3336 | |
| 3337 | static struct hda_pcm_stream vt1708B_pcm_digital_playback = { |
| 3338 | .substreams = 1, |
| 3339 | .channels_min = 2, |
| 3340 | .channels_max = 2, |
| 3341 | /* NID is set in via_build_pcms */ |
| 3342 | .ops = { |
| 3343 | .open = via_dig_playback_pcm_open, |
| 3344 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3345 | .prepare = via_dig_playback_pcm_prepare, |
| 3346 | .cleanup = via_dig_playback_pcm_cleanup |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3347 | }, |
| 3348 | }; |
| 3349 | |
| 3350 | static struct hda_pcm_stream vt1708B_pcm_digital_capture = { |
| 3351 | .substreams = 1, |
| 3352 | .channels_min = 2, |
| 3353 | .channels_max = 2, |
| 3354 | }; |
| 3355 | |
| 3356 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 3357 | static int vt1708B_auto_fill_dac_nids(struct via_spec *spec, |
| 3358 | const struct auto_pin_cfg *cfg) |
| 3359 | { |
| 3360 | int i; |
| 3361 | hda_nid_t nid; |
| 3362 | |
| 3363 | spec->multiout.num_dacs = cfg->line_outs; |
| 3364 | |
| 3365 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 3366 | |
| 3367 | for (i = 0; i < 4; i++) { |
| 3368 | nid = cfg->line_out_pins[i]; |
| 3369 | if (nid) { |
| 3370 | /* config dac list */ |
| 3371 | switch (i) { |
| 3372 | case AUTO_SEQ_FRONT: |
| 3373 | spec->multiout.dac_nids[i] = 0x10; |
| 3374 | break; |
| 3375 | case AUTO_SEQ_CENLFE: |
| 3376 | spec->multiout.dac_nids[i] = 0x24; |
| 3377 | break; |
| 3378 | case AUTO_SEQ_SURROUND: |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 3379 | spec->multiout.dac_nids[i] = 0x11; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3380 | break; |
| 3381 | case AUTO_SEQ_SIDE: |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 3382 | spec->multiout.dac_nids[i] = 0x25; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3383 | break; |
| 3384 | } |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | return 0; |
| 3389 | } |
| 3390 | |
| 3391 | /* add playback controls from the parsed DAC table */ |
| 3392 | static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec, |
| 3393 | const struct auto_pin_cfg *cfg) |
| 3394 | { |
| 3395 | char name[32]; |
| 3396 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; |
Harald Welte | fb4cb77 | 2008-09-09 15:53:36 +0800 | [diff] [blame] | 3397 | hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27}; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3398 | hda_nid_t nid, nid_vol = 0; |
| 3399 | int i, err; |
| 3400 | |
| 3401 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 3402 | nid = cfg->line_out_pins[i]; |
| 3403 | |
| 3404 | if (!nid) |
| 3405 | continue; |
| 3406 | |
| 3407 | nid_vol = nid_vols[i]; |
| 3408 | |
| 3409 | if (i == AUTO_SEQ_CENLFE) { |
| 3410 | /* Center/LFE */ |
| 3411 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3412 | "Center Playback Volume", |
| 3413 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 3414 | HDA_OUTPUT)); |
| 3415 | if (err < 0) |
| 3416 | return err; |
| 3417 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3418 | "LFE Playback Volume", |
| 3419 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 3420 | HDA_OUTPUT)); |
| 3421 | if (err < 0) |
| 3422 | return err; |
| 3423 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3424 | "Center Playback Switch", |
| 3425 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 3426 | HDA_OUTPUT)); |
| 3427 | if (err < 0) |
| 3428 | return err; |
| 3429 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3430 | "LFE Playback Switch", |
| 3431 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 3432 | HDA_OUTPUT)); |
| 3433 | if (err < 0) |
| 3434 | return err; |
| 3435 | } else if (i == AUTO_SEQ_FRONT) { |
| 3436 | /* add control to mixer index 0 */ |
| 3437 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3438 | "Master Front Playback Volume", |
| 3439 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3440 | HDA_INPUT)); |
| 3441 | if (err < 0) |
| 3442 | return err; |
| 3443 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3444 | "Master Front Playback Switch", |
| 3445 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3446 | HDA_INPUT)); |
| 3447 | if (err < 0) |
| 3448 | return err; |
| 3449 | |
| 3450 | /* add control to PW3 */ |
| 3451 | sprintf(name, "%s Playback Volume", chname[i]); |
| 3452 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 3453 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 3454 | HDA_OUTPUT)); |
| 3455 | if (err < 0) |
| 3456 | return err; |
| 3457 | sprintf(name, "%s Playback Switch", chname[i]); |
| 3458 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 3459 | HDA_COMPOSE_AMP_VAL(nid, 3, 0, |
| 3460 | HDA_OUTPUT)); |
| 3461 | if (err < 0) |
| 3462 | return err; |
| 3463 | } else { |
| 3464 | sprintf(name, "%s Playback Volume", chname[i]); |
| 3465 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 3466 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3467 | HDA_OUTPUT)); |
| 3468 | if (err < 0) |
| 3469 | return err; |
| 3470 | sprintf(name, "%s Playback Switch", chname[i]); |
| 3471 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 3472 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3473 | HDA_OUTPUT)); |
| 3474 | if (err < 0) |
| 3475 | return err; |
| 3476 | } |
| 3477 | } |
| 3478 | |
| 3479 | return 0; |
| 3480 | } |
| 3481 | |
| 3482 | static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 3483 | { |
| 3484 | int err; |
| 3485 | |
| 3486 | if (!pin) |
| 3487 | return 0; |
| 3488 | |
| 3489 | spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */ |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 3490 | spec->hp_independent_mode_index = 1; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3491 | |
| 3492 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3493 | "Headphone Playback Volume", |
| 3494 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 3495 | if (err < 0) |
| 3496 | return err; |
| 3497 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3498 | "Headphone Playback Switch", |
| 3499 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 3500 | if (err < 0) |
| 3501 | return err; |
| 3502 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3503 | create_hp_imux(spec); |
| 3504 | |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3505 | return 0; |
| 3506 | } |
| 3507 | |
| 3508 | /* create playback/capture controls for input pins */ |
| 3509 | static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec, |
| 3510 | const struct auto_pin_cfg *cfg) |
| 3511 | { |
| 3512 | static char *labels[] = { |
| 3513 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 3514 | }; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3515 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3516 | int i, err, idx = 0; |
| 3517 | |
| 3518 | /* for internal loopback recording select */ |
| 3519 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 3520 | imux->items[imux->num_items].index = idx; |
| 3521 | imux->num_items++; |
| 3522 | |
| 3523 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 3524 | if (!cfg->input_pins[i]) |
| 3525 | continue; |
| 3526 | |
| 3527 | switch (cfg->input_pins[i]) { |
| 3528 | case 0x1a: /* Mic */ |
| 3529 | idx = 2; |
| 3530 | break; |
| 3531 | |
| 3532 | case 0x1b: /* Line In */ |
| 3533 | idx = 3; |
| 3534 | break; |
| 3535 | |
| 3536 | case 0x1e: /* Front Mic */ |
| 3537 | idx = 4; |
| 3538 | break; |
| 3539 | |
| 3540 | case 0x1f: /* CD */ |
| 3541 | idx = 1; |
| 3542 | break; |
| 3543 | } |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 3544 | err = via_new_analog_input(spec, labels[i], idx, 0x16); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3545 | if (err < 0) |
| 3546 | return err; |
| 3547 | imux->items[imux->num_items].label = labels[i]; |
| 3548 | imux->items[imux->num_items].index = idx; |
| 3549 | imux->num_items++; |
| 3550 | } |
| 3551 | return 0; |
| 3552 | } |
| 3553 | |
| 3554 | static int vt1708B_parse_auto_config(struct hda_codec *codec) |
| 3555 | { |
| 3556 | struct via_spec *spec = codec->spec; |
| 3557 | int err; |
| 3558 | |
| 3559 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 3560 | if (err < 0) |
| 3561 | return err; |
| 3562 | err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg); |
| 3563 | if (err < 0) |
| 3564 | return err; |
| 3565 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 3566 | return 0; /* can't find valid BIOS pin config */ |
| 3567 | |
| 3568 | err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 3569 | if (err < 0) |
| 3570 | return err; |
| 3571 | err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 3572 | if (err < 0) |
| 3573 | return err; |
| 3574 | err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 3575 | if (err < 0) |
| 3576 | return err; |
| 3577 | |
| 3578 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 3579 | |
Takashi Iwai | 0852d7a | 2009-02-11 11:35:15 +0100 | [diff] [blame] | 3580 | if (spec->autocfg.dig_outs) |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3581 | spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; |
Takashi Iwai | 55d1d6c | 2009-07-07 13:39:03 +0200 | [diff] [blame] | 3582 | spec->dig_in_pin = VT1708B_DIGIN_PIN; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3583 | if (spec->autocfg.dig_in_pin) |
| 3584 | spec->dig_in_nid = VT1708B_DIGIN_NID; |
| 3585 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 3586 | if (spec->kctls.list) |
| 3587 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3588 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3589 | spec->input_mux = &spec->private_imux[0]; |
| 3590 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 3591 | if (spec->hp_mux) |
| 3592 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3593 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 3594 | spec->mixers[spec->num_mixers++] = via_smart51_mixer; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3595 | return 1; |
| 3596 | } |
| 3597 | |
| 3598 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3599 | static struct hda_amp_list vt1708B_loopbacks[] = { |
| 3600 | { 0x16, HDA_INPUT, 1 }, |
| 3601 | { 0x16, HDA_INPUT, 2 }, |
| 3602 | { 0x16, HDA_INPUT, 3 }, |
| 3603 | { 0x16, HDA_INPUT, 4 }, |
| 3604 | { } /* end */ |
| 3605 | }; |
| 3606 | #endif |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3607 | static int patch_vt1708S(struct hda_codec *codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3608 | static int patch_vt1708B_8ch(struct hda_codec *codec) |
| 3609 | { |
| 3610 | struct via_spec *spec; |
| 3611 | int err; |
| 3612 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 3613 | if (get_codec_type(codec) == VT1708BCE) |
| 3614 | return patch_vt1708S(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3615 | /* create a codec specific record */ |
Harald Welte | eb14a46 | 2008-09-09 15:40:38 +0800 | [diff] [blame] | 3616 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3617 | if (spec == NULL) |
| 3618 | return -ENOMEM; |
| 3619 | |
| 3620 | codec->spec = spec; |
| 3621 | |
| 3622 | /* automatic parse from the BIOS config */ |
| 3623 | err = vt1708B_parse_auto_config(codec); |
| 3624 | if (err < 0) { |
| 3625 | via_free(codec); |
| 3626 | return err; |
| 3627 | } else if (!err) { |
| 3628 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3629 | "from BIOS. Using genenic mode...\n"); |
| 3630 | } |
| 3631 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3632 | spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs; |
| 3633 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3634 | |
| 3635 | spec->stream_name_analog = "VT1708B Analog"; |
| 3636 | spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback; |
| 3637 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; |
| 3638 | |
| 3639 | spec->stream_name_digital = "VT1708B Digital"; |
| 3640 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; |
| 3641 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; |
| 3642 | |
| 3643 | if (!spec->adc_nids && spec->input_mux) { |
| 3644 | spec->adc_nids = vt1708B_adc_nids; |
| 3645 | spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids); |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 3646 | get_mux_nids(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3647 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
| 3648 | spec->num_mixers++; |
| 3649 | } |
| 3650 | |
| 3651 | codec->patch_ops = via_patch_ops; |
| 3652 | |
| 3653 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3654 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3655 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3656 | spec->loopback.amplist = vt1708B_loopbacks; |
| 3657 | #endif |
| 3658 | |
| 3659 | return 0; |
| 3660 | } |
| 3661 | |
| 3662 | static int patch_vt1708B_4ch(struct hda_codec *codec) |
| 3663 | { |
| 3664 | struct via_spec *spec; |
| 3665 | int err; |
| 3666 | |
| 3667 | /* create a codec specific record */ |
Harald Welte | eb14a46 | 2008-09-09 15:40:38 +0800 | [diff] [blame] | 3668 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3669 | if (spec == NULL) |
| 3670 | return -ENOMEM; |
| 3671 | |
| 3672 | codec->spec = spec; |
| 3673 | |
| 3674 | /* automatic parse from the BIOS config */ |
| 3675 | err = vt1708B_parse_auto_config(codec); |
| 3676 | if (err < 0) { |
| 3677 | via_free(codec); |
| 3678 | return err; |
| 3679 | } else if (!err) { |
| 3680 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 3681 | "from BIOS. Using genenic mode...\n"); |
| 3682 | } |
| 3683 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3684 | spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs; |
| 3685 | spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3686 | |
| 3687 | spec->stream_name_analog = "VT1708B Analog"; |
| 3688 | spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback; |
| 3689 | spec->stream_analog_capture = &vt1708B_pcm_analog_capture; |
| 3690 | |
| 3691 | spec->stream_name_digital = "VT1708B Digital"; |
| 3692 | spec->stream_digital_playback = &vt1708B_pcm_digital_playback; |
| 3693 | spec->stream_digital_capture = &vt1708B_pcm_digital_capture; |
| 3694 | |
| 3695 | if (!spec->adc_nids && spec->input_mux) { |
| 3696 | spec->adc_nids = vt1708B_adc_nids; |
| 3697 | spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids); |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 3698 | get_mux_nids(codec); |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3699 | spec->mixers[spec->num_mixers] = vt1708B_capture_mixer; |
| 3700 | spec->num_mixers++; |
| 3701 | } |
| 3702 | |
| 3703 | codec->patch_ops = via_patch_ops; |
| 3704 | |
| 3705 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3706 | codec->patch_ops.unsol_event = via_unsol_event; |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 3707 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 3708 | spec->loopback.amplist = vt1708B_loopbacks; |
| 3709 | #endif |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 3710 | |
| 3711 | return 0; |
| 3712 | } |
| 3713 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3714 | /* Patch for VT1708S */ |
| 3715 | |
| 3716 | /* capture mixer elements */ |
| 3717 | static struct snd_kcontrol_new vt1708S_capture_mixer[] = { |
| 3718 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 3719 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 3720 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 3721 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 3722 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
| 3723 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
| 3724 | HDA_INPUT), |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3725 | { |
| 3726 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3727 | /* The multiple "Capture Source" controls confuse alsamixer |
| 3728 | * So call somewhat different.. |
| 3729 | */ |
| 3730 | /* .name = "Capture Source", */ |
| 3731 | .name = "Input Source", |
| 3732 | .count = 1, |
| 3733 | .info = via_mux_enum_info, |
| 3734 | .get = via_mux_enum_get, |
| 3735 | .put = via_mux_enum_put, |
| 3736 | }, |
| 3737 | { } /* end */ |
| 3738 | }; |
| 3739 | |
| 3740 | static struct hda_verb vt1708S_volume_init_verbs[] = { |
| 3741 | /* Unmute ADC0-1 and set the default input to mic-in */ |
| 3742 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3743 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3744 | |
| 3745 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the |
| 3746 | * analog-loopback mixer widget */ |
| 3747 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 3748 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 3749 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 3750 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 3751 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 3752 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, |
| 3753 | |
| 3754 | /* Setup default input of PW4 to MW0 */ |
| 3755 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3756 | /* PW9, PW10 Output enable */ |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3757 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 3758 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Harald Welte | d742632 | 2008-09-15 22:43:23 +0800 | [diff] [blame] | 3759 | /* Enable Mic Boost Volume backdoor */ |
| 3760 | {0x1, 0xf98, 0x1}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 3761 | /* don't bybass mixer */ |
| 3762 | {0x1, 0xf88, 0xc0}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3763 | { } |
| 3764 | }; |
| 3765 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3766 | static struct hda_verb vt1708S_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 3767 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 3768 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 3769 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3770 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3771 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3772 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3773 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3774 | {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 3775 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 3776 | { } |
| 3777 | }; |
| 3778 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3779 | static struct hda_pcm_stream vt1708S_pcm_analog_playback = { |
| 3780 | .substreams = 2, |
| 3781 | .channels_min = 2, |
| 3782 | .channels_max = 8, |
| 3783 | .nid = 0x10, /* NID to query formats and rates */ |
| 3784 | .ops = { |
| 3785 | .open = via_playback_pcm_open, |
Lydia Wang | c873cc2 | 2009-10-10 19:08:21 +0800 | [diff] [blame] | 3786 | .prepare = via_playback_multi_pcm_prepare, |
| 3787 | .cleanup = via_playback_multi_pcm_cleanup, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3788 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3789 | }, |
| 3790 | }; |
| 3791 | |
| 3792 | static struct hda_pcm_stream vt1708S_pcm_analog_capture = { |
| 3793 | .substreams = 2, |
| 3794 | .channels_min = 2, |
| 3795 | .channels_max = 2, |
| 3796 | .nid = 0x13, /* NID to query formats and rates */ |
| 3797 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3798 | .open = via_pcm_open_close, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3799 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 3800 | .cleanup = via_capture_pcm_cleanup, |
| 3801 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3802 | }, |
| 3803 | }; |
| 3804 | |
| 3805 | static struct hda_pcm_stream vt1708S_pcm_digital_playback = { |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3806 | .substreams = 1, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3807 | .channels_min = 2, |
| 3808 | .channels_max = 2, |
| 3809 | /* NID is set in via_build_pcms */ |
| 3810 | .ops = { |
| 3811 | .open = via_dig_playback_pcm_open, |
| 3812 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 3813 | .prepare = via_dig_playback_pcm_prepare, |
| 3814 | .cleanup = via_dig_playback_pcm_cleanup |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3815 | }, |
| 3816 | }; |
| 3817 | |
| 3818 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 3819 | static int vt1708S_auto_fill_dac_nids(struct via_spec *spec, |
| 3820 | const struct auto_pin_cfg *cfg) |
| 3821 | { |
| 3822 | int i; |
| 3823 | hda_nid_t nid; |
| 3824 | |
| 3825 | spec->multiout.num_dacs = cfg->line_outs; |
| 3826 | |
| 3827 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 3828 | |
| 3829 | for (i = 0; i < 4; i++) { |
| 3830 | nid = cfg->line_out_pins[i]; |
| 3831 | if (nid) { |
| 3832 | /* config dac list */ |
| 3833 | switch (i) { |
| 3834 | case AUTO_SEQ_FRONT: |
| 3835 | spec->multiout.dac_nids[i] = 0x10; |
| 3836 | break; |
| 3837 | case AUTO_SEQ_CENLFE: |
| 3838 | spec->multiout.dac_nids[i] = 0x24; |
| 3839 | break; |
| 3840 | case AUTO_SEQ_SURROUND: |
| 3841 | spec->multiout.dac_nids[i] = 0x11; |
| 3842 | break; |
| 3843 | case AUTO_SEQ_SIDE: |
| 3844 | spec->multiout.dac_nids[i] = 0x25; |
| 3845 | break; |
| 3846 | } |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | return 0; |
| 3851 | } |
| 3852 | |
| 3853 | /* add playback controls from the parsed DAC table */ |
| 3854 | static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec, |
| 3855 | const struct auto_pin_cfg *cfg) |
| 3856 | { |
| 3857 | char name[32]; |
| 3858 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; |
| 3859 | hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25}; |
| 3860 | hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27}; |
| 3861 | hda_nid_t nid, nid_vol, nid_mute; |
| 3862 | int i, err; |
| 3863 | |
| 3864 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 3865 | nid = cfg->line_out_pins[i]; |
| 3866 | |
| 3867 | if (!nid) |
| 3868 | continue; |
| 3869 | |
| 3870 | nid_vol = nid_vols[i]; |
| 3871 | nid_mute = nid_mutes[i]; |
| 3872 | |
| 3873 | if (i == AUTO_SEQ_CENLFE) { |
| 3874 | /* Center/LFE */ |
| 3875 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3876 | "Center Playback Volume", |
| 3877 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 3878 | HDA_OUTPUT)); |
| 3879 | if (err < 0) |
| 3880 | return err; |
| 3881 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3882 | "LFE Playback Volume", |
| 3883 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 3884 | HDA_OUTPUT)); |
| 3885 | if (err < 0) |
| 3886 | return err; |
| 3887 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3888 | "Center Playback Switch", |
| 3889 | HDA_COMPOSE_AMP_VAL(nid_mute, |
| 3890 | 1, 0, |
| 3891 | HDA_OUTPUT)); |
| 3892 | if (err < 0) |
| 3893 | return err; |
| 3894 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3895 | "LFE Playback Switch", |
| 3896 | HDA_COMPOSE_AMP_VAL(nid_mute, |
| 3897 | 2, 0, |
| 3898 | HDA_OUTPUT)); |
| 3899 | if (err < 0) |
| 3900 | return err; |
| 3901 | } else if (i == AUTO_SEQ_FRONT) { |
| 3902 | /* add control to mixer index 0 */ |
| 3903 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3904 | "Master Front Playback Volume", |
| 3905 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, |
| 3906 | HDA_INPUT)); |
| 3907 | if (err < 0) |
| 3908 | return err; |
| 3909 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3910 | "Master Front Playback Switch", |
| 3911 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, |
| 3912 | HDA_INPUT)); |
| 3913 | if (err < 0) |
| 3914 | return err; |
| 3915 | |
| 3916 | /* Front */ |
| 3917 | sprintf(name, "%s Playback Volume", chname[i]); |
| 3918 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 3919 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3920 | HDA_OUTPUT)); |
| 3921 | if (err < 0) |
| 3922 | return err; |
| 3923 | sprintf(name, "%s Playback Switch", chname[i]); |
| 3924 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 3925 | HDA_COMPOSE_AMP_VAL(nid_mute, |
| 3926 | 3, 0, |
| 3927 | HDA_OUTPUT)); |
| 3928 | if (err < 0) |
| 3929 | return err; |
| 3930 | } else { |
| 3931 | sprintf(name, "%s Playback Volume", chname[i]); |
| 3932 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name, |
| 3933 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, |
| 3934 | HDA_OUTPUT)); |
| 3935 | if (err < 0) |
| 3936 | return err; |
| 3937 | sprintf(name, "%s Playback Switch", chname[i]); |
| 3938 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name, |
| 3939 | HDA_COMPOSE_AMP_VAL(nid_mute, |
| 3940 | 3, 0, |
| 3941 | HDA_OUTPUT)); |
| 3942 | if (err < 0) |
| 3943 | return err; |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | return 0; |
| 3948 | } |
| 3949 | |
| 3950 | static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 3951 | { |
| 3952 | int err; |
| 3953 | |
| 3954 | if (!pin) |
| 3955 | return 0; |
| 3956 | |
| 3957 | spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */ |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 3958 | spec->hp_independent_mode_index = 1; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3959 | |
| 3960 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 3961 | "Headphone Playback Volume", |
| 3962 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); |
| 3963 | if (err < 0) |
| 3964 | return err; |
| 3965 | |
| 3966 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 3967 | "Headphone Playback Switch", |
| 3968 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 3969 | if (err < 0) |
| 3970 | return err; |
| 3971 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3972 | create_hp_imux(spec); |
| 3973 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3974 | return 0; |
| 3975 | } |
| 3976 | |
| 3977 | /* create playback/capture controls for input pins */ |
| 3978 | static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec, |
| 3979 | const struct auto_pin_cfg *cfg) |
| 3980 | { |
| 3981 | static char *labels[] = { |
| 3982 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 3983 | }; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 3984 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 3985 | int i, err, idx = 0; |
| 3986 | |
| 3987 | /* for internal loopback recording select */ |
| 3988 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 3989 | imux->items[imux->num_items].index = 5; |
| 3990 | imux->num_items++; |
| 3991 | |
| 3992 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 3993 | if (!cfg->input_pins[i]) |
| 3994 | continue; |
| 3995 | |
| 3996 | switch (cfg->input_pins[i]) { |
| 3997 | case 0x1a: /* Mic */ |
| 3998 | idx = 2; |
| 3999 | break; |
| 4000 | |
| 4001 | case 0x1b: /* Line In */ |
| 4002 | idx = 3; |
| 4003 | break; |
| 4004 | |
| 4005 | case 0x1e: /* Front Mic */ |
| 4006 | idx = 4; |
| 4007 | break; |
| 4008 | |
| 4009 | case 0x1f: /* CD */ |
| 4010 | idx = 1; |
| 4011 | break; |
| 4012 | } |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 4013 | err = via_new_analog_input(spec, labels[i], idx, 0x16); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4014 | if (err < 0) |
| 4015 | return err; |
| 4016 | imux->items[imux->num_items].label = labels[i]; |
| 4017 | imux->items[imux->num_items].index = idx-1; |
| 4018 | imux->num_items++; |
| 4019 | } |
| 4020 | return 0; |
| 4021 | } |
| 4022 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4023 | /* fill out digital output widgets; one for master and one for slave outputs */ |
| 4024 | static void fill_dig_outs(struct hda_codec *codec) |
| 4025 | { |
| 4026 | struct via_spec *spec = codec->spec; |
| 4027 | int i; |
| 4028 | |
| 4029 | for (i = 0; i < spec->autocfg.dig_outs; i++) { |
| 4030 | hda_nid_t nid; |
| 4031 | int conn; |
| 4032 | |
| 4033 | nid = spec->autocfg.dig_out_pins[i]; |
| 4034 | if (!nid) |
| 4035 | continue; |
| 4036 | conn = snd_hda_get_connections(codec, nid, &nid, 1); |
| 4037 | if (conn < 1) |
| 4038 | continue; |
| 4039 | if (!spec->multiout.dig_out_nid) |
| 4040 | spec->multiout.dig_out_nid = nid; |
| 4041 | else { |
| 4042 | spec->slave_dig_outs[0] = nid; |
| 4043 | break; /* at most two dig outs */ |
| 4044 | } |
| 4045 | } |
| 4046 | } |
| 4047 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4048 | static int vt1708S_parse_auto_config(struct hda_codec *codec) |
| 4049 | { |
| 4050 | struct via_spec *spec = codec->spec; |
| 4051 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4052 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4053 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4054 | if (err < 0) |
| 4055 | return err; |
| 4056 | err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg); |
| 4057 | if (err < 0) |
| 4058 | return err; |
| 4059 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 4060 | return 0; /* can't find valid BIOS pin config */ |
| 4061 | |
| 4062 | err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 4063 | if (err < 0) |
| 4064 | return err; |
| 4065 | err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 4066 | if (err < 0) |
| 4067 | return err; |
| 4068 | err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 4069 | if (err < 0) |
| 4070 | return err; |
| 4071 | |
| 4072 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4073 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4074 | fill_dig_outs(codec); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 4075 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4076 | if (spec->kctls.list) |
| 4077 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4078 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4079 | spec->input_mux = &spec->private_imux[0]; |
| 4080 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 4081 | if (spec->hp_mux) |
| 4082 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4083 | |
Lydia Wang | 1564b28 | 2009-10-10 19:07:52 +0800 | [diff] [blame] | 4084 | spec->mixers[spec->num_mixers++] = via_smart51_mixer; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4085 | return 1; |
| 4086 | } |
| 4087 | |
| 4088 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4089 | static struct hda_amp_list vt1708S_loopbacks[] = { |
| 4090 | { 0x16, HDA_INPUT, 1 }, |
| 4091 | { 0x16, HDA_INPUT, 2 }, |
| 4092 | { 0x16, HDA_INPUT, 3 }, |
| 4093 | { 0x16, HDA_INPUT, 4 }, |
| 4094 | { } /* end */ |
| 4095 | }; |
| 4096 | #endif |
| 4097 | |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 4098 | static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin, |
| 4099 | int offset, int num_steps, int step_size) |
| 4100 | { |
| 4101 | snd_hda_override_amp_caps(codec, pin, HDA_INPUT, |
| 4102 | (offset << AC_AMPCAP_OFFSET_SHIFT) | |
| 4103 | (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 4104 | (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 4105 | (0 << AC_AMPCAP_MUTE_SHIFT)); |
| 4106 | } |
| 4107 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4108 | static int patch_vt1708S(struct hda_codec *codec) |
| 4109 | { |
| 4110 | struct via_spec *spec; |
| 4111 | int err; |
| 4112 | |
| 4113 | /* create a codec specific record */ |
| 4114 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4115 | if (spec == NULL) |
| 4116 | return -ENOMEM; |
| 4117 | |
| 4118 | codec->spec = spec; |
| 4119 | |
| 4120 | /* automatic parse from the BIOS config */ |
| 4121 | err = vt1708S_parse_auto_config(codec); |
| 4122 | if (err < 0) { |
| 4123 | via_free(codec); |
| 4124 | return err; |
| 4125 | } else if (!err) { |
| 4126 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4127 | "from BIOS. Using genenic mode...\n"); |
| 4128 | } |
| 4129 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 4130 | spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs; |
| 4131 | spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4132 | |
| 4133 | spec->stream_name_analog = "VT1708S Analog"; |
| 4134 | spec->stream_analog_playback = &vt1708S_pcm_analog_playback; |
| 4135 | spec->stream_analog_capture = &vt1708S_pcm_analog_capture; |
| 4136 | |
| 4137 | spec->stream_name_digital = "VT1708S Digital"; |
| 4138 | spec->stream_digital_playback = &vt1708S_pcm_digital_playback; |
| 4139 | |
| 4140 | if (!spec->adc_nids && spec->input_mux) { |
| 4141 | spec->adc_nids = vt1708S_adc_nids; |
| 4142 | spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids); |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 4143 | get_mux_nids(codec); |
Lydia Wang | 6369bcf | 2009-10-10 19:08:31 +0800 | [diff] [blame] | 4144 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 4145 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4146 | spec->mixers[spec->num_mixers] = vt1708S_capture_mixer; |
| 4147 | spec->num_mixers++; |
| 4148 | } |
| 4149 | |
| 4150 | codec->patch_ops = via_patch_ops; |
| 4151 | |
| 4152 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 4153 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4154 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4155 | spec->loopback.amplist = vt1708S_loopbacks; |
| 4156 | #endif |
| 4157 | |
Lydia Wang | 518bf3b | 2009-10-10 19:07:29 +0800 | [diff] [blame] | 4158 | /* correct names for VT1708BCE */ |
| 4159 | if (get_codec_type(codec) == VT1708BCE) { |
| 4160 | kfree(codec->chip_name); |
| 4161 | codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL); |
| 4162 | snprintf(codec->bus->card->mixername, |
| 4163 | sizeof(codec->bus->card->mixername), |
| 4164 | "%s %s", codec->vendor_name, codec->chip_name); |
| 4165 | spec->stream_name_analog = "VT1708BCE Analog"; |
| 4166 | spec->stream_name_digital = "VT1708BCE Digital"; |
| 4167 | } |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4168 | return 0; |
| 4169 | } |
| 4170 | |
| 4171 | /* Patch for VT1702 */ |
| 4172 | |
| 4173 | /* capture mixer elements */ |
| 4174 | static struct snd_kcontrol_new vt1702_capture_mixer[] = { |
| 4175 | HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT), |
| 4176 | HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT), |
| 4177 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT), |
| 4178 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT), |
| 4179 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT), |
| 4180 | HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT), |
| 4181 | HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0, |
| 4182 | HDA_INPUT), |
| 4183 | { |
| 4184 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4185 | /* The multiple "Capture Source" controls confuse alsamixer |
| 4186 | * So call somewhat different.. |
| 4187 | */ |
| 4188 | /* .name = "Capture Source", */ |
| 4189 | .name = "Input Source", |
| 4190 | .count = 1, |
| 4191 | .info = via_mux_enum_info, |
| 4192 | .get = via_mux_enum_get, |
| 4193 | .put = via_mux_enum_put, |
| 4194 | }, |
| 4195 | { } /* end */ |
| 4196 | }; |
| 4197 | |
| 4198 | static struct hda_verb vt1702_volume_init_verbs[] = { |
| 4199 | /* |
| 4200 | * Unmute ADC0-1 and set the default input to mic-in |
| 4201 | */ |
| 4202 | {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4203 | {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4204 | {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4205 | |
| 4206 | |
| 4207 | /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4208 | * mixer widget |
| 4209 | */ |
| 4210 | /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */ |
| 4211 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4212 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4213 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)}, |
| 4214 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, |
| 4215 | {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 4216 | |
| 4217 | /* Setup default input of PW4 to MW0 */ |
| 4218 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4219 | /* PW6 PW7 Output enable */ |
| 4220 | {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 4221 | {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
Lydia Wang | bc7e7e5 | 2009-10-10 19:08:32 +0800 | [diff] [blame] | 4222 | /* mixer enable */ |
| 4223 | {0x1, 0xF88, 0x3}, |
| 4224 | /* GPIO 0~2 */ |
| 4225 | {0x1, 0xF82, 0x3F}, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4226 | { } |
| 4227 | }; |
| 4228 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 4229 | static struct hda_verb vt1702_uniwill_init_verbs[] = { |
Lydia Wang | a34df19 | 2009-10-10 19:08:01 +0800 | [diff] [blame] | 4230 | {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4231 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 4232 | {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4233 | {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4234 | {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4235 | {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 4236 | { } |
| 4237 | }; |
| 4238 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4239 | static struct hda_pcm_stream vt1702_pcm_analog_playback = { |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4240 | .substreams = 2, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4241 | .channels_min = 2, |
| 4242 | .channels_max = 2, |
| 4243 | .nid = 0x10, /* NID to query formats and rates */ |
| 4244 | .ops = { |
| 4245 | .open = via_playback_pcm_open, |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4246 | .prepare = via_playback_multi_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 4247 | .cleanup = via_playback_multi_pcm_cleanup, |
| 4248 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4249 | }, |
| 4250 | }; |
| 4251 | |
| 4252 | static struct hda_pcm_stream vt1702_pcm_analog_capture = { |
| 4253 | .substreams = 3, |
| 4254 | .channels_min = 2, |
| 4255 | .channels_max = 2, |
| 4256 | .nid = 0x12, /* NID to query formats and rates */ |
| 4257 | .ops = { |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 4258 | .open = via_pcm_open_close, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4259 | .prepare = via_capture_pcm_prepare, |
Lydia Wang | 1731437 | 2009-10-10 19:07:37 +0800 | [diff] [blame] | 4260 | .cleanup = via_capture_pcm_cleanup, |
| 4261 | .close = via_pcm_open_close |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4262 | }, |
| 4263 | }; |
| 4264 | |
| 4265 | static struct hda_pcm_stream vt1702_pcm_digital_playback = { |
Harald Welte | 5691ec7 | 2008-09-15 22:42:26 +0800 | [diff] [blame] | 4266 | .substreams = 2, |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4267 | .channels_min = 2, |
| 4268 | .channels_max = 2, |
| 4269 | /* NID is set in via_build_pcms */ |
| 4270 | .ops = { |
| 4271 | .open = via_dig_playback_pcm_open, |
| 4272 | .close = via_dig_playback_pcm_close, |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4273 | .prepare = via_dig_playback_pcm_prepare, |
| 4274 | .cleanup = via_dig_playback_pcm_cleanup |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4275 | }, |
| 4276 | }; |
| 4277 | |
| 4278 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 4279 | static int vt1702_auto_fill_dac_nids(struct via_spec *spec, |
| 4280 | const struct auto_pin_cfg *cfg) |
| 4281 | { |
| 4282 | spec->multiout.num_dacs = 1; |
| 4283 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 4284 | |
| 4285 | if (cfg->line_out_pins[0]) { |
| 4286 | /* config dac list */ |
| 4287 | spec->multiout.dac_nids[0] = 0x10; |
| 4288 | } |
| 4289 | |
| 4290 | return 0; |
| 4291 | } |
| 4292 | |
| 4293 | /* add playback controls from the parsed DAC table */ |
| 4294 | static int vt1702_auto_create_line_out_ctls(struct via_spec *spec, |
| 4295 | const struct auto_pin_cfg *cfg) |
| 4296 | { |
| 4297 | int err; |
| 4298 | |
| 4299 | if (!cfg->line_out_pins[0]) |
| 4300 | return -1; |
| 4301 | |
| 4302 | /* add control to mixer index 0 */ |
| 4303 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4304 | "Master Front Playback Volume", |
| 4305 | HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); |
| 4306 | if (err < 0) |
| 4307 | return err; |
| 4308 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 4309 | "Master Front Playback Switch", |
| 4310 | HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT)); |
| 4311 | if (err < 0) |
| 4312 | return err; |
| 4313 | |
| 4314 | /* Front */ |
| 4315 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4316 | "Front Playback Volume", |
| 4317 | HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT)); |
| 4318 | if (err < 0) |
| 4319 | return err; |
| 4320 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 4321 | "Front Playback Switch", |
| 4322 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT)); |
| 4323 | if (err < 0) |
| 4324 | return err; |
| 4325 | |
| 4326 | return 0; |
| 4327 | } |
| 4328 | |
| 4329 | static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 4330 | { |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 4331 | int err, i; |
| 4332 | struct hda_input_mux *imux; |
| 4333 | static const char *texts[] = { "ON", "OFF", NULL}; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4334 | if (!pin) |
| 4335 | return 0; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4336 | spec->multiout.hp_nid = 0x1D; |
Lydia Wang | cdc1784 | 2009-10-10 19:07:47 +0800 | [diff] [blame] | 4337 | spec->hp_independent_mode_index = 0; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4338 | |
| 4339 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4340 | "Headphone Playback Volume", |
| 4341 | HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT)); |
| 4342 | if (err < 0) |
| 4343 | return err; |
| 4344 | |
| 4345 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 4346 | "Headphone Playback Switch", |
| 4347 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 4348 | if (err < 0) |
| 4349 | return err; |
| 4350 | |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 4351 | imux = &spec->private_imux[1]; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4352 | |
Lydia Wang | 0713efe | 2009-10-10 19:07:43 +0800 | [diff] [blame] | 4353 | /* for hp mode select */ |
| 4354 | i = 0; |
| 4355 | while (texts[i] != NULL) { |
| 4356 | imux->items[imux->num_items].label = texts[i]; |
| 4357 | imux->items[imux->num_items].index = i; |
| 4358 | imux->num_items++; |
| 4359 | i++; |
| 4360 | } |
| 4361 | |
| 4362 | spec->hp_mux = &spec->private_imux[1]; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4363 | return 0; |
| 4364 | } |
| 4365 | |
| 4366 | /* create playback/capture controls for input pins */ |
| 4367 | static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec, |
| 4368 | const struct auto_pin_cfg *cfg) |
| 4369 | { |
| 4370 | static char *labels[] = { |
| 4371 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 4372 | }; |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4373 | struct hda_input_mux *imux = &spec->private_imux[0]; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4374 | int i, err, idx = 0; |
| 4375 | |
| 4376 | /* for internal loopback recording select */ |
| 4377 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 4378 | imux->items[imux->num_items].index = 3; |
| 4379 | imux->num_items++; |
| 4380 | |
| 4381 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 4382 | if (!cfg->input_pins[i]) |
| 4383 | continue; |
| 4384 | |
| 4385 | switch (cfg->input_pins[i]) { |
| 4386 | case 0x14: /* Mic */ |
| 4387 | idx = 1; |
| 4388 | break; |
| 4389 | |
| 4390 | case 0x15: /* Line In */ |
| 4391 | idx = 2; |
| 4392 | break; |
| 4393 | |
| 4394 | case 0x18: /* Front Mic */ |
| 4395 | idx = 3; |
| 4396 | break; |
| 4397 | } |
Lydia Wang | 9510e8d | 2009-10-10 19:07:39 +0800 | [diff] [blame] | 4398 | err = via_new_analog_input(spec, labels[i], idx, 0x1A); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4399 | if (err < 0) |
| 4400 | return err; |
| 4401 | imux->items[imux->num_items].label = labels[i]; |
| 4402 | imux->items[imux->num_items].index = idx-1; |
| 4403 | imux->num_items++; |
| 4404 | } |
| 4405 | return 0; |
| 4406 | } |
| 4407 | |
| 4408 | static int vt1702_parse_auto_config(struct hda_codec *codec) |
| 4409 | { |
| 4410 | struct via_spec *spec = codec->spec; |
| 4411 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4412 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4413 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4414 | if (err < 0) |
| 4415 | return err; |
| 4416 | err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg); |
| 4417 | if (err < 0) |
| 4418 | return err; |
| 4419 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 4420 | return 0; /* can't find valid BIOS pin config */ |
| 4421 | |
| 4422 | err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg); |
| 4423 | if (err < 0) |
| 4424 | return err; |
| 4425 | err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 4426 | if (err < 0) |
| 4427 | return err; |
Lydia Wang | c2c02ea | 2009-10-10 19:07:32 +0800 | [diff] [blame] | 4428 | /* limit AA path volume to 0 dB */ |
| 4429 | snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT, |
| 4430 | (0x17 << AC_AMPCAP_OFFSET_SHIFT) | |
| 4431 | (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) | |
| 4432 | (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) | |
| 4433 | (1 << AC_AMPCAP_MUTE_SHIFT)); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4434 | err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 4435 | if (err < 0) |
| 4436 | return err; |
| 4437 | |
| 4438 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4439 | |
Takashi Iwai | 9da2927 | 2009-05-07 16:31:14 +0200 | [diff] [blame] | 4440 | fill_dig_outs(codec); |
Harald Welte | 98aa34c | 2008-09-09 16:02:09 +0800 | [diff] [blame] | 4441 | |
Takashi Iwai | 603c401 | 2008-07-30 15:01:44 +0200 | [diff] [blame] | 4442 | if (spec->kctls.list) |
| 4443 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4444 | |
Harald Welte | 0aa62ae | 2008-09-09 15:58:27 +0800 | [diff] [blame] | 4445 | spec->input_mux = &spec->private_imux[0]; |
| 4446 | |
Harald Welte | f8fdd49 | 2008-09-15 22:41:31 +0800 | [diff] [blame] | 4447 | if (spec->hp_mux) |
| 4448 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4449 | |
| 4450 | return 1; |
| 4451 | } |
| 4452 | |
| 4453 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4454 | static struct hda_amp_list vt1702_loopbacks[] = { |
| 4455 | { 0x1A, HDA_INPUT, 1 }, |
| 4456 | { 0x1A, HDA_INPUT, 2 }, |
| 4457 | { 0x1A, HDA_INPUT, 3 }, |
| 4458 | { 0x1A, HDA_INPUT, 4 }, |
| 4459 | { } /* end */ |
| 4460 | }; |
| 4461 | #endif |
| 4462 | |
| 4463 | static int patch_vt1702(struct hda_codec *codec) |
| 4464 | { |
| 4465 | struct via_spec *spec; |
| 4466 | int err; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4467 | |
| 4468 | /* create a codec specific record */ |
| 4469 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4470 | if (spec == NULL) |
| 4471 | return -ENOMEM; |
| 4472 | |
| 4473 | codec->spec = spec; |
| 4474 | |
| 4475 | /* automatic parse from the BIOS config */ |
| 4476 | err = vt1702_parse_auto_config(codec); |
| 4477 | if (err < 0) { |
| 4478 | via_free(codec); |
| 4479 | return err; |
| 4480 | } else if (!err) { |
| 4481 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4482 | "from BIOS. Using genenic mode...\n"); |
| 4483 | } |
| 4484 | |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 4485 | spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs; |
| 4486 | spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4487 | |
| 4488 | spec->stream_name_analog = "VT1702 Analog"; |
| 4489 | spec->stream_analog_playback = &vt1702_pcm_analog_playback; |
| 4490 | spec->stream_analog_capture = &vt1702_pcm_analog_capture; |
| 4491 | |
| 4492 | spec->stream_name_digital = "VT1702 Digital"; |
| 4493 | spec->stream_digital_playback = &vt1702_pcm_digital_playback; |
| 4494 | |
| 4495 | if (!spec->adc_nids && spec->input_mux) { |
| 4496 | spec->adc_nids = vt1702_adc_nids; |
| 4497 | spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids); |
Takashi Iwai | 337b9d0 | 2009-07-07 18:18:59 +0200 | [diff] [blame] | 4498 | get_mux_nids(codec); |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4499 | spec->mixers[spec->num_mixers] = vt1702_capture_mixer; |
| 4500 | spec->num_mixers++; |
| 4501 | } |
| 4502 | |
| 4503 | codec->patch_ops = via_patch_ops; |
| 4504 | |
| 4505 | codec->patch_ops.init = via_auto_init; |
Harald Welte | 69e52a8 | 2008-09-09 15:57:32 +0800 | [diff] [blame] | 4506 | codec->patch_ops.unsol_event = via_unsol_event; |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4507 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4508 | spec->loopback.amplist = vt1702_loopbacks; |
| 4509 | #endif |
| 4510 | |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 4511 | return 0; |
| 4512 | } |
| 4513 | |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4514 | /* Patch for VT1718S */ |
| 4515 | |
| 4516 | /* capture mixer elements */ |
| 4517 | static struct snd_kcontrol_new vt1718S_capture_mixer[] = { |
| 4518 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 4519 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 4520 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 4521 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 4522 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 4523 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 4524 | HDA_INPUT), |
| 4525 | { |
| 4526 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4527 | /* The multiple "Capture Source" controls confuse alsamixer |
| 4528 | * So call somewhat different.. |
| 4529 | */ |
| 4530 | .name = "Input Source", |
| 4531 | .count = 2, |
| 4532 | .info = via_mux_enum_info, |
| 4533 | .get = via_mux_enum_get, |
| 4534 | .put = via_mux_enum_put, |
| 4535 | }, |
| 4536 | { } /* end */ |
| 4537 | }; |
| 4538 | |
| 4539 | static struct hda_verb vt1718S_volume_init_verbs[] = { |
| 4540 | /* |
| 4541 | * Unmute ADC0-1 and set the default input to mic-in |
| 4542 | */ |
| 4543 | {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4544 | {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4545 | |
| 4546 | |
| 4547 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 4548 | * mixer widget |
| 4549 | */ |
| 4550 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 4551 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 4552 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4553 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 4554 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 4555 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, |
| 4556 | |
| 4557 | /* Setup default input of Front HP to MW9 */ |
| 4558 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4559 | /* PW9 PW10 Output enable */ |
| 4560 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4561 | {0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 4562 | /* PW11 Input enable */ |
| 4563 | {0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN}, |
| 4564 | /* Enable Boost Volume backdoor */ |
| 4565 | {0x1, 0xf88, 0x8}, |
| 4566 | /* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */ |
| 4567 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4568 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4569 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4570 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4571 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4572 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4573 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4574 | {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4575 | {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 4576 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 4577 | /* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */ |
| 4578 | {0x34, AC_VERB_SET_CONNECT_SEL, 0x2}, |
| 4579 | {0x35, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 4580 | /* Unmute MW4's index 0 */ |
| 4581 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 4582 | { } |
| 4583 | }; |
| 4584 | |
| 4585 | |
| 4586 | static struct hda_verb vt1718S_uniwill_init_verbs[] = { |
| 4587 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 4588 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 4589 | {0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4590 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4591 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4592 | {0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4593 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4594 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4595 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 4596 | { } |
| 4597 | }; |
| 4598 | |
| 4599 | static struct hda_pcm_stream vt1718S_pcm_analog_playback = { |
| 4600 | .substreams = 2, |
| 4601 | .channels_min = 2, |
| 4602 | .channels_max = 10, |
| 4603 | .nid = 0x8, /* NID to query formats and rates */ |
| 4604 | .ops = { |
| 4605 | .open = via_playback_pcm_open, |
| 4606 | .prepare = via_playback_multi_pcm_prepare, |
| 4607 | .cleanup = via_playback_multi_pcm_cleanup, |
| 4608 | .close = via_pcm_open_close, |
| 4609 | }, |
| 4610 | }; |
| 4611 | |
| 4612 | static struct hda_pcm_stream vt1718S_pcm_analog_capture = { |
| 4613 | .substreams = 2, |
| 4614 | .channels_min = 2, |
| 4615 | .channels_max = 2, |
| 4616 | .nid = 0x10, /* NID to query formats and rates */ |
| 4617 | .ops = { |
| 4618 | .open = via_pcm_open_close, |
| 4619 | .prepare = via_capture_pcm_prepare, |
| 4620 | .cleanup = via_capture_pcm_cleanup, |
| 4621 | .close = via_pcm_open_close, |
| 4622 | }, |
| 4623 | }; |
| 4624 | |
| 4625 | static struct hda_pcm_stream vt1718S_pcm_digital_playback = { |
| 4626 | .substreams = 2, |
| 4627 | .channels_min = 2, |
| 4628 | .channels_max = 2, |
| 4629 | .rates = SNDRV_PCM_RATE_48000, |
| 4630 | /* NID is set in via_build_pcms */ |
| 4631 | .ops = { |
| 4632 | .open = via_dig_playback_pcm_open, |
| 4633 | .close = via_dig_playback_pcm_close, |
| 4634 | .prepare = via_dig_playback_pcm_prepare, |
| 4635 | .cleanup = via_dig_playback_pcm_cleanup |
| 4636 | }, |
| 4637 | }; |
| 4638 | |
| 4639 | static struct hda_pcm_stream vt1718S_pcm_digital_capture = { |
| 4640 | .substreams = 1, |
| 4641 | .channels_min = 2, |
| 4642 | .channels_max = 2, |
| 4643 | }; |
| 4644 | |
| 4645 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 4646 | static int vt1718S_auto_fill_dac_nids(struct via_spec *spec, |
| 4647 | const struct auto_pin_cfg *cfg) |
| 4648 | { |
| 4649 | int i; |
| 4650 | hda_nid_t nid; |
| 4651 | |
| 4652 | spec->multiout.num_dacs = cfg->line_outs; |
| 4653 | |
| 4654 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 4655 | |
| 4656 | for (i = 0; i < 4; i++) { |
| 4657 | nid = cfg->line_out_pins[i]; |
| 4658 | if (nid) { |
| 4659 | /* config dac list */ |
| 4660 | switch (i) { |
| 4661 | case AUTO_SEQ_FRONT: |
| 4662 | spec->multiout.dac_nids[i] = 0x8; |
| 4663 | break; |
| 4664 | case AUTO_SEQ_CENLFE: |
| 4665 | spec->multiout.dac_nids[i] = 0xa; |
| 4666 | break; |
| 4667 | case AUTO_SEQ_SURROUND: |
| 4668 | spec->multiout.dac_nids[i] = 0x9; |
| 4669 | break; |
| 4670 | case AUTO_SEQ_SIDE: |
| 4671 | spec->multiout.dac_nids[i] = 0xb; |
| 4672 | break; |
| 4673 | } |
| 4674 | } |
| 4675 | } |
| 4676 | |
| 4677 | return 0; |
| 4678 | } |
| 4679 | |
| 4680 | /* add playback controls from the parsed DAC table */ |
| 4681 | static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec, |
| 4682 | const struct auto_pin_cfg *cfg) |
| 4683 | { |
| 4684 | char name[32]; |
| 4685 | static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" }; |
| 4686 | hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb}; |
| 4687 | hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27}; |
| 4688 | hda_nid_t nid, nid_vol, nid_mute = 0; |
| 4689 | int i, err; |
| 4690 | |
| 4691 | for (i = 0; i <= AUTO_SEQ_SIDE; i++) { |
| 4692 | nid = cfg->line_out_pins[i]; |
| 4693 | |
| 4694 | if (!nid) |
| 4695 | continue; |
| 4696 | nid_vol = nid_vols[i]; |
| 4697 | nid_mute = nid_mutes[i]; |
| 4698 | |
| 4699 | if (i == AUTO_SEQ_CENLFE) { |
| 4700 | /* Center/LFE */ |
| 4701 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4702 | "Center Playback Volume", |
| 4703 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, |
| 4704 | HDA_OUTPUT)); |
| 4705 | if (err < 0) |
| 4706 | return err; |
| 4707 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4708 | "LFE Playback Volume", |
| 4709 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, |
| 4710 | HDA_OUTPUT)); |
| 4711 | if (err < 0) |
| 4712 | return err; |
| 4713 | err = via_add_control( |
| 4714 | spec, VIA_CTL_WIDGET_MUTE, |
| 4715 | "Center Playback Switch", |
| 4716 | HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, |
| 4717 | HDA_OUTPUT)); |
| 4718 | if (err < 0) |
| 4719 | return err; |
| 4720 | err = via_add_control( |
| 4721 | spec, VIA_CTL_WIDGET_MUTE, |
| 4722 | "LFE Playback Switch", |
| 4723 | HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, |
| 4724 | HDA_OUTPUT)); |
| 4725 | if (err < 0) |
| 4726 | return err; |
| 4727 | } else if (i == AUTO_SEQ_FRONT) { |
| 4728 | /* Front */ |
| 4729 | sprintf(name, "%s Playback Volume", chname[i]); |
| 4730 | err = via_add_control( |
| 4731 | spec, VIA_CTL_WIDGET_VOL, name, |
| 4732 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); |
| 4733 | if (err < 0) |
| 4734 | return err; |
| 4735 | sprintf(name, "%s Playback Switch", chname[i]); |
| 4736 | err = via_add_control( |
| 4737 | spec, VIA_CTL_WIDGET_MUTE, name, |
| 4738 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, |
| 4739 | HDA_OUTPUT)); |
| 4740 | if (err < 0) |
| 4741 | return err; |
| 4742 | } else { |
| 4743 | sprintf(name, "%s Playback Volume", chname[i]); |
| 4744 | err = via_add_control( |
| 4745 | spec, VIA_CTL_WIDGET_VOL, name, |
| 4746 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); |
| 4747 | if (err < 0) |
| 4748 | return err; |
| 4749 | sprintf(name, "%s Playback Switch", chname[i]); |
| 4750 | err = via_add_control( |
| 4751 | spec, VIA_CTL_WIDGET_MUTE, name, |
| 4752 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, |
| 4753 | HDA_OUTPUT)); |
| 4754 | if (err < 0) |
| 4755 | return err; |
| 4756 | } |
| 4757 | } |
| 4758 | return 0; |
| 4759 | } |
| 4760 | |
| 4761 | static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 4762 | { |
| 4763 | int err; |
| 4764 | |
| 4765 | if (!pin) |
| 4766 | return 0; |
| 4767 | |
| 4768 | spec->multiout.hp_nid = 0xc; /* AOW4 */ |
| 4769 | spec->hp_independent_mode_index = 1; |
| 4770 | |
| 4771 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 4772 | "Headphone Playback Volume", |
| 4773 | HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT)); |
| 4774 | if (err < 0) |
| 4775 | return err; |
| 4776 | |
| 4777 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 4778 | "Headphone Playback Switch", |
| 4779 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 4780 | if (err < 0) |
| 4781 | return err; |
| 4782 | |
| 4783 | create_hp_imux(spec); |
| 4784 | return 0; |
| 4785 | } |
| 4786 | |
| 4787 | /* create playback/capture controls for input pins */ |
| 4788 | static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec, |
| 4789 | const struct auto_pin_cfg *cfg) |
| 4790 | { |
| 4791 | static char *labels[] = { |
| 4792 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 4793 | }; |
| 4794 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 4795 | int i, err, idx = 0; |
| 4796 | |
| 4797 | /* for internal loopback recording select */ |
| 4798 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 4799 | imux->items[imux->num_items].index = 5; |
| 4800 | imux->num_items++; |
| 4801 | |
| 4802 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 4803 | if (!cfg->input_pins[i]) |
| 4804 | continue; |
| 4805 | |
| 4806 | switch (cfg->input_pins[i]) { |
| 4807 | case 0x2b: /* Mic */ |
| 4808 | idx = 1; |
| 4809 | break; |
| 4810 | |
| 4811 | case 0x2a: /* Line In */ |
| 4812 | idx = 2; |
| 4813 | break; |
| 4814 | |
| 4815 | case 0x29: /* Front Mic */ |
| 4816 | idx = 3; |
| 4817 | break; |
| 4818 | |
| 4819 | case 0x2c: /* CD */ |
| 4820 | idx = 0; |
| 4821 | break; |
| 4822 | } |
| 4823 | err = via_new_analog_input(spec, labels[i], idx, 0x21); |
| 4824 | if (err < 0) |
| 4825 | return err; |
| 4826 | imux->items[imux->num_items].label = labels[i]; |
| 4827 | imux->items[imux->num_items].index = idx; |
| 4828 | imux->num_items++; |
| 4829 | } |
| 4830 | return 0; |
| 4831 | } |
| 4832 | |
| 4833 | static int vt1718S_parse_auto_config(struct hda_codec *codec) |
| 4834 | { |
| 4835 | struct via_spec *spec = codec->spec; |
| 4836 | int err; |
| 4837 | |
| 4838 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 4839 | |
| 4840 | if (err < 0) |
| 4841 | return err; |
| 4842 | err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg); |
| 4843 | if (err < 0) |
| 4844 | return err; |
| 4845 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 4846 | return 0; /* can't find valid BIOS pin config */ |
| 4847 | |
| 4848 | err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 4849 | if (err < 0) |
| 4850 | return err; |
| 4851 | err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 4852 | if (err < 0) |
| 4853 | return err; |
| 4854 | err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 4855 | if (err < 0) |
| 4856 | return err; |
| 4857 | |
| 4858 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 4859 | |
| 4860 | fill_dig_outs(codec); |
| 4861 | |
| 4862 | if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428) |
| 4863 | spec->dig_in_nid = 0x13; |
| 4864 | |
| 4865 | if (spec->kctls.list) |
| 4866 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 4867 | |
| 4868 | spec->input_mux = &spec->private_imux[0]; |
| 4869 | |
| 4870 | if (spec->hp_mux) |
| 4871 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
| 4872 | |
| 4873 | spec->mixers[spec->num_mixers++] = via_smart51_mixer; |
| 4874 | |
| 4875 | return 1; |
| 4876 | } |
| 4877 | |
| 4878 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4879 | static struct hda_amp_list vt1718S_loopbacks[] = { |
| 4880 | { 0x21, HDA_INPUT, 1 }, |
| 4881 | { 0x21, HDA_INPUT, 2 }, |
| 4882 | { 0x21, HDA_INPUT, 3 }, |
| 4883 | { 0x21, HDA_INPUT, 4 }, |
| 4884 | { } /* end */ |
| 4885 | }; |
| 4886 | #endif |
| 4887 | |
| 4888 | static int patch_vt1718S(struct hda_codec *codec) |
| 4889 | { |
| 4890 | struct via_spec *spec; |
| 4891 | int err; |
| 4892 | |
| 4893 | /* create a codec specific record */ |
| 4894 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 4895 | if (spec == NULL) |
| 4896 | return -ENOMEM; |
| 4897 | |
| 4898 | codec->spec = spec; |
| 4899 | |
| 4900 | /* automatic parse from the BIOS config */ |
| 4901 | err = vt1718S_parse_auto_config(codec); |
| 4902 | if (err < 0) { |
| 4903 | via_free(codec); |
| 4904 | return err; |
| 4905 | } else if (!err) { |
| 4906 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 4907 | "from BIOS. Using genenic mode...\n"); |
| 4908 | } |
| 4909 | |
| 4910 | spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs; |
| 4911 | spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs; |
| 4912 | |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4913 | if (codec->vendor_id == 0x11060441) |
| 4914 | spec->stream_name_analog = "VT2020 Analog"; |
| 4915 | else if (codec->vendor_id == 0x11064441) |
| 4916 | spec->stream_name_analog = "VT1828S Analog"; |
| 4917 | else |
| 4918 | spec->stream_name_analog = "VT1718S Analog"; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4919 | spec->stream_analog_playback = &vt1718S_pcm_analog_playback; |
| 4920 | spec->stream_analog_capture = &vt1718S_pcm_analog_capture; |
| 4921 | |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4922 | if (codec->vendor_id == 0x11060441) |
| 4923 | spec->stream_name_digital = "VT2020 Digital"; |
| 4924 | else if (codec->vendor_id == 0x11064441) |
| 4925 | spec->stream_name_digital = "VT1828S Digital"; |
| 4926 | else |
| 4927 | spec->stream_name_digital = "VT1718S Digital"; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4928 | spec->stream_digital_playback = &vt1718S_pcm_digital_playback; |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4929 | if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441) |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4930 | spec->stream_digital_capture = &vt1718S_pcm_digital_capture; |
| 4931 | |
| 4932 | if (!spec->adc_nids && spec->input_mux) { |
| 4933 | spec->adc_nids = vt1718S_adc_nids; |
| 4934 | spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids); |
| 4935 | get_mux_nids(codec); |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 4936 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 4937 | override_mic_boost(codec, 0x29, 0, 3, 40); |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4938 | spec->mixers[spec->num_mixers] = vt1718S_capture_mixer; |
| 4939 | spec->num_mixers++; |
| 4940 | } |
| 4941 | |
| 4942 | codec->patch_ops = via_patch_ops; |
| 4943 | |
| 4944 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame^] | 4945 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 4946 | |
| 4947 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 4948 | spec->loopback.amplist = vt1718S_loopbacks; |
| 4949 | #endif |
| 4950 | |
| 4951 | return 0; |
| 4952 | } |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 4953 | |
| 4954 | /* Patch for VT1716S */ |
| 4955 | |
| 4956 | static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol, |
| 4957 | struct snd_ctl_elem_info *uinfo) |
| 4958 | { |
| 4959 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 4960 | uinfo->count = 1; |
| 4961 | uinfo->value.integer.min = 0; |
| 4962 | uinfo->value.integer.max = 1; |
| 4963 | return 0; |
| 4964 | } |
| 4965 | |
| 4966 | static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol, |
| 4967 | struct snd_ctl_elem_value *ucontrol) |
| 4968 | { |
| 4969 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 4970 | int index = 0; |
| 4971 | |
| 4972 | index = snd_hda_codec_read(codec, 0x26, 0, |
| 4973 | AC_VERB_GET_CONNECT_SEL, 0); |
| 4974 | if (index != -1) |
| 4975 | *ucontrol->value.integer.value = index; |
| 4976 | |
| 4977 | return 0; |
| 4978 | } |
| 4979 | |
| 4980 | static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol, |
| 4981 | struct snd_ctl_elem_value *ucontrol) |
| 4982 | { |
| 4983 | struct hda_codec *codec = snd_kcontrol_chip(kcontrol); |
| 4984 | struct via_spec *spec = codec->spec; |
| 4985 | int index = *ucontrol->value.integer.value; |
| 4986 | |
| 4987 | snd_hda_codec_write(codec, 0x26, 0, |
| 4988 | AC_VERB_SET_CONNECT_SEL, index); |
| 4989 | spec->dmic_enabled = index; |
| 4990 | set_jack_power_state(codec); |
| 4991 | |
| 4992 | return 1; |
| 4993 | } |
| 4994 | |
| 4995 | /* capture mixer elements */ |
| 4996 | static struct snd_kcontrol_new vt1716S_capture_mixer[] = { |
| 4997 | HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT), |
| 4998 | HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT), |
| 4999 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT), |
| 5000 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT), |
| 5001 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT), |
| 5002 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0, |
| 5003 | HDA_INPUT), |
| 5004 | { |
| 5005 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 5006 | .name = "Input Source", |
| 5007 | .count = 1, |
| 5008 | .info = via_mux_enum_info, |
| 5009 | .get = via_mux_enum_get, |
| 5010 | .put = via_mux_enum_put, |
| 5011 | }, |
| 5012 | { } /* end */ |
| 5013 | }; |
| 5014 | |
| 5015 | static struct snd_kcontrol_new vt1716s_dmic_mixer[] = { |
| 5016 | HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT), |
| 5017 | { |
| 5018 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 5019 | .name = "Digital Mic Capture Switch", |
| 5020 | .count = 1, |
| 5021 | .info = vt1716s_dmic_info, |
| 5022 | .get = vt1716s_dmic_get, |
| 5023 | .put = vt1716s_dmic_put, |
| 5024 | }, |
| 5025 | {} /* end */ |
| 5026 | }; |
| 5027 | |
| 5028 | |
| 5029 | /* mono-out mixer elements */ |
| 5030 | static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = { |
| 5031 | HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT), |
| 5032 | { } /* end */ |
| 5033 | }; |
| 5034 | |
| 5035 | static struct hda_verb vt1716S_volume_init_verbs[] = { |
| 5036 | /* |
| 5037 | * Unmute ADC0-1 and set the default input to mic-in |
| 5038 | */ |
| 5039 | {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5040 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5041 | |
| 5042 | |
| 5043 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 5044 | * mixer widget |
| 5045 | */ |
| 5046 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 5047 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 5048 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5049 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 5050 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 5051 | {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 5052 | |
| 5053 | /* MUX Indices: Stereo Mixer = 5 */ |
| 5054 | {0x17, AC_VERB_SET_CONNECT_SEL, 0x5}, |
| 5055 | |
| 5056 | /* Setup default input of PW4 to MW0 */ |
| 5057 | {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0}, |
| 5058 | |
| 5059 | /* Setup default input of SW1 as MW0 */ |
| 5060 | {0x18, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 5061 | |
| 5062 | /* Setup default input of SW4 as AOW0 */ |
| 5063 | {0x28, AC_VERB_SET_CONNECT_SEL, 0x1}, |
| 5064 | |
| 5065 | /* PW9 PW10 Output enable */ |
| 5066 | {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 5067 | {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 5068 | |
| 5069 | /* Unmute SW1, PW12 */ |
| 5070 | {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5071 | {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, |
| 5072 | /* PW12 Output enable */ |
| 5073 | {0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, |
| 5074 | /* Enable Boost Volume backdoor */ |
| 5075 | {0x1, 0xf8a, 0x80}, |
| 5076 | /* don't bybass mixer */ |
| 5077 | {0x1, 0xf88, 0xc0}, |
| 5078 | /* Enable mono output */ |
| 5079 | {0x1, 0xf90, 0x08}, |
| 5080 | { } |
| 5081 | }; |
| 5082 | |
| 5083 | |
| 5084 | static struct hda_verb vt1716S_uniwill_init_verbs[] = { |
| 5085 | {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5086 | AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT}, |
| 5087 | {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5088 | {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5089 | {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5090 | {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5091 | AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT}, |
| 5092 | {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5093 | {0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5094 | { } |
| 5095 | }; |
| 5096 | |
| 5097 | static struct hda_pcm_stream vt1716S_pcm_analog_playback = { |
| 5098 | .substreams = 2, |
| 5099 | .channels_min = 2, |
| 5100 | .channels_max = 6, |
| 5101 | .nid = 0x10, /* NID to query formats and rates */ |
| 5102 | .ops = { |
| 5103 | .open = via_playback_pcm_open, |
| 5104 | .prepare = via_playback_multi_pcm_prepare, |
| 5105 | .cleanup = via_playback_multi_pcm_cleanup, |
| 5106 | .close = via_pcm_open_close, |
| 5107 | }, |
| 5108 | }; |
| 5109 | |
| 5110 | static struct hda_pcm_stream vt1716S_pcm_analog_capture = { |
| 5111 | .substreams = 2, |
| 5112 | .channels_min = 2, |
| 5113 | .channels_max = 2, |
| 5114 | .nid = 0x13, /* NID to query formats and rates */ |
| 5115 | .ops = { |
| 5116 | .open = via_pcm_open_close, |
| 5117 | .prepare = via_capture_pcm_prepare, |
| 5118 | .cleanup = via_capture_pcm_cleanup, |
| 5119 | .close = via_pcm_open_close, |
| 5120 | }, |
| 5121 | }; |
| 5122 | |
| 5123 | static struct hda_pcm_stream vt1716S_pcm_digital_playback = { |
| 5124 | .substreams = 2, |
| 5125 | .channels_min = 2, |
| 5126 | .channels_max = 2, |
| 5127 | .rates = SNDRV_PCM_RATE_48000, |
| 5128 | /* NID is set in via_build_pcms */ |
| 5129 | .ops = { |
| 5130 | .open = via_dig_playback_pcm_open, |
| 5131 | .close = via_dig_playback_pcm_close, |
| 5132 | .prepare = via_dig_playback_pcm_prepare, |
| 5133 | .cleanup = via_dig_playback_pcm_cleanup |
| 5134 | }, |
| 5135 | }; |
| 5136 | |
| 5137 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 5138 | static int vt1716S_auto_fill_dac_nids(struct via_spec *spec, |
| 5139 | const struct auto_pin_cfg *cfg) |
| 5140 | { int i; |
| 5141 | hda_nid_t nid; |
| 5142 | |
| 5143 | spec->multiout.num_dacs = cfg->line_outs; |
| 5144 | |
| 5145 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 5146 | |
| 5147 | for (i = 0; i < 3; i++) { |
| 5148 | nid = cfg->line_out_pins[i]; |
| 5149 | if (nid) { |
| 5150 | /* config dac list */ |
| 5151 | switch (i) { |
| 5152 | case AUTO_SEQ_FRONT: |
| 5153 | spec->multiout.dac_nids[i] = 0x10; |
| 5154 | break; |
| 5155 | case AUTO_SEQ_CENLFE: |
| 5156 | spec->multiout.dac_nids[i] = 0x25; |
| 5157 | break; |
| 5158 | case AUTO_SEQ_SURROUND: |
| 5159 | spec->multiout.dac_nids[i] = 0x11; |
| 5160 | break; |
| 5161 | } |
| 5162 | } |
| 5163 | } |
| 5164 | |
| 5165 | return 0; |
| 5166 | } |
| 5167 | |
| 5168 | /* add playback controls from the parsed DAC table */ |
| 5169 | static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec, |
| 5170 | const struct auto_pin_cfg *cfg) |
| 5171 | { |
| 5172 | char name[32]; |
| 5173 | static const char *chname[3] = { "Front", "Surround", "C/LFE" }; |
| 5174 | hda_nid_t nid_vols[] = {0x10, 0x11, 0x25}; |
| 5175 | hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27}; |
| 5176 | hda_nid_t nid, nid_vol, nid_mute; |
| 5177 | int i, err; |
| 5178 | |
| 5179 | for (i = 0; i <= AUTO_SEQ_CENLFE; i++) { |
| 5180 | nid = cfg->line_out_pins[i]; |
| 5181 | |
| 5182 | if (!nid) |
| 5183 | continue; |
| 5184 | |
| 5185 | nid_vol = nid_vols[i]; |
| 5186 | nid_mute = nid_mutes[i]; |
| 5187 | |
| 5188 | if (i == AUTO_SEQ_CENLFE) { |
| 5189 | err = via_add_control( |
| 5190 | spec, VIA_CTL_WIDGET_VOL, |
| 5191 | "Center Playback Volume", |
| 5192 | HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT)); |
| 5193 | if (err < 0) |
| 5194 | return err; |
| 5195 | err = via_add_control( |
| 5196 | spec, VIA_CTL_WIDGET_VOL, |
| 5197 | "LFE Playback Volume", |
| 5198 | HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT)); |
| 5199 | if (err < 0) |
| 5200 | return err; |
| 5201 | err = via_add_control( |
| 5202 | spec, VIA_CTL_WIDGET_MUTE, |
| 5203 | "Center Playback Switch", |
| 5204 | HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0, |
| 5205 | HDA_OUTPUT)); |
| 5206 | if (err < 0) |
| 5207 | return err; |
| 5208 | err = via_add_control( |
| 5209 | spec, VIA_CTL_WIDGET_MUTE, |
| 5210 | "LFE Playback Switch", |
| 5211 | HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0, |
| 5212 | HDA_OUTPUT)); |
| 5213 | if (err < 0) |
| 5214 | return err; |
| 5215 | } else if (i == AUTO_SEQ_FRONT) { |
| 5216 | |
| 5217 | err = via_add_control( |
| 5218 | spec, VIA_CTL_WIDGET_VOL, |
| 5219 | "Master Front Playback Volume", |
| 5220 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); |
| 5221 | if (err < 0) |
| 5222 | return err; |
| 5223 | err = via_add_control( |
| 5224 | spec, VIA_CTL_WIDGET_MUTE, |
| 5225 | "Master Front Playback Switch", |
| 5226 | HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT)); |
| 5227 | if (err < 0) |
| 5228 | return err; |
| 5229 | |
| 5230 | sprintf(name, "%s Playback Volume", chname[i]); |
| 5231 | err = via_add_control( |
| 5232 | spec, VIA_CTL_WIDGET_VOL, name, |
| 5233 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); |
| 5234 | if (err < 0) |
| 5235 | return err; |
| 5236 | sprintf(name, "%s Playback Switch", chname[i]); |
| 5237 | err = via_add_control( |
| 5238 | spec, VIA_CTL_WIDGET_MUTE, name, |
| 5239 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, |
| 5240 | HDA_OUTPUT)); |
| 5241 | if (err < 0) |
| 5242 | return err; |
| 5243 | } else { |
| 5244 | sprintf(name, "%s Playback Volume", chname[i]); |
| 5245 | err = via_add_control( |
| 5246 | spec, VIA_CTL_WIDGET_VOL, name, |
| 5247 | HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT)); |
| 5248 | if (err < 0) |
| 5249 | return err; |
| 5250 | sprintf(name, "%s Playback Switch", chname[i]); |
| 5251 | err = via_add_control( |
| 5252 | spec, VIA_CTL_WIDGET_MUTE, name, |
| 5253 | HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0, |
| 5254 | HDA_OUTPUT)); |
| 5255 | if (err < 0) |
| 5256 | return err; |
| 5257 | } |
| 5258 | } |
| 5259 | return 0; |
| 5260 | } |
| 5261 | |
| 5262 | static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 5263 | { |
| 5264 | int err; |
| 5265 | |
| 5266 | if (!pin) |
| 5267 | return 0; |
| 5268 | |
| 5269 | spec->multiout.hp_nid = 0x25; /* AOW3 */ |
| 5270 | spec->hp_independent_mode_index = 1; |
| 5271 | |
| 5272 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5273 | "Headphone Playback Volume", |
| 5274 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); |
| 5275 | if (err < 0) |
| 5276 | return err; |
| 5277 | |
| 5278 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 5279 | "Headphone Playback Switch", |
| 5280 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 5281 | if (err < 0) |
| 5282 | return err; |
| 5283 | |
| 5284 | create_hp_imux(spec); |
| 5285 | return 0; |
| 5286 | } |
| 5287 | |
| 5288 | /* create playback/capture controls for input pins */ |
| 5289 | static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec, |
| 5290 | const struct auto_pin_cfg *cfg) |
| 5291 | { |
| 5292 | static char *labels[] = { |
| 5293 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 5294 | }; |
| 5295 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 5296 | int i, err, idx = 0; |
| 5297 | |
| 5298 | /* for internal loopback recording select */ |
| 5299 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 5300 | imux->items[imux->num_items].index = 5; |
| 5301 | imux->num_items++; |
| 5302 | |
| 5303 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 5304 | if (!cfg->input_pins[i]) |
| 5305 | continue; |
| 5306 | |
| 5307 | switch (cfg->input_pins[i]) { |
| 5308 | case 0x1a: /* Mic */ |
| 5309 | idx = 2; |
| 5310 | break; |
| 5311 | |
| 5312 | case 0x1b: /* Line In */ |
| 5313 | idx = 3; |
| 5314 | break; |
| 5315 | |
| 5316 | case 0x1e: /* Front Mic */ |
| 5317 | idx = 4; |
| 5318 | break; |
| 5319 | |
| 5320 | case 0x1f: /* CD */ |
| 5321 | idx = 1; |
| 5322 | break; |
| 5323 | } |
| 5324 | err = via_new_analog_input(spec, labels[i], idx, 0x16); |
| 5325 | if (err < 0) |
| 5326 | return err; |
| 5327 | imux->items[imux->num_items].label = labels[i]; |
| 5328 | imux->items[imux->num_items].index = idx-1; |
| 5329 | imux->num_items++; |
| 5330 | } |
| 5331 | return 0; |
| 5332 | } |
| 5333 | |
| 5334 | static int vt1716S_parse_auto_config(struct hda_codec *codec) |
| 5335 | { |
| 5336 | struct via_spec *spec = codec->spec; |
| 5337 | int err; |
| 5338 | |
| 5339 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 5340 | if (err < 0) |
| 5341 | return err; |
| 5342 | err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg); |
| 5343 | if (err < 0) |
| 5344 | return err; |
| 5345 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 5346 | return 0; /* can't find valid BIOS pin config */ |
| 5347 | |
| 5348 | err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 5349 | if (err < 0) |
| 5350 | return err; |
| 5351 | err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 5352 | if (err < 0) |
| 5353 | return err; |
| 5354 | err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 5355 | if (err < 0) |
| 5356 | return err; |
| 5357 | |
| 5358 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 5359 | |
| 5360 | fill_dig_outs(codec); |
| 5361 | |
| 5362 | if (spec->kctls.list) |
| 5363 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 5364 | |
| 5365 | spec->input_mux = &spec->private_imux[0]; |
| 5366 | |
| 5367 | if (spec->hp_mux) |
| 5368 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
| 5369 | |
| 5370 | spec->mixers[spec->num_mixers++] = via_smart51_mixer; |
| 5371 | |
| 5372 | return 1; |
| 5373 | } |
| 5374 | |
| 5375 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5376 | static struct hda_amp_list vt1716S_loopbacks[] = { |
| 5377 | { 0x16, HDA_INPUT, 1 }, |
| 5378 | { 0x16, HDA_INPUT, 2 }, |
| 5379 | { 0x16, HDA_INPUT, 3 }, |
| 5380 | { 0x16, HDA_INPUT, 4 }, |
| 5381 | { } /* end */ |
| 5382 | }; |
| 5383 | #endif |
| 5384 | |
| 5385 | static int patch_vt1716S(struct hda_codec *codec) |
| 5386 | { |
| 5387 | struct via_spec *spec; |
| 5388 | int err; |
| 5389 | |
| 5390 | /* create a codec specific record */ |
| 5391 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5392 | if (spec == NULL) |
| 5393 | return -ENOMEM; |
| 5394 | |
| 5395 | codec->spec = spec; |
| 5396 | |
| 5397 | /* automatic parse from the BIOS config */ |
| 5398 | err = vt1716S_parse_auto_config(codec); |
| 5399 | if (err < 0) { |
| 5400 | via_free(codec); |
| 5401 | return err; |
| 5402 | } else if (!err) { |
| 5403 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 5404 | "from BIOS. Using genenic mode...\n"); |
| 5405 | } |
| 5406 | |
| 5407 | spec->init_verbs[spec->num_iverbs++] = vt1716S_volume_init_verbs; |
| 5408 | spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs; |
| 5409 | |
| 5410 | spec->stream_name_analog = "VT1716S Analog"; |
| 5411 | spec->stream_analog_playback = &vt1716S_pcm_analog_playback; |
| 5412 | spec->stream_analog_capture = &vt1716S_pcm_analog_capture; |
| 5413 | |
| 5414 | spec->stream_name_digital = "VT1716S Digital"; |
| 5415 | spec->stream_digital_playback = &vt1716S_pcm_digital_playback; |
| 5416 | |
| 5417 | if (!spec->adc_nids && spec->input_mux) { |
| 5418 | spec->adc_nids = vt1716S_adc_nids; |
| 5419 | spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids); |
| 5420 | get_mux_nids(codec); |
| 5421 | override_mic_boost(codec, 0x1a, 0, 3, 40); |
| 5422 | override_mic_boost(codec, 0x1e, 0, 3, 40); |
| 5423 | spec->mixers[spec->num_mixers] = vt1716S_capture_mixer; |
| 5424 | spec->num_mixers++; |
| 5425 | } |
| 5426 | |
| 5427 | spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer; |
| 5428 | spec->num_mixers++; |
| 5429 | |
| 5430 | spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer; |
| 5431 | |
| 5432 | codec->patch_ops = via_patch_ops; |
| 5433 | |
| 5434 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame^] | 5435 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 5436 | |
| 5437 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5438 | spec->loopback.amplist = vt1716S_loopbacks; |
| 5439 | #endif |
| 5440 | |
| 5441 | return 0; |
| 5442 | } |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5443 | |
| 5444 | /* for vt2002P */ |
| 5445 | |
| 5446 | /* capture mixer elements */ |
| 5447 | static struct snd_kcontrol_new vt2002P_capture_mixer[] = { |
| 5448 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 5449 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 5450 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 5451 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 5452 | HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 5453 | HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 5454 | HDA_INPUT), |
| 5455 | { |
| 5456 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 5457 | /* The multiple "Capture Source" controls confuse alsamixer |
| 5458 | * So call somewhat different.. |
| 5459 | */ |
| 5460 | /* .name = "Capture Source", */ |
| 5461 | .name = "Input Source", |
| 5462 | .count = 2, |
| 5463 | .info = via_mux_enum_info, |
| 5464 | .get = via_mux_enum_get, |
| 5465 | .put = via_mux_enum_put, |
| 5466 | }, |
| 5467 | { } /* end */ |
| 5468 | }; |
| 5469 | |
| 5470 | static struct hda_verb vt2002P_volume_init_verbs[] = { |
| 5471 | /* |
| 5472 | * Unmute ADC0-1 and set the default input to mic-in |
| 5473 | */ |
| 5474 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5475 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5476 | |
| 5477 | |
| 5478 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 5479 | * mixer widget |
| 5480 | */ |
| 5481 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 5482 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 5483 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5484 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 5485 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 5486 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 5487 | |
| 5488 | /* MUX Indices: Mic = 0 */ |
| 5489 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5490 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5491 | |
| 5492 | /* PW9 Output enable */ |
| 5493 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 5494 | |
| 5495 | /* Enable Boost Volume backdoor */ |
| 5496 | {0x1, 0xfb9, 0x24}, |
| 5497 | |
| 5498 | /* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 5499 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5500 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5501 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5502 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5503 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5504 | {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5505 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5506 | {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5507 | |
| 5508 | /* set MUX0/1/4/8 = 0 (AOW0) */ |
| 5509 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5510 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5511 | {0x37, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5512 | {0x3b, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5513 | |
| 5514 | /* set PW0 index=0 (MW0) */ |
| 5515 | {0x24, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5516 | |
| 5517 | /* Enable AOW0 to MW9 */ |
| 5518 | {0x1, 0xfb8, 0x88}, |
| 5519 | { } |
| 5520 | }; |
| 5521 | |
| 5522 | |
| 5523 | static struct hda_verb vt2002P_uniwill_init_verbs[] = { |
| 5524 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5525 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5526 | {0x26, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5527 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5528 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5529 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5530 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5531 | { } |
| 5532 | }; |
| 5533 | |
| 5534 | static struct hda_pcm_stream vt2002P_pcm_analog_playback = { |
| 5535 | .substreams = 2, |
| 5536 | .channels_min = 2, |
| 5537 | .channels_max = 2, |
| 5538 | .nid = 0x8, /* NID to query formats and rates */ |
| 5539 | .ops = { |
| 5540 | .open = via_playback_pcm_open, |
| 5541 | .prepare = via_playback_multi_pcm_prepare, |
| 5542 | .cleanup = via_playback_multi_pcm_cleanup, |
| 5543 | .close = via_pcm_open_close, |
| 5544 | }, |
| 5545 | }; |
| 5546 | |
| 5547 | static struct hda_pcm_stream vt2002P_pcm_analog_capture = { |
| 5548 | .substreams = 2, |
| 5549 | .channels_min = 2, |
| 5550 | .channels_max = 2, |
| 5551 | .nid = 0x10, /* NID to query formats and rates */ |
| 5552 | .ops = { |
| 5553 | .open = via_pcm_open_close, |
| 5554 | .prepare = via_capture_pcm_prepare, |
| 5555 | .cleanup = via_capture_pcm_cleanup, |
| 5556 | .close = via_pcm_open_close, |
| 5557 | }, |
| 5558 | }; |
| 5559 | |
| 5560 | static struct hda_pcm_stream vt2002P_pcm_digital_playback = { |
| 5561 | .substreams = 1, |
| 5562 | .channels_min = 2, |
| 5563 | .channels_max = 2, |
| 5564 | .rates = SNDRV_PCM_RATE_48000, |
| 5565 | /* NID is set in via_build_pcms */ |
| 5566 | .ops = { |
| 5567 | .open = via_dig_playback_pcm_open, |
| 5568 | .close = via_dig_playback_pcm_close, |
| 5569 | .prepare = via_dig_playback_pcm_prepare, |
| 5570 | .cleanup = via_dig_playback_pcm_cleanup |
| 5571 | }, |
| 5572 | }; |
| 5573 | |
| 5574 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 5575 | static int vt2002P_auto_fill_dac_nids(struct via_spec *spec, |
| 5576 | const struct auto_pin_cfg *cfg) |
| 5577 | { |
| 5578 | spec->multiout.num_dacs = 1; |
| 5579 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 5580 | if (cfg->line_out_pins[0]) |
| 5581 | spec->multiout.dac_nids[0] = 0x8; |
| 5582 | return 0; |
| 5583 | } |
| 5584 | |
| 5585 | /* add playback controls from the parsed DAC table */ |
| 5586 | static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec, |
| 5587 | const struct auto_pin_cfg *cfg) |
| 5588 | { |
| 5589 | int err; |
| 5590 | |
| 5591 | if (!cfg->line_out_pins[0]) |
| 5592 | return -1; |
| 5593 | |
| 5594 | |
| 5595 | /* Line-Out: PortE */ |
| 5596 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5597 | "Master Front Playback Volume", |
| 5598 | HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); |
| 5599 | if (err < 0) |
| 5600 | return err; |
| 5601 | err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, |
| 5602 | "Master Front Playback Switch", |
| 5603 | HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT)); |
| 5604 | if (err < 0) |
| 5605 | return err; |
| 5606 | |
| 5607 | return 0; |
| 5608 | } |
| 5609 | |
| 5610 | static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 5611 | { |
| 5612 | int err; |
| 5613 | |
| 5614 | if (!pin) |
| 5615 | return 0; |
| 5616 | |
| 5617 | spec->multiout.hp_nid = 0x9; |
| 5618 | spec->hp_independent_mode_index = 1; |
| 5619 | |
| 5620 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5621 | "Headphone Playback Volume", |
| 5622 | HDA_COMPOSE_AMP_VAL( |
| 5623 | spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); |
| 5624 | if (err < 0) |
| 5625 | return err; |
| 5626 | |
| 5627 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 5628 | "Headphone Playback Switch", |
| 5629 | HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT)); |
| 5630 | if (err < 0) |
| 5631 | return err; |
| 5632 | |
| 5633 | create_hp_imux(spec); |
| 5634 | return 0; |
| 5635 | } |
| 5636 | |
| 5637 | /* create playback/capture controls for input pins */ |
| 5638 | static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec, |
| 5639 | const struct auto_pin_cfg *cfg) |
| 5640 | { |
| 5641 | static char *labels[] = { |
| 5642 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 5643 | }; |
| 5644 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 5645 | int i, err, idx = 0; |
| 5646 | |
| 5647 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 5648 | if (!cfg->input_pins[i]) |
| 5649 | continue; |
| 5650 | |
| 5651 | switch (cfg->input_pins[i]) { |
| 5652 | case 0x2b: /* Mic */ |
| 5653 | idx = 0; |
| 5654 | break; |
| 5655 | |
| 5656 | case 0x2a: /* Line In */ |
| 5657 | idx = 1; |
| 5658 | break; |
| 5659 | |
| 5660 | case 0x29: /* Front Mic */ |
| 5661 | idx = 2; |
| 5662 | break; |
| 5663 | } |
| 5664 | err = via_new_analog_input(spec, labels[i], idx, 0x21); |
| 5665 | if (err < 0) |
| 5666 | return err; |
| 5667 | imux->items[imux->num_items].label = labels[i]; |
| 5668 | imux->items[imux->num_items].index = idx; |
| 5669 | imux->num_items++; |
| 5670 | } |
| 5671 | |
| 5672 | /* build volume/mute control of loopback */ |
| 5673 | err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21); |
| 5674 | if (err < 0) |
| 5675 | return err; |
| 5676 | |
| 5677 | /* for internal loopback recording select */ |
| 5678 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 5679 | imux->items[imux->num_items].index = 3; |
| 5680 | imux->num_items++; |
| 5681 | |
| 5682 | /* for digital mic select */ |
| 5683 | imux->items[imux->num_items].label = "Digital Mic"; |
| 5684 | imux->items[imux->num_items].index = 4; |
| 5685 | imux->num_items++; |
| 5686 | |
| 5687 | return 0; |
| 5688 | } |
| 5689 | |
| 5690 | static int vt2002P_parse_auto_config(struct hda_codec *codec) |
| 5691 | { |
| 5692 | struct via_spec *spec = codec->spec; |
| 5693 | int err; |
| 5694 | |
| 5695 | |
| 5696 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 5697 | if (err < 0) |
| 5698 | return err; |
| 5699 | |
| 5700 | err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg); |
| 5701 | if (err < 0) |
| 5702 | return err; |
| 5703 | |
| 5704 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0]) |
| 5705 | return 0; /* can't find valid BIOS pin config */ |
| 5706 | |
| 5707 | err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 5708 | if (err < 0) |
| 5709 | return err; |
| 5710 | err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 5711 | if (err < 0) |
| 5712 | return err; |
| 5713 | err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 5714 | if (err < 0) |
| 5715 | return err; |
| 5716 | |
| 5717 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 5718 | |
| 5719 | fill_dig_outs(codec); |
| 5720 | |
| 5721 | if (spec->kctls.list) |
| 5722 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 5723 | |
| 5724 | spec->input_mux = &spec->private_imux[0]; |
| 5725 | |
| 5726 | if (spec->hp_mux) |
| 5727 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
| 5728 | |
| 5729 | return 1; |
| 5730 | } |
| 5731 | |
| 5732 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5733 | static struct hda_amp_list vt2002P_loopbacks[] = { |
| 5734 | { 0x21, HDA_INPUT, 0 }, |
| 5735 | { 0x21, HDA_INPUT, 1 }, |
| 5736 | { 0x21, HDA_INPUT, 2 }, |
| 5737 | { } /* end */ |
| 5738 | }; |
| 5739 | #endif |
| 5740 | |
| 5741 | |
| 5742 | /* patch for vt2002P */ |
| 5743 | static int patch_vt2002P(struct hda_codec *codec) |
| 5744 | { |
| 5745 | struct via_spec *spec; |
| 5746 | int err; |
| 5747 | |
| 5748 | /* create a codec specific record */ |
| 5749 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 5750 | if (spec == NULL) |
| 5751 | return -ENOMEM; |
| 5752 | |
| 5753 | codec->spec = spec; |
| 5754 | |
| 5755 | /* automatic parse from the BIOS config */ |
| 5756 | err = vt2002P_parse_auto_config(codec); |
| 5757 | if (err < 0) { |
| 5758 | via_free(codec); |
| 5759 | return err; |
| 5760 | } else if (!err) { |
| 5761 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 5762 | "from BIOS. Using genenic mode...\n"); |
| 5763 | } |
| 5764 | |
| 5765 | spec->init_verbs[spec->num_iverbs++] = vt2002P_volume_init_verbs; |
| 5766 | spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs; |
| 5767 | |
| 5768 | spec->stream_name_analog = "VT2002P Analog"; |
| 5769 | spec->stream_analog_playback = &vt2002P_pcm_analog_playback; |
| 5770 | spec->stream_analog_capture = &vt2002P_pcm_analog_capture; |
| 5771 | |
| 5772 | spec->stream_name_digital = "VT2002P Digital"; |
| 5773 | spec->stream_digital_playback = &vt2002P_pcm_digital_playback; |
| 5774 | |
| 5775 | if (!spec->adc_nids && spec->input_mux) { |
| 5776 | spec->adc_nids = vt2002P_adc_nids; |
| 5777 | spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids); |
| 5778 | get_mux_nids(codec); |
| 5779 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 5780 | override_mic_boost(codec, 0x29, 0, 3, 40); |
| 5781 | spec->mixers[spec->num_mixers] = vt2002P_capture_mixer; |
| 5782 | spec->num_mixers++; |
| 5783 | } |
| 5784 | |
| 5785 | codec->patch_ops = via_patch_ops; |
| 5786 | |
| 5787 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame^] | 5788 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 5789 | |
| 5790 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 5791 | spec->loopback.amplist = vt2002P_loopbacks; |
| 5792 | #endif |
| 5793 | |
| 5794 | return 0; |
| 5795 | } |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 5796 | |
| 5797 | /* for vt1812 */ |
| 5798 | |
| 5799 | /* capture mixer elements */ |
| 5800 | static struct snd_kcontrol_new vt1812_capture_mixer[] = { |
| 5801 | HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT), |
| 5802 | HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT), |
| 5803 | HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT), |
| 5804 | HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT), |
| 5805 | HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT), |
| 5806 | HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0, |
| 5807 | HDA_INPUT), |
| 5808 | { |
| 5809 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 5810 | /* The multiple "Capture Source" controls confuse alsamixer |
| 5811 | * So call somewhat different.. |
| 5812 | */ |
| 5813 | .name = "Input Source", |
| 5814 | .count = 2, |
| 5815 | .info = via_mux_enum_info, |
| 5816 | .get = via_mux_enum_get, |
| 5817 | .put = via_mux_enum_put, |
| 5818 | }, |
| 5819 | { } /* end */ |
| 5820 | }; |
| 5821 | |
| 5822 | static struct hda_verb vt1812_volume_init_verbs[] = { |
| 5823 | /* |
| 5824 | * Unmute ADC0-1 and set the default input to mic-in |
| 5825 | */ |
| 5826 | {0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5827 | {0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5828 | |
| 5829 | |
| 5830 | /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback |
| 5831 | * mixer widget |
| 5832 | */ |
| 5833 | /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */ |
| 5834 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, |
| 5835 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, |
| 5836 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, |
| 5837 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, |
| 5838 | {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, |
| 5839 | |
| 5840 | /* MUX Indices: Mic = 0 */ |
| 5841 | {0x1e, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5842 | {0x1f, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5843 | |
| 5844 | /* PW9 Output enable */ |
| 5845 | {0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN}, |
| 5846 | |
| 5847 | /* Enable Boost Volume backdoor */ |
| 5848 | {0x1, 0xfb9, 0x24}, |
| 5849 | |
| 5850 | /* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */ |
| 5851 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5852 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5853 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5854 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5855 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, |
| 5856 | {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5857 | {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5858 | {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5859 | {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5860 | {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, |
| 5861 | |
| 5862 | /* set MUX0/1/4/13/15 = 0 (AOW0) */ |
| 5863 | {0x34, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5864 | {0x35, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5865 | {0x38, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5866 | {0x3c, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5867 | {0x3d, AC_VERB_SET_CONNECT_SEL, 0}, |
| 5868 | |
| 5869 | /* Enable AOW0 to MW9 */ |
| 5870 | {0x1, 0xfb8, 0xa8}, |
| 5871 | { } |
| 5872 | }; |
| 5873 | |
| 5874 | |
| 5875 | static struct hda_verb vt1812_uniwill_init_verbs[] = { |
| 5876 | {0x33, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5877 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5878 | {0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT }, |
| 5879 | {0x28, AC_VERB_SET_UNSOLICITED_ENABLE, |
| 5880 | AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT}, |
| 5881 | {0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5882 | {0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5883 | {0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT}, |
| 5884 | { } |
| 5885 | }; |
| 5886 | |
| 5887 | static struct hda_pcm_stream vt1812_pcm_analog_playback = { |
| 5888 | .substreams = 2, |
| 5889 | .channels_min = 2, |
| 5890 | .channels_max = 2, |
| 5891 | .nid = 0x8, /* NID to query formats and rates */ |
| 5892 | .ops = { |
| 5893 | .open = via_playback_pcm_open, |
| 5894 | .prepare = via_playback_multi_pcm_prepare, |
| 5895 | .cleanup = via_playback_multi_pcm_cleanup, |
| 5896 | .close = via_pcm_open_close, |
| 5897 | }, |
| 5898 | }; |
| 5899 | |
| 5900 | static struct hda_pcm_stream vt1812_pcm_analog_capture = { |
| 5901 | .substreams = 2, |
| 5902 | .channels_min = 2, |
| 5903 | .channels_max = 2, |
| 5904 | .nid = 0x10, /* NID to query formats and rates */ |
| 5905 | .ops = { |
| 5906 | .open = via_pcm_open_close, |
| 5907 | .prepare = via_capture_pcm_prepare, |
| 5908 | .cleanup = via_capture_pcm_cleanup, |
| 5909 | .close = via_pcm_open_close, |
| 5910 | }, |
| 5911 | }; |
| 5912 | |
| 5913 | static struct hda_pcm_stream vt1812_pcm_digital_playback = { |
| 5914 | .substreams = 1, |
| 5915 | .channels_min = 2, |
| 5916 | .channels_max = 2, |
| 5917 | .rates = SNDRV_PCM_RATE_48000, |
| 5918 | /* NID is set in via_build_pcms */ |
| 5919 | .ops = { |
| 5920 | .open = via_dig_playback_pcm_open, |
| 5921 | .close = via_dig_playback_pcm_close, |
| 5922 | .prepare = via_dig_playback_pcm_prepare, |
| 5923 | .cleanup = via_dig_playback_pcm_cleanup |
| 5924 | }, |
| 5925 | }; |
| 5926 | /* fill in the dac_nids table from the parsed pin configuration */ |
| 5927 | static int vt1812_auto_fill_dac_nids(struct via_spec *spec, |
| 5928 | const struct auto_pin_cfg *cfg) |
| 5929 | { |
| 5930 | spec->multiout.num_dacs = 1; |
| 5931 | spec->multiout.dac_nids = spec->private_dac_nids; |
| 5932 | if (cfg->line_out_pins[0]) |
| 5933 | spec->multiout.dac_nids[0] = 0x8; |
| 5934 | return 0; |
| 5935 | } |
| 5936 | |
| 5937 | |
| 5938 | /* add playback controls from the parsed DAC table */ |
| 5939 | static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec, |
| 5940 | const struct auto_pin_cfg *cfg) |
| 5941 | { |
| 5942 | int err; |
| 5943 | |
| 5944 | if (!cfg->line_out_pins[0]) |
| 5945 | return -1; |
| 5946 | |
| 5947 | /* Line-Out: PortE */ |
| 5948 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5949 | "Master Front Playback Volume", |
| 5950 | HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT)); |
| 5951 | if (err < 0) |
| 5952 | return err; |
| 5953 | err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE, |
| 5954 | "Master Front Playback Switch", |
| 5955 | HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT)); |
| 5956 | if (err < 0) |
| 5957 | return err; |
| 5958 | |
| 5959 | return 0; |
| 5960 | } |
| 5961 | |
| 5962 | static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin) |
| 5963 | { |
| 5964 | int err; |
| 5965 | |
| 5966 | if (!pin) |
| 5967 | return 0; |
| 5968 | |
| 5969 | spec->multiout.hp_nid = 0x9; |
| 5970 | spec->hp_independent_mode_index = 1; |
| 5971 | |
| 5972 | |
| 5973 | err = via_add_control(spec, VIA_CTL_WIDGET_VOL, |
| 5974 | "Headphone Playback Volume", |
| 5975 | HDA_COMPOSE_AMP_VAL( |
| 5976 | spec->multiout.hp_nid, 3, 0, HDA_OUTPUT)); |
| 5977 | if (err < 0) |
| 5978 | return err; |
| 5979 | |
| 5980 | err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, |
| 5981 | "Headphone Playback Switch", |
| 5982 | HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); |
| 5983 | if (err < 0) |
| 5984 | return err; |
| 5985 | |
| 5986 | create_hp_imux(spec); |
| 5987 | return 0; |
| 5988 | } |
| 5989 | |
| 5990 | /* create playback/capture controls for input pins */ |
| 5991 | static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec, |
| 5992 | const struct auto_pin_cfg *cfg) |
| 5993 | { |
| 5994 | static char *labels[] = { |
| 5995 | "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL |
| 5996 | }; |
| 5997 | struct hda_input_mux *imux = &spec->private_imux[0]; |
| 5998 | int i, err, idx = 0; |
| 5999 | |
| 6000 | for (i = 0; i < AUTO_PIN_LAST; i++) { |
| 6001 | if (!cfg->input_pins[i]) |
| 6002 | continue; |
| 6003 | |
| 6004 | switch (cfg->input_pins[i]) { |
| 6005 | case 0x2b: /* Mic */ |
| 6006 | idx = 0; |
| 6007 | break; |
| 6008 | |
| 6009 | case 0x2a: /* Line In */ |
| 6010 | idx = 1; |
| 6011 | break; |
| 6012 | |
| 6013 | case 0x29: /* Front Mic */ |
| 6014 | idx = 2; |
| 6015 | break; |
| 6016 | } |
| 6017 | err = via_new_analog_input(spec, labels[i], idx, 0x21); |
| 6018 | if (err < 0) |
| 6019 | return err; |
| 6020 | imux->items[imux->num_items].label = labels[i]; |
| 6021 | imux->items[imux->num_items].index = idx; |
| 6022 | imux->num_items++; |
| 6023 | } |
| 6024 | /* build volume/mute control of loopback */ |
| 6025 | err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21); |
| 6026 | if (err < 0) |
| 6027 | return err; |
| 6028 | |
| 6029 | /* for internal loopback recording select */ |
| 6030 | imux->items[imux->num_items].label = "Stereo Mixer"; |
| 6031 | imux->items[imux->num_items].index = 5; |
| 6032 | imux->num_items++; |
| 6033 | |
| 6034 | /* for digital mic select */ |
| 6035 | imux->items[imux->num_items].label = "Digital Mic"; |
| 6036 | imux->items[imux->num_items].index = 6; |
| 6037 | imux->num_items++; |
| 6038 | |
| 6039 | return 0; |
| 6040 | } |
| 6041 | |
| 6042 | static int vt1812_parse_auto_config(struct hda_codec *codec) |
| 6043 | { |
| 6044 | struct via_spec *spec = codec->spec; |
| 6045 | int err; |
| 6046 | |
| 6047 | |
| 6048 | err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL); |
| 6049 | if (err < 0) |
| 6050 | return err; |
| 6051 | fill_dig_outs(codec); |
| 6052 | err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg); |
| 6053 | if (err < 0) |
| 6054 | return err; |
| 6055 | |
| 6056 | if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs) |
| 6057 | return 0; /* can't find valid BIOS pin config */ |
| 6058 | |
| 6059 | err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg); |
| 6060 | if (err < 0) |
| 6061 | return err; |
| 6062 | err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]); |
| 6063 | if (err < 0) |
| 6064 | return err; |
| 6065 | err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg); |
| 6066 | if (err < 0) |
| 6067 | return err; |
| 6068 | |
| 6069 | spec->multiout.max_channels = spec->multiout.num_dacs * 2; |
| 6070 | |
| 6071 | fill_dig_outs(codec); |
| 6072 | |
| 6073 | if (spec->kctls.list) |
| 6074 | spec->mixers[spec->num_mixers++] = spec->kctls.list; |
| 6075 | |
| 6076 | spec->input_mux = &spec->private_imux[0]; |
| 6077 | |
| 6078 | if (spec->hp_mux) |
| 6079 | spec->mixers[spec->num_mixers++] = via_hp_mixer; |
| 6080 | |
| 6081 | return 1; |
| 6082 | } |
| 6083 | |
| 6084 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6085 | static struct hda_amp_list vt1812_loopbacks[] = { |
| 6086 | { 0x21, HDA_INPUT, 0 }, |
| 6087 | { 0x21, HDA_INPUT, 1 }, |
| 6088 | { 0x21, HDA_INPUT, 2 }, |
| 6089 | { } /* end */ |
| 6090 | }; |
| 6091 | #endif |
| 6092 | |
| 6093 | |
| 6094 | /* patch for vt1812 */ |
| 6095 | static int patch_vt1812(struct hda_codec *codec) |
| 6096 | { |
| 6097 | struct via_spec *spec; |
| 6098 | int err; |
| 6099 | |
| 6100 | /* create a codec specific record */ |
| 6101 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 6102 | if (spec == NULL) |
| 6103 | return -ENOMEM; |
| 6104 | |
| 6105 | codec->spec = spec; |
| 6106 | |
| 6107 | /* automatic parse from the BIOS config */ |
| 6108 | err = vt1812_parse_auto_config(codec); |
| 6109 | if (err < 0) { |
| 6110 | via_free(codec); |
| 6111 | return err; |
| 6112 | } else if (!err) { |
| 6113 | printk(KERN_INFO "hda_codec: Cannot set up configuration " |
| 6114 | "from BIOS. Using genenic mode...\n"); |
| 6115 | } |
| 6116 | |
| 6117 | |
| 6118 | spec->init_verbs[spec->num_iverbs++] = vt1812_volume_init_verbs; |
| 6119 | spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs; |
| 6120 | |
| 6121 | spec->stream_name_analog = "VT1812 Analog"; |
| 6122 | spec->stream_analog_playback = &vt1812_pcm_analog_playback; |
| 6123 | spec->stream_analog_capture = &vt1812_pcm_analog_capture; |
| 6124 | |
| 6125 | spec->stream_name_digital = "VT1812 Digital"; |
| 6126 | spec->stream_digital_playback = &vt1812_pcm_digital_playback; |
| 6127 | |
| 6128 | |
| 6129 | if (!spec->adc_nids && spec->input_mux) { |
| 6130 | spec->adc_nids = vt1812_adc_nids; |
| 6131 | spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids); |
| 6132 | get_mux_nids(codec); |
| 6133 | override_mic_boost(codec, 0x2b, 0, 3, 40); |
| 6134 | override_mic_boost(codec, 0x29, 0, 3, 40); |
| 6135 | spec->mixers[spec->num_mixers] = vt1812_capture_mixer; |
| 6136 | spec->num_mixers++; |
| 6137 | } |
| 6138 | |
| 6139 | codec->patch_ops = via_patch_ops; |
| 6140 | |
| 6141 | codec->patch_ops.init = via_auto_init; |
Stephen Rothwell | 0f48327 | 2009-10-12 15:56:17 +1100 | [diff] [blame^] | 6142 | codec->patch_ops.unsol_event = via_unsol_event; |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6143 | |
| 6144 | #ifdef CONFIG_SND_HDA_POWER_SAVE |
| 6145 | spec->loopback.amplist = vt1812_loopbacks; |
| 6146 | #endif |
| 6147 | |
| 6148 | return 0; |
| 6149 | } |
| 6150 | |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 6151 | /* |
| 6152 | * patch entries |
| 6153 | */ |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 6154 | static struct hda_codec_preset snd_hda_preset_via[] = { |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6155 | { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708}, |
| 6156 | { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708}, |
| 6157 | { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708}, |
| 6158 | { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708}, |
| 6159 | { .id = 0x1106e710, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6160 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6161 | { .id = 0x1106e711, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6162 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6163 | { .id = 0x1106e712, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6164 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6165 | { .id = 0x1106e713, .name = "VT1709 10-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6166 | .patch = patch_vt1709_10ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6167 | { .id = 0x1106e714, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6168 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6169 | { .id = 0x1106e715, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6170 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6171 | { .id = 0x1106e716, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6172 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6173 | { .id = 0x1106e717, .name = "VT1709 6-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6174 | .patch = patch_vt1709_6ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6175 | { .id = 0x1106e720, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6176 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6177 | { .id = 0x1106e721, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6178 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6179 | { .id = 0x1106e722, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6180 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6181 | { .id = 0x1106e723, .name = "VT1708B 8-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6182 | .patch = patch_vt1708B_8ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6183 | { .id = 0x1106e724, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6184 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6185 | { .id = 0x1106e725, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6186 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6187 | { .id = 0x1106e726, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6188 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6189 | { .id = 0x1106e727, .name = "VT1708B 4-Ch", |
Josepch Chan | f7278fd | 2007-12-13 16:40:40 +0100 | [diff] [blame] | 6190 | .patch = patch_vt1708B_4ch}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6191 | { .id = 0x11060397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6192 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6193 | { .id = 0x11061397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6194 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6195 | { .id = 0x11062397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6196 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6197 | { .id = 0x11063397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6198 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6199 | { .id = 0x11064397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6200 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6201 | { .id = 0x11065397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6202 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6203 | { .id = 0x11066397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6204 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6205 | { .id = 0x11067397, .name = "VT1708S", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6206 | .patch = patch_vt1708S}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6207 | { .id = 0x11060398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6208 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6209 | { .id = 0x11061398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6210 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6211 | { .id = 0x11062398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6212 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6213 | { .id = 0x11063398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6214 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6215 | { .id = 0x11064398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6216 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6217 | { .id = 0x11065398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6218 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6219 | { .id = 0x11066398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6220 | .patch = patch_vt1702}, |
Takashi Iwai | 3218c17 | 2008-12-18 09:17:56 +0100 | [diff] [blame] | 6221 | { .id = 0x11067398, .name = "VT1702", |
Harald Welte | d949cac | 2008-09-09 15:56:01 +0800 | [diff] [blame] | 6222 | .patch = patch_vt1702}, |
Lydia Wang | eb7188c | 2009-10-10 19:08:34 +0800 | [diff] [blame] | 6223 | { .id = 0x11060428, .name = "VT1718S", |
| 6224 | .patch = patch_vt1718S}, |
| 6225 | { .id = 0x11064428, .name = "VT1718S", |
| 6226 | .patch = patch_vt1718S}, |
Lydia Wang | bb3c6bfc | 2009-10-10 19:08:39 +0800 | [diff] [blame] | 6227 | { .id = 0x11060441, .name = "VT2020", |
| 6228 | .patch = patch_vt1718S}, |
| 6229 | { .id = 0x11064441, .name = "VT1828S", |
| 6230 | .patch = patch_vt1718S}, |
Lydia Wang | f3db423 | 2009-10-10 19:08:41 +0800 | [diff] [blame] | 6231 | { .id = 0x11060433, .name = "VT1716S", |
| 6232 | .patch = patch_vt1716S}, |
| 6233 | { .id = 0x1106a721, .name = "VT1716S", |
| 6234 | .patch = patch_vt1716S}, |
Lydia Wang | 25eaba2 | 2009-10-10 19:08:43 +0800 | [diff] [blame] | 6235 | { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P}, |
| 6236 | { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P}, |
Lydia Wang | ab6734e | 2009-10-10 19:08:46 +0800 | [diff] [blame] | 6237 | { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812}, |
Joseph Chan | c577b8a | 2006-11-29 15:29:40 +0100 | [diff] [blame] | 6238 | {} /* terminator */ |
| 6239 | }; |
Takashi Iwai | 1289e9e | 2008-11-27 15:47:11 +0100 | [diff] [blame] | 6240 | |
| 6241 | MODULE_ALIAS("snd-hda-codec-id:1106*"); |
| 6242 | |
| 6243 | static struct hda_codec_preset_list via_list = { |
| 6244 | .preset = snd_hda_preset_via, |
| 6245 | .owner = THIS_MODULE, |
| 6246 | }; |
| 6247 | |
| 6248 | MODULE_LICENSE("GPL"); |
| 6249 | MODULE_DESCRIPTION("VIA HD-audio codec"); |
| 6250 | |
| 6251 | static int __init patch_via_init(void) |
| 6252 | { |
| 6253 | return snd_hda_add_codec_preset(&via_list); |
| 6254 | } |
| 6255 | |
| 6256 | static void __exit patch_via_exit(void) |
| 6257 | { |
| 6258 | snd_hda_delete_codec_preset(&via_list); |
| 6259 | } |
| 6260 | |
| 6261 | module_init(patch_via_init) |
| 6262 | module_exit(patch_via_exit) |