blob: 1ec14ac24232a87169bb19552937a39d05a86af5 [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 Iwai1c716152011-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 Iwaia9fd4f32009-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 Iwaia9fd4f32009-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 Iwai1c716152011-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 Iwai1c716152011-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 Iwai1c716152011-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;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002642 unsigned int val;
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002643 int err, idx;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002644
Takashi Iwaibd32f782012-12-12 18:08:52 +01002645 if (!nid_has_volume(codec, mix_nid, HDA_INPUT) &&
2646 !nid_has_mute(codec, mix_nid, HDA_INPUT))
2647 return 0; /* no need for analog loopback */
2648
Takashi Iwaic9967f12012-12-14 16:39:22 +01002649 path = snd_array_new(&spec->paths);
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002650 if (!path)
2651 return -ENOMEM;
2652 memset(path, 0, sizeof(*path));
2653 if (!parse_nid_path(codec, pin, mix_nid, 2, path))
2654 return -EINVAL;
2655
2656 idx = path->idx[path->depth - 1];
Takashi Iwaibd32f782012-12-12 18:08:52 +01002657 if (nid_has_volume(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002658 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2659 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002660 if (err < 0)
2661 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002662 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002663 }
2664
2665 if (nid_has_mute(codec, mix_nid, HDA_INPUT)) {
Takashi Iwai829f69e2012-12-14 18:26:02 +01002666 val = HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT);
2667 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx, val);
Takashi Iwaibd32f782012-12-12 18:08:52 +01002668 if (err < 0)
2669 return err;
Takashi Iwai829f69e2012-12-14 18:26:02 +01002670 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwaibd32f782012-12-12 18:08:52 +01002671 }
2672
Takashi Iwai829f69e2012-12-14 18:26:02 +01002673 path->active = true;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002674 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002675 return 0;
2676}
2677
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002678static int new_capture_source(struct hda_codec *codec, int adc_idx,
2679 hda_nid_t pin, int idx, const char *label)
2680{
2681 struct alc_spec *spec = codec->spec;
2682 struct hda_input_mux *imux = &spec->private_imux[0];
2683 struct nid_path *path;
2684
Takashi Iwaic9967f12012-12-14 16:39:22 +01002685 path = snd_array_new(&spec->paths);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002686 if (!path)
2687 return -ENOMEM;
2688 memset(path, 0, sizeof(*path));
2689 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2690 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2691 pin, spec->adc_nids[adc_idx]);
2692 return -EINVAL;
2693 }
2694
2695 spec->imux_pins[imux->num_items] = pin;
2696 snd_hda_add_imux_item(imux, label, idx, NULL);
2697 return 0;
2698}
2699
Takashi Iwai05f5f472009-08-25 13:10:18 +02002700static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002701{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002702 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2703 return (pincap & AC_PINCAP_IN) != 0;
2704}
2705
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002706/* check whether the given two widgets can be connected */
2707static bool is_reachable_path(struct hda_codec *codec,
2708 hda_nid_t from_nid, hda_nid_t to_nid)
2709{
2710 if (!from_nid || !to_nid)
2711 return false;
2712 return snd_hda_get_conn_index(codec, to_nid, from_nid, true) >= 0;
2713}
2714
Takashi Iwai1d045db2011-07-07 18:23:21 +02002715/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002716static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002717{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002718 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002719 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002720 hda_nid_t *adc_nids = spec->private_adc_nids;
2721 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2722 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002723 int i, nums = 0;
2724
2725 nid = codec->start_nid;
2726 for (i = 0; i < codec->num_nodes; i++, nid++) {
2727 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002728 unsigned int caps = get_wcaps(codec, nid);
2729 int type = get_wcaps_type(caps);
2730
2731 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2732 continue;
2733 adc_nids[nums] = nid;
2734 cap_nids[nums] = nid;
2735 src = nid;
2736 for (;;) {
2737 int n;
2738 type = get_wcaps_type(get_wcaps(codec, src));
2739 if (type == AC_WID_PIN)
2740 break;
2741 if (type == AC_WID_AUD_SEL) {
2742 cap_nids[nums] = src;
2743 break;
2744 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002745 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 if (n > 1) {
2747 cap_nids[nums] = src;
2748 break;
2749 } else if (n != 1)
2750 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002751 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2752 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002753 }
2754 if (++nums >= max_nums)
2755 break;
2756 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002757 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002758 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002759 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002760 return nums;
2761}
2762
Takashi Iwai05f5f472009-08-25 13:10:18 +02002763/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002764static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002765{
2766 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002767 const struct auto_pin_cfg *cfg = &spec->autocfg;
2768 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002769 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002770 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002771 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002772 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002773
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002774 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002775 if (num_adcs < 0)
2776 return 0;
2777
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002778 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002779 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002780 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002781
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002782 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002783 if (!alc_is_input_pin(codec, pin))
2784 continue;
2785
David Henningsson5322bf22011-01-05 11:03:56 +01002786 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002787 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2788 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002789 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002790 type_idx++;
2791 else
2792 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002793 prev_label = label;
2794
Takashi Iwai05f5f472009-08-25 13:10:18 +02002795 if (mixer) {
Takashi Iwaic2fd19c2012-12-12 18:02:41 +01002796 if (is_reachable_path(codec, pin, mixer)) {
2797 err = new_analog_input(codec, pin,
2798 label, type_idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002799 if (err < 0)
2800 return err;
2801 }
2802 }
2803
Takashi Iwaib7821702011-07-06 15:12:46 +02002804 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002805 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002806 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002807 if (idx >= 0) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002808 err = new_capture_source(codec, c, pin, idx, label);
2809 if (err < 0)
2810 return err;
Takashi Iwaib7821702011-07-06 15:12:46 +02002811 break;
2812 }
2813 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002814 }
Takashi Iwai21268962011-07-07 15:01:13 +02002815
2816 spec->num_mux_defs = 1;
2817 spec->input_mux = imux;
2818
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002819 return 0;
2820}
2821
Takashi Iwai24de1832011-11-07 17:13:39 +01002822/* create a shared input with the headphone out */
2823static int alc_auto_create_shared_input(struct hda_codec *codec)
2824{
2825 struct alc_spec *spec = codec->spec;
2826 struct auto_pin_cfg *cfg = &spec->autocfg;
2827 unsigned int defcfg;
2828 hda_nid_t nid;
2829
2830 /* only one internal input pin? */
2831 if (cfg->num_inputs != 1)
2832 return 0;
2833 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2834 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2835 return 0;
2836
2837 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2838 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2839 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2840 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2841 else
2842 return 0; /* both not available */
2843
2844 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2845 return 0; /* no input */
2846
2847 cfg->inputs[1].pin = nid;
2848 cfg->inputs[1].type = AUTO_PIN_MIC;
2849 cfg->num_inputs = 2;
2850 spec->shared_mic_hp = 1;
2851 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2852 return 0;
2853}
2854
Takashi Iwai829f69e2012-12-14 18:26:02 +01002855static struct nid_path *
2856get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid);
2857static void activate_path(struct hda_codec *codec, struct nid_path *path,
2858 bool enable);
2859
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002860static int get_pin_type(int line_out_type)
2861{
2862 if (line_out_type == AUTO_PIN_HP_OUT)
2863 return PIN_HP;
2864 else
2865 return PIN_OUT;
2866}
2867
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002868static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002869{
2870 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002871 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002872 int i;
2873
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002874 for (i = 0; i < cfg->num_inputs; i++) {
2875 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002876 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002877 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002878 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002879 snd_hda_codec_write(codec, nid, 0,
2880 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002881 AMP_OUT_MUTE);
2882 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002883
Takashi Iwai829f69e2012-12-14 18:26:02 +01002884 /* mute loopback inputs */
2885 if (spec->mixer_nid) {
2886 struct nid_path *path;
2887 path = get_nid_path(codec, nid, spec->mixer_nid);
2888 if (path)
2889 activate_path(codec, path, path->active);
2890 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002891 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002892}
2893
Takashi Iwai185d99f2012-02-16 18:39:45 +01002894static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2895{
2896 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002897 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002898
Takashi Iwaic9967f12012-12-14 16:39:22 +01002899 for (i = 0; i < spec->paths.used; i++) {
2900 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002901 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002902 return true;
2903 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002904 return false;
2905}
2906
Takashi Iwai463419d2012-12-05 14:17:37 +01002907/* look for an empty DAC slot */
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002908static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin,
2909 bool is_digital)
Takashi Iwai463419d2012-12-05 14:17:37 +01002910{
2911 struct alc_spec *spec = codec->spec;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002912 bool cap_digital;
Takashi Iwai463419d2012-12-05 14:17:37 +01002913 int i;
2914
2915 for (i = 0; i < spec->num_all_dacs; i++) {
2916 hda_nid_t nid = spec->all_dacs[i];
2917 if (!nid || alc_is_dac_already_used(codec, nid))
2918 continue;
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01002919 cap_digital = !!(get_wcaps(codec, nid) & AC_WCAP_DIGITAL);
2920 if (is_digital != cap_digital)
2921 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01002922 if (is_reachable_path(codec, nid, pin))
Takashi Iwai463419d2012-12-05 14:17:37 +01002923 return nid;
2924 }
2925 return 0;
2926}
2927
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002928/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002929static bool __parse_nid_path(struct hda_codec *codec,
2930 hda_nid_t from_nid, hda_nid_t to_nid,
2931 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002932{
2933 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002934 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002935 int i, nums;
2936
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002937 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002938 if (!with_aa_mix)
2939 return false;
2940 with_aa_mix = 2; /* mark aa-mix is included */
2941 }
2942
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002943 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002944 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002945 if (conn[i] != from_nid) {
2946 /* special case: when from_nid is 0,
2947 * try to find an empty DAC
2948 */
2949 if (from_nid ||
2950 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2951 alc_is_dac_already_used(codec, conn[i]))
2952 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002953 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002954 /* aa-mix is requested but not included? */
2955 if (!(spec->mixer_nid && with_aa_mix == 1))
2956 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002957 }
2958 if (depth >= MAX_NID_PATH_DEPTH)
2959 return false;
2960 for (i = 0; i < nums; i++) {
2961 unsigned int type;
2962 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002963 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2964 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002965 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002966 if (__parse_nid_path(codec, from_nid, conn[i],
2967 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002968 goto found;
2969 }
2970 return false;
2971
2972 found:
2973 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002974 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002975 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002976 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002977 path->depth++;
2978 return true;
2979}
2980
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002981/* parse the widget path from the given nid to the target nid;
2982 * when @from_nid is 0, try to find an empty DAC;
2983 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2984 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2985 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002986 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002987static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2988 hda_nid_t to_nid, int with_aa_mix,
2989 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002990{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002991 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2992 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002993 path->depth++;
2994#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002995 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002996 path->depth, path->path[0], path->path[1],
2997 path->path[2], path->path[3], path->path[4]);
2998#endif
2999 return true;
3000 }
3001 return false;
3002}
3003
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003004static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3005{
Takashi Iwai140547e2012-02-16 17:23:46 +01003006 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01003007 int i;
3008 hda_nid_t nid_found = 0;
3009
3010 for (i = 0; i < spec->num_all_dacs; i++) {
3011 hda_nid_t nid = spec->all_dacs[i];
3012 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003013 continue;
Takashi Iwai9c640762012-12-14 16:15:56 +01003014 if (is_reachable_path(codec, nid, pin)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003015 if (nid_found)
3016 return 0;
3017 nid_found = nid;
3018 }
3019 }
3020 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003021}
3022
Takashi Iwaiba8111272012-12-06 18:06:23 +01003023static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003024{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003025 struct alc_spec *spec = codec->spec;
3026 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003027
Takashi Iwaic9967f12012-12-14 16:39:22 +01003028 for (i = 0; i < spec->paths.used; i++) {
3029 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003030 if (path->ctls[type] == val)
3031 return true;
3032 }
3033 return false;
3034}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003035
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003036/* badness definition */
3037enum {
3038 /* No primary DAC is found for the main output */
3039 BAD_NO_PRIMARY_DAC = 0x10000,
3040 /* No DAC is found for the extra output */
3041 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003042 /* No possible multi-ios */
3043 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003044 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003045 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003046 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003047 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003048 /* Primary DAC shared with main surrounds */
3049 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003050 /* Primary DAC shared with main CLFE */
3051 BAD_SHARED_CLFE = 0x10,
3052 /* Primary DAC shared with extra surrounds */
3053 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003054 /* Volume widget is shared */
3055 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003056};
3057
3058static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003059 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003060static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003061 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003062
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003063static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3064 hda_nid_t dac)
3065{
3066 struct alc_spec *spec = codec->spec;
3067 struct nid_path *path;
3068
Takashi Iwaic9967f12012-12-14 16:39:22 +01003069 path = snd_array_new(&spec->paths);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003070 if (!path)
3071 return false;
3072 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003073 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003074 return true;
3075 /* push back */
Takashi Iwaic9967f12012-12-14 16:39:22 +01003076 spec->paths.used--;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003077 return false;
3078}
3079
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003080/* get the path between the given NIDs;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003081 * passing 0 to either @pin or @dac behaves as a wildcard
3082 */
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003083static struct nid_path *
3084get_nid_path(struct hda_codec *codec, hda_nid_t from_nid, hda_nid_t to_nid)
Takashi Iwaiba8111272012-12-06 18:06:23 +01003085{
3086 struct alc_spec *spec = codec->spec;
3087 int i;
3088
Takashi Iwaic9967f12012-12-14 16:39:22 +01003089 for (i = 0; i < spec->paths.used; i++) {
3090 struct nid_path *path = snd_array_elem(&spec->paths, i);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003091 if (path->depth <= 0)
3092 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003093 if ((!from_nid || path->path[0] == from_nid) &&
3094 (!to_nid || path->path[path->depth - 1] == to_nid))
Takashi Iwaiba8111272012-12-06 18:06:23 +01003095 return path;
3096 }
3097 return NULL;
3098}
3099
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003100/* look for widgets in the path between the given NIDs appropriate for
3101 * volume and mute controls, and assign the values to ctls[].
3102 *
3103 * When no appropriate widget is found in the path, the badness value
3104 * is incremented depending on the situation. The function returns the
3105 * total badness for both volume and mute controls.
3106 */
3107static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3108 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003109{
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003110 struct nid_path *path = get_nid_path(codec, dac, pin);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003111 hda_nid_t nid;
3112 unsigned int val;
3113 int badness = 0;
3114
Takashi Iwaiba8111272012-12-06 18:06:23 +01003115 if (!path)
3116 return BAD_SHARED_VOL * 2;
3117 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003118 if (nid) {
3119 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003120 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003121 badness += BAD_SHARED_VOL;
3122 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003123 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003124 } else
3125 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003126 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003127 if (nid) {
3128 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003129 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3130 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003131 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3132 else
3133 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003134 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003135 badness += BAD_SHARED_VOL;
3136 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003137 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003138 } else
3139 badness += BAD_SHARED_VOL;
3140 return badness;
3141}
3142
Takashi Iwaidc31b582012-02-17 17:27:53 +01003143struct badness_table {
3144 int no_primary_dac; /* no primary DAC */
3145 int no_dac; /* no secondary DACs */
3146 int shared_primary; /* primary DAC is shared with main output */
3147 int shared_surr; /* secondary DAC shared with main or primary */
3148 int shared_clfe; /* third DAC shared with main or primary */
3149 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3150};
3151
3152static struct badness_table main_out_badness = {
3153 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3154 .no_dac = BAD_NO_DAC,
3155 .shared_primary = BAD_NO_PRIMARY_DAC,
3156 .shared_surr = BAD_SHARED_SURROUND,
3157 .shared_clfe = BAD_SHARED_CLFE,
3158 .shared_surr_main = BAD_SHARED_SURROUND,
3159};
3160
3161static struct badness_table extra_out_badness = {
3162 .no_primary_dac = BAD_NO_DAC,
3163 .no_dac = BAD_NO_DAC,
3164 .shared_primary = BAD_NO_EXTRA_DAC,
3165 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3166 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3167 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3168};
3169
3170/* try to assign DACs to pins and return the resultant badness */
3171static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3172 const hda_nid_t *pins, hda_nid_t *dacs,
3173 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003174{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003175 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003176 struct auto_pin_cfg *cfg = &spec->autocfg;
3177 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003178 int badness = 0;
3179 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003180
Takashi Iwai185d99f2012-02-16 18:39:45 +01003181 if (!num_outs)
3182 return 0;
3183
Takashi Iwaidc31b582012-02-17 17:27:53 +01003184 for (i = 0; i < num_outs; i++) {
3185 hda_nid_t pin = pins[i];
3186 if (!dacs[i])
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01003187 dacs[i] = alc_auto_look_for_dac(codec, pin, false);
Takashi Iwaidc31b582012-02-17 17:27:53 +01003188 if (!dacs[i] && !i) {
3189 for (j = 1; j < num_outs; j++) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003190 if (is_reachable_path(codec, dacs[j], pin)) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003191 dacs[0] = dacs[j];
3192 dacs[j] = 0;
3193 break;
3194 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003195 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003196 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003197 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003198 if (!dac) {
Takashi Iwai9c640762012-12-14 16:15:56 +01003199 if (is_reachable_path(codec, dacs[0], pin))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003200 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003201 else if (cfg->line_outs > i &&
Takashi Iwai9c640762012-12-14 16:15:56 +01003202 is_reachable_path(codec, spec->private_dac_nids[i], pin))
Takashi Iwaidc31b582012-02-17 17:27:53 +01003203 dac = spec->private_dac_nids[i];
3204 if (dac) {
3205 if (!i)
3206 badness += bad->shared_primary;
3207 else if (i == 1)
3208 badness += bad->shared_surr;
3209 else
3210 badness += bad->shared_clfe;
Takashi Iwai9c640762012-12-14 16:15:56 +01003211 } else if (is_reachable_path(codec, spec->private_dac_nids[0], pin)) {
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003212 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003213 badness += bad->shared_surr_main;
3214 } else if (!i)
3215 badness += bad->no_primary_dac;
3216 else
3217 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003218 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003219 if (!add_new_out_path(codec, pin, dac))
3220 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003221 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003222 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003223 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003224
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003225 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003226}
3227
3228static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003229 hda_nid_t reference_pin,
3230 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003231
Takashi Iwai185d99f2012-02-16 18:39:45 +01003232static bool alc_map_singles(struct hda_codec *codec, int outs,
3233 const hda_nid_t *pins, hda_nid_t *dacs)
3234{
3235 int i;
3236 bool found = false;
3237 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003238 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003239 if (dacs[i])
3240 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003241 dac = get_dac_if_single(codec, pins[i]);
3242 if (!dac)
3243 continue;
3244 if (add_new_out_path(codec, pins[i], dac)) {
3245 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003246 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003247 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003248 }
3249 return found;
3250}
3251
Takashi Iwai7085ec12009-10-02 09:03:58 +02003252/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003253static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003254 bool fill_hardwired,
3255 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003256{
3257 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003258 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003259 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003260
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003261 /* set num_dacs once to full for alc_auto_look_for_dac() */
3262 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003263 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003264 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3265 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3266 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003267 spec->multi_ios = 0;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003268 snd_array_free(&spec->paths);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003269 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003270
3271 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003272 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003273 bool mapped;
3274 do {
3275 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003276 cfg->line_out_pins,
3277 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003278 mapped |= alc_map_singles(codec, cfg->hp_outs,
3279 cfg->hp_pins,
3280 spec->multiout.hp_out_nid);
3281 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3282 cfg->speaker_pins,
3283 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003284 if (fill_mio_first && cfg->line_outs == 1 &&
3285 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3286 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3287 if (!err)
3288 mapped = true;
3289 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003290 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003291 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003292
Takashi Iwaidc31b582012-02-17 17:27:53 +01003293 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3294 spec->private_dac_nids,
3295 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003296
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003297 /* re-count num_dacs and squash invalid entries */
3298 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003299 for (i = 0; i < cfg->line_outs; i++) {
3300 if (spec->private_dac_nids[i])
3301 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003302 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003303 memmove(spec->private_dac_nids + i,
3304 spec->private_dac_nids + i + 1,
3305 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003306 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3307 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003308 }
3309
Takashi Iwai276dd702012-02-17 16:17:03 +01003310 if (fill_mio_first &&
3311 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003312 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003313 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003314 if (err < 0)
3315 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003316 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003317 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003318
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003319 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003320 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3321 spec->multiout.hp_out_nid,
3322 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003323 if (err < 0)
3324 return err;
3325 badness += err;
3326 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003327 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003328 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3329 cfg->speaker_pins,
3330 spec->multiout.extra_out_nid,
3331 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003332 if (err < 0)
3333 return err;
3334 badness += err;
3335 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003336 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3337 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003338 if (err < 0)
3339 return err;
3340 badness += err;
3341 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003342 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3343 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003344 int offset = 0;
3345 if (cfg->line_outs >= 3)
3346 offset = 1;
3347 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3348 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003349 if (err < 0)
3350 return err;
3351 badness += err;
3352 }
3353
3354 if (spec->multi_ios == 2) {
3355 for (i = 0; i < 2; i++)
3356 spec->private_dac_nids[spec->multiout.num_dacs++] =
3357 spec->multi_io[i].dac;
3358 spec->ext_channel_count = 2;
3359 } else if (spec->multi_ios) {
3360 spec->multi_ios = 0;
3361 badness += BAD_MULTI_IO;
3362 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003363
3364 return badness;
3365}
3366
3367#define DEBUG_BADNESS
3368
3369#ifdef DEBUG_BADNESS
3370#define debug_badness snd_printdd
3371#else
3372#define debug_badness(...)
3373#endif
3374
3375static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3376{
3377 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3378 cfg->line_out_pins[0], cfg->line_out_pins[1],
3379 cfg->line_out_pins[2], cfg->line_out_pins[2],
3380 spec->multiout.dac_nids[0],
3381 spec->multiout.dac_nids[1],
3382 spec->multiout.dac_nids[2],
3383 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003384 if (spec->multi_ios > 0)
3385 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3386 spec->multi_ios,
3387 spec->multi_io[0].pin, spec->multi_io[1].pin,
3388 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003389 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3390 cfg->hp_pins[0], cfg->hp_pins[1],
3391 cfg->hp_pins[2], cfg->hp_pins[2],
3392 spec->multiout.hp_out_nid[0],
3393 spec->multiout.hp_out_nid[1],
3394 spec->multiout.hp_out_nid[2],
3395 spec->multiout.hp_out_nid[3]);
3396 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3397 cfg->speaker_pins[0], cfg->speaker_pins[1],
3398 cfg->speaker_pins[2], cfg->speaker_pins[3],
3399 spec->multiout.extra_out_nid[0],
3400 spec->multiout.extra_out_nid[1],
3401 spec->multiout.extra_out_nid[2],
3402 spec->multiout.extra_out_nid[3]);
3403}
3404
Takashi Iwai463419d2012-12-05 14:17:37 +01003405/* find all available DACs of the codec */
3406static void alc_fill_all_nids(struct hda_codec *codec)
3407{
3408 struct alc_spec *spec = codec->spec;
3409 int i;
3410 hda_nid_t nid = codec->start_nid;
3411
3412 spec->num_all_dacs = 0;
3413 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3414 for (i = 0; i < codec->num_nodes; i++, nid++) {
3415 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3416 continue;
3417 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3418 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3419 break;
3420 }
3421 spec->all_dacs[spec->num_all_dacs++] = nid;
3422 }
3423}
3424
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003425static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3426{
3427 struct alc_spec *spec = codec->spec;
3428 struct auto_pin_cfg *cfg = &spec->autocfg;
3429 struct auto_pin_cfg *best_cfg;
3430 int best_badness = INT_MAX;
3431 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003432 bool fill_hardwired = true, fill_mio_first = true;
3433 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003434 bool hp_spk_swapped = false;
3435
Takashi Iwai463419d2012-12-05 14:17:37 +01003436 alc_fill_all_nids(codec);
3437
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003438 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3439 if (!best_cfg)
3440 return -ENOMEM;
3441 *best_cfg = *cfg;
3442
3443 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003444 badness = fill_and_eval_dacs(codec, fill_hardwired,
3445 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003446 if (badness < 0) {
3447 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003448 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003449 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003450 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3451 cfg->line_out_type, fill_hardwired, fill_mio_first,
3452 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003453 debug_show_configs(spec, cfg);
3454 if (badness < best_badness) {
3455 best_badness = badness;
3456 *best_cfg = *cfg;
3457 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003458 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003459 }
3460 if (!badness)
3461 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003462 fill_mio_first = !fill_mio_first;
3463 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003464 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003465 fill_hardwired = !fill_hardwired;
3466 if (!fill_hardwired)
3467 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003468 if (hp_spk_swapped)
3469 break;
3470 hp_spk_swapped = true;
3471 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003472 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3473 cfg->hp_outs = cfg->line_outs;
3474 memcpy(cfg->hp_pins, cfg->line_out_pins,
3475 sizeof(cfg->hp_pins));
3476 cfg->line_outs = cfg->speaker_outs;
3477 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3478 sizeof(cfg->speaker_pins));
3479 cfg->speaker_outs = 0;
3480 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3481 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003482 fill_hardwired = true;
3483 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003484 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003485 if (cfg->hp_outs > 0 &&
3486 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3487 cfg->speaker_outs = cfg->line_outs;
3488 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3489 sizeof(cfg->speaker_pins));
3490 cfg->line_outs = cfg->hp_outs;
3491 memcpy(cfg->line_out_pins, cfg->hp_pins,
3492 sizeof(cfg->hp_pins));
3493 cfg->hp_outs = 0;
3494 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3495 cfg->line_out_type = AUTO_PIN_HP_OUT;
3496 fill_hardwired = true;
3497 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003498 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003499 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003500 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003501
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003502 if (badness) {
3503 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003504 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003505 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003506 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3507 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003508 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003509
Takashi Iwaiba8111272012-12-06 18:06:23 +01003510 if (cfg->line_out_pins[0]) {
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003511 struct nid_path *path = get_nid_path(codec,
3512 spec->multiout.dac_nids[0],
3513 cfg->line_out_pins[0]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003514 if (path)
3515 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3516 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003517
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003518 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003519 return 0;
3520}
3521
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003522/* replace the channels in the composed amp value with the given number */
3523static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3524{
3525 val &= ~(0x3U << 16);
3526 val |= chs << 16;
3527 return val;
3528}
3529
Takashi Iwai343a04b2011-07-06 14:28:39 +02003530static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003531 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003532 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003533 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003534{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003535 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003536 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003537 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003538 val = path->ctls[NID_PATH_VOL_CTL];
3539 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003540 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003541 val = amp_val_replace_channels(val, chs);
3542 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3543}
3544
3545/* return the channel bits suitable for the given path->ctls[] */
3546static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3547 int type)
3548{
3549 int chs = 1; /* mono (left only) */
3550 if (path) {
3551 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3552 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3553 chs = 3; /* stereo */
3554 }
3555 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003556}
3557
Takashi Iwaie29d3772011-11-14 17:13:23 +01003558static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3559 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003560 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003561{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003562 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3563 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003564}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003565
3566/* create a mute-switch for the given mixer widget;
3567 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3568 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003569static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003570 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003571 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003572 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003573{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003574 unsigned int val;
3575 int type = ALC_CTL_WIDGET_MUTE;
3576
3577 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003578 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003579 val = path->ctls[NID_PATH_MUTE_CTL];
3580 if (!val)
3581 return 0;
3582 val = amp_val_replace_channels(val, chs);
3583 if (get_amp_direction_(val) == HDA_INPUT) {
3584 hda_nid_t nid = get_amp_nid_(val);
Takashi Iwai9366ede2012-12-13 16:43:52 +01003585 int nums = snd_hda_get_num_conns(codec, nid);
3586 if (nums > 1) {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003587 type = ALC_CTL_BIND_MUTE;
Takashi Iwai9366ede2012-12-13 16:43:52 +01003588 val |= nums << 19;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003589 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003590 }
3591 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003592}
3593
Takashi Iwaie29d3772011-11-14 17:13:23 +01003594static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003595 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003596{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003597 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3598 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003599}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003600
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003601static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003602 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003603{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003604 int i;
3605
3606 for (i = path->depth - 1; i >= 0; i--) {
3607 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3608 return path->path[i];
3609 if (i != path->depth - 1 && i != 0 &&
3610 nid_has_mute(codec, path->path[i], HDA_INPUT))
3611 return path->path[i];
3612 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003613 return 0;
3614}
3615
3616static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003617 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003618{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003619 int i;
3620
3621 for (i = path->depth - 1; i >= 0; i--) {
3622 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3623 return path->path[i];
3624 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003625 return 0;
3626}
3627
Takashi Iwai7085ec12009-10-02 09:03:58 +02003628/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003629static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003630 const struct auto_pin_cfg *cfg)
3631{
3632 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003633 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003634
Takashi Iwaice764ab2011-04-27 16:35:23 +02003635 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003636 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003637 noutputs += spec->multi_ios;
3638
3639 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003640 const char *name;
3641 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003642 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003643 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003644
3645 dac = spec->multiout.dac_nids[i];
3646 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003647 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003648 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003649 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003650 index = 0;
3651 name = channel_name[i];
3652 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003653 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003654 name = alc_get_line_out_pfx(spec, i, true, &index);
3655 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003656
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003657 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003658 if (!path)
3659 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003660 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003661 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003662 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003663 if (err < 0)
3664 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003665 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003666 if (err < 0)
3667 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003668 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003669 if (err < 0)
3670 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003671 err = alc_auto_add_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003672 if (err < 0)
3673 return err;
3674 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003675 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003676 if (err < 0)
3677 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003678 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003679 if (err < 0)
3680 return err;
3681 }
3682 }
3683 return 0;
3684}
3685
Takashi Iwai343a04b2011-07-06 14:28:39 +02003686static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003687 hda_nid_t dac, const char *pfx,
3688 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003689{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003690 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003691 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003692
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003693 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003694 if (!path)
3695 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003696 /* bind volume control will be created in the case of dac = 0 */
3697 if (dac) {
3698 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3699 if (err < 0)
3700 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003701 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003702 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003703 if (err < 0)
3704 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003705 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003706}
3707
Takashi Iwai23c09b02011-08-19 09:05:35 +02003708static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3709 unsigned int nums,
3710 struct hda_ctl_ops *ops)
3711{
3712 struct alc_spec *spec = codec->spec;
3713 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003714 ctlp = snd_array_new(&spec->bind_ctls);
3715 if (!ctlp)
3716 return NULL;
3717 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3718 *ctlp = ctl;
3719 if (ctl)
3720 ctl->ops = ops;
3721 return ctl;
3722}
3723
3724/* add playback controls for speaker and HP outputs */
3725static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3726 const hda_nid_t *pins,
3727 const hda_nid_t *dacs,
3728 const char *pfx)
3729{
3730 struct alc_spec *spec = codec->spec;
3731 struct hda_bind_ctls *ctl;
3732 char name[32];
3733 int i, n, err;
3734
3735 if (!num_pins || !pins[0])
3736 return 0;
3737
Takashi Iwai527e4d72011-10-27 16:33:27 +02003738 if (num_pins == 1) {
3739 hda_nid_t dac = *dacs;
3740 if (!dac)
3741 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003742 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003743 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003744
Takashi Iwai23c09b02011-08-19 09:05:35 +02003745 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003746 hda_nid_t dac;
3747 if (dacs[num_pins - 1])
3748 dac = dacs[i]; /* with individual volumes */
3749 else
3750 dac = 0;
3751 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3752 err = alc_auto_create_extra_out(codec, pins[i], dac,
3753 "Bass Speaker", 0);
3754 } else if (num_pins >= 3) {
3755 snprintf(name, sizeof(name), "%s %s",
3756 pfx, channel_name[i]);
3757 err = alc_auto_create_extra_out(codec, pins[i], dac,
3758 name, 0);
3759 } else {
3760 err = alc_auto_create_extra_out(codec, pins[i], dac,
3761 pfx, i);
3762 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003763 if (err < 0)
3764 return err;
3765 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003766 if (dacs[num_pins - 1])
3767 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003768
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003769 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003770 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3771 if (!ctl)
3772 return -ENOMEM;
3773 n = 0;
3774 for (i = 0; i < num_pins; i++) {
3775 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003776 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003777 if (!pins[i] || !dacs[i])
3778 continue;
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003779 path = get_nid_path(codec, dacs[i], pins[i]);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003780 if (!path)
3781 continue;
3782 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003783 if (vol)
3784 ctl->values[n++] =
3785 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3786 }
3787 if (n) {
3788 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3789 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3790 if (err < 0)
3791 return err;
3792 }
3793 return 0;
3794}
3795
Takashi Iwai343a04b2011-07-06 14:28:39 +02003796static int alc_auto_create_hp_out(struct hda_codec *codec)
3797{
3798 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003799 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3800 spec->autocfg.hp_pins,
3801 spec->multiout.hp_out_nid,
3802 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003803}
3804
3805static int alc_auto_create_speaker_out(struct hda_codec *codec)
3806{
3807 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003808 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3809 spec->autocfg.speaker_pins,
3810 spec->multiout.extra_out_nid,
3811 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003812}
3813
Takashi Iwai130e5f02012-12-14 16:09:29 +01003814/* check whether a control with the given (nid, dir, idx) was assigned */
3815static bool is_ctl_associated(struct hda_codec *codec, hda_nid_t nid,
3816 int dir, int idx)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003817{
Takashi Iwai130e5f02012-12-14 16:09:29 +01003818 struct alc_spec *spec = codec->spec;
Takashi Iwaic9967f12012-12-14 16:39:22 +01003819 int i, type;
3820
3821 for (i = 0; i < spec->paths.used; i++) {
3822 struct nid_path *p = snd_array_elem(&spec->paths, i);
3823 if (p->depth <= 0)
3824 continue;
Takashi Iwai8dd48672012-12-14 18:19:04 +01003825 for (type = 0; type < NID_PATH_NUM_CTLS; type++) {
Takashi Iwaic9967f12012-12-14 16:39:22 +01003826 unsigned int val = p->ctls[type];
3827 if (get_amp_nid_(val) == nid &&
3828 get_amp_direction_(val) == dir &&
3829 get_amp_index_(val) == idx)
3830 return true;
3831 }
3832 }
3833 return false;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003834}
3835
3836/* can have the amp-in capability? */
3837static bool has_amp_in(struct hda_codec *codec, struct nid_path *path, int idx)
3838{
3839 hda_nid_t nid = path->path[idx];
3840 unsigned int caps = get_wcaps(codec, nid);
3841 unsigned int type = get_wcaps_type(caps);
3842
3843 if (!(caps & AC_WCAP_IN_AMP))
3844 return false;
3845 if (type == AC_WID_PIN && idx > 0) /* only for input pins */
3846 return false;
3847 return true;
3848}
3849
3850/* can have the amp-out capability? */
3851static bool has_amp_out(struct hda_codec *codec, struct nid_path *path, int idx)
3852{
3853 hda_nid_t nid = path->path[idx];
3854 unsigned int caps = get_wcaps(codec, nid);
3855 unsigned int type = get_wcaps_type(caps);
3856
3857 if (!(caps & AC_WCAP_OUT_AMP))
3858 return false;
3859 if (type == AC_WID_PIN && !idx) /* only for output pins */
3860 return false;
3861 return true;
3862}
3863
Takashi Iwaic9967f12012-12-14 16:39:22 +01003864/* check whether the given (nid,dir,idx) is active */
3865static bool is_active_nid(struct hda_codec *codec, hda_nid_t nid,
3866 unsigned int idx, unsigned int dir)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003867{
Takashi Iwaic9967f12012-12-14 16:39:22 +01003868 struct alc_spec *spec = codec->spec;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003869 int i, n;
3870
Takashi Iwaic9967f12012-12-14 16:39:22 +01003871 for (n = 0; n < spec->paths.used; n++) {
3872 struct nid_path *path = snd_array_elem(&spec->paths, n);
Takashi Iwai130e5f02012-12-14 16:09:29 +01003873 if (!path->active)
3874 continue;
3875 for (i = 0; i < path->depth; i++) {
3876 if (path->path[i] == nid) {
3877 if (dir == HDA_OUTPUT || path->idx[i] == idx)
3878 return true;
3879 break;
3880 }
3881 }
3882 }
3883 return false;
3884}
3885
Takashi Iwai130e5f02012-12-14 16:09:29 +01003886/* get the default amp value for the target state */
3887static int get_amp_val_to_activate(struct hda_codec *codec, hda_nid_t nid,
3888 int dir, bool enable)
3889{
3890 unsigned int caps;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003891 unsigned int val = 0;
3892
3893 caps = query_amp_caps(codec, nid, dir);
3894 if (caps & AC_AMPCAP_NUM_STEPS) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003895 /* set to 0dB */
3896 if (enable)
3897 val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
Takashi Iwai78e635c2012-12-10 17:07:16 +01003898 }
3899 if (caps & AC_AMPCAP_MUTE) {
Takashi Iwai130e5f02012-12-14 16:09:29 +01003900 if (!enable)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003901 val |= HDA_AMP_MUTE;
3902 }
3903 return val;
3904}
3905
Takashi Iwai130e5f02012-12-14 16:09:29 +01003906/* initialize the amp value (only at the first time) */
3907static void init_amp(struct hda_codec *codec, hda_nid_t nid, int dir, int idx)
3908{
3909 int val = get_amp_val_to_activate(codec, nid, dir, false);
3910 snd_hda_codec_amp_init_stereo(codec, nid, dir, idx, 0xff, val);
3911}
3912
3913static void activate_amp(struct hda_codec *codec, hda_nid_t nid, int dir,
3914 int idx, bool enable)
3915{
3916 int val;
3917 if (is_ctl_associated(codec, nid, dir, idx) ||
3918 is_active_nid(codec, nid, dir, idx))
3919 return;
3920 val = get_amp_val_to_activate(codec, nid, dir, enable);
3921 snd_hda_codec_amp_stereo(codec, nid, dir, idx, 0xff, val);
3922}
3923
3924static void activate_amp_out(struct hda_codec *codec, struct nid_path *path,
3925 int i, bool enable)
3926{
3927 hda_nid_t nid = path->path[i];
3928 init_amp(codec, nid, HDA_OUTPUT, 0);
3929 activate_amp(codec, nid, HDA_OUTPUT, 0, enable);
3930}
3931
3932static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
3933 int i, bool enable)
3934{
3935 struct alc_spec *spec = codec->spec;
3936 hda_nid_t conn[16];
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003937 int n, nums, idx;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003938 hda_nid_t nid = path->path[i];
3939
3940 nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003941 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_PIN) {
3942 nums = 1;
3943 idx = 0;
3944 } else
3945 idx = path->idx[i];
3946
Takashi Iwai130e5f02012-12-14 16:09:29 +01003947 for (n = 0; n < nums; n++)
3948 init_amp(codec, nid, HDA_INPUT, n);
3949
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003950 if (is_ctl_associated(codec, nid, HDA_INPUT, idx))
Takashi Iwai130e5f02012-12-14 16:09:29 +01003951 return;
3952
3953 /* here is a little bit tricky in comparison with activate_amp_out();
3954 * when aa-mixer is available, we need to enable the path as well
3955 */
3956 for (n = 0; n < nums; n++) {
Takashi Iwai0250f7c2012-12-14 17:53:29 +01003957 if (n != idx && conn[n] != spec->mixer_nid)
Takashi Iwai130e5f02012-12-14 16:09:29 +01003958 continue;
3959 activate_amp(codec, nid, HDA_INPUT, n, enable);
3960 }
3961}
3962
3963static void activate_path(struct hda_codec *codec, struct nid_path *path,
3964 bool enable)
3965{
3966 int i;
3967
Takashi Iwai130e5f02012-12-14 16:09:29 +01003968 if (!enable)
3969 path->active = false;
3970
3971 for (i = path->depth - 1; i >= 0; i--) {
Takashi Iwai183a4442012-12-17 18:00:02 +01003972 if (enable && path->multi[i])
Takashi Iwai130e5f02012-12-14 16:09:29 +01003973 snd_hda_codec_write_cache(codec, path->path[i], 0,
3974 AC_VERB_SET_CONNECT_SEL,
3975 path->idx[i]);
3976 if (has_amp_in(codec, path, i))
3977 activate_amp_in(codec, path, i, enable);
3978 if (has_amp_out(codec, path, i))
3979 activate_amp_out(codec, path, i, enable);
3980 }
3981
3982 if (enable)
3983 path->active = true;
3984}
3985
Takashi Iwai78e635c2012-12-10 17:07:16 +01003986/* configure the path from the given dac to the pin as the proper output */
3987static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3988 hda_nid_t pin, int pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01003989 hda_nid_t dac)
Takashi Iwai78e635c2012-12-10 17:07:16 +01003990{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003991 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003992
Takashi Iwai130e5f02012-12-14 16:09:29 +01003993 snd_hda_set_pin_ctl_cache(codec, pin, pin_type);
Takashi Iwai6518f7a2012-12-14 17:34:51 +01003994 path = get_nid_path(codec, dac, pin);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003995 if (!path)
3996 return;
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01003997 if (path->active)
3998 return;
Takashi Iwai130e5f02012-12-14 16:09:29 +01003999 activate_path(codec, path, true);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004000}
4001
Takashi Iwai343a04b2011-07-06 14:28:39 +02004002static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004003{
4004 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02004005 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004006 int i;
4007
4008 for (i = 0; i <= HDA_SIDE; i++) {
4009 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4010 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02004011 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai130e5f02012-12-14 16:09:29 +01004012 spec->multiout.dac_nids[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004013
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004014 }
4015}
4016
Takashi Iwai343a04b2011-07-06 14:28:39 +02004017static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004018{
4019 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004020 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004021 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004022
David Henningsson636030e2011-10-12 19:26:03 +02004023 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004024 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
4025 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02004026 pin = spec->autocfg.hp_pins[i];
4027 if (!pin)
4028 break;
4029 dac = spec->multiout.hp_out_nid[i];
4030 if (!dac) {
4031 if (i > 0 && spec->multiout.hp_out_nid[0])
4032 dac = spec->multiout.hp_out_nid[0];
4033 else
4034 dac = spec->multiout.dac_nids[0];
4035 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004036 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004037 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02004038 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02004039 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
4040 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02004041 pin = spec->autocfg.speaker_pins[i];
4042 if (!pin)
4043 break;
4044 dac = spec->multiout.extra_out_nid[i];
4045 if (!dac) {
4046 if (i > 0 && spec->multiout.extra_out_nid[0])
4047 dac = spec->multiout.extra_out_nid[0];
4048 else
4049 dac = spec->multiout.dac_nids[0];
4050 }
Takashi Iwai130e5f02012-12-14 16:09:29 +01004051 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02004052 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02004053}
4054
Takashi Iwai276dd702012-02-17 16:17:03 +01004055/* check whether the given pin can be a multi-io pin */
4056static bool can_be_multiio_pin(struct hda_codec *codec,
4057 unsigned int location, hda_nid_t nid)
4058{
4059 unsigned int defcfg, caps;
4060
4061 defcfg = snd_hda_codec_get_pincfg(codec, nid);
4062 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
4063 return false;
4064 if (location && get_defcfg_location(defcfg) != location)
4065 return false;
4066 caps = snd_hda_query_pin_caps(codec, nid);
4067 if (!(caps & AC_PINCAP_OUT))
4068 return false;
4069 return true;
4070}
4071
Takashi Iwaice764ab2011-04-27 16:35:23 +02004072/*
4073 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01004074 *
4075 * When hardwired is set, try to fill ony hardwired pins, and returns
4076 * zero if any pins are filled, non-zero if nothing found.
4077 * When hardwired is off, try to fill possible input pins, and returns
4078 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02004079 */
4080static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01004081 hda_nid_t reference_pin,
4082 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004083{
4084 struct alc_spec *spec = codec->spec;
4085 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004086 int type, i, j, dacs, num_pins, old_pins;
4087 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4088 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004089 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004090
Takashi Iwai276dd702012-02-17 16:17:03 +01004091 old_pins = spec->multi_ios;
4092 if (old_pins >= 2)
4093 goto end_fill;
4094
4095 num_pins = 0;
4096 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4097 for (i = 0; i < cfg->num_inputs; i++) {
4098 if (cfg->inputs[i].type != type)
4099 continue;
4100 if (can_be_multiio_pin(codec, location,
4101 cfg->inputs[i].pin))
4102 num_pins++;
4103 }
4104 }
4105 if (num_pins < 2)
4106 goto end_fill;
4107
Takashi Iwai07b18f62011-11-10 15:42:54 +01004108 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004109 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4110 for (i = 0; i < cfg->num_inputs; i++) {
4111 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004112 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004113
Takashi Iwaice764ab2011-04-27 16:35:23 +02004114 if (cfg->inputs[i].type != type)
4115 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004116 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004117 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004118 for (j = 0; j < spec->multi_ios; j++) {
4119 if (nid == spec->multi_io[j].pin)
4120 break;
4121 }
4122 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004123 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004124
4125 if (offset && offset + spec->multi_ios < dacs) {
4126 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai9c640762012-12-14 16:15:56 +01004127 if (!is_reachable_path(codec, dac, nid))
Takashi Iwai07b18f62011-11-10 15:42:54 +01004128 dac = 0;
4129 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004130 if (hardwired)
4131 dac = get_dac_if_single(codec, nid);
4132 else if (!dac)
Takashi Iwaifef7fbb2012-12-14 16:54:44 +01004133 dac = alc_auto_look_for_dac(codec, nid, false);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004134 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004135 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004136 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004137 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004138 if (!add_new_out_path(codec, nid, dac)) {
4139 badness++;
4140 continue;
4141 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004142 spec->multi_io[spec->multi_ios].pin = nid;
4143 spec->multi_io[spec->multi_ios].dac = dac;
4144 spec->multi_ios++;
4145 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004146 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004147 }
4148 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004149 end_fill:
4150 if (badness)
4151 badness = BAD_MULTI_IO;
4152 if (old_pins == spec->multi_ios) {
4153 if (hardwired)
4154 return 1; /* nothing found */
4155 else
4156 return badness; /* no badness if nothing found */
4157 }
4158 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004159 /* cancel newly assigned paths */
Takashi Iwaic9967f12012-12-14 16:39:22 +01004160 spec->paths.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004161 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004162 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004163 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004164
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004165 /* assign volume and mute controls */
4166 for (i = old_pins; i < spec->multi_ios; i++)
4167 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4168 spec->multi_io[i].dac);
4169
4170 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004171}
4172
4173static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4174 struct snd_ctl_elem_info *uinfo)
4175{
4176 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4177 struct alc_spec *spec = codec->spec;
4178
4179 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4180 uinfo->count = 1;
4181 uinfo->value.enumerated.items = spec->multi_ios + 1;
4182 if (uinfo->value.enumerated.item > spec->multi_ios)
4183 uinfo->value.enumerated.item = spec->multi_ios;
4184 sprintf(uinfo->value.enumerated.name, "%dch",
4185 (uinfo->value.enumerated.item + 1) * 2);
4186 return 0;
4187}
4188
4189static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4190 struct snd_ctl_elem_value *ucontrol)
4191{
4192 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4193 struct alc_spec *spec = codec->spec;
4194 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4195 return 0;
4196}
4197
4198static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4199{
4200 struct alc_spec *spec = codec->spec;
4201 hda_nid_t nid = spec->multi_io[idx].pin;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004202 struct nid_path *path;
4203
Takashi Iwai6518f7a2012-12-14 17:34:51 +01004204 path = get_nid_path(codec, spec->multi_io[idx].dac, nid);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004205 if (!path)
4206 return -EINVAL;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004207
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004208 if (path->active == output)
4209 return 0;
Takashi Iwai130e5f02012-12-14 16:09:29 +01004210
Takashi Iwaice764ab2011-04-27 16:35:23 +02004211 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004212 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwai130e5f02012-12-14 16:09:29 +01004213 activate_path(codec, path, true);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004214 } else {
Takashi Iwai130e5f02012-12-14 16:09:29 +01004215 activate_path(codec, path, false);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004216 snd_hda_set_pin_ctl_cache(codec, nid,
4217 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004218 }
4219 return 0;
4220}
4221
4222static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4223 struct snd_ctl_elem_value *ucontrol)
4224{
4225 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4226 struct alc_spec *spec = codec->spec;
4227 int i, ch;
4228
4229 ch = ucontrol->value.enumerated.item[0];
4230 if (ch < 0 || ch > spec->multi_ios)
4231 return -EINVAL;
4232 if (ch == (spec->ext_channel_count - 1) / 2)
4233 return 0;
4234 spec->ext_channel_count = (ch + 1) * 2;
4235 for (i = 0; i < spec->multi_ios; i++)
4236 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004237 spec->multiout.max_channels = max(spec->ext_channel_count,
4238 spec->const_channel_count);
4239 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004240 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004241 return 1;
4242}
4243
Takashi Iwaia9111322011-05-02 11:30:18 +02004244static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004245 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4246 .name = "Channel Mode",
4247 .info = alc_auto_ch_mode_info,
4248 .get = alc_auto_ch_mode_get,
4249 .put = alc_auto_ch_mode_put,
4250};
4251
Takashi Iwai23c09b02011-08-19 09:05:35 +02004252static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004253{
4254 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004255
Takashi Iwaic2674682011-08-24 17:57:44 +02004256 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004257 if (!alc_kcontrol_new(spec, "Channel Mode",
4258 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004259 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004260 }
4261 return 0;
4262}
4263
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004264static void alc_auto_init_multi_io(struct hda_codec *codec)
4265{
4266 struct alc_spec *spec = codec->spec;
4267 int i;
4268
4269 for (i = 0; i < spec->multi_ios; i++) {
4270 hda_nid_t pin = spec->multi_io[i].pin;
4271 struct nid_path *path;
4272 path = get_nid_path(codec, spec->multi_io[i].dac, pin);
4273 if (!path)
4274 continue;
4275 if (!spec->multi_io[i].ctl_in)
4276 spec->multi_io[i].ctl_in =
4277 snd_hda_codec_update_cache(codec, pin, 0,
4278 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4279 activate_path(codec, path, path->active);
4280 }
4281}
4282
Takashi Iwai1d045db2011-07-07 18:23:21 +02004283/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4284 * active input pins
4285 */
4286static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4287{
4288 struct alc_spec *spec = codec->spec;
4289 const struct hda_input_mux *imux;
4290 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4291 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4292 int i, n, nums;
4293
4294 imux = spec->input_mux;
4295 if (!imux)
4296 return;
4297 if (spec->dyn_adc_switch)
4298 return;
4299
Takashi Iwai26acaf02012-03-22 14:36:50 +01004300 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004301 nums = 0;
4302 for (n = 0; n < spec->num_adc_nids; n++) {
4303 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004304 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004305 for (i = 0; i < imux->num_items; i++) {
4306 hda_nid_t pin = spec->imux_pins[i];
4307 if (pin) {
4308 if (get_connection_index(codec, cap, pin) < 0)
4309 break;
4310 } else if (num_conns <= imux->items[i].index)
4311 break;
4312 }
4313 if (i >= imux->num_items) {
4314 adc_nids[nums] = spec->private_adc_nids[n];
4315 capsrc_nids[nums++] = cap;
4316 }
4317 }
4318 if (!nums) {
4319 /* check whether ADC-switch is possible */
4320 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004321 if (spec->shared_mic_hp) {
4322 spec->shared_mic_hp = 0;
4323 spec->private_imux[0].num_items = 1;
4324 goto again;
4325 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004326 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4327 " using fallback 0x%x\n",
4328 codec->chip_name, spec->private_adc_nids[0]);
4329 spec->num_adc_nids = 1;
4330 spec->auto_mic = 0;
4331 return;
4332 }
4333 } else if (nums != spec->num_adc_nids) {
4334 memcpy(spec->private_adc_nids, adc_nids,
4335 nums * sizeof(hda_nid_t));
4336 memcpy(spec->private_capsrc_nids, capsrc_nids,
4337 nums * sizeof(hda_nid_t));
4338 spec->num_adc_nids = nums;
4339 }
4340
4341 if (spec->auto_mic)
4342 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004343 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004344 spec->num_adc_nids = 1; /* reduce to a single ADC */
4345}
4346
4347/*
4348 * initialize ADC paths
4349 */
4350static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4351{
4352 struct alc_spec *spec = codec->spec;
4353 hda_nid_t nid;
4354
4355 nid = spec->adc_nids[adc_idx];
4356 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004357 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004358 snd_hda_codec_write(codec, nid, 0,
4359 AC_VERB_SET_AMP_GAIN_MUTE,
4360 AMP_IN_MUTE(0));
4361 return;
4362 }
4363 if (!spec->capsrc_nids)
4364 return;
4365 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004366 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004367 snd_hda_codec_write(codec, nid, 0,
4368 AC_VERB_SET_AMP_GAIN_MUTE,
4369 AMP_OUT_MUTE);
4370}
4371
4372static void alc_auto_init_input_src(struct hda_codec *codec)
4373{
4374 struct alc_spec *spec = codec->spec;
4375 int c, nums;
4376
4377 for (c = 0; c < spec->num_adc_nids; c++)
4378 alc_auto_init_adc(codec, c);
4379 if (spec->dyn_adc_switch)
4380 nums = 1;
4381 else
4382 nums = spec->num_adc_nids;
4383 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004384 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385}
4386
4387/* add mic boosts if needed */
4388static int alc_auto_add_mic_boost(struct hda_codec *codec)
4389{
4390 struct alc_spec *spec = codec->spec;
4391 struct auto_pin_cfg *cfg = &spec->autocfg;
4392 int i, err;
4393 int type_idx = 0;
4394 hda_nid_t nid;
4395 const char *prev_label = NULL;
4396
4397 for (i = 0; i < cfg->num_inputs; i++) {
4398 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4399 break;
4400 nid = cfg->inputs[i].pin;
4401 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4402 const char *label;
4403 char boost_label[32];
Takashi Iwai8dd48672012-12-14 18:19:04 +01004404 struct nid_path *path;
4405 unsigned int val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004406
4407 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004408 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4409 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004410 if (prev_label && !strcmp(label, prev_label))
4411 type_idx++;
4412 else
4413 type_idx = 0;
4414 prev_label = label;
4415
4416 snprintf(boost_label, sizeof(boost_label),
4417 "%s Boost Volume", label);
Takashi Iwai8dd48672012-12-14 18:19:04 +01004418 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004419 err = add_control(spec, ALC_CTL_WIDGET_VOL,
Takashi Iwai8dd48672012-12-14 18:19:04 +01004420 boost_label, type_idx, val);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004421 if (err < 0)
4422 return err;
Takashi Iwai8dd48672012-12-14 18:19:04 +01004423
4424 path = get_nid_path(codec, nid, 0);
4425 if (path)
4426 path->ctls[NID_PATH_BOOST_CTL] = val;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427 }
4428 }
4429 return 0;
4430}
4431
4432/* select or unmute the given capsrc route */
4433static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4434 int idx)
4435{
4436 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4437 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4438 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004439 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004440 snd_hda_codec_write_cache(codec, cap, 0,
4441 AC_VERB_SET_CONNECT_SEL, idx);
4442 }
4443}
4444
4445/* set the default connection to that pin */
4446static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4447{
4448 struct alc_spec *spec = codec->spec;
4449 int i;
4450
4451 if (!pin)
4452 return 0;
4453 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004454 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004455 int idx;
4456
4457 idx = get_connection_index(codec, cap, pin);
4458 if (idx < 0)
4459 continue;
4460 select_or_unmute_capsrc(codec, cap, idx);
4461 return i; /* return the found index */
4462 }
4463 return -1; /* not found */
4464}
4465
4466/* initialize some special cases for input sources */
4467static void alc_init_special_input_src(struct hda_codec *codec)
4468{
4469 struct alc_spec *spec = codec->spec;
4470 int i;
4471
4472 for (i = 0; i < spec->autocfg.num_inputs; i++)
4473 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4474}
4475
4476/* assign appropriate capture mixers */
4477static void set_capture_mixer(struct hda_codec *codec)
4478{
4479 struct alc_spec *spec = codec->spec;
4480 static const struct snd_kcontrol_new *caps[2][3] = {
4481 { alc_capture_mixer_nosrc1,
4482 alc_capture_mixer_nosrc2,
4483 alc_capture_mixer_nosrc3 },
4484 { alc_capture_mixer1,
4485 alc_capture_mixer2,
4486 alc_capture_mixer3 },
4487 };
4488
4489 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004490 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004491 if (!spec->capsrc_nids)
4492 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004493 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004494 return; /* no volume in capsrc, too */
4495 spec->vol_in_capsrc = 1;
4496 }
4497
4498 if (spec->num_adc_nids > 0) {
4499 int mux = 0;
4500 int num_adcs = 0;
4501
4502 if (spec->input_mux && spec->input_mux->num_items > 1)
4503 mux = 1;
4504 if (spec->auto_mic) {
4505 num_adcs = 1;
4506 mux = 0;
4507 } else if (spec->dyn_adc_switch)
4508 num_adcs = 1;
4509 if (!num_adcs) {
4510 if (spec->num_adc_nids > 3)
4511 spec->num_adc_nids = 3;
4512 else if (!spec->num_adc_nids)
4513 return;
4514 num_adcs = spec->num_adc_nids;
4515 }
4516 spec->cap_mixer = caps[mux][num_adcs - 1];
4517 }
4518}
4519
4520/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004521 * standard auto-parser initializations
4522 */
4523static void alc_auto_init_std(struct hda_codec *codec)
4524{
Takashi Iwaie4770622011-07-08 11:11:35 +02004525 alc_auto_init_multi_out(codec);
4526 alc_auto_init_extra_out(codec);
Takashi Iwai3ebf1e92012-12-14 18:04:37 +01004527 alc_auto_init_multi_io(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004528 alc_auto_init_analog_input(codec);
4529 alc_auto_init_input_src(codec);
4530 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004531 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004532}
4533
4534/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004535 * Digital-beep handlers
4536 */
4537#ifdef CONFIG_SND_HDA_INPUT_BEEP
4538#define set_beep_amp(spec, nid, idx, dir) \
4539 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4540
4541static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004542 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004543 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4544 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4545 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4546 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004547 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004548 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4549 {}
4550};
4551
4552static inline int has_cdefine_beep(struct hda_codec *codec)
4553{
4554 struct alc_spec *spec = codec->spec;
4555 const struct snd_pci_quirk *q;
4556 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4557 if (q)
4558 return q->value;
4559 return spec->cdefine.enable_pcbeep;
4560}
4561#else
4562#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4563#define has_cdefine_beep(codec) 0
4564#endif
4565
4566/* parse the BIOS configuration and set up the alc_spec */
4567/* return 1 if successful, 0 if the proper config is not found,
4568 * or a negative error code
4569 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004570static int alc_parse_auto_config(struct hda_codec *codec,
4571 const hda_nid_t *ignore_nids,
4572 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004573{
4574 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004575 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004576 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004577
Takashi Iwai53c334a2011-08-23 18:27:14 +02004578 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4579 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004580 if (err < 0)
4581 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004582 if (!cfg->line_outs) {
4583 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004584 spec->multiout.max_channels = 2;
4585 spec->no_analog = 1;
4586 goto dig_only;
4587 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004588 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004589 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004590
Takashi Iwaie427c232012-07-29 10:04:08 +02004591 if (!spec->no_primary_hp &&
4592 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004593 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004594 /* use HP as primary out */
4595 cfg->speaker_outs = cfg->line_outs;
4596 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4597 sizeof(cfg->speaker_pins));
4598 cfg->line_outs = cfg->hp_outs;
4599 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4600 cfg->hp_outs = 0;
4601 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4602 cfg->line_out_type = AUTO_PIN_HP_OUT;
4603 }
4604
Takashi Iwai1d045db2011-07-07 18:23:21 +02004605 err = alc_auto_fill_dac_nids(codec);
4606 if (err < 0)
4607 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004608 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004609 if (err < 0)
4610 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004611 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004612 if (err < 0)
4613 return err;
4614 err = alc_auto_create_hp_out(codec);
4615 if (err < 0)
4616 return err;
4617 err = alc_auto_create_speaker_out(codec);
4618 if (err < 0)
4619 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004620 err = alc_auto_create_shared_input(codec);
4621 if (err < 0)
4622 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004623 err = alc_auto_create_input_ctls(codec);
4624 if (err < 0)
4625 return err;
4626
Takashi Iwaib6adb572012-12-03 10:30:58 +01004627 /* check the multiple speaker pins */
4628 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4629 spec->const_channel_count = cfg->line_outs * 2;
4630 else
4631 spec->const_channel_count = cfg->speaker_outs * 2;
4632
4633 if (spec->multi_ios > 0)
4634 spec->multiout.max_channels = max(spec->ext_channel_count,
4635 spec->const_channel_count);
4636 else
4637 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004638
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004639 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004640 alc_auto_parse_digital(codec);
4641
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004642 if (!spec->no_analog)
4643 alc_remove_invalid_adc_nids(codec);
4644
4645 if (ssid_nids)
4646 alc_ssid_check(codec, ssid_nids);
4647
4648 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004649 err = alc_auto_check_switches(codec);
4650 if (err < 0)
4651 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004652 err = alc_auto_add_mic_boost(codec);
4653 if (err < 0)
4654 return err;
4655 }
4656
Takashi Iwai1d045db2011-07-07 18:23:21 +02004657 if (spec->kctls.list)
4658 add_mixer(spec, spec->kctls.list);
4659
Takashi Iwai070cff42012-02-21 12:54:17 +01004660 if (!spec->no_analog && !spec->cap_mixer)
4661 set_capture_mixer(codec);
4662
Takashi Iwai1d045db2011-07-07 18:23:21 +02004663 return 1;
4664}
4665
Takashi Iwai3de95172012-05-07 18:03:15 +02004666/* common preparation job for alc_spec */
4667static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4668{
4669 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4670 int err;
4671
4672 if (!spec)
4673 return -ENOMEM;
4674 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004675 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004676 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004677 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004678 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4679 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwaic9967f12012-12-14 16:39:22 +01004680 snd_array_init(&spec->paths, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004681
4682 err = alc_codec_rename_from_preset(codec);
4683 if (err < 0) {
4684 kfree(spec);
4685 return err;
4686 }
4687 return 0;
4688}
4689
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004690static int alc880_parse_auto_config(struct hda_codec *codec)
4691{
4692 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004693 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004694 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4695}
4696
Takashi Iwai1d045db2011-07-07 18:23:21 +02004697/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004698 * ALC880 fix-ups
4699 */
4700enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004701 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004702 ALC880_FIXUP_GPIO2,
4703 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004704 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004705 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004706 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004707 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004708 ALC880_FIXUP_VOL_KNOB,
4709 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004710 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004711 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004712 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004713 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004714 ALC880_FIXUP_3ST_BASE,
4715 ALC880_FIXUP_3ST,
4716 ALC880_FIXUP_3ST_DIG,
4717 ALC880_FIXUP_5ST_BASE,
4718 ALC880_FIXUP_5ST,
4719 ALC880_FIXUP_5ST_DIG,
4720 ALC880_FIXUP_6ST_BASE,
4721 ALC880_FIXUP_6ST,
4722 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004723};
4724
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004725/* enable the volume-knob widget support on NID 0x21 */
4726static void alc880_fixup_vol_knob(struct hda_codec *codec,
4727 const struct alc_fixup *fix, int action)
4728{
4729 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004730 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004731}
4732
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004733static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004734 [ALC880_FIXUP_GPIO1] = {
4735 .type = ALC_FIXUP_VERBS,
4736 .v.verbs = alc_gpio1_init_verbs,
4737 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004738 [ALC880_FIXUP_GPIO2] = {
4739 .type = ALC_FIXUP_VERBS,
4740 .v.verbs = alc_gpio2_init_verbs,
4741 },
4742 [ALC880_FIXUP_MEDION_RIM] = {
4743 .type = ALC_FIXUP_VERBS,
4744 .v.verbs = (const struct hda_verb[]) {
4745 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4746 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4747 { }
4748 },
4749 .chained = true,
4750 .chain_id = ALC880_FIXUP_GPIO2,
4751 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004752 [ALC880_FIXUP_LG] = {
4753 .type = ALC_FIXUP_PINS,
4754 .v.pins = (const struct alc_pincfg[]) {
4755 /* disable bogus unused pins */
4756 { 0x16, 0x411111f0 },
4757 { 0x18, 0x411111f0 },
4758 { 0x1a, 0x411111f0 },
4759 { }
4760 }
4761 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004762 [ALC880_FIXUP_W810] = {
4763 .type = ALC_FIXUP_PINS,
4764 .v.pins = (const struct alc_pincfg[]) {
4765 /* disable bogus unused pins */
4766 { 0x17, 0x411111f0 },
4767 { }
4768 },
4769 .chained = true,
4770 .chain_id = ALC880_FIXUP_GPIO2,
4771 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004772 [ALC880_FIXUP_EAPD_COEF] = {
4773 .type = ALC_FIXUP_VERBS,
4774 .v.verbs = (const struct hda_verb[]) {
4775 /* change to EAPD mode */
4776 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4777 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4778 {}
4779 },
4780 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004781 [ALC880_FIXUP_TCL_S700] = {
4782 .type = ALC_FIXUP_VERBS,
4783 .v.verbs = (const struct hda_verb[]) {
4784 /* change to EAPD mode */
4785 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4786 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4787 {}
4788 },
4789 .chained = true,
4790 .chain_id = ALC880_FIXUP_GPIO2,
4791 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004792 [ALC880_FIXUP_VOL_KNOB] = {
4793 .type = ALC_FIXUP_FUNC,
4794 .v.func = alc880_fixup_vol_knob,
4795 },
4796 [ALC880_FIXUP_FUJITSU] = {
4797 /* override all pins as BIOS on old Amilo is broken */
4798 .type = ALC_FIXUP_PINS,
4799 .v.pins = (const struct alc_pincfg[]) {
4800 { 0x14, 0x0121411f }, /* HP */
4801 { 0x15, 0x99030120 }, /* speaker */
4802 { 0x16, 0x99030130 }, /* bass speaker */
4803 { 0x17, 0x411111f0 }, /* N/A */
4804 { 0x18, 0x411111f0 }, /* N/A */
4805 { 0x19, 0x01a19950 }, /* mic-in */
4806 { 0x1a, 0x411111f0 }, /* N/A */
4807 { 0x1b, 0x411111f0 }, /* N/A */
4808 { 0x1c, 0x411111f0 }, /* N/A */
4809 { 0x1d, 0x411111f0 }, /* N/A */
4810 { 0x1e, 0x01454140 }, /* SPDIF out */
4811 { }
4812 },
4813 .chained = true,
4814 .chain_id = ALC880_FIXUP_VOL_KNOB,
4815 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004816 [ALC880_FIXUP_F1734] = {
4817 /* almost compatible with FUJITSU, but no bass and SPDIF */
4818 .type = ALC_FIXUP_PINS,
4819 .v.pins = (const struct alc_pincfg[]) {
4820 { 0x14, 0x0121411f }, /* HP */
4821 { 0x15, 0x99030120 }, /* speaker */
4822 { 0x16, 0x411111f0 }, /* N/A */
4823 { 0x17, 0x411111f0 }, /* N/A */
4824 { 0x18, 0x411111f0 }, /* N/A */
4825 { 0x19, 0x01a19950 }, /* mic-in */
4826 { 0x1a, 0x411111f0 }, /* N/A */
4827 { 0x1b, 0x411111f0 }, /* N/A */
4828 { 0x1c, 0x411111f0 }, /* N/A */
4829 { 0x1d, 0x411111f0 }, /* N/A */
4830 { 0x1e, 0x411111f0 }, /* N/A */
4831 { }
4832 },
4833 .chained = true,
4834 .chain_id = ALC880_FIXUP_VOL_KNOB,
4835 },
Takashi Iwai817de922012-02-20 17:20:48 +01004836 [ALC880_FIXUP_UNIWILL] = {
4837 /* need to fix HP and speaker pins to be parsed correctly */
4838 .type = ALC_FIXUP_PINS,
4839 .v.pins = (const struct alc_pincfg[]) {
4840 { 0x14, 0x0121411f }, /* HP */
4841 { 0x15, 0x99030120 }, /* speaker */
4842 { 0x16, 0x99030130 }, /* bass speaker */
4843 { }
4844 },
4845 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004846 [ALC880_FIXUP_UNIWILL_DIG] = {
4847 .type = ALC_FIXUP_PINS,
4848 .v.pins = (const struct alc_pincfg[]) {
4849 /* disable bogus unused pins */
4850 { 0x17, 0x411111f0 },
4851 { 0x19, 0x411111f0 },
4852 { 0x1b, 0x411111f0 },
4853 { 0x1f, 0x411111f0 },
4854 { }
4855 }
4856 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004857 [ALC880_FIXUP_Z71V] = {
4858 .type = ALC_FIXUP_PINS,
4859 .v.pins = (const struct alc_pincfg[]) {
4860 /* set up the whole pins as BIOS is utterly broken */
4861 { 0x14, 0x99030120 }, /* speaker */
4862 { 0x15, 0x0121411f }, /* HP */
4863 { 0x16, 0x411111f0 }, /* N/A */
4864 { 0x17, 0x411111f0 }, /* N/A */
4865 { 0x18, 0x01a19950 }, /* mic-in */
4866 { 0x19, 0x411111f0 }, /* N/A */
4867 { 0x1a, 0x01813031 }, /* line-in */
4868 { 0x1b, 0x411111f0 }, /* N/A */
4869 { 0x1c, 0x411111f0 }, /* N/A */
4870 { 0x1d, 0x411111f0 }, /* N/A */
4871 { 0x1e, 0x0144111e }, /* SPDIF */
4872 { }
4873 }
4874 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004875 [ALC880_FIXUP_3ST_BASE] = {
4876 .type = ALC_FIXUP_PINS,
4877 .v.pins = (const struct alc_pincfg[]) {
4878 { 0x14, 0x01014010 }, /* line-out */
4879 { 0x15, 0x411111f0 }, /* N/A */
4880 { 0x16, 0x411111f0 }, /* N/A */
4881 { 0x17, 0x411111f0 }, /* N/A */
4882 { 0x18, 0x01a19c30 }, /* mic-in */
4883 { 0x19, 0x0121411f }, /* HP */
4884 { 0x1a, 0x01813031 }, /* line-in */
4885 { 0x1b, 0x02a19c40 }, /* front-mic */
4886 { 0x1c, 0x411111f0 }, /* N/A */
4887 { 0x1d, 0x411111f0 }, /* N/A */
4888 /* 0x1e is filled in below */
4889 { 0x1f, 0x411111f0 }, /* N/A */
4890 { }
4891 }
4892 },
4893 [ALC880_FIXUP_3ST] = {
4894 .type = ALC_FIXUP_PINS,
4895 .v.pins = (const struct alc_pincfg[]) {
4896 { 0x1e, 0x411111f0 }, /* N/A */
4897 { }
4898 },
4899 .chained = true,
4900 .chain_id = ALC880_FIXUP_3ST_BASE,
4901 },
4902 [ALC880_FIXUP_3ST_DIG] = {
4903 .type = ALC_FIXUP_PINS,
4904 .v.pins = (const struct alc_pincfg[]) {
4905 { 0x1e, 0x0144111e }, /* SPDIF */
4906 { }
4907 },
4908 .chained = true,
4909 .chain_id = ALC880_FIXUP_3ST_BASE,
4910 },
4911 [ALC880_FIXUP_5ST_BASE] = {
4912 .type = ALC_FIXUP_PINS,
4913 .v.pins = (const struct alc_pincfg[]) {
4914 { 0x14, 0x01014010 }, /* front */
4915 { 0x15, 0x411111f0 }, /* N/A */
4916 { 0x16, 0x01011411 }, /* CLFE */
4917 { 0x17, 0x01016412 }, /* surr */
4918 { 0x18, 0x01a19c30 }, /* mic-in */
4919 { 0x19, 0x0121411f }, /* HP */
4920 { 0x1a, 0x01813031 }, /* line-in */
4921 { 0x1b, 0x02a19c40 }, /* front-mic */
4922 { 0x1c, 0x411111f0 }, /* N/A */
4923 { 0x1d, 0x411111f0 }, /* N/A */
4924 /* 0x1e is filled in below */
4925 { 0x1f, 0x411111f0 }, /* N/A */
4926 { }
4927 }
4928 },
4929 [ALC880_FIXUP_5ST] = {
4930 .type = ALC_FIXUP_PINS,
4931 .v.pins = (const struct alc_pincfg[]) {
4932 { 0x1e, 0x411111f0 }, /* N/A */
4933 { }
4934 },
4935 .chained = true,
4936 .chain_id = ALC880_FIXUP_5ST_BASE,
4937 },
4938 [ALC880_FIXUP_5ST_DIG] = {
4939 .type = ALC_FIXUP_PINS,
4940 .v.pins = (const struct alc_pincfg[]) {
4941 { 0x1e, 0x0144111e }, /* SPDIF */
4942 { }
4943 },
4944 .chained = true,
4945 .chain_id = ALC880_FIXUP_5ST_BASE,
4946 },
4947 [ALC880_FIXUP_6ST_BASE] = {
4948 .type = ALC_FIXUP_PINS,
4949 .v.pins = (const struct alc_pincfg[]) {
4950 { 0x14, 0x01014010 }, /* front */
4951 { 0x15, 0x01016412 }, /* surr */
4952 { 0x16, 0x01011411 }, /* CLFE */
4953 { 0x17, 0x01012414 }, /* side */
4954 { 0x18, 0x01a19c30 }, /* mic-in */
4955 { 0x19, 0x02a19c40 }, /* front-mic */
4956 { 0x1a, 0x01813031 }, /* line-in */
4957 { 0x1b, 0x0121411f }, /* HP */
4958 { 0x1c, 0x411111f0 }, /* N/A */
4959 { 0x1d, 0x411111f0 }, /* N/A */
4960 /* 0x1e is filled in below */
4961 { 0x1f, 0x411111f0 }, /* N/A */
4962 { }
4963 }
4964 },
4965 [ALC880_FIXUP_6ST] = {
4966 .type = ALC_FIXUP_PINS,
4967 .v.pins = (const struct alc_pincfg[]) {
4968 { 0x1e, 0x411111f0 }, /* N/A */
4969 { }
4970 },
4971 .chained = true,
4972 .chain_id = ALC880_FIXUP_6ST_BASE,
4973 },
4974 [ALC880_FIXUP_6ST_DIG] = {
4975 .type = ALC_FIXUP_PINS,
4976 .v.pins = (const struct alc_pincfg[]) {
4977 { 0x1e, 0x0144111e }, /* SPDIF */
4978 { }
4979 },
4980 .chained = true,
4981 .chain_id = ALC880_FIXUP_6ST_BASE,
4982 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004983};
4984
4985static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004986 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004987 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004988 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4989 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004990 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004991 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004992 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004993 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004994 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004995 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004996 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004997 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004998 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004999 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01005000 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01005001 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
5002 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
5003 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01005004 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005005
5006 /* Below is the copied entries from alc880_quirks.c.
5007 * It's not quite sure whether BIOS sets the correct pin-config table
5008 * on these machines, thus they are kept to be compatible with
5009 * the old static quirks. Once when it's confirmed to work without
5010 * these overrides, it'd be better to remove.
5011 */
5012 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
5013 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
5014 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
5015 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
5016 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
5017 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
5018 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
5019 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
5020 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
5021 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
5022 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
5023 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
5024 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
5025 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
5026 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
5027 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
5028 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
5029 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
5030 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
5031 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
5032 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
5033 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
5034 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
5035 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5036 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5037 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5038 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5039 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5040 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5041 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
5042 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5043 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5044 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
5045 /* default Intel */
5046 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
5047 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
5048 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
5049 {}
5050};
5051
5052static const struct alc_model_fixup alc880_fixup_models[] = {
5053 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
5054 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
5055 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
5056 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
5057 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
5058 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01005059 {}
5060};
5061
5062
5063/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02005064 * OK, here we have finally the patch for ALC880
5065 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005066static int patch_alc880(struct hda_codec *codec)
5067{
5068 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069 int err;
5070
Takashi Iwai3de95172012-05-07 18:03:15 +02005071 err = alc_alloc_spec(codec, 0x0b);
5072 if (err < 0)
5073 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005074
Takashi Iwai3de95172012-05-07 18:03:15 +02005075 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02005076 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005077
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005078 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
5079 alc880_fixups);
5080 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081
Takashi Iwai67b6ec32012-02-20 18:20:42 +01005082 /* automatic parse from the BIOS config */
5083 err = alc880_parse_auto_config(codec);
5084 if (err < 0)
5085 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005086
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005087 if (!spec->no_analog) {
5088 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005089 if (err < 0)
5090 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005091 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5092 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005093
Takashi Iwai1d045db2011-07-07 18:23:21 +02005094 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02005095 codec->patch_ops.unsol_event = alc880_unsol_event;
5096
Takashi Iwai1d045db2011-07-07 18:23:21 +02005097
Takashi Iwai589876e2012-02-20 15:47:55 +01005098 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5099
Takashi Iwai1d045db2011-07-07 18:23:21 +02005100 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005101
5102 error:
5103 alc_free(codec);
5104 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105}
5106
5107
5108/*
5109 * ALC260 support
5110 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005111static int alc260_parse_auto_config(struct hda_codec *codec)
5112{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005113 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005114 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5115 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005116}
5117
Takashi Iwai1d045db2011-07-07 18:23:21 +02005118/*
5119 * Pin config fixes
5120 */
5121enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005122 ALC260_FIXUP_HP_DC5750,
5123 ALC260_FIXUP_HP_PIN_0F,
5124 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005125 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005126 ALC260_FIXUP_GPIO1_TOGGLE,
5127 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005128 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005129 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005130};
5131
Takashi Iwai20f7d922012-02-16 12:35:16 +01005132static void alc260_gpio1_automute(struct hda_codec *codec)
5133{
5134 struct alc_spec *spec = codec->spec;
5135 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5136 spec->hp_jack_present);
5137}
5138
5139static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5140 const struct alc_fixup *fix, int action)
5141{
5142 struct alc_spec *spec = codec->spec;
5143 if (action == ALC_FIXUP_ACT_PROBE) {
5144 /* although the machine has only one output pin, we need to
5145 * toggle GPIO1 according to the jack state
5146 */
5147 spec->automute_hook = alc260_gpio1_automute;
5148 spec->detect_hp = 1;
5149 spec->automute_speaker = 1;
5150 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005151 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5152 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005153 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005154 }
5155}
5156
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005157static void alc260_fixup_kn1(struct hda_codec *codec,
5158 const struct alc_fixup *fix, int action)
5159{
5160 struct alc_spec *spec = codec->spec;
5161 static const struct alc_pincfg pincfgs[] = {
5162 { 0x0f, 0x02214000 }, /* HP/speaker */
5163 { 0x12, 0x90a60160 }, /* int mic */
5164 { 0x13, 0x02a19000 }, /* ext mic */
5165 { 0x18, 0x01446000 }, /* SPDIF out */
5166 /* disable bogus I/O pins */
5167 { 0x10, 0x411111f0 },
5168 { 0x11, 0x411111f0 },
5169 { 0x14, 0x411111f0 },
5170 { 0x15, 0x411111f0 },
5171 { 0x16, 0x411111f0 },
5172 { 0x17, 0x411111f0 },
5173 { 0x19, 0x411111f0 },
5174 { }
5175 };
5176
5177 switch (action) {
5178 case ALC_FIXUP_ACT_PRE_PROBE:
5179 alc_apply_pincfgs(codec, pincfgs);
5180 break;
5181 case ALC_FIXUP_ACT_PROBE:
5182 spec->init_amp = ALC_INIT_NONE;
5183 break;
5184 }
5185}
5186
Takashi Iwai1d045db2011-07-07 18:23:21 +02005187static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005188 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005189 .type = ALC_FIXUP_PINS,
5190 .v.pins = (const struct alc_pincfg[]) {
5191 { 0x11, 0x90130110 }, /* speaker */
5192 { }
5193 }
5194 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005195 [ALC260_FIXUP_HP_PIN_0F] = {
5196 .type = ALC_FIXUP_PINS,
5197 .v.pins = (const struct alc_pincfg[]) {
5198 { 0x0f, 0x01214000 }, /* HP */
5199 { }
5200 }
5201 },
5202 [ALC260_FIXUP_COEF] = {
5203 .type = ALC_FIXUP_VERBS,
5204 .v.verbs = (const struct hda_verb[]) {
5205 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5206 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5207 { }
5208 },
5209 .chained = true,
5210 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5211 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005212 [ALC260_FIXUP_GPIO1] = {
5213 .type = ALC_FIXUP_VERBS,
5214 .v.verbs = alc_gpio1_init_verbs,
5215 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005216 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5217 .type = ALC_FIXUP_FUNC,
5218 .v.func = alc260_fixup_gpio1_toggle,
5219 .chained = true,
5220 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5221 },
5222 [ALC260_FIXUP_REPLACER] = {
5223 .type = ALC_FIXUP_VERBS,
5224 .v.verbs = (const struct hda_verb[]) {
5225 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5226 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5227 { }
5228 },
5229 .chained = true,
5230 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5231 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005232 [ALC260_FIXUP_HP_B1900] = {
5233 .type = ALC_FIXUP_FUNC,
5234 .v.func = alc260_fixup_gpio1_toggle,
5235 .chained = true,
5236 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005237 },
5238 [ALC260_FIXUP_KN1] = {
5239 .type = ALC_FIXUP_FUNC,
5240 .v.func = alc260_fixup_kn1,
5241 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005242};
5243
5244static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005245 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005246 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005247 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005248 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005249 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005250 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005251 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005252 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005253 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005254 {}
5255};
5256
5257/*
5258 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005259static int patch_alc260(struct hda_codec *codec)
5260{
5261 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005262 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005263
Takashi Iwai3de95172012-05-07 18:03:15 +02005264 err = alc_alloc_spec(codec, 0x07);
5265 if (err < 0)
5266 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005267
Takashi Iwai3de95172012-05-07 18:03:15 +02005268 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005269
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005270 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5271 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005272
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005273 /* automatic parse from the BIOS config */
5274 err = alc260_parse_auto_config(codec);
5275 if (err < 0)
5276 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005277
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005278 if (!spec->no_analog) {
5279 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005280 if (err < 0)
5281 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005282 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5283 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005284
Takashi Iwai1d045db2011-07-07 18:23:21 +02005285 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005286 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005287
Takashi Iwai589876e2012-02-20 15:47:55 +01005288 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5289
Takashi Iwai1d045db2011-07-07 18:23:21 +02005290 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005291
5292 error:
5293 alc_free(codec);
5294 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005295}
5296
5297
5298/*
5299 * ALC882/883/885/888/889 support
5300 *
5301 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5302 * configuration. Each pin widget can choose any input DACs and a mixer.
5303 * Each ADC is connected from a mixer of all inputs. This makes possible
5304 * 6-channel independent captures.
5305 *
5306 * In addition, an independent DAC for the multi-playback (not used in this
5307 * driver yet).
5308 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005309
5310/*
5311 * Pin config fixes
5312 */
5313enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005314 ALC882_FIXUP_ABIT_AW9D_MAX,
5315 ALC882_FIXUP_LENOVO_Y530,
5316 ALC882_FIXUP_PB_M5210,
5317 ALC882_FIXUP_ACER_ASPIRE_7736,
5318 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005319 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005320 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005321 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005322 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005323 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005324 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005325 ALC882_FIXUP_GPIO1,
5326 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005327 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005328 ALC889_FIXUP_COEF,
5329 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005330 ALC882_FIXUP_ACER_ASPIRE_4930G,
5331 ALC882_FIXUP_ACER_ASPIRE_8930G,
5332 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005333 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005334 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005335 ALC889_FIXUP_MBP_VREF,
5336 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005337 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005338 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005339};
5340
Takashi Iwai68ef0562011-11-09 18:24:44 +01005341static void alc889_fixup_coef(struct hda_codec *codec,
5342 const struct alc_fixup *fix, int action)
5343{
5344 if (action != ALC_FIXUP_ACT_INIT)
5345 return;
5346 alc889_coef_init(codec);
5347}
5348
Takashi Iwai56710872011-11-14 17:42:11 +01005349/* toggle speaker-output according to the hp-jack state */
5350static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5351{
5352 unsigned int gpiostate, gpiomask, gpiodir;
5353
5354 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5355 AC_VERB_GET_GPIO_DATA, 0);
5356
5357 if (!muted)
5358 gpiostate |= (1 << pin);
5359 else
5360 gpiostate &= ~(1 << pin);
5361
5362 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5363 AC_VERB_GET_GPIO_MASK, 0);
5364 gpiomask |= (1 << pin);
5365
5366 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5367 AC_VERB_GET_GPIO_DIRECTION, 0);
5368 gpiodir |= (1 << pin);
5369
5370
5371 snd_hda_codec_write(codec, codec->afg, 0,
5372 AC_VERB_SET_GPIO_MASK, gpiomask);
5373 snd_hda_codec_write(codec, codec->afg, 0,
5374 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5375
5376 msleep(1);
5377
5378 snd_hda_codec_write(codec, codec->afg, 0,
5379 AC_VERB_SET_GPIO_DATA, gpiostate);
5380}
5381
5382/* set up GPIO at initialization */
5383static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5384 const struct alc_fixup *fix, int action)
5385{
5386 if (action != ALC_FIXUP_ACT_INIT)
5387 return;
5388 alc882_gpio_mute(codec, 0, 0);
5389 alc882_gpio_mute(codec, 1, 0);
5390}
5391
Takashi Iwai02a237b2012-02-13 15:25:07 +01005392/* Fix the connection of some pins for ALC889:
5393 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5394 * work correctly (bko#42740)
5395 */
5396static void alc889_fixup_dac_route(struct hda_codec *codec,
5397 const struct alc_fixup *fix, int action)
5398{
5399 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005400 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005401 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5402 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5403 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5404 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5405 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5406 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005407 } else if (action == ALC_FIXUP_ACT_PROBE) {
5408 /* restore the connections */
5409 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5410 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5411 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5412 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5413 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005414 }
5415}
5416
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005417/* Set VREF on HP pin */
5418static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5419 const struct alc_fixup *fix, int action)
5420{
5421 struct alc_spec *spec = codec->spec;
5422 static hda_nid_t nids[2] = { 0x14, 0x15 };
5423 int i;
5424
5425 if (action != ALC_FIXUP_ACT_INIT)
5426 return;
5427 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5428 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5429 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5430 continue;
5431 val = snd_hda_codec_read(codec, nids[i], 0,
5432 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5433 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005434 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005435 spec->keep_vref_in_automute = 1;
5436 break;
5437 }
5438}
5439
5440/* Set VREF on speaker pins on imac91 */
5441static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5442 const struct alc_fixup *fix, int action)
5443{
5444 struct alc_spec *spec = codec->spec;
5445 static hda_nid_t nids[2] = { 0x18, 0x1a };
5446 int i;
5447
5448 if (action != ALC_FIXUP_ACT_INIT)
5449 return;
5450 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5451 unsigned int val;
5452 val = snd_hda_codec_read(codec, nids[i], 0,
5453 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5454 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005455 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005456 }
5457 spec->keep_vref_in_automute = 1;
5458}
5459
Takashi Iwaie427c232012-07-29 10:04:08 +02005460/* Don't take HP output as primary
5461 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5462 */
5463static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5464 const struct alc_fixup *fix, int action)
5465{
5466 struct alc_spec *spec = codec->spec;
5467 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5468 spec->no_primary_hp = 1;
5469}
5470
Takashi Iwai1d045db2011-07-07 18:23:21 +02005471static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005472 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005473 .type = ALC_FIXUP_PINS,
5474 .v.pins = (const struct alc_pincfg[]) {
5475 { 0x15, 0x01080104 }, /* side */
5476 { 0x16, 0x01011012 }, /* rear */
5477 { 0x17, 0x01016011 }, /* clfe */
5478 { }
5479 }
5480 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005481 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005482 .type = ALC_FIXUP_PINS,
5483 .v.pins = (const struct alc_pincfg[]) {
5484 { 0x15, 0x99130112 }, /* rear int speakers */
5485 { 0x16, 0x99130111 }, /* subwoofer */
5486 { }
5487 }
5488 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005489 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005490 .type = ALC_FIXUP_VERBS,
5491 .v.verbs = (const struct hda_verb[]) {
5492 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5493 {}
5494 }
5495 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005496 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005497 .type = ALC_FIXUP_FUNC,
5498 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005500 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005501 .type = ALC_FIXUP_PINS,
5502 .v.pins = (const struct alc_pincfg[]) {
5503 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5504 { }
5505 }
5506 },
Marton Balint8f239212012-03-05 21:33:23 +01005507 [ALC889_FIXUP_CD] = {
5508 .type = ALC_FIXUP_PINS,
5509 .v.pins = (const struct alc_pincfg[]) {
5510 { 0x1c, 0x993301f0 }, /* CD */
5511 { }
5512 }
5513 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005514 [ALC889_FIXUP_VAIO_TT] = {
5515 .type = ALC_FIXUP_PINS,
5516 .v.pins = (const struct alc_pincfg[]) {
5517 { 0x17, 0x90170111 }, /* hidden surround speaker */
5518 { }
5519 }
5520 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005521 [ALC888_FIXUP_EEE1601] = {
5522 .type = ALC_FIXUP_VERBS,
5523 .v.verbs = (const struct hda_verb[]) {
5524 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5525 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5526 { }
5527 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005528 },
5529 [ALC882_FIXUP_EAPD] = {
5530 .type = ALC_FIXUP_VERBS,
5531 .v.verbs = (const struct hda_verb[]) {
5532 /* change to EAPD mode */
5533 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5534 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5535 { }
5536 }
5537 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005538 [ALC883_FIXUP_EAPD] = {
5539 .type = ALC_FIXUP_VERBS,
5540 .v.verbs = (const struct hda_verb[]) {
5541 /* change to EAPD mode */
5542 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5543 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5544 { }
5545 }
5546 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005547 [ALC883_FIXUP_ACER_EAPD] = {
5548 .type = ALC_FIXUP_VERBS,
5549 .v.verbs = (const struct hda_verb[]) {
5550 /* eanable EAPD on Acer laptops */
5551 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5552 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5553 { }
5554 }
5555 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005556 [ALC882_FIXUP_GPIO1] = {
5557 .type = ALC_FIXUP_VERBS,
5558 .v.verbs = alc_gpio1_init_verbs,
5559 },
5560 [ALC882_FIXUP_GPIO2] = {
5561 .type = ALC_FIXUP_VERBS,
5562 .v.verbs = alc_gpio2_init_verbs,
5563 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005564 [ALC882_FIXUP_GPIO3] = {
5565 .type = ALC_FIXUP_VERBS,
5566 .v.verbs = alc_gpio3_init_verbs,
5567 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005568 [ALC882_FIXUP_ASUS_W2JC] = {
5569 .type = ALC_FIXUP_VERBS,
5570 .v.verbs = alc_gpio1_init_verbs,
5571 .chained = true,
5572 .chain_id = ALC882_FIXUP_EAPD,
5573 },
5574 [ALC889_FIXUP_COEF] = {
5575 .type = ALC_FIXUP_FUNC,
5576 .v.func = alc889_fixup_coef,
5577 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005578 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5579 .type = ALC_FIXUP_PINS,
5580 .v.pins = (const struct alc_pincfg[]) {
5581 { 0x16, 0x99130111 }, /* CLFE speaker */
5582 { 0x17, 0x99130112 }, /* surround speaker */
5583 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005584 },
5585 .chained = true,
5586 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005587 },
5588 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5589 .type = ALC_FIXUP_PINS,
5590 .v.pins = (const struct alc_pincfg[]) {
5591 { 0x16, 0x99130111 }, /* CLFE speaker */
5592 { 0x1b, 0x99130112 }, /* surround speaker */
5593 { }
5594 },
5595 .chained = true,
5596 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5597 },
5598 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5599 /* additional init verbs for Acer Aspire 8930G */
5600 .type = ALC_FIXUP_VERBS,
5601 .v.verbs = (const struct hda_verb[]) {
5602 /* Enable all DACs */
5603 /* DAC DISABLE/MUTE 1? */
5604 /* setting bits 1-5 disables DAC nids 0x02-0x06
5605 * apparently. Init=0x38 */
5606 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5607 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5608 /* DAC DISABLE/MUTE 2? */
5609 /* some bit here disables the other DACs.
5610 * Init=0x4900 */
5611 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5612 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5613 /* DMIC fix
5614 * This laptop has a stereo digital microphone.
5615 * The mics are only 1cm apart which makes the stereo
5616 * useless. However, either the mic or the ALC889
5617 * makes the signal become a difference/sum signal
5618 * instead of standard stereo, which is annoying.
5619 * So instead we flip this bit which makes the
5620 * codec replicate the sum signal to both channels,
5621 * turning it into a normal mono mic.
5622 */
5623 /* DMIC_CONTROL? Init value = 0x0001 */
5624 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5625 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5626 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5627 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5628 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005629 },
5630 .chained = true,
5631 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005632 },
Takashi Iwai56710872011-11-14 17:42:11 +01005633 [ALC885_FIXUP_MACPRO_GPIO] = {
5634 .type = ALC_FIXUP_FUNC,
5635 .v.func = alc885_fixup_macpro_gpio,
5636 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005637 [ALC889_FIXUP_DAC_ROUTE] = {
5638 .type = ALC_FIXUP_FUNC,
5639 .v.func = alc889_fixup_dac_route,
5640 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005641 [ALC889_FIXUP_MBP_VREF] = {
5642 .type = ALC_FIXUP_FUNC,
5643 .v.func = alc889_fixup_mbp_vref,
5644 .chained = true,
5645 .chain_id = ALC882_FIXUP_GPIO1,
5646 },
5647 [ALC889_FIXUP_IMAC91_VREF] = {
5648 .type = ALC_FIXUP_FUNC,
5649 .v.func = alc889_fixup_imac91_vref,
5650 .chained = true,
5651 .chain_id = ALC882_FIXUP_GPIO1,
5652 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005653 [ALC882_FIXUP_INV_DMIC] = {
5654 .type = ALC_FIXUP_FUNC,
5655 .v.func = alc_fixup_inv_dmic_0x12,
5656 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005657 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5658 .type = ALC_FIXUP_FUNC,
5659 .v.func = alc882_fixup_no_primary_hp,
5660 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661};
5662
5663static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005664 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5665 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5666 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5667 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5668 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5669 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005670 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5671 ALC882_FIXUP_ACER_ASPIRE_4930G),
5672 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5673 ALC882_FIXUP_ACER_ASPIRE_4930G),
5674 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5675 ALC882_FIXUP_ACER_ASPIRE_8930G),
5676 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5677 ALC882_FIXUP_ACER_ASPIRE_8930G),
5678 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5679 ALC882_FIXUP_ACER_ASPIRE_4930G),
5680 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5681 ALC882_FIXUP_ACER_ASPIRE_4930G),
5682 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5683 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005684 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005685 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5686 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005687 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005688 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005689 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005690 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005691 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005692 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005693 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005694 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005695 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005696
5697 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005698 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5699 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5700 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005701 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5702 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5703 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005704 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5705 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005706 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005707 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5708 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5709 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5710 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005711 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005712 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5713 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5714 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005715 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005716 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005717 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5718 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5719 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005720
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005721 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005722 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005723 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005724 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005725 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005726 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5727 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005728 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005729 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005730 {}
5731};
5732
Takashi Iwai912093b2012-04-11 14:03:41 +02005733static const struct alc_model_fixup alc882_fixup_models[] = {
5734 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5735 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5736 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005737 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005738 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005739 {}
5740};
5741
Takashi Iwai1d045db2011-07-07 18:23:21 +02005742/*
5743 * BIOS auto configuration
5744 */
5745/* almost identical with ALC880 parser... */
5746static int alc882_parse_auto_config(struct hda_codec *codec)
5747{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005749 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5750 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751}
5752
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753/*
5754 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755static int patch_alc882(struct hda_codec *codec)
5756{
5757 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005758 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759
Takashi Iwai3de95172012-05-07 18:03:15 +02005760 err = alc_alloc_spec(codec, 0x0b);
5761 if (err < 0)
5762 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763
Takashi Iwai3de95172012-05-07 18:03:15 +02005764 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765
5766 switch (codec->vendor_id) {
5767 case 0x10ec0882:
5768 case 0x10ec0885:
5769 break;
5770 default:
5771 /* ALC883 and variants */
5772 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5773 break;
5774 }
5775
Takashi Iwai912093b2012-04-11 14:03:41 +02005776 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5777 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005778 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005779
5780 alc_auto_parse_customize_define(codec);
5781
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005782 /* automatic parse from the BIOS config */
5783 err = alc882_parse_auto_config(codec);
5784 if (err < 0)
5785 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005787 if (!spec->no_analog && has_cdefine_beep(codec)) {
5788 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005789 if (err < 0)
5790 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005791 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005792 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793
Takashi Iwai1d045db2011-07-07 18:23:21 +02005794 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005795
Takashi Iwai589876e2012-02-20 15:47:55 +01005796 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5797
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005799
5800 error:
5801 alc_free(codec);
5802 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005803}
5804
5805
5806/*
5807 * ALC262 support
5808 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005809static int alc262_parse_auto_config(struct hda_codec *codec)
5810{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005811 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005812 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5813 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005814}
5815
5816/*
5817 * Pin config fixes
5818 */
5819enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005820 ALC262_FIXUP_FSC_H270,
5821 ALC262_FIXUP_HP_Z200,
5822 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005823 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005824 ALC262_FIXUP_BENQ,
5825 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005826 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005827};
5828
5829static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005830 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005831 .type = ALC_FIXUP_PINS,
5832 .v.pins = (const struct alc_pincfg[]) {
5833 { 0x14, 0x99130110 }, /* speaker */
5834 { 0x15, 0x0221142f }, /* front HP */
5835 { 0x1b, 0x0121141f }, /* rear HP */
5836 { }
5837 }
5838 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005839 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005840 .type = ALC_FIXUP_PINS,
5841 .v.pins = (const struct alc_pincfg[]) {
5842 { 0x16, 0x99130120 }, /* internal speaker */
5843 { }
5844 }
5845 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005846 [ALC262_FIXUP_TYAN] = {
5847 .type = ALC_FIXUP_PINS,
5848 .v.pins = (const struct alc_pincfg[]) {
5849 { 0x14, 0x1993e1f0 }, /* int AUX */
5850 { }
5851 }
5852 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005853 [ALC262_FIXUP_LENOVO_3000] = {
5854 .type = ALC_FIXUP_VERBS,
5855 .v.verbs = (const struct hda_verb[]) {
5856 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005857 {}
5858 },
5859 .chained = true,
5860 .chain_id = ALC262_FIXUP_BENQ,
5861 },
5862 [ALC262_FIXUP_BENQ] = {
5863 .type = ALC_FIXUP_VERBS,
5864 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005865 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5866 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5867 {}
5868 }
5869 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005870 [ALC262_FIXUP_BENQ_T31] = {
5871 .type = ALC_FIXUP_VERBS,
5872 .v.verbs = (const struct hda_verb[]) {
5873 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5874 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5875 {}
5876 }
5877 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005878 [ALC262_FIXUP_INV_DMIC] = {
5879 .type = ALC_FIXUP_FUNC,
5880 .v.func = alc_fixup_inv_dmic_0x12,
5881 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005882};
5883
5884static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005885 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005886 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5887 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005888 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5889 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005890 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005891 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5892 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005893 {}
5894};
5895
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005896static const struct alc_model_fixup alc262_fixup_models[] = {
5897 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5898 {}
5899};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005900
Takashi Iwai1d045db2011-07-07 18:23:21 +02005901/*
5902 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005903static int patch_alc262(struct hda_codec *codec)
5904{
5905 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005906 int err;
5907
Takashi Iwai3de95172012-05-07 18:03:15 +02005908 err = alc_alloc_spec(codec, 0x0b);
5909 if (err < 0)
5910 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005911
Takashi Iwai3de95172012-05-07 18:03:15 +02005912 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005913
5914#if 0
5915 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5916 * under-run
5917 */
5918 {
5919 int tmp;
5920 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5921 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5922 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5923 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5924 }
5925#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005926 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5927
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005928 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5929 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005930 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005931
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005932 alc_auto_parse_customize_define(codec);
5933
Takashi Iwai42399f72011-11-07 17:18:44 +01005934 /* automatic parse from the BIOS config */
5935 err = alc262_parse_auto_config(codec);
5936 if (err < 0)
5937 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005938
Takashi Iwai1d045db2011-07-07 18:23:21 +02005939 if (!spec->no_analog && has_cdefine_beep(codec)) {
5940 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005941 if (err < 0)
5942 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005943 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005944 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005945
Takashi Iwai1d045db2011-07-07 18:23:21 +02005946 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005947 spec->shutup = alc_eapd_shutup;
5948
Takashi Iwai589876e2012-02-20 15:47:55 +01005949 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5950
Takashi Iwai1d045db2011-07-07 18:23:21 +02005951 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005952
5953 error:
5954 alc_free(codec);
5955 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005956}
5957
5958/*
5959 * ALC268
5960 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005961/* bind Beep switches of both NID 0x0f and 0x10 */
5962static const struct hda_bind_ctls alc268_bind_beep_sw = {
5963 .ops = &snd_hda_bind_sw,
5964 .values = {
5965 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5966 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5967 0
5968 },
5969};
5970
5971static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5972 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5973 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5974 { }
5975};
5976
5977/* set PCBEEP vol = 0, mute connections */
5978static const struct hda_verb alc268_beep_init_verbs[] = {
5979 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5980 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5981 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5982 { }
5983};
5984
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005985enum {
5986 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005987 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005988};
5989
5990static const struct alc_fixup alc268_fixups[] = {
5991 [ALC268_FIXUP_INV_DMIC] = {
5992 .type = ALC_FIXUP_FUNC,
5993 .v.func = alc_fixup_inv_dmic_0x12,
5994 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005995 [ALC268_FIXUP_HP_EAPD] = {
5996 .type = ALC_FIXUP_VERBS,
5997 .v.verbs = (const struct hda_verb[]) {
5998 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5999 {}
6000 }
6001 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006002};
6003
6004static const struct alc_model_fixup alc268_fixup_models[] = {
6005 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02006006 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
6007 {}
6008};
6009
6010static const struct snd_pci_quirk alc268_fixup_tbl[] = {
6011 /* below is codec SSID since multiple Toshiba laptops have the
6012 * same PCI SSID 1179:ff00
6013 */
6014 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006015 {}
6016};
6017
Takashi Iwai1d045db2011-07-07 18:23:21 +02006018/*
6019 * BIOS auto configuration
6020 */
6021static int alc268_parse_auto_config(struct hda_codec *codec)
6022{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006023 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02006024 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006025 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
6026 if (err > 0) {
6027 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
6028 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02006029 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006030 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006031 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006032 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006033}
6034
Takashi Iwai1d045db2011-07-07 18:23:21 +02006035/*
6036 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006037static int patch_alc268(struct hda_codec *codec)
6038{
6039 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006040 int i, has_beep, err;
6041
Takashi Iwai1d045db2011-07-07 18:23:21 +02006042 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006043 err = alc_alloc_spec(codec, 0);
6044 if (err < 0)
6045 return err;
6046
6047 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006048
Takashi Iwaicb766402012-10-20 10:55:21 +02006049 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006050 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6051
Takashi Iwai6ebb8052011-08-16 15:15:40 +02006052 /* automatic parse from the BIOS config */
6053 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006054 if (err < 0)
6055 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006056
Takashi Iwai1d045db2011-07-07 18:23:21 +02006057 has_beep = 0;
6058 for (i = 0; i < spec->num_mixers; i++) {
6059 if (spec->mixers[i] == alc268_beep_mixer) {
6060 has_beep = 1;
6061 break;
6062 }
6063 }
6064
6065 if (has_beep) {
6066 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006067 if (err < 0)
6068 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006069 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
6070 /* override the amp caps for beep generator */
6071 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
6072 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
6073 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
6074 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6075 (0 << AC_AMPCAP_MUTE_SHIFT));
6076 }
6077
Takashi Iwai1d045db2011-07-07 18:23:21 +02006078 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006079 spec->shutup = alc_eapd_shutup;
6080
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006081 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6082
Takashi Iwai1d045db2011-07-07 18:23:21 +02006083 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006084
6085 error:
6086 alc_free(codec);
6087 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006088}
6089
6090/*
6091 * ALC269
6092 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006093static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
6094 .substreams = 1,
6095 .channels_min = 2,
6096 .channels_max = 8,
6097 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6098 /* NID is set in alc_build_pcms */
6099 .ops = {
6100 .open = alc_playback_pcm_open,
6101 .prepare = alc_playback_pcm_prepare,
6102 .cleanup = alc_playback_pcm_cleanup
6103 },
6104};
6105
6106static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6107 .substreams = 1,
6108 .channels_min = 2,
6109 .channels_max = 2,
6110 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6111 /* NID is set in alc_build_pcms */
6112};
6113
Takashi Iwai1d045db2011-07-07 18:23:21 +02006114/* different alc269-variants */
6115enum {
6116 ALC269_TYPE_ALC269VA,
6117 ALC269_TYPE_ALC269VB,
6118 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006119 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006120 ALC269_TYPE_ALC280,
6121 ALC269_TYPE_ALC282,
6122 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006123};
6124
6125/*
6126 * BIOS auto configuration
6127 */
6128static int alc269_parse_auto_config(struct hda_codec *codec)
6129{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006130 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006131 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6132 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6133 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006134 const hda_nid_t *ssids;
6135
6136 switch (spec->codec_variant) {
6137 case ALC269_TYPE_ALC269VA:
6138 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006139 case ALC269_TYPE_ALC280:
6140 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006141 ssids = alc269va_ssids;
6142 break;
6143 case ALC269_TYPE_ALC269VB:
6144 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006145 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006146 ssids = alc269_ssids;
6147 break;
6148 default:
6149 ssids = alc269_ssids;
6150 break;
6151 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006152
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006153 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006154}
6155
Kailang Yang1387e2d2012-11-08 10:23:18 +01006156static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006157{
6158 int val = alc_read_coef_idx(codec, 0x04);
6159 if (power_up)
6160 val |= 1 << 11;
6161 else
6162 val &= ~(1 << 11);
6163 alc_write_coef_idx(codec, 0x04, val);
6164}
6165
6166static void alc269_shutup(struct hda_codec *codec)
6167{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006168 struct alc_spec *spec = codec->spec;
6169
6170 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6171 return;
6172
Kailang Yang1387e2d2012-11-08 10:23:18 +01006173 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6174 alc269vb_toggle_power_output(codec, 0);
6175 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6176 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006177 msleep(150);
6178 }
6179}
6180
Takashi Iwai2a439522011-07-26 09:52:50 +02006181#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006182static int alc269_resume(struct hda_codec *codec)
6183{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006184 struct alc_spec *spec = codec->spec;
6185
Kailang Yang1387e2d2012-11-08 10:23:18 +01006186 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6187 alc269vb_toggle_power_output(codec, 0);
6188 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006189 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006190 msleep(150);
6191 }
6192
6193 codec->patch_ops.init(codec);
6194
Kailang Yang1387e2d2012-11-08 10:23:18 +01006195 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6196 alc269vb_toggle_power_output(codec, 1);
6197 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006198 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006199 msleep(200);
6200 }
6201
Takashi Iwai1d045db2011-07-07 18:23:21 +02006202 snd_hda_codec_resume_amp(codec);
6203 snd_hda_codec_resume_cache(codec);
6204 hda_call_check_power_status(codec, 0x01);
6205 return 0;
6206}
Takashi Iwai2a439522011-07-26 09:52:50 +02006207#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006208
David Henningsson108cc102012-07-20 10:37:25 +02006209static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6210 const struct alc_fixup *fix, int action)
6211{
6212 struct alc_spec *spec = codec->spec;
6213
6214 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6215 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6216}
6217
Takashi Iwai1d045db2011-07-07 18:23:21 +02006218static void alc269_fixup_hweq(struct hda_codec *codec,
6219 const struct alc_fixup *fix, int action)
6220{
6221 int coef;
6222
6223 if (action != ALC_FIXUP_ACT_INIT)
6224 return;
6225 coef = alc_read_coef_idx(codec, 0x1e);
6226 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6227}
6228
6229static void alc271_fixup_dmic(struct hda_codec *codec,
6230 const struct alc_fixup *fix, int action)
6231{
6232 static const struct hda_verb verbs[] = {
6233 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6234 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6235 {}
6236 };
6237 unsigned int cfg;
6238
6239 if (strcmp(codec->chip_name, "ALC271X"))
6240 return;
6241 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6242 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6243 snd_hda_sequence_write(codec, verbs);
6244}
6245
Takashi Iwai017f2a12011-07-09 14:42:25 +02006246static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6247 const struct alc_fixup *fix, int action)
6248{
6249 struct alc_spec *spec = codec->spec;
6250
6251 if (action != ALC_FIXUP_ACT_PROBE)
6252 return;
6253
6254 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6255 * fix the sample rate of analog I/O to 44.1kHz
6256 */
6257 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6258 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6259}
6260
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006261static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6262 const struct alc_fixup *fix, int action)
6263{
6264 int coef;
6265
6266 if (action != ALC_FIXUP_ACT_INIT)
6267 return;
6268 /* The digital-mic unit sends PDM (differential signal) instead of
6269 * the standard PCM, thus you can't record a valid mono stream as is.
6270 * Below is a workaround specific to ALC269 to control the dmic
6271 * signal source as mono.
6272 */
6273 coef = alc_read_coef_idx(codec, 0x07);
6274 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6275}
6276
Takashi Iwai24519912011-08-16 15:08:49 +02006277static void alc269_quanta_automute(struct hda_codec *codec)
6278{
David Henningsson42cf0d02011-09-20 12:04:56 +02006279 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006280
6281 snd_hda_codec_write(codec, 0x20, 0,
6282 AC_VERB_SET_COEF_INDEX, 0x0c);
6283 snd_hda_codec_write(codec, 0x20, 0,
6284 AC_VERB_SET_PROC_COEF, 0x680);
6285
6286 snd_hda_codec_write(codec, 0x20, 0,
6287 AC_VERB_SET_COEF_INDEX, 0x0c);
6288 snd_hda_codec_write(codec, 0x20, 0,
6289 AC_VERB_SET_PROC_COEF, 0x480);
6290}
6291
6292static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6293 const struct alc_fixup *fix, int action)
6294{
6295 struct alc_spec *spec = codec->spec;
6296 if (action != ALC_FIXUP_ACT_PROBE)
6297 return;
6298 spec->automute_hook = alc269_quanta_automute;
6299}
6300
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006301/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6302static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6303{
6304 struct hda_codec *codec = private_data;
6305 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6306 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6307 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6308}
6309
6310static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6311 const struct alc_fixup *fix, int action)
6312{
6313 struct alc_spec *spec = codec->spec;
6314 switch (action) {
6315 case ALC_FIXUP_ACT_BUILD:
6316 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6317 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6318 /* fallthru */
6319 case ALC_FIXUP_ACT_INIT:
6320 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6321 break;
6322 }
6323}
6324
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006325/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6326static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6327{
6328 struct hda_codec *codec = private_data;
6329 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006330 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006331}
6332
6333static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6334 const struct alc_fixup *fix, int action)
6335{
6336 struct alc_spec *spec = codec->spec;
6337 switch (action) {
6338 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006339 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006340 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006341 /* fallthru */
6342 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006343 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006344 break;
6345 }
6346}
6347
Dylan Reid08a978d2012-11-18 22:56:40 -08006348static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6349 const struct alc_fixup *fix,
6350 int action)
6351{
6352 struct alc_spec *spec = codec->spec;
6353
6354 if (action == ALC_FIXUP_ACT_PROBE)
6355 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6356 spec->autocfg.hp_pins[0]);
6357}
David Henningsson693b6132012-06-22 19:12:10 +02006358
Takashi Iwai1d045db2011-07-07 18:23:21 +02006359enum {
6360 ALC269_FIXUP_SONY_VAIO,
6361 ALC275_FIXUP_SONY_VAIO_GPIO2,
6362 ALC269_FIXUP_DELL_M101Z,
6363 ALC269_FIXUP_SKU_IGNORE,
6364 ALC269_FIXUP_ASUS_G73JW,
6365 ALC269_FIXUP_LENOVO_EAPD,
6366 ALC275_FIXUP_SONY_HWEQ,
6367 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006368 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006369 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006370 ALC269_FIXUP_QUANTA_MUTE,
6371 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006372 ALC269_FIXUP_AMIC,
6373 ALC269_FIXUP_DMIC,
6374 ALC269VB_FIXUP_AMIC,
6375 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006376 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006377 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006378 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006379 ALC269_FIXUP_LENOVO_DOCK,
6380 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006381 ALC271_FIXUP_AMIC_MIC2,
6382 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006383};
6384
6385static const struct alc_fixup alc269_fixups[] = {
6386 [ALC269_FIXUP_SONY_VAIO] = {
6387 .type = ALC_FIXUP_VERBS,
6388 .v.verbs = (const struct hda_verb[]) {
6389 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6390 {}
6391 }
6392 },
6393 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6394 .type = ALC_FIXUP_VERBS,
6395 .v.verbs = (const struct hda_verb[]) {
6396 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6397 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6398 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6399 { }
6400 },
6401 .chained = true,
6402 .chain_id = ALC269_FIXUP_SONY_VAIO
6403 },
6404 [ALC269_FIXUP_DELL_M101Z] = {
6405 .type = ALC_FIXUP_VERBS,
6406 .v.verbs = (const struct hda_verb[]) {
6407 /* Enables internal speaker */
6408 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6409 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6410 {}
6411 }
6412 },
6413 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006414 .type = ALC_FIXUP_FUNC,
6415 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006416 },
6417 [ALC269_FIXUP_ASUS_G73JW] = {
6418 .type = ALC_FIXUP_PINS,
6419 .v.pins = (const struct alc_pincfg[]) {
6420 { 0x17, 0x99130111 }, /* subwoofer */
6421 { }
6422 }
6423 },
6424 [ALC269_FIXUP_LENOVO_EAPD] = {
6425 .type = ALC_FIXUP_VERBS,
6426 .v.verbs = (const struct hda_verb[]) {
6427 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6428 {}
6429 }
6430 },
6431 [ALC275_FIXUP_SONY_HWEQ] = {
6432 .type = ALC_FIXUP_FUNC,
6433 .v.func = alc269_fixup_hweq,
6434 .chained = true,
6435 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6436 },
6437 [ALC271_FIXUP_DMIC] = {
6438 .type = ALC_FIXUP_FUNC,
6439 .v.func = alc271_fixup_dmic,
6440 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006441 [ALC269_FIXUP_PCM_44K] = {
6442 .type = ALC_FIXUP_FUNC,
6443 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006444 .chained = true,
6445 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006446 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006447 [ALC269_FIXUP_STEREO_DMIC] = {
6448 .type = ALC_FIXUP_FUNC,
6449 .v.func = alc269_fixup_stereo_dmic,
6450 },
Takashi Iwai24519912011-08-16 15:08:49 +02006451 [ALC269_FIXUP_QUANTA_MUTE] = {
6452 .type = ALC_FIXUP_FUNC,
6453 .v.func = alc269_fixup_quanta_mute,
6454 },
6455 [ALC269_FIXUP_LIFEBOOK] = {
6456 .type = ALC_FIXUP_PINS,
6457 .v.pins = (const struct alc_pincfg[]) {
6458 { 0x1a, 0x2101103f }, /* dock line-out */
6459 { 0x1b, 0x23a11040 }, /* dock mic-in */
6460 { }
6461 },
6462 .chained = true,
6463 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6464 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006465 [ALC269_FIXUP_AMIC] = {
6466 .type = ALC_FIXUP_PINS,
6467 .v.pins = (const struct alc_pincfg[]) {
6468 { 0x14, 0x99130110 }, /* speaker */
6469 { 0x15, 0x0121401f }, /* HP out */
6470 { 0x18, 0x01a19c20 }, /* mic */
6471 { 0x19, 0x99a3092f }, /* int-mic */
6472 { }
6473 },
6474 },
6475 [ALC269_FIXUP_DMIC] = {
6476 .type = ALC_FIXUP_PINS,
6477 .v.pins = (const struct alc_pincfg[]) {
6478 { 0x12, 0x99a3092f }, /* int-mic */
6479 { 0x14, 0x99130110 }, /* speaker */
6480 { 0x15, 0x0121401f }, /* HP out */
6481 { 0x18, 0x01a19c20 }, /* mic */
6482 { }
6483 },
6484 },
6485 [ALC269VB_FIXUP_AMIC] = {
6486 .type = ALC_FIXUP_PINS,
6487 .v.pins = (const struct alc_pincfg[]) {
6488 { 0x14, 0x99130110 }, /* speaker */
6489 { 0x18, 0x01a19c20 }, /* mic */
6490 { 0x19, 0x99a3092f }, /* int-mic */
6491 { 0x21, 0x0121401f }, /* HP out */
6492 { }
6493 },
6494 },
David Henningsson2267ea92012-01-03 08:45:56 +01006495 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006496 .type = ALC_FIXUP_PINS,
6497 .v.pins = (const struct alc_pincfg[]) {
6498 { 0x12, 0x99a3092f }, /* int-mic */
6499 { 0x14, 0x99130110 }, /* speaker */
6500 { 0x18, 0x01a19c20 }, /* mic */
6501 { 0x21, 0x0121401f }, /* HP out */
6502 { }
6503 },
6504 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006505 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6506 .type = ALC_FIXUP_FUNC,
6507 .v.func = alc269_fixup_mic1_mute,
6508 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006509 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6510 .type = ALC_FIXUP_FUNC,
6511 .v.func = alc269_fixup_mic2_mute,
6512 },
David Henningsson693b6132012-06-22 19:12:10 +02006513 [ALC269_FIXUP_INV_DMIC] = {
6514 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006515 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006516 },
David Henningsson108cc102012-07-20 10:37:25 +02006517 [ALC269_FIXUP_LENOVO_DOCK] = {
6518 .type = ALC_FIXUP_PINS,
6519 .v.pins = (const struct alc_pincfg[]) {
6520 { 0x19, 0x23a11040 }, /* dock mic */
6521 { 0x1b, 0x2121103f }, /* dock headphone */
6522 { }
6523 },
6524 .chained = true,
6525 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6526 },
6527 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6528 .type = ALC_FIXUP_FUNC,
6529 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6530 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006531 [ALC271_FIXUP_AMIC_MIC2] = {
6532 .type = ALC_FIXUP_PINS,
6533 .v.pins = (const struct alc_pincfg[]) {
6534 { 0x14, 0x99130110 }, /* speaker */
6535 { 0x19, 0x01a19c20 }, /* mic */
6536 { 0x1b, 0x99a7012f }, /* int-mic */
6537 { 0x21, 0x0121401f }, /* HP out */
6538 { }
6539 },
6540 },
6541 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6542 .type = ALC_FIXUP_FUNC,
6543 .v.func = alc271_hp_gate_mic_jack,
6544 .chained = true,
6545 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6546 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006547};
6548
6549static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006550 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6551 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006552 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006553 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006554 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006555 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006556 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006557 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006558 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6559 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6560 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6561 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6562 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006563 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6564 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6565 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6566 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6567 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006568 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006569 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006570 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006571 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6572 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6573 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6574 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6575 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006576 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006577 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006578 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006579 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006580 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006581 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006582 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006583
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006584#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006585 /* Below is a quirk table taken from the old code.
6586 * Basically the device should work as is without the fixup table.
6587 * If BIOS doesn't give a proper info, enable the corresponding
6588 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006589 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006590 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6591 ALC269_FIXUP_AMIC),
6592 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006593 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6594 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6595 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6596 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6597 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6598 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6599 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6600 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6601 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6602 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6603 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6604 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6605 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6606 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6607 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6608 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6609 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6610 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6611 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6612 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6613 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6614 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6615 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6616 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6617 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6618 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6619 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6620 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6621 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6622 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6623 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6624 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6625 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6626 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6627 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6628 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6629 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6630 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6631#endif
6632 {}
6633};
6634
6635static const struct alc_model_fixup alc269_fixup_models[] = {
6636 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6637 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006638 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6639 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6640 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006641 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006642 {}
6643};
6644
6645
Takashi Iwai546bb672012-03-07 08:37:19 +01006646static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006647{
Kailang Yang526af6e2012-03-07 08:25:20 +01006648 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006649 int val;
6650
Kailang Yang526af6e2012-03-07 08:25:20 +01006651 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006652 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006653
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006654 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006655 alc_write_coef_idx(codec, 0xf, 0x960b);
6656 alc_write_coef_idx(codec, 0xe, 0x8817);
6657 }
6658
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006659 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006660 alc_write_coef_idx(codec, 0xf, 0x960b);
6661 alc_write_coef_idx(codec, 0xe, 0x8814);
6662 }
6663
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006664 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006665 val = alc_read_coef_idx(codec, 0x04);
6666 /* Power up output pin */
6667 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6668 }
6669
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006670 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006671 val = alc_read_coef_idx(codec, 0xd);
6672 if ((val & 0x0c00) >> 10 != 0x1) {
6673 /* Capless ramp up clock control */
6674 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6675 }
6676 val = alc_read_coef_idx(codec, 0x17);
6677 if ((val & 0x01c0) >> 6 != 0x4) {
6678 /* Class D power on reset */
6679 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6680 }
6681 }
6682
6683 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6684 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6685
6686 val = alc_read_coef_idx(codec, 0x4); /* HP */
6687 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006688}
6689
6690/*
6691 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006692static int patch_alc269(struct hda_codec *codec)
6693{
6694 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006695 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006696
Takashi Iwai3de95172012-05-07 18:03:15 +02006697 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006698 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006699 return err;
6700
6701 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006702
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006703 alc_pick_fixup(codec, alc269_fixup_models,
6704 alc269_fixup_tbl, alc269_fixups);
6705 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6706
6707 alc_auto_parse_customize_define(codec);
6708
Kailang Yang065380f2013-01-10 10:25:48 +01006709 switch (codec->vendor_id) {
6710 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006711 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006712 switch (alc_get_coef0(codec) & 0x00f0) {
6713 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006714 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006715 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006716 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006717 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006718 break;
6719 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006720 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6721 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006722 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006723 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006724 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006725 case 0x0030:
6726 spec->codec_variant = ALC269_TYPE_ALC269VD;
6727 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006728 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006729 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006730 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006731 if (err < 0)
6732 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006733 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006734 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006735 break;
6736
6737 case 0x10ec0280:
6738 case 0x10ec0290:
6739 spec->codec_variant = ALC269_TYPE_ALC280;
6740 break;
6741 case 0x10ec0282:
6742 case 0x10ec0283:
6743 spec->codec_variant = ALC269_TYPE_ALC282;
6744 break;
6745 case 0x10ec0284:
6746 case 0x10ec0292:
6747 spec->codec_variant = ALC269_TYPE_ALC284;
6748 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006749 }
6750
Takashi Iwaia4297b52011-08-23 18:40:12 +02006751 /* automatic parse from the BIOS config */
6752 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006753 if (err < 0)
6754 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006755
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006756 if (!spec->no_analog && has_cdefine_beep(codec)) {
6757 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006758 if (err < 0)
6759 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006760 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006761 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006762
Takashi Iwai1d045db2011-07-07 18:23:21 +02006763 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006764#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006765 codec->patch_ops.resume = alc269_resume;
6766#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006767 spec->shutup = alc269_shutup;
6768
Takashi Iwai589876e2012-02-20 15:47:55 +01006769 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6770
Takashi Iwai1d045db2011-07-07 18:23:21 +02006771 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006772
6773 error:
6774 alc_free(codec);
6775 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006776}
6777
6778/*
6779 * ALC861
6780 */
6781
Takashi Iwai1d045db2011-07-07 18:23:21 +02006782static int alc861_parse_auto_config(struct hda_codec *codec)
6783{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006784 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006785 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6786 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006787}
6788
Takashi Iwai1d045db2011-07-07 18:23:21 +02006789/* Pin config fixes */
6790enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006791 ALC861_FIXUP_FSC_AMILO_PI1505,
6792 ALC861_FIXUP_AMP_VREF_0F,
6793 ALC861_FIXUP_NO_JACK_DETECT,
6794 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006795};
6796
Takashi Iwai31150f22012-01-30 10:54:08 +01006797/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6798static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6799 const struct alc_fixup *fix, int action)
6800{
6801 struct alc_spec *spec = codec->spec;
6802 unsigned int val;
6803
6804 if (action != ALC_FIXUP_ACT_INIT)
6805 return;
6806 val = snd_hda_codec_read(codec, 0x0f, 0,
6807 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6808 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6809 val |= AC_PINCTL_IN_EN;
6810 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006811 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006812 spec->keep_vref_in_automute = 1;
6813}
6814
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006815/* suppress the jack-detection */
6816static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6817 const struct alc_fixup *fix, int action)
6818{
6819 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6820 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006821}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006822
Takashi Iwai1d045db2011-07-07 18:23:21 +02006823static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006824 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006825 .type = ALC_FIXUP_PINS,
6826 .v.pins = (const struct alc_pincfg[]) {
6827 { 0x0b, 0x0221101f }, /* HP */
6828 { 0x0f, 0x90170310 }, /* speaker */
6829 { }
6830 }
6831 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006832 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006833 .type = ALC_FIXUP_FUNC,
6834 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006835 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006836 [ALC861_FIXUP_NO_JACK_DETECT] = {
6837 .type = ALC_FIXUP_FUNC,
6838 .v.func = alc_fixup_no_jack_detect,
6839 },
6840 [ALC861_FIXUP_ASUS_A6RP] = {
6841 .type = ALC_FIXUP_FUNC,
6842 .v.func = alc861_fixup_asus_amp_vref_0f,
6843 .chained = true,
6844 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6845 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006846};
6847
6848static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006849 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6850 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6851 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6852 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6853 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6854 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006855 {}
6856};
6857
6858/*
6859 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006860static int patch_alc861(struct hda_codec *codec)
6861{
6862 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006863 int err;
6864
Takashi Iwai3de95172012-05-07 18:03:15 +02006865 err = alc_alloc_spec(codec, 0x15);
6866 if (err < 0)
6867 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006868
Takashi Iwai3de95172012-05-07 18:03:15 +02006869 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006870
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006871 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6872 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006873
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006874 /* automatic parse from the BIOS config */
6875 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006876 if (err < 0)
6877 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006878
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006879 if (!spec->no_analog) {
6880 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006881 if (err < 0)
6882 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006883 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6884 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006885
Takashi Iwai1d045db2011-07-07 18:23:21 +02006886 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006887#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006888 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006889#endif
6890
Takashi Iwai589876e2012-02-20 15:47:55 +01006891 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6892
Takashi Iwai1d045db2011-07-07 18:23:21 +02006893 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006894
6895 error:
6896 alc_free(codec);
6897 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006898}
6899
6900/*
6901 * ALC861-VD support
6902 *
6903 * Based on ALC882
6904 *
6905 * In addition, an independent DAC
6906 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006907static int alc861vd_parse_auto_config(struct hda_codec *codec)
6908{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006909 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006910 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6911 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006912}
6913
Takashi Iwai1d045db2011-07-07 18:23:21 +02006914enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006915 ALC660VD_FIX_ASUS_GPIO1,
6916 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006917};
6918
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006919/* exclude VREF80 */
6920static void alc861vd_fixup_dallas(struct hda_codec *codec,
6921 const struct alc_fixup *fix, int action)
6922{
6923 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006924 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6925 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006926 }
6927}
6928
Takashi Iwai1d045db2011-07-07 18:23:21 +02006929static const struct alc_fixup alc861vd_fixups[] = {
6930 [ALC660VD_FIX_ASUS_GPIO1] = {
6931 .type = ALC_FIXUP_VERBS,
6932 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006933 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006934 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6935 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6936 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6937 { }
6938 }
6939 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006940 [ALC861VD_FIX_DALLAS] = {
6941 .type = ALC_FIXUP_FUNC,
6942 .v.func = alc861vd_fixup_dallas,
6943 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006944};
6945
6946static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006947 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006948 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006949 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006950 {}
6951};
6952
Takashi Iwai1d045db2011-07-07 18:23:21 +02006953/*
6954 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006955static int patch_alc861vd(struct hda_codec *codec)
6956{
6957 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006958 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006959
Takashi Iwai3de95172012-05-07 18:03:15 +02006960 err = alc_alloc_spec(codec, 0x0b);
6961 if (err < 0)
6962 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006963
Takashi Iwai3de95172012-05-07 18:03:15 +02006964 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006965
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006966 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6967 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006968
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006969 /* automatic parse from the BIOS config */
6970 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006971 if (err < 0)
6972 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006973
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006974 if (!spec->no_analog) {
6975 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006976 if (err < 0)
6977 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006978 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6979 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006980
Takashi Iwai1d045db2011-07-07 18:23:21 +02006981 codec->patch_ops = alc_patch_ops;
6982
Takashi Iwai1d045db2011-07-07 18:23:21 +02006983 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006984
Takashi Iwai589876e2012-02-20 15:47:55 +01006985 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6986
Takashi Iwai1d045db2011-07-07 18:23:21 +02006987 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006988
6989 error:
6990 alc_free(codec);
6991 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006992}
6993
6994/*
6995 * ALC662 support
6996 *
6997 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6998 * configuration. Each pin widget can choose any input DACs and a mixer.
6999 * Each ADC is connected from a mixer of all inputs. This makes possible
7000 * 6-channel independent captures.
7001 *
7002 * In addition, an independent DAC for the multi-playback (not used in this
7003 * driver yet).
7004 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02007005
7006/*
7007 * BIOS auto configuration
7008 */
7009
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007010static int alc662_parse_auto_config(struct hda_codec *codec)
7011{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02007012 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007013 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
7014 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
7015 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02007016
Kailang Yang6227cdc2010-02-25 08:36:52 +01007017 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
7018 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007019 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01007020 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007021 ssids = alc662_ssids;
7022 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007023}
7024
Todd Broch6be79482010-12-07 16:51:05 -08007025static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007026 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01007027{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007028 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01007029 return;
Todd Broch6be79482010-12-07 16:51:05 -08007030 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
7031 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
7032 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
7033 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
7034 (0 << AC_AMPCAP_MUTE_SHIFT)))
7035 printk(KERN_WARNING
7036 "hda_codec: failed to override amp caps for NID 0x2\n");
7037}
7038
David Henningsson6cb3b702010-09-09 08:51:44 +02007039enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04007040 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02007041 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08007042 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007043 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02007044 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007045 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02007046 ALC662_FIXUP_ASUS_MODE1,
7047 ALC662_FIXUP_ASUS_MODE2,
7048 ALC662_FIXUP_ASUS_MODE3,
7049 ALC662_FIXUP_ASUS_MODE4,
7050 ALC662_FIXUP_ASUS_MODE5,
7051 ALC662_FIXUP_ASUS_MODE6,
7052 ALC662_FIXUP_ASUS_MODE7,
7053 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01007054 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02007055 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02007056 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02007057};
7058
7059static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04007060 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007061 .type = ALC_FIXUP_PINS,
7062 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04007063 { 0x15, 0x99130112 }, /* subwoofer */
7064 { }
7065 }
7066 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007067 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007068 .type = ALC_FIXUP_PINS,
7069 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02007070 { 0x17, 0x99130112 }, /* subwoofer */
7071 { }
7072 }
7073 },
Todd Broch6be79482010-12-07 16:51:05 -08007074 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01007075 .type = ALC_FIXUP_FUNC,
7076 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01007077 },
7078 [ALC662_FIXUP_CZC_P10T] = {
7079 .type = ALC_FIXUP_VERBS,
7080 .v.verbs = (const struct hda_verb[]) {
7081 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
7082 {}
7083 }
7084 },
David Henningsson94024cd2011-04-29 14:10:55 +02007085 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02007086 .type = ALC_FIXUP_FUNC,
7087 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02007088 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007089 [ALC662_FIXUP_HP_RP5800] = {
7090 .type = ALC_FIXUP_PINS,
7091 .v.pins = (const struct alc_pincfg[]) {
7092 { 0x14, 0x0221201f }, /* HP out */
7093 { }
7094 },
7095 .chained = true,
7096 .chain_id = ALC662_FIXUP_SKU_IGNORE
7097 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007098 [ALC662_FIXUP_ASUS_MODE1] = {
7099 .type = ALC_FIXUP_PINS,
7100 .v.pins = (const struct alc_pincfg[]) {
7101 { 0x14, 0x99130110 }, /* speaker */
7102 { 0x18, 0x01a19c20 }, /* mic */
7103 { 0x19, 0x99a3092f }, /* int-mic */
7104 { 0x21, 0x0121401f }, /* HP out */
7105 { }
7106 },
7107 .chained = true,
7108 .chain_id = ALC662_FIXUP_SKU_IGNORE
7109 },
7110 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007111 .type = ALC_FIXUP_PINS,
7112 .v.pins = (const struct alc_pincfg[]) {
7113 { 0x14, 0x99130110 }, /* speaker */
7114 { 0x18, 0x01a19820 }, /* mic */
7115 { 0x19, 0x99a3092f }, /* int-mic */
7116 { 0x1b, 0x0121401f }, /* HP out */
7117 { }
7118 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007119 .chained = true,
7120 .chain_id = ALC662_FIXUP_SKU_IGNORE
7121 },
7122 [ALC662_FIXUP_ASUS_MODE3] = {
7123 .type = ALC_FIXUP_PINS,
7124 .v.pins = (const struct alc_pincfg[]) {
7125 { 0x14, 0x99130110 }, /* speaker */
7126 { 0x15, 0x0121441f }, /* HP */
7127 { 0x18, 0x01a19840 }, /* mic */
7128 { 0x19, 0x99a3094f }, /* int-mic */
7129 { 0x21, 0x01211420 }, /* HP2 */
7130 { }
7131 },
7132 .chained = true,
7133 .chain_id = ALC662_FIXUP_SKU_IGNORE
7134 },
7135 [ALC662_FIXUP_ASUS_MODE4] = {
7136 .type = ALC_FIXUP_PINS,
7137 .v.pins = (const struct alc_pincfg[]) {
7138 { 0x14, 0x99130110 }, /* speaker */
7139 { 0x16, 0x99130111 }, /* speaker */
7140 { 0x18, 0x01a19840 }, /* mic */
7141 { 0x19, 0x99a3094f }, /* int-mic */
7142 { 0x21, 0x0121441f }, /* HP */
7143 { }
7144 },
7145 .chained = true,
7146 .chain_id = ALC662_FIXUP_SKU_IGNORE
7147 },
7148 [ALC662_FIXUP_ASUS_MODE5] = {
7149 .type = ALC_FIXUP_PINS,
7150 .v.pins = (const struct alc_pincfg[]) {
7151 { 0x14, 0x99130110 }, /* speaker */
7152 { 0x15, 0x0121441f }, /* HP */
7153 { 0x16, 0x99130111 }, /* speaker */
7154 { 0x18, 0x01a19840 }, /* mic */
7155 { 0x19, 0x99a3094f }, /* int-mic */
7156 { }
7157 },
7158 .chained = true,
7159 .chain_id = ALC662_FIXUP_SKU_IGNORE
7160 },
7161 [ALC662_FIXUP_ASUS_MODE6] = {
7162 .type = ALC_FIXUP_PINS,
7163 .v.pins = (const struct alc_pincfg[]) {
7164 { 0x14, 0x99130110 }, /* speaker */
7165 { 0x15, 0x01211420 }, /* HP2 */
7166 { 0x18, 0x01a19840 }, /* mic */
7167 { 0x19, 0x99a3094f }, /* int-mic */
7168 { 0x1b, 0x0121441f }, /* HP */
7169 { }
7170 },
7171 .chained = true,
7172 .chain_id = ALC662_FIXUP_SKU_IGNORE
7173 },
7174 [ALC662_FIXUP_ASUS_MODE7] = {
7175 .type = ALC_FIXUP_PINS,
7176 .v.pins = (const struct alc_pincfg[]) {
7177 { 0x14, 0x99130110 }, /* speaker */
7178 { 0x17, 0x99130111 }, /* speaker */
7179 { 0x18, 0x01a19840 }, /* mic */
7180 { 0x19, 0x99a3094f }, /* int-mic */
7181 { 0x1b, 0x01214020 }, /* HP */
7182 { 0x21, 0x0121401f }, /* HP */
7183 { }
7184 },
7185 .chained = true,
7186 .chain_id = ALC662_FIXUP_SKU_IGNORE
7187 },
7188 [ALC662_FIXUP_ASUS_MODE8] = {
7189 .type = ALC_FIXUP_PINS,
7190 .v.pins = (const struct alc_pincfg[]) {
7191 { 0x14, 0x99130110 }, /* speaker */
7192 { 0x12, 0x99a30970 }, /* int-mic */
7193 { 0x15, 0x01214020 }, /* HP */
7194 { 0x17, 0x99130111 }, /* speaker */
7195 { 0x18, 0x01a19840 }, /* mic */
7196 { 0x21, 0x0121401f }, /* HP */
7197 { }
7198 },
7199 .chained = true,
7200 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007201 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007202 [ALC662_FIXUP_NO_JACK_DETECT] = {
7203 .type = ALC_FIXUP_FUNC,
7204 .v.func = alc_fixup_no_jack_detect,
7205 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007206 [ALC662_FIXUP_ZOTAC_Z68] = {
7207 .type = ALC_FIXUP_PINS,
7208 .v.pins = (const struct alc_pincfg[]) {
7209 { 0x1b, 0x02214020 }, /* Front HP */
7210 { }
7211 }
7212 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007213 [ALC662_FIXUP_INV_DMIC] = {
7214 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007215 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007216 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007217};
7218
Takashi Iwaia9111322011-05-02 11:30:18 +02007219static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007220 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007221 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007222 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007223 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007224 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007225 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007226 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007227 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007228 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007229 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007230 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007231 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007232 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007233
7234#if 0
7235 /* Below is a quirk table taken from the old code.
7236 * Basically the device should work as is without the fixup table.
7237 * If BIOS doesn't give a proper info, enable the corresponding
7238 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007239 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007240 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7241 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7242 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7243 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7244 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7245 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7246 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7247 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7248 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7249 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7250 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7251 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7252 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7253 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7254 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7255 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7256 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7257 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7258 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7259 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7260 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7261 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7262 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7263 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7264 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7265 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7266 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7267 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7268 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7269 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7270 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7271 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7272 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7273 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7274 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7275 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7276 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7277 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7278 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7279 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7280 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7281 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7282 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7283 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7284 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7285 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7286 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7287 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7288 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7289 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7290#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007291 {}
7292};
7293
Todd Broch6be79482010-12-07 16:51:05 -08007294static const struct alc_model_fixup alc662_fixup_models[] = {
7295 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007296 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7297 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7298 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7299 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7300 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7301 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7302 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7303 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007304 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007305 {}
7306};
David Henningsson6cb3b702010-09-09 08:51:44 +02007307
Kailang Yang8663ff72012-06-29 09:35:52 +02007308static void alc662_fill_coef(struct hda_codec *codec)
7309{
7310 int val, coef;
7311
7312 coef = alc_get_coef0(codec);
7313
7314 switch (codec->vendor_id) {
7315 case 0x10ec0662:
7316 if ((coef & 0x00f0) == 0x0030) {
7317 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7318 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7319 }
7320 break;
7321 case 0x10ec0272:
7322 case 0x10ec0273:
7323 case 0x10ec0663:
7324 case 0x10ec0665:
7325 case 0x10ec0670:
7326 case 0x10ec0671:
7327 case 0x10ec0672:
7328 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7329 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7330 break;
7331 }
7332}
David Henningsson6cb3b702010-09-09 08:51:44 +02007333
Takashi Iwai1d045db2011-07-07 18:23:21 +02007334/*
7335 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007336static int patch_alc662(struct hda_codec *codec)
7337{
7338 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007339 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007340
Takashi Iwai3de95172012-05-07 18:03:15 +02007341 err = alc_alloc_spec(codec, 0x0b);
7342 if (err < 0)
7343 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007344
Takashi Iwai3de95172012-05-07 18:03:15 +02007345 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007346
Takashi Iwai53c334a2011-08-23 18:27:14 +02007347 /* handle multiple HPs as is */
7348 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7349
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007350 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7351
Kailang Yang8663ff72012-06-29 09:35:52 +02007352 spec->init_hook = alc662_fill_coef;
7353 alc662_fill_coef(codec);
7354
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007355 alc_pick_fixup(codec, alc662_fixup_models,
7356 alc662_fixup_tbl, alc662_fixups);
7357 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7358
7359 alc_auto_parse_customize_define(codec);
7360
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007361 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007362 codec->bus->pci->subsystem_vendor == 0x1025 &&
7363 spec->cdefine.platform_type == 1) {
7364 if (alc_codec_rename(codec, "ALC272X") < 0)
7365 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007366 }
Kailang Yang274693f2009-12-03 10:07:50 +01007367
Takashi Iwaib9c51062011-08-24 18:08:07 +02007368 /* automatic parse from the BIOS config */
7369 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007370 if (err < 0)
7371 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007372
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007373 if (!spec->no_analog && has_cdefine_beep(codec)) {
7374 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007375 if (err < 0)
7376 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007377 switch (codec->vendor_id) {
7378 case 0x10ec0662:
7379 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7380 break;
7381 case 0x10ec0272:
7382 case 0x10ec0663:
7383 case 0x10ec0665:
7384 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7385 break;
7386 case 0x10ec0273:
7387 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7388 break;
7389 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007390 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007391
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007392 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007393 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007394
Takashi Iwai589876e2012-02-20 15:47:55 +01007395 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7396
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007397 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007398
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007399 error:
7400 alc_free(codec);
7401 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007402}
7403
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007404/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007405 * ALC680 support
7406 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007407
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007408static int alc680_parse_auto_config(struct hda_codec *codec)
7409{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007410 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007411}
7412
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007413/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007414 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007415static int patch_alc680(struct hda_codec *codec)
7416{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007417 int err;
7418
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007419 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007420 err = alc_alloc_spec(codec, 0);
7421 if (err < 0)
7422 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007423
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007424 /* automatic parse from the BIOS config */
7425 err = alc680_parse_auto_config(codec);
7426 if (err < 0) {
7427 alc_free(codec);
7428 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007429 }
7430
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007431 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007432
7433 return 0;
7434}
7435
7436/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007437 * patch entries
7438 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007439static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007440 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007441 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007442 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007443 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007444 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007445 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007446 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007447 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007448 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007449 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007450 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007451 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007452 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007453 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007454 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007455 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007456 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007457 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007458 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7459 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7460 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007461 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007462 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007463 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7464 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007465 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7466 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007467 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007468 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007469 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007470 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007471 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007472 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007473 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007474 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007475 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007476 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007477 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007478 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007479 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007480 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007481 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007482 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007483 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007484 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007485 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007486 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007487 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007488 {} /* terminator */
7489};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007490
7491MODULE_ALIAS("snd-hda-codec-id:10ec*");
7492
7493MODULE_LICENSE("GPL");
7494MODULE_DESCRIPTION("Realtek HD-audio codec");
7495
7496static struct hda_codec_preset_list realtek_list = {
7497 .preset = snd_hda_preset_realtek,
7498 .owner = THIS_MODULE,
7499};
7500
7501static int __init patch_realtek_init(void)
7502{
7503 return snd_hda_add_codec_preset(&realtek_list);
7504}
7505
7506static void __exit patch_realtek_exit(void)
7507{
7508 snd_hda_delete_codec_preset(&realtek_list);
7509}
7510
7511module_init(patch_realtek_init)
7512module_exit(patch_realtek_exit)