blob: 9026b60bdc35b621309aae56e9e59427ff8f0d3b [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 Iwaic14c95f2012-02-16 16:38:07 +010076#define MAX_VOL_NIDS 0x40
77
Takashi Iwai23d30f22012-05-07 17:17:32 +020078/* make compatible with old code */
79#define alc_apply_pincfgs snd_hda_apply_pincfgs
80#define alc_apply_fixup snd_hda_apply_fixup
81#define alc_pick_fixup snd_hda_pick_fixup
82#define alc_fixup hda_fixup
83#define alc_pincfg hda_pintbl
84#define alc_model_fixup hda_model_fixup
85
86#define ALC_FIXUP_PINS HDA_FIXUP_PINS
87#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
88#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
89
90#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
91#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
92#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
93#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
94
95
Takashi Iwai30dcd3b2012-12-06 15:45:38 +010096#define MAX_NID_PATH_DEPTH 5
97
Takashi Iwai8dd48672012-12-14 18:19:04 +010098enum {
99 NID_PATH_VOL_CTL,
100 NID_PATH_MUTE_CTL,
101 NID_PATH_BOOST_CTL,
102 NID_PATH_NUM_CTLS
103};
104
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100105/* Widget connection path
106 *
107 * For output, stored in the order of DAC -> ... -> pin,
108 * for input, pin -> ... -> ADC.
109 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100110 * idx[i] contains the source index number to select on of the widget path[i];
111 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100112 * multi[] indicates whether it's a selector widget with multi-connectors
113 * (i.e. the connection selection is mandatory)
114 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
115 */
116struct nid_path {
117 int depth;
118 hda_nid_t path[MAX_NID_PATH_DEPTH];
119 unsigned char idx[MAX_NID_PATH_DEPTH];
120 unsigned char multi[MAX_NID_PATH_DEPTH];
Takashi Iwai8dd48672012-12-14 18:19:04 +0100121 unsigned int ctls[NID_PATH_NUM_CTLS]; /* NID_PATH_XXX_CTL */
Takashi Iwai130e5f02012-12-14 16:09:29 +0100122 bool active;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100123};
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 Iwaic9967f12012-12-14 16:39:22 +0100200 /* path list */
201 struct snd_array paths;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +0100202
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100203 /* hooks */
204 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200205#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500206 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100207#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200208 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200209 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100210
Takashi Iwai834be882006-03-01 14:16:17 +0100211 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200212 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200213 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200214 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200215 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200216 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200217 unsigned int automute_speaker:1; /* automute speaker outputs */
218 unsigned int automute_lo:1; /* automute LO outputs */
219 unsigned int detect_hp:1; /* Headphone detection enabled */
220 unsigned int detect_lo:1; /* Line-out detection enabled */
221 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
222 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100223 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200224
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100225 /* other flags */
226 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200227 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100228 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200229 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200230 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100231 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200232 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
233 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200234 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200235
236 /* auto-mute control */
237 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200238 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200239
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200240 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200241 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100242
Takashi Iwai2134ea42008-01-10 16:53:55 +0100243 /* for virtual master */
244 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100245 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200246#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200247 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100248 int num_loopbacks;
249 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200250#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200251
252 /* for PLL fix */
253 hda_nid_t pll_nid;
254 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200255 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100256
Takashi Iwaice764ab2011-04-27 16:35:23 +0200257 /* multi-io */
258 int multi_ios;
259 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200260
261 /* bind volumes */
262 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100263};
264
Takashi Iwai44c02402011-07-08 15:14:19 +0200265static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
266 int dir, unsigned int bits)
267{
268 if (!nid)
269 return false;
270 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
271 if (query_amp_caps(codec, nid, dir) & bits)
272 return true;
273 return false;
274}
275
276#define nid_has_mute(codec, nid, dir) \
277 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
278#define nid_has_volume(codec, nid, dir) \
279 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281/*
282 * input MUX handling
283 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200284static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
285 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
288 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200289 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
290 if (mux_idx >= spec->num_mux_defs)
291 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100292 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
293 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200294 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200297static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
301 struct alc_spec *spec = codec->spec;
302 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
303
304 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
305 return 0;
306}
307
Takashi Iwai21268962011-07-07 15:01:13 +0200308static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Takashi Iwai21268962011-07-07 15:01:13 +0200310 struct alc_spec *spec = codec->spec;
311 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
312
313 if (spec->cur_adc && spec->cur_adc != new_adc) {
314 /* stream is running, let's swap the current ADC */
315 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
316 spec->cur_adc = new_adc;
317 snd_hda_codec_setup_stream(codec, new_adc,
318 spec->cur_adc_stream_tag, 0,
319 spec->cur_adc_format);
320 return true;
321 }
322 return false;
323}
324
Takashi Iwai61071592011-11-23 07:52:15 +0100325static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
326{
327 return spec->capsrc_nids ?
328 spec->capsrc_nids[idx] : spec->adc_nids[idx];
329}
330
Takashi Iwai24de1832011-11-07 17:13:39 +0100331static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200332static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100333
David Henningsson00227f12012-06-27 18:45:44 +0200334/* for shared I/O, change the pin-control accordingly */
335static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
336{
337 struct alc_spec *spec = codec->spec;
338 unsigned int val;
339 hda_nid_t pin = spec->autocfg.inputs[1].pin;
340 /* NOTE: this assumes that there are only two inputs, the
341 * first is the real internal mic and the second is HP/mic jack.
342 */
343
344 val = snd_hda_get_default_vref(codec, pin);
345
346 /* This pin does not have vref caps - let's enable vref on pin 0x18
347 instead, as suggested by Realtek */
348 if (val == AC_PINCTL_VREF_HIZ) {
349 const hda_nid_t vref_pin = 0x18;
350 /* Sanity check pin 0x18 */
351 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
352 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
353 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
354 if (vref_val != AC_PINCTL_VREF_HIZ)
355 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
356 }
357 }
358
359 val = set_as_mic ? val | PIN_IN : PIN_HP;
360 snd_hda_set_pin_ctl(codec, pin, val);
361
362 spec->automute_speaker = !set_as_mic;
363 call_update_outputs(codec);
364}
Takashi Iwai21268962011-07-07 15:01:13 +0200365
366/* select the given imux item; either unmute exclusively or select the route */
367static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
368 unsigned int idx, bool force)
369{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100371 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100372 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100373 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200374 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Takashi Iwai5803a322012-02-21 11:59:45 +0100376 if (!spec->input_mux)
377 return 0;
378
Takashi Iwaicd896c32008-11-18 12:36:33 +0100379 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
380 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100381 if (!imux->num_items && mux_idx > 0)
382 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100383 if (!imux->num_items)
384 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100385
Takashi Iwai21268962011-07-07 15:01:13 +0200386 if (idx >= imux->num_items)
387 idx = imux->num_items - 1;
388 if (spec->cur_mux[adc_idx] == idx && !force)
389 return 0;
390 spec->cur_mux[adc_idx] = idx;
391
David Henningsson00227f12012-06-27 18:45:44 +0200392 if (spec->shared_mic_hp)
393 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100394
Takashi Iwai21268962011-07-07 15:01:13 +0200395 if (spec->dyn_adc_switch) {
396 alc_dyn_adc_pcm_resetup(codec, idx);
397 adc_idx = spec->dyn_adc_idx[idx];
398 }
399
Takashi Iwai61071592011-11-23 07:52:15 +0100400 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200401
402 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200403 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100404 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200405 return 1;
406
Takashi Iwaia22d5432009-07-27 12:54:26 +0200407 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200408 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100409 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100410 int active = imux->items[idx].index;
411 for (i = 0; i < num_conns; i++) {
412 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
413 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100414 HDA_AMP_MUTE, v);
415 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100416 } else {
417 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200418 snd_hda_codec_write_cache(codec, nid, 0,
419 AC_VERB_SET_CONNECT_SEL,
420 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100421 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200422 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200423 return 1;
424}
425
426static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
427 struct snd_ctl_elem_value *ucontrol)
428{
429 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
430 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
431 return alc_mux_select(codec, adc_idx,
432 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100433}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100436 * set up the input pin config (depending on the given auto-pin type)
437 */
438static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
439 int auto_pin_type)
440{
441 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200442 if (auto_pin_type == AUTO_PIN_MIC)
443 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200444 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100445}
446
447/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200448 * Append the given mixer and verb elements for the later use
449 * The mixer array is referred in build_controls(), and init_verbs are
450 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100451 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200452static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100453{
454 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
455 return;
456 spec->mixers[spec->num_mixers++] = mix;
457}
458
Takashi Iwaid88897e2008-10-31 15:01:37 +0100459/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200460 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100461 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200462/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200463static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200464 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
465 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
466 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
467 { }
468};
469
Takashi Iwaia9111322011-05-02 11:30:18 +0200470static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200471 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
472 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
473 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
474 { }
475};
476
Takashi Iwaia9111322011-05-02 11:30:18 +0200477static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200478 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
479 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
480 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
481 { }
482};
483
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200484/*
485 * Fix hardware PLL issue
486 * On some codecs, the analog PLL gating control must be off while
487 * the default value is 1.
488 */
489static void alc_fix_pll(struct hda_codec *codec)
490{
491 struct alc_spec *spec = codec->spec;
492 unsigned int val;
493
494 if (!spec->pll_nid)
495 return;
496 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
497 spec->pll_coef_idx);
498 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
499 AC_VERB_GET_PROC_COEF, 0);
500 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
501 spec->pll_coef_idx);
502 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
503 val & ~(1 << spec->pll_coef_bit));
504}
505
506static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
507 unsigned int coef_idx, unsigned int coef_bit)
508{
509 struct alc_spec *spec = codec->spec;
510 spec->pll_nid = nid;
511 spec->pll_coef_idx = coef_idx;
512 spec->pll_coef_bit = coef_bit;
513 alc_fix_pll(codec);
514}
515
Takashi Iwai1d045db2011-07-07 18:23:21 +0200516/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200517 * Jack detections for HP auto-mute and mic-switch
518 */
519
520/* check each pin in the given array; returns true if any of them is plugged */
521static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200522{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200523 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200524
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200525 for (i = 0; i < num_pins; i++) {
526 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200527 if (!nid)
528 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200530 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200531 return present;
532}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200533
Takashi Iwai1d045db2011-07-07 18:23:21 +0200534/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200536 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537{
538 struct alc_spec *spec = codec->spec;
Takashi Iwaie9427962011-04-28 15:46:07 +0200539 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200540 int i;
541
542 for (i = 0; i < num_pins; i++) {
543 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100544 unsigned int val;
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200545 if (!nid)
546 break;
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100547 /* don't reset VREF value in case it's controlling
548 * the amp (see alc861_fixup_asus_amp_vref_0f())
549 */
550 if (spec->keep_vref_in_automute) {
551 val = snd_hda_codec_read(codec, nid, 0,
Takashi Iwai31150f22012-01-30 10:54:08 +0100552 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwaib8a47c72012-12-14 14:20:34 +0100553 val &= ~PIN_HP;
554 } else
555 val = 0;
556 val |= pin_bits;
557 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200558 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200559}
560
David Henningsson42cf0d02011-09-20 12:04:56 +0200561/* Toggle outputs muting */
562static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563{
564 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200566
Takashi Iwaic0a20262011-06-10 15:28:15 +0200567 /* Control HP pins/amps depending on master_mute state;
568 * in general, HP pins/amps control should be enabled in all cases,
569 * but currently set only for master_mute, just to be safe
570 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100571 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
572 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200573 spec->autocfg.hp_pins, spec->master_mute, true);
574
David Henningsson42cf0d02011-09-20 12:04:56 +0200575 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200576 on = 0;
577 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200578 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200580 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200581 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582
583 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200584 /* if LO is a copy of either HP or Speaker, don't need to handle it */
585 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
586 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200588 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200589 on = 0;
590 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200591 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200592 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200593 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200594 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200595}
596
David Henningsson42cf0d02011-09-20 12:04:56 +0200597static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200598{
599 struct alc_spec *spec = codec->spec;
600 if (spec->automute_hook)
601 spec->automute_hook(codec);
602 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200603 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200604}
605
Takashi Iwai1d045db2011-07-07 18:23:21 +0200606/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200607static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608{
609 struct alc_spec *spec = codec->spec;
610
David Henningsson42cf0d02011-09-20 12:04:56 +0200611 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200612 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
613 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200614 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200615 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200616 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200617}
618
Takashi Iwai1d045db2011-07-07 18:23:21 +0200619/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200620static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200621{
622 struct alc_spec *spec = codec->spec;
623
David Henningssonf7f4b2322012-10-10 16:32:09 +0200624 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
625 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200626 /* check LO jack only when it's different from HP */
627 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
628 return;
629
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200630 spec->line_jack_present =
631 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
632 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200633 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200634 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200635 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200636}
637
Takashi Iwai8d087c72011-06-28 12:45:47 +0200638#define get_connection_index(codec, mux, nid) \
639 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200640
Takashi Iwai1d045db2011-07-07 18:23:21 +0200641/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200642static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200643{
644 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200645 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200646
Takashi Iwai21268962011-07-07 15:01:13 +0200647 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200648 return;
649 if (snd_BUG_ON(!spec->adc_nids))
650 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200651 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200652 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200653
Takashi Iwai21268962011-07-07 15:01:13 +0200654 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
655 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
656 else if (spec->dock_mic_idx >= 0 &&
657 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
658 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
659 else
660 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200661}
662
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100663/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200664static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100665{
666 unsigned int val;
667 struct snd_kcontrol *kctl;
668 struct snd_ctl_elem_value *uctl;
669
670 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
671 if (!kctl)
672 return;
673 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
674 if (!uctl)
675 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200676 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100677 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
678 val &= HDA_AMP_VOLMASK;
679 uctl->value.integer.value[0] = val;
680 uctl->value.integer.value[1] = val;
681 kctl->put(kctl, uctl);
682 kfree(uctl);
683}
684
David Henningsson29adc4b2012-09-25 11:31:00 +0200685static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100686{
David Henningsson29adc4b2012-09-25 11:31:00 +0200687 /* For some reason, the res given from ALC880 is broken.
688 Here we adjust it properly. */
689 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100690}
691
Takashi Iwai1d045db2011-07-07 18:23:21 +0200692/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200693static void alc_inithook(struct hda_codec *codec)
694{
David Henningsson29adc4b2012-09-25 11:31:00 +0200695 alc_hp_automute(codec, NULL);
696 alc_line_automute(codec, NULL);
697 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200698}
699
Kailang Yangf9423e72008-05-27 12:32:25 +0200700/* additional initialization for ALC888 variants */
701static void alc888_coef_init(struct hda_codec *codec)
702{
703 unsigned int tmp;
704
705 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
706 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
707 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100708 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200709 /* alc888S-VC */
710 snd_hda_codec_read(codec, 0x20, 0,
711 AC_VERB_SET_PROC_COEF, 0x830);
712 else
713 /* alc888-VB */
714 snd_hda_codec_read(codec, 0x20, 0,
715 AC_VERB_SET_PROC_COEF, 0x3030);
716}
717
Takashi Iwai1d045db2011-07-07 18:23:21 +0200718/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200719static void alc889_coef_init(struct hda_codec *codec)
720{
721 unsigned int tmp;
722
723 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
724 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
725 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
726 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
727}
728
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100729/* turn on/off EAPD control (only if available) */
730static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
731{
732 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
733 return;
734 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
735 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
736 on ? 2 : 0);
737}
738
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200739/* turn on/off EAPD controls of the codec */
740static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
741{
742 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200743 static hda_nid_t pins[] = {
744 0x0f, 0x10, 0x14, 0x15, 0
745 };
746 hda_nid_t *p;
747 for (p = pins; *p; p++)
748 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200749}
750
Takashi Iwai1c7161532011-04-07 10:37:16 +0200751/* generic shutup callback;
752 * just turning off EPAD and a little pause for avoiding pop-noise
753 */
754static void alc_eapd_shutup(struct hda_codec *codec)
755{
756 alc_auto_setup_eapd(codec, false);
757 msleep(200);
758}
759
Takashi Iwai1d045db2011-07-07 18:23:21 +0200760/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200761static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200762{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200763 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200764
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200765 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200766 switch (type) {
767 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200768 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
769 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200771 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
772 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200773 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200774 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
775 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200776 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200777 switch (codec->vendor_id) {
778 case 0x10ec0260:
779 snd_hda_codec_write(codec, 0x1a, 0,
780 AC_VERB_SET_COEF_INDEX, 7);
781 tmp = snd_hda_codec_read(codec, 0x1a, 0,
782 AC_VERB_GET_PROC_COEF, 0);
783 snd_hda_codec_write(codec, 0x1a, 0,
784 AC_VERB_SET_COEF_INDEX, 7);
785 snd_hda_codec_write(codec, 0x1a, 0,
786 AC_VERB_SET_PROC_COEF,
787 tmp | 0x2010);
788 break;
789 case 0x10ec0262:
790 case 0x10ec0880:
791 case 0x10ec0882:
792 case 0x10ec0883:
793 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100794 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100795 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200796 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200797 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200798 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200799 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200800 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100801#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200802 case 0x10ec0267:
803 case 0x10ec0268:
804 snd_hda_codec_write(codec, 0x20, 0,
805 AC_VERB_SET_COEF_INDEX, 7);
806 tmp = snd_hda_codec_read(codec, 0x20, 0,
807 AC_VERB_GET_PROC_COEF, 0);
808 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200809 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200810 snd_hda_codec_write(codec, 0x20, 0,
811 AC_VERB_SET_PROC_COEF,
812 tmp | 0x3000);
813 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100814#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200815 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200816 break;
817 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200818}
Kailang Yangea1fb292008-08-26 12:58:38 +0200819
Takashi Iwai1d045db2011-07-07 18:23:21 +0200820/*
821 * Auto-Mute mode mixer enum support
822 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200823static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_info *uinfo)
825{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
827 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200828 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100829 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200830 };
831
Takashi Iwaidda415d2012-11-30 18:34:38 +0100832 if (spec->automute_speaker_possible && spec->automute_lo_possible)
833 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
834 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200835}
836
837static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
838 struct snd_ctl_elem_value *ucontrol)
839{
840 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
841 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200842 unsigned int val = 0;
843 if (spec->automute_speaker)
844 val++;
845 if (spec->automute_lo)
846 val++;
847
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200848 ucontrol->value.enumerated.item[0] = val;
849 return 0;
850}
851
852static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
853 struct snd_ctl_elem_value *ucontrol)
854{
855 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
856 struct alc_spec *spec = codec->spec;
857
858 switch (ucontrol->value.enumerated.item[0]) {
859 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200860 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200861 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200862 spec->automute_speaker = 0;
863 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200864 break;
865 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200866 if (spec->automute_speaker_possible) {
867 if (!spec->automute_lo && spec->automute_speaker)
868 return 0;
869 spec->automute_speaker = 1;
870 spec->automute_lo = 0;
871 } else if (spec->automute_lo_possible) {
872 if (spec->automute_lo)
873 return 0;
874 spec->automute_lo = 1;
875 } else
876 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200877 break;
878 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200879 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200880 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200881 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200882 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200883 spec->automute_speaker = 1;
884 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 break;
886 default:
887 return -EINVAL;
888 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200889 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200890 return 1;
891}
892
Takashi Iwaia9111322011-05-02 11:30:18 +0200893static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200894 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
895 .name = "Auto-Mute Mode",
896 .info = alc_automute_mode_info,
897 .get = alc_automute_mode_get,
898 .put = alc_automute_mode_put,
899};
900
Takashi Iwai668d1e92012-11-29 14:10:17 +0100901static struct snd_kcontrol_new *
902alc_kcontrol_new(struct alc_spec *spec, const char *name,
903 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200904{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100905 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
906 if (!knew)
907 return NULL;
908 *knew = *temp;
909 knew->name = kstrdup(name, GFP_KERNEL);
910 if (!knew->name)
911 return NULL;
912 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200913}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200914
915static int alc_add_automute_mode_enum(struct hda_codec *codec)
916{
917 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200918
Takashi Iwai668d1e92012-11-29 14:10:17 +0100919 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200920 return -ENOMEM;
921 return 0;
922}
923
Takashi Iwai1d045db2011-07-07 18:23:21 +0200924/*
925 * Check the availability of HP/line-out auto-mute;
926 * Set up appropriately if really supported
927 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100928static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200929{
930 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200931 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200932 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100933 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200934
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200935 if (cfg->hp_pins[0])
936 present++;
937 if (cfg->line_out_pins[0])
938 present++;
939 if (cfg->speaker_pins[0])
940 present++;
941 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100942 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200943
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200944 if (!cfg->speaker_pins[0] &&
945 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200946 memcpy(cfg->speaker_pins, cfg->line_out_pins,
947 sizeof(cfg->speaker_pins));
948 cfg->speaker_outs = cfg->line_outs;
949 }
950
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200951 if (!cfg->hp_pins[0] &&
952 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200953 memcpy(cfg->hp_pins, cfg->line_out_pins,
954 sizeof(cfg->hp_pins));
955 cfg->hp_outs = cfg->line_outs;
956 }
957
958 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200959 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200960 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200961 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200962 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200963 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200964 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
965 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200966 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200967 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200968
David Henningsson42cf0d02011-09-20 12:04:56 +0200969 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
970 if (cfg->speaker_outs)
971 for (i = 0; i < cfg->line_outs; i++) {
972 hda_nid_t nid = cfg->line_out_pins[i];
973 if (!is_jack_detectable(codec, nid))
974 continue;
975 snd_printdd("realtek: Enable Line-Out "
976 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200977 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
978 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200979 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +0200980 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200981 spec->automute_lo_possible = spec->detect_hp;
982 }
983
984 spec->automute_speaker_possible = cfg->speaker_outs &&
985 (spec->detect_hp || spec->detect_lo);
986
987 spec->automute_lo = spec->automute_lo_possible;
988 spec->automute_speaker = spec->automute_speaker_possible;
989
Takashi Iwai475c3d22012-11-30 08:31:30 +0100990 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200991 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100992 err = alc_add_automute_mode_enum(codec);
993 if (err < 0)
994 return err;
995 }
996 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200997}
998
Takashi Iwai1d045db2011-07-07 18:23:21 +0200999/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001000static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1001{
1002 int i;
1003 for (i = 0; i < nums; i++)
1004 if (list[i] == nid)
1005 return i;
1006 return -1;
1007}
1008
Takashi Iwai1d045db2011-07-07 18:23:21 +02001009/* check whether dynamic ADC-switching is available */
1010static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1011{
1012 struct alc_spec *spec = codec->spec;
1013 struct hda_input_mux *imux = &spec->private_imux[0];
1014 int i, n, idx;
1015 hda_nid_t cap, pin;
1016
1017 if (imux != spec->input_mux) /* no dynamic imux? */
1018 return false;
1019
1020 for (n = 0; n < spec->num_adc_nids; n++) {
1021 cap = spec->private_capsrc_nids[n];
1022 for (i = 0; i < imux->num_items; i++) {
1023 pin = spec->imux_pins[i];
1024 if (!pin)
1025 return false;
1026 if (get_connection_index(codec, cap, pin) < 0)
1027 break;
1028 }
1029 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001030 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001031 }
1032
1033 for (i = 0; i < imux->num_items; i++) {
1034 pin = spec->imux_pins[i];
1035 for (n = 0; n < spec->num_adc_nids; n++) {
1036 cap = spec->private_capsrc_nids[n];
1037 idx = get_connection_index(codec, cap, pin);
1038 if (idx >= 0) {
1039 imux->items[i].index = idx;
1040 spec->dyn_adc_idx[i] = n;
1041 break;
1042 }
1043 }
1044 }
1045
1046 snd_printdd("realtek: enabling ADC switching\n");
1047 spec->dyn_adc_switch = 1;
1048 return true;
1049}
Takashi Iwai21268962011-07-07 15:01:13 +02001050
Takashi Iwai21268962011-07-07 15:01:13 +02001051/* check whether all auto-mic pins are valid; setup indices if OK */
1052static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1053{
1054 struct alc_spec *spec = codec->spec;
1055 const struct hda_input_mux *imux;
1056
1057 if (!spec->auto_mic)
1058 return false;
1059 if (spec->auto_mic_valid_imux)
1060 return true; /* already checked */
1061
1062 /* fill up imux indices */
1063 if (!alc_check_dyn_adc_switch(codec)) {
1064 spec->auto_mic = 0;
1065 return false;
1066 }
1067
1068 imux = spec->input_mux;
1069 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1070 spec->imux_pins, imux->num_items);
1071 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1072 spec->imux_pins, imux->num_items);
1073 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1074 spec->imux_pins, imux->num_items);
1075 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1076 spec->auto_mic = 0;
1077 return false; /* no corresponding imux */
1078 }
1079
David Henningsson29adc4b2012-09-25 11:31:00 +02001080 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1081 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001082 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001083 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1084 ALC_MIC_EVENT,
1085 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001086
1087 spec->auto_mic_valid_imux = 1;
1088 spec->auto_mic = 1;
1089 return true;
1090}
1091
Takashi Iwai1d045db2011-07-07 18:23:21 +02001092/*
1093 * Check the availability of auto-mic switch;
1094 * Set up if really supported
1095 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001096static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001097{
1098 struct alc_spec *spec = codec->spec;
1099 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001100 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001101 int i;
1102
Takashi Iwai24de1832011-11-07 17:13:39 +01001103 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001104 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001105
Takashi Iwai21268962011-07-07 15:01:13 +02001106 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1107
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001108 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001109 for (i = 0; i < cfg->num_inputs; i++) {
1110 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001111 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001112 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001113 switch (snd_hda_get_input_pin_attr(defcfg)) {
1114 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001115 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001116 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001117 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001118 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001119 fixed = nid;
1120 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001121 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001122 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001123 case INPUT_PIN_ATTR_DOCK:
1124 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001125 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001126 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001127 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001128 dock = nid;
1129 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001130 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001131 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001132 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001133 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001134 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001135 ext = nid;
1136 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001137 }
1138 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001139 if (!ext && dock) {
1140 ext = dock;
1141 dock = 0;
1142 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001143 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001144 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001145 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001146 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001148 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001149
1150 /* check imux indices */
1151 spec->ext_mic_pin = ext;
1152 spec->int_mic_pin = fixed;
1153 spec->dock_mic_pin = dock;
1154
1155 spec->auto_mic = 1;
1156 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001157 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001158
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001159 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1160 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001161
1162 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001163}
1164
Takashi Iwai1d045db2011-07-07 18:23:21 +02001165/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001166static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001167{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001168 int err;
1169
1170 err = alc_init_automute(codec);
1171 if (err < 0)
1172 return err;
1173 err = alc_init_auto_mic(codec);
1174 if (err < 0)
1175 return err;
1176 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001177}
1178
1179/*
1180 * Realtek SSID verification
1181 */
1182
David Henningsson90622912010-10-14 14:50:18 +02001183/* Could be any non-zero and even value. When used as fixup, tells
1184 * the driver to ignore any present sku defines.
1185 */
1186#define ALC_FIXUP_SKU_IGNORE (2)
1187
Takashi Iwai23d30f22012-05-07 17:17:32 +02001188static void alc_fixup_sku_ignore(struct hda_codec *codec,
1189 const struct hda_fixup *fix, int action)
1190{
1191 struct alc_spec *spec = codec->spec;
1192 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1193 spec->cdefine.fixup = 1;
1194 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1195 }
1196}
1197
Kailang Yangda00c242010-03-19 11:23:45 +01001198static int alc_auto_parse_customize_define(struct hda_codec *codec)
1199{
1200 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001201 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001202 struct alc_spec *spec = codec->spec;
1203
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001204 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1205
David Henningsson90622912010-10-14 14:50:18 +02001206 if (spec->cdefine.fixup) {
1207 ass = spec->cdefine.sku_cfg;
1208 if (ass == ALC_FIXUP_SKU_IGNORE)
1209 return -1;
1210 goto do_sku;
1211 }
1212
Kailang Yangda00c242010-03-19 11:23:45 +01001213 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001214 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001215 goto do_sku;
1216
1217 nid = 0x1d;
1218 if (codec->vendor_id == 0x10ec0260)
1219 nid = 0x17;
1220 ass = snd_hda_codec_get_pincfg(codec, nid);
1221
1222 if (!(ass & 1)) {
1223 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1224 codec->chip_name, ass);
1225 return -1;
1226 }
1227
1228 /* check sum */
1229 tmp = 0;
1230 for (i = 1; i < 16; i++) {
1231 if ((ass >> i) & 1)
1232 tmp++;
1233 }
1234 if (((ass >> 16) & 0xf) != tmp)
1235 return -1;
1236
1237 spec->cdefine.port_connectivity = ass >> 30;
1238 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1239 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1240 spec->cdefine.customization = ass >> 8;
1241do_sku:
1242 spec->cdefine.sku_cfg = ass;
1243 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1244 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1245 spec->cdefine.swap = (ass & 0x2) >> 1;
1246 spec->cdefine.override = ass & 0x1;
1247
1248 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1249 nid, spec->cdefine.sku_cfg);
1250 snd_printd("SKU: port_connectivity=0x%x\n",
1251 spec->cdefine.port_connectivity);
1252 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1253 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1254 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1255 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1256 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1257 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1258 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1259
1260 return 0;
1261}
1262
Takashi Iwai1d045db2011-07-07 18:23:21 +02001263/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001264static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1265{
Takashi Iwai21268962011-07-07 15:01:13 +02001266 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001267}
1268
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001269/* check subsystem ID and set up device-specific initialization;
1270 * return 1 if initialized, 0 if invalid SSID
1271 */
1272/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1273 * 31 ~ 16 : Manufacture ID
1274 * 15 ~ 8 : SKU ID
1275 * 7 ~ 0 : Assembly ID
1276 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1277 */
1278static int alc_subsystem_id(struct hda_codec *codec,
1279 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001280 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001281{
1282 unsigned int ass, tmp, i;
1283 unsigned nid;
1284 struct alc_spec *spec = codec->spec;
1285
David Henningsson90622912010-10-14 14:50:18 +02001286 if (spec->cdefine.fixup) {
1287 ass = spec->cdefine.sku_cfg;
1288 if (ass == ALC_FIXUP_SKU_IGNORE)
1289 return 0;
1290 goto do_sku;
1291 }
1292
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001293 ass = codec->subsystem_id & 0xffff;
1294 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1295 goto do_sku;
1296
1297 /* invalid SSID, check the special NID pin defcfg instead */
1298 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001299 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001300 * 29~21 : reserve
1301 * 20 : PCBEEP input
1302 * 19~16 : Check sum (15:1)
1303 * 15~1 : Custom
1304 * 0 : override
1305 */
1306 nid = 0x1d;
1307 if (codec->vendor_id == 0x10ec0260)
1308 nid = 0x17;
1309 ass = snd_hda_codec_get_pincfg(codec, nid);
1310 snd_printd("realtek: No valid SSID, "
1311 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001312 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001313 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001314 return 0;
1315 if ((ass >> 30) != 1) /* no physical connection */
1316 return 0;
1317
1318 /* check sum */
1319 tmp = 0;
1320 for (i = 1; i < 16; i++) {
1321 if ((ass >> i) & 1)
1322 tmp++;
1323 }
1324 if (((ass >> 16) & 0xf) != tmp)
1325 return 0;
1326do_sku:
1327 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1328 ass & 0xffff, codec->vendor_id);
1329 /*
1330 * 0 : override
1331 * 1 : Swap Jack
1332 * 2 : 0 --> Desktop, 1 --> Laptop
1333 * 3~5 : External Amplifier control
1334 * 7~6 : Reserved
1335 */
1336 tmp = (ass & 0x38) >> 3; /* external Amp control */
1337 switch (tmp) {
1338 case 1:
1339 spec->init_amp = ALC_INIT_GPIO1;
1340 break;
1341 case 3:
1342 spec->init_amp = ALC_INIT_GPIO2;
1343 break;
1344 case 7:
1345 spec->init_amp = ALC_INIT_GPIO3;
1346 break;
1347 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001348 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001349 spec->init_amp = ALC_INIT_DEFAULT;
1350 break;
1351 }
1352
1353 /* is laptop or Desktop and enable the function "Mute internal speaker
1354 * when the external headphone out jack is plugged"
1355 */
1356 if (!(ass & 0x8000))
1357 return 1;
1358 /*
1359 * 10~8 : Jack location
1360 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1361 * 14~13: Resvered
1362 * 15 : 1 --> enable the function "Mute internal speaker
1363 * when the external headphone out jack is plugged"
1364 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001365 if (!spec->autocfg.hp_pins[0] &&
1366 !(spec->autocfg.line_out_pins[0] &&
1367 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001368 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001369 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1370 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001371 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001372 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001373 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001374 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001375 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001376 else if (tmp == 3)
1377 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001378 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001379 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001380 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1381 spec->autocfg.line_outs))
1382 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001383 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001384 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001385 return 1;
1386}
Kailang Yangea1fb292008-08-26 12:58:38 +02001387
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001388/* Check the validity of ALC subsystem-id
1389 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1390static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001391{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001392 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001393 struct alc_spec *spec = codec->spec;
1394 snd_printd("realtek: "
1395 "Enable default setup for auto mode as fallback\n");
1396 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001397 }
Takashi Iwai21268962011-07-07 15:01:13 +02001398}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001399
Takashi Iwai41e41f12005-06-08 14:48:49 +02001400/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001401 * COEF access helper functions
1402 */
Kailang Yang274693f2009-12-03 10:07:50 +01001403static int alc_read_coef_idx(struct hda_codec *codec,
1404 unsigned int coef_idx)
1405{
1406 unsigned int val;
1407 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1408 coef_idx);
1409 val = snd_hda_codec_read(codec, 0x20, 0,
1410 AC_VERB_GET_PROC_COEF, 0);
1411 return val;
1412}
1413
Kailang Yang977ddd62010-09-15 10:02:29 +02001414static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1415 unsigned int coef_val)
1416{
1417 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1418 coef_idx);
1419 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1420 coef_val);
1421}
1422
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001423/* a special bypass for COEF 0; read the cached value at the second time */
1424static unsigned int alc_get_coef0(struct hda_codec *codec)
1425{
1426 struct alc_spec *spec = codec->spec;
1427 if (!spec->coef0)
1428 spec->coef0 = alc_read_coef_idx(codec, 0);
1429 return spec->coef0;
1430}
1431
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001432static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
1433 hda_nid_t pin, int pin_type,
1434 hda_nid_t dac);
1435static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
1436 bool is_digital);
1437static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
1438 hda_nid_t dac);
1439
Takashi Iwai1d045db2011-07-07 18:23:21 +02001440/*
1441 * Digital I/O handling
1442 */
1443
Takashi Iwai757899a2010-07-30 10:48:14 +02001444/* set right pin controls for digital I/O */
1445static void alc_auto_init_digital(struct hda_codec *codec)
1446{
1447 struct alc_spec *spec = codec->spec;
1448 int i;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001449 hda_nid_t pin;
Takashi Iwai757899a2010-07-30 10:48:14 +02001450
1451 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1452 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001453 if (!pin)
1454 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001455 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
Takashi Iwai757899a2010-07-30 10:48:14 +02001456 }
1457 pin = spec->autocfg.dig_in_pin;
1458 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001459 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001460}
1461
1462/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1463static void alc_auto_parse_digital(struct hda_codec *codec)
1464{
1465 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001466 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001467 hda_nid_t dig_nid;
1468
1469 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001470 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001471 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001472 hda_nid_t pin = spec->autocfg.dig_out_pins[i];
1473 dig_nid = alc_auto_look_for_dac(codec, pin, true);
1474 if (!dig_nid)
Takashi Iwai757899a2010-07-30 10:48:14 +02001475 continue;
Takashi Iwai51e41522011-11-03 16:54:06 +01001476 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001477 spec->multiout.dig_out_nid = dig_nid;
1478 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1479 } else {
1480 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001481 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001482 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001483 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001484 }
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01001485 add_new_out_path(codec, pin, dig_nid);
Takashi Iwai51e41522011-11-03 16:54:06 +01001486 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001487 }
1488
1489 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001490 dig_nid = codec->start_nid;
1491 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1492 unsigned int wcaps = get_wcaps(codec, dig_nid);
1493 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1494 continue;
1495 if (!(wcaps & AC_WCAP_DIGITAL))
1496 continue;
1497 if (!(wcaps & AC_WCAP_CONN_LIST))
1498 continue;
1499 err = get_connection_index(codec, dig_nid,
1500 spec->autocfg.dig_in_pin);
1501 if (err >= 0) {
1502 spec->dig_in_nid = dig_nid;
1503 break;
1504 }
1505 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001506 }
1507}
1508
Takashi Iwaif95474e2007-07-10 00:47:43 +02001509/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001510 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001511 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001512static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1513 struct snd_ctl_elem_info *uinfo)
1514{
1515 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1516 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001517 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001518 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001519
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001520 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001521 if (spec->vol_in_capsrc)
1522 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1523 else
1524 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1525 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001526 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001527 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001528 return err;
1529}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001531static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1532 unsigned int size, unsigned int __user *tlv)
1533{
1534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1535 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001536 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001537 int err;
1538
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001539 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001540 if (spec->vol_in_capsrc)
1541 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1542 else
1543 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1544 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001545 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001546 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001547 return err;
1548}
1549
1550typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1551 struct snd_ctl_elem_value *ucontrol);
1552
1553static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1554 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001555 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001556{
1557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1558 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001559 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001560
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001561 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001562 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001563 for (i = 0; i < spec->num_adc_nids; i++) {
1564 kcontrol->private_value =
1565 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1566 3, 0, HDA_INPUT);
1567 err = func(kcontrol, ucontrol);
1568 if (err < 0)
1569 goto error;
1570 }
1571 } else {
1572 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001573 if (spec->vol_in_capsrc)
1574 kcontrol->private_value =
1575 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1576 3, 0, HDA_OUTPUT);
1577 else
1578 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001579 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1580 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001581 err = func(kcontrol, ucontrol);
1582 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001583 if (err >= 0 && is_put)
1584 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001585 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001586 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001587 return err;
1588}
1589
1590static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1591 struct snd_ctl_elem_value *ucontrol)
1592{
1593 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001594 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001595}
1596
1597static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1598 struct snd_ctl_elem_value *ucontrol)
1599{
1600 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001601 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001602}
1603
1604/* capture mixer elements */
1605#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1606
1607static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1608 struct snd_ctl_elem_value *ucontrol)
1609{
1610 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001611 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001612}
1613
1614static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1615 struct snd_ctl_elem_value *ucontrol)
1616{
1617 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001618 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001619}
1620
Takashi Iwaia23b6882009-03-23 15:21:36 +01001621#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001622 { \
1623 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1624 .name = "Capture Switch", \
1625 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1626 .count = num, \
1627 .info = alc_cap_sw_info, \
1628 .get = alc_cap_sw_get, \
1629 .put = alc_cap_sw_put, \
1630 }, \
1631 { \
1632 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1633 .name = "Capture Volume", \
1634 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1635 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1636 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1637 .count = num, \
1638 .info = alc_cap_vol_info, \
1639 .get = alc_cap_vol_get, \
1640 .put = alc_cap_vol_put, \
1641 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001642 }
1643
1644#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001645 { \
1646 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1647 /* .name = "Capture Source", */ \
1648 .name = "Input Source", \
1649 .count = num, \
1650 .info = alc_mux_enum_info, \
1651 .get = alc_mux_enum_get, \
1652 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001653 }
1654
1655#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001656static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001657 _DEFINE_CAPMIX(num), \
1658 _DEFINE_CAPSRC(num), \
1659 { } /* end */ \
1660}
1661
1662#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001663static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001664 _DEFINE_CAPMIX(num), \
1665 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001666}
1667
1668/* up to three ADCs */
1669DEFINE_CAPMIX(1);
1670DEFINE_CAPMIX(2);
1671DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001672DEFINE_CAPMIX_NOSRC(1);
1673DEFINE_CAPMIX_NOSRC(2);
1674DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001675
1676/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001677 * Inverted digital-mic handling
1678 *
1679 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1680 * gives the additional mute only to the right channel of the digital mic
1681 * capture stream. This is a workaround for avoiding the almost silence
1682 * by summing the stereo stream from some (known to be ForteMedia)
1683 * digital mic unit.
1684 *
1685 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1686 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1687 * without caching so that the cache can still keep the original value.
1688 * The cached value is then restored when the flag is set off or any other
1689 * than d-mic is used as the current input source.
1690 */
1691static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1692{
1693 struct alc_spec *spec = codec->spec;
1694 int i;
1695
1696 if (!spec->inv_dmic_fixup)
1697 return;
1698 if (!spec->inv_dmic_muted && !force)
1699 return;
1700 for (i = 0; i < spec->num_adc_nids; i++) {
1701 int src = spec->dyn_adc_switch ? 0 : i;
1702 bool dmic_fixup = false;
1703 hda_nid_t nid;
1704 int parm, dir, v;
1705
1706 if (spec->inv_dmic_muted &&
1707 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1708 dmic_fixup = true;
1709 if (!dmic_fixup && !force)
1710 continue;
1711 if (spec->vol_in_capsrc) {
1712 nid = spec->capsrc_nids[i];
1713 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1714 dir = HDA_OUTPUT;
1715 } else {
1716 nid = spec->adc_nids[i];
1717 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1718 dir = HDA_INPUT;
1719 }
1720 /* we care only right channel */
1721 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1722 if (v & 0x80) /* if already muted, we don't need to touch */
1723 continue;
1724 if (dmic_fixup) /* add mute for d-mic */
1725 v |= 0x80;
1726 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1727 parm | v);
1728 }
1729}
1730
1731static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1732 struct snd_ctl_elem_value *ucontrol)
1733{
1734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1735 struct alc_spec *spec = codec->spec;
1736
1737 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1738 return 0;
1739}
1740
1741static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1742 struct snd_ctl_elem_value *ucontrol)
1743{
1744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1745 struct alc_spec *spec = codec->spec;
1746 unsigned int val = !ucontrol->value.integer.value[0];
1747
1748 if (val == spec->inv_dmic_muted)
1749 return 0;
1750 spec->inv_dmic_muted = val;
1751 alc_inv_dmic_sync(codec, true);
1752 return 0;
1753}
1754
1755static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1756 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1757 .info = snd_ctl_boolean_mono_info,
1758 .get = alc_inv_dmic_sw_get,
1759 .put = alc_inv_dmic_sw_put,
1760};
1761
1762static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1763{
1764 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001765
1766 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1767 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001768 return -ENOMEM;
1769 spec->inv_dmic_fixup = 1;
1770 spec->inv_dmic_muted = 0;
1771 spec->inv_dmic_pin = nid;
1772 return 0;
1773}
1774
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001775/* typically the digital mic is put at node 0x12 */
1776static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1777 const struct alc_fixup *fix, int action)
1778{
1779 if (action == ALC_FIXUP_ACT_PROBE)
1780 alc_add_inv_dmic_mixer(codec, 0x12);
1781}
1782
Takashi Iwai125821a2012-06-22 14:30:29 +02001783/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001784 * virtual master controls
1785 */
1786
1787/*
1788 * slave controls for virtual master
1789 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001790static const char * const alc_slave_pfxs[] = {
1791 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001792 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001793 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001794 NULL,
1795};
1796
1797/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001798 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001800
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001801#define NID_MAPPING (-1)
1802
1803#define SUBDEV_SPEAKER_ (0 << 6)
1804#define SUBDEV_HP_ (1 << 6)
1805#define SUBDEV_LINE_ (2 << 6)
1806#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1807#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1808#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1809
Takashi Iwai603c4012008-07-30 15:01:44 +02001810static void alc_free_kctls(struct hda_codec *codec);
1811
Takashi Iwai67d634c2009-11-16 15:35:59 +01001812#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001813/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001814static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001815 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001816 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001817 { } /* end */
1818};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001819#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001820
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001821static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822{
1823 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001824 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001825 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001826 int i, j, err;
1827 unsigned int u;
1828 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
1830 for (i = 0; i < spec->num_mixers; i++) {
1831 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1832 if (err < 0)
1833 return err;
1834 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001835 if (spec->cap_mixer) {
1836 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1837 if (err < 0)
1838 return err;
1839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001841 err = snd_hda_create_dig_out_ctls(codec,
1842 spec->multiout.dig_out_nid,
1843 spec->multiout.dig_out_nid,
1844 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 if (err < 0)
1846 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001847 if (!spec->no_analog) {
1848 err = snd_hda_create_spdif_share_sw(codec,
1849 &spec->multiout);
1850 if (err < 0)
1851 return err;
1852 spec->multiout.share_spdif = 1;
1853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 }
1855 if (spec->dig_in_nid) {
1856 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1857 if (err < 0)
1858 return err;
1859 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001860
Takashi Iwai67d634c2009-11-16 15:35:59 +01001861#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001862 /* create beep controls if needed */
1863 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001864 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001865 for (knew = alc_beep_mixer; knew->name; knew++) {
1866 struct snd_kcontrol *kctl;
1867 kctl = snd_ctl_new1(knew, codec);
1868 if (!kctl)
1869 return -ENOMEM;
1870 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001871 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001872 if (err < 0)
1873 return err;
1874 }
1875 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001876#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001877
Takashi Iwai2134ea42008-01-10 16:53:55 +01001878 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001879 if (!spec->no_analog &&
1880 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001881 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001882 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001883 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001884 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001885 vmaster_tlv, alc_slave_pfxs,
1886 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001887 if (err < 0)
1888 return err;
1889 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001890 if (!spec->no_analog &&
1891 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001892 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1893 NULL, alc_slave_pfxs,
1894 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001895 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001896 if (err < 0)
1897 return err;
1898 }
1899
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001900 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001901 if (spec->capsrc_nids || spec->adc_nids) {
1902 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1903 if (!kctl)
1904 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1905 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001906 err = snd_hda_add_nid(codec, kctl, i,
1907 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001908 if (err < 0)
1909 return err;
1910 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001911 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001912 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001913 const char *kname = kctl ? kctl->id.name : NULL;
1914 for (knew = spec->cap_mixer; knew->name; knew++) {
1915 if (kname && strcmp(knew->name, kname) == 0)
1916 continue;
1917 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1918 for (i = 0; kctl && i < kctl->count; i++) {
1919 err = snd_hda_add_nid(codec, kctl, i,
1920 spec->adc_nids[i]);
1921 if (err < 0)
1922 return err;
1923 }
1924 }
1925 }
1926
1927 /* other nid->control mapping */
1928 for (i = 0; i < spec->num_mixers; i++) {
1929 for (knew = spec->mixers[i]; knew->name; knew++) {
1930 if (knew->iface != NID_MAPPING)
1931 continue;
1932 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1933 if (kctl == NULL)
1934 continue;
1935 u = knew->subdevice;
1936 for (j = 0; j < 4; j++, u >>= 8) {
1937 nid = u & 0x3f;
1938 if (nid == 0)
1939 continue;
1940 switch (u & 0xc0) {
1941 case SUBDEV_SPEAKER_:
1942 nid = spec->autocfg.speaker_pins[nid];
1943 break;
1944 case SUBDEV_LINE_:
1945 nid = spec->autocfg.line_out_pins[nid];
1946 break;
1947 case SUBDEV_HP_:
1948 nid = spec->autocfg.hp_pins[nid];
1949 break;
1950 default:
1951 continue;
1952 }
1953 err = snd_hda_add_nid(codec, kctl, 0, nid);
1954 if (err < 0)
1955 return err;
1956 }
1957 u = knew->private_value;
1958 for (j = 0; j < 4; j++, u >>= 8) {
1959 nid = u & 0xff;
1960 if (nid == 0)
1961 continue;
1962 err = snd_hda_add_nid(codec, kctl, 0, nid);
1963 if (err < 0)
1964 return err;
1965 }
1966 }
1967 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001968
1969 alc_free_kctls(codec); /* no longer needed */
1970
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001971 return 0;
1972}
1973
David Henningsson5780b622012-06-27 18:45:45 +02001974static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001975{
1976 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02001977
1978 if (spec->shared_mic_hp) {
1979 int err;
1980 int nid = spec->autocfg.inputs[1].pin;
1981 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
1982 if (err < 0)
1983 return err;
1984 err = snd_hda_jack_detect_enable(codec, nid, 0);
1985 if (err < 0)
1986 return err;
1987 }
1988
1989 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
1990}
1991
1992static int alc_build_controls(struct hda_codec *codec)
1993{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001994 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001995 if (err < 0)
1996 return err;
David Henningsson5780b622012-06-27 18:45:45 +02001997
1998 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001999 if (err < 0)
2000 return err;
2001 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2002 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003}
2004
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002007 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002008 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002009
Takashi Iwai584c0c42011-03-10 12:51:11 +01002010static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002011static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002012
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013static int alc_init(struct hda_codec *codec)
2014{
2015 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002016
Takashi Iwai546bb672012-03-07 08:37:19 +01002017 if (spec->init_hook)
2018 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002019
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002020 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002021 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002022
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002023 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002024 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002025 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002026
Takashi Iwai58701122011-01-13 15:41:45 +01002027 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2028
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002029 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 return 0;
2031}
2032
Takashi Iwai83012a72012-08-24 18:38:08 +02002033#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002034static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2035{
2036 struct alc_spec *spec = codec->spec;
2037 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2038}
2039#endif
2040
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041/*
2042 * Analog playback callbacks
2043 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002044static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002046 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047{
2048 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002049 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2050 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051}
2052
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002053static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 struct hda_codec *codec,
2055 unsigned int stream_tag,
2056 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002057 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058{
2059 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002060 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2061 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062}
2063
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002064static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002066 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
2068 struct alc_spec *spec = codec->spec;
2069 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2070}
2071
2072/*
2073 * Digital out
2074 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002075static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002077 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078{
2079 struct alc_spec *spec = codec->spec;
2080 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2081}
2082
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002083static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002084 struct hda_codec *codec,
2085 unsigned int stream_tag,
2086 unsigned int format,
2087 struct snd_pcm_substream *substream)
2088{
2089 struct alc_spec *spec = codec->spec;
2090 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2091 stream_tag, format, substream);
2092}
2093
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002094static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002095 struct hda_codec *codec,
2096 struct snd_pcm_substream *substream)
2097{
2098 struct alc_spec *spec = codec->spec;
2099 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2100}
2101
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002102static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002104 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
2106 struct alc_spec *spec = codec->spec;
2107 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2108}
2109
2110/*
2111 * Analog capture
2112 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002113static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct hda_codec *codec,
2115 unsigned int stream_tag,
2116 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002117 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
2119 struct alc_spec *spec = codec->spec;
2120
Takashi Iwai63300792008-01-24 15:31:36 +01002121 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 stream_tag, 0, format);
2123 return 0;
2124}
2125
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002126static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002128 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 struct alc_spec *spec = codec->spec;
2131
Takashi Iwai888afa12008-03-18 09:57:50 +01002132 snd_hda_codec_cleanup_stream(codec,
2133 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 return 0;
2135}
2136
Takashi Iwai840b64c2010-07-13 22:49:01 +02002137/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002138static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002139 struct hda_codec *codec,
2140 unsigned int stream_tag,
2141 unsigned int format,
2142 struct snd_pcm_substream *substream)
2143{
2144 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002145 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002146 spec->cur_adc_stream_tag = stream_tag;
2147 spec->cur_adc_format = format;
2148 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2149 return 0;
2150}
2151
Takashi Iwai21268962011-07-07 15:01:13 +02002152static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002153 struct hda_codec *codec,
2154 struct snd_pcm_substream *substream)
2155{
2156 struct alc_spec *spec = codec->spec;
2157 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2158 spec->cur_adc = 0;
2159 return 0;
2160}
2161
Takashi Iwai21268962011-07-07 15:01:13 +02002162static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002163 .substreams = 1,
2164 .channels_min = 2,
2165 .channels_max = 2,
2166 .nid = 0, /* fill later */
2167 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002168 .prepare = dyn_adc_capture_pcm_prepare,
2169 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002170 },
2171};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
2173/*
2174 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002175static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 .substreams = 1,
2177 .channels_min = 2,
2178 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002179 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002181 .open = alc_playback_pcm_open,
2182 .prepare = alc_playback_pcm_prepare,
2183 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 },
2185};
2186
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002187static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002188 .substreams = 1,
2189 .channels_min = 2,
2190 .channels_max = 2,
2191 /* NID is set in alc_build_pcms */
2192};
2193
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002194static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002195 .substreams = 1,
2196 .channels_min = 2,
2197 .channels_max = 2,
2198 /* NID is set in alc_build_pcms */
2199};
2200
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002201static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002202 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 .channels_min = 2,
2204 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002205 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002207 .prepare = alc_alt_capture_pcm_prepare,
2208 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 },
2210};
2211
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002212static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 .substreams = 1,
2214 .channels_min = 2,
2215 .channels_max = 2,
2216 /* NID is set in alc_build_pcms */
2217 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002218 .open = alc_dig_playback_pcm_open,
2219 .close = alc_dig_playback_pcm_close,
2220 .prepare = alc_dig_playback_pcm_prepare,
2221 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 },
2223};
2224
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002225static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 .substreams = 1,
2227 .channels_min = 2,
2228 .channels_max = 2,
2229 /* NID is set in alc_build_pcms */
2230};
2231
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002232/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002233static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002234 .substreams = 0,
2235 .channels_min = 0,
2236 .channels_max = 0,
2237};
2238
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239static int alc_build_pcms(struct hda_codec *codec)
2240{
2241 struct alc_spec *spec = codec->spec;
2242 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002243 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002244 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 int i;
2246
2247 codec->num_pcms = 1;
2248 codec->pcm_info = info;
2249
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002250 if (spec->no_analog)
2251 goto skip_analog;
2252
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002253 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2254 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002256
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002257 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002258 p = spec->stream_analog_playback;
2259 if (!p)
2260 p = &alc_pcm_analog_playback;
2261 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002262 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002263 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2264 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002265 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2266 spec->autocfg.line_outs == 2)
2267 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2268 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002269 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002270 if (spec->adc_nids) {
2271 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002272 if (!p) {
2273 if (spec->dyn_adc_switch)
2274 p = &dyn_adc_pcm_analog_capture;
2275 else
2276 p = &alc_pcm_analog_capture;
2277 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002278 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002279 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Takashi Iwai4a471b72005-12-07 13:56:29 +01002282 if (spec->channel_mode) {
2283 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2284 for (i = 0; i < spec->num_channel_mode; i++) {
2285 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2286 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 }
2289 }
2290
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002291 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002292 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002294 snprintf(spec->stream_name_digital,
2295 sizeof(spec->stream_name_digital),
2296 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002297 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002298 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002299 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002301 if (spec->dig_out_type)
2302 info->pcm_type = spec->dig_out_type;
2303 else
2304 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002305 if (spec->multiout.dig_out_nid) {
2306 p = spec->stream_digital_playback;
2307 if (!p)
2308 p = &alc_pcm_digital_playback;
2309 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2311 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002312 if (spec->dig_in_nid) {
2313 p = spec->stream_digital_capture;
2314 if (!p)
2315 p = &alc_pcm_digital_capture;
2316 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2318 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002319 /* FIXME: do we need this for all Realtek codec models? */
2320 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 }
2322
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002323 if (spec->no_analog)
2324 return 0;
2325
Takashi Iwaie08a0072006-09-07 17:52:14 +02002326 /* If the use of more than one ADC is requested for the current
2327 * model, configure a second analog capture-only PCM.
2328 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002329 have_multi_adcs = (spec->num_adc_nids > 1) &&
2330 !spec->dyn_adc_switch && !spec->auto_mic &&
2331 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002332 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002333 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002334 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002335 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002336 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002337 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002338 p = spec->stream_analog_alt_playback;
2339 if (!p)
2340 p = &alc_pcm_analog_alt_playback;
2341 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002342 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2343 spec->alt_dac_nid;
2344 } else {
2345 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2346 alc_pcm_null_stream;
2347 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2348 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002349 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002350 p = spec->stream_analog_alt_capture;
2351 if (!p)
2352 p = &alc_pcm_analog_alt_capture;
2353 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002354 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2355 spec->adc_nids[1];
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2357 spec->num_adc_nids - 1;
2358 } else {
2359 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2360 alc_pcm_null_stream;
2361 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002362 }
2363 }
2364
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 return 0;
2366}
2367
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002368static inline void alc_shutup(struct hda_codec *codec)
2369{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002370 struct alc_spec *spec = codec->spec;
2371
2372 if (spec && spec->shutup)
2373 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002374 snd_hda_shutup_pins(codec);
2375}
2376
Takashi Iwai603c4012008-07-30 15:01:44 +02002377static void alc_free_kctls(struct hda_codec *codec)
2378{
2379 struct alc_spec *spec = codec->spec;
2380
2381 if (spec->kctls.list) {
2382 struct snd_kcontrol_new *kctl = spec->kctls.list;
2383 int i;
2384 for (i = 0; i < spec->kctls.used; i++)
2385 kfree(kctl[i].name);
2386 }
2387 snd_array_free(&spec->kctls);
2388}
2389
Takashi Iwai23c09b02011-08-19 09:05:35 +02002390static void alc_free_bind_ctls(struct hda_codec *codec)
2391{
2392 struct alc_spec *spec = codec->spec;
2393 if (spec->bind_ctls.list) {
2394 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2395 int i;
2396 for (i = 0; i < spec->bind_ctls.used; i++)
2397 kfree(ctl[i]);
2398 }
2399 snd_array_free(&spec->bind_ctls);
2400}
2401
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402static void alc_free(struct hda_codec *codec)
2403{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002404 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002405
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002406 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002407 return;
2408
Takashi Iwai603c4012008-07-30 15:01:44 +02002409 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002410 alc_free_bind_ctls(codec);
Takashi Iwaic9967f12012-12-14 16:39:22 +01002411 snd_array_free(&spec->paths);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002412 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002413 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002414 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
Takashi Iwai83012a72012-08-24 18:38:08 +02002417#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002418static void alc_power_eapd(struct hda_codec *codec)
2419{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002420 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002421}
2422
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002423static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002424{
2425 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002426 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002427 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002428 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002429 return 0;
2430}
2431#endif
2432
Takashi Iwai2a439522011-07-26 09:52:50 +02002433#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002434static int alc_resume(struct hda_codec *codec)
2435{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002436 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002437 codec->patch_ops.init(codec);
2438 snd_hda_codec_resume_amp(codec);
2439 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002440 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002441 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002442 return 0;
2443}
Takashi Iwaie044c392008-10-27 16:56:24 +01002444#endif
2445
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446/*
2447 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002448static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 .build_controls = alc_build_controls,
2450 .build_pcms = alc_build_pcms,
2451 .init = alc_init,
2452 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002453 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002454#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002455 .resume = alc_resume,
2456#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002457#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002458 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002459 .check_power_status = alc_check_power_status,
2460#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002461 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462};
2463
David Henningsson29adc4b2012-09-25 11:31:00 +02002464
Kailang Yangc027ddc2010-03-19 11:33:06 +01002465/* replace the codec chip_name with the given string */
2466static int alc_codec_rename(struct hda_codec *codec, const char *name)
2467{
2468 kfree(codec->chip_name);
2469 codec->chip_name = kstrdup(name, GFP_KERNEL);
2470 if (!codec->chip_name) {
2471 alc_free(codec);
2472 return -ENOMEM;
2473 }
2474 return 0;
2475}
2476
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002477/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002478 * Rename codecs appropriately from COEF value
2479 */
2480struct alc_codec_rename_table {
2481 unsigned int vendor_id;
2482 unsigned short coef_mask;
2483 unsigned short coef_bits;
2484 const char *name;
2485};
2486
2487static struct alc_codec_rename_table rename_tbl[] = {
2488 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2489 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2490 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2491 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2492 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2493 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2494 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002495 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002496 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2497 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2498 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2499 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2500 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2501 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2502 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2503 { } /* terminator */
2504};
2505
2506static int alc_codec_rename_from_preset(struct hda_codec *codec)
2507{
2508 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002509
2510 for (p = rename_tbl; p->vendor_id; p++) {
2511 if (p->vendor_id != codec->vendor_id)
2512 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002513 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002514 return alc_codec_rename(codec, p->name);
2515 }
2516 return 0;
2517}
2518
2519/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002520 * Automatic parse of I/O pins from the BIOS configuration
2521 */
2522
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002523enum {
2524 ALC_CTL_WIDGET_VOL,
2525 ALC_CTL_WIDGET_MUTE,
2526 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002527 ALC_CTL_BIND_VOL,
2528 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002529};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002530static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002531 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2532 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002533 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002534 HDA_BIND_VOL(NULL, 0),
2535 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002536};
2537
2538/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002539static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002540 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002541{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002542 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002543
Takashi Iwai668d1e92012-11-29 14:10:17 +01002544 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002545 if (!knew)
2546 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002547 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002548 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002549 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002550 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002551 return 0;
2552}
2553
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002554static int add_control_with_pfx(struct alc_spec *spec, int type,
2555 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002556 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002557{
2558 char name[32];
2559 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002560 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002561}
2562
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002563#define add_pb_vol_ctrl(spec, type, pfx, val) \
2564 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2565#define add_pb_sw_ctrl(spec, type, pfx, val) \
2566 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2567#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2568 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2569#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2570 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002571
Takashi Iwai23c09b02011-08-19 09:05:35 +02002572static const char * const channel_name[4] = {
2573 "Front", "Surround", "CLFE", "Side"
2574};
2575
Takashi Iwai6843ca12011-06-24 11:03:58 +02002576static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2577 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002578{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002579 struct auto_pin_cfg *cfg = &spec->autocfg;
2580
Takashi Iwai6843ca12011-06-24 11:03:58 +02002581 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002582 if (cfg->line_outs == 1 && !spec->multi_ios &&
2583 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002584 return "Master";
2585
2586 switch (cfg->line_out_type) {
2587 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002588 if (cfg->line_outs == 1)
2589 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002590 if (cfg->line_outs == 2)
2591 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002592 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002593 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002594 /* for multi-io case, only the primary out */
2595 if (ch && spec->multi_ios)
2596 break;
2597 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002598 return "Headphone";
2599 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002600 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002601 return "PCM";
2602 break;
2603 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002604 if (ch >= ARRAY_SIZE(channel_name)) {
2605 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002606 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002607 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002608
2609 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002610}
2611
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002612static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2613 hda_nid_t to_nid, int with_aa_mix,
2614 struct nid_path *path);
2615
Takashi Iwai83012a72012-08-24 18:38:08 +02002616#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002617/* add the powersave loopback-list entry */
2618static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2619{
2620 struct hda_amp_list *list;
2621
2622 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2623 return;
2624 list = spec->loopback_list + spec->num_loopbacks;
2625 list->nid = mix;
2626 list->dir = HDA_INPUT;
2627 list->idx = idx;
2628 spec->num_loopbacks++;
2629 spec->loopback.amplist = spec->loopback_list;
2630}
2631#else
2632#define add_loopback_list(spec, mix, idx) /* NOP */
2633#endif
2634
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002635/* create input playback/capture controls for the given pin */
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002636static int new_analog_input(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002637 const char *ctlname, int ctlidx,
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002638 hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002639{
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002640 struct alc_spec *spec = codec->spec;
2641 struct nid_path *path;
2642 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002643
Takashi Iwaibd32f782012-12-12 18:08:52 +01002644 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2645 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2646 return 0; /* no need for analog loopback */
2647
Takashi Iwaic9967f12012-12-14 16:39:22 +01002648 path = snd_array_new(&spec->paths);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002649 if (!path)
2650 return -ENOMEM;
2651 memset(path, 0, sizeof(*path));
2652 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2653 return -EINVAL;
2654
2655 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002656 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
2657 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002658 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002659 if (err < 0)
2660 return err;
2661 }
2662
2663 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
2664 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002665 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
Takashi Iwaibd32f782012-12-12 18:08:52 +01002666 if (err < 0)
2667 return err;
2668 }
2669
Takashi Iwai164f73e2012-02-21 11:27:09 +01002670 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002671 return 0;
2672}
2673
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002674static int new_capture_source(struct hda_codec *codec, int adc_idx,
2675 hda_nid_t pin, int idx, const char *label)
2676{
2677 struct alc_spec *spec = codec->spec;
2678 struct hda_input_mux *imux = &spec->private_imux[0];
2679 struct nid_path *path;
2680
Takashi Iwaic9967f12012-12-14 16:39:22 +01002681 path = snd_array_new(&spec->paths);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002682 if (!path)
2683 return -ENOMEM;
2684 memset(path, 0, sizeof(*path));
2685 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2686 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2687 pin, spec->adc_nids[adc_idx]);
2688 return -EINVAL;
2689 }
2690
2691 spec->imux_pins[imux->num_items] = pin;
2692 snd_hda_add_imux_item(imux, label, idx, NULL);
2693 return 0;
2694}
2695
Takashi Iwai05f5f472009-08-25 13:10:18 +02002696static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002697{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002698 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2699 return (pincap & AC_PINCAP_IN) != 0;
2700}
2701
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002702/* check whether the given two widgets can be connected */
2703static bool is_reachable_path(struct hda_codec *codec,
2704 hda_nid_t from_nid, hda_nid_t to_nid)
2705{
2706 if (!from_nid || !to_nid)
2707 return false;
2708 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2709}
2710
Takashi Iwai1d045db2011-07-07 18:23:21 +02002711/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002712static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002713{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002714 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002715 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002716 hda_nid_t *adc_nids = spec->private_adc_nids;
2717 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2718 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002719 int i, nums = 0;
2720
2721 nid = codec->start_nid;
2722 for (i = 0; i < codec->num_nodes; i++, nid++) {
2723 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002724 unsigned int caps = get_wcaps(codec, nid);
2725 int type = get_wcaps_type(caps);
2726
2727 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2728 continue;
2729 adc_nids[nums] = nid;
2730 cap_nids[nums] = nid;
2731 src = nid;
2732 for (;;) {
2733 int n;
2734 type = get_wcaps_type(get_wcaps(codec, src));
2735 if (type == AC_WID_PIN)
2736 break;
2737 if (type == AC_WID_AUD_SEL) {
2738 cap_nids[nums] = src;
2739 break;
2740 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002741 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002742 if (n > 1) {
2743 cap_nids[nums] = src;
2744 break;
2745 } else if (n != 1)
2746 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002747 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2748 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002749 }
2750 if (++nums >= max_nums)
2751 break;
2752 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002753 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002754 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002755 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002756 return nums;
2757}
2758
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002760static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761{
2762 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002763 const struct auto_pin_cfg *cfg = &spec->autocfg;
2764 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002765 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002766 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002767 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002768 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002769
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002770 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002771 if (num_adcs < 0)
2772 return 0;
2773
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002774 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002775 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002776 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002777
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002778 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002779 if (!alc_is_input_pin(codec, pin))
2780 continue;
2781
David Henningsson5322bf22011-01-05 11:03:56 +01002782 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002783 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2784 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002785 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002786 type_idx++;
2787 else
2788 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002789 prev_label = label;
2790
Takashi Iwai05f5f472009-08-25 13:10:18 +02002791 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002792 if (is_reachable_path(codec, pin, mixer)) {
2793 err = new_analog_input(codec, pin,
2794 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002795 if (err < 0)
2796 return err;
2797 }
2798 }
2799
Takashi Iwaib7821702011-07-06 15:12:46 +02002800 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002801 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002802 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002803 if (idx >= 0) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002804 err = new_capture_source(codec, c, pin, idx, label);
2805 if (err < 0)
2806 return err;
Takashi Iwaib7821702011-07-06 15:12:46 +02002807 break;
2808 }
2809 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002810 }
Takashi Iwai21268962011-07-07 15:01:13 +02002811
2812 spec->num_mux_defs = 1;
2813 spec->input_mux = imux;
2814
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002815 return 0;
2816}
2817
Takashi Iwai24de1832011-11-07 17:13:39 +01002818/* create a shared input with the headphone out */
2819static int alc_auto_create_shared_input(struct hda_codec *codec)
2820{
2821 struct alc_spec *spec = codec->spec;
2822 struct auto_pin_cfg *cfg = &spec->autocfg;
2823 unsigned int defcfg;
2824 hda_nid_t nid;
2825
2826 /* only one internal input pin? */
2827 if (cfg->num_inputs != 1)
2828 return 0;
2829 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2830 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2831 return 0;
2832
2833 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2834 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2835 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2836 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2837 else
2838 return 0; /* both not available */
2839
2840 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2841 return 0; /* no input */
2842
2843 cfg->inputs[1].pin = nid;
2844 cfg->inputs[1].type = AUTO_PIN_MIC;
2845 cfg->num_inputs = 2;
2846 spec->shared_mic_hp = 1;
2847 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2848 return 0;
2849}
2850
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002851static int get_pin_type(int line_out_type)
2852{
2853 if (line_out_type == AUTO_PIN_HP_OUT)
2854 return PIN_HP;
2855 else
2856 return PIN_OUT;
2857}
2858
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002859static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002860{
2861 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002862 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002863 int i;
2864
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002865 for (i = 0; i < cfg->num_inputs; i++) {
2866 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002867 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002868 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002869 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002870 snd_hda_codec_write(codec, nid, 0,
2871 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002872 AMP_OUT_MUTE);
2873 }
2874 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002875
2876 /* mute all loopback inputs */
2877 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002878 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002879 for (i = 0; i < nums; i++)
2880 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2881 AC_VERB_SET_AMP_GAIN_MUTE,
2882 AMP_IN_MUTE(i));
2883 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002884}
2885
Takashi Iwai185d99f2012-02-16 18:39:45 +01002886static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2887{
2888 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002889 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002890
Takashi Iwaic9967f12012-12-14 16:39:22 +01002891 for (i = 0; i < spec->paths.used; i++) {
2892 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002893 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002894 return true;
2895 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002896 return false;
2897}
2898
Takashi Iwai463419d2012-12-05 14:17:37 +01002899/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002900static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2901 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002902{
2903 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002904 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002905 int i;
2906
2907 for (i = 0; i < spec->num_all_dacs; i++) {
2908 hda_nid_t nid = spec->all_dacs[i];
2909 if (!nid || alc_is_dac_already_used(codec, nid))
2910 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002911 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2912 if (is_digital != cap_digital)
2913 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002914 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002915 return nid;
2916 }
2917 return 0;
2918}
2919
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002920/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002921static bool __parse_nid_path(struct hda_codec *codec,
2922 hda_nid_t from_nid, hda_nid_t to_nid,
2923 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002924{
2925 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002926 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002927 int i, nums;
2928
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002929 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002930 if (!with_aa_mix)
2931 return false;
2932 with_aa_mix = 2; /* mark aa-mix is included */
2933 }
2934
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002935 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002936 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002937 if (conn[i] != from_nid) {
2938 /* special case: when from_nid is 0,
2939 * try to find an empty DAC
2940 */
2941 if (from_nid ||
2942 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2943 alc_is_dac_already_used(codec, conn[i]))
2944 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002945 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002946 /* aa-mix is requested but not included? */
2947 if (!(spec->mixer_nid && with_aa_mix == 1))
2948 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002949 }
2950 if (depth >= MAX_NID_PATH_DEPTH)
2951 return false;
2952 for (i = 0; i < nums; i++) {
2953 unsigned int type;
2954 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002955 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2956 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002957 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002958 if (__parse_nid_path(codec, from_nid, conn[i],
2959 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002960 goto found;
2961 }
2962 return false;
2963
2964 found:
2965 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002966 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002967 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002968 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002969 path->depth++;
2970 return true;
2971}
2972
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002973/* parse the widget path from the given nid to the target nid;
2974 * when @from_nid is 0, try to find an empty DAC;
2975 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2976 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2977 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002978 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002979static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2980 hda_nid_t to_nid, int with_aa_mix,
2981 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002982{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002983 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2984 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002985 path->depth++;
2986#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002987 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002988 path->depth, path->path[0], path->path[1],
2989 path->path[2], path->path[3], path->path[4]);
2990#endif
2991 return true;
2992 }
2993 return false;
2994}
2995
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002996static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2997{
Takashi Iwai140547e2012-02-16 17:23:46 +01002998 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01002999 int i;
3000 hda_nid_t nid_found = 0;
3001
3002 for (i = 0; i < spec->num_all_dacs; i++) {
3003 hda_nid_t nid = spec->all_dacs[i];
3004 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003005 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01003006 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003007 if (nid_found)
3008 return 0;
3009 nid_found = nid;
3010 }
3011 }
3012 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003013}
3014
Takashi Iwaiba8111272012-12-06 18:06:23 +01003015static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003016{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003017 struct alc_spec *spec = codec->spec;
3018 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003019
Takashi Iwaic9967f12012-12-14 16:39:22 +01003020 for (i = 0; i < spec->paths.used; i++) {
3021 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003022 if (path->ctls[type] == val)
3023 return true;
3024 }
3025 return false;
3026}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003027
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003028/* badness definition */
3029enum {
3030 /* No primary DAC is found for the main output */
3031 BAD_NO_PRIMARY_DAC = 0x10000,
3032 /* No DAC is found for the extra output */
3033 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003034 /* No possible multi-ios */
3035 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003036 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003037 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003038 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003039 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003040 /* Primary DAC shared with main surrounds */
3041 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003042 /* Primary DAC shared with main CLFE */
3043 BAD_SHARED_CLFE = 0x10,
3044 /* Primary DAC shared with extra surrounds */
3045 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003046 /* Volume widget is shared */
3047 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003048};
3049
3050static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003051 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003052static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003053 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003054
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003055static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3056 hda_nid_t dac)
3057{
3058 struct alc_spec *spec = codec->spec;
3059 struct nid_path *path;
3060
Takashi Iwaic9967f12012-12-14 16:39:22 +01003061 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003062 if (!path)
3063 return false;
3064 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003065 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003066 return true;
3067 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01003068 spec->paths.used--;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003069 return false;
3070}
3071
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003072/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003073 * passing 0 to either @pin or @dac behaves as a wildcard
3074 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003075static struct nid_path *
3076get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01003077{
3078 struct alc_spec *spec = codec->spec;
3079 int i;
3080
Takashi Iwaic9967f12012-12-14 16:39:22 +01003081 for (i = 0; i < spec->paths.used; i++) {
3082 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003083 if (path->depth <= 0)
3084 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003085 if ((!from_nid || path->path[0] == from_nid) &&
3086 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01003087 return path;
3088 }
3089 return NULL;
3090}
3091
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003092/* look for widgets in the path between the given NIDs appropriate for
3093 * volume and mute controls, and assign the values to ctls[].
3094 *
3095 * When no appropriate widget is found in the path, the badness value
3096 * is incremented depending on the situation. The function returns the
3097 * total badness for both volume and mute controls.
3098 */
3099static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3100 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003101{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003102 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003103 hda_nid_t nid;
3104 unsigned int val;
3105 int badness = 0;
3106
Takashi Iwaiba8111272012-12-06 18:06:23 +01003107 if (!path)
3108 return BAD_SHARED_VOL * 2;
3109 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003110 if (nid) {
3111 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003112 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003113 badness += BAD_SHARED_VOL;
3114 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003115 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003116 } else
3117 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003118 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003119 if (nid) {
3120 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003121 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3122 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003123 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3124 else
3125 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003126 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003127 badness += BAD_SHARED_VOL;
3128 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003129 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003130 } else
3131 badness += BAD_SHARED_VOL;
3132 return badness;
3133}
3134
Takashi Iwaidc31b582012-02-17 17:27:53 +01003135struct badness_table {
3136 int no_primary_dac; /* no primary DAC */
3137 int no_dac; /* no secondary DACs */
3138 int shared_primary; /* primary DAC is shared with main output */
3139 int shared_surr; /* secondary DAC shared with main or primary */
3140 int shared_clfe; /* third DAC shared with main or primary */
3141 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3142};
3143
3144static struct badness_table main_out_badness = {
3145 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3146 .no_dac = BAD_NO_DAC,
3147 .shared_primary = BAD_NO_PRIMARY_DAC,
3148 .shared_surr = BAD_SHARED_SURROUND,
3149 .shared_clfe = BAD_SHARED_CLFE,
3150 .shared_surr_main = BAD_SHARED_SURROUND,
3151};
3152
3153static struct badness_table extra_out_badness = {
3154 .no_primary_dac = BAD_NO_DAC,
3155 .no_dac = BAD_NO_DAC,
3156 .shared_primary = BAD_NO_EXTRA_DAC,
3157 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3158 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3159 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3160};
3161
3162/* try to assign DACs to pins and return the resultant badness */
3163static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3164 const hda_nid_t *pins, hda_nid_t *dacs,
3165 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003166{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003167 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003168 struct auto_pin_cfg *cfg = &spec->autocfg;
3169 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003170 int badness = 0;
3171 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003172
Takashi Iwai185d99f2012-02-16 18:39:45 +01003173 if (!num_outs)
3174 return 0;
3175
Takashi Iwaidc31b582012-02-17 17:27:53 +01003176 for (i = 0; i < num_outs; i++) {
3177 hda_nid_t pin = pins[i];
3178 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003179 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003180 if (!dacs[i] && !i) {
3181 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003182 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003183 dacs[0] = dacs[j];
3184 dacs[j] = 0;
3185 break;
3186 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003187 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003188 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003189 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003190 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003191 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003192 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003193 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003194 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003195 dac = spec->private_dac_nids[i];
3196 if (dac) {
3197 if (!i)
3198 badness += bad->shared_primary;
3199 else if (i == 1)
3200 badness += bad->shared_surr;
3201 else
3202 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003203 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003204 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003205 badness += bad->shared_surr_main;
3206 } else if (!i)
3207 badness += bad->no_primary_dac;
3208 else
3209 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003210 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003211 if (!add_new_out_path(codec, pin, dac))
3212 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003213 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003214 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003215 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003216
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003217 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003218}
3219
3220static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003221 hda_nid_t reference_pin,
3222 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003223
Takashi Iwai185d99f2012-02-16 18:39:45 +01003224static bool alc_map_singles(struct hda_codec *codec, int outs,
3225 const hda_nid_t *pins, hda_nid_t *dacs)
3226{
3227 int i;
3228 bool found = false;
3229 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003230 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003231 if (dacs[i])
3232 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003233 dac = get_dac_if_single(codec, pins[i]);
3234 if (!dac)
3235 continue;
3236 if (add_new_out_path(codec, pins[i], dac)) {
3237 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003238 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003239 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003240 }
3241 return found;
3242}
3243
Takashi Iwai7085ec12009-10-02 09:03:58 +02003244/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003245static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003246 bool fill_hardwired,
3247 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003248{
3249 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003250 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003251 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003252
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003253 /* set num_dacs once to full for alc_auto_look_for_dac() */
3254 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003255 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003256 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3257 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3258 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003259 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003260 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003261 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003262
3263 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003264 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003265 bool mapped;
3266 do {
3267 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003268 cfg->line_out_pins,
3269 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003270 mapped |= alc_map_singles(codec, cfg->hp_outs,
3271 cfg->hp_pins,
3272 spec->multiout.hp_out_nid);
3273 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3274 cfg->speaker_pins,
3275 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003276 if (fill_mio_first && cfg->line_outs == 1 &&
3277 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3278 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3279 if (!err)
3280 mapped = true;
3281 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003282 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003283 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003284
Takashi Iwaidc31b582012-02-17 17:27:53 +01003285 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3286 spec->private_dac_nids,
3287 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003288
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003289 /* re-count num_dacs and squash invalid entries */
3290 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003291 for (i = 0; i < cfg->line_outs; i++) {
3292 if (spec->private_dac_nids[i])
3293 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003294 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003295 memmove(spec->private_dac_nids + i,
3296 spec->private_dac_nids + i + 1,
3297 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003298 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3299 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003300 }
3301
Takashi Iwai276dd702012-02-17 16:17:03 +01003302 if (fill_mio_first &&
3303 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003304 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003305 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003306 if (err < 0)
3307 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003308 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003309 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003310
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003311 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003312 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3313 spec->multiout.hp_out_nid,
3314 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003315 if (err < 0)
3316 return err;
3317 badness += err;
3318 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003319 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003320 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3321 cfg->speaker_pins,
3322 spec->multiout.extra_out_nid,
3323 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003324 if (err < 0)
3325 return err;
3326 badness += err;
3327 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003328 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3329 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003330 if (err < 0)
3331 return err;
3332 badness += err;
3333 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003334 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3335 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003336 int offset = 0;
3337 if (cfg->line_outs >= 3)
3338 offset = 1;
3339 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3340 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003341 if (err < 0)
3342 return err;
3343 badness += err;
3344 }
3345
3346 if (spec->multi_ios == 2) {
3347 for (i = 0; i < 2; i++)
3348 spec->private_dac_nids[spec->multiout.num_dacs++] =
3349 spec->multi_io[i].dac;
3350 spec->ext_channel_count = 2;
3351 } else if (spec->multi_ios) {
3352 spec->multi_ios = 0;
3353 badness += BAD_MULTI_IO;
3354 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003355
3356 return badness;
3357}
3358
3359#define DEBUG_BADNESS
3360
3361#ifdef DEBUG_BADNESS
3362#define debug_badness snd_printdd
3363#else
3364#define debug_badness(...)
3365#endif
3366
3367static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3368{
3369 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3370 cfg->line_out_pins[0], cfg->line_out_pins[1],
3371 cfg->line_out_pins[2], cfg->line_out_pins[2],
3372 spec->multiout.dac_nids[0],
3373 spec->multiout.dac_nids[1],
3374 spec->multiout.dac_nids[2],
3375 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003376 if (spec->multi_ios > 0)
3377 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3378 spec->multi_ios,
3379 spec->multi_io[0].pin, spec->multi_io[1].pin,
3380 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003381 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3382 cfg->hp_pins[0], cfg->hp_pins[1],
3383 cfg->hp_pins[2], cfg->hp_pins[2],
3384 spec->multiout.hp_out_nid[0],
3385 spec->multiout.hp_out_nid[1],
3386 spec->multiout.hp_out_nid[2],
3387 spec->multiout.hp_out_nid[3]);
3388 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3389 cfg->speaker_pins[0], cfg->speaker_pins[1],
3390 cfg->speaker_pins[2], cfg->speaker_pins[3],
3391 spec->multiout.extra_out_nid[0],
3392 spec->multiout.extra_out_nid[1],
3393 spec->multiout.extra_out_nid[2],
3394 spec->multiout.extra_out_nid[3]);
3395}
3396
Takashi Iwai463419d2012-12-05 14:17:37 +01003397/* find all available DACs of the codec */
3398static void alc_fill_all_nids(struct hda_codec *codec)
3399{
3400 struct alc_spec *spec = codec->spec;
3401 int i;
3402 hda_nid_t nid = codec->start_nid;
3403
3404 spec->num_all_dacs = 0;
3405 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3406 for (i = 0; i < codec->num_nodes; i++, nid++) {
3407 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3408 continue;
3409 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3410 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3411 break;
3412 }
3413 spec->all_dacs[spec->num_all_dacs++] = nid;
3414 }
3415}
3416
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003417static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3418{
3419 struct alc_spec *spec = codec->spec;
3420 struct auto_pin_cfg *cfg = &spec->autocfg;
3421 struct auto_pin_cfg *best_cfg;
3422 int best_badness = INT_MAX;
3423 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003424 bool fill_hardwired = true, fill_mio_first = true;
3425 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003426 bool hp_spk_swapped = false;
3427
Takashi Iwai463419d2012-12-05 14:17:37 +01003428 alc_fill_all_nids(codec);
3429
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003430 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3431 if (!best_cfg)
3432 return -ENOMEM;
3433 *best_cfg = *cfg;
3434
3435 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003436 badness = fill_and_eval_dacs(codec, fill_hardwired,
3437 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003438 if (badness < 0) {
3439 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003440 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003441 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003442 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3443 cfg->line_out_type, fill_hardwired, fill_mio_first,
3444 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003445 debug_show_configs(spec, cfg);
3446 if (badness < best_badness) {
3447 best_badness = badness;
3448 *best_cfg = *cfg;
3449 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003450 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003451 }
3452 if (!badness)
3453 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003454 fill_mio_first = !fill_mio_first;
3455 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003456 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003457 fill_hardwired = !fill_hardwired;
3458 if (!fill_hardwired)
3459 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003460 if (hp_spk_swapped)
3461 break;
3462 hp_spk_swapped = true;
3463 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003464 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3465 cfg->hp_outs = cfg->line_outs;
3466 memcpy(cfg->hp_pins, cfg->line_out_pins,
3467 sizeof(cfg->hp_pins));
3468 cfg->line_outs = cfg->speaker_outs;
3469 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3470 sizeof(cfg->speaker_pins));
3471 cfg->speaker_outs = 0;
3472 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3473 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003474 fill_hardwired = true;
3475 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003476 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003477 if (cfg->hp_outs > 0 &&
3478 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3479 cfg->speaker_outs = cfg->line_outs;
3480 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3481 sizeof(cfg->speaker_pins));
3482 cfg->line_outs = cfg->hp_outs;
3483 memcpy(cfg->line_out_pins, cfg->hp_pins,
3484 sizeof(cfg->hp_pins));
3485 cfg->hp_outs = 0;
3486 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3487 cfg->line_out_type = AUTO_PIN_HP_OUT;
3488 fill_hardwired = true;
3489 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003490 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003491 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003492 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003493
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003494 if (badness) {
3495 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003496 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003497 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003498 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3499 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003500 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003501
Takashi Iwaiba8111272012-12-06 18:06:23 +01003502 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003503 struct nid_path *path = get_nid_path(codec,
3504 spec->multiout.dac_nids[0],
3505 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003506 if (path)
3507 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3508 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003509
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003510 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003511 return 0;
3512}
3513
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003514/* replace the channels in the composed amp value with the given number */
3515static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3516{
3517 val &= ~(0x3U << 16);
3518 val |= chs << 16;
3519 return val;
3520}
3521
Takashi Iwai343a04b2011-07-06 14:28:39 +02003522static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003523 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003524 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003525 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003526{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003527 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003528 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003529 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003530 val = path->ctls[NID_PATH_VOL_CTL];
3531 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003532 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003533 val = amp_val_replace_channels(val, chs);
3534 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3535}
3536
3537/* return the channel bits suitable for the given path->ctls[] */
3538static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3539 int type)
3540{
3541 int chs = 1; /* mono (left only) */
3542 if (path) {
3543 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3544 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3545 chs = 3; /* stereo */
3546 }
3547 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003548}
3549
Takashi Iwaie29d3772011-11-14 17:13:23 +01003550static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3551 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003552 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003553{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003554 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3555 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003556}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003557
3558/* create a mute-switch for the given mixer widget;
3559 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3560 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003561static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003562 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003563 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003564 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003565{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003566 unsigned int val;
3567 int type = ALC_CTL_WIDGET_MUTE;
3568
3569 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003570 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003571 val = path->ctls[NID_PATH_MUTE_CTL];
3572 if (!val)
3573 return 0;
3574 val = amp_val_replace_channels(val, chs);
3575 if (get_amp_direction_(val) == HDA_INPUT) {
3576 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003577 int nums = snd_hda_get_num_conns(codec, nid);
3578 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003579 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003580 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003581 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003582 }
3583 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003584}
3585
Takashi Iwaie29d3772011-11-14 17:13:23 +01003586static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003587 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003588{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003589 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3590 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003591}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003592
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003593static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003594 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003595{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003596 int i;
3597
3598 for (i = path->depth - 1; i >= 0; i--) {
3599 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3600 return path->path[i];
3601 if (i != path->depth - 1 && i != 0 &&
3602 nid_has_mute(codec, path->path[i], HDA_INPUT))
3603 return path->path[i];
3604 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003605 return 0;
3606}
3607
3608static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003609 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003610{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003611 int i;
3612
3613 for (i = path->depth - 1; i >= 0; i--) {
3614 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3615 return path->path[i];
3616 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003617 return 0;
3618}
3619
Takashi Iwai7085ec12009-10-02 09:03:58 +02003620/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003621static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003622 const struct auto_pin_cfg *cfg)
3623{
3624 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003625 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003626
Takashi Iwaice764ab2011-04-27 16:35:23 +02003627 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003628 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003629 noutputs += spec->multi_ios;
3630
3631 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003632 const char *name;
3633 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003634 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003635 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003636
3637 dac = spec->multiout.dac_nids[i];
3638 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003639 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003640 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003641 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003642 index = 0;
3643 name = channel_name[i];
3644 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003645 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003646 name = alc_get_line_out_pfx(spec, i, true, &index);
3647 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003648
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003649 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003650 if (!path)
3651 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003652 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003653 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003654 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003655 if (err < 0)
3656 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003657 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003658 if (err < 0)
3659 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003660 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003661 if (err < 0)
3662 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003663 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003664 if (err < 0)
3665 return err;
3666 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003667 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003668 if (err < 0)
3669 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003670 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003671 if (err < 0)
3672 return err;
3673 }
3674 }
3675 return 0;
3676}
3677
Takashi Iwai343a04b2011-07-06 14:28:39 +02003678static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003679 hda_nid_t dac, const char *pfx,
3680 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003681{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003682 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003683 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003684
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003685 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003686 if (!path)
3687 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003688 /* bind volume control will be created in the case of dac = 0 */
3689 if (dac) {
3690 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3691 if (err < 0)
3692 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003693 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003694 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003695 if (err < 0)
3696 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003697 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003698}
3699
Takashi Iwai23c09b02011-08-19 09:05:35 +02003700static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3701 unsigned int nums,
3702 struct hda_ctl_ops *ops)
3703{
3704 struct alc_spec *spec = codec->spec;
3705 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003706 ctlp = snd_array_new(&spec->bind_ctls);
3707 if (!ctlp)
3708 return NULL;
3709 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3710 *ctlp = ctl;
3711 if (ctl)
3712 ctl->ops = ops;
3713 return ctl;
3714}
3715
3716/* add playback controls for speaker and HP outputs */
3717static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3718 const hda_nid_t *pins,
3719 const hda_nid_t *dacs,
3720 const char *pfx)
3721{
3722 struct alc_spec *spec = codec->spec;
3723 struct hda_bind_ctls *ctl;
3724 char name[32];
3725 int i, n, err;
3726
3727 if (!num_pins || !pins[0])
3728 return 0;
3729
Takashi Iwai527e4d72011-10-27 16:33:27 +02003730 if (num_pins == 1) {
3731 hda_nid_t dac = *dacs;
3732 if (!dac)
3733 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003734 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003735 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003736
Takashi Iwai23c09b02011-08-19 09:05:35 +02003737 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003738 hda_nid_t dac;
3739 if (dacs[num_pins - 1])
3740 dac = dacs[i]; /* with individual volumes */
3741 else
3742 dac = 0;
3743 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3744 err = alc_auto_create_extra_out(codec, pins[i], dac,
3745 "Bass Speaker", 0);
3746 } else if (num_pins >= 3) {
3747 snprintf(name, sizeof(name), "%s %s",
3748 pfx, channel_name[i]);
3749 err = alc_auto_create_extra_out(codec, pins[i], dac,
3750 name, 0);
3751 } else {
3752 err = alc_auto_create_extra_out(codec, pins[i], dac,
3753 pfx, i);
3754 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003755 if (err < 0)
3756 return err;
3757 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003758 if (dacs[num_pins - 1])
3759 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003760
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003761 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003762 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3763 if (!ctl)
3764 return -ENOMEM;
3765 n = 0;
3766 for (i = 0; i < num_pins; i++) {
3767 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003768 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003769 if (!pins[i] || !dacs[i])
3770 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003771 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003772 if (!path)
3773 continue;
3774 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003775 if (vol)
3776 ctl->values[n++] =
3777 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3778 }
3779 if (n) {
3780 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3781 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3782 if (err < 0)
3783 return err;
3784 }
3785 return 0;
3786}
3787
Takashi Iwai343a04b2011-07-06 14:28:39 +02003788static int alc_auto_create_hp_out(struct hda_codec *codec)
3789{
3790 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003791 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3792 spec->autocfg.hp_pins,
3793 spec->multiout.hp_out_nid,
3794 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003795}
3796
3797static int alc_auto_create_speaker_out(struct hda_codec *codec)
3798{
3799 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003800 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3801 spec->autocfg.speaker_pins,
3802 spec->multiout.extra_out_nid,
3803 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003804}
3805
Takashi Iwai130e5f02012-12-14 16:09:29 +01003806/* check whether a control with the given (nid, dir, idx) was assigned */
3807static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3808 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003809{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003810 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003811 int i, type;
3812
3813 for (i = 0; i < spec->paths.used; i++) {
3814 struct nid_path *p = snd_array_elem(&spec->paths, i);
3815 if (p->depth <= 0)
3816 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003817 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003818 unsigned int val = p->ctls[type];
3819 if (get_amp_nid_(val) == nid &&
3820 get_amp_direction_(val) == dir &&
3821 get_amp_index_(val) == idx)
3822 return true;
3823 }
3824 }
3825 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003826}
3827
3828/* can have the amp-in capability? */
3829static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3830{
3831 hda_nid_t nid = path->path[idx];
3832 unsigned int caps = get_wcaps(codec, nid);
3833 unsigned int type = get_wcaps_type(caps);
3834
3835 if (!(caps & AC_WCAP_IN_AMP))
3836 return false;
3837 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3838 return false;
3839 return true;
3840}
3841
3842/* can have the amp-out capability? */
3843static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3844{
3845 hda_nid_t nid = path->path[idx];
3846 unsigned int caps = get_wcaps(codec, nid);
3847 unsigned int type = get_wcaps_type(caps);
3848
3849 if (!(caps & AC_WCAP_OUT_AMP))
3850 return false;
3851 if (type == AC_WID_PIN && !idx) /* only for output pins */
3852 return false;
3853 return true;
3854}
3855
Takashi Iwaic9967f12012-12-14 16:39:22 +01003856/* check whether the given (nid,dir,idx) is active */
3857static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3858 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003859{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003860 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003861 int i, n;
3862
Takashi Iwaic9967f12012-12-14 16:39:22 +01003863 for (n = 0; n < spec->paths.used; n++) {
3864 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003865 if (!path->active)
3866 continue;
3867 for (i = 0; i < path->depth; i++) {
3868 if (path->path[i] == nid) {
3869 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3870 return true;
3871 break;
3872 }
3873 }
3874 }
3875 return false;
3876}
3877
Takashi Iwai130e5f02012-12-14 16:09:29 +01003878/* get the default amp value for the target state */
3879static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3880 int dir, bool enable)
3881{
3882 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003883 unsigned int val = 0;
3884
3885 caps = query_amp_caps(codec, nid, dir);
3886 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003887 /* set to 0dB */
3888 if (enable)
3889 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003890 }
3891 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003892 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003893 val |= HDA_AMP_MUTE;
3894 }
3895 return val;
3896}
3897
Takashi Iwai130e5f02012-12-14 16:09:29 +01003898/* initialize the amp value (only at the first time) */
3899static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3900{
3901 int val = get_amp_val_to_activate(codec, nid, dir, false);
3902 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3903}
3904
3905static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3906 int idx, bool enable)
3907{
3908 int val;
3909 if (is_ctl_associated(codec, nid, dir, idx) ||
3910 is_active_nid(codec, nid, dir, idx))
3911 return;
3912 val = get_amp_val_to_activate(codec, nid, dir, enable);
3913 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3914}
3915
3916static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3917 int i, bool enable)
3918{
3919 hda_nid_t nid = path->path[i];
3920 init_amp(codec, nid, HDA_OUTPUT, 0);
3921 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3922}
3923
3924static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
3925 int i, bool enable)
3926{
3927 struct alc_spec *spec = codec->spec;
3928 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003929 int n, nums, idx;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003930 hda_nid_t nid = path->path[i];
3931
3932 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003933 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN) {
3934 nums = 1;
3935 idx = 0;
3936 } else
3937 idx = path->idx[i];
3938
Takashi Iwai130e5f02012-12-14 16:09:29 +01003939 for (n = 0; n < nums; n++)
3940 init_amp(codec, nid, HDA_INPUT, n);
3941
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003942 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003943 return;
3944
3945 /* here is a little bit tricky in comparison with activate_amp_out();
3946 * when aa-mixer is available, we need to enable the path as well
3947 */
3948 for (n = 0; n < nums; n++) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003949 if (n != idx && conn[n] != spec->mixer_nid)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003950 continue;
3951 activate_amp(codec, nid, HDA_INPUT, n, enable);
3952 }
3953}
3954
3955static void activate_path(struct hda_codec *codec, struct nid_path *path,
3956 bool enable)
3957{
3958 int i;
3959
Takashi Iwai130e5f02012-12-14 16:09:29 +01003960 if (!enable)
3961 path->active = false;
3962
3963 for (i = path->depth - 1; i >= 0; i--) {
3964 if (path->multi[i])
3965 snd_hda_codec_write_cache(codec, path->path[i], 0,
3966 AC_VERB_SET_CONNECT_SEL,
3967 path->idx[i]);
3968 if (has_amp_in(codec, path, i))
3969 activate_amp_in(codec, path, i, enable);
3970 if (has_amp_out(codec, path, i))
3971 activate_amp_out(codec, path, i, enable);
3972 }
3973
3974 if (enable)
3975 path->active = true;
3976}
3977
Takashi Iwai78e635c2012-12-10 17:07:16 +01003978/* configure the path from the given dac to the pin as the proper output */
3979static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3980 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003981 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003982{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003983 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003984
Takashi Iwai130e5f02012-12-14 16:09:29 +01003985 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003986 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003987 if (!path)
3988 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003989 if (path->active)
3990 return;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003991 activate_path(codec, path, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003992}
3993
Takashi Iwai343a04b2011-07-06 14:28:39 +02003994static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003995{
3996 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003997 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003998 int i;
3999
4000 for (i = 0; i <= HDA_SIDE; i++) {
4001 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4002 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02004003 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01004004 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004005
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004006 }
4007}
4008
Takashi Iwai343a04b2011-07-06 14:28:39 +02004009static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004010{
4011 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004012 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004013 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004014
David Henningsson636030e2011-10-12 19:26:03 +02004015 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004016 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4017 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02004018 pin = spec->autocfg.hp_pins[i];
4019 if (!pin)
4020 break;
4021 dac = spec->multiout.hp_out_nid[i];
4022 if (!dac) {
4023 if (i > 0 && spec->multiout.hp_out_nid[0])
4024 dac = spec->multiout.hp_out_nid[0];
4025 else
4026 dac = spec->multiout.dac_nids[0];
4027 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004028 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004029 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004030 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004031 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4032 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004033 pin = spec->autocfg.speaker_pins[i];
4034 if (!pin)
4035 break;
4036 dac = spec->multiout.extra_out_nid[i];
4037 if (!dac) {
4038 if (i > 0 && spec->multiout.extra_out_nid[0])
4039 dac = spec->multiout.extra_out_nid[0];
4040 else
4041 dac = spec->multiout.dac_nids[0];
4042 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004043 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004044 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004045}
4046
Takashi Iwai276dd702012-02-17 16:17:03 +01004047/* check whether the given pin can be a multi-io pin */
4048static bool can_be_multiio_pin(struct hda_codec *codec,
4049 unsigned int location, hda_nid_t nid)
4050{
4051 unsigned int defcfg, caps;
4052
4053 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4054 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4055 return false;
4056 if (location && get_defcfg_location(defcfg) != location)
4057 return false;
4058 caps = snd_hda_query_pin_caps(codec, nid);
4059 if (!(caps & AC_PINCAP_OUT))
4060 return false;
4061 return true;
4062}
4063
Takashi Iwaice764ab2011-04-27 16:35:23 +02004064/*
4065 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004066 *
4067 * When hardwired is set, try to fill ony hardwired pins, and returns
4068 * zero if any pins are filled, non-zero if nothing found.
4069 * When hardwired is off, try to fill possible input pins, and returns
4070 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004071 */
4072static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004073 hda_nid_t reference_pin,
4074 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004075{
4076 struct alc_spec *spec = codec->spec;
4077 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004078 int type, i, j, dacs, num_pins, old_pins;
4079 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4080 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004081 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004082
Takashi Iwai276dd702012-02-17 16:17:03 +01004083 old_pins = spec->multi_ios;
4084 if (old_pins >= 2)
4085 goto end_fill;
4086
4087 num_pins = 0;
4088 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4089 for (i = 0; i < cfg->num_inputs; i++) {
4090 if (cfg->inputs[i].type != type)
4091 continue;
4092 if (can_be_multiio_pin(codec, location,
4093 cfg->inputs[i].pin))
4094 num_pins++;
4095 }
4096 }
4097 if (num_pins < 2)
4098 goto end_fill;
4099
Takashi Iwai07b18f62011-11-10 15:42:54 +01004100 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004101 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4102 for (i = 0; i < cfg->num_inputs; i++) {
4103 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004104 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004105
Takashi Iwaice764ab2011-04-27 16:35:23 +02004106 if (cfg->inputs[i].type != type)
4107 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004108 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004109 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004110 for (j = 0; j < spec->multi_ios; j++) {
4111 if (nid == spec->multi_io[j].pin)
4112 break;
4113 }
4114 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004115 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004116
4117 if (offset && offset + spec->multi_ios < dacs) {
4118 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004119 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004120 dac = 0;
4121 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004122 if (hardwired)
4123 dac = get_dac_if_single(codec, nid);
4124 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004125 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004126 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004127 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004128 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004129 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004130 if (!add_new_out_path(codec, nid, dac)) {
4131 badness++;
4132 continue;
4133 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004134 spec->multi_io[spec->multi_ios].pin = nid;
4135 spec->multi_io[spec->multi_ios].dac = dac;
4136 spec->multi_ios++;
4137 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004138 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004139 }
4140 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004141 end_fill:
4142 if (badness)
4143 badness = BAD_MULTI_IO;
4144 if (old_pins == spec->multi_ios) {
4145 if (hardwired)
4146 return 1; /* nothing found */
4147 else
4148 return badness; /* no badness if nothing found */
4149 }
4150 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004151 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004152 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004153 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004154 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004155 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004156
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004157 /* assign volume and mute controls */
4158 for (i = old_pins; i < spec->multi_ios; i++)
4159 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4160 spec->multi_io[i].dac);
4161
4162 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004163}
4164
4165static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4166 struct snd_ctl_elem_info *uinfo)
4167{
4168 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4169 struct alc_spec *spec = codec->spec;
4170
4171 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4172 uinfo->count = 1;
4173 uinfo->value.enumerated.items = spec->multi_ios + 1;
4174 if (uinfo->value.enumerated.item > spec->multi_ios)
4175 uinfo->value.enumerated.item = spec->multi_ios;
4176 sprintf(uinfo->value.enumerated.name, "%dch",
4177 (uinfo->value.enumerated.item + 1) * 2);
4178 return 0;
4179}
4180
4181static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4182 struct snd_ctl_elem_value *ucontrol)
4183{
4184 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4185 struct alc_spec *spec = codec->spec;
4186 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4187 return 0;
4188}
4189
4190static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4191{
4192 struct alc_spec *spec = codec->spec;
4193 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004194 struct nid_path *path;
4195
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004196 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004197 if (!path)
4198 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004199
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004200 if (path->active == output)
4201 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004202
Takashi Iwaice764ab2011-04-27 16:35:23 +02004203 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004204 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004205 activate_path(codec, path, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004206 } else {
Takashi Iwai130e5f02012-12-14 16:09:29 +01004207 activate_path(codec, path, false);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004208 snd_hda_set_pin_ctl_cache(codec, nid,
4209 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004210 }
4211 return 0;
4212}
4213
4214static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4215 struct snd_ctl_elem_value *ucontrol)
4216{
4217 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4218 struct alc_spec *spec = codec->spec;
4219 int i, ch;
4220
4221 ch = ucontrol->value.enumerated.item[0];
4222 if (ch < 0 || ch > spec->multi_ios)
4223 return -EINVAL;
4224 if (ch == (spec->ext_channel_count - 1) / 2)
4225 return 0;
4226 spec->ext_channel_count = (ch + 1) * 2;
4227 for (i = 0; i < spec->multi_ios; i++)
4228 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004229 spec->multiout.max_channels = max(spec->ext_channel_count,
4230 spec->const_channel_count);
4231 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004232 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004233 return 1;
4234}
4235
Takashi Iwaia9111322011-05-02 11:30:18 +02004236static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4238 .name = "Channel Mode",
4239 .info = alc_auto_ch_mode_info,
4240 .get = alc_auto_ch_mode_get,
4241 .put = alc_auto_ch_mode_put,
4242};
4243
Takashi Iwai23c09b02011-08-19 09:05:35 +02004244static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004245{
4246 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004247
Takashi Iwaic2674682011-08-24 17:57:44 +02004248 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004249 if (!alc_kcontrol_new(spec, "Channel Mode",
4250 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004251 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004252 }
4253 return 0;
4254}
4255
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004256static void alc_auto_init_multi_io(struct hda_codec *codec)
4257{
4258 struct alc_spec *spec = codec->spec;
4259 int i;
4260
4261 for (i = 0; i < spec->multi_ios; i++) {
4262 hda_nid_t pin = spec->multi_io[i].pin;
4263 struct nid_path *path;
4264 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4265 if (!path)
4266 continue;
4267 if (!spec->multi_io[i].ctl_in)
4268 spec->multi_io[i].ctl_in =
4269 snd_hda_codec_update_cache(codec, pin, 0,
4270 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4271 activate_path(codec, path, path->active);
4272 }
4273}
4274
Takashi Iwai1d045db2011-07-07 18:23:21 +02004275/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4276 * active input pins
4277 */
4278static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4279{
4280 struct alc_spec *spec = codec->spec;
4281 const struct hda_input_mux *imux;
4282 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4283 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4284 int i, n, nums;
4285
4286 imux = spec->input_mux;
4287 if (!imux)
4288 return;
4289 if (spec->dyn_adc_switch)
4290 return;
4291
Takashi Iwai26acaf02012-03-22 14:36:50 +01004292 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004293 nums = 0;
4294 for (n = 0; n < spec->num_adc_nids; n++) {
4295 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004296 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004297 for (i = 0; i < imux->num_items; i++) {
4298 hda_nid_t pin = spec->imux_pins[i];
4299 if (pin) {
4300 if (get_connection_index(codec, cap, pin) < 0)
4301 break;
4302 } else if (num_conns <= imux->items[i].index)
4303 break;
4304 }
4305 if (i >= imux->num_items) {
4306 adc_nids[nums] = spec->private_adc_nids[n];
4307 capsrc_nids[nums++] = cap;
4308 }
4309 }
4310 if (!nums) {
4311 /* check whether ADC-switch is possible */
4312 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004313 if (spec->shared_mic_hp) {
4314 spec->shared_mic_hp = 0;
4315 spec->private_imux[0].num_items = 1;
4316 goto again;
4317 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004318 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4319 " using fallback 0x%x\n",
4320 codec->chip_name, spec->private_adc_nids[0]);
4321 spec->num_adc_nids = 1;
4322 spec->auto_mic = 0;
4323 return;
4324 }
4325 } else if (nums != spec->num_adc_nids) {
4326 memcpy(spec->private_adc_nids, adc_nids,
4327 nums * sizeof(hda_nid_t));
4328 memcpy(spec->private_capsrc_nids, capsrc_nids,
4329 nums * sizeof(hda_nid_t));
4330 spec->num_adc_nids = nums;
4331 }
4332
4333 if (spec->auto_mic)
4334 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004335 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004336 spec->num_adc_nids = 1; /* reduce to a single ADC */
4337}
4338
4339/*
4340 * initialize ADC paths
4341 */
4342static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4343{
4344 struct alc_spec *spec = codec->spec;
4345 hda_nid_t nid;
4346
4347 nid = spec->adc_nids[adc_idx];
4348 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004349 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004350 snd_hda_codec_write(codec, nid, 0,
4351 AC_VERB_SET_AMP_GAIN_MUTE,
4352 AMP_IN_MUTE(0));
4353 return;
4354 }
4355 if (!spec->capsrc_nids)
4356 return;
4357 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004358 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004359 snd_hda_codec_write(codec, nid, 0,
4360 AC_VERB_SET_AMP_GAIN_MUTE,
4361 AMP_OUT_MUTE);
4362}
4363
4364static void alc_auto_init_input_src(struct hda_codec *codec)
4365{
4366 struct alc_spec *spec = codec->spec;
4367 int c, nums;
4368
4369 for (c = 0; c < spec->num_adc_nids; c++)
4370 alc_auto_init_adc(codec, c);
4371 if (spec->dyn_adc_switch)
4372 nums = 1;
4373 else
4374 nums = spec->num_adc_nids;
4375 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004376 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004377}
4378
4379/* add mic boosts if needed */
4380static int alc_auto_add_mic_boost(struct hda_codec *codec)
4381{
4382 struct alc_spec *spec = codec->spec;
4383 struct auto_pin_cfg *cfg = &spec->autocfg;
4384 int i, err;
4385 int type_idx = 0;
4386 hda_nid_t nid;
4387 const char *prev_label = NULL;
4388
4389 for (i = 0; i < cfg->num_inputs; i++) {
4390 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4391 break;
4392 nid = cfg->inputs[i].pin;
4393 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4394 const char *label;
4395 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004396 struct nid_path *path;
4397 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004398
4399 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004400 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4401 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004402 if (prev_label && !strcmp(label, prev_label))
4403 type_idx++;
4404 else
4405 type_idx = 0;
4406 prev_label = label;
4407
4408 snprintf(boost_label, sizeof(boost_label),
4409 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004410 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004411 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004412 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004413 if (err < 0)
4414 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004415
4416 path = get_nid_path(codec, nid, 0);
4417 if (path)
4418 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004419 }
4420 }
4421 return 0;
4422}
4423
4424/* select or unmute the given capsrc route */
4425static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4426 int idx)
4427{
4428 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4429 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4430 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004431 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004432 snd_hda_codec_write_cache(codec, cap, 0,
4433 AC_VERB_SET_CONNECT_SEL, idx);
4434 }
4435}
4436
4437/* set the default connection to that pin */
4438static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4439{
4440 struct alc_spec *spec = codec->spec;
4441 int i;
4442
4443 if (!pin)
4444 return 0;
4445 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004446 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004447 int idx;
4448
4449 idx = get_connection_index(codec, cap, pin);
4450 if (idx < 0)
4451 continue;
4452 select_or_unmute_capsrc(codec, cap, idx);
4453 return i; /* return the found index */
4454 }
4455 return -1; /* not found */
4456}
4457
4458/* initialize some special cases for input sources */
4459static void alc_init_special_input_src(struct hda_codec *codec)
4460{
4461 struct alc_spec *spec = codec->spec;
4462 int i;
4463
4464 for (i = 0; i < spec->autocfg.num_inputs; i++)
4465 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4466}
4467
4468/* assign appropriate capture mixers */
4469static void set_capture_mixer(struct hda_codec *codec)
4470{
4471 struct alc_spec *spec = codec->spec;
4472 static const struct snd_kcontrol_new *caps[2][3] = {
4473 { alc_capture_mixer_nosrc1,
4474 alc_capture_mixer_nosrc2,
4475 alc_capture_mixer_nosrc3 },
4476 { alc_capture_mixer1,
4477 alc_capture_mixer2,
4478 alc_capture_mixer3 },
4479 };
4480
4481 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004482 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004483 if (!spec->capsrc_nids)
4484 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004485 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004486 return; /* no volume in capsrc, too */
4487 spec->vol_in_capsrc = 1;
4488 }
4489
4490 if (spec->num_adc_nids > 0) {
4491 int mux = 0;
4492 int num_adcs = 0;
4493
4494 if (spec->input_mux && spec->input_mux->num_items > 1)
4495 mux = 1;
4496 if (spec->auto_mic) {
4497 num_adcs = 1;
4498 mux = 0;
4499 } else if (spec->dyn_adc_switch)
4500 num_adcs = 1;
4501 if (!num_adcs) {
4502 if (spec->num_adc_nids > 3)
4503 spec->num_adc_nids = 3;
4504 else if (!spec->num_adc_nids)
4505 return;
4506 num_adcs = spec->num_adc_nids;
4507 }
4508 spec->cap_mixer = caps[mux][num_adcs - 1];
4509 }
4510}
4511
4512/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004513 * standard auto-parser initializations
4514 */
4515static void alc_auto_init_std(struct hda_codec *codec)
4516{
Takashi Iwaie4770622011-07-08 11:11:35 +02004517 alc_auto_init_multi_out(codec);
4518 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004519 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004520 alc_auto_init_analog_input(codec);
4521 alc_auto_init_input_src(codec);
4522 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004523 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004524}
4525
4526/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004527 * Digital-beep handlers
4528 */
4529#ifdef CONFIG_SND_HDA_INPUT_BEEP
4530#define set_beep_amp(spec, nid, idx, dir) \
4531 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4532
4533static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004534 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004535 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4536 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4537 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4538 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004539 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004540 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4541 {}
4542};
4543
4544static inline int has_cdefine_beep(struct hda_codec *codec)
4545{
4546 struct alc_spec *spec = codec->spec;
4547 const struct snd_pci_quirk *q;
4548 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4549 if (q)
4550 return q->value;
4551 return spec->cdefine.enable_pcbeep;
4552}
4553#else
4554#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4555#define has_cdefine_beep(codec) 0
4556#endif
4557
4558/* parse the BIOS configuration and set up the alc_spec */
4559/* return 1 if successful, 0 if the proper config is not found,
4560 * or a negative error code
4561 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004562static int alc_parse_auto_config(struct hda_codec *codec,
4563 const hda_nid_t *ignore_nids,
4564 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004565{
4566 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004567 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004568 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004569
Takashi Iwai53c334a2011-08-23 18:27:14 +02004570 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4571 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004572 if (err < 0)
4573 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004574 if (!cfg->line_outs) {
4575 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004576 spec->multiout.max_channels = 2;
4577 spec->no_analog = 1;
4578 goto dig_only;
4579 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004580 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004581 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004582
Takashi Iwaie427c232012-07-29 10:04:08 +02004583 if (!spec->no_primary_hp &&
4584 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004585 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004586 /* use HP as primary out */
4587 cfg->speaker_outs = cfg->line_outs;
4588 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4589 sizeof(cfg->speaker_pins));
4590 cfg->line_outs = cfg->hp_outs;
4591 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4592 cfg->hp_outs = 0;
4593 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4594 cfg->line_out_type = AUTO_PIN_HP_OUT;
4595 }
4596
Takashi Iwai1d045db2011-07-07 18:23:21 +02004597 err = alc_auto_fill_dac_nids(codec);
4598 if (err < 0)
4599 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004600 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004601 if (err < 0)
4602 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004603 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004604 if (err < 0)
4605 return err;
4606 err = alc_auto_create_hp_out(codec);
4607 if (err < 0)
4608 return err;
4609 err = alc_auto_create_speaker_out(codec);
4610 if (err < 0)
4611 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004612 err = alc_auto_create_shared_input(codec);
4613 if (err < 0)
4614 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004615 err = alc_auto_create_input_ctls(codec);
4616 if (err < 0)
4617 return err;
4618
Takashi Iwaib6adb572012-12-03 10:30:58 +01004619 /* check the multiple speaker pins */
4620 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4621 spec->const_channel_count = cfg->line_outs * 2;
4622 else
4623 spec->const_channel_count = cfg->speaker_outs * 2;
4624
4625 if (spec->multi_ios > 0)
4626 spec->multiout.max_channels = max(spec->ext_channel_count,
4627 spec->const_channel_count);
4628 else
4629 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004630
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004631 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004632 alc_auto_parse_digital(codec);
4633
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004634 if (!spec->no_analog)
4635 alc_remove_invalid_adc_nids(codec);
4636
4637 if (ssid_nids)
4638 alc_ssid_check(codec, ssid_nids);
4639
4640 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004641 err = alc_auto_check_switches(codec);
4642 if (err < 0)
4643 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004644 err = alc_auto_add_mic_boost(codec);
4645 if (err < 0)
4646 return err;
4647 }
4648
Takashi Iwai1d045db2011-07-07 18:23:21 +02004649 if (spec->kctls.list)
4650 add_mixer(spec, spec->kctls.list);
4651
Takashi Iwai070cff42012-02-21 12:54:17 +01004652 if (!spec->no_analog && !spec->cap_mixer)
4653 set_capture_mixer(codec);
4654
Takashi Iwai1d045db2011-07-07 18:23:21 +02004655 return 1;
4656}
4657
Takashi Iwai3de95172012-05-07 18:03:15 +02004658/* common preparation job for alc_spec */
4659static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4660{
4661 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4662 int err;
4663
4664 if (!spec)
4665 return -ENOMEM;
4666 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004667 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004668 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004669 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004670 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4671 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004672 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004673
4674 err = alc_codec_rename_from_preset(codec);
4675 if (err < 0) {
4676 kfree(spec);
4677 return err;
4678 }
4679 return 0;
4680}
4681
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004682static int alc880_parse_auto_config(struct hda_codec *codec)
4683{
4684 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004685 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004686 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4687}
4688
Takashi Iwai1d045db2011-07-07 18:23:21 +02004689/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004690 * ALC880 fix-ups
4691 */
4692enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004693 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004694 ALC880_FIXUP_GPIO2,
4695 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004696 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004697 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004698 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004699 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004700 ALC880_FIXUP_VOL_KNOB,
4701 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004702 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004703 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004704 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004705 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004706 ALC880_FIXUP_3ST_BASE,
4707 ALC880_FIXUP_3ST,
4708 ALC880_FIXUP_3ST_DIG,
4709 ALC880_FIXUP_5ST_BASE,
4710 ALC880_FIXUP_5ST,
4711 ALC880_FIXUP_5ST_DIG,
4712 ALC880_FIXUP_6ST_BASE,
4713 ALC880_FIXUP_6ST,
4714 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004715};
4716
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004717/* enable the volume-knob widget support on NID 0x21 */
4718static void alc880_fixup_vol_knob(struct hda_codec *codec,
4719 const struct alc_fixup *fix, int action)
4720{
4721 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004722 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004723}
4724
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004725static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004726 [ALC880_FIXUP_GPIO1] = {
4727 .type = ALC_FIXUP_VERBS,
4728 .v.verbs = alc_gpio1_init_verbs,
4729 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004730 [ALC880_FIXUP_GPIO2] = {
4731 .type = ALC_FIXUP_VERBS,
4732 .v.verbs = alc_gpio2_init_verbs,
4733 },
4734 [ALC880_FIXUP_MEDION_RIM] = {
4735 .type = ALC_FIXUP_VERBS,
4736 .v.verbs = (const struct hda_verb[]) {
4737 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4738 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4739 { }
4740 },
4741 .chained = true,
4742 .chain_id = ALC880_FIXUP_GPIO2,
4743 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004744 [ALC880_FIXUP_LG] = {
4745 .type = ALC_FIXUP_PINS,
4746 .v.pins = (const struct alc_pincfg[]) {
4747 /* disable bogus unused pins */
4748 { 0x16, 0x411111f0 },
4749 { 0x18, 0x411111f0 },
4750 { 0x1a, 0x411111f0 },
4751 { }
4752 }
4753 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004754 [ALC880_FIXUP_W810] = {
4755 .type = ALC_FIXUP_PINS,
4756 .v.pins = (const struct alc_pincfg[]) {
4757 /* disable bogus unused pins */
4758 { 0x17, 0x411111f0 },
4759 { }
4760 },
4761 .chained = true,
4762 .chain_id = ALC880_FIXUP_GPIO2,
4763 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004764 [ALC880_FIXUP_EAPD_COEF] = {
4765 .type = ALC_FIXUP_VERBS,
4766 .v.verbs = (const struct hda_verb[]) {
4767 /* change to EAPD mode */
4768 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4769 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4770 {}
4771 },
4772 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004773 [ALC880_FIXUP_TCL_S700] = {
4774 .type = ALC_FIXUP_VERBS,
4775 .v.verbs = (const struct hda_verb[]) {
4776 /* change to EAPD mode */
4777 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4778 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4779 {}
4780 },
4781 .chained = true,
4782 .chain_id = ALC880_FIXUP_GPIO2,
4783 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004784 [ALC880_FIXUP_VOL_KNOB] = {
4785 .type = ALC_FIXUP_FUNC,
4786 .v.func = alc880_fixup_vol_knob,
4787 },
4788 [ALC880_FIXUP_FUJITSU] = {
4789 /* override all pins as BIOS on old Amilo is broken */
4790 .type = ALC_FIXUP_PINS,
4791 .v.pins = (const struct alc_pincfg[]) {
4792 { 0x14, 0x0121411f }, /* HP */
4793 { 0x15, 0x99030120 }, /* speaker */
4794 { 0x16, 0x99030130 }, /* bass speaker */
4795 { 0x17, 0x411111f0 }, /* N/A */
4796 { 0x18, 0x411111f0 }, /* N/A */
4797 { 0x19, 0x01a19950 }, /* mic-in */
4798 { 0x1a, 0x411111f0 }, /* N/A */
4799 { 0x1b, 0x411111f0 }, /* N/A */
4800 { 0x1c, 0x411111f0 }, /* N/A */
4801 { 0x1d, 0x411111f0 }, /* N/A */
4802 { 0x1e, 0x01454140 }, /* SPDIF out */
4803 { }
4804 },
4805 .chained = true,
4806 .chain_id = ALC880_FIXUP_VOL_KNOB,
4807 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004808 [ALC880_FIXUP_F1734] = {
4809 /* almost compatible with FUJITSU, but no bass and SPDIF */
4810 .type = ALC_FIXUP_PINS,
4811 .v.pins = (const struct alc_pincfg[]) {
4812 { 0x14, 0x0121411f }, /* HP */
4813 { 0x15, 0x99030120 }, /* speaker */
4814 { 0x16, 0x411111f0 }, /* N/A */
4815 { 0x17, 0x411111f0 }, /* N/A */
4816 { 0x18, 0x411111f0 }, /* N/A */
4817 { 0x19, 0x01a19950 }, /* mic-in */
4818 { 0x1a, 0x411111f0 }, /* N/A */
4819 { 0x1b, 0x411111f0 }, /* N/A */
4820 { 0x1c, 0x411111f0 }, /* N/A */
4821 { 0x1d, 0x411111f0 }, /* N/A */
4822 { 0x1e, 0x411111f0 }, /* N/A */
4823 { }
4824 },
4825 .chained = true,
4826 .chain_id = ALC880_FIXUP_VOL_KNOB,
4827 },
Takashi Iwai817de922012-02-20 17:20:48 +01004828 [ALC880_FIXUP_UNIWILL] = {
4829 /* need to fix HP and speaker pins to be parsed correctly */
4830 .type = ALC_FIXUP_PINS,
4831 .v.pins = (const struct alc_pincfg[]) {
4832 { 0x14, 0x0121411f }, /* HP */
4833 { 0x15, 0x99030120 }, /* speaker */
4834 { 0x16, 0x99030130 }, /* bass speaker */
4835 { }
4836 },
4837 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004838 [ALC880_FIXUP_UNIWILL_DIG] = {
4839 .type = ALC_FIXUP_PINS,
4840 .v.pins = (const struct alc_pincfg[]) {
4841 /* disable bogus unused pins */
4842 { 0x17, 0x411111f0 },
4843 { 0x19, 0x411111f0 },
4844 { 0x1b, 0x411111f0 },
4845 { 0x1f, 0x411111f0 },
4846 { }
4847 }
4848 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004849 [ALC880_FIXUP_Z71V] = {
4850 .type = ALC_FIXUP_PINS,
4851 .v.pins = (const struct alc_pincfg[]) {
4852 /* set up the whole pins as BIOS is utterly broken */
4853 { 0x14, 0x99030120 }, /* speaker */
4854 { 0x15, 0x0121411f }, /* HP */
4855 { 0x16, 0x411111f0 }, /* N/A */
4856 { 0x17, 0x411111f0 }, /* N/A */
4857 { 0x18, 0x01a19950 }, /* mic-in */
4858 { 0x19, 0x411111f0 }, /* N/A */
4859 { 0x1a, 0x01813031 }, /* line-in */
4860 { 0x1b, 0x411111f0 }, /* N/A */
4861 { 0x1c, 0x411111f0 }, /* N/A */
4862 { 0x1d, 0x411111f0 }, /* N/A */
4863 { 0x1e, 0x0144111e }, /* SPDIF */
4864 { }
4865 }
4866 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004867 [ALC880_FIXUP_3ST_BASE] = {
4868 .type = ALC_FIXUP_PINS,
4869 .v.pins = (const struct alc_pincfg[]) {
4870 { 0x14, 0x01014010 }, /* line-out */
4871 { 0x15, 0x411111f0 }, /* N/A */
4872 { 0x16, 0x411111f0 }, /* N/A */
4873 { 0x17, 0x411111f0 }, /* N/A */
4874 { 0x18, 0x01a19c30 }, /* mic-in */
4875 { 0x19, 0x0121411f }, /* HP */
4876 { 0x1a, 0x01813031 }, /* line-in */
4877 { 0x1b, 0x02a19c40 }, /* front-mic */
4878 { 0x1c, 0x411111f0 }, /* N/A */
4879 { 0x1d, 0x411111f0 }, /* N/A */
4880 /* 0x1e is filled in below */
4881 { 0x1f, 0x411111f0 }, /* N/A */
4882 { }
4883 }
4884 },
4885 [ALC880_FIXUP_3ST] = {
4886 .type = ALC_FIXUP_PINS,
4887 .v.pins = (const struct alc_pincfg[]) {
4888 { 0x1e, 0x411111f0 }, /* N/A */
4889 { }
4890 },
4891 .chained = true,
4892 .chain_id = ALC880_FIXUP_3ST_BASE,
4893 },
4894 [ALC880_FIXUP_3ST_DIG] = {
4895 .type = ALC_FIXUP_PINS,
4896 .v.pins = (const struct alc_pincfg[]) {
4897 { 0x1e, 0x0144111e }, /* SPDIF */
4898 { }
4899 },
4900 .chained = true,
4901 .chain_id = ALC880_FIXUP_3ST_BASE,
4902 },
4903 [ALC880_FIXUP_5ST_BASE] = {
4904 .type = ALC_FIXUP_PINS,
4905 .v.pins = (const struct alc_pincfg[]) {
4906 { 0x14, 0x01014010 }, /* front */
4907 { 0x15, 0x411111f0 }, /* N/A */
4908 { 0x16, 0x01011411 }, /* CLFE */
4909 { 0x17, 0x01016412 }, /* surr */
4910 { 0x18, 0x01a19c30 }, /* mic-in */
4911 { 0x19, 0x0121411f }, /* HP */
4912 { 0x1a, 0x01813031 }, /* line-in */
4913 { 0x1b, 0x02a19c40 }, /* front-mic */
4914 { 0x1c, 0x411111f0 }, /* N/A */
4915 { 0x1d, 0x411111f0 }, /* N/A */
4916 /* 0x1e is filled in below */
4917 { 0x1f, 0x411111f0 }, /* N/A */
4918 { }
4919 }
4920 },
4921 [ALC880_FIXUP_5ST] = {
4922 .type = ALC_FIXUP_PINS,
4923 .v.pins = (const struct alc_pincfg[]) {
4924 { 0x1e, 0x411111f0 }, /* N/A */
4925 { }
4926 },
4927 .chained = true,
4928 .chain_id = ALC880_FIXUP_5ST_BASE,
4929 },
4930 [ALC880_FIXUP_5ST_DIG] = {
4931 .type = ALC_FIXUP_PINS,
4932 .v.pins = (const struct alc_pincfg[]) {
4933 { 0x1e, 0x0144111e }, /* SPDIF */
4934 { }
4935 },
4936 .chained = true,
4937 .chain_id = ALC880_FIXUP_5ST_BASE,
4938 },
4939 [ALC880_FIXUP_6ST_BASE] = {
4940 .type = ALC_FIXUP_PINS,
4941 .v.pins = (const struct alc_pincfg[]) {
4942 { 0x14, 0x01014010 }, /* front */
4943 { 0x15, 0x01016412 }, /* surr */
4944 { 0x16, 0x01011411 }, /* CLFE */
4945 { 0x17, 0x01012414 }, /* side */
4946 { 0x18, 0x01a19c30 }, /* mic-in */
4947 { 0x19, 0x02a19c40 }, /* front-mic */
4948 { 0x1a, 0x01813031 }, /* line-in */
4949 { 0x1b, 0x0121411f }, /* HP */
4950 { 0x1c, 0x411111f0 }, /* N/A */
4951 { 0x1d, 0x411111f0 }, /* N/A */
4952 /* 0x1e is filled in below */
4953 { 0x1f, 0x411111f0 }, /* N/A */
4954 { }
4955 }
4956 },
4957 [ALC880_FIXUP_6ST] = {
4958 .type = ALC_FIXUP_PINS,
4959 .v.pins = (const struct alc_pincfg[]) {
4960 { 0x1e, 0x411111f0 }, /* N/A */
4961 { }
4962 },
4963 .chained = true,
4964 .chain_id = ALC880_FIXUP_6ST_BASE,
4965 },
4966 [ALC880_FIXUP_6ST_DIG] = {
4967 .type = ALC_FIXUP_PINS,
4968 .v.pins = (const struct alc_pincfg[]) {
4969 { 0x1e, 0x0144111e }, /* SPDIF */
4970 { }
4971 },
4972 .chained = true,
4973 .chain_id = ALC880_FIXUP_6ST_BASE,
4974 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004975};
4976
4977static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004978 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004979 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004980 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4981 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004982 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004983 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004984 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004985 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004986 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004987 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004988 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004989 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004990 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004991 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004992 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004993 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4994 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4995 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004996 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004997
4998 /* Below is the copied entries from alc880_quirks.c.
4999 * It's not quite sure whether BIOS sets the correct pin-config table
5000 * on these machines, thus they are kept to be compatible with
5001 * the old static quirks. Once when it's confirmed to work without
5002 * these overrides, it'd be better to remove.
5003 */
5004 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
5005 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
5006 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
5007 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
5008 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
5009 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
5010 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
5011 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
5012 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
5013 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
5014 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
5015 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
5016 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
5017 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
5018 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
5019 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
5020 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
5021 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
5022 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
5023 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
5024 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
5025 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
5026 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
5027 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5028 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5029 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5030 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5031 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5032 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5033 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5034 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5035 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5036 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5037 /* default Intel */
5038 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
5039 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
5040 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
5041 {}
5042};
5043
5044static const struct alc_model_fixup alc880_fixup_models[] = {
5045 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
5046 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
5047 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
5048 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
5049 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
5050 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01005051 {}
5052};
5053
5054
5055/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02005056 * OK, here we have finally the patch for ALC880
5057 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005058static int patch_alc880(struct hda_codec *codec)
5059{
5060 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005061 int err;
5062
Takashi Iwai3de95172012-05-07 18:03:15 +02005063 err = alc_alloc_spec(codec, 0x0b);
5064 if (err < 0)
5065 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005066
Takashi Iwai3de95172012-05-07 18:03:15 +02005067 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02005068 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005070 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5071 alc880_fixups);
5072 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005073
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005074 /* automatic parse from the BIOS config */
5075 err = alc880_parse_auto_config(codec);
5076 if (err < 0)
5077 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005078
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005079 if (!spec->no_analog) {
5080 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005081 if (err < 0)
5082 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005083 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5084 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005085
Takashi Iwai1d045db2011-07-07 18:23:21 +02005086 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005087 codec->patch_ops.unsol_event = alc880_unsol_event;
5088
Takashi Iwai1d045db2011-07-07 18:23:21 +02005089
Takashi Iwai589876e2012-02-20 15:47:55 +01005090 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5091
Takashi Iwai1d045db2011-07-07 18:23:21 +02005092 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005093
5094 error:
5095 alc_free(codec);
5096 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005097}
5098
5099
5100/*
5101 * ALC260 support
5102 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005103static int alc260_parse_auto_config(struct hda_codec *codec)
5104{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005106 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5107 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005108}
5109
Takashi Iwai1d045db2011-07-07 18:23:21 +02005110/*
5111 * Pin config fixes
5112 */
5113enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005114 ALC260_FIXUP_HP_DC5750,
5115 ALC260_FIXUP_HP_PIN_0F,
5116 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005117 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005118 ALC260_FIXUP_GPIO1_TOGGLE,
5119 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005120 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005121 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005122};
5123
Takashi Iwai20f7d922012-02-16 12:35:16 +01005124static void alc260_gpio1_automute(struct hda_codec *codec)
5125{
5126 struct alc_spec *spec = codec->spec;
5127 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5128 spec->hp_jack_present);
5129}
5130
5131static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5132 const struct alc_fixup *fix, int action)
5133{
5134 struct alc_spec *spec = codec->spec;
5135 if (action == ALC_FIXUP_ACT_PROBE) {
5136 /* although the machine has only one output pin, we need to
5137 * toggle GPIO1 according to the jack state
5138 */
5139 spec->automute_hook = alc260_gpio1_automute;
5140 spec->detect_hp = 1;
5141 spec->automute_speaker = 1;
5142 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005143 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5144 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005145 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005146 }
5147}
5148
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005149static void alc260_fixup_kn1(struct hda_codec *codec,
5150 const struct alc_fixup *fix, int action)
5151{
5152 struct alc_spec *spec = codec->spec;
5153 static const struct alc_pincfg pincfgs[] = {
5154 { 0x0f, 0x02214000 }, /* HP/speaker */
5155 { 0x12, 0x90a60160 }, /* int mic */
5156 { 0x13, 0x02a19000 }, /* ext mic */
5157 { 0x18, 0x01446000 }, /* SPDIF out */
5158 /* disable bogus I/O pins */
5159 { 0x10, 0x411111f0 },
5160 { 0x11, 0x411111f0 },
5161 { 0x14, 0x411111f0 },
5162 { 0x15, 0x411111f0 },
5163 { 0x16, 0x411111f0 },
5164 { 0x17, 0x411111f0 },
5165 { 0x19, 0x411111f0 },
5166 { }
5167 };
5168
5169 switch (action) {
5170 case ALC_FIXUP_ACT_PRE_PROBE:
5171 alc_apply_pincfgs(codec, pincfgs);
5172 break;
5173 case ALC_FIXUP_ACT_PROBE:
5174 spec->init_amp = ALC_INIT_NONE;
5175 break;
5176 }
5177}
5178
Takashi Iwai1d045db2011-07-07 18:23:21 +02005179static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005180 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005181 .type = ALC_FIXUP_PINS,
5182 .v.pins = (const struct alc_pincfg[]) {
5183 { 0x11, 0x90130110 }, /* speaker */
5184 { }
5185 }
5186 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005187 [ALC260_FIXUP_HP_PIN_0F] = {
5188 .type = ALC_FIXUP_PINS,
5189 .v.pins = (const struct alc_pincfg[]) {
5190 { 0x0f, 0x01214000 }, /* HP */
5191 { }
5192 }
5193 },
5194 [ALC260_FIXUP_COEF] = {
5195 .type = ALC_FIXUP_VERBS,
5196 .v.verbs = (const struct hda_verb[]) {
5197 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5198 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5199 { }
5200 },
5201 .chained = true,
5202 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5203 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005204 [ALC260_FIXUP_GPIO1] = {
5205 .type = ALC_FIXUP_VERBS,
5206 .v.verbs = alc_gpio1_init_verbs,
5207 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005208 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5209 .type = ALC_FIXUP_FUNC,
5210 .v.func = alc260_fixup_gpio1_toggle,
5211 .chained = true,
5212 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5213 },
5214 [ALC260_FIXUP_REPLACER] = {
5215 .type = ALC_FIXUP_VERBS,
5216 .v.verbs = (const struct hda_verb[]) {
5217 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5218 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5219 { }
5220 },
5221 .chained = true,
5222 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5223 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005224 [ALC260_FIXUP_HP_B1900] = {
5225 .type = ALC_FIXUP_FUNC,
5226 .v.func = alc260_fixup_gpio1_toggle,
5227 .chained = true,
5228 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005229 },
5230 [ALC260_FIXUP_KN1] = {
5231 .type = ALC_FIXUP_FUNC,
5232 .v.func = alc260_fixup_kn1,
5233 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005234};
5235
5236static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005237 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005238 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005239 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005240 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005241 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005242 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005243 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005244 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005245 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005246 {}
5247};
5248
5249/*
5250 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005251static int patch_alc260(struct hda_codec *codec)
5252{
5253 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005254 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005255
Takashi Iwai3de95172012-05-07 18:03:15 +02005256 err = alc_alloc_spec(codec, 0x07);
5257 if (err < 0)
5258 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005259
Takashi Iwai3de95172012-05-07 18:03:15 +02005260 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005261
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005262 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5263 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005264
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005265 /* automatic parse from the BIOS config */
5266 err = alc260_parse_auto_config(codec);
5267 if (err < 0)
5268 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005269
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005270 if (!spec->no_analog) {
5271 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005272 if (err < 0)
5273 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005274 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5275 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005276
Takashi Iwai1d045db2011-07-07 18:23:21 +02005277 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005278 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005279
Takashi Iwai589876e2012-02-20 15:47:55 +01005280 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5281
Takashi Iwai1d045db2011-07-07 18:23:21 +02005282 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005283
5284 error:
5285 alc_free(codec);
5286 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005287}
5288
5289
5290/*
5291 * ALC882/883/885/888/889 support
5292 *
5293 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5294 * configuration. Each pin widget can choose any input DACs and a mixer.
5295 * Each ADC is connected from a mixer of all inputs. This makes possible
5296 * 6-channel independent captures.
5297 *
5298 * In addition, an independent DAC for the multi-playback (not used in this
5299 * driver yet).
5300 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005301
5302/*
5303 * Pin config fixes
5304 */
5305enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005306 ALC882_FIXUP_ABIT_AW9D_MAX,
5307 ALC882_FIXUP_LENOVO_Y530,
5308 ALC882_FIXUP_PB_M5210,
5309 ALC882_FIXUP_ACER_ASPIRE_7736,
5310 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005311 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005312 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005313 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005314 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005315 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005316 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005317 ALC882_FIXUP_GPIO1,
5318 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005319 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005320 ALC889_FIXUP_COEF,
5321 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005322 ALC882_FIXUP_ACER_ASPIRE_4930G,
5323 ALC882_FIXUP_ACER_ASPIRE_8930G,
5324 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005325 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005326 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005327 ALC889_FIXUP_MBP_VREF,
5328 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005329 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005330 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005331};
5332
Takashi Iwai68ef0562011-11-09 18:24:44 +01005333static void alc889_fixup_coef(struct hda_codec *codec,
5334 const struct alc_fixup *fix, int action)
5335{
5336 if (action != ALC_FIXUP_ACT_INIT)
5337 return;
5338 alc889_coef_init(codec);
5339}
5340
Takashi Iwai56710872011-11-14 17:42:11 +01005341/* toggle speaker-output according to the hp-jack state */
5342static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5343{
5344 unsigned int gpiostate, gpiomask, gpiodir;
5345
5346 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5347 AC_VERB_GET_GPIO_DATA, 0);
5348
5349 if (!muted)
5350 gpiostate |= (1 << pin);
5351 else
5352 gpiostate &= ~(1 << pin);
5353
5354 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5355 AC_VERB_GET_GPIO_MASK, 0);
5356 gpiomask |= (1 << pin);
5357
5358 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5359 AC_VERB_GET_GPIO_DIRECTION, 0);
5360 gpiodir |= (1 << pin);
5361
5362
5363 snd_hda_codec_write(codec, codec->afg, 0,
5364 AC_VERB_SET_GPIO_MASK, gpiomask);
5365 snd_hda_codec_write(codec, codec->afg, 0,
5366 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5367
5368 msleep(1);
5369
5370 snd_hda_codec_write(codec, codec->afg, 0,
5371 AC_VERB_SET_GPIO_DATA, gpiostate);
5372}
5373
5374/* set up GPIO at initialization */
5375static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5376 const struct alc_fixup *fix, int action)
5377{
5378 if (action != ALC_FIXUP_ACT_INIT)
5379 return;
5380 alc882_gpio_mute(codec, 0, 0);
5381 alc882_gpio_mute(codec, 1, 0);
5382}
5383
Takashi Iwai02a237b2012-02-13 15:25:07 +01005384/* Fix the connection of some pins for ALC889:
5385 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5386 * work correctly (bko#42740)
5387 */
5388static void alc889_fixup_dac_route(struct hda_codec *codec,
5389 const struct alc_fixup *fix, int action)
5390{
5391 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005392 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005393 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5394 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5395 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5396 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5397 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5398 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005399 } else if (action == ALC_FIXUP_ACT_PROBE) {
5400 /* restore the connections */
5401 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5402 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5403 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5404 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5405 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005406 }
5407}
5408
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005409/* Set VREF on HP pin */
5410static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5411 const struct alc_fixup *fix, int action)
5412{
5413 struct alc_spec *spec = codec->spec;
5414 static hda_nid_t nids[2] = { 0x14, 0x15 };
5415 int i;
5416
5417 if (action != ALC_FIXUP_ACT_INIT)
5418 return;
5419 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5420 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5421 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5422 continue;
5423 val = snd_hda_codec_read(codec, nids[i], 0,
5424 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5425 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005426 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005427 spec->keep_vref_in_automute = 1;
5428 break;
5429 }
5430}
5431
5432/* Set VREF on speaker pins on imac91 */
5433static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5434 const struct alc_fixup *fix, int action)
5435{
5436 struct alc_spec *spec = codec->spec;
5437 static hda_nid_t nids[2] = { 0x18, 0x1a };
5438 int i;
5439
5440 if (action != ALC_FIXUP_ACT_INIT)
5441 return;
5442 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5443 unsigned int val;
5444 val = snd_hda_codec_read(codec, nids[i], 0,
5445 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5446 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005447 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005448 }
5449 spec->keep_vref_in_automute = 1;
5450}
5451
Takashi Iwaie427c232012-07-29 10:04:08 +02005452/* Don't take HP output as primary
5453 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5454 */
5455static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5456 const struct alc_fixup *fix, int action)
5457{
5458 struct alc_spec *spec = codec->spec;
5459 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5460 spec->no_primary_hp = 1;
5461}
5462
Takashi Iwai1d045db2011-07-07 18:23:21 +02005463static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005464 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005465 .type = ALC_FIXUP_PINS,
5466 .v.pins = (const struct alc_pincfg[]) {
5467 { 0x15, 0x01080104 }, /* side */
5468 { 0x16, 0x01011012 }, /* rear */
5469 { 0x17, 0x01016011 }, /* clfe */
5470 { }
5471 }
5472 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005473 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005474 .type = ALC_FIXUP_PINS,
5475 .v.pins = (const struct alc_pincfg[]) {
5476 { 0x15, 0x99130112 }, /* rear int speakers */
5477 { 0x16, 0x99130111 }, /* subwoofer */
5478 { }
5479 }
5480 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005481 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005482 .type = ALC_FIXUP_VERBS,
5483 .v.verbs = (const struct hda_verb[]) {
5484 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5485 {}
5486 }
5487 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005488 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005489 .type = ALC_FIXUP_FUNC,
5490 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005492 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005493 .type = ALC_FIXUP_PINS,
5494 .v.pins = (const struct alc_pincfg[]) {
5495 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5496 { }
5497 }
5498 },
Marton Balint8f239212012-03-05 21:33:23 +01005499 [ALC889_FIXUP_CD] = {
5500 .type = ALC_FIXUP_PINS,
5501 .v.pins = (const struct alc_pincfg[]) {
5502 { 0x1c, 0x993301f0 }, /* CD */
5503 { }
5504 }
5505 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005506 [ALC889_FIXUP_VAIO_TT] = {
5507 .type = ALC_FIXUP_PINS,
5508 .v.pins = (const struct alc_pincfg[]) {
5509 { 0x17, 0x90170111 }, /* hidden surround speaker */
5510 { }
5511 }
5512 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005513 [ALC888_FIXUP_EEE1601] = {
5514 .type = ALC_FIXUP_VERBS,
5515 .v.verbs = (const struct hda_verb[]) {
5516 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5517 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5518 { }
5519 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005520 },
5521 [ALC882_FIXUP_EAPD] = {
5522 .type = ALC_FIXUP_VERBS,
5523 .v.verbs = (const struct hda_verb[]) {
5524 /* change to EAPD mode */
5525 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5526 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5527 { }
5528 }
5529 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005530 [ALC883_FIXUP_EAPD] = {
5531 .type = ALC_FIXUP_VERBS,
5532 .v.verbs = (const struct hda_verb[]) {
5533 /* change to EAPD mode */
5534 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5535 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5536 { }
5537 }
5538 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005539 [ALC883_FIXUP_ACER_EAPD] = {
5540 .type = ALC_FIXUP_VERBS,
5541 .v.verbs = (const struct hda_verb[]) {
5542 /* eanable EAPD on Acer laptops */
5543 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5544 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5545 { }
5546 }
5547 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005548 [ALC882_FIXUP_GPIO1] = {
5549 .type = ALC_FIXUP_VERBS,
5550 .v.verbs = alc_gpio1_init_verbs,
5551 },
5552 [ALC882_FIXUP_GPIO2] = {
5553 .type = ALC_FIXUP_VERBS,
5554 .v.verbs = alc_gpio2_init_verbs,
5555 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005556 [ALC882_FIXUP_GPIO3] = {
5557 .type = ALC_FIXUP_VERBS,
5558 .v.verbs = alc_gpio3_init_verbs,
5559 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005560 [ALC882_FIXUP_ASUS_W2JC] = {
5561 .type = ALC_FIXUP_VERBS,
5562 .v.verbs = alc_gpio1_init_verbs,
5563 .chained = true,
5564 .chain_id = ALC882_FIXUP_EAPD,
5565 },
5566 [ALC889_FIXUP_COEF] = {
5567 .type = ALC_FIXUP_FUNC,
5568 .v.func = alc889_fixup_coef,
5569 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005570 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5571 .type = ALC_FIXUP_PINS,
5572 .v.pins = (const struct alc_pincfg[]) {
5573 { 0x16, 0x99130111 }, /* CLFE speaker */
5574 { 0x17, 0x99130112 }, /* surround speaker */
5575 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005576 },
5577 .chained = true,
5578 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005579 },
5580 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5581 .type = ALC_FIXUP_PINS,
5582 .v.pins = (const struct alc_pincfg[]) {
5583 { 0x16, 0x99130111 }, /* CLFE speaker */
5584 { 0x1b, 0x99130112 }, /* surround speaker */
5585 { }
5586 },
5587 .chained = true,
5588 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5589 },
5590 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5591 /* additional init verbs for Acer Aspire 8930G */
5592 .type = ALC_FIXUP_VERBS,
5593 .v.verbs = (const struct hda_verb[]) {
5594 /* Enable all DACs */
5595 /* DAC DISABLE/MUTE 1? */
5596 /* setting bits 1-5 disables DAC nids 0x02-0x06
5597 * apparently. Init=0x38 */
5598 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5599 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5600 /* DAC DISABLE/MUTE 2? */
5601 /* some bit here disables the other DACs.
5602 * Init=0x4900 */
5603 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5604 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5605 /* DMIC fix
5606 * This laptop has a stereo digital microphone.
5607 * The mics are only 1cm apart which makes the stereo
5608 * useless. However, either the mic or the ALC889
5609 * makes the signal become a difference/sum signal
5610 * instead of standard stereo, which is annoying.
5611 * So instead we flip this bit which makes the
5612 * codec replicate the sum signal to both channels,
5613 * turning it into a normal mono mic.
5614 */
5615 /* DMIC_CONTROL? Init value = 0x0001 */
5616 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5617 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5618 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5619 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5620 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005621 },
5622 .chained = true,
5623 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005624 },
Takashi Iwai56710872011-11-14 17:42:11 +01005625 [ALC885_FIXUP_MACPRO_GPIO] = {
5626 .type = ALC_FIXUP_FUNC,
5627 .v.func = alc885_fixup_macpro_gpio,
5628 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005629 [ALC889_FIXUP_DAC_ROUTE] = {
5630 .type = ALC_FIXUP_FUNC,
5631 .v.func = alc889_fixup_dac_route,
5632 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005633 [ALC889_FIXUP_MBP_VREF] = {
5634 .type = ALC_FIXUP_FUNC,
5635 .v.func = alc889_fixup_mbp_vref,
5636 .chained = true,
5637 .chain_id = ALC882_FIXUP_GPIO1,
5638 },
5639 [ALC889_FIXUP_IMAC91_VREF] = {
5640 .type = ALC_FIXUP_FUNC,
5641 .v.func = alc889_fixup_imac91_vref,
5642 .chained = true,
5643 .chain_id = ALC882_FIXUP_GPIO1,
5644 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005645 [ALC882_FIXUP_INV_DMIC] = {
5646 .type = ALC_FIXUP_FUNC,
5647 .v.func = alc_fixup_inv_dmic_0x12,
5648 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005649 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5650 .type = ALC_FIXUP_FUNC,
5651 .v.func = alc882_fixup_no_primary_hp,
5652 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005653};
5654
5655static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005656 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5657 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5658 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5659 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5660 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5661 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005662 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5663 ALC882_FIXUP_ACER_ASPIRE_4930G),
5664 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5665 ALC882_FIXUP_ACER_ASPIRE_4930G),
5666 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5667 ALC882_FIXUP_ACER_ASPIRE_8930G),
5668 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5669 ALC882_FIXUP_ACER_ASPIRE_8930G),
5670 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5671 ALC882_FIXUP_ACER_ASPIRE_4930G),
5672 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5673 ALC882_FIXUP_ACER_ASPIRE_4930G),
5674 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5675 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005676 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005677 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5678 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005679 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005680 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005681 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005682 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005683 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005684 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005685 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005686 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005687 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005688
5689 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005690 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5691 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5692 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005693 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5694 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5695 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005696 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5697 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005698 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005699 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5700 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5701 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5702 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005703 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005704 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5705 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5706 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005707 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005708 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005709 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5710 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5711 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005712
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005713 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005714 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005715 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005716 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005717 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005718 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5719 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005720 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005721 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005722 {}
5723};
5724
Takashi Iwai912093b2012-04-11 14:03:41 +02005725static const struct alc_model_fixup alc882_fixup_models[] = {
5726 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5727 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5728 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005729 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005730 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005731 {}
5732};
5733
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734/*
5735 * BIOS auto configuration
5736 */
5737/* almost identical with ALC880 parser... */
5738static int alc882_parse_auto_config(struct hda_codec *codec)
5739{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005740 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005741 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5742 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743}
5744
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745/*
5746 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005747static int patch_alc882(struct hda_codec *codec)
5748{
5749 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005750 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751
Takashi Iwai3de95172012-05-07 18:03:15 +02005752 err = alc_alloc_spec(codec, 0x0b);
5753 if (err < 0)
5754 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755
Takashi Iwai3de95172012-05-07 18:03:15 +02005756 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757
5758 switch (codec->vendor_id) {
5759 case 0x10ec0882:
5760 case 0x10ec0885:
5761 break;
5762 default:
5763 /* ALC883 and variants */
5764 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5765 break;
5766 }
5767
Takashi Iwai912093b2012-04-11 14:03:41 +02005768 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5769 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005770 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005771
5772 alc_auto_parse_customize_define(codec);
5773
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005774 /* automatic parse from the BIOS config */
5775 err = alc882_parse_auto_config(codec);
5776 if (err < 0)
5777 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005778
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005779 if (!spec->no_analog && has_cdefine_beep(codec)) {
5780 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005781 if (err < 0)
5782 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005783 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005784 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005785
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787
Takashi Iwai589876e2012-02-20 15:47:55 +01005788 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5789
Takashi Iwai1d045db2011-07-07 18:23:21 +02005790 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005791
5792 error:
5793 alc_free(codec);
5794 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005795}
5796
5797
5798/*
5799 * ALC262 support
5800 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005801static int alc262_parse_auto_config(struct hda_codec *codec)
5802{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005803 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005804 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5805 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005806}
5807
5808/*
5809 * Pin config fixes
5810 */
5811enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005812 ALC262_FIXUP_FSC_H270,
5813 ALC262_FIXUP_HP_Z200,
5814 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005815 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005816 ALC262_FIXUP_BENQ,
5817 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005818 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005819};
5820
5821static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005822 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005823 .type = ALC_FIXUP_PINS,
5824 .v.pins = (const struct alc_pincfg[]) {
5825 { 0x14, 0x99130110 }, /* speaker */
5826 { 0x15, 0x0221142f }, /* front HP */
5827 { 0x1b, 0x0121141f }, /* rear HP */
5828 { }
5829 }
5830 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005831 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005832 .type = ALC_FIXUP_PINS,
5833 .v.pins = (const struct alc_pincfg[]) {
5834 { 0x16, 0x99130120 }, /* internal speaker */
5835 { }
5836 }
5837 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005838 [ALC262_FIXUP_TYAN] = {
5839 .type = ALC_FIXUP_PINS,
5840 .v.pins = (const struct alc_pincfg[]) {
5841 { 0x14, 0x1993e1f0 }, /* int AUX */
5842 { }
5843 }
5844 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005845 [ALC262_FIXUP_LENOVO_3000] = {
5846 .type = ALC_FIXUP_VERBS,
5847 .v.verbs = (const struct hda_verb[]) {
5848 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005849 {}
5850 },
5851 .chained = true,
5852 .chain_id = ALC262_FIXUP_BENQ,
5853 },
5854 [ALC262_FIXUP_BENQ] = {
5855 .type = ALC_FIXUP_VERBS,
5856 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005857 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5858 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5859 {}
5860 }
5861 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005862 [ALC262_FIXUP_BENQ_T31] = {
5863 .type = ALC_FIXUP_VERBS,
5864 .v.verbs = (const struct hda_verb[]) {
5865 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5866 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5867 {}
5868 }
5869 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005870 [ALC262_FIXUP_INV_DMIC] = {
5871 .type = ALC_FIXUP_FUNC,
5872 .v.func = alc_fixup_inv_dmic_0x12,
5873 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005874};
5875
5876static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005877 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005878 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5879 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005880 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5881 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005882 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005883 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5884 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005885 {}
5886};
5887
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005888static const struct alc_model_fixup alc262_fixup_models[] = {
5889 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5890 {}
5891};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005892
Takashi Iwai1d045db2011-07-07 18:23:21 +02005893/*
5894 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005895static int patch_alc262(struct hda_codec *codec)
5896{
5897 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005898 int err;
5899
Takashi Iwai3de95172012-05-07 18:03:15 +02005900 err = alc_alloc_spec(codec, 0x0b);
5901 if (err < 0)
5902 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005903
Takashi Iwai3de95172012-05-07 18:03:15 +02005904 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005905
5906#if 0
5907 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5908 * under-run
5909 */
5910 {
5911 int tmp;
5912 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5913 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5914 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5915 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5916 }
5917#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005918 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5919
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005920 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5921 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005922 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005923
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005924 alc_auto_parse_customize_define(codec);
5925
Takashi Iwai42399f72011-11-07 17:18:44 +01005926 /* automatic parse from the BIOS config */
5927 err = alc262_parse_auto_config(codec);
5928 if (err < 0)
5929 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005930
Takashi Iwai1d045db2011-07-07 18:23:21 +02005931 if (!spec->no_analog && has_cdefine_beep(codec)) {
5932 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005933 if (err < 0)
5934 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005935 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005936 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005937
Takashi Iwai1d045db2011-07-07 18:23:21 +02005938 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005939 spec->shutup = alc_eapd_shutup;
5940
Takashi Iwai589876e2012-02-20 15:47:55 +01005941 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5942
Takashi Iwai1d045db2011-07-07 18:23:21 +02005943 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005944
5945 error:
5946 alc_free(codec);
5947 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005948}
5949
5950/*
5951 * ALC268
5952 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005953/* bind Beep switches of both NID 0x0f and 0x10 */
5954static const struct hda_bind_ctls alc268_bind_beep_sw = {
5955 .ops = &snd_hda_bind_sw,
5956 .values = {
5957 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5958 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5959 0
5960 },
5961};
5962
5963static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5964 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5965 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5966 { }
5967};
5968
5969/* set PCBEEP vol = 0, mute connections */
5970static const struct hda_verb alc268_beep_init_verbs[] = {
5971 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5972 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5973 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5974 { }
5975};
5976
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005977enum {
5978 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005979 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005980};
5981
5982static const struct alc_fixup alc268_fixups[] = {
5983 [ALC268_FIXUP_INV_DMIC] = {
5984 .type = ALC_FIXUP_FUNC,
5985 .v.func = alc_fixup_inv_dmic_0x12,
5986 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005987 [ALC268_FIXUP_HP_EAPD] = {
5988 .type = ALC_FIXUP_VERBS,
5989 .v.verbs = (const struct hda_verb[]) {
5990 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5991 {}
5992 }
5993 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005994};
5995
5996static const struct alc_model_fixup alc268_fixup_models[] = {
5997 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005998 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5999 {}
6000};
6001
6002static const struct snd_pci_quirk alc268_fixup_tbl[] = {
6003 /* below is codec SSID since multiple Toshiba laptops have the
6004 * same PCI SSID 1179:ff00
6005 */
6006 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006007 {}
6008};
6009
Takashi Iwai1d045db2011-07-07 18:23:21 +02006010/*
6011 * BIOS auto configuration
6012 */
6013static int alc268_parse_auto_config(struct hda_codec *codec)
6014{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006015 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02006016 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006017 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
6018 if (err > 0) {
6019 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
6020 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02006021 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006022 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006023 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006024 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006025}
6026
Takashi Iwai1d045db2011-07-07 18:23:21 +02006027/*
6028 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006029static int patch_alc268(struct hda_codec *codec)
6030{
6031 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006032 int i, has_beep, err;
6033
Takashi Iwai1d045db2011-07-07 18:23:21 +02006034 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006035 err = alc_alloc_spec(codec, 0);
6036 if (err < 0)
6037 return err;
6038
6039 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006040
Takashi Iwaicb766402012-10-20 10:55:21 +02006041 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006042 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6043
Takashi Iwai6ebb8052011-08-16 15:15:40 +02006044 /* automatic parse from the BIOS config */
6045 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006046 if (err < 0)
6047 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006048
Takashi Iwai1d045db2011-07-07 18:23:21 +02006049 has_beep = 0;
6050 for (i = 0; i < spec->num_mixers; i++) {
6051 if (spec->mixers[i] == alc268_beep_mixer) {
6052 has_beep = 1;
6053 break;
6054 }
6055 }
6056
6057 if (has_beep) {
6058 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006059 if (err < 0)
6060 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006061 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
6062 /* override the amp caps for beep generator */
6063 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
6064 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
6065 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6066 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6067 (0 << AC_AMPCAP_MUTE_SHIFT));
6068 }
6069
Takashi Iwai1d045db2011-07-07 18:23:21 +02006070 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006071 spec->shutup = alc_eapd_shutup;
6072
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006073 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6074
Takashi Iwai1d045db2011-07-07 18:23:21 +02006075 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006076
6077 error:
6078 alc_free(codec);
6079 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006080}
6081
6082/*
6083 * ALC269
6084 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006085static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6086 .substreams = 1,
6087 .channels_min = 2,
6088 .channels_max = 8,
6089 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6090 /* NID is set in alc_build_pcms */
6091 .ops = {
6092 .open = alc_playback_pcm_open,
6093 .prepare = alc_playback_pcm_prepare,
6094 .cleanup = alc_playback_pcm_cleanup
6095 },
6096};
6097
6098static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6099 .substreams = 1,
6100 .channels_min = 2,
6101 .channels_max = 2,
6102 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6103 /* NID is set in alc_build_pcms */
6104};
6105
Takashi Iwai1d045db2011-07-07 18:23:21 +02006106/* different alc269-variants */
6107enum {
6108 ALC269_TYPE_ALC269VA,
6109 ALC269_TYPE_ALC269VB,
6110 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006111 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006112 ALC269_TYPE_ALC280,
6113 ALC269_TYPE_ALC282,
6114 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006115};
6116
6117/*
6118 * BIOS auto configuration
6119 */
6120static int alc269_parse_auto_config(struct hda_codec *codec)
6121{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006122 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006123 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6124 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6125 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006126 const hda_nid_t *ssids;
6127
6128 switch (spec->codec_variant) {
6129 case ALC269_TYPE_ALC269VA:
6130 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006131 case ALC269_TYPE_ALC280:
6132 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006133 ssids = alc269va_ssids;
6134 break;
6135 case ALC269_TYPE_ALC269VB:
6136 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006137 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006138 ssids = alc269_ssids;
6139 break;
6140 default:
6141 ssids = alc269_ssids;
6142 break;
6143 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006144
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006145 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006146}
6147
Kailang Yang1387e2d2012-11-08 10:23:18 +01006148static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006149{
6150 int val = alc_read_coef_idx(codec, 0x04);
6151 if (power_up)
6152 val |= 1 << 11;
6153 else
6154 val &= ~(1 << 11);
6155 alc_write_coef_idx(codec, 0x04, val);
6156}
6157
6158static void alc269_shutup(struct hda_codec *codec)
6159{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006160 struct alc_spec *spec = codec->spec;
6161
6162 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6163 return;
6164
Kailang Yang1387e2d2012-11-08 10:23:18 +01006165 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6166 alc269vb_toggle_power_output(codec, 0);
6167 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6168 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006169 msleep(150);
6170 }
6171}
6172
Takashi Iwai2a439522011-07-26 09:52:50 +02006173#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006174static int alc269_resume(struct hda_codec *codec)
6175{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006176 struct alc_spec *spec = codec->spec;
6177
Kailang Yang1387e2d2012-11-08 10:23:18 +01006178 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6179 alc269vb_toggle_power_output(codec, 0);
6180 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006181 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006182 msleep(150);
6183 }
6184
6185 codec->patch_ops.init(codec);
6186
Kailang Yang1387e2d2012-11-08 10:23:18 +01006187 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6188 alc269vb_toggle_power_output(codec, 1);
6189 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006190 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006191 msleep(200);
6192 }
6193
Takashi Iwai1d045db2011-07-07 18:23:21 +02006194 snd_hda_codec_resume_amp(codec);
6195 snd_hda_codec_resume_cache(codec);
6196 hda_call_check_power_status(codec, 0x01);
6197 return 0;
6198}
Takashi Iwai2a439522011-07-26 09:52:50 +02006199#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006200
David Henningsson108cc102012-07-20 10:37:25 +02006201static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6202 const struct alc_fixup *fix, int action)
6203{
6204 struct alc_spec *spec = codec->spec;
6205
6206 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6207 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6208}
6209
Takashi Iwai1d045db2011-07-07 18:23:21 +02006210static void alc269_fixup_hweq(struct hda_codec *codec,
6211 const struct alc_fixup *fix, int action)
6212{
6213 int coef;
6214
6215 if (action != ALC_FIXUP_ACT_INIT)
6216 return;
6217 coef = alc_read_coef_idx(codec, 0x1e);
6218 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6219}
6220
6221static void alc271_fixup_dmic(struct hda_codec *codec,
6222 const struct alc_fixup *fix, int action)
6223{
6224 static const struct hda_verb verbs[] = {
6225 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6226 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6227 {}
6228 };
6229 unsigned int cfg;
6230
6231 if (strcmp(codec->chip_name, "ALC271X"))
6232 return;
6233 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6234 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6235 snd_hda_sequence_write(codec, verbs);
6236}
6237
Takashi Iwai017f2a12011-07-09 14:42:25 +02006238static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6239 const struct alc_fixup *fix, int action)
6240{
6241 struct alc_spec *spec = codec->spec;
6242
6243 if (action != ALC_FIXUP_ACT_PROBE)
6244 return;
6245
6246 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6247 * fix the sample rate of analog I/O to 44.1kHz
6248 */
6249 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6250 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6251}
6252
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006253static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6254 const struct alc_fixup *fix, int action)
6255{
6256 int coef;
6257
6258 if (action != ALC_FIXUP_ACT_INIT)
6259 return;
6260 /* The digital-mic unit sends PDM (differential signal) instead of
6261 * the standard PCM, thus you can't record a valid mono stream as is.
6262 * Below is a workaround specific to ALC269 to control the dmic
6263 * signal source as mono.
6264 */
6265 coef = alc_read_coef_idx(codec, 0x07);
6266 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6267}
6268
Takashi Iwai24519912011-08-16 15:08:49 +02006269static void alc269_quanta_automute(struct hda_codec *codec)
6270{
David Henningsson42cf0d02011-09-20 12:04:56 +02006271 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006272
6273 snd_hda_codec_write(codec, 0x20, 0,
6274 AC_VERB_SET_COEF_INDEX, 0x0c);
6275 snd_hda_codec_write(codec, 0x20, 0,
6276 AC_VERB_SET_PROC_COEF, 0x680);
6277
6278 snd_hda_codec_write(codec, 0x20, 0,
6279 AC_VERB_SET_COEF_INDEX, 0x0c);
6280 snd_hda_codec_write(codec, 0x20, 0,
6281 AC_VERB_SET_PROC_COEF, 0x480);
6282}
6283
6284static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6285 const struct alc_fixup *fix, int action)
6286{
6287 struct alc_spec *spec = codec->spec;
6288 if (action != ALC_FIXUP_ACT_PROBE)
6289 return;
6290 spec->automute_hook = alc269_quanta_automute;
6291}
6292
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006293/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6294static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6295{
6296 struct hda_codec *codec = private_data;
6297 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6298 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6299 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6300}
6301
6302static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6303 const struct alc_fixup *fix, int action)
6304{
6305 struct alc_spec *spec = codec->spec;
6306 switch (action) {
6307 case ALC_FIXUP_ACT_BUILD:
6308 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6309 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6310 /* fallthru */
6311 case ALC_FIXUP_ACT_INIT:
6312 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6313 break;
6314 }
6315}
6316
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006317/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6318static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6319{
6320 struct hda_codec *codec = private_data;
6321 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006322 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006323}
6324
6325static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6326 const struct alc_fixup *fix, int action)
6327{
6328 struct alc_spec *spec = codec->spec;
6329 switch (action) {
6330 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006331 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006332 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006333 /* fallthru */
6334 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006335 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006336 break;
6337 }
6338}
6339
Dylan Reid08a978d2012-11-18 22:56:40 -08006340static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6341 const struct alc_fixup *fix,
6342 int action)
6343{
6344 struct alc_spec *spec = codec->spec;
6345
6346 if (action == ALC_FIXUP_ACT_PROBE)
6347 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6348 spec->autocfg.hp_pins[0]);
6349}
David Henningsson693b6132012-06-22 19:12:10 +02006350
Takashi Iwai1d045db2011-07-07 18:23:21 +02006351enum {
6352 ALC269_FIXUP_SONY_VAIO,
6353 ALC275_FIXUP_SONY_VAIO_GPIO2,
6354 ALC269_FIXUP_DELL_M101Z,
6355 ALC269_FIXUP_SKU_IGNORE,
6356 ALC269_FIXUP_ASUS_G73JW,
6357 ALC269_FIXUP_LENOVO_EAPD,
6358 ALC275_FIXUP_SONY_HWEQ,
6359 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006360 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006361 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006362 ALC269_FIXUP_QUANTA_MUTE,
6363 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006364 ALC269_FIXUP_AMIC,
6365 ALC269_FIXUP_DMIC,
6366 ALC269VB_FIXUP_AMIC,
6367 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006368 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006369 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006370 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006371 ALC269_FIXUP_LENOVO_DOCK,
6372 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006373 ALC271_FIXUP_AMIC_MIC2,
6374 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006375};
6376
6377static const struct alc_fixup alc269_fixups[] = {
6378 [ALC269_FIXUP_SONY_VAIO] = {
6379 .type = ALC_FIXUP_VERBS,
6380 .v.verbs = (const struct hda_verb[]) {
6381 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6382 {}
6383 }
6384 },
6385 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6386 .type = ALC_FIXUP_VERBS,
6387 .v.verbs = (const struct hda_verb[]) {
6388 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6389 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6390 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6391 { }
6392 },
6393 .chained = true,
6394 .chain_id = ALC269_FIXUP_SONY_VAIO
6395 },
6396 [ALC269_FIXUP_DELL_M101Z] = {
6397 .type = ALC_FIXUP_VERBS,
6398 .v.verbs = (const struct hda_verb[]) {
6399 /* Enables internal speaker */
6400 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6401 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6402 {}
6403 }
6404 },
6405 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006406 .type = ALC_FIXUP_FUNC,
6407 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006408 },
6409 [ALC269_FIXUP_ASUS_G73JW] = {
6410 .type = ALC_FIXUP_PINS,
6411 .v.pins = (const struct alc_pincfg[]) {
6412 { 0x17, 0x99130111 }, /* subwoofer */
6413 { }
6414 }
6415 },
6416 [ALC269_FIXUP_LENOVO_EAPD] = {
6417 .type = ALC_FIXUP_VERBS,
6418 .v.verbs = (const struct hda_verb[]) {
6419 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6420 {}
6421 }
6422 },
6423 [ALC275_FIXUP_SONY_HWEQ] = {
6424 .type = ALC_FIXUP_FUNC,
6425 .v.func = alc269_fixup_hweq,
6426 .chained = true,
6427 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6428 },
6429 [ALC271_FIXUP_DMIC] = {
6430 .type = ALC_FIXUP_FUNC,
6431 .v.func = alc271_fixup_dmic,
6432 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006433 [ALC269_FIXUP_PCM_44K] = {
6434 .type = ALC_FIXUP_FUNC,
6435 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006436 .chained = true,
6437 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006438 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006439 [ALC269_FIXUP_STEREO_DMIC] = {
6440 .type = ALC_FIXUP_FUNC,
6441 .v.func = alc269_fixup_stereo_dmic,
6442 },
Takashi Iwai24519912011-08-16 15:08:49 +02006443 [ALC269_FIXUP_QUANTA_MUTE] = {
6444 .type = ALC_FIXUP_FUNC,
6445 .v.func = alc269_fixup_quanta_mute,
6446 },
6447 [ALC269_FIXUP_LIFEBOOK] = {
6448 .type = ALC_FIXUP_PINS,
6449 .v.pins = (const struct alc_pincfg[]) {
6450 { 0x1a, 0x2101103f }, /* dock line-out */
6451 { 0x1b, 0x23a11040 }, /* dock mic-in */
6452 { }
6453 },
6454 .chained = true,
6455 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6456 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006457 [ALC269_FIXUP_AMIC] = {
6458 .type = ALC_FIXUP_PINS,
6459 .v.pins = (const struct alc_pincfg[]) {
6460 { 0x14, 0x99130110 }, /* speaker */
6461 { 0x15, 0x0121401f }, /* HP out */
6462 { 0x18, 0x01a19c20 }, /* mic */
6463 { 0x19, 0x99a3092f }, /* int-mic */
6464 { }
6465 },
6466 },
6467 [ALC269_FIXUP_DMIC] = {
6468 .type = ALC_FIXUP_PINS,
6469 .v.pins = (const struct alc_pincfg[]) {
6470 { 0x12, 0x99a3092f }, /* int-mic */
6471 { 0x14, 0x99130110 }, /* speaker */
6472 { 0x15, 0x0121401f }, /* HP out */
6473 { 0x18, 0x01a19c20 }, /* mic */
6474 { }
6475 },
6476 },
6477 [ALC269VB_FIXUP_AMIC] = {
6478 .type = ALC_FIXUP_PINS,
6479 .v.pins = (const struct alc_pincfg[]) {
6480 { 0x14, 0x99130110 }, /* speaker */
6481 { 0x18, 0x01a19c20 }, /* mic */
6482 { 0x19, 0x99a3092f }, /* int-mic */
6483 { 0x21, 0x0121401f }, /* HP out */
6484 { }
6485 },
6486 },
David Henningsson2267ea92012-01-03 08:45:56 +01006487 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006488 .type = ALC_FIXUP_PINS,
6489 .v.pins = (const struct alc_pincfg[]) {
6490 { 0x12, 0x99a3092f }, /* int-mic */
6491 { 0x14, 0x99130110 }, /* speaker */
6492 { 0x18, 0x01a19c20 }, /* mic */
6493 { 0x21, 0x0121401f }, /* HP out */
6494 { }
6495 },
6496 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006497 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6498 .type = ALC_FIXUP_FUNC,
6499 .v.func = alc269_fixup_mic1_mute,
6500 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006501 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6502 .type = ALC_FIXUP_FUNC,
6503 .v.func = alc269_fixup_mic2_mute,
6504 },
David Henningsson693b6132012-06-22 19:12:10 +02006505 [ALC269_FIXUP_INV_DMIC] = {
6506 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006507 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006508 },
David Henningsson108cc102012-07-20 10:37:25 +02006509 [ALC269_FIXUP_LENOVO_DOCK] = {
6510 .type = ALC_FIXUP_PINS,
6511 .v.pins = (const struct alc_pincfg[]) {
6512 { 0x19, 0x23a11040 }, /* dock mic */
6513 { 0x1b, 0x2121103f }, /* dock headphone */
6514 { }
6515 },
6516 .chained = true,
6517 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6518 },
6519 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6520 .type = ALC_FIXUP_FUNC,
6521 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6522 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006523 [ALC271_FIXUP_AMIC_MIC2] = {
6524 .type = ALC_FIXUP_PINS,
6525 .v.pins = (const struct alc_pincfg[]) {
6526 { 0x14, 0x99130110 }, /* speaker */
6527 { 0x19, 0x01a19c20 }, /* mic */
6528 { 0x1b, 0x99a7012f }, /* int-mic */
6529 { 0x21, 0x0121401f }, /* HP out */
6530 { }
6531 },
6532 },
6533 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6534 .type = ALC_FIXUP_FUNC,
6535 .v.func = alc271_hp_gate_mic_jack,
6536 .chained = true,
6537 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6538 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006539};
6540
6541static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006542 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6543 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006544 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006545 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006546 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006547 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006548 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006549 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006550 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6551 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6552 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6553 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6554 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006555 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6556 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6557 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6558 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6559 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006560 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006561 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006562 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006563 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6564 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6565 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6566 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6567 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006568 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006569 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006570 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006571 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006572 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006573 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006574 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006575
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006576#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006577 /* Below is a quirk table taken from the old code.
6578 * Basically the device should work as is without the fixup table.
6579 * If BIOS doesn't give a proper info, enable the corresponding
6580 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006581 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006582 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6583 ALC269_FIXUP_AMIC),
6584 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006585 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6586 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6587 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6588 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6589 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6590 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6591 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6592 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6593 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6594 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6595 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6596 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6597 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6598 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6599 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6600 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6601 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6602 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6603 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6604 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6605 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6606 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6607 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6608 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6609 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6610 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6611 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6612 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6613 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6614 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6615 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6616 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6617 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6618 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6619 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6620 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6621 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6622 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6623#endif
6624 {}
6625};
6626
6627static const struct alc_model_fixup alc269_fixup_models[] = {
6628 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6629 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006630 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6631 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6632 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006633 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006634 {}
6635};
6636
6637
Takashi Iwai546bb672012-03-07 08:37:19 +01006638static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006639{
Kailang Yang526af6e2012-03-07 08:25:20 +01006640 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006641 int val;
6642
Kailang Yang526af6e2012-03-07 08:25:20 +01006643 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006644 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006645
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006646 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006647 alc_write_coef_idx(codec, 0xf, 0x960b);
6648 alc_write_coef_idx(codec, 0xe, 0x8817);
6649 }
6650
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006651 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006652 alc_write_coef_idx(codec, 0xf, 0x960b);
6653 alc_write_coef_idx(codec, 0xe, 0x8814);
6654 }
6655
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006656 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006657 val = alc_read_coef_idx(codec, 0x04);
6658 /* Power up output pin */
6659 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6660 }
6661
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006662 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006663 val = alc_read_coef_idx(codec, 0xd);
6664 if ((val & 0x0c00) >> 10 != 0x1) {
6665 /* Capless ramp up clock control */
6666 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6667 }
6668 val = alc_read_coef_idx(codec, 0x17);
6669 if ((val & 0x01c0) >> 6 != 0x4) {
6670 /* Class D power on reset */
6671 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6672 }
6673 }
6674
6675 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6676 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6677
6678 val = alc_read_coef_idx(codec, 0x4); /* HP */
6679 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006680}
6681
6682/*
6683 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006684static int patch_alc269(struct hda_codec *codec)
6685{
6686 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006687 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006688
Takashi Iwai3de95172012-05-07 18:03:15 +02006689 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006690 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006691 return err;
6692
6693 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006694
Herton Ronaldo Krzesinski9f720bb92012-09-27 10:38:14 -03006695 alc_pick_fixup(codec, alc269_fixup_models,
6696 alc269_fixup_tbl, alc269_fixups);
6697 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6698
6699 alc_auto_parse_customize_define(codec);
6700
Kailang Yang065380f2013-01-10 10:25:48 +01006701 switch (codec->vendor_id) {
6702 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006703 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006704 switch (alc_get_coef0(codec) & 0x00f0) {
6705 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006706 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006707 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006708 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006709 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006710 break;
6711 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006712 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6713 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006714 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006715 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006716 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006717 case 0x0030:
6718 spec->codec_variant = ALC269_TYPE_ALC269VD;
6719 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006720 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006721 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006722 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006723 if (err < 0)
6724 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006725 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006726 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006727 break;
6728
6729 case 0x10ec0280:
6730 case 0x10ec0290:
6731 spec->codec_variant = ALC269_TYPE_ALC280;
6732 break;
6733 case 0x10ec0282:
6734 case 0x10ec0283:
6735 spec->codec_variant = ALC269_TYPE_ALC282;
6736 break;
6737 case 0x10ec0284:
6738 case 0x10ec0292:
6739 spec->codec_variant = ALC269_TYPE_ALC284;
6740 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006741 }
6742
Takashi Iwaia4297b52011-08-23 18:40:12 +02006743 /* automatic parse from the BIOS config */
6744 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006745 if (err < 0)
6746 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006747
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006748 if (!spec->no_analog && has_cdefine_beep(codec)) {
6749 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006750 if (err < 0)
6751 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006752 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006753 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006754
Takashi Iwai1d045db2011-07-07 18:23:21 +02006755 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006756#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006757 codec->patch_ops.resume = alc269_resume;
6758#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006759 spec->shutup = alc269_shutup;
6760
Takashi Iwai589876e2012-02-20 15:47:55 +01006761 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6762
Takashi Iwai1d045db2011-07-07 18:23:21 +02006763 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006764
6765 error:
6766 alc_free(codec);
6767 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006768}
6769
6770/*
6771 * ALC861
6772 */
6773
Takashi Iwai1d045db2011-07-07 18:23:21 +02006774static int alc861_parse_auto_config(struct hda_codec *codec)
6775{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006776 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006777 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6778 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006779}
6780
Takashi Iwai1d045db2011-07-07 18:23:21 +02006781/* Pin config fixes */
6782enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006783 ALC861_FIXUP_FSC_AMILO_PI1505,
6784 ALC861_FIXUP_AMP_VREF_0F,
6785 ALC861_FIXUP_NO_JACK_DETECT,
6786 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006787};
6788
Takashi Iwai31150f22012-01-30 10:54:08 +01006789/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6790static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6791 const struct alc_fixup *fix, int action)
6792{
6793 struct alc_spec *spec = codec->spec;
6794 unsigned int val;
6795
6796 if (action != ALC_FIXUP_ACT_INIT)
6797 return;
6798 val = snd_hda_codec_read(codec, 0x0f, 0,
6799 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6800 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6801 val |= AC_PINCTL_IN_EN;
6802 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006803 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006804 spec->keep_vref_in_automute = 1;
6805}
6806
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006807/* suppress the jack-detection */
6808static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6809 const struct alc_fixup *fix, int action)
6810{
6811 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6812 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006813}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006814
Takashi Iwai1d045db2011-07-07 18:23:21 +02006815static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006816 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006817 .type = ALC_FIXUP_PINS,
6818 .v.pins = (const struct alc_pincfg[]) {
6819 { 0x0b, 0x0221101f }, /* HP */
6820 { 0x0f, 0x90170310 }, /* speaker */
6821 { }
6822 }
6823 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006824 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006825 .type = ALC_FIXUP_FUNC,
6826 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006827 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006828 [ALC861_FIXUP_NO_JACK_DETECT] = {
6829 .type = ALC_FIXUP_FUNC,
6830 .v.func = alc_fixup_no_jack_detect,
6831 },
6832 [ALC861_FIXUP_ASUS_A6RP] = {
6833 .type = ALC_FIXUP_FUNC,
6834 .v.func = alc861_fixup_asus_amp_vref_0f,
6835 .chained = true,
6836 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6837 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006838};
6839
6840static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006841 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6842 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6843 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6844 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6845 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6846 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006847 {}
6848};
6849
6850/*
6851 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006852static int patch_alc861(struct hda_codec *codec)
6853{
6854 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006855 int err;
6856
Takashi Iwai3de95172012-05-07 18:03:15 +02006857 err = alc_alloc_spec(codec, 0x15);
6858 if (err < 0)
6859 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006860
Takashi Iwai3de95172012-05-07 18:03:15 +02006861 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006862
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006863 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6864 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006865
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006866 /* automatic parse from the BIOS config */
6867 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006868 if (err < 0)
6869 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006870
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006871 if (!spec->no_analog) {
6872 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006873 if (err < 0)
6874 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006875 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6876 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006877
Takashi Iwai1d045db2011-07-07 18:23:21 +02006878 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006879#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006880 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006881#endif
6882
Takashi Iwai589876e2012-02-20 15:47:55 +01006883 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6884
Takashi Iwai1d045db2011-07-07 18:23:21 +02006885 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006886
6887 error:
6888 alc_free(codec);
6889 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006890}
6891
6892/*
6893 * ALC861-VD support
6894 *
6895 * Based on ALC882
6896 *
6897 * In addition, an independent DAC
6898 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006899static int alc861vd_parse_auto_config(struct hda_codec *codec)
6900{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006901 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006902 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6903 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006904}
6905
Takashi Iwai1d045db2011-07-07 18:23:21 +02006906enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006907 ALC660VD_FIX_ASUS_GPIO1,
6908 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006909};
6910
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006911/* exclude VREF80 */
6912static void alc861vd_fixup_dallas(struct hda_codec *codec,
6913 const struct alc_fixup *fix, int action)
6914{
6915 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006916 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6917 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006918 }
6919}
6920
Takashi Iwai1d045db2011-07-07 18:23:21 +02006921static const struct alc_fixup alc861vd_fixups[] = {
6922 [ALC660VD_FIX_ASUS_GPIO1] = {
6923 .type = ALC_FIXUP_VERBS,
6924 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006925 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006926 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6927 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6928 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6929 { }
6930 }
6931 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006932 [ALC861VD_FIX_DALLAS] = {
6933 .type = ALC_FIXUP_FUNC,
6934 .v.func = alc861vd_fixup_dallas,
6935 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006936};
6937
6938static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006939 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006940 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006941 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006942 {}
6943};
6944
Takashi Iwai1d045db2011-07-07 18:23:21 +02006945/*
6946 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006947static int patch_alc861vd(struct hda_codec *codec)
6948{
6949 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006950 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006951
Takashi Iwai3de95172012-05-07 18:03:15 +02006952 err = alc_alloc_spec(codec, 0x0b);
6953 if (err < 0)
6954 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006955
Takashi Iwai3de95172012-05-07 18:03:15 +02006956 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006957
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006958 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6959 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006960
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006961 /* automatic parse from the BIOS config */
6962 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006963 if (err < 0)
6964 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006965
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006966 if (!spec->no_analog) {
6967 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006968 if (err < 0)
6969 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006970 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6971 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006972
Takashi Iwai1d045db2011-07-07 18:23:21 +02006973 codec->patch_ops = alc_patch_ops;
6974
Takashi Iwai1d045db2011-07-07 18:23:21 +02006975 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006976
Takashi Iwai589876e2012-02-20 15:47:55 +01006977 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6978
Takashi Iwai1d045db2011-07-07 18:23:21 +02006979 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006980
6981 error:
6982 alc_free(codec);
6983 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006984}
6985
6986/*
6987 * ALC662 support
6988 *
6989 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6990 * configuration. Each pin widget can choose any input DACs and a mixer.
6991 * Each ADC is connected from a mixer of all inputs. This makes possible
6992 * 6-channel independent captures.
6993 *
6994 * In addition, an independent DAC for the multi-playback (not used in this
6995 * driver yet).
6996 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006997
6998/*
6999 * BIOS auto configuration
7000 */
7001
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007002static int alc662_parse_auto_config(struct hda_codec *codec)
7003{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02007004 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007005 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
7006 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
7007 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02007008
Kailang Yang6227cdc2010-02-25 08:36:52 +01007009 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
7010 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007011 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01007012 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007013 ssids = alc662_ssids;
7014 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007015}
7016
Todd Broch6be79482010-12-07 16:51:05 -08007017static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007018 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01007019{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007020 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01007021 return;
Todd Broch6be79482010-12-07 16:51:05 -08007022 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
7023 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
7024 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
7025 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
7026 (0 << AC_AMPCAP_MUTE_SHIFT)))
7027 printk(KERN_WARNING
7028 "hda_codec: failed to override amp caps for NID 0x2\n");
7029}
7030
David Henningsson6cb3b702010-09-09 08:51:44 +02007031enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04007032 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02007033 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08007034 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007035 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02007036 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007037 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02007038 ALC662_FIXUP_ASUS_MODE1,
7039 ALC662_FIXUP_ASUS_MODE2,
7040 ALC662_FIXUP_ASUS_MODE3,
7041 ALC662_FIXUP_ASUS_MODE4,
7042 ALC662_FIXUP_ASUS_MODE5,
7043 ALC662_FIXUP_ASUS_MODE6,
7044 ALC662_FIXUP_ASUS_MODE7,
7045 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01007046 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02007047 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02007048 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02007049};
7050
7051static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04007052 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007053 .type = ALC_FIXUP_PINS,
7054 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04007055 { 0x15, 0x99130112 }, /* subwoofer */
7056 { }
7057 }
7058 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007059 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007060 .type = ALC_FIXUP_PINS,
7061 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02007062 { 0x17, 0x99130112 }, /* subwoofer */
7063 { }
7064 }
7065 },
Todd Broch6be79482010-12-07 16:51:05 -08007066 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007067 .type = ALC_FIXUP_FUNC,
7068 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007069 },
7070 [ALC662_FIXUP_CZC_P10T] = {
7071 .type = ALC_FIXUP_VERBS,
7072 .v.verbs = (const struct hda_verb[]) {
7073 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7074 {}
7075 }
7076 },
David Henningsson94024cd2011-04-29 14:10:55 +02007077 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007078 .type = ALC_FIXUP_FUNC,
7079 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007080 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007081 [ALC662_FIXUP_HP_RP5800] = {
7082 .type = ALC_FIXUP_PINS,
7083 .v.pins = (const struct alc_pincfg[]) {
7084 { 0x14, 0x0221201f }, /* HP out */
7085 { }
7086 },
7087 .chained = true,
7088 .chain_id = ALC662_FIXUP_SKU_IGNORE
7089 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007090 [ALC662_FIXUP_ASUS_MODE1] = {
7091 .type = ALC_FIXUP_PINS,
7092 .v.pins = (const struct alc_pincfg[]) {
7093 { 0x14, 0x99130110 }, /* speaker */
7094 { 0x18, 0x01a19c20 }, /* mic */
7095 { 0x19, 0x99a3092f }, /* int-mic */
7096 { 0x21, 0x0121401f }, /* HP out */
7097 { }
7098 },
7099 .chained = true,
7100 .chain_id = ALC662_FIXUP_SKU_IGNORE
7101 },
7102 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007103 .type = ALC_FIXUP_PINS,
7104 .v.pins = (const struct alc_pincfg[]) {
7105 { 0x14, 0x99130110 }, /* speaker */
7106 { 0x18, 0x01a19820 }, /* mic */
7107 { 0x19, 0x99a3092f }, /* int-mic */
7108 { 0x1b, 0x0121401f }, /* HP out */
7109 { }
7110 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007111 .chained = true,
7112 .chain_id = ALC662_FIXUP_SKU_IGNORE
7113 },
7114 [ALC662_FIXUP_ASUS_MODE3] = {
7115 .type = ALC_FIXUP_PINS,
7116 .v.pins = (const struct alc_pincfg[]) {
7117 { 0x14, 0x99130110 }, /* speaker */
7118 { 0x15, 0x0121441f }, /* HP */
7119 { 0x18, 0x01a19840 }, /* mic */
7120 { 0x19, 0x99a3094f }, /* int-mic */
7121 { 0x21, 0x01211420 }, /* HP2 */
7122 { }
7123 },
7124 .chained = true,
7125 .chain_id = ALC662_FIXUP_SKU_IGNORE
7126 },
7127 [ALC662_FIXUP_ASUS_MODE4] = {
7128 .type = ALC_FIXUP_PINS,
7129 .v.pins = (const struct alc_pincfg[]) {
7130 { 0x14, 0x99130110 }, /* speaker */
7131 { 0x16, 0x99130111 }, /* speaker */
7132 { 0x18, 0x01a19840 }, /* mic */
7133 { 0x19, 0x99a3094f }, /* int-mic */
7134 { 0x21, 0x0121441f }, /* HP */
7135 { }
7136 },
7137 .chained = true,
7138 .chain_id = ALC662_FIXUP_SKU_IGNORE
7139 },
7140 [ALC662_FIXUP_ASUS_MODE5] = {
7141 .type = ALC_FIXUP_PINS,
7142 .v.pins = (const struct alc_pincfg[]) {
7143 { 0x14, 0x99130110 }, /* speaker */
7144 { 0x15, 0x0121441f }, /* HP */
7145 { 0x16, 0x99130111 }, /* speaker */
7146 { 0x18, 0x01a19840 }, /* mic */
7147 { 0x19, 0x99a3094f }, /* int-mic */
7148 { }
7149 },
7150 .chained = true,
7151 .chain_id = ALC662_FIXUP_SKU_IGNORE
7152 },
7153 [ALC662_FIXUP_ASUS_MODE6] = {
7154 .type = ALC_FIXUP_PINS,
7155 .v.pins = (const struct alc_pincfg[]) {
7156 { 0x14, 0x99130110 }, /* speaker */
7157 { 0x15, 0x01211420 }, /* HP2 */
7158 { 0x18, 0x01a19840 }, /* mic */
7159 { 0x19, 0x99a3094f }, /* int-mic */
7160 { 0x1b, 0x0121441f }, /* HP */
7161 { }
7162 },
7163 .chained = true,
7164 .chain_id = ALC662_FIXUP_SKU_IGNORE
7165 },
7166 [ALC662_FIXUP_ASUS_MODE7] = {
7167 .type = ALC_FIXUP_PINS,
7168 .v.pins = (const struct alc_pincfg[]) {
7169 { 0x14, 0x99130110 }, /* speaker */
7170 { 0x17, 0x99130111 }, /* speaker */
7171 { 0x18, 0x01a19840 }, /* mic */
7172 { 0x19, 0x99a3094f }, /* int-mic */
7173 { 0x1b, 0x01214020 }, /* HP */
7174 { 0x21, 0x0121401f }, /* HP */
7175 { }
7176 },
7177 .chained = true,
7178 .chain_id = ALC662_FIXUP_SKU_IGNORE
7179 },
7180 [ALC662_FIXUP_ASUS_MODE8] = {
7181 .type = ALC_FIXUP_PINS,
7182 .v.pins = (const struct alc_pincfg[]) {
7183 { 0x14, 0x99130110 }, /* speaker */
7184 { 0x12, 0x99a30970 }, /* int-mic */
7185 { 0x15, 0x01214020 }, /* HP */
7186 { 0x17, 0x99130111 }, /* speaker */
7187 { 0x18, 0x01a19840 }, /* mic */
7188 { 0x21, 0x0121401f }, /* HP */
7189 { }
7190 },
7191 .chained = true,
7192 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007193 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007194 [ALC662_FIXUP_NO_JACK_DETECT] = {
7195 .type = ALC_FIXUP_FUNC,
7196 .v.func = alc_fixup_no_jack_detect,
7197 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007198 [ALC662_FIXUP_ZOTAC_Z68] = {
7199 .type = ALC_FIXUP_PINS,
7200 .v.pins = (const struct alc_pincfg[]) {
7201 { 0x1b, 0x02214020 }, /* Front HP */
7202 { }
7203 }
7204 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007205 [ALC662_FIXUP_INV_DMIC] = {
7206 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007207 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007208 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007209};
7210
Takashi Iwaia9111322011-05-02 11:30:18 +02007211static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007212 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007213 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007214 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007215 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007216 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007217 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007218 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007219 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007220 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007221 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007222 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007223 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007224 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007225
7226#if 0
7227 /* Below is a quirk table taken from the old code.
7228 * Basically the device should work as is without the fixup table.
7229 * If BIOS doesn't give a proper info, enable the corresponding
7230 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007231 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007232 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7233 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7234 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7235 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7236 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7237 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7238 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7239 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7240 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7241 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7242 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7243 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7244 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7245 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7246 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7247 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7248 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7249 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7250 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7251 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7252 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7253 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7254 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7255 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7256 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7257 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7258 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7259 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7260 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7261 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7262 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7263 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7264 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7265 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7266 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7267 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7268 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7269 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7270 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7271 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7272 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7273 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7274 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7275 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7276 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7277 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7278 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7279 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7280 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7281 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7282#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007283 {}
7284};
7285
Todd Broch6be79482010-12-07 16:51:05 -08007286static const struct alc_model_fixup alc662_fixup_models[] = {
7287 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007288 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7289 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7290 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7291 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7292 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7293 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7294 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7295 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007296 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007297 {}
7298};
David Henningsson6cb3b702010-09-09 08:51:44 +02007299
Kailang Yang8663ff72012-06-29 09:35:52 +02007300static void alc662_fill_coef(struct hda_codec *codec)
7301{
7302 int val, coef;
7303
7304 coef = alc_get_coef0(codec);
7305
7306 switch (codec->vendor_id) {
7307 case 0x10ec0662:
7308 if ((coef & 0x00f0) == 0x0030) {
7309 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7310 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7311 }
7312 break;
7313 case 0x10ec0272:
7314 case 0x10ec0273:
7315 case 0x10ec0663:
7316 case 0x10ec0665:
7317 case 0x10ec0670:
7318 case 0x10ec0671:
7319 case 0x10ec0672:
7320 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7321 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7322 break;
7323 }
7324}
David Henningsson6cb3b702010-09-09 08:51:44 +02007325
Takashi Iwai1d045db2011-07-07 18:23:21 +02007326/*
7327 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007328static int patch_alc662(struct hda_codec *codec)
7329{
7330 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007331 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007332
Takashi Iwai3de95172012-05-07 18:03:15 +02007333 err = alc_alloc_spec(codec, 0x0b);
7334 if (err < 0)
7335 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007336
Takashi Iwai3de95172012-05-07 18:03:15 +02007337 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007338
Takashi Iwai53c334a2011-08-23 18:27:14 +02007339 /* handle multiple HPs as is */
7340 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7341
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007342 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7343
Kailang Yang8663ff72012-06-29 09:35:52 +02007344 spec->init_hook = alc662_fill_coef;
7345 alc662_fill_coef(codec);
7346
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007347 alc_pick_fixup(codec, alc662_fixup_models,
7348 alc662_fixup_tbl, alc662_fixups);
7349 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7350
7351 alc_auto_parse_customize_define(codec);
7352
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007353 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007354 codec->bus->pci->subsystem_vendor == 0x1025 &&
7355 spec->cdefine.platform_type == 1) {
7356 if (alc_codec_rename(codec, "ALC272X") < 0)
7357 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007358 }
Kailang Yang274693f2009-12-03 10:07:50 +01007359
Takashi Iwaib9c51062011-08-24 18:08:07 +02007360 /* automatic parse from the BIOS config */
7361 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007362 if (err < 0)
7363 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007364
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007365 if (!spec->no_analog && has_cdefine_beep(codec)) {
7366 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007367 if (err < 0)
7368 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007369 switch (codec->vendor_id) {
7370 case 0x10ec0662:
7371 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7372 break;
7373 case 0x10ec0272:
7374 case 0x10ec0663:
7375 case 0x10ec0665:
7376 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7377 break;
7378 case 0x10ec0273:
7379 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7380 break;
7381 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007382 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007383
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007384 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02007385 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007386
Takashi Iwai589876e2012-02-20 15:47:55 +01007387 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7388
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007389 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007390
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007391 error:
7392 alc_free(codec);
7393 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007394}
7395
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007396/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007397 * ALC680 support
7398 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007399
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007400static int alc680_parse_auto_config(struct hda_codec *codec)
7401{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007402 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007403}
7404
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007405/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007406 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007407static int patch_alc680(struct hda_codec *codec)
7408{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007409 int err;
7410
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007411 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007412 err = alc_alloc_spec(codec, 0);
7413 if (err < 0)
7414 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007415
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007416 /* automatic parse from the BIOS config */
7417 err = alc680_parse_auto_config(codec);
7418 if (err < 0) {
7419 alc_free(codec);
7420 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007421 }
7422
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007423 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007424
7425 return 0;
7426}
7427
7428/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007429 * patch entries
7430 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007431static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007432 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007433 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007434 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007435 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007436 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007437 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007438 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007439 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007440 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007441 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007442 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007443 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007444 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007445 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007446 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007447 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007448 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007449 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007450 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7451 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7452 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007453 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007454 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007455 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7456 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007457 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7458 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007459 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007460 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007461 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007462 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007463 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007464 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007465 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007466 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007467 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007468 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007469 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007470 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007471 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007472 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007473 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007474 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007475 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007476 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007477 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007478 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007479 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007480 {} /* terminator */
7481};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007482
7483MODULE_ALIAS("snd-hda-codec-id:10ec*");
7484
7485MODULE_LICENSE("GPL");
7486MODULE_DESCRIPTION("Realtek HD-audio codec");
7487
7488static struct hda_codec_preset_list realtek_list = {
7489 .preset = snd_hda_preset_realtek,
7490 .owner = THIS_MODULE,
7491};
7492
7493static int __init patch_realtek_init(void)
7494{
7495 return snd_hda_add_codec_preset(&realtek_list);
7496}
7497
7498static void __exit patch_realtek_exit(void)
7499{
7500 snd_hda_delete_codec_preset(&realtek_list);
7501}
7502
7503module_init(patch_realtek_init)
7504module_exit(patch_realtek_exit)