blob: 8ce0a0d4f083744a673478652eb3d0b787fcd3db [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe409a3e92012-03-27 13:01:01 +10309 * Jonathan Woithe <jwoithe@just42.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Takashi Iwai23d30f22012-05-07 17:17:32 +020035#include "hda_auto_parser.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090036#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020037#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Takashi Iwai1d045db2011-07-07 18:23:21 +020039/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020044
Kailang Yangdf694da2005-12-05 19:42:22 +010045/* for GPIO Poll */
46#define GPIO_MASK 0x03
47
Takashi Iwai4a79ba32009-04-22 16:31:35 +020048/* extra amp-initialization sequence types */
49enum {
50 ALC_INIT_NONE,
51 ALC_INIT_DEFAULT,
52 ALC_INIT_GPIO1,
53 ALC_INIT_GPIO2,
54 ALC_INIT_GPIO3,
55};
56
Kailang Yangda00c242010-03-19 11:23:45 +010057struct alc_customize_define {
58 unsigned int sku_cfg;
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
65 unsigned int swap:1;
66 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020067 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010068};
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Takashi Iwaic14c95f2012-02-16 16:38:07 +010082#define MAX_VOL_NIDS 0x40
83
Takashi Iwai23d30f22012-05-07 17:17:32 +020084/* make compatible with old code */
85#define alc_apply_pincfgs snd_hda_apply_pincfgs
86#define alc_apply_fixup snd_hda_apply_fixup
87#define alc_pick_fixup snd_hda_pick_fixup
88#define alc_fixup hda_fixup
89#define alc_pincfg hda_pintbl
90#define alc_model_fixup hda_model_fixup
91
92#define ALC_FIXUP_PINS HDA_FIXUP_PINS
93#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
95
96#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
100
101
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100102#define MAX_NID_PATH_DEPTH 5
103
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100104/* Widget connection path
105 *
106 * For output, stored in the order of DAC -> ... -> pin,
107 * for input, pin -> ... -> ADC.
108 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100109 * idx[i] contains the source index number to select on of the widget path[i];
110 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100111 * multi[] indicates whether it's a selector widget with multi-connectors
112 * (i.e. the connection selection is mandatory)
113 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
114 */
115struct nid_path {
116 int depth;
117 hda_nid_t path[MAX_NID_PATH_DEPTH];
118 unsigned char idx[MAX_NID_PATH_DEPTH];
119 unsigned char multi[MAX_NID_PATH_DEPTH];
120 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
121};
122
Takashi Iwaiba8111272012-12-06 18:06:23 +0100123enum { NID_PATH_VOL_CTL = 0, NID_PATH_MUTE_CTL = 1 };
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200126 struct hda_gen_spec gen;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200129 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200131 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100132 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200134 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200135 const struct hda_pcm_stream *stream_analog_playback;
136 const struct hda_pcm_stream *stream_analog_capture;
137 const struct hda_pcm_stream *stream_analog_alt_playback;
138 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200140 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200141 const struct hda_pcm_stream *stream_digital_playback;
142 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200145 struct hda_multi_out multiout; /* playback set-up
146 * max_channels, dacs must be set
147 * dig_out_nid and hp_nid are optional
148 */
Takashi Iwai63300792008-01-24 15:31:36 +0100149 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100150 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100151 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* capture */
154 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200155 const hda_nid_t *adc_nids;
156 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200157 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200158 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Takashi Iwai840b64c2010-07-13 22:49:01 +0200160 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200161 hda_nid_t cur_adc;
162 unsigned int cur_adc_stream_tag;
163 unsigned int cur_adc_format;
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200166 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 const struct hda_input_mux *input_mux;
168 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200169 hda_nid_t ext_mic_pin;
170 hda_nid_t dock_mic_pin;
171 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100174 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200176 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100177 int const_channel_count; /* min. channel count (for speakers) */
178 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100181 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200182
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200183 /* dynamic controls, init_verbs and input_mux */
184 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100185 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200186 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200187 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200188 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200189 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
190 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200191 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
192 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
193 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200194 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100195
Takashi Iwai463419d2012-12-05 14:17:37 +0100196 /* DAC list */
197 int num_all_dacs;
198 hda_nid_t all_dacs[16];
199
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100200 /* output paths */
201 struct snd_array out_path;
202
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100203 /* input paths */
204 struct snd_array in_path;
205
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100206 /* analog loopback paths */
207 struct snd_array loopback_path;
208
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100209 /* hooks */
210 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200211#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500212 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100213#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200214 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200215 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100216
Takashi Iwai834be882006-03-01 14:16:17 +0100217 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200218 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200219 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200220 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200221 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200222 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200223 unsigned int automute_speaker:1; /* automute speaker outputs */
224 unsigned int automute_lo:1; /* automute LO outputs */
225 unsigned int detect_hp:1; /* Headphone detection enabled */
226 unsigned int detect_lo:1; /* Line-out detection enabled */
227 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
228 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100229 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200230
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100231 /* other flags */
232 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200233 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100234 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200235 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200236 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100237 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200238 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
239 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200240 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200241
242 /* auto-mute control */
243 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200244 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200245
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200246 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200247 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100248
Takashi Iwai2134ea42008-01-10 16:53:55 +0100249 /* for virtual master */
250 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100251 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200252#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200253 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100254 int num_loopbacks;
255 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200256#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200257
258 /* for PLL fix */
259 hda_nid_t pll_nid;
260 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200261 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100262
Takashi Iwaice764ab2011-04-27 16:35:23 +0200263 /* multi-io */
264 int multi_ios;
265 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200266
267 /* bind volumes */
268 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100269};
270
Takashi Iwai44c02402011-07-08 15:14:19 +0200271static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
272 int dir, unsigned int bits)
273{
274 if (!nid)
275 return false;
276 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
277 if (query_amp_caps(codec, nid, dir) & bits)
278 return true;
279 return false;
280}
281
282#define nid_has_mute(codec, nid, dir) \
283 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
284#define nid_has_volume(codec, nid, dir) \
285 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/*
288 * input MUX handling
289 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200290static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
291 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
293 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
294 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200295 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
296 if (mux_idx >= spec->num_mux_defs)
297 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100298 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
299 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200300 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200303static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
304 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
307 struct alc_spec *spec = codec->spec;
308 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
309
310 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
311 return 0;
312}
313
Takashi Iwai21268962011-07-07 15:01:13 +0200314static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Takashi Iwai21268962011-07-07 15:01:13 +0200316 struct alc_spec *spec = codec->spec;
317 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
318
319 if (spec->cur_adc && spec->cur_adc != new_adc) {
320 /* stream is running, let's swap the current ADC */
321 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
322 spec->cur_adc = new_adc;
323 snd_hda_codec_setup_stream(codec, new_adc,
324 spec->cur_adc_stream_tag, 0,
325 spec->cur_adc_format);
326 return true;
327 }
328 return false;
329}
330
Takashi Iwai61071592011-11-23 07:52:15 +0100331static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
332{
333 return spec->capsrc_nids ?
334 spec->capsrc_nids[idx] : spec->adc_nids[idx];
335}
336
Takashi Iwai24de1832011-11-07 17:13:39 +0100337static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200338static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100339
David Henningsson00227f12012-06-27 18:45:44 +0200340/* for shared I/O, change the pin-control accordingly */
341static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
342{
343 struct alc_spec *spec = codec->spec;
344 unsigned int val;
345 hda_nid_t pin = spec->autocfg.inputs[1].pin;
346 /* NOTE: this assumes that there are only two inputs, the
347 * first is the real internal mic and the second is HP/mic jack.
348 */
349
350 val = snd_hda_get_default_vref(codec, pin);
351
352 /* This pin does not have vref caps - let's enable vref on pin 0x18
353 instead, as suggested by Realtek */
354 if (val == AC_PINCTL_VREF_HIZ) {
355 const hda_nid_t vref_pin = 0x18;
356 /* Sanity check pin 0x18 */
357 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
358 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
359 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
360 if (vref_val != AC_PINCTL_VREF_HIZ)
361 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
362 }
363 }
364
365 val = set_as_mic ? val | PIN_IN : PIN_HP;
366 snd_hda_set_pin_ctl(codec, pin, val);
367
368 spec->automute_speaker = !set_as_mic;
369 call_update_outputs(codec);
370}
Takashi Iwai21268962011-07-07 15:01:13 +0200371
372/* select the given imux item; either unmute exclusively or select the route */
373static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
374 unsigned int idx, bool force)
375{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100377 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100378 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100379 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200380 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Takashi Iwai5803a322012-02-21 11:59:45 +0100382 if (!spec->input_mux)
383 return 0;
384
Takashi Iwaicd896c32008-11-18 12:36:33 +0100385 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
386 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100387 if (!imux->num_items && mux_idx > 0)
388 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100389 if (!imux->num_items)
390 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100391
Takashi Iwai21268962011-07-07 15:01:13 +0200392 if (idx >= imux->num_items)
393 idx = imux->num_items - 1;
394 if (spec->cur_mux[adc_idx] == idx && !force)
395 return 0;
396 spec->cur_mux[adc_idx] = idx;
397
David Henningsson00227f12012-06-27 18:45:44 +0200398 if (spec->shared_mic_hp)
399 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100400
Takashi Iwai21268962011-07-07 15:01:13 +0200401 if (spec->dyn_adc_switch) {
402 alc_dyn_adc_pcm_resetup(codec, idx);
403 adc_idx = spec->dyn_adc_idx[idx];
404 }
405
Takashi Iwai61071592011-11-23 07:52:15 +0100406 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200407
408 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200409 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100410 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200411 return 1;
412
Takashi Iwaia22d5432009-07-27 12:54:26 +0200413 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200414 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100415 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100416 int active = imux->items[idx].index;
417 for (i = 0; i < num_conns; i++) {
418 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
419 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100420 HDA_AMP_MUTE, v);
421 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100422 } else {
423 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200424 snd_hda_codec_write_cache(codec, nid, 0,
425 AC_VERB_SET_CONNECT_SEL,
426 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100427 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200428 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200429 return 1;
430}
431
432static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
433 struct snd_ctl_elem_value *ucontrol)
434{
435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
436 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
437 return alc_mux_select(codec, adc_idx,
438 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100439}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100442 * set up the input pin config (depending on the given auto-pin type)
443 */
444static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
445 int auto_pin_type)
446{
447 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200448 if (auto_pin_type == AUTO_PIN_MIC)
449 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200450 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100451}
452
453/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200454 * Append the given mixer and verb elements for the later use
455 * The mixer array is referred in build_controls(), and init_verbs are
456 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100457 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200458static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100459{
460 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
461 return;
462 spec->mixers[spec->num_mixers++] = mix;
463}
464
Takashi Iwaid88897e2008-10-31 15:01:37 +0100465/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200466 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100467 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200468/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200469static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200470 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
471 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
472 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
473 { }
474};
475
Takashi Iwaia9111322011-05-02 11:30:18 +0200476static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200477 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
478 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
479 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
480 { }
481};
482
Takashi Iwaia9111322011-05-02 11:30:18 +0200483static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200484 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
485 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
486 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
487 { }
488};
489
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200490/*
491 * Fix hardware PLL issue
492 * On some codecs, the analog PLL gating control must be off while
493 * the default value is 1.
494 */
495static void alc_fix_pll(struct hda_codec *codec)
496{
497 struct alc_spec *spec = codec->spec;
498 unsigned int val;
499
500 if (!spec->pll_nid)
501 return;
502 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
503 spec->pll_coef_idx);
504 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
505 AC_VERB_GET_PROC_COEF, 0);
506 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
507 spec->pll_coef_idx);
508 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
509 val & ~(1 << spec->pll_coef_bit));
510}
511
512static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
513 unsigned int coef_idx, unsigned int coef_bit)
514{
515 struct alc_spec *spec = codec->spec;
516 spec->pll_nid = nid;
517 spec->pll_coef_idx = coef_idx;
518 spec->pll_coef_bit = coef_bit;
519 alc_fix_pll(codec);
520}
521
Takashi Iwai1d045db2011-07-07 18:23:21 +0200522/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200523 * Jack detections for HP auto-mute and mic-switch
524 */
525
526/* check each pin in the given array; returns true if any of them is plugged */
527static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200528{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200530
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200531 for (i = 0; i < num_pins; i++) {
532 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200533 if (!nid)
534 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200536 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537 return present;
538}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200539
Takashi Iwai1d045db2011-07-07 18:23:21 +0200540/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200541static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200542 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543{
544 struct alc_spec *spec = codec->spec;
545 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200546 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200547 int i;
548
549 for (i = 0; i < num_pins; i++) {
550 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100551 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200552 if (!nid)
553 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200554 switch (spec->automute_mode) {
555 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100556 /* don't reset VREF value in case it's controlling
557 * the amp (see alc861_fixup_asus_amp_vref_0f())
558 */
559 if (spec->keep_vref_in_automute) {
560 val = snd_hda_codec_read(codec, nid, 0,
561 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
562 val &= ~PIN_HP;
563 } else
564 val = 0;
565 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200566 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200567 break;
568 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200569 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200570 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200571 break;
572 case ALC_AUTOMUTE_MIXER:
573 nid = spec->automute_mixer_nid[i];
574 if (!nid)
575 break;
576 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200578 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200579 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200580 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200581 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200582 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200583}
584
David Henningsson42cf0d02011-09-20 12:04:56 +0200585/* Toggle outputs muting */
586static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587{
588 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200589 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590
Takashi Iwaic0a20262011-06-10 15:28:15 +0200591 /* Control HP pins/amps depending on master_mute state;
592 * in general, HP pins/amps control should be enabled in all cases,
593 * but currently set only for master_mute, just to be safe
594 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100595 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
596 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200597 spec->autocfg.hp_pins, spec->master_mute, true);
598
David Henningsson42cf0d02011-09-20 12:04:56 +0200599 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200600 on = 0;
601 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200602 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200603 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200604 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200605 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200606
607 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200608 /* if LO is a copy of either HP or Speaker, don't need to handle it */
609 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
610 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200611 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200612 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200613 on = 0;
614 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200615 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200616 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200617 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200618 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200619}
620
David Henningsson42cf0d02011-09-20 12:04:56 +0200621static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200622{
623 struct alc_spec *spec = codec->spec;
624 if (spec->automute_hook)
625 spec->automute_hook(codec);
626 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200627 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200628}
629
Takashi Iwai1d045db2011-07-07 18:23:21 +0200630/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200631static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200632{
633 struct alc_spec *spec = codec->spec;
634
David Henningsson42cf0d02011-09-20 12:04:56 +0200635 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200636 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
637 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200638 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200639 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200640 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200641}
642
Takashi Iwai1d045db2011-07-07 18:23:21 +0200643/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200644static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200645{
646 struct alc_spec *spec = codec->spec;
647
David Henningssonf7f4b232012-10-10 16:32:09 +0200648 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
649 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200650 /* check LO jack only when it's different from HP */
651 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
652 return;
653
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200654 spec->line_jack_present =
655 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
656 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200657 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200658 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200659 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200660}
661
Takashi Iwai8d087c72011-06-28 12:45:47 +0200662#define get_connection_index(codec, mux, nid) \
663 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200664
Takashi Iwai1d045db2011-07-07 18:23:21 +0200665/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200666static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200667{
668 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200669 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200670
Takashi Iwai21268962011-07-07 15:01:13 +0200671 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200672 return;
673 if (snd_BUG_ON(!spec->adc_nids))
674 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200675 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200676 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200677
Takashi Iwai21268962011-07-07 15:01:13 +0200678 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
679 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
680 else if (spec->dock_mic_idx >= 0 &&
681 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
682 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
683 else
684 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200685}
686
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100687/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200688static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100689{
690 unsigned int val;
691 struct snd_kcontrol *kctl;
692 struct snd_ctl_elem_value *uctl;
693
694 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
695 if (!kctl)
696 return;
697 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
698 if (!uctl)
699 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200700 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100701 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
702 val &= HDA_AMP_VOLMASK;
703 uctl->value.integer.value[0] = val;
704 uctl->value.integer.value[1] = val;
705 kctl->put(kctl, uctl);
706 kfree(uctl);
707}
708
David Henningsson29adc4b2012-09-25 11:31:00 +0200709static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100710{
David Henningsson29adc4b2012-09-25 11:31:00 +0200711 /* For some reason, the res given from ALC880 is broken.
712 Here we adjust it properly. */
713 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100714}
715
Takashi Iwai1d045db2011-07-07 18:23:21 +0200716/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200717static void alc_inithook(struct hda_codec *codec)
718{
David Henningsson29adc4b2012-09-25 11:31:00 +0200719 alc_hp_automute(codec, NULL);
720 alc_line_automute(codec, NULL);
721 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200722}
723
Kailang Yangf9423e72008-05-27 12:32:25 +0200724/* additional initialization for ALC888 variants */
725static void alc888_coef_init(struct hda_codec *codec)
726{
727 unsigned int tmp;
728
729 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
730 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
731 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100732 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200733 /* alc888S-VC */
734 snd_hda_codec_read(codec, 0x20, 0,
735 AC_VERB_SET_PROC_COEF, 0x830);
736 else
737 /* alc888-VB */
738 snd_hda_codec_read(codec, 0x20, 0,
739 AC_VERB_SET_PROC_COEF, 0x3030);
740}
741
Takashi Iwai1d045db2011-07-07 18:23:21 +0200742/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200743static void alc889_coef_init(struct hda_codec *codec)
744{
745 unsigned int tmp;
746
747 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
748 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
749 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
750 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
751}
752
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100753/* turn on/off EAPD control (only if available) */
754static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
755{
756 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
757 return;
758 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
759 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
760 on ? 2 : 0);
761}
762
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200763/* turn on/off EAPD controls of the codec */
764static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
765{
766 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200767 static hda_nid_t pins[] = {
768 0x0f, 0x10, 0x14, 0x15, 0
769 };
770 hda_nid_t *p;
771 for (p = pins; *p; p++)
772 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200773}
774
Takashi Iwai1c716152011-04-07 10:37:16 +0200775/* generic shutup callback;
776 * just turning off EPAD and a little pause for avoiding pop-noise
777 */
778static void alc_eapd_shutup(struct hda_codec *codec)
779{
780 alc_auto_setup_eapd(codec, false);
781 msleep(200);
782}
783
Takashi Iwai1d045db2011-07-07 18:23:21 +0200784/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200785static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200786{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200787 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200788
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200789 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200790 switch (type) {
791 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200792 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
793 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200794 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200795 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
796 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200797 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200798 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
799 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200800 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200801 switch (codec->vendor_id) {
802 case 0x10ec0260:
803 snd_hda_codec_write(codec, 0x1a, 0,
804 AC_VERB_SET_COEF_INDEX, 7);
805 tmp = snd_hda_codec_read(codec, 0x1a, 0,
806 AC_VERB_GET_PROC_COEF, 0);
807 snd_hda_codec_write(codec, 0x1a, 0,
808 AC_VERB_SET_COEF_INDEX, 7);
809 snd_hda_codec_write(codec, 0x1a, 0,
810 AC_VERB_SET_PROC_COEF,
811 tmp | 0x2010);
812 break;
813 case 0x10ec0262:
814 case 0x10ec0880:
815 case 0x10ec0882:
816 case 0x10ec0883:
817 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100818 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100819 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200820 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200821 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200822 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200823 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200824 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100825#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200826 case 0x10ec0267:
827 case 0x10ec0268:
828 snd_hda_codec_write(codec, 0x20, 0,
829 AC_VERB_SET_COEF_INDEX, 7);
830 tmp = snd_hda_codec_read(codec, 0x20, 0,
831 AC_VERB_GET_PROC_COEF, 0);
832 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200833 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200834 snd_hda_codec_write(codec, 0x20, 0,
835 AC_VERB_SET_PROC_COEF,
836 tmp | 0x3000);
837 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100838#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200839 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200840 break;
841 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200842}
Kailang Yangea1fb292008-08-26 12:58:38 +0200843
Takashi Iwai1d045db2011-07-07 18:23:21 +0200844/*
845 * Auto-Mute mode mixer enum support
846 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
848 struct snd_ctl_elem_info *uinfo)
849{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200852 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100853 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200854 };
855
Takashi Iwaidda415d2012-11-30 18:34:38 +0100856 if (spec->automute_speaker_possible && spec->automute_lo_possible)
857 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
858 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200859}
860
861static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
862 struct snd_ctl_elem_value *ucontrol)
863{
864 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
865 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200866 unsigned int val = 0;
867 if (spec->automute_speaker)
868 val++;
869 if (spec->automute_lo)
870 val++;
871
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200872 ucontrol->value.enumerated.item[0] = val;
873 return 0;
874}
875
876static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
877 struct snd_ctl_elem_value *ucontrol)
878{
879 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
880 struct alc_spec *spec = codec->spec;
881
882 switch (ucontrol->value.enumerated.item[0]) {
883 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 spec->automute_speaker = 0;
887 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888 break;
889 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200890 if (spec->automute_speaker_possible) {
891 if (!spec->automute_lo && spec->automute_speaker)
892 return 0;
893 spec->automute_speaker = 1;
894 spec->automute_lo = 0;
895 } else if (spec->automute_lo_possible) {
896 if (spec->automute_lo)
897 return 0;
898 spec->automute_lo = 1;
899 } else
900 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200901 break;
902 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200903 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200904 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200905 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200906 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200907 spec->automute_speaker = 1;
908 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909 break;
910 default:
911 return -EINVAL;
912 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200913 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200914 return 1;
915}
916
Takashi Iwaia9111322011-05-02 11:30:18 +0200917static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
919 .name = "Auto-Mute Mode",
920 .info = alc_automute_mode_info,
921 .get = alc_automute_mode_get,
922 .put = alc_automute_mode_put,
923};
924
Takashi Iwai668d1e92012-11-29 14:10:17 +0100925static struct snd_kcontrol_new *
926alc_kcontrol_new(struct alc_spec *spec, const char *name,
927 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200928{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100929 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
930 if (!knew)
931 return NULL;
932 *knew = *temp;
933 knew->name = kstrdup(name, GFP_KERNEL);
934 if (!knew->name)
935 return NULL;
936 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200937}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200938
939static int alc_add_automute_mode_enum(struct hda_codec *codec)
940{
941 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200942
Takashi Iwai668d1e92012-11-29 14:10:17 +0100943 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200944 return -ENOMEM;
945 return 0;
946}
947
Takashi Iwai1d045db2011-07-07 18:23:21 +0200948/*
949 * Check the availability of HP/line-out auto-mute;
950 * Set up appropriately if really supported
951 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100952static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200953{
954 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200955 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200956 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100957 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200958
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200959 if (cfg->hp_pins[0])
960 present++;
961 if (cfg->line_out_pins[0])
962 present++;
963 if (cfg->speaker_pins[0])
964 present++;
965 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100966 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200967
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200968 if (!cfg->speaker_pins[0] &&
969 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200970 memcpy(cfg->speaker_pins, cfg->line_out_pins,
971 sizeof(cfg->speaker_pins));
972 cfg->speaker_outs = cfg->line_outs;
973 }
974
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200975 if (!cfg->hp_pins[0] &&
976 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200977 memcpy(cfg->hp_pins, cfg->line_out_pins,
978 sizeof(cfg->hp_pins));
979 cfg->hp_outs = cfg->line_outs;
980 }
981
David Henningsson42cf0d02011-09-20 12:04:56 +0200982 spec->automute_mode = ALC_AUTOMUTE_PIN;
983
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200984 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200985 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200986 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200987 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200988 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200989 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200990 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
991 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200992 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200993 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200994
David Henningsson42cf0d02011-09-20 12:04:56 +0200995 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
996 if (cfg->speaker_outs)
997 for (i = 0; i < cfg->line_outs; i++) {
998 hda_nid_t nid = cfg->line_out_pins[i];
999 if (!is_jack_detectable(codec, nid))
1000 continue;
1001 snd_printdd("realtek: Enable Line-Out "
1002 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +02001003 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
1004 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +02001005 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +02001006 }
David Henningsson42cf0d02011-09-20 12:04:56 +02001007 spec->automute_lo_possible = spec->detect_hp;
1008 }
1009
1010 spec->automute_speaker_possible = cfg->speaker_outs &&
1011 (spec->detect_hp || spec->detect_lo);
1012
1013 spec->automute_lo = spec->automute_lo_possible;
1014 spec->automute_speaker = spec->automute_speaker_possible;
1015
Takashi Iwai475c3d22012-11-30 08:31:30 +01001016 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001017 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001018 err = alc_add_automute_mode_enum(codec);
1019 if (err < 0)
1020 return err;
1021 }
1022 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001023}
1024
Takashi Iwai1d045db2011-07-07 18:23:21 +02001025/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001026static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1027{
1028 int i;
1029 for (i = 0; i < nums; i++)
1030 if (list[i] == nid)
1031 return i;
1032 return -1;
1033}
1034
Takashi Iwai1d045db2011-07-07 18:23:21 +02001035/* check whether dynamic ADC-switching is available */
1036static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1037{
1038 struct alc_spec *spec = codec->spec;
1039 struct hda_input_mux *imux = &spec->private_imux[0];
1040 int i, n, idx;
1041 hda_nid_t cap, pin;
1042
1043 if (imux != spec->input_mux) /* no dynamic imux? */
1044 return false;
1045
1046 for (n = 0; n < spec->num_adc_nids; n++) {
1047 cap = spec->private_capsrc_nids[n];
1048 for (i = 0; i < imux->num_items; i++) {
1049 pin = spec->imux_pins[i];
1050 if (!pin)
1051 return false;
1052 if (get_connection_index(codec, cap, pin) < 0)
1053 break;
1054 }
1055 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001056 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001057 }
1058
1059 for (i = 0; i < imux->num_items; i++) {
1060 pin = spec->imux_pins[i];
1061 for (n = 0; n < spec->num_adc_nids; n++) {
1062 cap = spec->private_capsrc_nids[n];
1063 idx = get_connection_index(codec, cap, pin);
1064 if (idx >= 0) {
1065 imux->items[i].index = idx;
1066 spec->dyn_adc_idx[i] = n;
1067 break;
1068 }
1069 }
1070 }
1071
1072 snd_printdd("realtek: enabling ADC switching\n");
1073 spec->dyn_adc_switch = 1;
1074 return true;
1075}
Takashi Iwai21268962011-07-07 15:01:13 +02001076
Takashi Iwai21268962011-07-07 15:01:13 +02001077/* check whether all auto-mic pins are valid; setup indices if OK */
1078static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1079{
1080 struct alc_spec *spec = codec->spec;
1081 const struct hda_input_mux *imux;
1082
1083 if (!spec->auto_mic)
1084 return false;
1085 if (spec->auto_mic_valid_imux)
1086 return true; /* already checked */
1087
1088 /* fill up imux indices */
1089 if (!alc_check_dyn_adc_switch(codec)) {
1090 spec->auto_mic = 0;
1091 return false;
1092 }
1093
1094 imux = spec->input_mux;
1095 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1098 spec->imux_pins, imux->num_items);
1099 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1100 spec->imux_pins, imux->num_items);
1101 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1102 spec->auto_mic = 0;
1103 return false; /* no corresponding imux */
1104 }
1105
David Henningsson29adc4b2012-09-25 11:31:00 +02001106 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1107 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001108 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001109 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1110 ALC_MIC_EVENT,
1111 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001112
1113 spec->auto_mic_valid_imux = 1;
1114 spec->auto_mic = 1;
1115 return true;
1116}
1117
Takashi Iwai1d045db2011-07-07 18:23:21 +02001118/*
1119 * Check the availability of auto-mic switch;
1120 * Set up if really supported
1121 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001122static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001123{
1124 struct alc_spec *spec = codec->spec;
1125 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001126 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001127 int i;
1128
Takashi Iwai24de1832011-11-07 17:13:39 +01001129 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001130 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001131
Takashi Iwai21268962011-07-07 15:01:13 +02001132 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1133
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001134 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001135 for (i = 0; i < cfg->num_inputs; i++) {
1136 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001137 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001138 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001139 switch (snd_hda_get_input_pin_attr(defcfg)) {
1140 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001141 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001142 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001143 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001144 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 fixed = nid;
1146 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001147 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001148 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001149 case INPUT_PIN_ATTR_DOCK:
1150 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001151 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001152 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001153 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001154 dock = nid;
1155 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001156 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001157 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001158 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001159 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001160 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001161 ext = nid;
1162 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001163 }
1164 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001165 if (!ext && dock) {
1166 ext = dock;
1167 dock = 0;
1168 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001169 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001170 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001171 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001172 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001173 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001174 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001175
1176 /* check imux indices */
1177 spec->ext_mic_pin = ext;
1178 spec->int_mic_pin = fixed;
1179 spec->dock_mic_pin = dock;
1180
1181 spec->auto_mic = 1;
1182 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001183 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001184
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001185 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1186 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001187
1188 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001189}
1190
Takashi Iwai1d045db2011-07-07 18:23:21 +02001191/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001192static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001193{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001194 int err;
1195
1196 err = alc_init_automute(codec);
1197 if (err < 0)
1198 return err;
1199 err = alc_init_auto_mic(codec);
1200 if (err < 0)
1201 return err;
1202 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001203}
1204
1205/*
1206 * Realtek SSID verification
1207 */
1208
David Henningsson90622912010-10-14 14:50:18 +02001209/* Could be any non-zero and even value. When used as fixup, tells
1210 * the driver to ignore any present sku defines.
1211 */
1212#define ALC_FIXUP_SKU_IGNORE (2)
1213
Takashi Iwai23d30f22012-05-07 17:17:32 +02001214static void alc_fixup_sku_ignore(struct hda_codec *codec,
1215 const struct hda_fixup *fix, int action)
1216{
1217 struct alc_spec *spec = codec->spec;
1218 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1219 spec->cdefine.fixup = 1;
1220 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1221 }
1222}
1223
Kailang Yangda00c242010-03-19 11:23:45 +01001224static int alc_auto_parse_customize_define(struct hda_codec *codec)
1225{
1226 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001227 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001228 struct alc_spec *spec = codec->spec;
1229
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001230 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1231
David Henningsson90622912010-10-14 14:50:18 +02001232 if (spec->cdefine.fixup) {
1233 ass = spec->cdefine.sku_cfg;
1234 if (ass == ALC_FIXUP_SKU_IGNORE)
1235 return -1;
1236 goto do_sku;
1237 }
1238
Kailang Yangda00c242010-03-19 11:23:45 +01001239 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001240 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001241 goto do_sku;
1242
1243 nid = 0x1d;
1244 if (codec->vendor_id == 0x10ec0260)
1245 nid = 0x17;
1246 ass = snd_hda_codec_get_pincfg(codec, nid);
1247
1248 if (!(ass & 1)) {
1249 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1250 codec->chip_name, ass);
1251 return -1;
1252 }
1253
1254 /* check sum */
1255 tmp = 0;
1256 for (i = 1; i < 16; i++) {
1257 if ((ass >> i) & 1)
1258 tmp++;
1259 }
1260 if (((ass >> 16) & 0xf) != tmp)
1261 return -1;
1262
1263 spec->cdefine.port_connectivity = ass >> 30;
1264 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1265 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1266 spec->cdefine.customization = ass >> 8;
1267do_sku:
1268 spec->cdefine.sku_cfg = ass;
1269 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1270 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1271 spec->cdefine.swap = (ass & 0x2) >> 1;
1272 spec->cdefine.override = ass & 0x1;
1273
1274 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1275 nid, spec->cdefine.sku_cfg);
1276 snd_printd("SKU: port_connectivity=0x%x\n",
1277 spec->cdefine.port_connectivity);
1278 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1279 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1280 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1281 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1282 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1283 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1284 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1285
1286 return 0;
1287}
1288
Takashi Iwai1d045db2011-07-07 18:23:21 +02001289/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001290static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1291{
Takashi Iwai21268962011-07-07 15:01:13 +02001292 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001293}
1294
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295/* check subsystem ID and set up device-specific initialization;
1296 * return 1 if initialized, 0 if invalid SSID
1297 */
1298/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1299 * 31 ~ 16 : Manufacture ID
1300 * 15 ~ 8 : SKU ID
1301 * 7 ~ 0 : Assembly ID
1302 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1303 */
1304static int alc_subsystem_id(struct hda_codec *codec,
1305 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001306 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001307{
1308 unsigned int ass, tmp, i;
1309 unsigned nid;
1310 struct alc_spec *spec = codec->spec;
1311
David Henningsson90622912010-10-14 14:50:18 +02001312 if (spec->cdefine.fixup) {
1313 ass = spec->cdefine.sku_cfg;
1314 if (ass == ALC_FIXUP_SKU_IGNORE)
1315 return 0;
1316 goto do_sku;
1317 }
1318
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001319 ass = codec->subsystem_id & 0xffff;
1320 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1321 goto do_sku;
1322
1323 /* invalid SSID, check the special NID pin defcfg instead */
1324 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001325 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001326 * 29~21 : reserve
1327 * 20 : PCBEEP input
1328 * 19~16 : Check sum (15:1)
1329 * 15~1 : Custom
1330 * 0 : override
1331 */
1332 nid = 0x1d;
1333 if (codec->vendor_id == 0x10ec0260)
1334 nid = 0x17;
1335 ass = snd_hda_codec_get_pincfg(codec, nid);
1336 snd_printd("realtek: No valid SSID, "
1337 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001338 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001339 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001340 return 0;
1341 if ((ass >> 30) != 1) /* no physical connection */
1342 return 0;
1343
1344 /* check sum */
1345 tmp = 0;
1346 for (i = 1; i < 16; i++) {
1347 if ((ass >> i) & 1)
1348 tmp++;
1349 }
1350 if (((ass >> 16) & 0xf) != tmp)
1351 return 0;
1352do_sku:
1353 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1354 ass & 0xffff, codec->vendor_id);
1355 /*
1356 * 0 : override
1357 * 1 : Swap Jack
1358 * 2 : 0 --> Desktop, 1 --> Laptop
1359 * 3~5 : External Amplifier control
1360 * 7~6 : Reserved
1361 */
1362 tmp = (ass & 0x38) >> 3; /* external Amp control */
1363 switch (tmp) {
1364 case 1:
1365 spec->init_amp = ALC_INIT_GPIO1;
1366 break;
1367 case 3:
1368 spec->init_amp = ALC_INIT_GPIO2;
1369 break;
1370 case 7:
1371 spec->init_amp = ALC_INIT_GPIO3;
1372 break;
1373 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001374 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001375 spec->init_amp = ALC_INIT_DEFAULT;
1376 break;
1377 }
1378
1379 /* is laptop or Desktop and enable the function "Mute internal speaker
1380 * when the external headphone out jack is plugged"
1381 */
1382 if (!(ass & 0x8000))
1383 return 1;
1384 /*
1385 * 10~8 : Jack location
1386 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1387 * 14~13: Resvered
1388 * 15 : 1 --> enable the function "Mute internal speaker
1389 * when the external headphone out jack is plugged"
1390 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001391 if (!spec->autocfg.hp_pins[0] &&
1392 !(spec->autocfg.line_out_pins[0] &&
1393 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001394 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001395 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1396 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001397 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001398 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001399 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001400 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001401 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001402 else if (tmp == 3)
1403 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001404 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001405 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001406 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1407 spec->autocfg.line_outs))
1408 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001409 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001410 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001411 return 1;
1412}
Kailang Yangea1fb292008-08-26 12:58:38 +02001413
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001414/* Check the validity of ALC subsystem-id
1415 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1416static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001417{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001418 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001419 struct alc_spec *spec = codec->spec;
1420 snd_printd("realtek: "
1421 "Enable default setup for auto mode as fallback\n");
1422 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001423 }
Takashi Iwai21268962011-07-07 15:01:13 +02001424}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001425
Takashi Iwai41e41f12005-06-08 14:48:49 +02001426/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001427 * COEF access helper functions
1428 */
Kailang Yang274693f2009-12-03 10:07:50 +01001429static int alc_read_coef_idx(struct hda_codec *codec,
1430 unsigned int coef_idx)
1431{
1432 unsigned int val;
1433 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1434 coef_idx);
1435 val = snd_hda_codec_read(codec, 0x20, 0,
1436 AC_VERB_GET_PROC_COEF, 0);
1437 return val;
1438}
1439
Kailang Yang977ddd62010-09-15 10:02:29 +02001440static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1441 unsigned int coef_val)
1442{
1443 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1444 coef_idx);
1445 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1446 coef_val);
1447}
1448
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001449/* a special bypass for COEF 0; read the cached value at the second time */
1450static unsigned int alc_get_coef0(struct hda_codec *codec)
1451{
1452 struct alc_spec *spec = codec->spec;
1453 if (!spec->coef0)
1454 spec->coef0 = alc_read_coef_idx(codec, 0);
1455 return spec->coef0;
1456}
1457
Takashi Iwai1d045db2011-07-07 18:23:21 +02001458/*
1459 * Digital I/O handling
1460 */
1461
Takashi Iwai757899a2010-07-30 10:48:14 +02001462/* set right pin controls for digital I/O */
1463static void alc_auto_init_digital(struct hda_codec *codec)
1464{
1465 struct alc_spec *spec = codec->spec;
1466 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001467 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001468
1469 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1470 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001471 if (!pin)
1472 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001473 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001474 if (!i)
1475 dac = spec->multiout.dig_out_nid;
1476 else
1477 dac = spec->slave_dig_outs[i - 1];
1478 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1479 continue;
1480 snd_hda_codec_write(codec, dac, 0,
1481 AC_VERB_SET_AMP_GAIN_MUTE,
1482 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001483 }
1484 pin = spec->autocfg.dig_in_pin;
1485 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001486 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001487}
1488
1489/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1490static void alc_auto_parse_digital(struct hda_codec *codec)
1491{
1492 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001493 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001494 hda_nid_t dig_nid;
1495
1496 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001497 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001498 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001499 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001500 err = snd_hda_get_connections(codec,
1501 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001502 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001503 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001504 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001505 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001506 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001507 spec->multiout.dig_out_nid = dig_nid;
1508 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1509 } else {
1510 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001511 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001512 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001513 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001514 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001515 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001516 }
1517
1518 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001519 dig_nid = codec->start_nid;
1520 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1521 unsigned int wcaps = get_wcaps(codec, dig_nid);
1522 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1523 continue;
1524 if (!(wcaps & AC_WCAP_DIGITAL))
1525 continue;
1526 if (!(wcaps & AC_WCAP_CONN_LIST))
1527 continue;
1528 err = get_connection_index(codec, dig_nid,
1529 spec->autocfg.dig_in_pin);
1530 if (err >= 0) {
1531 spec->dig_in_nid = dig_nid;
1532 break;
1533 }
1534 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001535 }
1536}
1537
Takashi Iwaif95474e2007-07-10 00:47:43 +02001538/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001539 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001540 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001541static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1542 struct snd_ctl_elem_info *uinfo)
1543{
1544 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1545 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001546 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001547 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001548
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001549 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001550 if (spec->vol_in_capsrc)
1551 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1552 else
1553 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1554 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001555 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001556 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001557 return err;
1558}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001560static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1561 unsigned int size, unsigned int __user *tlv)
1562{
1563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1564 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001565 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001566 int err;
1567
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001568 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001569 if (spec->vol_in_capsrc)
1570 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1571 else
1572 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1573 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001574 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001575 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001576 return err;
1577}
1578
1579typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1580 struct snd_ctl_elem_value *ucontrol);
1581
1582static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1583 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001584 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001585{
1586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1587 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001588 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001589
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001590 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001591 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001592 for (i = 0; i < spec->num_adc_nids; i++) {
1593 kcontrol->private_value =
1594 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1595 3, 0, HDA_INPUT);
1596 err = func(kcontrol, ucontrol);
1597 if (err < 0)
1598 goto error;
1599 }
1600 } else {
1601 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001602 if (spec->vol_in_capsrc)
1603 kcontrol->private_value =
1604 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1605 3, 0, HDA_OUTPUT);
1606 else
1607 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001608 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1609 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001610 err = func(kcontrol, ucontrol);
1611 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001612 if (err >= 0 && is_put)
1613 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001614 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001615 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001616 return err;
1617}
1618
1619static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1620 struct snd_ctl_elem_value *ucontrol)
1621{
1622 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001623 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001624}
1625
1626static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1627 struct snd_ctl_elem_value *ucontrol)
1628{
1629 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001630 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001631}
1632
1633/* capture mixer elements */
1634#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1635
1636static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1637 struct snd_ctl_elem_value *ucontrol)
1638{
1639 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001640 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001641}
1642
1643static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1644 struct snd_ctl_elem_value *ucontrol)
1645{
1646 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001647 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001648}
1649
Takashi Iwaia23b6882009-03-23 15:21:36 +01001650#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001651 { \
1652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1653 .name = "Capture Switch", \
1654 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1655 .count = num, \
1656 .info = alc_cap_sw_info, \
1657 .get = alc_cap_sw_get, \
1658 .put = alc_cap_sw_put, \
1659 }, \
1660 { \
1661 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1662 .name = "Capture Volume", \
1663 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1664 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1665 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1666 .count = num, \
1667 .info = alc_cap_vol_info, \
1668 .get = alc_cap_vol_get, \
1669 .put = alc_cap_vol_put, \
1670 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001671 }
1672
1673#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001674 { \
1675 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1676 /* .name = "Capture Source", */ \
1677 .name = "Input Source", \
1678 .count = num, \
1679 .info = alc_mux_enum_info, \
1680 .get = alc_mux_enum_get, \
1681 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001682 }
1683
1684#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001685static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001686 _DEFINE_CAPMIX(num), \
1687 _DEFINE_CAPSRC(num), \
1688 { } /* end */ \
1689}
1690
1691#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001692static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001693 _DEFINE_CAPMIX(num), \
1694 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001695}
1696
1697/* up to three ADCs */
1698DEFINE_CAPMIX(1);
1699DEFINE_CAPMIX(2);
1700DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001701DEFINE_CAPMIX_NOSRC(1);
1702DEFINE_CAPMIX_NOSRC(2);
1703DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001704
1705/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001706 * Inverted digital-mic handling
1707 *
1708 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1709 * gives the additional mute only to the right channel of the digital mic
1710 * capture stream. This is a workaround for avoiding the almost silence
1711 * by summing the stereo stream from some (known to be ForteMedia)
1712 * digital mic unit.
1713 *
1714 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1715 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1716 * without caching so that the cache can still keep the original value.
1717 * The cached value is then restored when the flag is set off or any other
1718 * than d-mic is used as the current input source.
1719 */
1720static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1721{
1722 struct alc_spec *spec = codec->spec;
1723 int i;
1724
1725 if (!spec->inv_dmic_fixup)
1726 return;
1727 if (!spec->inv_dmic_muted && !force)
1728 return;
1729 for (i = 0; i < spec->num_adc_nids; i++) {
1730 int src = spec->dyn_adc_switch ? 0 : i;
1731 bool dmic_fixup = false;
1732 hda_nid_t nid;
1733 int parm, dir, v;
1734
1735 if (spec->inv_dmic_muted &&
1736 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1737 dmic_fixup = true;
1738 if (!dmic_fixup && !force)
1739 continue;
1740 if (spec->vol_in_capsrc) {
1741 nid = spec->capsrc_nids[i];
1742 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1743 dir = HDA_OUTPUT;
1744 } else {
1745 nid = spec->adc_nids[i];
1746 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1747 dir = HDA_INPUT;
1748 }
1749 /* we care only right channel */
1750 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1751 if (v & 0x80) /* if already muted, we don't need to touch */
1752 continue;
1753 if (dmic_fixup) /* add mute for d-mic */
1754 v |= 0x80;
1755 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1756 parm | v);
1757 }
1758}
1759
1760static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1761 struct snd_ctl_elem_value *ucontrol)
1762{
1763 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1764 struct alc_spec *spec = codec->spec;
1765
1766 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1767 return 0;
1768}
1769
1770static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1771 struct snd_ctl_elem_value *ucontrol)
1772{
1773 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1774 struct alc_spec *spec = codec->spec;
1775 unsigned int val = !ucontrol->value.integer.value[0];
1776
1777 if (val == spec->inv_dmic_muted)
1778 return 0;
1779 spec->inv_dmic_muted = val;
1780 alc_inv_dmic_sync(codec, true);
1781 return 0;
1782}
1783
1784static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1786 .info = snd_ctl_boolean_mono_info,
1787 .get = alc_inv_dmic_sw_get,
1788 .put = alc_inv_dmic_sw_put,
1789};
1790
1791static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1792{
1793 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001794
1795 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1796 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001797 return -ENOMEM;
1798 spec->inv_dmic_fixup = 1;
1799 spec->inv_dmic_muted = 0;
1800 spec->inv_dmic_pin = nid;
1801 return 0;
1802}
1803
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001804/* typically the digital mic is put at node 0x12 */
1805static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1806 const struct alc_fixup *fix, int action)
1807{
1808 if (action == ALC_FIXUP_ACT_PROBE)
1809 alc_add_inv_dmic_mixer(codec, 0x12);
1810}
1811
Takashi Iwai125821a2012-06-22 14:30:29 +02001812/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001813 * virtual master controls
1814 */
1815
1816/*
1817 * slave controls for virtual master
1818 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001819static const char * const alc_slave_pfxs[] = {
1820 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001821 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001822 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001823 NULL,
1824};
1825
1826/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001827 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001829
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001830#define NID_MAPPING (-1)
1831
1832#define SUBDEV_SPEAKER_ (0 << 6)
1833#define SUBDEV_HP_ (1 << 6)
1834#define SUBDEV_LINE_ (2 << 6)
1835#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1836#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1837#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1838
Takashi Iwai603c4012008-07-30 15:01:44 +02001839static void alc_free_kctls(struct hda_codec *codec);
1840
Takashi Iwai67d634c2009-11-16 15:35:59 +01001841#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001842/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001843static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001844 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001845 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001846 { } /* end */
1847};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001848#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001849
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001850static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
1852 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001853 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001854 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001855 int i, j, err;
1856 unsigned int u;
1857 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
1859 for (i = 0; i < spec->num_mixers; i++) {
1860 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1861 if (err < 0)
1862 return err;
1863 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001864 if (spec->cap_mixer) {
1865 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1866 if (err < 0)
1867 return err;
1868 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001870 err = snd_hda_create_dig_out_ctls(codec,
1871 spec->multiout.dig_out_nid,
1872 spec->multiout.dig_out_nid,
1873 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 if (err < 0)
1875 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001876 if (!spec->no_analog) {
1877 err = snd_hda_create_spdif_share_sw(codec,
1878 &spec->multiout);
1879 if (err < 0)
1880 return err;
1881 spec->multiout.share_spdif = 1;
1882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 }
1884 if (spec->dig_in_nid) {
1885 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1886 if (err < 0)
1887 return err;
1888 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001889
Takashi Iwai67d634c2009-11-16 15:35:59 +01001890#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001891 /* create beep controls if needed */
1892 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001893 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001894 for (knew = alc_beep_mixer; knew->name; knew++) {
1895 struct snd_kcontrol *kctl;
1896 kctl = snd_ctl_new1(knew, codec);
1897 if (!kctl)
1898 return -ENOMEM;
1899 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001900 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001901 if (err < 0)
1902 return err;
1903 }
1904 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001905#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001906
Takashi Iwai2134ea42008-01-10 16:53:55 +01001907 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001908 if (!spec->no_analog &&
1909 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001910 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001911 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001912 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001913 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001914 vmaster_tlv, alc_slave_pfxs,
1915 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001916 if (err < 0)
1917 return err;
1918 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001919 if (!spec->no_analog &&
1920 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001921 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1922 NULL, alc_slave_pfxs,
1923 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001924 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001925 if (err < 0)
1926 return err;
1927 }
1928
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001929 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001930 if (spec->capsrc_nids || spec->adc_nids) {
1931 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1932 if (!kctl)
1933 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1934 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001935 err = snd_hda_add_nid(codec, kctl, i,
1936 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001937 if (err < 0)
1938 return err;
1939 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001940 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001941 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001942 const char *kname = kctl ? kctl->id.name : NULL;
1943 for (knew = spec->cap_mixer; knew->name; knew++) {
1944 if (kname && strcmp(knew->name, kname) == 0)
1945 continue;
1946 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1947 for (i = 0; kctl && i < kctl->count; i++) {
1948 err = snd_hda_add_nid(codec, kctl, i,
1949 spec->adc_nids[i]);
1950 if (err < 0)
1951 return err;
1952 }
1953 }
1954 }
1955
1956 /* other nid->control mapping */
1957 for (i = 0; i < spec->num_mixers; i++) {
1958 for (knew = spec->mixers[i]; knew->name; knew++) {
1959 if (knew->iface != NID_MAPPING)
1960 continue;
1961 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1962 if (kctl == NULL)
1963 continue;
1964 u = knew->subdevice;
1965 for (j = 0; j < 4; j++, u >>= 8) {
1966 nid = u & 0x3f;
1967 if (nid == 0)
1968 continue;
1969 switch (u & 0xc0) {
1970 case SUBDEV_SPEAKER_:
1971 nid = spec->autocfg.speaker_pins[nid];
1972 break;
1973 case SUBDEV_LINE_:
1974 nid = spec->autocfg.line_out_pins[nid];
1975 break;
1976 case SUBDEV_HP_:
1977 nid = spec->autocfg.hp_pins[nid];
1978 break;
1979 default:
1980 continue;
1981 }
1982 err = snd_hda_add_nid(codec, kctl, 0, nid);
1983 if (err < 0)
1984 return err;
1985 }
1986 u = knew->private_value;
1987 for (j = 0; j < 4; j++, u >>= 8) {
1988 nid = u & 0xff;
1989 if (nid == 0)
1990 continue;
1991 err = snd_hda_add_nid(codec, kctl, 0, nid);
1992 if (err < 0)
1993 return err;
1994 }
1995 }
1996 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001997
1998 alc_free_kctls(codec); /* no longer needed */
1999
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002000 return 0;
2001}
2002
David Henningsson5780b622012-06-27 18:45:45 +02002003static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002004{
2005 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02002006
2007 if (spec->shared_mic_hp) {
2008 int err;
2009 int nid = spec->autocfg.inputs[1].pin;
2010 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2011 if (err < 0)
2012 return err;
2013 err = snd_hda_jack_detect_enable(codec, nid, 0);
2014 if (err < 0)
2015 return err;
2016 }
2017
2018 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2019}
2020
2021static int alc_build_controls(struct hda_codec *codec)
2022{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002023 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002024 if (err < 0)
2025 return err;
David Henningsson5780b622012-06-27 18:45:45 +02002026
2027 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002028 if (err < 0)
2029 return err;
2030 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2031 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032}
2033
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002036 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002037 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002038
Takashi Iwai584c0c42011-03-10 12:51:11 +01002039static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002040static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042static int alc_init(struct hda_codec *codec)
2043{
2044 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002045
Takashi Iwai546bb672012-03-07 08:37:19 +01002046 if (spec->init_hook)
2047 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002048
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002049 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002050 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002051
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002052 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002053 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002054 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002055
Takashi Iwai58701122011-01-13 15:41:45 +01002056 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2057
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002058 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 return 0;
2060}
2061
Takashi Iwai83012a72012-08-24 18:38:08 +02002062#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002063static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2064{
2065 struct alc_spec *spec = codec->spec;
2066 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2067}
2068#endif
2069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070/*
2071 * Analog playback callbacks
2072 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002073static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002075 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
2077 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002078 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2079 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080}
2081
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002082static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 struct hda_codec *codec,
2084 unsigned int stream_tag,
2085 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002086 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
2088 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002089 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2090 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002093static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002095 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
2097 struct alc_spec *spec = codec->spec;
2098 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2099}
2100
2101/*
2102 * Digital out
2103 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002104static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002106 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 struct alc_spec *spec = codec->spec;
2109 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2110}
2111
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002112static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002113 struct hda_codec *codec,
2114 unsigned int stream_tag,
2115 unsigned int format,
2116 struct snd_pcm_substream *substream)
2117{
2118 struct alc_spec *spec = codec->spec;
2119 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2120 stream_tag, format, substream);
2121}
2122
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002123static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002124 struct hda_codec *codec,
2125 struct snd_pcm_substream *substream)
2126{
2127 struct alc_spec *spec = codec->spec;
2128 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2129}
2130
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002131static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002133 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
2135 struct alc_spec *spec = codec->spec;
2136 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2137}
2138
2139/*
2140 * Analog capture
2141 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002142static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct hda_codec *codec,
2144 unsigned int stream_tag,
2145 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002146 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147{
2148 struct alc_spec *spec = codec->spec;
2149
Takashi Iwai63300792008-01-24 15:31:36 +01002150 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 stream_tag, 0, format);
2152 return 0;
2153}
2154
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002155static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002157 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
2159 struct alc_spec *spec = codec->spec;
2160
Takashi Iwai888afa12008-03-18 09:57:50 +01002161 snd_hda_codec_cleanup_stream(codec,
2162 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 return 0;
2164}
2165
Takashi Iwai840b64c2010-07-13 22:49:01 +02002166/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002167static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002168 struct hda_codec *codec,
2169 unsigned int stream_tag,
2170 unsigned int format,
2171 struct snd_pcm_substream *substream)
2172{
2173 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002174 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002175 spec->cur_adc_stream_tag = stream_tag;
2176 spec->cur_adc_format = format;
2177 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2178 return 0;
2179}
2180
Takashi Iwai21268962011-07-07 15:01:13 +02002181static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002182 struct hda_codec *codec,
2183 struct snd_pcm_substream *substream)
2184{
2185 struct alc_spec *spec = codec->spec;
2186 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2187 spec->cur_adc = 0;
2188 return 0;
2189}
2190
Takashi Iwai21268962011-07-07 15:01:13 +02002191static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002192 .substreams = 1,
2193 .channels_min = 2,
2194 .channels_max = 2,
2195 .nid = 0, /* fill later */
2196 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002197 .prepare = dyn_adc_capture_pcm_prepare,
2198 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002199 },
2200};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
2202/*
2203 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002204static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 .substreams = 1,
2206 .channels_min = 2,
2207 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002208 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002210 .open = alc_playback_pcm_open,
2211 .prepare = alc_playback_pcm_prepare,
2212 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 },
2214};
2215
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002216static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002217 .substreams = 1,
2218 .channels_min = 2,
2219 .channels_max = 2,
2220 /* NID is set in alc_build_pcms */
2221};
2222
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002223static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002224 .substreams = 1,
2225 .channels_min = 2,
2226 .channels_max = 2,
2227 /* NID is set in alc_build_pcms */
2228};
2229
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002230static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002231 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 .channels_min = 2,
2233 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002234 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002236 .prepare = alc_alt_capture_pcm_prepare,
2237 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 },
2239};
2240
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002241static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 .substreams = 1,
2243 .channels_min = 2,
2244 .channels_max = 2,
2245 /* NID is set in alc_build_pcms */
2246 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002247 .open = alc_dig_playback_pcm_open,
2248 .close = alc_dig_playback_pcm_close,
2249 .prepare = alc_dig_playback_pcm_prepare,
2250 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 },
2252};
2253
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002254static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 .substreams = 1,
2256 .channels_min = 2,
2257 .channels_max = 2,
2258 /* NID is set in alc_build_pcms */
2259};
2260
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002261/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002262static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002263 .substreams = 0,
2264 .channels_min = 0,
2265 .channels_max = 0,
2266};
2267
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268static int alc_build_pcms(struct hda_codec *codec)
2269{
2270 struct alc_spec *spec = codec->spec;
2271 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002272 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002273 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 int i;
2275
2276 codec->num_pcms = 1;
2277 codec->pcm_info = info;
2278
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002279 if (spec->no_analog)
2280 goto skip_analog;
2281
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002282 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2283 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002285
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002286 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002287 p = spec->stream_analog_playback;
2288 if (!p)
2289 p = &alc_pcm_analog_playback;
2290 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002291 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002292 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2293 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002294 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2295 spec->autocfg.line_outs == 2)
2296 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2297 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002298 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002299 if (spec->adc_nids) {
2300 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002301 if (!p) {
2302 if (spec->dyn_adc_switch)
2303 p = &dyn_adc_pcm_analog_capture;
2304 else
2305 p = &alc_pcm_analog_capture;
2306 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002307 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002308 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
Takashi Iwai4a471b72005-12-07 13:56:29 +01002311 if (spec->channel_mode) {
2312 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2313 for (i = 0; i < spec->num_channel_mode; i++) {
2314 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2315 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 }
2318 }
2319
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002320 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002321 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002323 snprintf(spec->stream_name_digital,
2324 sizeof(spec->stream_name_digital),
2325 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002326 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002327 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002328 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002330 if (spec->dig_out_type)
2331 info->pcm_type = spec->dig_out_type;
2332 else
2333 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002334 if (spec->multiout.dig_out_nid) {
2335 p = spec->stream_digital_playback;
2336 if (!p)
2337 p = &alc_pcm_digital_playback;
2338 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2340 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002341 if (spec->dig_in_nid) {
2342 p = spec->stream_digital_capture;
2343 if (!p)
2344 p = &alc_pcm_digital_capture;
2345 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2347 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002348 /* FIXME: do we need this for all Realtek codec models? */
2349 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 }
2351
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002352 if (spec->no_analog)
2353 return 0;
2354
Takashi Iwaie08a0072006-09-07 17:52:14 +02002355 /* If the use of more than one ADC is requested for the current
2356 * model, configure a second analog capture-only PCM.
2357 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002358 have_multi_adcs = (spec->num_adc_nids > 1) &&
2359 !spec->dyn_adc_switch && !spec->auto_mic &&
2360 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002361 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002362 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002363 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002364 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002365 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002366 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002367 p = spec->stream_analog_alt_playback;
2368 if (!p)
2369 p = &alc_pcm_analog_alt_playback;
2370 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002371 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2372 spec->alt_dac_nid;
2373 } else {
2374 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2375 alc_pcm_null_stream;
2376 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2377 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002378 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002379 p = spec->stream_analog_alt_capture;
2380 if (!p)
2381 p = &alc_pcm_analog_alt_capture;
2382 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002383 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2384 spec->adc_nids[1];
2385 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2386 spec->num_adc_nids - 1;
2387 } else {
2388 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2389 alc_pcm_null_stream;
2390 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002391 }
2392 }
2393
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 return 0;
2395}
2396
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002397static inline void alc_shutup(struct hda_codec *codec)
2398{
Takashi Iwai1c716152011-04-07 10:37:16 +02002399 struct alc_spec *spec = codec->spec;
2400
2401 if (spec && spec->shutup)
2402 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002403 snd_hda_shutup_pins(codec);
2404}
2405
Takashi Iwai603c4012008-07-30 15:01:44 +02002406static void alc_free_kctls(struct hda_codec *codec)
2407{
2408 struct alc_spec *spec = codec->spec;
2409
2410 if (spec->kctls.list) {
2411 struct snd_kcontrol_new *kctl = spec->kctls.list;
2412 int i;
2413 for (i = 0; i < spec->kctls.used; i++)
2414 kfree(kctl[i].name);
2415 }
2416 snd_array_free(&spec->kctls);
2417}
2418
Takashi Iwai23c09b02011-08-19 09:05:35 +02002419static void alc_free_bind_ctls(struct hda_codec *codec)
2420{
2421 struct alc_spec *spec = codec->spec;
2422 if (spec->bind_ctls.list) {
2423 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2424 int i;
2425 for (i = 0; i < spec->bind_ctls.used; i++)
2426 kfree(ctl[i]);
2427 }
2428 snd_array_free(&spec->bind_ctls);
2429}
2430
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431static void alc_free(struct hda_codec *codec)
2432{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002433 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002434
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002435 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002436 return;
2437
Takashi Iwai603c4012008-07-30 15:01:44 +02002438 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002439 alc_free_bind_ctls(codec);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002440 snd_array_free(&spec->out_path);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002441 snd_array_free(&spec->in_path);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002442 snd_array_free(&spec->loopback_path);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002443 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002444 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002445 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446}
2447
Takashi Iwai83012a72012-08-24 18:38:08 +02002448#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002449static void alc_power_eapd(struct hda_codec *codec)
2450{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002451 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002452}
2453
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002454static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002455{
2456 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002457 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002458 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002459 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002460 return 0;
2461}
2462#endif
2463
Takashi Iwai2a439522011-07-26 09:52:50 +02002464#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002465static int alc_resume(struct hda_codec *codec)
2466{
Takashi Iwai1c716152011-04-07 10:37:16 +02002467 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002468 codec->patch_ops.init(codec);
2469 snd_hda_codec_resume_amp(codec);
2470 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002471 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002472 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002473 return 0;
2474}
Takashi Iwaie044c392008-10-27 16:56:24 +01002475#endif
2476
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477/*
2478 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002479static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 .build_controls = alc_build_controls,
2481 .build_pcms = alc_build_pcms,
2482 .init = alc_init,
2483 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002484 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002485#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002486 .resume = alc_resume,
2487#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002488#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002489 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002490 .check_power_status = alc_check_power_status,
2491#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002492 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493};
2494
David Henningsson29adc4b2012-09-25 11:31:00 +02002495
Kailang Yangc027ddc2010-03-19 11:33:06 +01002496/* replace the codec chip_name with the given string */
2497static int alc_codec_rename(struct hda_codec *codec, const char *name)
2498{
2499 kfree(codec->chip_name);
2500 codec->chip_name = kstrdup(name, GFP_KERNEL);
2501 if (!codec->chip_name) {
2502 alc_free(codec);
2503 return -ENOMEM;
2504 }
2505 return 0;
2506}
2507
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002508/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002509 * Rename codecs appropriately from COEF value
2510 */
2511struct alc_codec_rename_table {
2512 unsigned int vendor_id;
2513 unsigned short coef_mask;
2514 unsigned short coef_bits;
2515 const char *name;
2516};
2517
2518static struct alc_codec_rename_table rename_tbl[] = {
2519 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2520 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2521 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2522 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2523 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2524 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2525 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002526 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002527 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2528 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2529 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2530 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2531 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2532 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2533 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2534 { } /* terminator */
2535};
2536
2537static int alc_codec_rename_from_preset(struct hda_codec *codec)
2538{
2539 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002540
2541 for (p = rename_tbl; p->vendor_id; p++) {
2542 if (p->vendor_id != codec->vendor_id)
2543 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002544 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002545 return alc_codec_rename(codec, p->name);
2546 }
2547 return 0;
2548}
2549
2550/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002551 * Automatic parse of I/O pins from the BIOS configuration
2552 */
2553
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002554enum {
2555 ALC_CTL_WIDGET_VOL,
2556 ALC_CTL_WIDGET_MUTE,
2557 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002558 ALC_CTL_BIND_VOL,
2559 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002560};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002561static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002562 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2563 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002564 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002565 HDA_BIND_VOL(NULL, 0),
2566 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002567};
2568
2569/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002570static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002571 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002572{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002573 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574
Takashi Iwai668d1e92012-11-29 14:10:17 +01002575 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002576 if (!knew)
2577 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002578 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002579 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002580 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002581 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002582 return 0;
2583}
2584
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002585static int add_control_with_pfx(struct alc_spec *spec, int type,
2586 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002587 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002588{
2589 char name[32];
2590 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002591 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002592}
2593
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002594#define add_pb_vol_ctrl(spec, type, pfx, val) \
2595 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2596#define add_pb_sw_ctrl(spec, type, pfx, val) \
2597 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2598#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2599 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2600#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2601 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002602
Takashi Iwai23c09b02011-08-19 09:05:35 +02002603static const char * const channel_name[4] = {
2604 "Front", "Surround", "CLFE", "Side"
2605};
2606
Takashi Iwai6843ca12011-06-24 11:03:58 +02002607static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2608 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002609{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002610 struct auto_pin_cfg *cfg = &spec->autocfg;
2611
Takashi Iwai6843ca12011-06-24 11:03:58 +02002612 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002613 if (cfg->line_outs == 1 && !spec->multi_ios &&
2614 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002615 return "Master";
2616
2617 switch (cfg->line_out_type) {
2618 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002619 if (cfg->line_outs == 1)
2620 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002621 if (cfg->line_outs == 2)
2622 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002623 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002624 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002625 /* for multi-io case, only the primary out */
2626 if (ch && spec->multi_ios)
2627 break;
2628 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002629 return "Headphone";
2630 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002631 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002632 return "PCM";
2633 break;
2634 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002635 if (ch >= ARRAY_SIZE(channel_name)) {
2636 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002637 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002638 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002639
2640 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002641}
2642
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002643static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2644 hda_nid_t to_nid, int with_aa_mix,
2645 struct nid_path *path);
2646
Takashi Iwai83012a72012-08-24 18:38:08 +02002647#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002648/* add the powersave loopback-list entry */
2649static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2650{
2651 struct hda_amp_list *list;
2652
2653 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2654 return;
2655 list = spec->loopback_list + spec->num_loopbacks;
2656 list->nid = mix;
2657 list->dir = HDA_INPUT;
2658 list->idx = idx;
2659 spec->num_loopbacks++;
2660 spec->loopback.amplist = spec->loopback_list;
2661}
2662#else
2663#define add_loopback_list(spec, mix, idx) /* NOP */
2664#endif
2665
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002666/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002667static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002668 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002669 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002670{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002671 struct alc_spec *spec = codec->spec;
2672 struct nid_path *path;
2673 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002674
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002675 path = snd_array_new(&spec->loopback_path);
2676 if (!path)
2677 return -ENOMEM;
2678 memset(path, 0, sizeof(*path));
2679 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2680 return -EINVAL;
2681
2682 idx = path->idx[path->depth - 1];
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002683 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002684 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2685 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002686 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002687 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002688 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2689 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002690 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002691 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002692 return 0;
2693}
2694
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002695static int new_capture_source(struct hda_codec *codec, int adc_idx,
2696 hda_nid_t pin, int idx, const char *label)
2697{
2698 struct alc_spec *spec = codec->spec;
2699 struct hda_input_mux *imux = &spec->private_imux[0];
2700 struct nid_path *path;
2701
2702 path = snd_array_new(&spec->in_path);
2703 if (!path)
2704 return -ENOMEM;
2705 memset(path, 0, sizeof(*path));
2706 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2707 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2708 pin, spec->adc_nids[adc_idx]);
2709 return -EINVAL;
2710 }
2711
2712 spec->imux_pins[imux->num_items] = pin;
2713 snd_hda_add_imux_item(imux, label, idx, NULL);
2714 return 0;
2715}
2716
Takashi Iwai05f5f472009-08-25 13:10:18 +02002717static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002718{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002719 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2720 return (pincap & AC_PINCAP_IN) != 0;
2721}
2722
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002723/* check whether the given two widgets can be connected */
2724static bool is_reachable_path(struct hda_codec *codec,
2725 hda_nid_t from_nid, hda_nid_t to_nid)
2726{
2727 if (!from_nid || !to_nid)
2728 return false;
2729 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2730}
2731
Takashi Iwai1d045db2011-07-07 18:23:21 +02002732/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002733static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002734{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002735 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002736 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002737 hda_nid_t *adc_nids = spec->private_adc_nids;
2738 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2739 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002740 int i, nums = 0;
2741
2742 nid = codec->start_nid;
2743 for (i = 0; i < codec->num_nodes; i++, nid++) {
2744 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002745 unsigned int caps = get_wcaps(codec, nid);
2746 int type = get_wcaps_type(caps);
2747
2748 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2749 continue;
2750 adc_nids[nums] = nid;
2751 cap_nids[nums] = nid;
2752 src = nid;
2753 for (;;) {
2754 int n;
2755 type = get_wcaps_type(get_wcaps(codec, src));
2756 if (type == AC_WID_PIN)
2757 break;
2758 if (type == AC_WID_AUD_SEL) {
2759 cap_nids[nums] = src;
2760 break;
2761 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002762 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002763 if (n > 1) {
2764 cap_nids[nums] = src;
2765 break;
2766 } else if (n != 1)
2767 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002768 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2769 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002770 }
2771 if (++nums >= max_nums)
2772 break;
2773 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002774 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002775 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002776 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002777 return nums;
2778}
2779
Takashi Iwai05f5f472009-08-25 13:10:18 +02002780/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002781static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002782{
2783 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002784 const struct auto_pin_cfg *cfg = &spec->autocfg;
2785 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002786 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002787 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002788 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002789 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002790
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002791 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002792 if (num_adcs < 0)
2793 return 0;
2794
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002795 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002796 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002797 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002798
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002799 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002800 if (!alc_is_input_pin(codec, pin))
2801 continue;
2802
David Henningsson5322bf22011-01-05 11:03:56 +01002803 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002804 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2805 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002806 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002807 type_idx++;
2808 else
2809 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002810 prev_label = label;
2811
Takashi Iwai05f5f472009-08-25 13:10:18 +02002812 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002813 if (is_reachable_path(codec, pin, mixer)) {
2814 err = new_analog_input(codec, pin,
2815 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002816 if (err < 0)
2817 return err;
2818 }
2819 }
2820
Takashi Iwaib7821702011-07-06 15:12:46 +02002821 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002822 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002823 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002824 if (idx >= 0) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002825 err = new_capture_source(codec, c, pin, idx, label);
2826 if (err < 0)
2827 return err;
Takashi Iwaib7821702011-07-06 15:12:46 +02002828 break;
2829 }
2830 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002831 }
Takashi Iwai21268962011-07-07 15:01:13 +02002832
2833 spec->num_mux_defs = 1;
2834 spec->input_mux = imux;
2835
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002836 return 0;
2837}
2838
Takashi Iwai24de1832011-11-07 17:13:39 +01002839/* create a shared input with the headphone out */
2840static int alc_auto_create_shared_input(struct hda_codec *codec)
2841{
2842 struct alc_spec *spec = codec->spec;
2843 struct auto_pin_cfg *cfg = &spec->autocfg;
2844 unsigned int defcfg;
2845 hda_nid_t nid;
2846
2847 /* only one internal input pin? */
2848 if (cfg->num_inputs != 1)
2849 return 0;
2850 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2851 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2852 return 0;
2853
2854 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2855 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2856 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2857 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2858 else
2859 return 0; /* both not available */
2860
2861 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2862 return 0; /* no input */
2863
2864 cfg->inputs[1].pin = nid;
2865 cfg->inputs[1].type = AUTO_PIN_MIC;
2866 cfg->num_inputs = 2;
2867 spec->shared_mic_hp = 1;
2868 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2869 return 0;
2870}
2871
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002872static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2873 unsigned int pin_type)
2874{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002875 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002876 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002877 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2878 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002879 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002880}
2881
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002882static int get_pin_type(int line_out_type)
2883{
2884 if (line_out_type == AUTO_PIN_HP_OUT)
2885 return PIN_HP;
2886 else
2887 return PIN_OUT;
2888}
2889
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002890static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002891{
2892 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002893 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002894 int i;
2895
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002896 for (i = 0; i < cfg->num_inputs; i++) {
2897 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002898 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002899 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002900 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002901 snd_hda_codec_write(codec, nid, 0,
2902 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002903 AMP_OUT_MUTE);
2904 }
2905 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002906
2907 /* mute all loopback inputs */
2908 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002909 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002910 for (i = 0; i < nums; i++)
2911 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2912 AC_VERB_SET_AMP_GAIN_MUTE,
2913 AMP_IN_MUTE(i));
2914 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002915}
2916
Takashi Iwai185d99f2012-02-16 18:39:45 +01002917static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2918{
2919 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002920 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002921
2922 for (i = 0; i < spec->out_path.used; i++) {
2923 struct nid_path *path = snd_array_elem(&spec->out_path, i);
2924 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002925 return true;
2926 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002927 return false;
2928}
2929
Takashi Iwai07b18f62011-11-10 15:42:54 +01002930/* check whether the DAC is reachable from the pin */
2931static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2932 hda_nid_t pin, hda_nid_t dac)
2933{
Takashi Iwaidc31b582012-02-17 17:27:53 +01002934 if (!pin || !dac)
2935 return false;
Takashi Iwai6a84c302012-12-05 14:08:45 +01002936 return snd_hda_get_conn_index(codec, pin, dac, true) >= 0;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002937}
2938
Takashi Iwai463419d2012-12-05 14:17:37 +01002939/* look for an empty DAC slot */
2940static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2941{
2942 struct alc_spec *spec = codec->spec;
2943 int i;
2944
2945 for (i = 0; i < spec->num_all_dacs; i++) {
2946 hda_nid_t nid = spec->all_dacs[i];
2947 if (!nid || alc_is_dac_already_used(codec, nid))
2948 continue;
2949 if (alc_auto_is_dac_reachable(codec, pin, nid))
2950 return nid;
2951 }
2952 return 0;
2953}
2954
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002955/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002956static bool __parse_nid_path(struct hda_codec *codec,
2957 hda_nid_t from_nid, hda_nid_t to_nid,
2958 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002959{
2960 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002961 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002962 int i, nums;
2963
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002964 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002965 if (!with_aa_mix)
2966 return false;
2967 with_aa_mix = 2; /* mark aa-mix is included */
2968 }
2969
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002970 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002971 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002972 if (conn[i] != from_nid) {
2973 /* special case: when from_nid is 0,
2974 * try to find an empty DAC
2975 */
2976 if (from_nid ||
2977 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2978 alc_is_dac_already_used(codec, conn[i]))
2979 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002980 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002981 /* aa-mix is requested but not included? */
2982 if (!(spec->mixer_nid && with_aa_mix == 1))
2983 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002984 }
2985 if (depth >= MAX_NID_PATH_DEPTH)
2986 return false;
2987 for (i = 0; i < nums; i++) {
2988 unsigned int type;
2989 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002990 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2991 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002992 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002993 if (__parse_nid_path(codec, from_nid, conn[i],
2994 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002995 goto found;
2996 }
2997 return false;
2998
2999 found:
3000 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01003001 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003002 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01003003 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003004 path->depth++;
3005 return true;
3006}
3007
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003008/* parse the widget path from the given nid to the target nid;
3009 * when @from_nid is 0, try to find an empty DAC;
3010 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
3011 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
3012 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003013 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003014static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
3015 hda_nid_t to_nid, int with_aa_mix,
3016 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003017{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003018 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
3019 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003020 path->depth++;
3021#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003022 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003023 path->depth, path->path[0], path->path[1],
3024 path->path[2], path->path[3], path->path[4]);
3025#endif
3026 return true;
3027 }
3028 return false;
3029}
3030
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003031static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3032{
Takashi Iwai140547e2012-02-16 17:23:46 +01003033 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01003034 int i;
3035 hda_nid_t nid_found = 0;
3036
3037 for (i = 0; i < spec->num_all_dacs; i++) {
3038 hda_nid_t nid = spec->all_dacs[i];
3039 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003040 continue;
Takashi Iwai463419d2012-12-05 14:17:37 +01003041 if (alc_auto_is_dac_reachable(codec, pin, nid)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003042 if (nid_found)
3043 return 0;
3044 nid_found = nid;
3045 }
3046 }
3047 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003048}
3049
Takashi Iwaiba8111272012-12-06 18:06:23 +01003050static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003051{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003052 struct alc_spec *spec = codec->spec;
3053 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003054
Takashi Iwaiba8111272012-12-06 18:06:23 +01003055 for (i = 0; i < spec->out_path.used; i++) {
3056 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3057 if (path->ctls[type] == val)
3058 return true;
3059 }
3060 return false;
3061}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003062
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003063/* badness definition */
3064enum {
3065 /* No primary DAC is found for the main output */
3066 BAD_NO_PRIMARY_DAC = 0x10000,
3067 /* No DAC is found for the extra output */
3068 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003069 /* No possible multi-ios */
3070 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003071 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003072 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003074 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003075 /* Primary DAC shared with main surrounds */
3076 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003077 /* Primary DAC shared with main CLFE */
3078 BAD_SHARED_CLFE = 0x10,
3079 /* Primary DAC shared with extra surrounds */
3080 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003081 /* Volume widget is shared */
3082 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003083};
3084
3085static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003086 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003087static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003088 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003089
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003090static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3091 hda_nid_t dac)
3092{
3093 struct alc_spec *spec = codec->spec;
3094 struct nid_path *path;
3095
3096 path = snd_array_new(&spec->out_path);
3097 if (!path)
3098 return false;
3099 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003100 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003101 return true;
3102 /* push back */
3103 spec->out_path.used--;
3104 return false;
3105}
3106
Takashi Iwaiba8111272012-12-06 18:06:23 +01003107/* get the path pointing from the given dac to pin;
3108 * passing 0 to either @pin or @dac behaves as a wildcard
3109 */
3110static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3111 hda_nid_t dac)
3112{
3113 struct alc_spec *spec = codec->spec;
3114 int i;
3115
3116 for (i = 0; i < spec->out_path.used; i++) {
3117 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3118 if (path->depth <= 0)
3119 continue;
3120 if ((!dac || path->path[0] == dac) &&
3121 (!pin || path->path[path->depth - 1] == pin))
3122 return path;
3123 }
3124 return NULL;
3125}
3126
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003127/* look for widgets in the path between the given NIDs appropriate for
3128 * volume and mute controls, and assign the values to ctls[].
3129 *
3130 * When no appropriate widget is found in the path, the badness value
3131 * is incremented depending on the situation. The function returns the
3132 * total badness for both volume and mute controls.
3133 */
3134static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3135 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003136{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003137 struct nid_path *path = get_out_path(codec, pin, dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003138 hda_nid_t nid;
3139 unsigned int val;
3140 int badness = 0;
3141
Takashi Iwaiba8111272012-12-06 18:06:23 +01003142 if (!path)
3143 return BAD_SHARED_VOL * 2;
3144 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003145 if (nid) {
3146 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003147 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003148 badness += BAD_SHARED_VOL;
3149 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003150 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003151 } else
3152 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003153 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003154 if (nid) {
3155 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003156 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3157 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003158 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3159 else
3160 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003161 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003162 badness += BAD_SHARED_VOL;
3163 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003164 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003165 } else
3166 badness += BAD_SHARED_VOL;
3167 return badness;
3168}
3169
Takashi Iwaidc31b582012-02-17 17:27:53 +01003170struct badness_table {
3171 int no_primary_dac; /* no primary DAC */
3172 int no_dac; /* no secondary DACs */
3173 int shared_primary; /* primary DAC is shared with main output */
3174 int shared_surr; /* secondary DAC shared with main or primary */
3175 int shared_clfe; /* third DAC shared with main or primary */
3176 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3177};
3178
3179static struct badness_table main_out_badness = {
3180 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3181 .no_dac = BAD_NO_DAC,
3182 .shared_primary = BAD_NO_PRIMARY_DAC,
3183 .shared_surr = BAD_SHARED_SURROUND,
3184 .shared_clfe = BAD_SHARED_CLFE,
3185 .shared_surr_main = BAD_SHARED_SURROUND,
3186};
3187
3188static struct badness_table extra_out_badness = {
3189 .no_primary_dac = BAD_NO_DAC,
3190 .no_dac = BAD_NO_DAC,
3191 .shared_primary = BAD_NO_EXTRA_DAC,
3192 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3193 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3194 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3195};
3196
3197/* try to assign DACs to pins and return the resultant badness */
3198static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3199 const hda_nid_t *pins, hda_nid_t *dacs,
3200 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003201{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003202 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003203 struct auto_pin_cfg *cfg = &spec->autocfg;
3204 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003205 int badness = 0;
3206 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003207
Takashi Iwai185d99f2012-02-16 18:39:45 +01003208 if (!num_outs)
3209 return 0;
3210
Takashi Iwaidc31b582012-02-17 17:27:53 +01003211 for (i = 0; i < num_outs; i++) {
3212 hda_nid_t pin = pins[i];
3213 if (!dacs[i])
3214 dacs[i] = alc_auto_look_for_dac(codec, pin);
3215 if (!dacs[i] && !i) {
3216 for (j = 1; j < num_outs; j++) {
3217 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3218 dacs[0] = dacs[j];
3219 dacs[j] = 0;
3220 break;
3221 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003222 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003223 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003224 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003225 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003226 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003227 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003228 else if (cfg->line_outs > i &&
3229 alc_auto_is_dac_reachable(codec, pin,
3230 spec->private_dac_nids[i]))
3231 dac = spec->private_dac_nids[i];
3232 if (dac) {
3233 if (!i)
3234 badness += bad->shared_primary;
3235 else if (i == 1)
3236 badness += bad->shared_surr;
3237 else
3238 badness += bad->shared_clfe;
3239 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003240 spec->private_dac_nids[0])) {
3241 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003242 badness += bad->shared_surr_main;
3243 } else if (!i)
3244 badness += bad->no_primary_dac;
3245 else
3246 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003247 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003248 if (!add_new_out_path(codec, pin, dac))
3249 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003250 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003251 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003252 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003253
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003254 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003255}
3256
3257static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003258 hda_nid_t reference_pin,
3259 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003260
Takashi Iwai185d99f2012-02-16 18:39:45 +01003261static bool alc_map_singles(struct hda_codec *codec, int outs,
3262 const hda_nid_t *pins, hda_nid_t *dacs)
3263{
3264 int i;
3265 bool found = false;
3266 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003267 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003268 if (dacs[i])
3269 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003270 dac = get_dac_if_single(codec, pins[i]);
3271 if (!dac)
3272 continue;
3273 if (add_new_out_path(codec, pins[i], dac)) {
3274 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003275 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003276 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003277 }
3278 return found;
3279}
3280
Takashi Iwai7085ec12009-10-02 09:03:58 +02003281/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003282static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003283 bool fill_hardwired,
3284 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003285{
3286 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003287 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003288 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003289
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003290 /* set num_dacs once to full for alc_auto_look_for_dac() */
3291 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003292 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003293 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3294 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3295 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003296 spec->multi_ios = 0;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003297 snd_array_free(&spec->out_path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003298 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003299
3300 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003301 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003302 bool mapped;
3303 do {
3304 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003305 cfg->line_out_pins,
3306 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003307 mapped |= alc_map_singles(codec, cfg->hp_outs,
3308 cfg->hp_pins,
3309 spec->multiout.hp_out_nid);
3310 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3311 cfg->speaker_pins,
3312 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003313 if (fill_mio_first && cfg->line_outs == 1 &&
3314 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3315 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3316 if (!err)
3317 mapped = true;
3318 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003319 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003320 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003321
Takashi Iwaidc31b582012-02-17 17:27:53 +01003322 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3323 spec->private_dac_nids,
3324 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003325
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003326 /* re-count num_dacs and squash invalid entries */
3327 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003328 for (i = 0; i < cfg->line_outs; i++) {
3329 if (spec->private_dac_nids[i])
3330 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003331 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003332 memmove(spec->private_dac_nids + i,
3333 spec->private_dac_nids + i + 1,
3334 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003335 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3336 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003337 }
3338
Takashi Iwai276dd702012-02-17 16:17:03 +01003339 if (fill_mio_first &&
3340 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003341 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003342 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003343 if (err < 0)
3344 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003345 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003346 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003347
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003348 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003349 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3350 spec->multiout.hp_out_nid,
3351 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003352 if (err < 0)
3353 return err;
3354 badness += err;
3355 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003356 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003357 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3358 cfg->speaker_pins,
3359 spec->multiout.extra_out_nid,
3360 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003361 if (err < 0)
3362 return err;
3363 badness += err;
3364 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003365 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3366 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003367 if (err < 0)
3368 return err;
3369 badness += err;
3370 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003371 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3372 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003373 int offset = 0;
3374 if (cfg->line_outs >= 3)
3375 offset = 1;
3376 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3377 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003378 if (err < 0)
3379 return err;
3380 badness += err;
3381 }
3382
3383 if (spec->multi_ios == 2) {
3384 for (i = 0; i < 2; i++)
3385 spec->private_dac_nids[spec->multiout.num_dacs++] =
3386 spec->multi_io[i].dac;
3387 spec->ext_channel_count = 2;
3388 } else if (spec->multi_ios) {
3389 spec->multi_ios = 0;
3390 badness += BAD_MULTI_IO;
3391 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003392
3393 return badness;
3394}
3395
3396#define DEBUG_BADNESS
3397
3398#ifdef DEBUG_BADNESS
3399#define debug_badness snd_printdd
3400#else
3401#define debug_badness(...)
3402#endif
3403
3404static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3405{
3406 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3407 cfg->line_out_pins[0], cfg->line_out_pins[1],
3408 cfg->line_out_pins[2], cfg->line_out_pins[2],
3409 spec->multiout.dac_nids[0],
3410 spec->multiout.dac_nids[1],
3411 spec->multiout.dac_nids[2],
3412 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003413 if (spec->multi_ios > 0)
3414 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3415 spec->multi_ios,
3416 spec->multi_io[0].pin, spec->multi_io[1].pin,
3417 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003418 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3419 cfg->hp_pins[0], cfg->hp_pins[1],
3420 cfg->hp_pins[2], cfg->hp_pins[2],
3421 spec->multiout.hp_out_nid[0],
3422 spec->multiout.hp_out_nid[1],
3423 spec->multiout.hp_out_nid[2],
3424 spec->multiout.hp_out_nid[3]);
3425 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3426 cfg->speaker_pins[0], cfg->speaker_pins[1],
3427 cfg->speaker_pins[2], cfg->speaker_pins[3],
3428 spec->multiout.extra_out_nid[0],
3429 spec->multiout.extra_out_nid[1],
3430 spec->multiout.extra_out_nid[2],
3431 spec->multiout.extra_out_nid[3]);
3432}
3433
Takashi Iwai463419d2012-12-05 14:17:37 +01003434/* find all available DACs of the codec */
3435static void alc_fill_all_nids(struct hda_codec *codec)
3436{
3437 struct alc_spec *spec = codec->spec;
3438 int i;
3439 hda_nid_t nid = codec->start_nid;
3440
3441 spec->num_all_dacs = 0;
3442 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3443 for (i = 0; i < codec->num_nodes; i++, nid++) {
3444 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3445 continue;
3446 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3447 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3448 break;
3449 }
3450 spec->all_dacs[spec->num_all_dacs++] = nid;
3451 }
3452}
3453
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003454static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3455{
3456 struct alc_spec *spec = codec->spec;
3457 struct auto_pin_cfg *cfg = &spec->autocfg;
3458 struct auto_pin_cfg *best_cfg;
3459 int best_badness = INT_MAX;
3460 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003461 bool fill_hardwired = true, fill_mio_first = true;
3462 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003463 bool hp_spk_swapped = false;
3464
Takashi Iwai463419d2012-12-05 14:17:37 +01003465 alc_fill_all_nids(codec);
3466
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003467 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3468 if (!best_cfg)
3469 return -ENOMEM;
3470 *best_cfg = *cfg;
3471
3472 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003473 badness = fill_and_eval_dacs(codec, fill_hardwired,
3474 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003475 if (badness < 0) {
3476 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003477 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003478 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003479 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3480 cfg->line_out_type, fill_hardwired, fill_mio_first,
3481 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003482 debug_show_configs(spec, cfg);
3483 if (badness < best_badness) {
3484 best_badness = badness;
3485 *best_cfg = *cfg;
3486 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003487 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003488 }
3489 if (!badness)
3490 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003491 fill_mio_first = !fill_mio_first;
3492 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003493 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003494 fill_hardwired = !fill_hardwired;
3495 if (!fill_hardwired)
3496 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003497 if (hp_spk_swapped)
3498 break;
3499 hp_spk_swapped = true;
3500 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003501 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3502 cfg->hp_outs = cfg->line_outs;
3503 memcpy(cfg->hp_pins, cfg->line_out_pins,
3504 sizeof(cfg->hp_pins));
3505 cfg->line_outs = cfg->speaker_outs;
3506 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3507 sizeof(cfg->speaker_pins));
3508 cfg->speaker_outs = 0;
3509 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3510 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003511 fill_hardwired = true;
3512 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003513 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003514 if (cfg->hp_outs > 0 &&
3515 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3516 cfg->speaker_outs = cfg->line_outs;
3517 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3518 sizeof(cfg->speaker_pins));
3519 cfg->line_outs = cfg->hp_outs;
3520 memcpy(cfg->line_out_pins, cfg->hp_pins,
3521 sizeof(cfg->hp_pins));
3522 cfg->hp_outs = 0;
3523 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3524 cfg->line_out_type = AUTO_PIN_HP_OUT;
3525 fill_hardwired = true;
3526 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003527 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003528 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003529 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003530
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003531 if (badness) {
3532 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003533 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003534 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003535 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3536 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003537 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003538
Takashi Iwaiba8111272012-12-06 18:06:23 +01003539 if (cfg->line_out_pins[0]) {
3540 struct nid_path *path = get_out_path(codec,
3541 cfg->line_out_pins[0],
3542 spec->multiout.dac_nids[0]);
3543 if (path)
3544 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3545 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003546
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003547 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003548 return 0;
3549}
3550
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003551/* replace the channels in the composed amp value with the given number */
3552static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3553{
3554 val &= ~(0x3U << 16);
3555 val |= chs << 16;
3556 return val;
3557}
3558
Takashi Iwai343a04b2011-07-06 14:28:39 +02003559static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003560 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003561 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003562 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003563{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003564 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003565 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003566 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003567 val = path->ctls[NID_PATH_VOL_CTL];
3568 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003569 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003570 val = amp_val_replace_channels(val, chs);
3571 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3572}
3573
3574/* return the channel bits suitable for the given path->ctls[] */
3575static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3576 int type)
3577{
3578 int chs = 1; /* mono (left only) */
3579 if (path) {
3580 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3581 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3582 chs = 3; /* stereo */
3583 }
3584 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003585}
3586
Takashi Iwaie29d3772011-11-14 17:13:23 +01003587static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3588 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003589 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003590{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003591 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3592 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003593}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003594
3595/* create a mute-switch for the given mixer widget;
3596 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3597 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003598static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003599 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003600 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003601 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003602{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003603 unsigned int val;
3604 int type = ALC_CTL_WIDGET_MUTE;
3605
3606 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003607 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003608 val = path->ctls[NID_PATH_MUTE_CTL];
3609 if (!val)
3610 return 0;
3611 val = amp_val_replace_channels(val, chs);
3612 if (get_amp_direction_(val) == HDA_INPUT) {
3613 hda_nid_t nid = get_amp_nid_(val);
3614 if (snd_hda_get_num_conns(codec, nid) > 1) {
3615 type = ALC_CTL_BIND_MUTE;
3616 val |= 2 << 19; /* FIXME: fixed two widgets, so far */
3617 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003618 }
3619 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003620}
3621
Takashi Iwaie29d3772011-11-14 17:13:23 +01003622static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003623 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003624{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003625 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3626 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003627}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003628
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003629static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003630 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003631{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003632 int i;
3633
3634 for (i = path->depth - 1; i >= 0; i--) {
3635 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3636 return path->path[i];
3637 if (i != path->depth - 1 && i != 0 &&
3638 nid_has_mute(codec, path->path[i], HDA_INPUT))
3639 return path->path[i];
3640 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003641 return 0;
3642}
3643
3644static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003645 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003646{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003647 int i;
3648
3649 for (i = path->depth - 1; i >= 0; i--) {
3650 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3651 return path->path[i];
3652 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003653 return 0;
3654}
3655
Takashi Iwai7085ec12009-10-02 09:03:58 +02003656/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003657static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003658 const struct auto_pin_cfg *cfg)
3659{
3660 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003661 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003662
Takashi Iwaice764ab2011-04-27 16:35:23 +02003663 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003664 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003665 noutputs += spec->multi_ios;
3666
3667 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003668 const char *name;
3669 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003670 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003671 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003672
3673 dac = spec->multiout.dac_nids[i];
3674 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003675 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003676 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003677 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003678 index = 0;
3679 name = channel_name[i];
3680 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003681 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003682 name = alc_get_line_out_pfx(spec, i, true, &index);
3683 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003684
Takashi Iwaiba8111272012-12-06 18:06:23 +01003685 path = get_out_path(codec, pin, dac);
3686 if (!path)
3687 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003688 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003689 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003690 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003691 if (err < 0)
3692 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003693 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003694 if (err < 0)
3695 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003696 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003697 if (err < 0)
3698 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003699 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003700 if (err < 0)
3701 return err;
3702 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003703 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003704 if (err < 0)
3705 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003706 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003707 if (err < 0)
3708 return err;
3709 }
3710 }
3711 return 0;
3712}
3713
Takashi Iwai343a04b2011-07-06 14:28:39 +02003714static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003715 hda_nid_t dac, const char *pfx,
3716 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003717{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003718 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003719 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003720
Takashi Iwaiba8111272012-12-06 18:06:23 +01003721 path = get_out_path(codec, pin, dac);
3722 if (!path)
3723 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003724 /* bind volume control will be created in the case of dac = 0 */
3725 if (dac) {
3726 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3727 if (err < 0)
3728 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003729 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003730 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003731 if (err < 0)
3732 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003733 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003734}
3735
Takashi Iwai23c09b02011-08-19 09:05:35 +02003736static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3737 unsigned int nums,
3738 struct hda_ctl_ops *ops)
3739{
3740 struct alc_spec *spec = codec->spec;
3741 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003742 ctlp = snd_array_new(&spec->bind_ctls);
3743 if (!ctlp)
3744 return NULL;
3745 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3746 *ctlp = ctl;
3747 if (ctl)
3748 ctl->ops = ops;
3749 return ctl;
3750}
3751
3752/* add playback controls for speaker and HP outputs */
3753static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3754 const hda_nid_t *pins,
3755 const hda_nid_t *dacs,
3756 const char *pfx)
3757{
3758 struct alc_spec *spec = codec->spec;
3759 struct hda_bind_ctls *ctl;
3760 char name[32];
3761 int i, n, err;
3762
3763 if (!num_pins || !pins[0])
3764 return 0;
3765
Takashi Iwai527e4d72011-10-27 16:33:27 +02003766 if (num_pins == 1) {
3767 hda_nid_t dac = *dacs;
3768 if (!dac)
3769 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003770 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003771 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003772
Takashi Iwai23c09b02011-08-19 09:05:35 +02003773 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003774 hda_nid_t dac;
3775 if (dacs[num_pins - 1])
3776 dac = dacs[i]; /* with individual volumes */
3777 else
3778 dac = 0;
3779 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3780 err = alc_auto_create_extra_out(codec, pins[i], dac,
3781 "Bass Speaker", 0);
3782 } else if (num_pins >= 3) {
3783 snprintf(name, sizeof(name), "%s %s",
3784 pfx, channel_name[i]);
3785 err = alc_auto_create_extra_out(codec, pins[i], dac,
3786 name, 0);
3787 } else {
3788 err = alc_auto_create_extra_out(codec, pins[i], dac,
3789 pfx, i);
3790 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003791 if (err < 0)
3792 return err;
3793 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003794 if (dacs[num_pins - 1])
3795 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003796
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003797 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003798 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3799 if (!ctl)
3800 return -ENOMEM;
3801 n = 0;
3802 for (i = 0; i < num_pins; i++) {
3803 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003804 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003805 if (!pins[i] || !dacs[i])
3806 continue;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003807 path = get_out_path(codec, pins[i], dacs[i]);
3808 if (!path)
3809 continue;
3810 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003811 if (vol)
3812 ctl->values[n++] =
3813 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3814 }
3815 if (n) {
3816 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3817 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3818 if (err < 0)
3819 return err;
3820 }
3821 return 0;
3822}
3823
Takashi Iwai343a04b2011-07-06 14:28:39 +02003824static int alc_auto_create_hp_out(struct hda_codec *codec)
3825{
3826 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003827 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3828 spec->autocfg.hp_pins,
3829 spec->multiout.hp_out_nid,
3830 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003831}
3832
3833static int alc_auto_create_speaker_out(struct hda_codec *codec)
3834{
3835 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003836 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3837 spec->autocfg.speaker_pins,
3838 spec->multiout.extra_out_nid,
3839 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003840}
3841
Takashi Iwai78e635c2012-12-10 17:07:16 +01003842/* is a volume or mute control already present? */
3843static bool __is_out_ctl_present(struct hda_codec *codec,
3844 struct nid_path *exclude_path,
3845 hda_nid_t nid, int dir, int types)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003846{
Takashi Iwai78e635c2012-12-10 17:07:16 +01003847 struct alc_spec *spec = codec->spec;
3848 int i, type;
3849
3850 for (i = 0; i < spec->out_path.used; i++) {
3851 struct nid_path *p = snd_array_elem(&spec->out_path, i);
3852 if (p == exclude_path || p->depth <= 0)
3853 continue;
3854 for (type = 0; type < 2; type++) {
3855 if (types & (1 << type)) {
3856 unsigned int val = p->ctls[type];
3857 if (get_amp_nid_(val) == nid &&
3858 get_amp_direction_(val) == dir)
3859 return true;
3860 }
3861 }
3862 }
3863 return false;
3864}
3865
3866#define is_out_ctl_present(codec, path, nid, dir) \
3867 __is_out_ctl_present(codec, path, nid, dir, 3) /* check both types */
3868#define is_out_vol_ctl_present(codec, nid, dir) \
3869 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_VOL_CTL)
3870#define is_out_mute_ctl_present(codec, nid, dir) \
3871 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_MUTE_CTL)
3872
3873static int get_default_amp_val(struct hda_codec *codec, hda_nid_t nid, int dir)
3874{
3875 unsigned int caps, offset;
3876 unsigned int val = 0;
3877
3878 caps = query_amp_caps(codec, nid, dir);
3879 if (caps & AC_AMPCAP_NUM_STEPS) {
3880 offset = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
3881 /* if a volume control is assigned, set the lowest level
3882 * as default; otherwise set to 0dB
3883 */
3884 if (is_out_vol_ctl_present(codec, nid, dir))
3885 val = 0;
3886 else
3887 val = offset;
3888 }
3889 if (caps & AC_AMPCAP_MUTE) {
3890 /* if a mute control is assigned, mute as default */
3891 if (is_out_mute_ctl_present(codec, nid, dir))
3892 val |= HDA_AMP_MUTE;
3893 }
3894 return val;
3895}
3896
3897/* configure the path from the given dac to the pin as the proper output */
3898static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3899 hda_nid_t pin, int pin_type,
3900 hda_nid_t dac, bool force)
3901{
3902 int i, val;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003903 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003904
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003905 alc_set_pin_output(codec, pin, pin_type);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003906 path = get_out_path(codec, pin, dac);
3907 if (!path)
3908 return;
Takashi Iwai43dea222011-11-06 11:25:34 +01003909
Takashi Iwai78e635c2012-12-10 17:07:16 +01003910 for (i = path->depth - 1; i >= 0; i--) {
3911 hda_nid_t nid = path->path[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01003912 if (path->multi[i])
Takashi Iwai78e635c2012-12-10 17:07:16 +01003913 snd_hda_codec_write(codec, nid, 0,
3914 AC_VERB_SET_CONNECT_SEL,
Takashi Iwai95e960c2012-12-10 17:27:57 +01003915 path->idx[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003916
3917 if (i != 0 && i != path->depth - 1 &&
3918 (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) &&
3919 (force || !is_out_ctl_present(codec, path, nid,
3920 HDA_INPUT))) {
3921 val = get_default_amp_val(codec, nid, HDA_INPUT);
3922 snd_hda_codec_write(codec, nid, 0,
3923 AC_VERB_SET_AMP_GAIN_MUTE,
3924 AMP_IN_UNMUTE(0) | val);
3925 snd_hda_codec_write(codec, nid, 0,
3926 AC_VERB_SET_AMP_GAIN_MUTE,
3927 AMP_IN_UNMUTE(1) | val);
3928 }
3929 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
3930 (force || !is_out_ctl_present(codec, path, nid,
3931 HDA_OUTPUT))) {
3932 val = get_default_amp_val(codec, nid, HDA_OUTPUT);
3933 snd_hda_codec_write(codec, nid, 0,
3934 AC_VERB_SET_AMP_GAIN_MUTE,
3935 AMP_OUT_UNMUTE | val);
3936 }
3937 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003938}
3939
Takashi Iwai343a04b2011-07-06 14:28:39 +02003940static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003941{
3942 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003943 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003944 int i;
3945
3946 for (i = 0; i <= HDA_SIDE; i++) {
3947 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3948 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003949 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai78e635c2012-12-10 17:07:16 +01003950 spec->multiout.dac_nids[i], true);
3951
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003952 }
3953}
3954
Takashi Iwai343a04b2011-07-06 14:28:39 +02003955static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003956{
3957 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003958 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003959 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003960
David Henningsson636030e2011-10-12 19:26:03 +02003961 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003962 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3963 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003964 pin = spec->autocfg.hp_pins[i];
3965 if (!pin)
3966 break;
3967 dac = spec->multiout.hp_out_nid[i];
3968 if (!dac) {
3969 if (i > 0 && spec->multiout.hp_out_nid[0])
3970 dac = spec->multiout.hp_out_nid[0];
3971 else
3972 dac = spec->multiout.dac_nids[0];
3973 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003974 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003975 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003976 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003977 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3978 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003979 pin = spec->autocfg.speaker_pins[i];
3980 if (!pin)
3981 break;
3982 dac = spec->multiout.extra_out_nid[i];
3983 if (!dac) {
3984 if (i > 0 && spec->multiout.extra_out_nid[0])
3985 dac = spec->multiout.extra_out_nid[0];
3986 else
3987 dac = spec->multiout.dac_nids[0];
3988 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003989 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003990 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003991}
3992
Takashi Iwai276dd702012-02-17 16:17:03 +01003993/* check whether the given pin can be a multi-io pin */
3994static bool can_be_multiio_pin(struct hda_codec *codec,
3995 unsigned int location, hda_nid_t nid)
3996{
3997 unsigned int defcfg, caps;
3998
3999 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4000 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4001 return false;
4002 if (location && get_defcfg_location(defcfg) != location)
4003 return false;
4004 caps = snd_hda_query_pin_caps(codec, nid);
4005 if (!(caps & AC_PINCAP_OUT))
4006 return false;
4007 return true;
4008}
4009
Takashi Iwaice764ab2011-04-27 16:35:23 +02004010/*
4011 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004012 *
4013 * When hardwired is set, try to fill ony hardwired pins, and returns
4014 * zero if any pins are filled, non-zero if nothing found.
4015 * When hardwired is off, try to fill possible input pins, and returns
4016 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004017 */
4018static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004019 hda_nid_t reference_pin,
4020 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004021{
4022 struct alc_spec *spec = codec->spec;
4023 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004024 int type, i, j, dacs, num_pins, old_pins;
4025 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4026 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004027 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004028
Takashi Iwai276dd702012-02-17 16:17:03 +01004029 old_pins = spec->multi_ios;
4030 if (old_pins >= 2)
4031 goto end_fill;
4032
4033 num_pins = 0;
4034 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4035 for (i = 0; i < cfg->num_inputs; i++) {
4036 if (cfg->inputs[i].type != type)
4037 continue;
4038 if (can_be_multiio_pin(codec, location,
4039 cfg->inputs[i].pin))
4040 num_pins++;
4041 }
4042 }
4043 if (num_pins < 2)
4044 goto end_fill;
4045
Takashi Iwai07b18f62011-11-10 15:42:54 +01004046 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004047 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4048 for (i = 0; i < cfg->num_inputs; i++) {
4049 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004050 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004051
Takashi Iwaice764ab2011-04-27 16:35:23 +02004052 if (cfg->inputs[i].type != type)
4053 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004054 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004055 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004056 for (j = 0; j < spec->multi_ios; j++) {
4057 if (nid == spec->multi_io[j].pin)
4058 break;
4059 }
4060 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004061 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004062
4063 if (offset && offset + spec->multi_ios < dacs) {
4064 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01004065 if (!alc_auto_is_dac_reachable(codec, nid, dac))
4066 dac = 0;
4067 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004068 if (hardwired)
4069 dac = get_dac_if_single(codec, nid);
4070 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01004071 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004072 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004073 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004074 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004075 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004076 if (!add_new_out_path(codec, nid, dac)) {
4077 badness++;
4078 continue;
4079 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004080 spec->multi_io[spec->multi_ios].pin = nid;
4081 spec->multi_io[spec->multi_ios].dac = dac;
4082 spec->multi_ios++;
4083 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004084 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004085 }
4086 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004087 end_fill:
4088 if (badness)
4089 badness = BAD_MULTI_IO;
4090 if (old_pins == spec->multi_ios) {
4091 if (hardwired)
4092 return 1; /* nothing found */
4093 else
4094 return badness; /* no badness if nothing found */
4095 }
4096 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004097 /* cancel newly assigned paths */
4098 spec->out_path.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004099 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004100 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004101 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004102
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004103 /* assign volume and mute controls */
4104 for (i = old_pins; i < spec->multi_ios; i++)
4105 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4106 spec->multi_io[i].dac);
4107
4108 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004109}
4110
4111static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4112 struct snd_ctl_elem_info *uinfo)
4113{
4114 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4115 struct alc_spec *spec = codec->spec;
4116
4117 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4118 uinfo->count = 1;
4119 uinfo->value.enumerated.items = spec->multi_ios + 1;
4120 if (uinfo->value.enumerated.item > spec->multi_ios)
4121 uinfo->value.enumerated.item = spec->multi_ios;
4122 sprintf(uinfo->value.enumerated.name, "%dch",
4123 (uinfo->value.enumerated.item + 1) * 2);
4124 return 0;
4125}
4126
4127static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4128 struct snd_ctl_elem_value *ucontrol)
4129{
4130 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4131 struct alc_spec *spec = codec->spec;
4132 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4133 return 0;
4134}
4135
4136static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4137{
4138 struct alc_spec *spec = codec->spec;
4139 hda_nid_t nid = spec->multi_io[idx].pin;
4140
4141 if (!spec->multi_io[idx].ctl_in)
4142 spec->multi_io[idx].ctl_in =
4143 snd_hda_codec_read(codec, nid, 0,
4144 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4145 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004146 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004147 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4148 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4149 HDA_AMP_MUTE, 0);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004150 alc_auto_set_output_and_unmute(codec, nid, PIN_OUT,
4151 spec->multi_io[idx].dac, false);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004152 } else {
4153 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4154 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4155 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004156 snd_hda_set_pin_ctl_cache(codec, nid,
4157 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004158 }
4159 return 0;
4160}
4161
4162static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4163 struct snd_ctl_elem_value *ucontrol)
4164{
4165 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4166 struct alc_spec *spec = codec->spec;
4167 int i, ch;
4168
4169 ch = ucontrol->value.enumerated.item[0];
4170 if (ch < 0 || ch > spec->multi_ios)
4171 return -EINVAL;
4172 if (ch == (spec->ext_channel_count - 1) / 2)
4173 return 0;
4174 spec->ext_channel_count = (ch + 1) * 2;
4175 for (i = 0; i < spec->multi_ios; i++)
4176 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004177 spec->multiout.max_channels = max(spec->ext_channel_count,
4178 spec->const_channel_count);
4179 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004180 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004181 return 1;
4182}
4183
Takashi Iwaia9111322011-05-02 11:30:18 +02004184static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004185 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4186 .name = "Channel Mode",
4187 .info = alc_auto_ch_mode_info,
4188 .get = alc_auto_ch_mode_get,
4189 .put = alc_auto_ch_mode_put,
4190};
4191
Takashi Iwai23c09b02011-08-19 09:05:35 +02004192static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004193{
4194 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004195
Takashi Iwaic2674682011-08-24 17:57:44 +02004196 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004197 if (!alc_kcontrol_new(spec, "Channel Mode",
4198 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004199 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004200 }
4201 return 0;
4202}
4203
Takashi Iwai1d045db2011-07-07 18:23:21 +02004204/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4205 * active input pins
4206 */
4207static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4208{
4209 struct alc_spec *spec = codec->spec;
4210 const struct hda_input_mux *imux;
4211 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4212 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4213 int i, n, nums;
4214
4215 imux = spec->input_mux;
4216 if (!imux)
4217 return;
4218 if (spec->dyn_adc_switch)
4219 return;
4220
Takashi Iwai26acaf02012-03-22 14:36:50 +01004221 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004222 nums = 0;
4223 for (n = 0; n < spec->num_adc_nids; n++) {
4224 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004225 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004226 for (i = 0; i < imux->num_items; i++) {
4227 hda_nid_t pin = spec->imux_pins[i];
4228 if (pin) {
4229 if (get_connection_index(codec, cap, pin) < 0)
4230 break;
4231 } else if (num_conns <= imux->items[i].index)
4232 break;
4233 }
4234 if (i >= imux->num_items) {
4235 adc_nids[nums] = spec->private_adc_nids[n];
4236 capsrc_nids[nums++] = cap;
4237 }
4238 }
4239 if (!nums) {
4240 /* check whether ADC-switch is possible */
4241 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004242 if (spec->shared_mic_hp) {
4243 spec->shared_mic_hp = 0;
4244 spec->private_imux[0].num_items = 1;
4245 goto again;
4246 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004247 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4248 " using fallback 0x%x\n",
4249 codec->chip_name, spec->private_adc_nids[0]);
4250 spec->num_adc_nids = 1;
4251 spec->auto_mic = 0;
4252 return;
4253 }
4254 } else if (nums != spec->num_adc_nids) {
4255 memcpy(spec->private_adc_nids, adc_nids,
4256 nums * sizeof(hda_nid_t));
4257 memcpy(spec->private_capsrc_nids, capsrc_nids,
4258 nums * sizeof(hda_nid_t));
4259 spec->num_adc_nids = nums;
4260 }
4261
4262 if (spec->auto_mic)
4263 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004264 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004265 spec->num_adc_nids = 1; /* reduce to a single ADC */
4266}
4267
4268/*
4269 * initialize ADC paths
4270 */
4271static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4272{
4273 struct alc_spec *spec = codec->spec;
4274 hda_nid_t nid;
4275
4276 nid = spec->adc_nids[adc_idx];
4277 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004278 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004279 snd_hda_codec_write(codec, nid, 0,
4280 AC_VERB_SET_AMP_GAIN_MUTE,
4281 AMP_IN_MUTE(0));
4282 return;
4283 }
4284 if (!spec->capsrc_nids)
4285 return;
4286 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004287 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004288 snd_hda_codec_write(codec, nid, 0,
4289 AC_VERB_SET_AMP_GAIN_MUTE,
4290 AMP_OUT_MUTE);
4291}
4292
4293static void alc_auto_init_input_src(struct hda_codec *codec)
4294{
4295 struct alc_spec *spec = codec->spec;
4296 int c, nums;
4297
4298 for (c = 0; c < spec->num_adc_nids; c++)
4299 alc_auto_init_adc(codec, c);
4300 if (spec->dyn_adc_switch)
4301 nums = 1;
4302 else
4303 nums = spec->num_adc_nids;
4304 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004305 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004306}
4307
4308/* add mic boosts if needed */
4309static int alc_auto_add_mic_boost(struct hda_codec *codec)
4310{
4311 struct alc_spec *spec = codec->spec;
4312 struct auto_pin_cfg *cfg = &spec->autocfg;
4313 int i, err;
4314 int type_idx = 0;
4315 hda_nid_t nid;
4316 const char *prev_label = NULL;
4317
4318 for (i = 0; i < cfg->num_inputs; i++) {
4319 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4320 break;
4321 nid = cfg->inputs[i].pin;
4322 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4323 const char *label;
4324 char boost_label[32];
4325
4326 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004327 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4328 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004329 if (prev_label && !strcmp(label, prev_label))
4330 type_idx++;
4331 else
4332 type_idx = 0;
4333 prev_label = label;
4334
4335 snprintf(boost_label, sizeof(boost_label),
4336 "%s Boost Volume", label);
4337 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4338 boost_label, type_idx,
4339 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4340 if (err < 0)
4341 return err;
4342 }
4343 }
4344 return 0;
4345}
4346
4347/* select or unmute the given capsrc route */
4348static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4349 int idx)
4350{
4351 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4352 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4353 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004354 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004355 snd_hda_codec_write_cache(codec, cap, 0,
4356 AC_VERB_SET_CONNECT_SEL, idx);
4357 }
4358}
4359
4360/* set the default connection to that pin */
4361static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4362{
4363 struct alc_spec *spec = codec->spec;
4364 int i;
4365
4366 if (!pin)
4367 return 0;
4368 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004369 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004370 int idx;
4371
4372 idx = get_connection_index(codec, cap, pin);
4373 if (idx < 0)
4374 continue;
4375 select_or_unmute_capsrc(codec, cap, idx);
4376 return i; /* return the found index */
4377 }
4378 return -1; /* not found */
4379}
4380
4381/* initialize some special cases for input sources */
4382static void alc_init_special_input_src(struct hda_codec *codec)
4383{
4384 struct alc_spec *spec = codec->spec;
4385 int i;
4386
4387 for (i = 0; i < spec->autocfg.num_inputs; i++)
4388 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4389}
4390
4391/* assign appropriate capture mixers */
4392static void set_capture_mixer(struct hda_codec *codec)
4393{
4394 struct alc_spec *spec = codec->spec;
4395 static const struct snd_kcontrol_new *caps[2][3] = {
4396 { alc_capture_mixer_nosrc1,
4397 alc_capture_mixer_nosrc2,
4398 alc_capture_mixer_nosrc3 },
4399 { alc_capture_mixer1,
4400 alc_capture_mixer2,
4401 alc_capture_mixer3 },
4402 };
4403
4404 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004405 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004406 if (!spec->capsrc_nids)
4407 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004408 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 return; /* no volume in capsrc, too */
4410 spec->vol_in_capsrc = 1;
4411 }
4412
4413 if (spec->num_adc_nids > 0) {
4414 int mux = 0;
4415 int num_adcs = 0;
4416
4417 if (spec->input_mux && spec->input_mux->num_items > 1)
4418 mux = 1;
4419 if (spec->auto_mic) {
4420 num_adcs = 1;
4421 mux = 0;
4422 } else if (spec->dyn_adc_switch)
4423 num_adcs = 1;
4424 if (!num_adcs) {
4425 if (spec->num_adc_nids > 3)
4426 spec->num_adc_nids = 3;
4427 else if (!spec->num_adc_nids)
4428 return;
4429 num_adcs = spec->num_adc_nids;
4430 }
4431 spec->cap_mixer = caps[mux][num_adcs - 1];
4432 }
4433}
4434
4435/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004436 * standard auto-parser initializations
4437 */
4438static void alc_auto_init_std(struct hda_codec *codec)
4439{
Takashi Iwaie4770622011-07-08 11:11:35 +02004440 alc_auto_init_multi_out(codec);
4441 alc_auto_init_extra_out(codec);
4442 alc_auto_init_analog_input(codec);
4443 alc_auto_init_input_src(codec);
4444 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004445 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004446}
4447
4448/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004449 * Digital-beep handlers
4450 */
4451#ifdef CONFIG_SND_HDA_INPUT_BEEP
4452#define set_beep_amp(spec, nid, idx, dir) \
4453 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4454
4455static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004456 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004457 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4458 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4459 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4460 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004461 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004462 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4463 {}
4464};
4465
4466static inline int has_cdefine_beep(struct hda_codec *codec)
4467{
4468 struct alc_spec *spec = codec->spec;
4469 const struct snd_pci_quirk *q;
4470 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4471 if (q)
4472 return q->value;
4473 return spec->cdefine.enable_pcbeep;
4474}
4475#else
4476#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4477#define has_cdefine_beep(codec) 0
4478#endif
4479
4480/* parse the BIOS configuration and set up the alc_spec */
4481/* return 1 if successful, 0 if the proper config is not found,
4482 * or a negative error code
4483 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004484static int alc_parse_auto_config(struct hda_codec *codec,
4485 const hda_nid_t *ignore_nids,
4486 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004487{
4488 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004489 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004490 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004491
Takashi Iwai53c334a2011-08-23 18:27:14 +02004492 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4493 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004494 if (err < 0)
4495 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004496 if (!cfg->line_outs) {
4497 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004498 spec->multiout.max_channels = 2;
4499 spec->no_analog = 1;
4500 goto dig_only;
4501 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004502 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004503 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004504
Takashi Iwaie427c232012-07-29 10:04:08 +02004505 if (!spec->no_primary_hp &&
4506 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004507 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004508 /* use HP as primary out */
4509 cfg->speaker_outs = cfg->line_outs;
4510 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4511 sizeof(cfg->speaker_pins));
4512 cfg->line_outs = cfg->hp_outs;
4513 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4514 cfg->hp_outs = 0;
4515 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4516 cfg->line_out_type = AUTO_PIN_HP_OUT;
4517 }
4518
Takashi Iwai1d045db2011-07-07 18:23:21 +02004519 err = alc_auto_fill_dac_nids(codec);
4520 if (err < 0)
4521 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004522 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004523 if (err < 0)
4524 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004525 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004526 if (err < 0)
4527 return err;
4528 err = alc_auto_create_hp_out(codec);
4529 if (err < 0)
4530 return err;
4531 err = alc_auto_create_speaker_out(codec);
4532 if (err < 0)
4533 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004534 err = alc_auto_create_shared_input(codec);
4535 if (err < 0)
4536 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004537 err = alc_auto_create_input_ctls(codec);
4538 if (err < 0)
4539 return err;
4540
Takashi Iwaib6adb572012-12-03 10:30:58 +01004541 /* check the multiple speaker pins */
4542 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4543 spec->const_channel_count = cfg->line_outs * 2;
4544 else
4545 spec->const_channel_count = cfg->speaker_outs * 2;
4546
4547 if (spec->multi_ios > 0)
4548 spec->multiout.max_channels = max(spec->ext_channel_count,
4549 spec->const_channel_count);
4550 else
4551 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004552
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004553 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004554 alc_auto_parse_digital(codec);
4555
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004556 if (!spec->no_analog)
4557 alc_remove_invalid_adc_nids(codec);
4558
4559 if (ssid_nids)
4560 alc_ssid_check(codec, ssid_nids);
4561
4562 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004563 err = alc_auto_check_switches(codec);
4564 if (err < 0)
4565 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004566 err = alc_auto_add_mic_boost(codec);
4567 if (err < 0)
4568 return err;
4569 }
4570
Takashi Iwai1d045db2011-07-07 18:23:21 +02004571 if (spec->kctls.list)
4572 add_mixer(spec, spec->kctls.list);
4573
Takashi Iwai070cff42012-02-21 12:54:17 +01004574 if (!spec->no_analog && !spec->cap_mixer)
4575 set_capture_mixer(codec);
4576
Takashi Iwai1d045db2011-07-07 18:23:21 +02004577 return 1;
4578}
4579
Takashi Iwai3de95172012-05-07 18:03:15 +02004580/* common preparation job for alc_spec */
4581static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4582{
4583 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4584 int err;
4585
4586 if (!spec)
4587 return -ENOMEM;
4588 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004589 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004590 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004591 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004592 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4593 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004594 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01004595 snd_array_init(&spec->in_path, sizeof(struct nid_path), 8);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01004596 snd_array_init(&spec->loopback_path, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004597
4598 err = alc_codec_rename_from_preset(codec);
4599 if (err < 0) {
4600 kfree(spec);
4601 return err;
4602 }
4603 return 0;
4604}
4605
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004606static int alc880_parse_auto_config(struct hda_codec *codec)
4607{
4608 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004609 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004610 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4611}
4612
Takashi Iwai1d045db2011-07-07 18:23:21 +02004613/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004614 * ALC880 fix-ups
4615 */
4616enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004617 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004618 ALC880_FIXUP_GPIO2,
4619 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004620 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004621 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004622 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004623 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004624 ALC880_FIXUP_VOL_KNOB,
4625 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004626 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004627 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004628 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004629 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004630 ALC880_FIXUP_3ST_BASE,
4631 ALC880_FIXUP_3ST,
4632 ALC880_FIXUP_3ST_DIG,
4633 ALC880_FIXUP_5ST_BASE,
4634 ALC880_FIXUP_5ST,
4635 ALC880_FIXUP_5ST_DIG,
4636 ALC880_FIXUP_6ST_BASE,
4637 ALC880_FIXUP_6ST,
4638 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004639};
4640
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004641/* enable the volume-knob widget support on NID 0x21 */
4642static void alc880_fixup_vol_knob(struct hda_codec *codec,
4643 const struct alc_fixup *fix, int action)
4644{
4645 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004646 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004647}
4648
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004649static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004650 [ALC880_FIXUP_GPIO1] = {
4651 .type = ALC_FIXUP_VERBS,
4652 .v.verbs = alc_gpio1_init_verbs,
4653 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004654 [ALC880_FIXUP_GPIO2] = {
4655 .type = ALC_FIXUP_VERBS,
4656 .v.verbs = alc_gpio2_init_verbs,
4657 },
4658 [ALC880_FIXUP_MEDION_RIM] = {
4659 .type = ALC_FIXUP_VERBS,
4660 .v.verbs = (const struct hda_verb[]) {
4661 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4662 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4663 { }
4664 },
4665 .chained = true,
4666 .chain_id = ALC880_FIXUP_GPIO2,
4667 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004668 [ALC880_FIXUP_LG] = {
4669 .type = ALC_FIXUP_PINS,
4670 .v.pins = (const struct alc_pincfg[]) {
4671 /* disable bogus unused pins */
4672 { 0x16, 0x411111f0 },
4673 { 0x18, 0x411111f0 },
4674 { 0x1a, 0x411111f0 },
4675 { }
4676 }
4677 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004678 [ALC880_FIXUP_W810] = {
4679 .type = ALC_FIXUP_PINS,
4680 .v.pins = (const struct alc_pincfg[]) {
4681 /* disable bogus unused pins */
4682 { 0x17, 0x411111f0 },
4683 { }
4684 },
4685 .chained = true,
4686 .chain_id = ALC880_FIXUP_GPIO2,
4687 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004688 [ALC880_FIXUP_EAPD_COEF] = {
4689 .type = ALC_FIXUP_VERBS,
4690 .v.verbs = (const struct hda_verb[]) {
4691 /* change to EAPD mode */
4692 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4693 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4694 {}
4695 },
4696 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004697 [ALC880_FIXUP_TCL_S700] = {
4698 .type = ALC_FIXUP_VERBS,
4699 .v.verbs = (const struct hda_verb[]) {
4700 /* change to EAPD mode */
4701 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4702 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4703 {}
4704 },
4705 .chained = true,
4706 .chain_id = ALC880_FIXUP_GPIO2,
4707 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004708 [ALC880_FIXUP_VOL_KNOB] = {
4709 .type = ALC_FIXUP_FUNC,
4710 .v.func = alc880_fixup_vol_knob,
4711 },
4712 [ALC880_FIXUP_FUJITSU] = {
4713 /* override all pins as BIOS on old Amilo is broken */
4714 .type = ALC_FIXUP_PINS,
4715 .v.pins = (const struct alc_pincfg[]) {
4716 { 0x14, 0x0121411f }, /* HP */
4717 { 0x15, 0x99030120 }, /* speaker */
4718 { 0x16, 0x99030130 }, /* bass speaker */
4719 { 0x17, 0x411111f0 }, /* N/A */
4720 { 0x18, 0x411111f0 }, /* N/A */
4721 { 0x19, 0x01a19950 }, /* mic-in */
4722 { 0x1a, 0x411111f0 }, /* N/A */
4723 { 0x1b, 0x411111f0 }, /* N/A */
4724 { 0x1c, 0x411111f0 }, /* N/A */
4725 { 0x1d, 0x411111f0 }, /* N/A */
4726 { 0x1e, 0x01454140 }, /* SPDIF out */
4727 { }
4728 },
4729 .chained = true,
4730 .chain_id = ALC880_FIXUP_VOL_KNOB,
4731 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004732 [ALC880_FIXUP_F1734] = {
4733 /* almost compatible with FUJITSU, but no bass and SPDIF */
4734 .type = ALC_FIXUP_PINS,
4735 .v.pins = (const struct alc_pincfg[]) {
4736 { 0x14, 0x0121411f }, /* HP */
4737 { 0x15, 0x99030120 }, /* speaker */
4738 { 0x16, 0x411111f0 }, /* N/A */
4739 { 0x17, 0x411111f0 }, /* N/A */
4740 { 0x18, 0x411111f0 }, /* N/A */
4741 { 0x19, 0x01a19950 }, /* mic-in */
4742 { 0x1a, 0x411111f0 }, /* N/A */
4743 { 0x1b, 0x411111f0 }, /* N/A */
4744 { 0x1c, 0x411111f0 }, /* N/A */
4745 { 0x1d, 0x411111f0 }, /* N/A */
4746 { 0x1e, 0x411111f0 }, /* N/A */
4747 { }
4748 },
4749 .chained = true,
4750 .chain_id = ALC880_FIXUP_VOL_KNOB,
4751 },
Takashi Iwai817de922012-02-20 17:20:48 +01004752 [ALC880_FIXUP_UNIWILL] = {
4753 /* need to fix HP and speaker pins to be parsed correctly */
4754 .type = ALC_FIXUP_PINS,
4755 .v.pins = (const struct alc_pincfg[]) {
4756 { 0x14, 0x0121411f }, /* HP */
4757 { 0x15, 0x99030120 }, /* speaker */
4758 { 0x16, 0x99030130 }, /* bass speaker */
4759 { }
4760 },
4761 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004762 [ALC880_FIXUP_UNIWILL_DIG] = {
4763 .type = ALC_FIXUP_PINS,
4764 .v.pins = (const struct alc_pincfg[]) {
4765 /* disable bogus unused pins */
4766 { 0x17, 0x411111f0 },
4767 { 0x19, 0x411111f0 },
4768 { 0x1b, 0x411111f0 },
4769 { 0x1f, 0x411111f0 },
4770 { }
4771 }
4772 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004773 [ALC880_FIXUP_Z71V] = {
4774 .type = ALC_FIXUP_PINS,
4775 .v.pins = (const struct alc_pincfg[]) {
4776 /* set up the whole pins as BIOS is utterly broken */
4777 { 0x14, 0x99030120 }, /* speaker */
4778 { 0x15, 0x0121411f }, /* HP */
4779 { 0x16, 0x411111f0 }, /* N/A */
4780 { 0x17, 0x411111f0 }, /* N/A */
4781 { 0x18, 0x01a19950 }, /* mic-in */
4782 { 0x19, 0x411111f0 }, /* N/A */
4783 { 0x1a, 0x01813031 }, /* line-in */
4784 { 0x1b, 0x411111f0 }, /* N/A */
4785 { 0x1c, 0x411111f0 }, /* N/A */
4786 { 0x1d, 0x411111f0 }, /* N/A */
4787 { 0x1e, 0x0144111e }, /* SPDIF */
4788 { }
4789 }
4790 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004791 [ALC880_FIXUP_3ST_BASE] = {
4792 .type = ALC_FIXUP_PINS,
4793 .v.pins = (const struct alc_pincfg[]) {
4794 { 0x14, 0x01014010 }, /* line-out */
4795 { 0x15, 0x411111f0 }, /* N/A */
4796 { 0x16, 0x411111f0 }, /* N/A */
4797 { 0x17, 0x411111f0 }, /* N/A */
4798 { 0x18, 0x01a19c30 }, /* mic-in */
4799 { 0x19, 0x0121411f }, /* HP */
4800 { 0x1a, 0x01813031 }, /* line-in */
4801 { 0x1b, 0x02a19c40 }, /* front-mic */
4802 { 0x1c, 0x411111f0 }, /* N/A */
4803 { 0x1d, 0x411111f0 }, /* N/A */
4804 /* 0x1e is filled in below */
4805 { 0x1f, 0x411111f0 }, /* N/A */
4806 { }
4807 }
4808 },
4809 [ALC880_FIXUP_3ST] = {
4810 .type = ALC_FIXUP_PINS,
4811 .v.pins = (const struct alc_pincfg[]) {
4812 { 0x1e, 0x411111f0 }, /* N/A */
4813 { }
4814 },
4815 .chained = true,
4816 .chain_id = ALC880_FIXUP_3ST_BASE,
4817 },
4818 [ALC880_FIXUP_3ST_DIG] = {
4819 .type = ALC_FIXUP_PINS,
4820 .v.pins = (const struct alc_pincfg[]) {
4821 { 0x1e, 0x0144111e }, /* SPDIF */
4822 { }
4823 },
4824 .chained = true,
4825 .chain_id = ALC880_FIXUP_3ST_BASE,
4826 },
4827 [ALC880_FIXUP_5ST_BASE] = {
4828 .type = ALC_FIXUP_PINS,
4829 .v.pins = (const struct alc_pincfg[]) {
4830 { 0x14, 0x01014010 }, /* front */
4831 { 0x15, 0x411111f0 }, /* N/A */
4832 { 0x16, 0x01011411 }, /* CLFE */
4833 { 0x17, 0x01016412 }, /* surr */
4834 { 0x18, 0x01a19c30 }, /* mic-in */
4835 { 0x19, 0x0121411f }, /* HP */
4836 { 0x1a, 0x01813031 }, /* line-in */
4837 { 0x1b, 0x02a19c40 }, /* front-mic */
4838 { 0x1c, 0x411111f0 }, /* N/A */
4839 { 0x1d, 0x411111f0 }, /* N/A */
4840 /* 0x1e is filled in below */
4841 { 0x1f, 0x411111f0 }, /* N/A */
4842 { }
4843 }
4844 },
4845 [ALC880_FIXUP_5ST] = {
4846 .type = ALC_FIXUP_PINS,
4847 .v.pins = (const struct alc_pincfg[]) {
4848 { 0x1e, 0x411111f0 }, /* N/A */
4849 { }
4850 },
4851 .chained = true,
4852 .chain_id = ALC880_FIXUP_5ST_BASE,
4853 },
4854 [ALC880_FIXUP_5ST_DIG] = {
4855 .type = ALC_FIXUP_PINS,
4856 .v.pins = (const struct alc_pincfg[]) {
4857 { 0x1e, 0x0144111e }, /* SPDIF */
4858 { }
4859 },
4860 .chained = true,
4861 .chain_id = ALC880_FIXUP_5ST_BASE,
4862 },
4863 [ALC880_FIXUP_6ST_BASE] = {
4864 .type = ALC_FIXUP_PINS,
4865 .v.pins = (const struct alc_pincfg[]) {
4866 { 0x14, 0x01014010 }, /* front */
4867 { 0x15, 0x01016412 }, /* surr */
4868 { 0x16, 0x01011411 }, /* CLFE */
4869 { 0x17, 0x01012414 }, /* side */
4870 { 0x18, 0x01a19c30 }, /* mic-in */
4871 { 0x19, 0x02a19c40 }, /* front-mic */
4872 { 0x1a, 0x01813031 }, /* line-in */
4873 { 0x1b, 0x0121411f }, /* HP */
4874 { 0x1c, 0x411111f0 }, /* N/A */
4875 { 0x1d, 0x411111f0 }, /* N/A */
4876 /* 0x1e is filled in below */
4877 { 0x1f, 0x411111f0 }, /* N/A */
4878 { }
4879 }
4880 },
4881 [ALC880_FIXUP_6ST] = {
4882 .type = ALC_FIXUP_PINS,
4883 .v.pins = (const struct alc_pincfg[]) {
4884 { 0x1e, 0x411111f0 }, /* N/A */
4885 { }
4886 },
4887 .chained = true,
4888 .chain_id = ALC880_FIXUP_6ST_BASE,
4889 },
4890 [ALC880_FIXUP_6ST_DIG] = {
4891 .type = ALC_FIXUP_PINS,
4892 .v.pins = (const struct alc_pincfg[]) {
4893 { 0x1e, 0x0144111e }, /* SPDIF */
4894 { }
4895 },
4896 .chained = true,
4897 .chain_id = ALC880_FIXUP_6ST_BASE,
4898 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004899};
4900
4901static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004902 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004903 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004904 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4905 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004906 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004907 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004908 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004909 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004910 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004911 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004912 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004913 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004914 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004915 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004916 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004917 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4918 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4919 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004920 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004921
4922 /* Below is the copied entries from alc880_quirks.c.
4923 * It's not quite sure whether BIOS sets the correct pin-config table
4924 * on these machines, thus they are kept to be compatible with
4925 * the old static quirks. Once when it's confirmed to work without
4926 * these overrides, it'd be better to remove.
4927 */
4928 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4929 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4930 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4931 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4932 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4933 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4934 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4935 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4936 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4937 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4938 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4939 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4940 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4941 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4942 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4943 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4944 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4945 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4946 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4947 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4948 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4949 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4950 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4951 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4952 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4953 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4954 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4955 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4956 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4957 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4958 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4959 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4960 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4961 /* default Intel */
4962 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4963 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4964 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4965 {}
4966};
4967
4968static const struct alc_model_fixup alc880_fixup_models[] = {
4969 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4970 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4971 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4972 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4973 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4974 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004975 {}
4976};
4977
4978
4979/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004980 * OK, here we have finally the patch for ALC880
4981 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004982static int patch_alc880(struct hda_codec *codec)
4983{
4984 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004985 int err;
4986
Takashi Iwai3de95172012-05-07 18:03:15 +02004987 err = alc_alloc_spec(codec, 0x0b);
4988 if (err < 0)
4989 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004990
Takashi Iwai3de95172012-05-07 18:03:15 +02004991 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004992 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004994 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4995 alc880_fixups);
4996 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004998 /* automatic parse from the BIOS config */
4999 err = alc880_parse_auto_config(codec);
5000 if (err < 0)
5001 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005002
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005003 if (!spec->no_analog) {
5004 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005005 if (err < 0)
5006 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005007 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5008 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005009
Takashi Iwai1d045db2011-07-07 18:23:21 +02005010 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005011 codec->patch_ops.unsol_event = alc880_unsol_event;
5012
Takashi Iwai1d045db2011-07-07 18:23:21 +02005013
Takashi Iwai589876e2012-02-20 15:47:55 +01005014 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5015
Takashi Iwai1d045db2011-07-07 18:23:21 +02005016 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005017
5018 error:
5019 alc_free(codec);
5020 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005021}
5022
5023
5024/*
5025 * ALC260 support
5026 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027static int alc260_parse_auto_config(struct hda_codec *codec)
5028{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005029 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005030 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5031 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005032}
5033
Takashi Iwai1d045db2011-07-07 18:23:21 +02005034/*
5035 * Pin config fixes
5036 */
5037enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005038 ALC260_FIXUP_HP_DC5750,
5039 ALC260_FIXUP_HP_PIN_0F,
5040 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005041 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005042 ALC260_FIXUP_GPIO1_TOGGLE,
5043 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005044 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005045 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005046};
5047
Takashi Iwai20f7d922012-02-16 12:35:16 +01005048static void alc260_gpio1_automute(struct hda_codec *codec)
5049{
5050 struct alc_spec *spec = codec->spec;
5051 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5052 spec->hp_jack_present);
5053}
5054
5055static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5056 const struct alc_fixup *fix, int action)
5057{
5058 struct alc_spec *spec = codec->spec;
5059 if (action == ALC_FIXUP_ACT_PROBE) {
5060 /* although the machine has only one output pin, we need to
5061 * toggle GPIO1 according to the jack state
5062 */
5063 spec->automute_hook = alc260_gpio1_automute;
5064 spec->detect_hp = 1;
5065 spec->automute_speaker = 1;
5066 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005067 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5068 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005069 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005070 }
5071}
5072
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005073static void alc260_fixup_kn1(struct hda_codec *codec,
5074 const struct alc_fixup *fix, int action)
5075{
5076 struct alc_spec *spec = codec->spec;
5077 static const struct alc_pincfg pincfgs[] = {
5078 { 0x0f, 0x02214000 }, /* HP/speaker */
5079 { 0x12, 0x90a60160 }, /* int mic */
5080 { 0x13, 0x02a19000 }, /* ext mic */
5081 { 0x18, 0x01446000 }, /* SPDIF out */
5082 /* disable bogus I/O pins */
5083 { 0x10, 0x411111f0 },
5084 { 0x11, 0x411111f0 },
5085 { 0x14, 0x411111f0 },
5086 { 0x15, 0x411111f0 },
5087 { 0x16, 0x411111f0 },
5088 { 0x17, 0x411111f0 },
5089 { 0x19, 0x411111f0 },
5090 { }
5091 };
5092
5093 switch (action) {
5094 case ALC_FIXUP_ACT_PRE_PROBE:
5095 alc_apply_pincfgs(codec, pincfgs);
5096 break;
5097 case ALC_FIXUP_ACT_PROBE:
5098 spec->init_amp = ALC_INIT_NONE;
5099 break;
5100 }
5101}
5102
Takashi Iwai1d045db2011-07-07 18:23:21 +02005103static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005104 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105 .type = ALC_FIXUP_PINS,
5106 .v.pins = (const struct alc_pincfg[]) {
5107 { 0x11, 0x90130110 }, /* speaker */
5108 { }
5109 }
5110 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005111 [ALC260_FIXUP_HP_PIN_0F] = {
5112 .type = ALC_FIXUP_PINS,
5113 .v.pins = (const struct alc_pincfg[]) {
5114 { 0x0f, 0x01214000 }, /* HP */
5115 { }
5116 }
5117 },
5118 [ALC260_FIXUP_COEF] = {
5119 .type = ALC_FIXUP_VERBS,
5120 .v.verbs = (const struct hda_verb[]) {
5121 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5122 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5123 { }
5124 },
5125 .chained = true,
5126 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5127 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005128 [ALC260_FIXUP_GPIO1] = {
5129 .type = ALC_FIXUP_VERBS,
5130 .v.verbs = alc_gpio1_init_verbs,
5131 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005132 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5133 .type = ALC_FIXUP_FUNC,
5134 .v.func = alc260_fixup_gpio1_toggle,
5135 .chained = true,
5136 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5137 },
5138 [ALC260_FIXUP_REPLACER] = {
5139 .type = ALC_FIXUP_VERBS,
5140 .v.verbs = (const struct hda_verb[]) {
5141 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5142 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5143 { }
5144 },
5145 .chained = true,
5146 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5147 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005148 [ALC260_FIXUP_HP_B1900] = {
5149 .type = ALC_FIXUP_FUNC,
5150 .v.func = alc260_fixup_gpio1_toggle,
5151 .chained = true,
5152 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005153 },
5154 [ALC260_FIXUP_KN1] = {
5155 .type = ALC_FIXUP_FUNC,
5156 .v.func = alc260_fixup_kn1,
5157 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005158};
5159
5160static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005161 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005162 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005163 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005164 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005165 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005166 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005167 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005168 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005169 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005170 {}
5171};
5172
5173/*
5174 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005175static int patch_alc260(struct hda_codec *codec)
5176{
5177 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005178 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005179
Takashi Iwai3de95172012-05-07 18:03:15 +02005180 err = alc_alloc_spec(codec, 0x07);
5181 if (err < 0)
5182 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005183
Takashi Iwai3de95172012-05-07 18:03:15 +02005184 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005185
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005186 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5187 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005188
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005189 /* automatic parse from the BIOS config */
5190 err = alc260_parse_auto_config(codec);
5191 if (err < 0)
5192 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005193
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005194 if (!spec->no_analog) {
5195 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005196 if (err < 0)
5197 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005198 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5199 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005200
Takashi Iwai1d045db2011-07-07 18:23:21 +02005201 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005202 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005203
Takashi Iwai589876e2012-02-20 15:47:55 +01005204 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5205
Takashi Iwai1d045db2011-07-07 18:23:21 +02005206 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005207
5208 error:
5209 alc_free(codec);
5210 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005211}
5212
5213
5214/*
5215 * ALC882/883/885/888/889 support
5216 *
5217 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5218 * configuration. Each pin widget can choose any input DACs and a mixer.
5219 * Each ADC is connected from a mixer of all inputs. This makes possible
5220 * 6-channel independent captures.
5221 *
5222 * In addition, an independent DAC for the multi-playback (not used in this
5223 * driver yet).
5224 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005225
5226/*
5227 * Pin config fixes
5228 */
5229enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005230 ALC882_FIXUP_ABIT_AW9D_MAX,
5231 ALC882_FIXUP_LENOVO_Y530,
5232 ALC882_FIXUP_PB_M5210,
5233 ALC882_FIXUP_ACER_ASPIRE_7736,
5234 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005235 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005236 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005237 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005238 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005239 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005240 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005241 ALC882_FIXUP_GPIO1,
5242 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005243 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005244 ALC889_FIXUP_COEF,
5245 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005246 ALC882_FIXUP_ACER_ASPIRE_4930G,
5247 ALC882_FIXUP_ACER_ASPIRE_8930G,
5248 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005249 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005250 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005251 ALC889_FIXUP_MBP_VREF,
5252 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005253 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005254 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005255};
5256
Takashi Iwai68ef0562011-11-09 18:24:44 +01005257static void alc889_fixup_coef(struct hda_codec *codec,
5258 const struct alc_fixup *fix, int action)
5259{
5260 if (action != ALC_FIXUP_ACT_INIT)
5261 return;
5262 alc889_coef_init(codec);
5263}
5264
Takashi Iwai56710872011-11-14 17:42:11 +01005265/* toggle speaker-output according to the hp-jack state */
5266static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5267{
5268 unsigned int gpiostate, gpiomask, gpiodir;
5269
5270 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5271 AC_VERB_GET_GPIO_DATA, 0);
5272
5273 if (!muted)
5274 gpiostate |= (1 << pin);
5275 else
5276 gpiostate &= ~(1 << pin);
5277
5278 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5279 AC_VERB_GET_GPIO_MASK, 0);
5280 gpiomask |= (1 << pin);
5281
5282 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5283 AC_VERB_GET_GPIO_DIRECTION, 0);
5284 gpiodir |= (1 << pin);
5285
5286
5287 snd_hda_codec_write(codec, codec->afg, 0,
5288 AC_VERB_SET_GPIO_MASK, gpiomask);
5289 snd_hda_codec_write(codec, codec->afg, 0,
5290 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5291
5292 msleep(1);
5293
5294 snd_hda_codec_write(codec, codec->afg, 0,
5295 AC_VERB_SET_GPIO_DATA, gpiostate);
5296}
5297
5298/* set up GPIO at initialization */
5299static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5300 const struct alc_fixup *fix, int action)
5301{
5302 if (action != ALC_FIXUP_ACT_INIT)
5303 return;
5304 alc882_gpio_mute(codec, 0, 0);
5305 alc882_gpio_mute(codec, 1, 0);
5306}
5307
Takashi Iwai02a237b2012-02-13 15:25:07 +01005308/* Fix the connection of some pins for ALC889:
5309 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5310 * work correctly (bko#42740)
5311 */
5312static void alc889_fixup_dac_route(struct hda_codec *codec,
5313 const struct alc_fixup *fix, int action)
5314{
5315 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005316 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005317 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5318 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5319 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5320 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5321 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5322 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005323 } else if (action == ALC_FIXUP_ACT_PROBE) {
5324 /* restore the connections */
5325 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5326 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5327 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5328 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5329 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005330 }
5331}
5332
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005333/* Set VREF on HP pin */
5334static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5335 const struct alc_fixup *fix, int action)
5336{
5337 struct alc_spec *spec = codec->spec;
5338 static hda_nid_t nids[2] = { 0x14, 0x15 };
5339 int i;
5340
5341 if (action != ALC_FIXUP_ACT_INIT)
5342 return;
5343 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5344 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5345 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5346 continue;
5347 val = snd_hda_codec_read(codec, nids[i], 0,
5348 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5349 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005350 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005351 spec->keep_vref_in_automute = 1;
5352 break;
5353 }
5354}
5355
5356/* Set VREF on speaker pins on imac91 */
5357static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5358 const struct alc_fixup *fix, int action)
5359{
5360 struct alc_spec *spec = codec->spec;
5361 static hda_nid_t nids[2] = { 0x18, 0x1a };
5362 int i;
5363
5364 if (action != ALC_FIXUP_ACT_INIT)
5365 return;
5366 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5367 unsigned int val;
5368 val = snd_hda_codec_read(codec, nids[i], 0,
5369 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5370 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005371 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005372 }
5373 spec->keep_vref_in_automute = 1;
5374}
5375
Takashi Iwaie427c232012-07-29 10:04:08 +02005376/* Don't take HP output as primary
5377 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5378 */
5379static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5380 const struct alc_fixup *fix, int action)
5381{
5382 struct alc_spec *spec = codec->spec;
5383 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5384 spec->no_primary_hp = 1;
5385}
5386
Takashi Iwai1d045db2011-07-07 18:23:21 +02005387static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005388 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005389 .type = ALC_FIXUP_PINS,
5390 .v.pins = (const struct alc_pincfg[]) {
5391 { 0x15, 0x01080104 }, /* side */
5392 { 0x16, 0x01011012 }, /* rear */
5393 { 0x17, 0x01016011 }, /* clfe */
5394 { }
5395 }
5396 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005397 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005398 .type = ALC_FIXUP_PINS,
5399 .v.pins = (const struct alc_pincfg[]) {
5400 { 0x15, 0x99130112 }, /* rear int speakers */
5401 { 0x16, 0x99130111 }, /* subwoofer */
5402 { }
5403 }
5404 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005405 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005406 .type = ALC_FIXUP_VERBS,
5407 .v.verbs = (const struct hda_verb[]) {
5408 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5409 {}
5410 }
5411 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005412 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005413 .type = ALC_FIXUP_FUNC,
5414 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005415 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005416 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005417 .type = ALC_FIXUP_PINS,
5418 .v.pins = (const struct alc_pincfg[]) {
5419 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5420 { }
5421 }
5422 },
Marton Balint8f239212012-03-05 21:33:23 +01005423 [ALC889_FIXUP_CD] = {
5424 .type = ALC_FIXUP_PINS,
5425 .v.pins = (const struct alc_pincfg[]) {
5426 { 0x1c, 0x993301f0 }, /* CD */
5427 { }
5428 }
5429 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005430 [ALC889_FIXUP_VAIO_TT] = {
5431 .type = ALC_FIXUP_PINS,
5432 .v.pins = (const struct alc_pincfg[]) {
5433 { 0x17, 0x90170111 }, /* hidden surround speaker */
5434 { }
5435 }
5436 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005437 [ALC888_FIXUP_EEE1601] = {
5438 .type = ALC_FIXUP_VERBS,
5439 .v.verbs = (const struct hda_verb[]) {
5440 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5441 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5442 { }
5443 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005444 },
5445 [ALC882_FIXUP_EAPD] = {
5446 .type = ALC_FIXUP_VERBS,
5447 .v.verbs = (const struct hda_verb[]) {
5448 /* change to EAPD mode */
5449 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5450 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5451 { }
5452 }
5453 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005454 [ALC883_FIXUP_EAPD] = {
5455 .type = ALC_FIXUP_VERBS,
5456 .v.verbs = (const struct hda_verb[]) {
5457 /* change to EAPD mode */
5458 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5459 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5460 { }
5461 }
5462 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005463 [ALC883_FIXUP_ACER_EAPD] = {
5464 .type = ALC_FIXUP_VERBS,
5465 .v.verbs = (const struct hda_verb[]) {
5466 /* eanable EAPD on Acer laptops */
5467 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5468 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5469 { }
5470 }
5471 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005472 [ALC882_FIXUP_GPIO1] = {
5473 .type = ALC_FIXUP_VERBS,
5474 .v.verbs = alc_gpio1_init_verbs,
5475 },
5476 [ALC882_FIXUP_GPIO2] = {
5477 .type = ALC_FIXUP_VERBS,
5478 .v.verbs = alc_gpio2_init_verbs,
5479 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005480 [ALC882_FIXUP_GPIO3] = {
5481 .type = ALC_FIXUP_VERBS,
5482 .v.verbs = alc_gpio3_init_verbs,
5483 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005484 [ALC882_FIXUP_ASUS_W2JC] = {
5485 .type = ALC_FIXUP_VERBS,
5486 .v.verbs = alc_gpio1_init_verbs,
5487 .chained = true,
5488 .chain_id = ALC882_FIXUP_EAPD,
5489 },
5490 [ALC889_FIXUP_COEF] = {
5491 .type = ALC_FIXUP_FUNC,
5492 .v.func = alc889_fixup_coef,
5493 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005494 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5495 .type = ALC_FIXUP_PINS,
5496 .v.pins = (const struct alc_pincfg[]) {
5497 { 0x16, 0x99130111 }, /* CLFE speaker */
5498 { 0x17, 0x99130112 }, /* surround speaker */
5499 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005500 },
5501 .chained = true,
5502 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005503 },
5504 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5505 .type = ALC_FIXUP_PINS,
5506 .v.pins = (const struct alc_pincfg[]) {
5507 { 0x16, 0x99130111 }, /* CLFE speaker */
5508 { 0x1b, 0x99130112 }, /* surround speaker */
5509 { }
5510 },
5511 .chained = true,
5512 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5513 },
5514 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5515 /* additional init verbs for Acer Aspire 8930G */
5516 .type = ALC_FIXUP_VERBS,
5517 .v.verbs = (const struct hda_verb[]) {
5518 /* Enable all DACs */
5519 /* DAC DISABLE/MUTE 1? */
5520 /* setting bits 1-5 disables DAC nids 0x02-0x06
5521 * apparently. Init=0x38 */
5522 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5523 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5524 /* DAC DISABLE/MUTE 2? */
5525 /* some bit here disables the other DACs.
5526 * Init=0x4900 */
5527 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5528 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5529 /* DMIC fix
5530 * This laptop has a stereo digital microphone.
5531 * The mics are only 1cm apart which makes the stereo
5532 * useless. However, either the mic or the ALC889
5533 * makes the signal become a difference/sum signal
5534 * instead of standard stereo, which is annoying.
5535 * So instead we flip this bit which makes the
5536 * codec replicate the sum signal to both channels,
5537 * turning it into a normal mono mic.
5538 */
5539 /* DMIC_CONTROL? Init value = 0x0001 */
5540 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5541 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5542 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5543 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5544 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005545 },
5546 .chained = true,
5547 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005548 },
Takashi Iwai56710872011-11-14 17:42:11 +01005549 [ALC885_FIXUP_MACPRO_GPIO] = {
5550 .type = ALC_FIXUP_FUNC,
5551 .v.func = alc885_fixup_macpro_gpio,
5552 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005553 [ALC889_FIXUP_DAC_ROUTE] = {
5554 .type = ALC_FIXUP_FUNC,
5555 .v.func = alc889_fixup_dac_route,
5556 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005557 [ALC889_FIXUP_MBP_VREF] = {
5558 .type = ALC_FIXUP_FUNC,
5559 .v.func = alc889_fixup_mbp_vref,
5560 .chained = true,
5561 .chain_id = ALC882_FIXUP_GPIO1,
5562 },
5563 [ALC889_FIXUP_IMAC91_VREF] = {
5564 .type = ALC_FIXUP_FUNC,
5565 .v.func = alc889_fixup_imac91_vref,
5566 .chained = true,
5567 .chain_id = ALC882_FIXUP_GPIO1,
5568 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005569 [ALC882_FIXUP_INV_DMIC] = {
5570 .type = ALC_FIXUP_FUNC,
5571 .v.func = alc_fixup_inv_dmic_0x12,
5572 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005573 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5574 .type = ALC_FIXUP_FUNC,
5575 .v.func = alc882_fixup_no_primary_hp,
5576 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005577};
5578
5579static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005580 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5581 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5582 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5583 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5584 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5585 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005586 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5587 ALC882_FIXUP_ACER_ASPIRE_4930G),
5588 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5589 ALC882_FIXUP_ACER_ASPIRE_4930G),
5590 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5591 ALC882_FIXUP_ACER_ASPIRE_8930G),
5592 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5593 ALC882_FIXUP_ACER_ASPIRE_8930G),
5594 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5595 ALC882_FIXUP_ACER_ASPIRE_4930G),
5596 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5597 ALC882_FIXUP_ACER_ASPIRE_4930G),
5598 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5599 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005600 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005601 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5602 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005603 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005604 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005605 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005606 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005607 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005608 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005609 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005610 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005611 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005612
5613 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005614 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5615 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5616 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005617 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5618 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5619 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005620 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5621 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005622 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005623 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5624 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5625 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5626 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005627 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005628 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5629 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5630 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005631 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005632 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005633 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5634 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5635 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005636
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005637 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005638 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005639 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005640 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005641 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005642 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5643 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005644 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005645 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005646 {}
5647};
5648
Takashi Iwai912093b2012-04-11 14:03:41 +02005649static const struct alc_model_fixup alc882_fixup_models[] = {
5650 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5651 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5652 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005653 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005654 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005655 {}
5656};
5657
Takashi Iwai1d045db2011-07-07 18:23:21 +02005658/*
5659 * BIOS auto configuration
5660 */
5661/* almost identical with ALC880 parser... */
5662static int alc882_parse_auto_config(struct hda_codec *codec)
5663{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005664 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005665 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5666 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005667}
5668
Takashi Iwai1d045db2011-07-07 18:23:21 +02005669/*
5670 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005671static int patch_alc882(struct hda_codec *codec)
5672{
5673 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005674 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005675
Takashi Iwai3de95172012-05-07 18:03:15 +02005676 err = alc_alloc_spec(codec, 0x0b);
5677 if (err < 0)
5678 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005679
Takashi Iwai3de95172012-05-07 18:03:15 +02005680 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005681
5682 switch (codec->vendor_id) {
5683 case 0x10ec0882:
5684 case 0x10ec0885:
5685 break;
5686 default:
5687 /* ALC883 and variants */
5688 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5689 break;
5690 }
5691
Takashi Iwai912093b2012-04-11 14:03:41 +02005692 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5693 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005694 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005695
5696 alc_auto_parse_customize_define(codec);
5697
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005698 /* automatic parse from the BIOS config */
5699 err = alc882_parse_auto_config(codec);
5700 if (err < 0)
5701 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005702
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005703 if (!spec->no_analog && has_cdefine_beep(codec)) {
5704 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005705 if (err < 0)
5706 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005707 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005708 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005709
Takashi Iwai1d045db2011-07-07 18:23:21 +02005710 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711
Takashi Iwai589876e2012-02-20 15:47:55 +01005712 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5713
Takashi Iwai1d045db2011-07-07 18:23:21 +02005714 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005715
5716 error:
5717 alc_free(codec);
5718 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719}
5720
5721
5722/*
5723 * ALC262 support
5724 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005725static int alc262_parse_auto_config(struct hda_codec *codec)
5726{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005728 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5729 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005730}
5731
5732/*
5733 * Pin config fixes
5734 */
5735enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005736 ALC262_FIXUP_FSC_H270,
5737 ALC262_FIXUP_HP_Z200,
5738 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005739 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005740 ALC262_FIXUP_BENQ,
5741 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005742 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743};
5744
5745static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005746 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005747 .type = ALC_FIXUP_PINS,
5748 .v.pins = (const struct alc_pincfg[]) {
5749 { 0x14, 0x99130110 }, /* speaker */
5750 { 0x15, 0x0221142f }, /* front HP */
5751 { 0x1b, 0x0121141f }, /* rear HP */
5752 { }
5753 }
5754 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005755 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005756 .type = ALC_FIXUP_PINS,
5757 .v.pins = (const struct alc_pincfg[]) {
5758 { 0x16, 0x99130120 }, /* internal speaker */
5759 { }
5760 }
5761 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005762 [ALC262_FIXUP_TYAN] = {
5763 .type = ALC_FIXUP_PINS,
5764 .v.pins = (const struct alc_pincfg[]) {
5765 { 0x14, 0x1993e1f0 }, /* int AUX */
5766 { }
5767 }
5768 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005769 [ALC262_FIXUP_LENOVO_3000] = {
5770 .type = ALC_FIXUP_VERBS,
5771 .v.verbs = (const struct hda_verb[]) {
5772 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005773 {}
5774 },
5775 .chained = true,
5776 .chain_id = ALC262_FIXUP_BENQ,
5777 },
5778 [ALC262_FIXUP_BENQ] = {
5779 .type = ALC_FIXUP_VERBS,
5780 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005781 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5782 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5783 {}
5784 }
5785 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005786 [ALC262_FIXUP_BENQ_T31] = {
5787 .type = ALC_FIXUP_VERBS,
5788 .v.verbs = (const struct hda_verb[]) {
5789 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5790 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5791 {}
5792 }
5793 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005794 [ALC262_FIXUP_INV_DMIC] = {
5795 .type = ALC_FIXUP_FUNC,
5796 .v.func = alc_fixup_inv_dmic_0x12,
5797 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798};
5799
5800static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005801 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005802 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5803 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005804 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5805 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005806 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005807 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5808 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005809 {}
5810};
5811
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005812static const struct alc_model_fixup alc262_fixup_models[] = {
5813 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5814 {}
5815};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005816
Takashi Iwai1d045db2011-07-07 18:23:21 +02005817/*
5818 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005819static int patch_alc262(struct hda_codec *codec)
5820{
5821 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005822 int err;
5823
Takashi Iwai3de95172012-05-07 18:03:15 +02005824 err = alc_alloc_spec(codec, 0x0b);
5825 if (err < 0)
5826 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005827
Takashi Iwai3de95172012-05-07 18:03:15 +02005828 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829
5830#if 0
5831 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5832 * under-run
5833 */
5834 {
5835 int tmp;
5836 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5837 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5838 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5839 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5840 }
5841#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005842 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5843
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005844 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5845 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005846 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005847
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005848 alc_auto_parse_customize_define(codec);
5849
Takashi Iwai42399f72011-11-07 17:18:44 +01005850 /* automatic parse from the BIOS config */
5851 err = alc262_parse_auto_config(codec);
5852 if (err < 0)
5853 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005854
Takashi Iwai1d045db2011-07-07 18:23:21 +02005855 if (!spec->no_analog && has_cdefine_beep(codec)) {
5856 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005857 if (err < 0)
5858 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005859 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005860 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005861
Takashi Iwai1d045db2011-07-07 18:23:21 +02005862 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005863 spec->shutup = alc_eapd_shutup;
5864
Takashi Iwai589876e2012-02-20 15:47:55 +01005865 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5866
Takashi Iwai1d045db2011-07-07 18:23:21 +02005867 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005868
5869 error:
5870 alc_free(codec);
5871 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005872}
5873
5874/*
5875 * ALC268
5876 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005877/* bind Beep switches of both NID 0x0f and 0x10 */
5878static const struct hda_bind_ctls alc268_bind_beep_sw = {
5879 .ops = &snd_hda_bind_sw,
5880 .values = {
5881 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5882 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5883 0
5884 },
5885};
5886
5887static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5888 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5889 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5890 { }
5891};
5892
5893/* set PCBEEP vol = 0, mute connections */
5894static const struct hda_verb alc268_beep_init_verbs[] = {
5895 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5896 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5897 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5898 { }
5899};
5900
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005901enum {
5902 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005903 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005904};
5905
5906static const struct alc_fixup alc268_fixups[] = {
5907 [ALC268_FIXUP_INV_DMIC] = {
5908 .type = ALC_FIXUP_FUNC,
5909 .v.func = alc_fixup_inv_dmic_0x12,
5910 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005911 [ALC268_FIXUP_HP_EAPD] = {
5912 .type = ALC_FIXUP_VERBS,
5913 .v.verbs = (const struct hda_verb[]) {
5914 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5915 {}
5916 }
5917 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005918};
5919
5920static const struct alc_model_fixup alc268_fixup_models[] = {
5921 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005922 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5923 {}
5924};
5925
5926static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5927 /* below is codec SSID since multiple Toshiba laptops have the
5928 * same PCI SSID 1179:ff00
5929 */
5930 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005931 {}
5932};
5933
Takashi Iwai1d045db2011-07-07 18:23:21 +02005934/*
5935 * BIOS auto configuration
5936 */
5937static int alc268_parse_auto_config(struct hda_codec *codec)
5938{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005939 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005940 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005941 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5942 if (err > 0) {
5943 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5944 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005945 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005946 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005947 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005948 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005949}
5950
Takashi Iwai1d045db2011-07-07 18:23:21 +02005951/*
5952 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005953static int patch_alc268(struct hda_codec *codec)
5954{
5955 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005956 int i, has_beep, err;
5957
Takashi Iwai1d045db2011-07-07 18:23:21 +02005958 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005959 err = alc_alloc_spec(codec, 0);
5960 if (err < 0)
5961 return err;
5962
5963 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005964
Takashi Iwaicb766402012-10-20 10:55:21 +02005965 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005966 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5967
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005968 /* automatic parse from the BIOS config */
5969 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005970 if (err < 0)
5971 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005972
Takashi Iwai1d045db2011-07-07 18:23:21 +02005973 has_beep = 0;
5974 for (i = 0; i < spec->num_mixers; i++) {
5975 if (spec->mixers[i] == alc268_beep_mixer) {
5976 has_beep = 1;
5977 break;
5978 }
5979 }
5980
5981 if (has_beep) {
5982 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005983 if (err < 0)
5984 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005985 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5986 /* override the amp caps for beep generator */
5987 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5988 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5989 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5990 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5991 (0 << AC_AMPCAP_MUTE_SHIFT));
5992 }
5993
Takashi Iwai1d045db2011-07-07 18:23:21 +02005994 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005995 spec->shutup = alc_eapd_shutup;
5996
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005997 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5998
Takashi Iwai1d045db2011-07-07 18:23:21 +02005999 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006000
6001 error:
6002 alc_free(codec);
6003 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006004}
6005
6006/*
6007 * ALC269
6008 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006009static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6010 .substreams = 1,
6011 .channels_min = 2,
6012 .channels_max = 8,
6013 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6014 /* NID is set in alc_build_pcms */
6015 .ops = {
6016 .open = alc_playback_pcm_open,
6017 .prepare = alc_playback_pcm_prepare,
6018 .cleanup = alc_playback_pcm_cleanup
6019 },
6020};
6021
6022static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6023 .substreams = 1,
6024 .channels_min = 2,
6025 .channels_max = 2,
6026 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6027 /* NID is set in alc_build_pcms */
6028};
6029
Takashi Iwai1d045db2011-07-07 18:23:21 +02006030/* different alc269-variants */
6031enum {
6032 ALC269_TYPE_ALC269VA,
6033 ALC269_TYPE_ALC269VB,
6034 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006035 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006036 ALC269_TYPE_ALC280,
6037 ALC269_TYPE_ALC282,
6038 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006039};
6040
6041/*
6042 * BIOS auto configuration
6043 */
6044static int alc269_parse_auto_config(struct hda_codec *codec)
6045{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006046 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006047 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6048 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6049 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006050 const hda_nid_t *ssids;
6051
6052 switch (spec->codec_variant) {
6053 case ALC269_TYPE_ALC269VA:
6054 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006055 case ALC269_TYPE_ALC280:
6056 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006057 ssids = alc269va_ssids;
6058 break;
6059 case ALC269_TYPE_ALC269VB:
6060 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006061 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006062 ssids = alc269_ssids;
6063 break;
6064 default:
6065 ssids = alc269_ssids;
6066 break;
6067 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006068
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006069 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006070}
6071
Kailang Yang1387e2d2012-11-08 10:23:18 +01006072static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006073{
6074 int val = alc_read_coef_idx(codec, 0x04);
6075 if (power_up)
6076 val |= 1 << 11;
6077 else
6078 val &= ~(1 << 11);
6079 alc_write_coef_idx(codec, 0x04, val);
6080}
6081
6082static void alc269_shutup(struct hda_codec *codec)
6083{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006084 struct alc_spec *spec = codec->spec;
6085
6086 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6087 return;
6088
Kailang Yang1387e2d2012-11-08 10:23:18 +01006089 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6090 alc269vb_toggle_power_output(codec, 0);
6091 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6092 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006093 msleep(150);
6094 }
6095}
6096
Takashi Iwai2a439522011-07-26 09:52:50 +02006097#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006098static int alc269_resume(struct hda_codec *codec)
6099{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006100 struct alc_spec *spec = codec->spec;
6101
Kailang Yang1387e2d2012-11-08 10:23:18 +01006102 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6103 alc269vb_toggle_power_output(codec, 0);
6104 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006105 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006106 msleep(150);
6107 }
6108
6109 codec->patch_ops.init(codec);
6110
Kailang Yang1387e2d2012-11-08 10:23:18 +01006111 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6112 alc269vb_toggle_power_output(codec, 1);
6113 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006114 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006115 msleep(200);
6116 }
6117
Takashi Iwai1d045db2011-07-07 18:23:21 +02006118 snd_hda_codec_resume_amp(codec);
6119 snd_hda_codec_resume_cache(codec);
6120 hda_call_check_power_status(codec, 0x01);
6121 return 0;
6122}
Takashi Iwai2a439522011-07-26 09:52:50 +02006123#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006124
David Henningsson108cc102012-07-20 10:37:25 +02006125static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6126 const struct alc_fixup *fix, int action)
6127{
6128 struct alc_spec *spec = codec->spec;
6129
6130 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6131 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6132}
6133
Takashi Iwai1d045db2011-07-07 18:23:21 +02006134static void alc269_fixup_hweq(struct hda_codec *codec,
6135 const struct alc_fixup *fix, int action)
6136{
6137 int coef;
6138
6139 if (action != ALC_FIXUP_ACT_INIT)
6140 return;
6141 coef = alc_read_coef_idx(codec, 0x1e);
6142 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6143}
6144
6145static void alc271_fixup_dmic(struct hda_codec *codec,
6146 const struct alc_fixup *fix, int action)
6147{
6148 static const struct hda_verb verbs[] = {
6149 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6150 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6151 {}
6152 };
6153 unsigned int cfg;
6154
6155 if (strcmp(codec->chip_name, "ALC271X"))
6156 return;
6157 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6158 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6159 snd_hda_sequence_write(codec, verbs);
6160}
6161
Takashi Iwai017f2a12011-07-09 14:42:25 +02006162static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6163 const struct alc_fixup *fix, int action)
6164{
6165 struct alc_spec *spec = codec->spec;
6166
6167 if (action != ALC_FIXUP_ACT_PROBE)
6168 return;
6169
6170 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6171 * fix the sample rate of analog I/O to 44.1kHz
6172 */
6173 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6174 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6175}
6176
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006177static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6178 const struct alc_fixup *fix, int action)
6179{
6180 int coef;
6181
6182 if (action != ALC_FIXUP_ACT_INIT)
6183 return;
6184 /* The digital-mic unit sends PDM (differential signal) instead of
6185 * the standard PCM, thus you can't record a valid mono stream as is.
6186 * Below is a workaround specific to ALC269 to control the dmic
6187 * signal source as mono.
6188 */
6189 coef = alc_read_coef_idx(codec, 0x07);
6190 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6191}
6192
Takashi Iwai24519912011-08-16 15:08:49 +02006193static void alc269_quanta_automute(struct hda_codec *codec)
6194{
David Henningsson42cf0d02011-09-20 12:04:56 +02006195 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006196
6197 snd_hda_codec_write(codec, 0x20, 0,
6198 AC_VERB_SET_COEF_INDEX, 0x0c);
6199 snd_hda_codec_write(codec, 0x20, 0,
6200 AC_VERB_SET_PROC_COEF, 0x680);
6201
6202 snd_hda_codec_write(codec, 0x20, 0,
6203 AC_VERB_SET_COEF_INDEX, 0x0c);
6204 snd_hda_codec_write(codec, 0x20, 0,
6205 AC_VERB_SET_PROC_COEF, 0x480);
6206}
6207
6208static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6209 const struct alc_fixup *fix, int action)
6210{
6211 struct alc_spec *spec = codec->spec;
6212 if (action != ALC_FIXUP_ACT_PROBE)
6213 return;
6214 spec->automute_hook = alc269_quanta_automute;
6215}
6216
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006217/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6218static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6219{
6220 struct hda_codec *codec = private_data;
6221 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6222 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6223 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6224}
6225
6226static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6227 const struct alc_fixup *fix, int action)
6228{
6229 struct alc_spec *spec = codec->spec;
6230 switch (action) {
6231 case ALC_FIXUP_ACT_BUILD:
6232 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6233 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6234 /* fallthru */
6235 case ALC_FIXUP_ACT_INIT:
6236 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6237 break;
6238 }
6239}
6240
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006241/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6242static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6243{
6244 struct hda_codec *codec = private_data;
6245 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006246 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006247}
6248
6249static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6250 const struct alc_fixup *fix, int action)
6251{
6252 struct alc_spec *spec = codec->spec;
6253 switch (action) {
6254 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006255 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006256 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006257 /* fallthru */
6258 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006259 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006260 break;
6261 }
6262}
6263
Dylan Reid08a978d2012-11-18 22:56:40 -08006264static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6265 const struct alc_fixup *fix,
6266 int action)
6267{
6268 struct alc_spec *spec = codec->spec;
6269
6270 if (action == ALC_FIXUP_ACT_PROBE)
6271 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6272 spec->autocfg.hp_pins[0]);
6273}
David Henningsson693b6132012-06-22 19:12:10 +02006274
Takashi Iwai1d045db2011-07-07 18:23:21 +02006275enum {
6276 ALC269_FIXUP_SONY_VAIO,
6277 ALC275_FIXUP_SONY_VAIO_GPIO2,
6278 ALC269_FIXUP_DELL_M101Z,
6279 ALC269_FIXUP_SKU_IGNORE,
6280 ALC269_FIXUP_ASUS_G73JW,
6281 ALC269_FIXUP_LENOVO_EAPD,
6282 ALC275_FIXUP_SONY_HWEQ,
6283 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006284 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006285 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006286 ALC269_FIXUP_QUANTA_MUTE,
6287 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006288 ALC269_FIXUP_AMIC,
6289 ALC269_FIXUP_DMIC,
6290 ALC269VB_FIXUP_AMIC,
6291 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006292 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006293 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006294 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006295 ALC269_FIXUP_LENOVO_DOCK,
6296 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006297 ALC271_FIXUP_AMIC_MIC2,
6298 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299};
6300
6301static const struct alc_fixup alc269_fixups[] = {
6302 [ALC269_FIXUP_SONY_VAIO] = {
6303 .type = ALC_FIXUP_VERBS,
6304 .v.verbs = (const struct hda_verb[]) {
6305 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6306 {}
6307 }
6308 },
6309 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6310 .type = ALC_FIXUP_VERBS,
6311 .v.verbs = (const struct hda_verb[]) {
6312 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6313 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6314 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6315 { }
6316 },
6317 .chained = true,
6318 .chain_id = ALC269_FIXUP_SONY_VAIO
6319 },
6320 [ALC269_FIXUP_DELL_M101Z] = {
6321 .type = ALC_FIXUP_VERBS,
6322 .v.verbs = (const struct hda_verb[]) {
6323 /* Enables internal speaker */
6324 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6325 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6326 {}
6327 }
6328 },
6329 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006330 .type = ALC_FIXUP_FUNC,
6331 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006332 },
6333 [ALC269_FIXUP_ASUS_G73JW] = {
6334 .type = ALC_FIXUP_PINS,
6335 .v.pins = (const struct alc_pincfg[]) {
6336 { 0x17, 0x99130111 }, /* subwoofer */
6337 { }
6338 }
6339 },
6340 [ALC269_FIXUP_LENOVO_EAPD] = {
6341 .type = ALC_FIXUP_VERBS,
6342 .v.verbs = (const struct hda_verb[]) {
6343 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6344 {}
6345 }
6346 },
6347 [ALC275_FIXUP_SONY_HWEQ] = {
6348 .type = ALC_FIXUP_FUNC,
6349 .v.func = alc269_fixup_hweq,
6350 .chained = true,
6351 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6352 },
6353 [ALC271_FIXUP_DMIC] = {
6354 .type = ALC_FIXUP_FUNC,
6355 .v.func = alc271_fixup_dmic,
6356 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006357 [ALC269_FIXUP_PCM_44K] = {
6358 .type = ALC_FIXUP_FUNC,
6359 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006360 .chained = true,
6361 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006362 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006363 [ALC269_FIXUP_STEREO_DMIC] = {
6364 .type = ALC_FIXUP_FUNC,
6365 .v.func = alc269_fixup_stereo_dmic,
6366 },
Takashi Iwai24519912011-08-16 15:08:49 +02006367 [ALC269_FIXUP_QUANTA_MUTE] = {
6368 .type = ALC_FIXUP_FUNC,
6369 .v.func = alc269_fixup_quanta_mute,
6370 },
6371 [ALC269_FIXUP_LIFEBOOK] = {
6372 .type = ALC_FIXUP_PINS,
6373 .v.pins = (const struct alc_pincfg[]) {
6374 { 0x1a, 0x2101103f }, /* dock line-out */
6375 { 0x1b, 0x23a11040 }, /* dock mic-in */
6376 { }
6377 },
6378 .chained = true,
6379 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6380 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006381 [ALC269_FIXUP_AMIC] = {
6382 .type = ALC_FIXUP_PINS,
6383 .v.pins = (const struct alc_pincfg[]) {
6384 { 0x14, 0x99130110 }, /* speaker */
6385 { 0x15, 0x0121401f }, /* HP out */
6386 { 0x18, 0x01a19c20 }, /* mic */
6387 { 0x19, 0x99a3092f }, /* int-mic */
6388 { }
6389 },
6390 },
6391 [ALC269_FIXUP_DMIC] = {
6392 .type = ALC_FIXUP_PINS,
6393 .v.pins = (const struct alc_pincfg[]) {
6394 { 0x12, 0x99a3092f }, /* int-mic */
6395 { 0x14, 0x99130110 }, /* speaker */
6396 { 0x15, 0x0121401f }, /* HP out */
6397 { 0x18, 0x01a19c20 }, /* mic */
6398 { }
6399 },
6400 },
6401 [ALC269VB_FIXUP_AMIC] = {
6402 .type = ALC_FIXUP_PINS,
6403 .v.pins = (const struct alc_pincfg[]) {
6404 { 0x14, 0x99130110 }, /* speaker */
6405 { 0x18, 0x01a19c20 }, /* mic */
6406 { 0x19, 0x99a3092f }, /* int-mic */
6407 { 0x21, 0x0121401f }, /* HP out */
6408 { }
6409 },
6410 },
David Henningsson2267ea92012-01-03 08:45:56 +01006411 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006412 .type = ALC_FIXUP_PINS,
6413 .v.pins = (const struct alc_pincfg[]) {
6414 { 0x12, 0x99a3092f }, /* int-mic */
6415 { 0x14, 0x99130110 }, /* speaker */
6416 { 0x18, 0x01a19c20 }, /* mic */
6417 { 0x21, 0x0121401f }, /* HP out */
6418 { }
6419 },
6420 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006421 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6422 .type = ALC_FIXUP_FUNC,
6423 .v.func = alc269_fixup_mic1_mute,
6424 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006425 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6426 .type = ALC_FIXUP_FUNC,
6427 .v.func = alc269_fixup_mic2_mute,
6428 },
David Henningsson693b6132012-06-22 19:12:10 +02006429 [ALC269_FIXUP_INV_DMIC] = {
6430 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006431 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006432 },
David Henningsson108cc102012-07-20 10:37:25 +02006433 [ALC269_FIXUP_LENOVO_DOCK] = {
6434 .type = ALC_FIXUP_PINS,
6435 .v.pins = (const struct alc_pincfg[]) {
6436 { 0x19, 0x23a11040 }, /* dock mic */
6437 { 0x1b, 0x2121103f }, /* dock headphone */
6438 { }
6439 },
6440 .chained = true,
6441 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6442 },
6443 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6444 .type = ALC_FIXUP_FUNC,
6445 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6446 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006447 [ALC271_FIXUP_AMIC_MIC2] = {
6448 .type = ALC_FIXUP_PINS,
6449 .v.pins = (const struct alc_pincfg[]) {
6450 { 0x14, 0x99130110 }, /* speaker */
6451 { 0x19, 0x01a19c20 }, /* mic */
6452 { 0x1b, 0x99a7012f }, /* int-mic */
6453 { 0x21, 0x0121401f }, /* HP out */
6454 { }
6455 },
6456 },
6457 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6458 .type = ALC_FIXUP_FUNC,
6459 .v.func = alc271_hp_gate_mic_jack,
6460 .chained = true,
6461 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6462 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006463};
6464
6465static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006466 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6467 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006468 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006469 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006470 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006471 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006472 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006473 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006474 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6475 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6476 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6477 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6478 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006479 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6480 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6481 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6482 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6483 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006484 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006485 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006486 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006487 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6488 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6489 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6490 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6491 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006492 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006493 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006494 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006495 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006496 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006497 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006498 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006499
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006500#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006501 /* Below is a quirk table taken from the old code.
6502 * Basically the device should work as is without the fixup table.
6503 * If BIOS doesn't give a proper info, enable the corresponding
6504 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006505 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006506 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6507 ALC269_FIXUP_AMIC),
6508 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006509 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6510 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6511 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6512 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6513 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6514 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6515 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6516 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6517 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6518 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6519 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6520 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6521 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6522 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6523 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6524 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6525 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6526 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6527 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6528 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6529 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6530 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6531 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6532 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6533 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6534 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6535 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6536 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6537 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6538 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6539 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6540 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6541 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6542 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6543 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6544 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6545 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6546 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6547#endif
6548 {}
6549};
6550
6551static const struct alc_model_fixup alc269_fixup_models[] = {
6552 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6553 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006554 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6555 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6556 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006557 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006558 {}
6559};
6560
6561
Takashi Iwai546bb672012-03-07 08:37:19 +01006562static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006563{
Kailang Yang526af6e2012-03-07 08:25:20 +01006564 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006565 int val;
6566
Kailang Yang526af6e2012-03-07 08:25:20 +01006567 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006568 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006569
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006570 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006571 alc_write_coef_idx(codec, 0xf, 0x960b);
6572 alc_write_coef_idx(codec, 0xe, 0x8817);
6573 }
6574
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006575 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006576 alc_write_coef_idx(codec, 0xf, 0x960b);
6577 alc_write_coef_idx(codec, 0xe, 0x8814);
6578 }
6579
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006580 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006581 val = alc_read_coef_idx(codec, 0x04);
6582 /* Power up output pin */
6583 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6584 }
6585
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006586 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006587 val = alc_read_coef_idx(codec, 0xd);
6588 if ((val & 0x0c00) >> 10 != 0x1) {
6589 /* Capless ramp up clock control */
6590 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6591 }
6592 val = alc_read_coef_idx(codec, 0x17);
6593 if ((val & 0x01c0) >> 6 != 0x4) {
6594 /* Class D power on reset */
6595 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6596 }
6597 }
6598
6599 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6600 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6601
6602 val = alc_read_coef_idx(codec, 0x4); /* HP */
6603 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006604}
6605
6606/*
6607 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006608static int patch_alc269(struct hda_codec *codec)
6609{
6610 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006611 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006612
Takashi Iwai3de95172012-05-07 18:03:15 +02006613 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006614 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006615 return err;
6616
6617 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006618
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006619 alc_pick_fixup(codec, alc269_fixup_models,
6620 alc269_fixup_tbl, alc269_fixups);
6621 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6622
6623 alc_auto_parse_customize_define(codec);
6624
Kailang Yang065380f2013-01-10 10:25:48 +01006625 switch (codec->vendor_id) {
6626 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006627 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006628 switch (alc_get_coef0(codec) & 0x00f0) {
6629 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006630 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006631 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006632 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006633 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006634 break;
6635 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006636 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6637 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006638 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006639 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006640 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006641 case 0x0030:
6642 spec->codec_variant = ALC269_TYPE_ALC269VD;
6643 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006644 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006645 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006646 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006647 if (err < 0)
6648 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006649 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006650 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006651 break;
6652
6653 case 0x10ec0280:
6654 case 0x10ec0290:
6655 spec->codec_variant = ALC269_TYPE_ALC280;
6656 break;
6657 case 0x10ec0282:
6658 case 0x10ec0283:
6659 spec->codec_variant = ALC269_TYPE_ALC282;
6660 break;
6661 case 0x10ec0284:
6662 case 0x10ec0292:
6663 spec->codec_variant = ALC269_TYPE_ALC284;
6664 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006665 }
6666
Takashi Iwaia4297b52011-08-23 18:40:12 +02006667 /* automatic parse from the BIOS config */
6668 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006669 if (err < 0)
6670 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006671
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006672 if (!spec->no_analog && has_cdefine_beep(codec)) {
6673 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006674 if (err < 0)
6675 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006676 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006677 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006678
Takashi Iwai1d045db2011-07-07 18:23:21 +02006679 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006680#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006681 codec->patch_ops.resume = alc269_resume;
6682#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006683 spec->shutup = alc269_shutup;
6684
Takashi Iwai589876e2012-02-20 15:47:55 +01006685 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6686
Takashi Iwai1d045db2011-07-07 18:23:21 +02006687 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006688
6689 error:
6690 alc_free(codec);
6691 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006692}
6693
6694/*
6695 * ALC861
6696 */
6697
Takashi Iwai1d045db2011-07-07 18:23:21 +02006698static int alc861_parse_auto_config(struct hda_codec *codec)
6699{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006700 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006701 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6702 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006703}
6704
Takashi Iwai1d045db2011-07-07 18:23:21 +02006705/* Pin config fixes */
6706enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006707 ALC861_FIXUP_FSC_AMILO_PI1505,
6708 ALC861_FIXUP_AMP_VREF_0F,
6709 ALC861_FIXUP_NO_JACK_DETECT,
6710 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006711};
6712
Takashi Iwai31150f22012-01-30 10:54:08 +01006713/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6714static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6715 const struct alc_fixup *fix, int action)
6716{
6717 struct alc_spec *spec = codec->spec;
6718 unsigned int val;
6719
6720 if (action != ALC_FIXUP_ACT_INIT)
6721 return;
6722 val = snd_hda_codec_read(codec, 0x0f, 0,
6723 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6724 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6725 val |= AC_PINCTL_IN_EN;
6726 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006727 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006728 spec->keep_vref_in_automute = 1;
6729}
6730
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006731/* suppress the jack-detection */
6732static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6733 const struct alc_fixup *fix, int action)
6734{
6735 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6736 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006737}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006738
Takashi Iwai1d045db2011-07-07 18:23:21 +02006739static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006740 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006741 .type = ALC_FIXUP_PINS,
6742 .v.pins = (const struct alc_pincfg[]) {
6743 { 0x0b, 0x0221101f }, /* HP */
6744 { 0x0f, 0x90170310 }, /* speaker */
6745 { }
6746 }
6747 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006748 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006749 .type = ALC_FIXUP_FUNC,
6750 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006751 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006752 [ALC861_FIXUP_NO_JACK_DETECT] = {
6753 .type = ALC_FIXUP_FUNC,
6754 .v.func = alc_fixup_no_jack_detect,
6755 },
6756 [ALC861_FIXUP_ASUS_A6RP] = {
6757 .type = ALC_FIXUP_FUNC,
6758 .v.func = alc861_fixup_asus_amp_vref_0f,
6759 .chained = true,
6760 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6761 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006762};
6763
6764static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006765 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6766 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6767 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6768 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6769 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6770 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006771 {}
6772};
6773
6774/*
6775 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006776static int patch_alc861(struct hda_codec *codec)
6777{
6778 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006779 int err;
6780
Takashi Iwai3de95172012-05-07 18:03:15 +02006781 err = alc_alloc_spec(codec, 0x15);
6782 if (err < 0)
6783 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006784
Takashi Iwai3de95172012-05-07 18:03:15 +02006785 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006786
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006787 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6788 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006789
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006790 /* automatic parse from the BIOS config */
6791 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006792 if (err < 0)
6793 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006794
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006795 if (!spec->no_analog) {
6796 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006797 if (err < 0)
6798 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006799 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6800 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006801
Takashi Iwai1d045db2011-07-07 18:23:21 +02006802 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006803#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006804 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006805#endif
6806
Takashi Iwai589876e2012-02-20 15:47:55 +01006807 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6808
Takashi Iwai1d045db2011-07-07 18:23:21 +02006809 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006810
6811 error:
6812 alc_free(codec);
6813 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006814}
6815
6816/*
6817 * ALC861-VD support
6818 *
6819 * Based on ALC882
6820 *
6821 * In addition, an independent DAC
6822 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006823static int alc861vd_parse_auto_config(struct hda_codec *codec)
6824{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006825 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006826 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6827 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006828}
6829
Takashi Iwai1d045db2011-07-07 18:23:21 +02006830enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006831 ALC660VD_FIX_ASUS_GPIO1,
6832 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006833};
6834
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006835/* exclude VREF80 */
6836static void alc861vd_fixup_dallas(struct hda_codec *codec,
6837 const struct alc_fixup *fix, int action)
6838{
6839 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006840 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6841 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006842 }
6843}
6844
Takashi Iwai1d045db2011-07-07 18:23:21 +02006845static const struct alc_fixup alc861vd_fixups[] = {
6846 [ALC660VD_FIX_ASUS_GPIO1] = {
6847 .type = ALC_FIXUP_VERBS,
6848 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006849 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006850 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6851 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6852 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6853 { }
6854 }
6855 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006856 [ALC861VD_FIX_DALLAS] = {
6857 .type = ALC_FIXUP_FUNC,
6858 .v.func = alc861vd_fixup_dallas,
6859 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006860};
6861
6862static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006863 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006864 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006865 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006866 {}
6867};
6868
Takashi Iwai1d045db2011-07-07 18:23:21 +02006869/*
6870 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006871static int patch_alc861vd(struct hda_codec *codec)
6872{
6873 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006874 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006875
Takashi Iwai3de95172012-05-07 18:03:15 +02006876 err = alc_alloc_spec(codec, 0x0b);
6877 if (err < 0)
6878 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006879
Takashi Iwai3de95172012-05-07 18:03:15 +02006880 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006881
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006882 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6883 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006884
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006885 /* automatic parse from the BIOS config */
6886 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006887 if (err < 0)
6888 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006889
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006890 if (!spec->no_analog) {
6891 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006892 if (err < 0)
6893 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006894 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6895 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006896
Takashi Iwai1d045db2011-07-07 18:23:21 +02006897 codec->patch_ops = alc_patch_ops;
6898
Takashi Iwai1d045db2011-07-07 18:23:21 +02006899 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006900
Takashi Iwai589876e2012-02-20 15:47:55 +01006901 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6902
Takashi Iwai1d045db2011-07-07 18:23:21 +02006903 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006904
6905 error:
6906 alc_free(codec);
6907 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006908}
6909
6910/*
6911 * ALC662 support
6912 *
6913 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6914 * configuration. Each pin widget can choose any input DACs and a mixer.
6915 * Each ADC is connected from a mixer of all inputs. This makes possible
6916 * 6-channel independent captures.
6917 *
6918 * In addition, an independent DAC for the multi-playback (not used in this
6919 * driver yet).
6920 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006921
6922/*
6923 * BIOS auto configuration
6924 */
6925
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006926static int alc662_parse_auto_config(struct hda_codec *codec)
6927{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006928 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006929 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6930 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6931 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006932
Kailang Yang6227cdc2010-02-25 08:36:52 +01006933 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6934 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006935 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006936 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006937 ssids = alc662_ssids;
6938 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006939}
6940
Todd Broch6be79482010-12-07 16:51:05 -08006941static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006942 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006943{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006944 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006945 return;
Todd Broch6be79482010-12-07 16:51:05 -08006946 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6947 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6948 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6949 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6950 (0 << AC_AMPCAP_MUTE_SHIFT)))
6951 printk(KERN_WARNING
6952 "hda_codec: failed to override amp caps for NID 0x2\n");
6953}
6954
David Henningsson6cb3b702010-09-09 08:51:44 +02006955enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006956 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006957 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006958 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006959 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006960 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006961 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006962 ALC662_FIXUP_ASUS_MODE1,
6963 ALC662_FIXUP_ASUS_MODE2,
6964 ALC662_FIXUP_ASUS_MODE3,
6965 ALC662_FIXUP_ASUS_MODE4,
6966 ALC662_FIXUP_ASUS_MODE5,
6967 ALC662_FIXUP_ASUS_MODE6,
6968 ALC662_FIXUP_ASUS_MODE7,
6969 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006970 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006971 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006972 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006973};
6974
6975static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006976 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006977 .type = ALC_FIXUP_PINS,
6978 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006979 { 0x15, 0x99130112 }, /* subwoofer */
6980 { }
6981 }
6982 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006983 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006984 .type = ALC_FIXUP_PINS,
6985 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006986 { 0x17, 0x99130112 }, /* subwoofer */
6987 { }
6988 }
6989 },
Todd Broch6be79482010-12-07 16:51:05 -08006990 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006991 .type = ALC_FIXUP_FUNC,
6992 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006993 },
6994 [ALC662_FIXUP_CZC_P10T] = {
6995 .type = ALC_FIXUP_VERBS,
6996 .v.verbs = (const struct hda_verb[]) {
6997 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6998 {}
6999 }
7000 },
David Henningsson94024cd2011-04-29 14:10:55 +02007001 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007002 .type = ALC_FIXUP_FUNC,
7003 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007004 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007005 [ALC662_FIXUP_HP_RP5800] = {
7006 .type = ALC_FIXUP_PINS,
7007 .v.pins = (const struct alc_pincfg[]) {
7008 { 0x14, 0x0221201f }, /* HP out */
7009 { }
7010 },
7011 .chained = true,
7012 .chain_id = ALC662_FIXUP_SKU_IGNORE
7013 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007014 [ALC662_FIXUP_ASUS_MODE1] = {
7015 .type = ALC_FIXUP_PINS,
7016 .v.pins = (const struct alc_pincfg[]) {
7017 { 0x14, 0x99130110 }, /* speaker */
7018 { 0x18, 0x01a19c20 }, /* mic */
7019 { 0x19, 0x99a3092f }, /* int-mic */
7020 { 0x21, 0x0121401f }, /* HP out */
7021 { }
7022 },
7023 .chained = true,
7024 .chain_id = ALC662_FIXUP_SKU_IGNORE
7025 },
7026 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007027 .type = ALC_FIXUP_PINS,
7028 .v.pins = (const struct alc_pincfg[]) {
7029 { 0x14, 0x99130110 }, /* speaker */
7030 { 0x18, 0x01a19820 }, /* mic */
7031 { 0x19, 0x99a3092f }, /* int-mic */
7032 { 0x1b, 0x0121401f }, /* HP out */
7033 { }
7034 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007035 .chained = true,
7036 .chain_id = ALC662_FIXUP_SKU_IGNORE
7037 },
7038 [ALC662_FIXUP_ASUS_MODE3] = {
7039 .type = ALC_FIXUP_PINS,
7040 .v.pins = (const struct alc_pincfg[]) {
7041 { 0x14, 0x99130110 }, /* speaker */
7042 { 0x15, 0x0121441f }, /* HP */
7043 { 0x18, 0x01a19840 }, /* mic */
7044 { 0x19, 0x99a3094f }, /* int-mic */
7045 { 0x21, 0x01211420 }, /* HP2 */
7046 { }
7047 },
7048 .chained = true,
7049 .chain_id = ALC662_FIXUP_SKU_IGNORE
7050 },
7051 [ALC662_FIXUP_ASUS_MODE4] = {
7052 .type = ALC_FIXUP_PINS,
7053 .v.pins = (const struct alc_pincfg[]) {
7054 { 0x14, 0x99130110 }, /* speaker */
7055 { 0x16, 0x99130111 }, /* speaker */
7056 { 0x18, 0x01a19840 }, /* mic */
7057 { 0x19, 0x99a3094f }, /* int-mic */
7058 { 0x21, 0x0121441f }, /* HP */
7059 { }
7060 },
7061 .chained = true,
7062 .chain_id = ALC662_FIXUP_SKU_IGNORE
7063 },
7064 [ALC662_FIXUP_ASUS_MODE5] = {
7065 .type = ALC_FIXUP_PINS,
7066 .v.pins = (const struct alc_pincfg[]) {
7067 { 0x14, 0x99130110 }, /* speaker */
7068 { 0x15, 0x0121441f }, /* HP */
7069 { 0x16, 0x99130111 }, /* speaker */
7070 { 0x18, 0x01a19840 }, /* mic */
7071 { 0x19, 0x99a3094f }, /* int-mic */
7072 { }
7073 },
7074 .chained = true,
7075 .chain_id = ALC662_FIXUP_SKU_IGNORE
7076 },
7077 [ALC662_FIXUP_ASUS_MODE6] = {
7078 .type = ALC_FIXUP_PINS,
7079 .v.pins = (const struct alc_pincfg[]) {
7080 { 0x14, 0x99130110 }, /* speaker */
7081 { 0x15, 0x01211420 }, /* HP2 */
7082 { 0x18, 0x01a19840 }, /* mic */
7083 { 0x19, 0x99a3094f }, /* int-mic */
7084 { 0x1b, 0x0121441f }, /* HP */
7085 { }
7086 },
7087 .chained = true,
7088 .chain_id = ALC662_FIXUP_SKU_IGNORE
7089 },
7090 [ALC662_FIXUP_ASUS_MODE7] = {
7091 .type = ALC_FIXUP_PINS,
7092 .v.pins = (const struct alc_pincfg[]) {
7093 { 0x14, 0x99130110 }, /* speaker */
7094 { 0x17, 0x99130111 }, /* speaker */
7095 { 0x18, 0x01a19840 }, /* mic */
7096 { 0x19, 0x99a3094f }, /* int-mic */
7097 { 0x1b, 0x01214020 }, /* HP */
7098 { 0x21, 0x0121401f }, /* HP */
7099 { }
7100 },
7101 .chained = true,
7102 .chain_id = ALC662_FIXUP_SKU_IGNORE
7103 },
7104 [ALC662_FIXUP_ASUS_MODE8] = {
7105 .type = ALC_FIXUP_PINS,
7106 .v.pins = (const struct alc_pincfg[]) {
7107 { 0x14, 0x99130110 }, /* speaker */
7108 { 0x12, 0x99a30970 }, /* int-mic */
7109 { 0x15, 0x01214020 }, /* HP */
7110 { 0x17, 0x99130111 }, /* speaker */
7111 { 0x18, 0x01a19840 }, /* mic */
7112 { 0x21, 0x0121401f }, /* HP */
7113 { }
7114 },
7115 .chained = true,
7116 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007117 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007118 [ALC662_FIXUP_NO_JACK_DETECT] = {
7119 .type = ALC_FIXUP_FUNC,
7120 .v.func = alc_fixup_no_jack_detect,
7121 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007122 [ALC662_FIXUP_ZOTAC_Z68] = {
7123 .type = ALC_FIXUP_PINS,
7124 .v.pins = (const struct alc_pincfg[]) {
7125 { 0x1b, 0x02214020 }, /* Front HP */
7126 { }
7127 }
7128 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007129 [ALC662_FIXUP_INV_DMIC] = {
7130 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007131 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007132 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007133};
7134
Takashi Iwaia9111322011-05-02 11:30:18 +02007135static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007136 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007137 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007138 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007139 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007140 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007141 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007142 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007143 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007144 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007145 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007146 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007147 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007148 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007149
7150#if 0
7151 /* Below is a quirk table taken from the old code.
7152 * Basically the device should work as is without the fixup table.
7153 * If BIOS doesn't give a proper info, enable the corresponding
7154 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007155 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007156 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7157 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7158 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7159 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7160 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7161 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7162 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7163 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7164 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7165 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7166 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7167 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7168 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7169 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7170 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7171 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7172 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7173 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7174 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7175 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7176 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7177 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7178 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7179 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7180 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7181 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7182 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7183 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7184 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7185 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7186 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7187 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7188 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7189 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7190 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7191 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7192 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7193 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7194 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7195 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7196 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7197 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7198 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7199 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7200 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7201 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7202 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7203 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7204 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7205 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7206#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007207 {}
7208};
7209
Todd Broch6be79482010-12-07 16:51:05 -08007210static const struct alc_model_fixup alc662_fixup_models[] = {
7211 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007212 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7213 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7214 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7215 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7216 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7217 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7218 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7219 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007220 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007221 {}
7222};
David Henningsson6cb3b702010-09-09 08:51:44 +02007223
Kailang Yang8663ff72012-06-29 09:35:52 +02007224static void alc662_fill_coef(struct hda_codec *codec)
7225{
7226 int val, coef;
7227
7228 coef = alc_get_coef0(codec);
7229
7230 switch (codec->vendor_id) {
7231 case 0x10ec0662:
7232 if ((coef & 0x00f0) == 0x0030) {
7233 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7234 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7235 }
7236 break;
7237 case 0x10ec0272:
7238 case 0x10ec0273:
7239 case 0x10ec0663:
7240 case 0x10ec0665:
7241 case 0x10ec0670:
7242 case 0x10ec0671:
7243 case 0x10ec0672:
7244 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7245 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7246 break;
7247 }
7248}
David Henningsson6cb3b702010-09-09 08:51:44 +02007249
Takashi Iwai1d045db2011-07-07 18:23:21 +02007250/*
7251 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007252static int patch_alc662(struct hda_codec *codec)
7253{
7254 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007255 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007256
Takashi Iwai3de95172012-05-07 18:03:15 +02007257 err = alc_alloc_spec(codec, 0x0b);
7258 if (err < 0)
7259 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007260
Takashi Iwai3de95172012-05-07 18:03:15 +02007261 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007262
Takashi Iwai53c334a2011-08-23 18:27:14 +02007263 /* handle multiple HPs as is */
7264 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7265
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007266 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7267
Kailang Yang8663ff72012-06-29 09:35:52 +02007268 spec->init_hook = alc662_fill_coef;
7269 alc662_fill_coef(codec);
7270
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007271 alc_pick_fixup(codec, alc662_fixup_models,
7272 alc662_fixup_tbl, alc662_fixups);
7273 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7274
7275 alc_auto_parse_customize_define(codec);
7276
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007277 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007278 codec->bus->pci->subsystem_vendor == 0x1025 &&
7279 spec->cdefine.platform_type == 1) {
7280 if (alc_codec_rename(codec, "ALC272X") < 0)
7281 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007282 }
Kailang Yang274693f2009-12-03 10:07:50 +01007283
Takashi Iwaib9c51062011-08-24 18:08:07 +02007284 /* automatic parse from the BIOS config */
7285 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007286 if (err < 0)
7287 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007288
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007289 if (!spec->no_analog && has_cdefine_beep(codec)) {
7290 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007291 if (err < 0)
7292 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007293 switch (codec->vendor_id) {
7294 case 0x10ec0662:
7295 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7296 break;
7297 case 0x10ec0272:
7298 case 0x10ec0663:
7299 case 0x10ec0665:
7300 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7301 break;
7302 case 0x10ec0273:
7303 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7304 break;
7305 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007306 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007307
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007308 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007309 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007310
Takashi Iwai589876e2012-02-20 15:47:55 +01007311 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7312
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007313 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007314
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007315 error:
7316 alc_free(codec);
7317 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007318}
7319
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007320/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007321 * ALC680 support
7322 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007323
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007324static int alc680_parse_auto_config(struct hda_codec *codec)
7325{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007326 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007327}
7328
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007329/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007330 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007331static int patch_alc680(struct hda_codec *codec)
7332{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007333 int err;
7334
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007335 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007336 err = alc_alloc_spec(codec, 0);
7337 if (err < 0)
7338 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007339
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007340 /* automatic parse from the BIOS config */
7341 err = alc680_parse_auto_config(codec);
7342 if (err < 0) {
7343 alc_free(codec);
7344 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007345 }
7346
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007347 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007348
7349 return 0;
7350}
7351
7352/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007353 * patch entries
7354 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007355static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007356 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007357 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007358 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007359 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007360 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007361 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007362 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007363 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007364 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007365 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007366 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007367 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007368 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007369 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007370 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007371 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007372 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007373 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007374 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7375 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7376 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007377 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007378 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007379 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7380 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007381 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7382 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007383 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007384 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007385 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007386 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007387 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007388 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007389 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007390 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007391 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007392 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007393 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007394 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007395 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007396 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007397 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007398 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007399 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007400 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007401 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007402 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007403 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007404 {} /* terminator */
7405};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007406
7407MODULE_ALIAS("snd-hda-codec-id:10ec*");
7408
7409MODULE_LICENSE("GPL");
7410MODULE_DESCRIPTION("Realtek HD-audio codec");
7411
7412static struct hda_codec_preset_list realtek_list = {
7413 .preset = snd_hda_preset_realtek,
7414 .owner = THIS_MODULE,
7415};
7416
7417static int __init patch_realtek_init(void)
7418{
7419 return snd_hda_add_codec_preset(&realtek_list);
7420}
7421
7422static void __exit patch_realtek_exit(void)
7423{
7424 snd_hda_delete_codec_preset(&realtek_list);
7425}
7426
7427module_init(patch_realtek_init)
7428module_exit(patch_realtek_exit)