blob: fbc4a97ea8f6daaf55324cbcf4a20a251d9e2ad8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe409a3e92012-03-27 13:01:01 +10309 * Jonathan Woithe <jwoithe@just42.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Takashi Iwai23d30f22012-05-07 17:17:32 +020035#include "hda_auto_parser.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090036#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020037#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Takashi Iwai1d045db2011-07-07 18:23:21 +020039/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020044
Kailang Yangdf694da2005-12-05 19:42:22 +010045/* for GPIO Poll */
46#define GPIO_MASK 0x03
47
Takashi Iwai4a79ba32009-04-22 16:31:35 +020048/* extra amp-initialization sequence types */
49enum {
50 ALC_INIT_NONE,
51 ALC_INIT_DEFAULT,
52 ALC_INIT_GPIO1,
53 ALC_INIT_GPIO2,
54 ALC_INIT_GPIO3,
55};
56
Kailang Yangda00c242010-03-19 11:23:45 +010057struct alc_customize_define {
58 unsigned int sku_cfg;
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
65 unsigned int swap:1;
66 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020067 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010068};
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Takashi Iwaic14c95f2012-02-16 16:38:07 +010082#define MAX_VOL_NIDS 0x40
83
Takashi Iwai23d30f22012-05-07 17:17:32 +020084/* make compatible with old code */
85#define alc_apply_pincfgs snd_hda_apply_pincfgs
86#define alc_apply_fixup snd_hda_apply_fixup
87#define alc_pick_fixup snd_hda_pick_fixup
88#define alc_fixup hda_fixup
89#define alc_pincfg hda_pintbl
90#define alc_model_fixup hda_model_fixup
91
92#define ALC_FIXUP_PINS HDA_FIXUP_PINS
93#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
95
96#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
100
101
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100102#define MAX_NID_PATH_DEPTH 5
103
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100104/* Widget connection path
105 *
106 * For output, stored in the order of DAC -> ... -> pin,
107 * for input, pin -> ... -> ADC.
108 *
Takashi Iwai95e960c2012-12-10 17:27:57 +0100109 * idx[i] contains the source index number to select on of the widget path[i];
110 * e.g. idx[1] is the index of the DAC (path[0]) selected by path[1] widget
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100111 * multi[] indicates whether it's a selector widget with multi-connectors
112 * (i.e. the connection selection is mandatory)
113 * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
114 */
115struct nid_path {
116 int depth;
117 hda_nid_t path[MAX_NID_PATH_DEPTH];
118 unsigned char idx[MAX_NID_PATH_DEPTH];
119 unsigned char multi[MAX_NID_PATH_DEPTH];
120 unsigned int ctls[2]; /* 0 = volume, 1 = mute */
121};
122
Takashi Iwaiba8111272012-12-06 18:06:23 +0100123enum { NID_PATH_VOL_CTL = 0, NID_PATH_MUTE_CTL = 1 };
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200126 struct hda_gen_spec gen;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200129 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200131 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100132 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200134 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200135 const struct hda_pcm_stream *stream_analog_playback;
136 const struct hda_pcm_stream *stream_analog_capture;
137 const struct hda_pcm_stream *stream_analog_alt_playback;
138 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200140 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200141 const struct hda_pcm_stream *stream_digital_playback;
142 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200145 struct hda_multi_out multiout; /* playback set-up
146 * max_channels, dacs must be set
147 * dig_out_nid and hp_nid are optional
148 */
Takashi Iwai63300792008-01-24 15:31:36 +0100149 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100150 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100151 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* capture */
154 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200155 const hda_nid_t *adc_nids;
156 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200157 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200158 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Takashi Iwai840b64c2010-07-13 22:49:01 +0200160 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200161 hda_nid_t cur_adc;
162 unsigned int cur_adc_stream_tag;
163 unsigned int cur_adc_format;
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200166 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 const struct hda_input_mux *input_mux;
168 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200169 hda_nid_t ext_mic_pin;
170 hda_nid_t dock_mic_pin;
171 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100174 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200176 int need_dac_fix;
Takashi Iwaib6adb572012-12-03 10:30:58 +0100177 int const_channel_count; /* min. channel count (for speakers) */
178 int ext_channel_count; /* current channel count for multi-io */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100181 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200182
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200183 /* dynamic controls, init_verbs and input_mux */
184 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100185 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200186 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200187 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200188 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200189 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
190 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200191 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
192 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
193 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200194 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100195
Takashi Iwai463419d2012-12-05 14:17:37 +0100196 /* DAC list */
197 int num_all_dacs;
198 hda_nid_t all_dacs[16];
199
Takashi Iwai30dcd3b2012-12-06 15:45:38 +0100200 /* output paths */
201 struct snd_array out_path;
202
Takashi Iwai36f0fd52012-12-12 17:25:00 +0100203 /* input paths */
204 struct snd_array in_path;
205
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100206 /* hooks */
207 void (*init_hook)(struct hda_codec *codec);
Takashi Iwai83012a72012-08-24 18:38:08 +0200208#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -0500209 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100210#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200211 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200212 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100213
Takashi Iwai834be882006-03-01 14:16:17 +0100214 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200215 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200216 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200217 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200218 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200219 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200220 unsigned int automute_speaker:1; /* automute speaker outputs */
221 unsigned int automute_lo:1; /* automute LO outputs */
222 unsigned int detect_hp:1; /* Headphone detection enabled */
223 unsigned int detect_lo:1; /* Line-out detection enabled */
224 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
225 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100226 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200227
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100228 /* other flags */
229 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200230 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100231 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200232 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200233 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100234 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200235 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
236 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaie427c232012-07-29 10:04:08 +0200237 unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
Takashi Iwaid922b512011-04-28 12:18:53 +0200238
239 /* auto-mute control */
240 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200241 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200242
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200243 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200244 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100245
Takashi Iwai2134ea42008-01-10 16:53:55 +0100246 /* for virtual master */
247 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100248 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwai83012a72012-08-24 18:38:08 +0200249#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +0200250 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100251 int num_loopbacks;
252 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200253#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200254
255 /* for PLL fix */
256 hda_nid_t pll_nid;
257 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200258 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100259
Takashi Iwaice764ab2011-04-27 16:35:23 +0200260 /* multi-io */
261 int multi_ios;
262 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200263
264 /* bind volumes */
265 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100266};
267
Takashi Iwai44c02402011-07-08 15:14:19 +0200268static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
269 int dir, unsigned int bits)
270{
271 if (!nid)
272 return false;
273 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
274 if (query_amp_caps(codec, nid, dir) & bits)
275 return true;
276 return false;
277}
278
279#define nid_has_mute(codec, nid, dir) \
280 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
281#define nid_has_volume(codec, nid, dir) \
282 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284/*
285 * input MUX handling
286 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200287static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
288 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
291 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200292 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
293 if (mux_idx >= spec->num_mux_defs)
294 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100295 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
296 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200297 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200300static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
304 struct alc_spec *spec = codec->spec;
305 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
306
307 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
308 return 0;
309}
310
Takashi Iwai21268962011-07-07 15:01:13 +0200311static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Takashi Iwai21268962011-07-07 15:01:13 +0200313 struct alc_spec *spec = codec->spec;
314 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
315
316 if (spec->cur_adc && spec->cur_adc != new_adc) {
317 /* stream is running, let's swap the current ADC */
318 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
319 spec->cur_adc = new_adc;
320 snd_hda_codec_setup_stream(codec, new_adc,
321 spec->cur_adc_stream_tag, 0,
322 spec->cur_adc_format);
323 return true;
324 }
325 return false;
326}
327
Takashi Iwai61071592011-11-23 07:52:15 +0100328static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
329{
330 return spec->capsrc_nids ?
331 spec->capsrc_nids[idx] : spec->adc_nids[idx];
332}
333
Takashi Iwai24de1832011-11-07 17:13:39 +0100334static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200335static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100336
David Henningsson00227f12012-06-27 18:45:44 +0200337/* for shared I/O, change the pin-control accordingly */
338static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
339{
340 struct alc_spec *spec = codec->spec;
341 unsigned int val;
342 hda_nid_t pin = spec->autocfg.inputs[1].pin;
343 /* NOTE: this assumes that there are only two inputs, the
344 * first is the real internal mic and the second is HP/mic jack.
345 */
346
347 val = snd_hda_get_default_vref(codec, pin);
348
349 /* This pin does not have vref caps - let's enable vref on pin 0x18
350 instead, as suggested by Realtek */
351 if (val == AC_PINCTL_VREF_HIZ) {
352 const hda_nid_t vref_pin = 0x18;
353 /* Sanity check pin 0x18 */
354 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
355 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
356 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
357 if (vref_val != AC_PINCTL_VREF_HIZ)
358 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
359 }
360 }
361
362 val = set_as_mic ? val | PIN_IN : PIN_HP;
363 snd_hda_set_pin_ctl(codec, pin, val);
364
365 spec->automute_speaker = !set_as_mic;
366 call_update_outputs(codec);
367}
Takashi Iwai21268962011-07-07 15:01:13 +0200368
369/* select the given imux item; either unmute exclusively or select the route */
370static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
371 unsigned int idx, bool force)
372{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100374 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100375 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100376 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200377 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Takashi Iwai5803a322012-02-21 11:59:45 +0100379 if (!spec->input_mux)
380 return 0;
381
Takashi Iwaicd896c32008-11-18 12:36:33 +0100382 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
383 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100384 if (!imux->num_items && mux_idx > 0)
385 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100386 if (!imux->num_items)
387 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100388
Takashi Iwai21268962011-07-07 15:01:13 +0200389 if (idx >= imux->num_items)
390 idx = imux->num_items - 1;
391 if (spec->cur_mux[adc_idx] == idx && !force)
392 return 0;
393 spec->cur_mux[adc_idx] = idx;
394
David Henningsson00227f12012-06-27 18:45:44 +0200395 if (spec->shared_mic_hp)
396 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100397
Takashi Iwai21268962011-07-07 15:01:13 +0200398 if (spec->dyn_adc_switch) {
399 alc_dyn_adc_pcm_resetup(codec, idx);
400 adc_idx = spec->dyn_adc_idx[idx];
401 }
402
Takashi Iwai61071592011-11-23 07:52:15 +0100403 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200404
405 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200406 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100407 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200408 return 1;
409
Takashi Iwaia22d5432009-07-27 12:54:26 +0200410 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200411 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100412 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100413 int active = imux->items[idx].index;
414 for (i = 0; i < num_conns; i++) {
415 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
416 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100417 HDA_AMP_MUTE, v);
418 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100419 } else {
420 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200421 snd_hda_codec_write_cache(codec, nid, 0,
422 AC_VERB_SET_CONNECT_SEL,
423 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100424 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200425 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200426 return 1;
427}
428
429static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
430 struct snd_ctl_elem_value *ucontrol)
431{
432 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
433 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
434 return alc_mux_select(codec, adc_idx,
435 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100436}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100439 * set up the input pin config (depending on the given auto-pin type)
440 */
441static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
442 int auto_pin_type)
443{
444 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200445 if (auto_pin_type == AUTO_PIN_MIC)
446 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200447 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100448}
449
450/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200451 * Append the given mixer and verb elements for the later use
452 * The mixer array is referred in build_controls(), and init_verbs are
453 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100454 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200455static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100456{
457 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
458 return;
459 spec->mixers[spec->num_mixers++] = mix;
460}
461
Takashi Iwaid88897e2008-10-31 15:01:37 +0100462/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200463 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100464 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200465/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200466static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200467 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
468 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
469 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
470 { }
471};
472
Takashi Iwaia9111322011-05-02 11:30:18 +0200473static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200474 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
475 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
476 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
477 { }
478};
479
Takashi Iwaia9111322011-05-02 11:30:18 +0200480static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200481 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
482 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
483 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
484 { }
485};
486
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200487/*
488 * Fix hardware PLL issue
489 * On some codecs, the analog PLL gating control must be off while
490 * the default value is 1.
491 */
492static void alc_fix_pll(struct hda_codec *codec)
493{
494 struct alc_spec *spec = codec->spec;
495 unsigned int val;
496
497 if (!spec->pll_nid)
498 return;
499 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
500 spec->pll_coef_idx);
501 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
502 AC_VERB_GET_PROC_COEF, 0);
503 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
504 spec->pll_coef_idx);
505 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
506 val & ~(1 << spec->pll_coef_bit));
507}
508
509static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
510 unsigned int coef_idx, unsigned int coef_bit)
511{
512 struct alc_spec *spec = codec->spec;
513 spec->pll_nid = nid;
514 spec->pll_coef_idx = coef_idx;
515 spec->pll_coef_bit = coef_bit;
516 alc_fix_pll(codec);
517}
518
Takashi Iwai1d045db2011-07-07 18:23:21 +0200519/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200520 * Jack detections for HP auto-mute and mic-switch
521 */
522
523/* check each pin in the given array; returns true if any of them is plugged */
524static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200525{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200527
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200528 for (i = 0; i < num_pins; i++) {
529 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200530 if (!nid)
531 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200533 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200534 return present;
535}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200536
Takashi Iwai1d045db2011-07-07 18:23:21 +0200537/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200538static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200539 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200540{
541 struct alc_spec *spec = codec->spec;
542 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200543 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200544 int i;
545
546 for (i = 0; i < num_pins; i++) {
547 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100548 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200549 if (!nid)
550 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200551 switch (spec->automute_mode) {
552 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100553 /* don't reset VREF value in case it's controlling
554 * the amp (see alc861_fixup_asus_amp_vref_0f())
555 */
556 if (spec->keep_vref_in_automute) {
557 val = snd_hda_codec_read(codec, nid, 0,
558 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
559 val &= ~PIN_HP;
560 } else
561 val = 0;
562 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200563 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200564 break;
565 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200566 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200568 break;
569 case ALC_AUTOMUTE_MIXER:
570 nid = spec->automute_mixer_nid[i];
571 if (!nid)
572 break;
573 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200574 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200575 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200576 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200577 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200578 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200579 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200580}
581
David Henningsson42cf0d02011-09-20 12:04:56 +0200582/* Toggle outputs muting */
583static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200584{
585 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200586 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587
Takashi Iwaic0a20262011-06-10 15:28:15 +0200588 /* Control HP pins/amps depending on master_mute state;
589 * in general, HP pins/amps control should be enabled in all cases,
590 * but currently set only for master_mute, just to be safe
591 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100592 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
593 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200594 spec->autocfg.hp_pins, spec->master_mute, true);
595
David Henningsson42cf0d02011-09-20 12:04:56 +0200596 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200597 on = 0;
598 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200599 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200600 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200601 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200602 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200603
604 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200605 /* if LO is a copy of either HP or Speaker, don't need to handle it */
606 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
607 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200609 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200610 on = 0;
611 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200612 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200613 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200614 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200615 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200616}
617
David Henningsson42cf0d02011-09-20 12:04:56 +0200618static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200619{
620 struct alc_spec *spec = codec->spec;
621 if (spec->automute_hook)
622 spec->automute_hook(codec);
623 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200624 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200625}
626
Takashi Iwai1d045db2011-07-07 18:23:21 +0200627/* standard HP-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200628static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200629{
630 struct alc_spec *spec = codec->spec;
631
David Henningsson42cf0d02011-09-20 12:04:56 +0200632 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200633 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
634 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200635 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200636 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200637 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200638}
639
Takashi Iwai1d045db2011-07-07 18:23:21 +0200640/* standard line-out-automute helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200641static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200642{
643 struct alc_spec *spec = codec->spec;
644
David Henningssonf7f4b232012-10-10 16:32:09 +0200645 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
646 return;
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200647 /* check LO jack only when it's different from HP */
648 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
649 return;
650
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200651 spec->line_jack_present =
652 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
653 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200654 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200655 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200656 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200657}
658
Takashi Iwai8d087c72011-06-28 12:45:47 +0200659#define get_connection_index(codec, mux, nid) \
660 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200661
Takashi Iwai1d045db2011-07-07 18:23:21 +0200662/* standard mic auto-switch helper */
David Henningsson29adc4b2012-09-25 11:31:00 +0200663static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
Kailang Yang7fb0d782008-10-15 11:12:35 +0200664{
665 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200666 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200667
Takashi Iwai21268962011-07-07 15:01:13 +0200668 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200669 return;
670 if (snd_BUG_ON(!spec->adc_nids))
671 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200672 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200673 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200674
Takashi Iwai21268962011-07-07 15:01:13 +0200675 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
676 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
677 else if (spec->dock_mic_idx >= 0 &&
678 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
679 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
680 else
681 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200682}
683
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100684/* update the master volume per volume-knob's unsol event */
David Henningsson29adc4b2012-09-25 11:31:00 +0200685static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100686{
687 unsigned int val;
688 struct snd_kcontrol *kctl;
689 struct snd_ctl_elem_value *uctl;
690
691 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
692 if (!kctl)
693 return;
694 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
695 if (!uctl)
696 return;
David Henningsson29adc4b2012-09-25 11:31:00 +0200697 val = snd_hda_codec_read(codec, jack->nid, 0,
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100698 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
699 val &= HDA_AMP_VOLMASK;
700 uctl->value.integer.value[0] = val;
701 uctl->value.integer.value[1] = val;
702 kctl->put(kctl, uctl);
703 kfree(uctl);
704}
705
David Henningsson29adc4b2012-09-25 11:31:00 +0200706static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100707{
David Henningsson29adc4b2012-09-25 11:31:00 +0200708 /* For some reason, the res given from ALC880 is broken.
709 Here we adjust it properly. */
710 snd_hda_jack_unsol_event(codec, res >> 2);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100711}
712
Takashi Iwai1d045db2011-07-07 18:23:21 +0200713/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200714static void alc_inithook(struct hda_codec *codec)
715{
David Henningsson29adc4b2012-09-25 11:31:00 +0200716 alc_hp_automute(codec, NULL);
717 alc_line_automute(codec, NULL);
718 alc_mic_automute(codec, NULL);
Kailang Yangc9b58002007-10-16 14:30:01 +0200719}
720
Kailang Yangf9423e72008-05-27 12:32:25 +0200721/* additional initialization for ALC888 variants */
722static void alc888_coef_init(struct hda_codec *codec)
723{
724 unsigned int tmp;
725
726 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
727 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
728 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100729 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200730 /* alc888S-VC */
731 snd_hda_codec_read(codec, 0x20, 0,
732 AC_VERB_SET_PROC_COEF, 0x830);
733 else
734 /* alc888-VB */
735 snd_hda_codec_read(codec, 0x20, 0,
736 AC_VERB_SET_PROC_COEF, 0x3030);
737}
738
Takashi Iwai1d045db2011-07-07 18:23:21 +0200739/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200740static void alc889_coef_init(struct hda_codec *codec)
741{
742 unsigned int tmp;
743
744 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
745 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
746 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
747 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
748}
749
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100750/* turn on/off EAPD control (only if available) */
751static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
752{
753 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
754 return;
755 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
756 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
757 on ? 2 : 0);
758}
759
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200760/* turn on/off EAPD controls of the codec */
761static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
762{
763 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200764 static hda_nid_t pins[] = {
765 0x0f, 0x10, 0x14, 0x15, 0
766 };
767 hda_nid_t *p;
768 for (p = pins; *p; p++)
769 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200770}
771
Takashi Iwai1c716152011-04-07 10:37:16 +0200772/* generic shutup callback;
773 * just turning off EPAD and a little pause for avoiding pop-noise
774 */
775static void alc_eapd_shutup(struct hda_codec *codec)
776{
777 alc_auto_setup_eapd(codec, false);
778 msleep(200);
779}
780
Takashi Iwai1d045db2011-07-07 18:23:21 +0200781/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200782static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200783{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200784 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200785
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200786 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200787 switch (type) {
788 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200789 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
790 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200791 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200792 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
793 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200794 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200795 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
796 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200797 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200798 switch (codec->vendor_id) {
799 case 0x10ec0260:
800 snd_hda_codec_write(codec, 0x1a, 0,
801 AC_VERB_SET_COEF_INDEX, 7);
802 tmp = snd_hda_codec_read(codec, 0x1a, 0,
803 AC_VERB_GET_PROC_COEF, 0);
804 snd_hda_codec_write(codec, 0x1a, 0,
805 AC_VERB_SET_COEF_INDEX, 7);
806 snd_hda_codec_write(codec, 0x1a, 0,
807 AC_VERB_SET_PROC_COEF,
808 tmp | 0x2010);
809 break;
810 case 0x10ec0262:
811 case 0x10ec0880:
812 case 0x10ec0882:
813 case 0x10ec0883:
814 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100815 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100816 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200817 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200818 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200819 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200820 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200821 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100822#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200823 case 0x10ec0267:
824 case 0x10ec0268:
825 snd_hda_codec_write(codec, 0x20, 0,
826 AC_VERB_SET_COEF_INDEX, 7);
827 tmp = snd_hda_codec_read(codec, 0x20, 0,
828 AC_VERB_GET_PROC_COEF, 0);
829 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200830 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200831 snd_hda_codec_write(codec, 0x20, 0,
832 AC_VERB_SET_PROC_COEF,
833 tmp | 0x3000);
834 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100835#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200836 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200837 break;
838 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200839}
Kailang Yangea1fb292008-08-26 12:58:38 +0200840
Takashi Iwai1d045db2011-07-07 18:23:21 +0200841/*
842 * Auto-Mute mode mixer enum support
843 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200844static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
845 struct snd_ctl_elem_info *uinfo)
846{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200847 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
848 struct alc_spec *spec = codec->spec;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200849 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100850 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200851 };
852
Takashi Iwaidda415d2012-11-30 18:34:38 +0100853 if (spec->automute_speaker_possible && spec->automute_lo_possible)
854 return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
855 return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856}
857
858static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
859 struct snd_ctl_elem_value *ucontrol)
860{
861 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
862 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200863 unsigned int val = 0;
864 if (spec->automute_speaker)
865 val++;
866 if (spec->automute_lo)
867 val++;
868
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200869 ucontrol->value.enumerated.item[0] = val;
870 return 0;
871}
872
873static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
874 struct snd_ctl_elem_value *ucontrol)
875{
876 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
877 struct alc_spec *spec = codec->spec;
878
879 switch (ucontrol->value.enumerated.item[0]) {
880 case 0:
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 = 0;
884 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 break;
886 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200887 if (spec->automute_speaker_possible) {
888 if (!spec->automute_lo && spec->automute_speaker)
889 return 0;
890 spec->automute_speaker = 1;
891 spec->automute_lo = 0;
892 } else if (spec->automute_lo_possible) {
893 if (spec->automute_lo)
894 return 0;
895 spec->automute_lo = 1;
896 } else
897 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200898 break;
899 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200900 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200901 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200902 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200903 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200904 spec->automute_speaker = 1;
905 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200906 break;
907 default:
908 return -EINVAL;
909 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200910 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200911 return 1;
912}
913
Takashi Iwaia9111322011-05-02 11:30:18 +0200914static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200915 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
916 .name = "Auto-Mute Mode",
917 .info = alc_automute_mode_info,
918 .get = alc_automute_mode_get,
919 .put = alc_automute_mode_put,
920};
921
Takashi Iwai668d1e92012-11-29 14:10:17 +0100922static struct snd_kcontrol_new *
923alc_kcontrol_new(struct alc_spec *spec, const char *name,
924 const struct snd_kcontrol_new *temp)
Takashi Iwai1d045db2011-07-07 18:23:21 +0200925{
Takashi Iwai668d1e92012-11-29 14:10:17 +0100926 struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
927 if (!knew)
928 return NULL;
929 *knew = *temp;
930 knew->name = kstrdup(name, GFP_KERNEL);
931 if (!knew->name)
932 return NULL;
933 return knew;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200934}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200935
936static int alc_add_automute_mode_enum(struct hda_codec *codec)
937{
938 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200939
Takashi Iwai668d1e92012-11-29 14:10:17 +0100940 if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200941 return -ENOMEM;
942 return 0;
943}
944
Takashi Iwai1d045db2011-07-07 18:23:21 +0200945/*
946 * Check the availability of HP/line-out auto-mute;
947 * Set up appropriately if really supported
948 */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100949static int alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200950{
951 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200952 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200953 int present = 0;
Takashi Iwai475c3d22012-11-30 08:31:30 +0100954 int i, err;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200955
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200956 if (cfg->hp_pins[0])
957 present++;
958 if (cfg->line_out_pins[0])
959 present++;
960 if (cfg->speaker_pins[0])
961 present++;
962 if (present < 2) /* need two different output types */
Takashi Iwai475c3d22012-11-30 08:31:30 +0100963 return 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200964
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200965 if (!cfg->speaker_pins[0] &&
966 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200967 memcpy(cfg->speaker_pins, cfg->line_out_pins,
968 sizeof(cfg->speaker_pins));
969 cfg->speaker_outs = cfg->line_outs;
970 }
971
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200972 if (!cfg->hp_pins[0] &&
973 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200974 memcpy(cfg->hp_pins, cfg->line_out_pins,
975 sizeof(cfg->hp_pins));
976 cfg->hp_outs = cfg->line_outs;
977 }
978
David Henningsson42cf0d02011-09-20 12:04:56 +0200979 spec->automute_mode = ALC_AUTOMUTE_PIN;
980
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200981 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200982 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200983 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200984 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200985 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200986 nid);
David Henningsson29adc4b2012-09-25 11:31:00 +0200987 snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
988 alc_hp_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +0200989 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200990 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200991
David Henningsson42cf0d02011-09-20 12:04:56 +0200992 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
993 if (cfg->speaker_outs)
994 for (i = 0; i < cfg->line_outs; i++) {
995 hda_nid_t nid = cfg->line_out_pins[i];
996 if (!is_jack_detectable(codec, nid))
997 continue;
998 snd_printdd("realtek: Enable Line-Out "
999 "auto-muting on NID 0x%x\n", nid);
David Henningsson29adc4b2012-09-25 11:31:00 +02001000 snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
1001 alc_line_automute);
David Henningsson42cf0d02011-09-20 12:04:56 +02001002 spec->detect_lo = 1;
David Henningsson29adc4b2012-09-25 11:31:00 +02001003 }
David Henningsson42cf0d02011-09-20 12:04:56 +02001004 spec->automute_lo_possible = spec->detect_hp;
1005 }
1006
1007 spec->automute_speaker_possible = cfg->speaker_outs &&
1008 (spec->detect_hp || spec->detect_lo);
1009
1010 spec->automute_lo = spec->automute_lo_possible;
1011 spec->automute_speaker = spec->automute_speaker_possible;
1012
Takashi Iwai475c3d22012-11-30 08:31:30 +01001013 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001014 /* create a control for automute mode */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001015 err = alc_add_automute_mode_enum(codec);
1016 if (err < 0)
1017 return err;
1018 }
1019 return 0;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001020}
1021
Takashi Iwai1d045db2011-07-07 18:23:21 +02001022/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001023static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1024{
1025 int i;
1026 for (i = 0; i < nums; i++)
1027 if (list[i] == nid)
1028 return i;
1029 return -1;
1030}
1031
Takashi Iwai1d045db2011-07-07 18:23:21 +02001032/* check whether dynamic ADC-switching is available */
1033static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1034{
1035 struct alc_spec *spec = codec->spec;
1036 struct hda_input_mux *imux = &spec->private_imux[0];
1037 int i, n, idx;
1038 hda_nid_t cap, pin;
1039
1040 if (imux != spec->input_mux) /* no dynamic imux? */
1041 return false;
1042
1043 for (n = 0; n < spec->num_adc_nids; n++) {
1044 cap = spec->private_capsrc_nids[n];
1045 for (i = 0; i < imux->num_items; i++) {
1046 pin = spec->imux_pins[i];
1047 if (!pin)
1048 return false;
1049 if (get_connection_index(codec, cap, pin) < 0)
1050 break;
1051 }
1052 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001053 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001054 }
1055
1056 for (i = 0; i < imux->num_items; i++) {
1057 pin = spec->imux_pins[i];
1058 for (n = 0; n < spec->num_adc_nids; n++) {
1059 cap = spec->private_capsrc_nids[n];
1060 idx = get_connection_index(codec, cap, pin);
1061 if (idx >= 0) {
1062 imux->items[i].index = idx;
1063 spec->dyn_adc_idx[i] = n;
1064 break;
1065 }
1066 }
1067 }
1068
1069 snd_printdd("realtek: enabling ADC switching\n");
1070 spec->dyn_adc_switch = 1;
1071 return true;
1072}
Takashi Iwai21268962011-07-07 15:01:13 +02001073
Takashi Iwai21268962011-07-07 15:01:13 +02001074/* check whether all auto-mic pins are valid; setup indices if OK */
1075static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1076{
1077 struct alc_spec *spec = codec->spec;
1078 const struct hda_input_mux *imux;
1079
1080 if (!spec->auto_mic)
1081 return false;
1082 if (spec->auto_mic_valid_imux)
1083 return true; /* already checked */
1084
1085 /* fill up imux indices */
1086 if (!alc_check_dyn_adc_switch(codec)) {
1087 spec->auto_mic = 0;
1088 return false;
1089 }
1090
1091 imux = spec->input_mux;
1092 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1093 spec->imux_pins, imux->num_items);
1094 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1095 spec->imux_pins, imux->num_items);
1096 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1097 spec->imux_pins, imux->num_items);
1098 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1099 spec->auto_mic = 0;
1100 return false; /* no corresponding imux */
1101 }
1102
David Henningsson29adc4b2012-09-25 11:31:00 +02001103 snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
1104 ALC_MIC_EVENT, alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001105 if (spec->dock_mic_pin)
David Henningsson29adc4b2012-09-25 11:31:00 +02001106 snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
1107 ALC_MIC_EVENT,
1108 alc_mic_automute);
Takashi Iwai21268962011-07-07 15:01:13 +02001109
1110 spec->auto_mic_valid_imux = 1;
1111 spec->auto_mic = 1;
1112 return true;
1113}
1114
Takashi Iwai1d045db2011-07-07 18:23:21 +02001115/*
1116 * Check the availability of auto-mic switch;
1117 * Set up if really supported
1118 */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001119static int alc_init_auto_mic(struct hda_codec *codec)
Takashi Iwai6c819492009-08-10 18:47:44 +02001120{
1121 struct alc_spec *spec = codec->spec;
1122 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001123 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001124 int i;
1125
Takashi Iwai24de1832011-11-07 17:13:39 +01001126 if (spec->shared_mic_hp)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001127 return 0; /* no auto-mic for the shared I/O */
Takashi Iwai24de1832011-11-07 17:13:39 +01001128
Takashi Iwai21268962011-07-07 15:01:13 +02001129 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1130
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001131 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001132 for (i = 0; i < cfg->num_inputs; i++) {
1133 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001134 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001135 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001136 switch (snd_hda_get_input_pin_attr(defcfg)) {
1137 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001138 if (fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001139 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001140 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001141 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001142 fixed = nid;
1143 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001144 case INPUT_PIN_ATTR_UNUSED:
Takashi Iwai475c3d22012-11-30 08:31:30 +01001145 return 0; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001146 case INPUT_PIN_ATTR_DOCK:
1147 if (dock)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001148 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001149 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001150 return 0; /* invalid type */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001151 dock = nid;
1152 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001153 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001154 if (ext)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001155 return 0; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001156 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001157 return 0; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001158 ext = nid;
1159 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001160 }
1161 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001162 if (!ext && dock) {
1163 ext = dock;
1164 dock = 0;
1165 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001166 if (!ext || !fixed)
Takashi Iwai475c3d22012-11-30 08:31:30 +01001167 return 0;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001168 if (!is_jack_detectable(codec, ext))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001169 return 0; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001170 if (dock && !is_jack_detectable(codec, dock))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001171 return 0; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001172
1173 /* check imux indices */
1174 spec->ext_mic_pin = ext;
1175 spec->int_mic_pin = fixed;
1176 spec->dock_mic_pin = dock;
1177
1178 spec->auto_mic = 1;
1179 if (!alc_auto_mic_check_imux(codec))
Takashi Iwai475c3d22012-11-30 08:31:30 +01001180 return 0;
Takashi Iwai21268962011-07-07 15:01:13 +02001181
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001182 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1183 ext, fixed, dock);
Takashi Iwai475c3d22012-11-30 08:31:30 +01001184
1185 return 0;
Takashi Iwai6c819492009-08-10 18:47:44 +02001186}
1187
Takashi Iwai1d045db2011-07-07 18:23:21 +02001188/* check the availabilities of auto-mute and auto-mic switches */
Takashi Iwai475c3d22012-11-30 08:31:30 +01001189static int alc_auto_check_switches(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02001190{
Takashi Iwai475c3d22012-11-30 08:31:30 +01001191 int err;
1192
1193 err = alc_init_automute(codec);
1194 if (err < 0)
1195 return err;
1196 err = alc_init_auto_mic(codec);
1197 if (err < 0)
1198 return err;
1199 return 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02001200}
1201
1202/*
1203 * Realtek SSID verification
1204 */
1205
David Henningsson90622912010-10-14 14:50:18 +02001206/* Could be any non-zero and even value. When used as fixup, tells
1207 * the driver to ignore any present sku defines.
1208 */
1209#define ALC_FIXUP_SKU_IGNORE (2)
1210
Takashi Iwai23d30f22012-05-07 17:17:32 +02001211static void alc_fixup_sku_ignore(struct hda_codec *codec,
1212 const struct hda_fixup *fix, int action)
1213{
1214 struct alc_spec *spec = codec->spec;
1215 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1216 spec->cdefine.fixup = 1;
1217 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1218 }
1219}
1220
Kailang Yangda00c242010-03-19 11:23:45 +01001221static int alc_auto_parse_customize_define(struct hda_codec *codec)
1222{
1223 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001224 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001225 struct alc_spec *spec = codec->spec;
1226
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001227 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1228
David Henningsson90622912010-10-14 14:50:18 +02001229 if (spec->cdefine.fixup) {
1230 ass = spec->cdefine.sku_cfg;
1231 if (ass == ALC_FIXUP_SKU_IGNORE)
1232 return -1;
1233 goto do_sku;
1234 }
1235
Kailang Yangda00c242010-03-19 11:23:45 +01001236 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001237 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001238 goto do_sku;
1239
1240 nid = 0x1d;
1241 if (codec->vendor_id == 0x10ec0260)
1242 nid = 0x17;
1243 ass = snd_hda_codec_get_pincfg(codec, nid);
1244
1245 if (!(ass & 1)) {
1246 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1247 codec->chip_name, ass);
1248 return -1;
1249 }
1250
1251 /* check sum */
1252 tmp = 0;
1253 for (i = 1; i < 16; i++) {
1254 if ((ass >> i) & 1)
1255 tmp++;
1256 }
1257 if (((ass >> 16) & 0xf) != tmp)
1258 return -1;
1259
1260 spec->cdefine.port_connectivity = ass >> 30;
1261 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1262 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1263 spec->cdefine.customization = ass >> 8;
1264do_sku:
1265 spec->cdefine.sku_cfg = ass;
1266 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1267 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1268 spec->cdefine.swap = (ass & 0x2) >> 1;
1269 spec->cdefine.override = ass & 0x1;
1270
1271 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1272 nid, spec->cdefine.sku_cfg);
1273 snd_printd("SKU: port_connectivity=0x%x\n",
1274 spec->cdefine.port_connectivity);
1275 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1276 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1277 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1278 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1279 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1280 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1281 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1282
1283 return 0;
1284}
1285
Takashi Iwai1d045db2011-07-07 18:23:21 +02001286/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001287static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1288{
Takashi Iwai21268962011-07-07 15:01:13 +02001289 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001290}
1291
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001292/* check subsystem ID and set up device-specific initialization;
1293 * return 1 if initialized, 0 if invalid SSID
1294 */
1295/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1296 * 31 ~ 16 : Manufacture ID
1297 * 15 ~ 8 : SKU ID
1298 * 7 ~ 0 : Assembly ID
1299 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1300 */
1301static int alc_subsystem_id(struct hda_codec *codec,
1302 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001303 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001304{
1305 unsigned int ass, tmp, i;
1306 unsigned nid;
1307 struct alc_spec *spec = codec->spec;
1308
David Henningsson90622912010-10-14 14:50:18 +02001309 if (spec->cdefine.fixup) {
1310 ass = spec->cdefine.sku_cfg;
1311 if (ass == ALC_FIXUP_SKU_IGNORE)
1312 return 0;
1313 goto do_sku;
1314 }
1315
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001316 ass = codec->subsystem_id & 0xffff;
1317 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1318 goto do_sku;
1319
1320 /* invalid SSID, check the special NID pin defcfg instead */
1321 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001322 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001323 * 29~21 : reserve
1324 * 20 : PCBEEP input
1325 * 19~16 : Check sum (15:1)
1326 * 15~1 : Custom
1327 * 0 : override
1328 */
1329 nid = 0x1d;
1330 if (codec->vendor_id == 0x10ec0260)
1331 nid = 0x17;
1332 ass = snd_hda_codec_get_pincfg(codec, nid);
1333 snd_printd("realtek: No valid SSID, "
1334 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001335 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001336 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001337 return 0;
1338 if ((ass >> 30) != 1) /* no physical connection */
1339 return 0;
1340
1341 /* check sum */
1342 tmp = 0;
1343 for (i = 1; i < 16; i++) {
1344 if ((ass >> i) & 1)
1345 tmp++;
1346 }
1347 if (((ass >> 16) & 0xf) != tmp)
1348 return 0;
1349do_sku:
1350 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1351 ass & 0xffff, codec->vendor_id);
1352 /*
1353 * 0 : override
1354 * 1 : Swap Jack
1355 * 2 : 0 --> Desktop, 1 --> Laptop
1356 * 3~5 : External Amplifier control
1357 * 7~6 : Reserved
1358 */
1359 tmp = (ass & 0x38) >> 3; /* external Amp control */
1360 switch (tmp) {
1361 case 1:
1362 spec->init_amp = ALC_INIT_GPIO1;
1363 break;
1364 case 3:
1365 spec->init_amp = ALC_INIT_GPIO2;
1366 break;
1367 case 7:
1368 spec->init_amp = ALC_INIT_GPIO3;
1369 break;
1370 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001371 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001372 spec->init_amp = ALC_INIT_DEFAULT;
1373 break;
1374 }
1375
1376 /* is laptop or Desktop and enable the function "Mute internal speaker
1377 * when the external headphone out jack is plugged"
1378 */
1379 if (!(ass & 0x8000))
1380 return 1;
1381 /*
1382 * 10~8 : Jack location
1383 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1384 * 14~13: Resvered
1385 * 15 : 1 --> enable the function "Mute internal speaker
1386 * when the external headphone out jack is plugged"
1387 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001388 if (!spec->autocfg.hp_pins[0] &&
1389 !(spec->autocfg.line_out_pins[0] &&
1390 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001391 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001392 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1393 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001394 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001395 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001396 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001397 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001398 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001399 else if (tmp == 3)
1400 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001401 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001402 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001403 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1404 spec->autocfg.line_outs))
1405 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001406 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001407 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001408 return 1;
1409}
Kailang Yangea1fb292008-08-26 12:58:38 +02001410
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001411/* Check the validity of ALC subsystem-id
1412 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1413static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001414{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001415 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001416 struct alc_spec *spec = codec->spec;
1417 snd_printd("realtek: "
1418 "Enable default setup for auto mode as fallback\n");
1419 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001420 }
Takashi Iwai21268962011-07-07 15:01:13 +02001421}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001422
Takashi Iwai41e41f12005-06-08 14:48:49 +02001423/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001424 * COEF access helper functions
1425 */
Kailang Yang274693f2009-12-03 10:07:50 +01001426static int alc_read_coef_idx(struct hda_codec *codec,
1427 unsigned int coef_idx)
1428{
1429 unsigned int val;
1430 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1431 coef_idx);
1432 val = snd_hda_codec_read(codec, 0x20, 0,
1433 AC_VERB_GET_PROC_COEF, 0);
1434 return val;
1435}
1436
Kailang Yang977ddd62010-09-15 10:02:29 +02001437static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1438 unsigned int coef_val)
1439{
1440 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1441 coef_idx);
1442 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1443 coef_val);
1444}
1445
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001446/* a special bypass for COEF 0; read the cached value at the second time */
1447static unsigned int alc_get_coef0(struct hda_codec *codec)
1448{
1449 struct alc_spec *spec = codec->spec;
1450 if (!spec->coef0)
1451 spec->coef0 = alc_read_coef_idx(codec, 0);
1452 return spec->coef0;
1453}
1454
Takashi Iwai1d045db2011-07-07 18:23:21 +02001455/*
1456 * Digital I/O handling
1457 */
1458
Takashi Iwai757899a2010-07-30 10:48:14 +02001459/* set right pin controls for digital I/O */
1460static void alc_auto_init_digital(struct hda_codec *codec)
1461{
1462 struct alc_spec *spec = codec->spec;
1463 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001464 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001465
1466 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1467 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001468 if (!pin)
1469 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001470 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001471 if (!i)
1472 dac = spec->multiout.dig_out_nid;
1473 else
1474 dac = spec->slave_dig_outs[i - 1];
1475 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1476 continue;
1477 snd_hda_codec_write(codec, dac, 0,
1478 AC_VERB_SET_AMP_GAIN_MUTE,
1479 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001480 }
1481 pin = spec->autocfg.dig_in_pin;
1482 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001483 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001484}
1485
1486/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1487static void alc_auto_parse_digital(struct hda_codec *codec)
1488{
1489 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001490 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001491 hda_nid_t dig_nid;
1492
1493 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001494 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001495 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001496 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001497 err = snd_hda_get_connections(codec,
1498 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001499 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001500 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001501 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001502 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001503 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001504 spec->multiout.dig_out_nid = dig_nid;
1505 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1506 } else {
1507 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001508 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001509 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001510 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001511 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001512 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001513 }
1514
1515 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001516 dig_nid = codec->start_nid;
1517 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1518 unsigned int wcaps = get_wcaps(codec, dig_nid);
1519 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1520 continue;
1521 if (!(wcaps & AC_WCAP_DIGITAL))
1522 continue;
1523 if (!(wcaps & AC_WCAP_CONN_LIST))
1524 continue;
1525 err = get_connection_index(codec, dig_nid,
1526 spec->autocfg.dig_in_pin);
1527 if (err >= 0) {
1528 spec->dig_in_nid = dig_nid;
1529 break;
1530 }
1531 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001532 }
1533}
1534
Takashi Iwaif95474e2007-07-10 00:47:43 +02001535/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001536 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001537 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001538static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1539 struct snd_ctl_elem_info *uinfo)
1540{
1541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1542 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001543 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001544 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001545
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001546 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001547 if (spec->vol_in_capsrc)
1548 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1549 else
1550 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1551 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001552 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001553 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001554 return err;
1555}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001557static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1558 unsigned int size, unsigned int __user *tlv)
1559{
1560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1561 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001562 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001563 int err;
1564
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001565 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001566 if (spec->vol_in_capsrc)
1567 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1568 else
1569 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1570 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001571 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001572 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001573 return err;
1574}
1575
1576typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1577 struct snd_ctl_elem_value *ucontrol);
1578
1579static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1580 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001581 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001582{
1583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1584 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001585 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001586
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001587 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001588 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001589 for (i = 0; i < spec->num_adc_nids; i++) {
1590 kcontrol->private_value =
1591 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1592 3, 0, HDA_INPUT);
1593 err = func(kcontrol, ucontrol);
1594 if (err < 0)
1595 goto error;
1596 }
1597 } else {
1598 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001599 if (spec->vol_in_capsrc)
1600 kcontrol->private_value =
1601 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1602 3, 0, HDA_OUTPUT);
1603 else
1604 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001605 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1606 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001607 err = func(kcontrol, ucontrol);
1608 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001609 if (err >= 0 && is_put)
1610 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001611 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001612 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001613 return err;
1614}
1615
1616static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1618{
1619 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001620 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001621}
1622
1623static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1625{
1626 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001627 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001628}
1629
1630/* capture mixer elements */
1631#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1632
1633static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1634 struct snd_ctl_elem_value *ucontrol)
1635{
1636 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001637 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001638}
1639
1640static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1641 struct snd_ctl_elem_value *ucontrol)
1642{
1643 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001644 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001645}
1646
Takashi Iwaia23b6882009-03-23 15:21:36 +01001647#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001648 { \
1649 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1650 .name = "Capture Switch", \
1651 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1652 .count = num, \
1653 .info = alc_cap_sw_info, \
1654 .get = alc_cap_sw_get, \
1655 .put = alc_cap_sw_put, \
1656 }, \
1657 { \
1658 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1659 .name = "Capture Volume", \
1660 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1661 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1662 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1663 .count = num, \
1664 .info = alc_cap_vol_info, \
1665 .get = alc_cap_vol_get, \
1666 .put = alc_cap_vol_put, \
1667 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001668 }
1669
1670#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001671 { \
1672 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1673 /* .name = "Capture Source", */ \
1674 .name = "Input Source", \
1675 .count = num, \
1676 .info = alc_mux_enum_info, \
1677 .get = alc_mux_enum_get, \
1678 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001679 }
1680
1681#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001682static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001683 _DEFINE_CAPMIX(num), \
1684 _DEFINE_CAPSRC(num), \
1685 { } /* end */ \
1686}
1687
1688#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001689static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001690 _DEFINE_CAPMIX(num), \
1691 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001692}
1693
1694/* up to three ADCs */
1695DEFINE_CAPMIX(1);
1696DEFINE_CAPMIX(2);
1697DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001698DEFINE_CAPMIX_NOSRC(1);
1699DEFINE_CAPMIX_NOSRC(2);
1700DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001701
1702/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001703 * Inverted digital-mic handling
1704 *
1705 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1706 * gives the additional mute only to the right channel of the digital mic
1707 * capture stream. This is a workaround for avoiding the almost silence
1708 * by summing the stereo stream from some (known to be ForteMedia)
1709 * digital mic unit.
1710 *
1711 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1712 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1713 * without caching so that the cache can still keep the original value.
1714 * The cached value is then restored when the flag is set off or any other
1715 * than d-mic is used as the current input source.
1716 */
1717static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1718{
1719 struct alc_spec *spec = codec->spec;
1720 int i;
1721
1722 if (!spec->inv_dmic_fixup)
1723 return;
1724 if (!spec->inv_dmic_muted && !force)
1725 return;
1726 for (i = 0; i < spec->num_adc_nids; i++) {
1727 int src = spec->dyn_adc_switch ? 0 : i;
1728 bool dmic_fixup = false;
1729 hda_nid_t nid;
1730 int parm, dir, v;
1731
1732 if (spec->inv_dmic_muted &&
1733 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1734 dmic_fixup = true;
1735 if (!dmic_fixup && !force)
1736 continue;
1737 if (spec->vol_in_capsrc) {
1738 nid = spec->capsrc_nids[i];
1739 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1740 dir = HDA_OUTPUT;
1741 } else {
1742 nid = spec->adc_nids[i];
1743 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1744 dir = HDA_INPUT;
1745 }
1746 /* we care only right channel */
1747 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1748 if (v & 0x80) /* if already muted, we don't need to touch */
1749 continue;
1750 if (dmic_fixup) /* add mute for d-mic */
1751 v |= 0x80;
1752 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1753 parm | v);
1754 }
1755}
1756
1757static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1758 struct snd_ctl_elem_value *ucontrol)
1759{
1760 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1761 struct alc_spec *spec = codec->spec;
1762
1763 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1764 return 0;
1765}
1766
1767static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1768 struct snd_ctl_elem_value *ucontrol)
1769{
1770 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1771 struct alc_spec *spec = codec->spec;
1772 unsigned int val = !ucontrol->value.integer.value[0];
1773
1774 if (val == spec->inv_dmic_muted)
1775 return 0;
1776 spec->inv_dmic_muted = val;
1777 alc_inv_dmic_sync(codec, true);
1778 return 0;
1779}
1780
1781static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1782 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1783 .info = snd_ctl_boolean_mono_info,
1784 .get = alc_inv_dmic_sw_get,
1785 .put = alc_inv_dmic_sw_put,
1786};
1787
1788static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1789{
1790 struct alc_spec *spec = codec->spec;
Takashi Iwai668d1e92012-11-29 14:10:17 +01001791
1792 if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
1793 &alc_inv_dmic_sw))
Takashi Iwai125821a2012-06-22 14:30:29 +02001794 return -ENOMEM;
1795 spec->inv_dmic_fixup = 1;
1796 spec->inv_dmic_muted = 0;
1797 spec->inv_dmic_pin = nid;
1798 return 0;
1799}
1800
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001801/* typically the digital mic is put at node 0x12 */
1802static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1803 const struct alc_fixup *fix, int action)
1804{
1805 if (action == ALC_FIXUP_ACT_PROBE)
1806 alc_add_inv_dmic_mixer(codec, 0x12);
1807}
1808
Takashi Iwai125821a2012-06-22 14:30:29 +02001809/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001810 * virtual master controls
1811 */
1812
1813/*
1814 * slave controls for virtual master
1815 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001816static const char * const alc_slave_pfxs[] = {
1817 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001818 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001819 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001820 NULL,
1821};
1822
1823/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001824 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001826
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001827#define NID_MAPPING (-1)
1828
1829#define SUBDEV_SPEAKER_ (0 << 6)
1830#define SUBDEV_HP_ (1 << 6)
1831#define SUBDEV_LINE_ (2 << 6)
1832#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1833#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1834#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1835
Takashi Iwai603c4012008-07-30 15:01:44 +02001836static void alc_free_kctls(struct hda_codec *codec);
1837
Takashi Iwai67d634c2009-11-16 15:35:59 +01001838#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001839/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001840static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001841 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001842 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001843 { } /* end */
1844};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001845#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001846
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001847static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848{
1849 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001850 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001851 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001852 int i, j, err;
1853 unsigned int u;
1854 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
1856 for (i = 0; i < spec->num_mixers; i++) {
1857 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1858 if (err < 0)
1859 return err;
1860 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001861 if (spec->cap_mixer) {
1862 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1863 if (err < 0)
1864 return err;
1865 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001867 err = snd_hda_create_dig_out_ctls(codec,
1868 spec->multiout.dig_out_nid,
1869 spec->multiout.dig_out_nid,
1870 spec->pcm_rec[1].pcm_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 if (err < 0)
1872 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001873 if (!spec->no_analog) {
1874 err = snd_hda_create_spdif_share_sw(codec,
1875 &spec->multiout);
1876 if (err < 0)
1877 return err;
1878 spec->multiout.share_spdif = 1;
1879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 }
1881 if (spec->dig_in_nid) {
1882 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1883 if (err < 0)
1884 return err;
1885 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001886
Takashi Iwai67d634c2009-11-16 15:35:59 +01001887#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001888 /* create beep controls if needed */
1889 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001890 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001891 for (knew = alc_beep_mixer; knew->name; knew++) {
1892 struct snd_kcontrol *kctl;
1893 kctl = snd_ctl_new1(knew, codec);
1894 if (!kctl)
1895 return -ENOMEM;
1896 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001897 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001898 if (err < 0)
1899 return err;
1900 }
1901 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001902#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001903
Takashi Iwai2134ea42008-01-10 16:53:55 +01001904 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001905 if (!spec->no_analog &&
1906 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001907 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001908 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001909 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001910 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001911 vmaster_tlv, alc_slave_pfxs,
1912 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001913 if (err < 0)
1914 return err;
1915 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001916 if (!spec->no_analog &&
1917 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001918 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1919 NULL, alc_slave_pfxs,
1920 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001921 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001922 if (err < 0)
1923 return err;
1924 }
1925
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001926 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001927 if (spec->capsrc_nids || spec->adc_nids) {
1928 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1929 if (!kctl)
1930 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1931 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001932 err = snd_hda_add_nid(codec, kctl, i,
1933 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001934 if (err < 0)
1935 return err;
1936 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001937 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001938 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001939 const char *kname = kctl ? kctl->id.name : NULL;
1940 for (knew = spec->cap_mixer; knew->name; knew++) {
1941 if (kname && strcmp(knew->name, kname) == 0)
1942 continue;
1943 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1944 for (i = 0; kctl && i < kctl->count; i++) {
1945 err = snd_hda_add_nid(codec, kctl, i,
1946 spec->adc_nids[i]);
1947 if (err < 0)
1948 return err;
1949 }
1950 }
1951 }
1952
1953 /* other nid->control mapping */
1954 for (i = 0; i < spec->num_mixers; i++) {
1955 for (knew = spec->mixers[i]; knew->name; knew++) {
1956 if (knew->iface != NID_MAPPING)
1957 continue;
1958 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1959 if (kctl == NULL)
1960 continue;
1961 u = knew->subdevice;
1962 for (j = 0; j < 4; j++, u >>= 8) {
1963 nid = u & 0x3f;
1964 if (nid == 0)
1965 continue;
1966 switch (u & 0xc0) {
1967 case SUBDEV_SPEAKER_:
1968 nid = spec->autocfg.speaker_pins[nid];
1969 break;
1970 case SUBDEV_LINE_:
1971 nid = spec->autocfg.line_out_pins[nid];
1972 break;
1973 case SUBDEV_HP_:
1974 nid = spec->autocfg.hp_pins[nid];
1975 break;
1976 default:
1977 continue;
1978 }
1979 err = snd_hda_add_nid(codec, kctl, 0, nid);
1980 if (err < 0)
1981 return err;
1982 }
1983 u = knew->private_value;
1984 for (j = 0; j < 4; j++, u >>= 8) {
1985 nid = u & 0xff;
1986 if (nid == 0)
1987 continue;
1988 err = snd_hda_add_nid(codec, kctl, 0, nid);
1989 if (err < 0)
1990 return err;
1991 }
1992 }
1993 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001994
1995 alc_free_kctls(codec); /* no longer needed */
1996
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001997 return 0;
1998}
1999
David Henningsson5780b622012-06-27 18:45:45 +02002000static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002001{
2002 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02002003
2004 if (spec->shared_mic_hp) {
2005 int err;
2006 int nid = spec->autocfg.inputs[1].pin;
2007 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2008 if (err < 0)
2009 return err;
2010 err = snd_hda_jack_detect_enable(codec, nid, 0);
2011 if (err < 0)
2012 return err;
2013 }
2014
2015 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2016}
2017
2018static int alc_build_controls(struct hda_codec *codec)
2019{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002020 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002021 if (err < 0)
2022 return err;
David Henningsson5780b622012-06-27 18:45:45 +02002023
2024 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002025 if (err < 0)
2026 return err;
2027 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2028 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029}
2030
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002031
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002033 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002034 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002035
Takashi Iwai584c0c42011-03-10 12:51:11 +01002036static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002037static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039static int alc_init(struct hda_codec *codec)
2040{
2041 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002042
Takashi Iwai546bb672012-03-07 08:37:19 +01002043 if (spec->init_hook)
2044 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002045
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002046 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002047 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002048
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002049 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002050 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002051 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002052
Takashi Iwai58701122011-01-13 15:41:45 +01002053 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2054
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002055 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 return 0;
2057}
2058
Takashi Iwai83012a72012-08-24 18:38:08 +02002059#ifdef CONFIG_PM
Takashi Iwaicb53c622007-08-10 17:21:45 +02002060static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2061{
2062 struct alc_spec *spec = codec->spec;
2063 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2064}
2065#endif
2066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067/*
2068 * Analog playback callbacks
2069 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002070static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002072 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
2074 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002075 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2076 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077}
2078
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002079static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 struct hda_codec *codec,
2081 unsigned int stream_tag,
2082 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002083 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084{
2085 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002086 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2087 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088}
2089
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002090static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002092 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093{
2094 struct alc_spec *spec = codec->spec;
2095 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2096}
2097
2098/*
2099 * Digital out
2100 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002101static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002103 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104{
2105 struct alc_spec *spec = codec->spec;
2106 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2107}
2108
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002109static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002110 struct hda_codec *codec,
2111 unsigned int stream_tag,
2112 unsigned int format,
2113 struct snd_pcm_substream *substream)
2114{
2115 struct alc_spec *spec = codec->spec;
2116 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2117 stream_tag, format, substream);
2118}
2119
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002120static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002121 struct hda_codec *codec,
2122 struct snd_pcm_substream *substream)
2123{
2124 struct alc_spec *spec = codec->spec;
2125 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2126}
2127
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002128static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002130 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131{
2132 struct alc_spec *spec = codec->spec;
2133 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2134}
2135
2136/*
2137 * Analog capture
2138 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002139static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 struct hda_codec *codec,
2141 unsigned int stream_tag,
2142 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002143 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144{
2145 struct alc_spec *spec = codec->spec;
2146
Takashi Iwai63300792008-01-24 15:31:36 +01002147 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 stream_tag, 0, format);
2149 return 0;
2150}
2151
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002152static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002154 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155{
2156 struct alc_spec *spec = codec->spec;
2157
Takashi Iwai888afa12008-03-18 09:57:50 +01002158 snd_hda_codec_cleanup_stream(codec,
2159 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 return 0;
2161}
2162
Takashi Iwai840b64c2010-07-13 22:49:01 +02002163/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002164static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002165 struct hda_codec *codec,
2166 unsigned int stream_tag,
2167 unsigned int format,
2168 struct snd_pcm_substream *substream)
2169{
2170 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002171 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002172 spec->cur_adc_stream_tag = stream_tag;
2173 spec->cur_adc_format = format;
2174 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2175 return 0;
2176}
2177
Takashi Iwai21268962011-07-07 15:01:13 +02002178static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002179 struct hda_codec *codec,
2180 struct snd_pcm_substream *substream)
2181{
2182 struct alc_spec *spec = codec->spec;
2183 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2184 spec->cur_adc = 0;
2185 return 0;
2186}
2187
Takashi Iwai21268962011-07-07 15:01:13 +02002188static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002189 .substreams = 1,
2190 .channels_min = 2,
2191 .channels_max = 2,
2192 .nid = 0, /* fill later */
2193 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002194 .prepare = dyn_adc_capture_pcm_prepare,
2195 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002196 },
2197};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
2199/*
2200 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002201static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 .substreams = 1,
2203 .channels_min = 2,
2204 .channels_max = 8,
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 .open = alc_playback_pcm_open,
2208 .prepare = alc_playback_pcm_prepare,
2209 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 },
2211};
2212
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002213static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002214 .substreams = 1,
2215 .channels_min = 2,
2216 .channels_max = 2,
2217 /* NID is set in alc_build_pcms */
2218};
2219
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002220static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002221 .substreams = 1,
2222 .channels_min = 2,
2223 .channels_max = 2,
2224 /* NID is set in alc_build_pcms */
2225};
2226
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002227static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002228 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 .channels_min = 2,
2230 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002231 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002233 .prepare = alc_alt_capture_pcm_prepare,
2234 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 },
2236};
2237
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002238static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 .substreams = 1,
2240 .channels_min = 2,
2241 .channels_max = 2,
2242 /* NID is set in alc_build_pcms */
2243 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002244 .open = alc_dig_playback_pcm_open,
2245 .close = alc_dig_playback_pcm_close,
2246 .prepare = alc_dig_playback_pcm_prepare,
2247 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 },
2249};
2250
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002251static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 .substreams = 1,
2253 .channels_min = 2,
2254 .channels_max = 2,
2255 /* NID is set in alc_build_pcms */
2256};
2257
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002258/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002259static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002260 .substreams = 0,
2261 .channels_min = 0,
2262 .channels_max = 0,
2263};
2264
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265static int alc_build_pcms(struct hda_codec *codec)
2266{
2267 struct alc_spec *spec = codec->spec;
2268 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002269 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002270 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 int i;
2272
2273 codec->num_pcms = 1;
2274 codec->pcm_info = info;
2275
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002276 if (spec->no_analog)
2277 goto skip_analog;
2278
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002279 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2280 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002282
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002283 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002284 p = spec->stream_analog_playback;
2285 if (!p)
2286 p = &alc_pcm_analog_playback;
2287 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002288 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
Takashi Iwai9c9a5172012-07-31 11:35:35 +02002289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
2290 spec->multiout.max_channels;
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002291 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2292 spec->autocfg.line_outs == 2)
2293 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2294 snd_pcm_2_1_chmaps;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002295 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002296 if (spec->adc_nids) {
2297 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002298 if (!p) {
2299 if (spec->dyn_adc_switch)
2300 p = &dyn_adc_pcm_analog_capture;
2301 else
2302 p = &alc_pcm_analog_capture;
2303 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002304 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002305 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
Takashi Iwai4a471b72005-12-07 13:56:29 +01002308 if (spec->channel_mode) {
2309 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2310 for (i = 0; i < spec->num_channel_mode; i++) {
2311 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2312 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 }
2315 }
2316
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002317 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002318 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002320 snprintf(spec->stream_name_digital,
2321 sizeof(spec->stream_name_digital),
2322 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002323 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002324 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002325 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002327 if (spec->dig_out_type)
2328 info->pcm_type = spec->dig_out_type;
2329 else
2330 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002331 if (spec->multiout.dig_out_nid) {
2332 p = spec->stream_digital_playback;
2333 if (!p)
2334 p = &alc_pcm_digital_playback;
2335 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2337 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002338 if (spec->dig_in_nid) {
2339 p = spec->stream_digital_capture;
2340 if (!p)
2341 p = &alc_pcm_digital_capture;
2342 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2344 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002345 /* FIXME: do we need this for all Realtek codec models? */
2346 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 }
2348
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002349 if (spec->no_analog)
2350 return 0;
2351
Takashi Iwaie08a0072006-09-07 17:52:14 +02002352 /* If the use of more than one ADC is requested for the current
2353 * model, configure a second analog capture-only PCM.
2354 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002355 have_multi_adcs = (spec->num_adc_nids > 1) &&
2356 !spec->dyn_adc_switch && !spec->auto_mic &&
2357 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002358 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002359 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002360 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002361 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002362 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002363 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002364 p = spec->stream_analog_alt_playback;
2365 if (!p)
2366 p = &alc_pcm_analog_alt_playback;
2367 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002368 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2369 spec->alt_dac_nid;
2370 } else {
2371 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2372 alc_pcm_null_stream;
2373 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2374 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002375 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002376 p = spec->stream_analog_alt_capture;
2377 if (!p)
2378 p = &alc_pcm_analog_alt_capture;
2379 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002380 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2381 spec->adc_nids[1];
2382 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2383 spec->num_adc_nids - 1;
2384 } else {
2385 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2386 alc_pcm_null_stream;
2387 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002388 }
2389 }
2390
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 return 0;
2392}
2393
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002394static inline void alc_shutup(struct hda_codec *codec)
2395{
Takashi Iwai1c716152011-04-07 10:37:16 +02002396 struct alc_spec *spec = codec->spec;
2397
2398 if (spec && spec->shutup)
2399 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002400 snd_hda_shutup_pins(codec);
2401}
2402
Takashi Iwai603c4012008-07-30 15:01:44 +02002403static void alc_free_kctls(struct hda_codec *codec)
2404{
2405 struct alc_spec *spec = codec->spec;
2406
2407 if (spec->kctls.list) {
2408 struct snd_kcontrol_new *kctl = spec->kctls.list;
2409 int i;
2410 for (i = 0; i < spec->kctls.used; i++)
2411 kfree(kctl[i].name);
2412 }
2413 snd_array_free(&spec->kctls);
2414}
2415
Takashi Iwai23c09b02011-08-19 09:05:35 +02002416static void alc_free_bind_ctls(struct hda_codec *codec)
2417{
2418 struct alc_spec *spec = codec->spec;
2419 if (spec->bind_ctls.list) {
2420 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2421 int i;
2422 for (i = 0; i < spec->bind_ctls.used; i++)
2423 kfree(ctl[i]);
2424 }
2425 snd_array_free(&spec->bind_ctls);
2426}
2427
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428static void alc_free(struct hda_codec *codec)
2429{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002430 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002431
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002432 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002433 return;
2434
Takashi Iwai603c4012008-07-30 15:01:44 +02002435 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002436 alc_free_bind_ctls(codec);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002437 snd_array_free(&spec->out_path);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002438 snd_array_free(&spec->in_path);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002439 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002440 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002441 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442}
2443
Takashi Iwai83012a72012-08-24 18:38:08 +02002444#ifdef CONFIG_PM
Daniel T Chenc97259d2009-12-27 18:52:08 -05002445static void alc_power_eapd(struct hda_codec *codec)
2446{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002447 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002448}
2449
Takashi Iwai68cb2b52012-07-02 15:20:37 +02002450static int alc_suspend(struct hda_codec *codec)
Hector Martinf5de24b2009-12-20 22:51:31 +01002451{
2452 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002453 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002454 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002455 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002456 return 0;
2457}
2458#endif
2459
Takashi Iwai2a439522011-07-26 09:52:50 +02002460#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002461static int alc_resume(struct hda_codec *codec)
2462{
Takashi Iwai1c716152011-04-07 10:37:16 +02002463 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002464 codec->patch_ops.init(codec);
2465 snd_hda_codec_resume_amp(codec);
2466 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002467 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002468 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002469 return 0;
2470}
Takashi Iwaie044c392008-10-27 16:56:24 +01002471#endif
2472
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473/*
2474 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002475static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 .build_controls = alc_build_controls,
2477 .build_pcms = alc_build_pcms,
2478 .init = alc_init,
2479 .free = alc_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02002480 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002481#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002482 .resume = alc_resume,
2483#endif
Takashi Iwai83012a72012-08-24 18:38:08 +02002484#ifdef CONFIG_PM
Hector Martinf5de24b2009-12-20 22:51:31 +01002485 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002486 .check_power_status = alc_check_power_status,
2487#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002488 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489};
2490
David Henningsson29adc4b2012-09-25 11:31:00 +02002491
Kailang Yangc027ddc2010-03-19 11:33:06 +01002492/* replace the codec chip_name with the given string */
2493static int alc_codec_rename(struct hda_codec *codec, const char *name)
2494{
2495 kfree(codec->chip_name);
2496 codec->chip_name = kstrdup(name, GFP_KERNEL);
2497 if (!codec->chip_name) {
2498 alc_free(codec);
2499 return -ENOMEM;
2500 }
2501 return 0;
2502}
2503
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002504/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002505 * Rename codecs appropriately from COEF value
2506 */
2507struct alc_codec_rename_table {
2508 unsigned int vendor_id;
2509 unsigned short coef_mask;
2510 unsigned short coef_bits;
2511 const char *name;
2512};
2513
2514static struct alc_codec_rename_table rename_tbl[] = {
2515 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2516 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2517 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2518 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2519 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2520 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2521 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002522 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002523 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2524 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2525 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2526 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2527 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2528 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2529 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2530 { } /* terminator */
2531};
2532
2533static int alc_codec_rename_from_preset(struct hda_codec *codec)
2534{
2535 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002536
2537 for (p = rename_tbl; p->vendor_id; p++) {
2538 if (p->vendor_id != codec->vendor_id)
2539 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002540 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002541 return alc_codec_rename(codec, p->name);
2542 }
2543 return 0;
2544}
2545
2546/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002547 * Automatic parse of I/O pins from the BIOS configuration
2548 */
2549
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002550enum {
2551 ALC_CTL_WIDGET_VOL,
2552 ALC_CTL_WIDGET_MUTE,
2553 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002554 ALC_CTL_BIND_VOL,
2555 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002556};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002557static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002558 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2559 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002560 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002561 HDA_BIND_VOL(NULL, 0),
2562 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002563};
2564
2565/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002566static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002567 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002568{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002569 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002570
Takashi Iwai668d1e92012-11-29 14:10:17 +01002571 knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
Takashi Iwai603c4012008-07-30 15:01:44 +02002572 if (!knew)
2573 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002574 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002575 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002576 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002577 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002578 return 0;
2579}
2580
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002581static int add_control_with_pfx(struct alc_spec *spec, int type,
2582 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002583 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002584{
2585 char name[32];
2586 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002587 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002588}
2589
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002590#define add_pb_vol_ctrl(spec, type, pfx, val) \
2591 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2592#define add_pb_sw_ctrl(spec, type, pfx, val) \
2593 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2594#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2595 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2596#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2597 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002598
Takashi Iwai23c09b02011-08-19 09:05:35 +02002599static const char * const channel_name[4] = {
2600 "Front", "Surround", "CLFE", "Side"
2601};
2602
Takashi Iwai6843ca12011-06-24 11:03:58 +02002603static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2604 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002605{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002606 struct auto_pin_cfg *cfg = &spec->autocfg;
2607
Takashi Iwai6843ca12011-06-24 11:03:58 +02002608 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002609 if (cfg->line_outs == 1 && !spec->multi_ios &&
2610 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002611 return "Master";
2612
2613 switch (cfg->line_out_type) {
2614 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002615 if (cfg->line_outs == 1)
2616 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002617 if (cfg->line_outs == 2)
2618 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002619 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002620 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002621 /* for multi-io case, only the primary out */
2622 if (ch && spec->multi_ios)
2623 break;
2624 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002625 return "Headphone";
2626 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002627 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002628 return "PCM";
2629 break;
2630 }
David Henningsson71aa5eb2012-10-17 12:43:44 +02002631 if (ch >= ARRAY_SIZE(channel_name)) {
2632 snd_BUG();
Takashi Iwai23c09b02011-08-19 09:05:35 +02002633 return "PCM";
David Henningsson71aa5eb2012-10-17 12:43:44 +02002634 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002635
2636 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002637}
2638
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002639static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2640 hda_nid_t to_nid, int with_aa_mix,
2641 struct nid_path *path);
2642
Takashi Iwai83012a72012-08-24 18:38:08 +02002643#ifdef CONFIG_PM
Takashi Iwai164f73e2012-02-21 11:27:09 +01002644/* add the powersave loopback-list entry */
2645static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2646{
2647 struct hda_amp_list *list;
2648
2649 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2650 return;
2651 list = spec->loopback_list + spec->num_loopbacks;
2652 list->nid = mix;
2653 list->dir = HDA_INPUT;
2654 list->idx = idx;
2655 spec->num_loopbacks++;
2656 spec->loopback.amplist = spec->loopback_list;
2657}
2658#else
2659#define add_loopback_list(spec, mix, idx) /* NOP */
2660#endif
2661
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002662/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002663static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002664 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002665 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002666{
Kailang Yangdf694da2005-12-05 19:42:22 +01002667 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002668
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002669 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002670 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2671 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002672 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002673 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002674 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2675 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002676 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002677 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002678 return 0;
2679}
2680
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002681static int new_capture_source(struct hda_codec *codec, int adc_idx,
2682 hda_nid_t pin, int idx, const char *label)
2683{
2684 struct alc_spec *spec = codec->spec;
2685 struct hda_input_mux *imux = &spec->private_imux[0];
2686 struct nid_path *path;
2687
2688 path = snd_array_new(&spec->in_path);
2689 if (!path)
2690 return -ENOMEM;
2691 memset(path, 0, sizeof(*path));
2692 if (!parse_nid_path(codec, pin, spec->adc_nids[adc_idx], 2, path)) {
2693 snd_printd(KERN_ERR "invalid input path 0x%x -> 0x%x\n",
2694 pin, spec->adc_nids[adc_idx]);
2695 return -EINVAL;
2696 }
2697
2698 spec->imux_pins[imux->num_items] = pin;
2699 snd_hda_add_imux_item(imux, label, idx, NULL);
2700 return 0;
2701}
2702
Takashi Iwai05f5f472009-08-25 13:10:18 +02002703static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002704{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002705 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2706 return (pincap & AC_PINCAP_IN) != 0;
2707}
2708
Takashi Iwai1d045db2011-07-07 18:23:21 +02002709/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002710static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002711{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002712 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002713 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002714 hda_nid_t *adc_nids = spec->private_adc_nids;
2715 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2716 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002717 int i, nums = 0;
2718
2719 nid = codec->start_nid;
2720 for (i = 0; i < codec->num_nodes; i++, nid++) {
2721 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002722 unsigned int caps = get_wcaps(codec, nid);
2723 int type = get_wcaps_type(caps);
2724
2725 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2726 continue;
2727 adc_nids[nums] = nid;
2728 cap_nids[nums] = nid;
2729 src = nid;
2730 for (;;) {
2731 int n;
2732 type = get_wcaps_type(get_wcaps(codec, src));
2733 if (type == AC_WID_PIN)
2734 break;
2735 if (type == AC_WID_AUD_SEL) {
2736 cap_nids[nums] = src;
2737 break;
2738 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002739 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002740 if (n > 1) {
2741 cap_nids[nums] = src;
2742 break;
2743 } else if (n != 1)
2744 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002745 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2746 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002747 }
2748 if (++nums >= max_nums)
2749 break;
2750 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002751 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002752 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002753 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002754 return nums;
2755}
2756
Takashi Iwai05f5f472009-08-25 13:10:18 +02002757/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002758static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759{
2760 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002761 const struct auto_pin_cfg *cfg = &spec->autocfg;
2762 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002763 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002764 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002765 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002766 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002767
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002768 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002769 if (num_adcs < 0)
2770 return 0;
2771
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002772 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002773 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002774 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002775
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002776 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002777 if (!alc_is_input_pin(codec, pin))
2778 continue;
2779
David Henningsson5322bf22011-01-05 11:03:56 +01002780 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002781 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2782 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002783 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002784 type_idx++;
2785 else
2786 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002787 prev_label = label;
2788
Takashi Iwai05f5f472009-08-25 13:10:18 +02002789 if (mixer) {
2790 idx = get_connection_index(codec, mixer, pin);
2791 if (idx >= 0) {
2792 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002793 label, type_idx,
2794 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002795 if (err < 0)
2796 return err;
2797 }
2798 }
2799
Takashi Iwaib7821702011-07-06 15:12:46 +02002800 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002801 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002802 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002803 if (idx >= 0) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002804 err = new_capture_source(codec, c, pin, idx, label);
2805 if (err < 0)
2806 return err;
Takashi Iwaib7821702011-07-06 15:12:46 +02002807 break;
2808 }
2809 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002810 }
Takashi Iwai21268962011-07-07 15:01:13 +02002811
2812 spec->num_mux_defs = 1;
2813 spec->input_mux = imux;
2814
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002815 return 0;
2816}
2817
Takashi Iwai24de1832011-11-07 17:13:39 +01002818/* create a shared input with the headphone out */
2819static int alc_auto_create_shared_input(struct hda_codec *codec)
2820{
2821 struct alc_spec *spec = codec->spec;
2822 struct auto_pin_cfg *cfg = &spec->autocfg;
2823 unsigned int defcfg;
2824 hda_nid_t nid;
2825
2826 /* only one internal input pin? */
2827 if (cfg->num_inputs != 1)
2828 return 0;
2829 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2830 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2831 return 0;
2832
2833 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2834 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2835 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2836 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2837 else
2838 return 0; /* both not available */
2839
2840 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2841 return 0; /* no input */
2842
2843 cfg->inputs[1].pin = nid;
2844 cfg->inputs[1].type = AUTO_PIN_MIC;
2845 cfg->num_inputs = 2;
2846 spec->shared_mic_hp = 1;
2847 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2848 return 0;
2849}
2850
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002851static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2852 unsigned int pin_type)
2853{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002854 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002855 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002856 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2857 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002858 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002859}
2860
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002861static int get_pin_type(int line_out_type)
2862{
2863 if (line_out_type == AUTO_PIN_HP_OUT)
2864 return PIN_HP;
2865 else
2866 return PIN_OUT;
2867}
2868
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002869static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002870{
2871 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002872 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002873 int i;
2874
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002875 for (i = 0; i < cfg->num_inputs; i++) {
2876 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002877 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002878 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002879 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002880 snd_hda_codec_write(codec, nid, 0,
2881 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002882 AMP_OUT_MUTE);
2883 }
2884 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002885
2886 /* mute all loopback inputs */
2887 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002888 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002889 for (i = 0; i < nums; i++)
2890 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2891 AC_VERB_SET_AMP_GAIN_MUTE,
2892 AMP_IN_MUTE(i));
2893 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002894}
2895
Takashi Iwai185d99f2012-02-16 18:39:45 +01002896static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2897{
2898 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002899 int i;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002900
2901 for (i = 0; i < spec->out_path.used; i++) {
2902 struct nid_path *path = snd_array_elem(&spec->out_path, i);
2903 if (path->path[0] == nid)
Takashi Iwai276dd702012-02-17 16:17:03 +01002904 return true;
2905 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002906 return false;
2907}
2908
Takashi Iwai07b18f62011-11-10 15:42:54 +01002909/* check whether the DAC is reachable from the pin */
2910static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2911 hda_nid_t pin, hda_nid_t dac)
2912{
Takashi Iwaidc31b582012-02-17 17:27:53 +01002913 if (!pin || !dac)
2914 return false;
Takashi Iwai6a84c302012-12-05 14:08:45 +01002915 return snd_hda_get_conn_index(codec, pin, dac, true) >= 0;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002916}
2917
Takashi Iwai463419d2012-12-05 14:17:37 +01002918/* look for an empty DAC slot */
2919static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2920{
2921 struct alc_spec *spec = codec->spec;
2922 int i;
2923
2924 for (i = 0; i < spec->num_all_dacs; i++) {
2925 hda_nid_t nid = spec->all_dacs[i];
2926 if (!nid || alc_is_dac_already_used(codec, nid))
2927 continue;
2928 if (alc_auto_is_dac_reachable(codec, pin, nid))
2929 return nid;
2930 }
2931 return 0;
2932}
2933
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002934/* called recursively */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002935static bool __parse_nid_path(struct hda_codec *codec,
2936 hda_nid_t from_nid, hda_nid_t to_nid,
2937 int with_aa_mix, struct nid_path *path, int depth)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002938{
2939 struct alc_spec *spec = codec->spec;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002940 hda_nid_t conn[16];
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002941 int i, nums;
2942
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002943 if (to_nid == spec->mixer_nid) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002944 if (!with_aa_mix)
2945 return false;
2946 with_aa_mix = 2; /* mark aa-mix is included */
2947 }
2948
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002949 nums = snd_hda_get_connections(codec, to_nid, conn, ARRAY_SIZE(conn));
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002950 for (i = 0; i < nums; i++) {
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002951 if (conn[i] != from_nid) {
2952 /* special case: when from_nid is 0,
2953 * try to find an empty DAC
2954 */
2955 if (from_nid ||
2956 get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT ||
2957 alc_is_dac_already_used(codec, conn[i]))
2958 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002959 }
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002960 /* aa-mix is requested but not included? */
2961 if (!(spec->mixer_nid && with_aa_mix == 1))
2962 goto found;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002963 }
2964 if (depth >= MAX_NID_PATH_DEPTH)
2965 return false;
2966 for (i = 0; i < nums; i++) {
2967 unsigned int type;
2968 type = get_wcaps_type(get_wcaps(codec, conn[i]));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002969 if (type == AC_WID_AUD_OUT || type == AC_WID_AUD_IN ||
2970 type == AC_WID_PIN)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002971 continue;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002972 if (__parse_nid_path(codec, from_nid, conn[i],
2973 with_aa_mix, path, depth + 1))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002974 goto found;
2975 }
2976 return false;
2977
2978 found:
2979 path->path[path->depth] = conn[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01002980 path->idx[path->depth + 1] = i;
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002981 if (nums > 1 && get_wcaps_type(get_wcaps(codec, to_nid)) != AC_WID_AUD_MIX)
Takashi Iwai95e960c2012-12-10 17:27:57 +01002982 path->multi[path->depth + 1] = 1;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002983 path->depth++;
2984 return true;
2985}
2986
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002987/* parse the widget path from the given nid to the target nid;
2988 * when @from_nid is 0, try to find an empty DAC;
2989 * when @with_aa_mix is 0, paths with spec->mixer_nid are excluded.
2990 * when @with_aa_mix is 1, paths without spec->mixer_nid are excluded.
2991 * when @with_aa_mix is 2, no special handling about spec->mixer_nid.
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002992 */
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002993static bool parse_nid_path(struct hda_codec *codec, hda_nid_t from_nid,
2994 hda_nid_t to_nid, int with_aa_mix,
2995 struct nid_path *path)
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002996{
Takashi Iwai36f0fd52012-12-12 17:25:00 +01002997 if (__parse_nid_path(codec, from_nid, to_nid, with_aa_mix, path, 1)) {
2998 path->path[path->depth] = to_nid;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01002999 path->depth++;
3000#if 0
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003001 snd_printdd("path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003002 path->depth, path->path[0], path->path[1],
3003 path->path[2], path->path[3], path->path[4]);
3004#endif
3005 return true;
3006 }
3007 return false;
3008}
3009
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003010static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3011{
Takashi Iwai140547e2012-02-16 17:23:46 +01003012 struct alc_spec *spec = codec->spec;
Takashi Iwai463419d2012-12-05 14:17:37 +01003013 int i;
3014 hda_nid_t nid_found = 0;
3015
3016 for (i = 0; i < spec->num_all_dacs; i++) {
3017 hda_nid_t nid = spec->all_dacs[i];
3018 if (!nid || alc_is_dac_already_used(codec, nid))
Takashi Iwai185d99f2012-02-16 18:39:45 +01003019 continue;
Takashi Iwai463419d2012-12-05 14:17:37 +01003020 if (alc_auto_is_dac_reachable(codec, pin, nid)) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003021 if (nid_found)
3022 return 0;
3023 nid_found = nid;
3024 }
3025 }
3026 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003027}
3028
Takashi Iwaiba8111272012-12-06 18:06:23 +01003029static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003030{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003031 struct alc_spec *spec = codec->spec;
3032 int i;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003033
Takashi Iwaiba8111272012-12-06 18:06:23 +01003034 for (i = 0; i < spec->out_path.used; i++) {
3035 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3036 if (path->ctls[type] == val)
3037 return true;
3038 }
3039 return false;
3040}
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003041
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003042/* badness definition */
3043enum {
3044 /* No primary DAC is found for the main output */
3045 BAD_NO_PRIMARY_DAC = 0x10000,
3046 /* No DAC is found for the extra output */
3047 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003048 /* No possible multi-ios */
3049 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003050 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003051 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003052 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003053 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003054 /* Primary DAC shared with main surrounds */
3055 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003056 /* Primary DAC shared with main CLFE */
3057 BAD_SHARED_CLFE = 0x10,
3058 /* Primary DAC shared with extra surrounds */
3059 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003060 /* Volume widget is shared */
3061 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003062};
3063
3064static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003065 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003066static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003067 struct nid_path *path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003068
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003069static bool add_new_out_path(struct hda_codec *codec, hda_nid_t pin,
3070 hda_nid_t dac)
3071{
3072 struct alc_spec *spec = codec->spec;
3073 struct nid_path *path;
3074
3075 path = snd_array_new(&spec->out_path);
3076 if (!path)
3077 return false;
3078 memset(path, 0, sizeof(*path));
Takashi Iwai36f0fd52012-12-12 17:25:00 +01003079 if (parse_nid_path(codec, dac, pin, 0, path))
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003080 return true;
3081 /* push back */
3082 spec->out_path.used--;
3083 return false;
3084}
3085
Takashi Iwaiba8111272012-12-06 18:06:23 +01003086/* get the path pointing from the given dac to pin;
3087 * passing 0 to either @pin or @dac behaves as a wildcard
3088 */
3089static struct nid_path *get_out_path(struct hda_codec *codec, hda_nid_t pin,
3090 hda_nid_t dac)
3091{
3092 struct alc_spec *spec = codec->spec;
3093 int i;
3094
3095 for (i = 0; i < spec->out_path.used; i++) {
3096 struct nid_path *path = snd_array_elem(&spec->out_path, i);
3097 if (path->depth <= 0)
3098 continue;
3099 if ((!dac || path->path[0] == dac) &&
3100 (!pin || path->path[path->depth - 1] == pin))
3101 return path;
3102 }
3103 return NULL;
3104}
3105
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003106/* look for widgets in the path between the given NIDs appropriate for
3107 * volume and mute controls, and assign the values to ctls[].
3108 *
3109 * When no appropriate widget is found in the path, the badness value
3110 * is incremented depending on the situation. The function returns the
3111 * total badness for both volume and mute controls.
3112 */
3113static int assign_out_path_ctls(struct hda_codec *codec, hda_nid_t pin,
3114 hda_nid_t dac)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003115{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003116 struct nid_path *path = get_out_path(codec, pin, dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003117 hda_nid_t nid;
3118 unsigned int val;
3119 int badness = 0;
3120
Takashi Iwaiba8111272012-12-06 18:06:23 +01003121 if (!path)
3122 return BAD_SHARED_VOL * 2;
3123 nid = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003124 if (nid) {
3125 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003126 if (is_ctl_used(codec, val, NID_PATH_VOL_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003127 badness += BAD_SHARED_VOL;
3128 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003129 path->ctls[NID_PATH_VOL_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003130 } else
3131 badness += BAD_SHARED_VOL;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003132 nid = alc_look_for_out_mute_nid(codec, path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003133 if (nid) {
3134 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003135 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT ||
3136 nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003137 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3138 else
3139 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003140 if (is_ctl_used(codec, val, NID_PATH_MUTE_CTL))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003141 badness += BAD_SHARED_VOL;
3142 else
Takashi Iwaiba8111272012-12-06 18:06:23 +01003143 path->ctls[NID_PATH_MUTE_CTL] = val;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003144 } else
3145 badness += BAD_SHARED_VOL;
3146 return badness;
3147}
3148
Takashi Iwaidc31b582012-02-17 17:27:53 +01003149struct badness_table {
3150 int no_primary_dac; /* no primary DAC */
3151 int no_dac; /* no secondary DACs */
3152 int shared_primary; /* primary DAC is shared with main output */
3153 int shared_surr; /* secondary DAC shared with main or primary */
3154 int shared_clfe; /* third DAC shared with main or primary */
3155 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3156};
3157
3158static struct badness_table main_out_badness = {
3159 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3160 .no_dac = BAD_NO_DAC,
3161 .shared_primary = BAD_NO_PRIMARY_DAC,
3162 .shared_surr = BAD_SHARED_SURROUND,
3163 .shared_clfe = BAD_SHARED_CLFE,
3164 .shared_surr_main = BAD_SHARED_SURROUND,
3165};
3166
3167static struct badness_table extra_out_badness = {
3168 .no_primary_dac = BAD_NO_DAC,
3169 .no_dac = BAD_NO_DAC,
3170 .shared_primary = BAD_NO_EXTRA_DAC,
3171 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3172 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3173 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3174};
3175
3176/* try to assign DACs to pins and return the resultant badness */
3177static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3178 const hda_nid_t *pins, hda_nid_t *dacs,
3179 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003180{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003181 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003182 struct auto_pin_cfg *cfg = &spec->autocfg;
3183 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003184 int badness = 0;
3185 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003186
Takashi Iwai185d99f2012-02-16 18:39:45 +01003187 if (!num_outs)
3188 return 0;
3189
Takashi Iwaidc31b582012-02-17 17:27:53 +01003190 for (i = 0; i < num_outs; i++) {
3191 hda_nid_t pin = pins[i];
3192 if (!dacs[i])
3193 dacs[i] = alc_auto_look_for_dac(codec, pin);
3194 if (!dacs[i] && !i) {
3195 for (j = 1; j < num_outs; j++) {
3196 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3197 dacs[0] = dacs[j];
3198 dacs[j] = 0;
3199 break;
3200 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003201 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003202 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003203 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003204 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003205 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003206 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003207 else if (cfg->line_outs > i &&
3208 alc_auto_is_dac_reachable(codec, pin,
3209 spec->private_dac_nids[i]))
3210 dac = spec->private_dac_nids[i];
3211 if (dac) {
3212 if (!i)
3213 badness += bad->shared_primary;
3214 else if (i == 1)
3215 badness += bad->shared_surr;
3216 else
3217 badness += bad->shared_clfe;
3218 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003219 spec->private_dac_nids[0])) {
3220 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003221 badness += bad->shared_surr_main;
3222 } else if (!i)
3223 badness += bad->no_primary_dac;
3224 else
3225 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003226 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003227 if (!add_new_out_path(codec, pin, dac))
3228 dac = dacs[i] = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003229 if (dac)
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003230 badness += assign_out_path_ctls(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003231 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003232
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003233 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003234}
3235
3236static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003237 hda_nid_t reference_pin,
3238 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003239
Takashi Iwai185d99f2012-02-16 18:39:45 +01003240static bool alc_map_singles(struct hda_codec *codec, int outs,
3241 const hda_nid_t *pins, hda_nid_t *dacs)
3242{
3243 int i;
3244 bool found = false;
3245 for (i = 0; i < outs; i++) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003246 hda_nid_t dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003247 if (dacs[i])
3248 continue;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003249 dac = get_dac_if_single(codec, pins[i]);
3250 if (!dac)
3251 continue;
3252 if (add_new_out_path(codec, pins[i], dac)) {
3253 dacs[i] = dac;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003254 found = true;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003255 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003256 }
3257 return found;
3258}
3259
Takashi Iwai7085ec12009-10-02 09:03:58 +02003260/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003261static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003262 bool fill_hardwired,
3263 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003264{
3265 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003266 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003267 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003268
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003269 /* set num_dacs once to full for alc_auto_look_for_dac() */
3270 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003271 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003272 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3273 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3274 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003275 spec->multi_ios = 0;
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01003276 snd_array_free(&spec->out_path);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003277 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003278
3279 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003280 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003281 bool mapped;
3282 do {
3283 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003284 cfg->line_out_pins,
3285 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003286 mapped |= alc_map_singles(codec, cfg->hp_outs,
3287 cfg->hp_pins,
3288 spec->multiout.hp_out_nid);
3289 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3290 cfg->speaker_pins,
3291 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003292 if (fill_mio_first && cfg->line_outs == 1 &&
3293 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3294 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3295 if (!err)
3296 mapped = true;
3297 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003298 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003299 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003300
Takashi Iwaidc31b582012-02-17 17:27:53 +01003301 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3302 spec->private_dac_nids,
3303 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003304
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003305 /* re-count num_dacs and squash invalid entries */
3306 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003307 for (i = 0; i < cfg->line_outs; i++) {
3308 if (spec->private_dac_nids[i])
3309 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003310 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003311 memmove(spec->private_dac_nids + i,
3312 spec->private_dac_nids + i + 1,
3313 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003314 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3315 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003316 }
3317
Takashi Iwai276dd702012-02-17 16:17:03 +01003318 if (fill_mio_first &&
3319 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003320 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003321 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003322 if (err < 0)
3323 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003324 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003325 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003326
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003327 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003328 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3329 spec->multiout.hp_out_nid,
3330 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003331 if (err < 0)
3332 return err;
3333 badness += err;
3334 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003335 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003336 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3337 cfg->speaker_pins,
3338 spec->multiout.extra_out_nid,
3339 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003340 if (err < 0)
3341 return err;
3342 badness += err;
3343 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003344 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3345 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003346 if (err < 0)
3347 return err;
3348 badness += err;
3349 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003350 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3351 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003352 int offset = 0;
3353 if (cfg->line_outs >= 3)
3354 offset = 1;
3355 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3356 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003357 if (err < 0)
3358 return err;
3359 badness += err;
3360 }
3361
3362 if (spec->multi_ios == 2) {
3363 for (i = 0; i < 2; i++)
3364 spec->private_dac_nids[spec->multiout.num_dacs++] =
3365 spec->multi_io[i].dac;
3366 spec->ext_channel_count = 2;
3367 } else if (spec->multi_ios) {
3368 spec->multi_ios = 0;
3369 badness += BAD_MULTI_IO;
3370 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003371
3372 return badness;
3373}
3374
3375#define DEBUG_BADNESS
3376
3377#ifdef DEBUG_BADNESS
3378#define debug_badness snd_printdd
3379#else
3380#define debug_badness(...)
3381#endif
3382
3383static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3384{
3385 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3386 cfg->line_out_pins[0], cfg->line_out_pins[1],
3387 cfg->line_out_pins[2], cfg->line_out_pins[2],
3388 spec->multiout.dac_nids[0],
3389 spec->multiout.dac_nids[1],
3390 spec->multiout.dac_nids[2],
3391 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003392 if (spec->multi_ios > 0)
3393 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3394 spec->multi_ios,
3395 spec->multi_io[0].pin, spec->multi_io[1].pin,
3396 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003397 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3398 cfg->hp_pins[0], cfg->hp_pins[1],
3399 cfg->hp_pins[2], cfg->hp_pins[2],
3400 spec->multiout.hp_out_nid[0],
3401 spec->multiout.hp_out_nid[1],
3402 spec->multiout.hp_out_nid[2],
3403 spec->multiout.hp_out_nid[3]);
3404 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3405 cfg->speaker_pins[0], cfg->speaker_pins[1],
3406 cfg->speaker_pins[2], cfg->speaker_pins[3],
3407 spec->multiout.extra_out_nid[0],
3408 spec->multiout.extra_out_nid[1],
3409 spec->multiout.extra_out_nid[2],
3410 spec->multiout.extra_out_nid[3]);
3411}
3412
Takashi Iwai463419d2012-12-05 14:17:37 +01003413/* find all available DACs of the codec */
3414static void alc_fill_all_nids(struct hda_codec *codec)
3415{
3416 struct alc_spec *spec = codec->spec;
3417 int i;
3418 hda_nid_t nid = codec->start_nid;
3419
3420 spec->num_all_dacs = 0;
3421 memset(spec->all_dacs, 0, sizeof(spec->all_dacs));
3422 for (i = 0; i < codec->num_nodes; i++, nid++) {
3423 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_OUT)
3424 continue;
3425 if (spec->num_all_dacs >= ARRAY_SIZE(spec->all_dacs)) {
3426 snd_printk(KERN_ERR "hda: Too many DACs!\n");
3427 break;
3428 }
3429 spec->all_dacs[spec->num_all_dacs++] = nid;
3430 }
3431}
3432
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003433static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3434{
3435 struct alc_spec *spec = codec->spec;
3436 struct auto_pin_cfg *cfg = &spec->autocfg;
3437 struct auto_pin_cfg *best_cfg;
3438 int best_badness = INT_MAX;
3439 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003440 bool fill_hardwired = true, fill_mio_first = true;
3441 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003442 bool hp_spk_swapped = false;
3443
Takashi Iwai463419d2012-12-05 14:17:37 +01003444 alc_fill_all_nids(codec);
3445
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003446 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3447 if (!best_cfg)
3448 return -ENOMEM;
3449 *best_cfg = *cfg;
3450
3451 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003452 badness = fill_and_eval_dacs(codec, fill_hardwired,
3453 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003454 if (badness < 0) {
3455 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003456 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003457 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003458 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3459 cfg->line_out_type, fill_hardwired, fill_mio_first,
3460 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003461 debug_show_configs(spec, cfg);
3462 if (badness < best_badness) {
3463 best_badness = badness;
3464 *best_cfg = *cfg;
3465 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003466 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003467 }
3468 if (!badness)
3469 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003470 fill_mio_first = !fill_mio_first;
3471 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003472 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003473 fill_hardwired = !fill_hardwired;
3474 if (!fill_hardwired)
3475 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003476 if (hp_spk_swapped)
3477 break;
3478 hp_spk_swapped = true;
3479 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003480 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3481 cfg->hp_outs = cfg->line_outs;
3482 memcpy(cfg->hp_pins, cfg->line_out_pins,
3483 sizeof(cfg->hp_pins));
3484 cfg->line_outs = cfg->speaker_outs;
3485 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3486 sizeof(cfg->speaker_pins));
3487 cfg->speaker_outs = 0;
3488 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3489 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003490 fill_hardwired = true;
3491 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003492 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003493 if (cfg->hp_outs > 0 &&
3494 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3495 cfg->speaker_outs = cfg->line_outs;
3496 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3497 sizeof(cfg->speaker_pins));
3498 cfg->line_outs = cfg->hp_outs;
3499 memcpy(cfg->line_out_pins, cfg->hp_pins,
3500 sizeof(cfg->hp_pins));
3501 cfg->hp_outs = 0;
3502 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3503 cfg->line_out_type = AUTO_PIN_HP_OUT;
3504 fill_hardwired = true;
3505 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003506 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003507 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003508 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003509
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003510 if (badness) {
3511 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003512 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003513 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003514 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3515 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003516 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003517
Takashi Iwaiba8111272012-12-06 18:06:23 +01003518 if (cfg->line_out_pins[0]) {
3519 struct nid_path *path = get_out_path(codec,
3520 cfg->line_out_pins[0],
3521 spec->multiout.dac_nids[0]);
3522 if (path)
3523 spec->vmaster_nid = alc_look_for_out_vol_nid(codec, path);
3524 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003525
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003526 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003527 return 0;
3528}
3529
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003530/* replace the channels in the composed amp value with the given number */
3531static unsigned int amp_val_replace_channels(unsigned int val, unsigned int chs)
3532{
3533 val &= ~(0x3U << 16);
3534 val |= chs << 16;
3535 return val;
3536}
3537
Takashi Iwai343a04b2011-07-06 14:28:39 +02003538static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003539 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003540 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003541 struct nid_path *path)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003542{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003543 unsigned int val;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003544 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003545 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003546 val = path->ctls[NID_PATH_VOL_CTL];
3547 if (!val)
Takashi Iwai527e4d72011-10-27 16:33:27 +02003548 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003549 val = amp_val_replace_channels(val, chs);
3550 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, val);
3551}
3552
3553/* return the channel bits suitable for the given path->ctls[] */
3554static int get_default_ch_nums(struct hda_codec *codec, struct nid_path *path,
3555 int type)
3556{
3557 int chs = 1; /* mono (left only) */
3558 if (path) {
3559 hda_nid_t nid = get_amp_nid_(path->ctls[type]);
3560 if (nid && (get_wcaps(codec, nid) & AC_WCAP_STEREO))
3561 chs = 3; /* stereo */
3562 }
3563 return chs;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003564}
3565
Takashi Iwaie29d3772011-11-14 17:13:23 +01003566static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3567 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003568 struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003569{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003570 int chs = get_default_ch_nums(codec, path, NID_PATH_VOL_CTL);
3571 return alc_auto_add_vol_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003572}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003573
3574/* create a mute-switch for the given mixer widget;
3575 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3576 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003577static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003578 const char *pfx, int cidx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003579 unsigned int chs,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003580 struct nid_path *path)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003581{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003582 unsigned int val;
3583 int type = ALC_CTL_WIDGET_MUTE;
3584
3585 if (!path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003586 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003587 val = path->ctls[NID_PATH_MUTE_CTL];
3588 if (!val)
3589 return 0;
3590 val = amp_val_replace_channels(val, chs);
3591 if (get_amp_direction_(val) == HDA_INPUT) {
3592 hda_nid_t nid = get_amp_nid_(val);
3593 if (snd_hda_get_num_conns(codec, nid) > 1) {
3594 type = ALC_CTL_BIND_MUTE;
3595 val |= 2 << 19; /* FIXME: fixed two widgets, so far */
3596 }
Takashi Iwai97aaab72011-07-06 14:02:55 +02003597 }
3598 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003599}
3600
Takashi Iwaie29d3772011-11-14 17:13:23 +01003601static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003602 int cidx, struct nid_path *path)
Takashi Iwaie29d3772011-11-14 17:13:23 +01003603{
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003604 int chs = get_default_ch_nums(codec, path, NID_PATH_MUTE_CTL);
3605 return alc_auto_add_sw_ctl(codec, pfx, cidx, chs, path);
Takashi Iwaie29d3772011-11-14 17:13:23 +01003606}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003607
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003608static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003609 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003610{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003611 int i;
3612
3613 for (i = path->depth - 1; i >= 0; i--) {
3614 if (nid_has_mute(codec, path->path[i], HDA_OUTPUT))
3615 return path->path[i];
3616 if (i != path->depth - 1 && i != 0 &&
3617 nid_has_mute(codec, path->path[i], HDA_INPUT))
3618 return path->path[i];
3619 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003620 return 0;
3621}
3622
3623static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
Takashi Iwaiba8111272012-12-06 18:06:23 +01003624 struct nid_path *path)
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003625{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003626 int i;
3627
3628 for (i = path->depth - 1; i >= 0; i--) {
3629 if (nid_has_volume(codec, path->path[i], HDA_OUTPUT))
3630 return path->path[i];
3631 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003632 return 0;
3633}
3634
Takashi Iwai7085ec12009-10-02 09:03:58 +02003635/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003636static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003637 const struct auto_pin_cfg *cfg)
3638{
3639 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003640 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003641
Takashi Iwaice764ab2011-04-27 16:35:23 +02003642 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003643 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003644 noutputs += spec->multi_ios;
3645
3646 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003647 const char *name;
3648 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003649 hda_nid_t dac, pin;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003650 struct nid_path *path;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003651
3652 dac = spec->multiout.dac_nids[i];
3653 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003654 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003655 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003656 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003657 index = 0;
3658 name = channel_name[i];
3659 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003660 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003661 name = alc_get_line_out_pfx(spec, i, true, &index);
3662 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003663
Takashi Iwaiba8111272012-12-06 18:06:23 +01003664 path = get_out_path(codec, pin, dac);
3665 if (!path)
3666 continue;
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003667 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003668 /* Center/LFE */
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003669 err = alc_auto_add_vol_ctl(codec, "Center", 0, 1, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003670 if (err < 0)
3671 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003672 err = alc_auto_add_vol_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003673 if (err < 0)
3674 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003675 err = alc_auto_add_sw_ctl(codec, "Center", 0, 1, 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_sw_ctl(codec, "LFE", 0, 2, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003679 if (err < 0)
3680 return err;
3681 } else {
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003682 err = alc_auto_add_stereo_vol(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003683 if (err < 0)
3684 return err;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003685 err = alc_auto_add_stereo_sw(codec, name, index, path);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003686 if (err < 0)
3687 return err;
3688 }
3689 }
3690 return 0;
3691}
3692
Takashi Iwai343a04b2011-07-06 14:28:39 +02003693static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003694 hda_nid_t dac, const char *pfx,
3695 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003696{
Takashi Iwaiba8111272012-12-06 18:06:23 +01003697 struct nid_path *path;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003698 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003699
Takashi Iwaiba8111272012-12-06 18:06:23 +01003700 path = get_out_path(codec, pin, dac);
3701 if (!path)
3702 return 0;
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003703 /* bind volume control will be created in the case of dac = 0 */
3704 if (dac) {
3705 err = alc_auto_add_stereo_vol(codec, pfx, cidx, path);
3706 if (err < 0)
3707 return err;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003708 }
Takashi Iwai792cf2f2012-12-10 16:04:30 +01003709 err = alc_auto_add_stereo_sw(codec, pfx, cidx, path);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003710 if (err < 0)
3711 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003712 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003713}
3714
Takashi Iwai23c09b02011-08-19 09:05:35 +02003715static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3716 unsigned int nums,
3717 struct hda_ctl_ops *ops)
3718{
3719 struct alc_spec *spec = codec->spec;
3720 struct hda_bind_ctls **ctlp, *ctl;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003721 ctlp = snd_array_new(&spec->bind_ctls);
3722 if (!ctlp)
3723 return NULL;
3724 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3725 *ctlp = ctl;
3726 if (ctl)
3727 ctl->ops = ops;
3728 return ctl;
3729}
3730
3731/* add playback controls for speaker and HP outputs */
3732static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3733 const hda_nid_t *pins,
3734 const hda_nid_t *dacs,
3735 const char *pfx)
3736{
3737 struct alc_spec *spec = codec->spec;
3738 struct hda_bind_ctls *ctl;
3739 char name[32];
3740 int i, n, err;
3741
3742 if (!num_pins || !pins[0])
3743 return 0;
3744
Takashi Iwai527e4d72011-10-27 16:33:27 +02003745 if (num_pins == 1) {
3746 hda_nid_t dac = *dacs;
3747 if (!dac)
3748 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003749 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003750 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003751
Takashi Iwai23c09b02011-08-19 09:05:35 +02003752 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003753 hda_nid_t dac;
3754 if (dacs[num_pins - 1])
3755 dac = dacs[i]; /* with individual volumes */
3756 else
3757 dac = 0;
3758 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3759 err = alc_auto_create_extra_out(codec, pins[i], dac,
3760 "Bass Speaker", 0);
3761 } else if (num_pins >= 3) {
3762 snprintf(name, sizeof(name), "%s %s",
3763 pfx, channel_name[i]);
3764 err = alc_auto_create_extra_out(codec, pins[i], dac,
3765 name, 0);
3766 } else {
3767 err = alc_auto_create_extra_out(codec, pins[i], dac,
3768 pfx, i);
3769 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003770 if (err < 0)
3771 return err;
3772 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003773 if (dacs[num_pins - 1])
3774 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003775
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003776 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003777 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3778 if (!ctl)
3779 return -ENOMEM;
3780 n = 0;
3781 for (i = 0; i < num_pins; i++) {
3782 hda_nid_t vol;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003783 struct nid_path *path;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003784 if (!pins[i] || !dacs[i])
3785 continue;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003786 path = get_out_path(codec, pins[i], dacs[i]);
3787 if (!path)
3788 continue;
3789 vol = alc_look_for_out_vol_nid(codec, path);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003790 if (vol)
3791 ctl->values[n++] =
3792 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3793 }
3794 if (n) {
3795 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3796 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3797 if (err < 0)
3798 return err;
3799 }
3800 return 0;
3801}
3802
Takashi Iwai343a04b2011-07-06 14:28:39 +02003803static int alc_auto_create_hp_out(struct hda_codec *codec)
3804{
3805 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003806 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3807 spec->autocfg.hp_pins,
3808 spec->multiout.hp_out_nid,
3809 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003810}
3811
3812static int alc_auto_create_speaker_out(struct hda_codec *codec)
3813{
3814 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003815 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3816 spec->autocfg.speaker_pins,
3817 spec->multiout.extra_out_nid,
3818 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003819}
3820
Takashi Iwai78e635c2012-12-10 17:07:16 +01003821/* is a volume or mute control already present? */
3822static bool __is_out_ctl_present(struct hda_codec *codec,
3823 struct nid_path *exclude_path,
3824 hda_nid_t nid, int dir, int types)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003825{
Takashi Iwai78e635c2012-12-10 17:07:16 +01003826 struct alc_spec *spec = codec->spec;
3827 int i, type;
3828
3829 for (i = 0; i < spec->out_path.used; i++) {
3830 struct nid_path *p = snd_array_elem(&spec->out_path, i);
3831 if (p == exclude_path || p->depth <= 0)
3832 continue;
3833 for (type = 0; type < 2; type++) {
3834 if (types & (1 << type)) {
3835 unsigned int val = p->ctls[type];
3836 if (get_amp_nid_(val) == nid &&
3837 get_amp_direction_(val) == dir)
3838 return true;
3839 }
3840 }
3841 }
3842 return false;
3843}
3844
3845#define is_out_ctl_present(codec, path, nid, dir) \
3846 __is_out_ctl_present(codec, path, nid, dir, 3) /* check both types */
3847#define is_out_vol_ctl_present(codec, nid, dir) \
3848 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_VOL_CTL)
3849#define is_out_mute_ctl_present(codec, nid, dir) \
3850 __is_out_ctl_present(codec, NULL, nid, dir, 1 << NID_PATH_MUTE_CTL)
3851
3852static int get_default_amp_val(struct hda_codec *codec, hda_nid_t nid, int dir)
3853{
3854 unsigned int caps, offset;
3855 unsigned int val = 0;
3856
3857 caps = query_amp_caps(codec, nid, dir);
3858 if (caps & AC_AMPCAP_NUM_STEPS) {
3859 offset = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
3860 /* if a volume control is assigned, set the lowest level
3861 * as default; otherwise set to 0dB
3862 */
3863 if (is_out_vol_ctl_present(codec, nid, dir))
3864 val = 0;
3865 else
3866 val = offset;
3867 }
3868 if (caps & AC_AMPCAP_MUTE) {
3869 /* if a mute control is assigned, mute as default */
3870 if (is_out_mute_ctl_present(codec, nid, dir))
3871 val |= HDA_AMP_MUTE;
3872 }
3873 return val;
3874}
3875
3876/* configure the path from the given dac to the pin as the proper output */
3877static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
3878 hda_nid_t pin, int pin_type,
3879 hda_nid_t dac, bool force)
3880{
3881 int i, val;
Takashi Iwaiba8111272012-12-06 18:06:23 +01003882 struct nid_path *path;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003883
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003884 alc_set_pin_output(codec, pin, pin_type);
Takashi Iwaiba8111272012-12-06 18:06:23 +01003885 path = get_out_path(codec, pin, dac);
3886 if (!path)
3887 return;
Takashi Iwai43dea222011-11-06 11:25:34 +01003888
Takashi Iwai78e635c2012-12-10 17:07:16 +01003889 for (i = path->depth - 1; i >= 0; i--) {
3890 hda_nid_t nid = path->path[i];
Takashi Iwai95e960c2012-12-10 17:27:57 +01003891 if (path->multi[i])
Takashi Iwai78e635c2012-12-10 17:07:16 +01003892 snd_hda_codec_write(codec, nid, 0,
3893 AC_VERB_SET_CONNECT_SEL,
Takashi Iwai95e960c2012-12-10 17:27:57 +01003894 path->idx[i]);
Takashi Iwai78e635c2012-12-10 17:07:16 +01003895
3896 if (i != 0 && i != path->depth - 1 &&
3897 (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) &&
3898 (force || !is_out_ctl_present(codec, path, nid,
3899 HDA_INPUT))) {
3900 val = get_default_amp_val(codec, nid, HDA_INPUT);
3901 snd_hda_codec_write(codec, nid, 0,
3902 AC_VERB_SET_AMP_GAIN_MUTE,
3903 AMP_IN_UNMUTE(0) | val);
3904 snd_hda_codec_write(codec, nid, 0,
3905 AC_VERB_SET_AMP_GAIN_MUTE,
3906 AMP_IN_UNMUTE(1) | val);
3907 }
3908 if ((get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) &&
3909 (force || !is_out_ctl_present(codec, path, nid,
3910 HDA_OUTPUT))) {
3911 val = get_default_amp_val(codec, nid, HDA_OUTPUT);
3912 snd_hda_codec_write(codec, nid, 0,
3913 AC_VERB_SET_AMP_GAIN_MUTE,
3914 AMP_OUT_UNMUTE | val);
3915 }
3916 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003917}
3918
Takashi Iwai343a04b2011-07-06 14:28:39 +02003919static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003920{
3921 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003922 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003923 int i;
3924
3925 for (i = 0; i <= HDA_SIDE; i++) {
3926 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3927 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003928 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai78e635c2012-12-10 17:07:16 +01003929 spec->multiout.dac_nids[i], true);
3930
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003931 }
3932}
3933
Takashi Iwai343a04b2011-07-06 14:28:39 +02003934static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003935{
3936 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003937 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003938 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003939
David Henningsson636030e2011-10-12 19:26:03 +02003940 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003941 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3942 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003943 pin = spec->autocfg.hp_pins[i];
3944 if (!pin)
3945 break;
3946 dac = spec->multiout.hp_out_nid[i];
3947 if (!dac) {
3948 if (i > 0 && spec->multiout.hp_out_nid[0])
3949 dac = spec->multiout.hp_out_nid[0];
3950 else
3951 dac = spec->multiout.dac_nids[0];
3952 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003953 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003954 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003955 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003956 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3957 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003958 pin = spec->autocfg.speaker_pins[i];
3959 if (!pin)
3960 break;
3961 dac = spec->multiout.extra_out_nid[i];
3962 if (!dac) {
3963 if (i > 0 && spec->multiout.extra_out_nid[0])
3964 dac = spec->multiout.extra_out_nid[0];
3965 else
3966 dac = spec->multiout.dac_nids[0];
3967 }
Takashi Iwai78e635c2012-12-10 17:07:16 +01003968 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac, true);
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003969 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003970}
3971
Takashi Iwai276dd702012-02-17 16:17:03 +01003972/* check whether the given pin can be a multi-io pin */
3973static bool can_be_multiio_pin(struct hda_codec *codec,
3974 unsigned int location, hda_nid_t nid)
3975{
3976 unsigned int defcfg, caps;
3977
3978 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3979 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3980 return false;
3981 if (location && get_defcfg_location(defcfg) != location)
3982 return false;
3983 caps = snd_hda_query_pin_caps(codec, nid);
3984 if (!(caps & AC_PINCAP_OUT))
3985 return false;
3986 return true;
3987}
3988
Takashi Iwaice764ab2011-04-27 16:35:23 +02003989/*
3990 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003991 *
3992 * When hardwired is set, try to fill ony hardwired pins, and returns
3993 * zero if any pins are filled, non-zero if nothing found.
3994 * When hardwired is off, try to fill possible input pins, and returns
3995 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003996 */
3997static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003998 hda_nid_t reference_pin,
3999 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004000{
4001 struct alc_spec *spec = codec->spec;
4002 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01004003 int type, i, j, dacs, num_pins, old_pins;
4004 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
4005 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004006 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004007
Takashi Iwai276dd702012-02-17 16:17:03 +01004008 old_pins = spec->multi_ios;
4009 if (old_pins >= 2)
4010 goto end_fill;
4011
4012 num_pins = 0;
4013 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4014 for (i = 0; i < cfg->num_inputs; i++) {
4015 if (cfg->inputs[i].type != type)
4016 continue;
4017 if (can_be_multiio_pin(codec, location,
4018 cfg->inputs[i].pin))
4019 num_pins++;
4020 }
4021 }
4022 if (num_pins < 2)
4023 goto end_fill;
4024
Takashi Iwai07b18f62011-11-10 15:42:54 +01004025 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004026 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
4027 for (i = 0; i < cfg->num_inputs; i++) {
4028 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01004029 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01004030
Takashi Iwaice764ab2011-04-27 16:35:23 +02004031 if (cfg->inputs[i].type != type)
4032 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004033 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004034 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004035 for (j = 0; j < spec->multi_ios; j++) {
4036 if (nid == spec->multi_io[j].pin)
4037 break;
4038 }
4039 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004040 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01004041
4042 if (offset && offset + spec->multi_ios < dacs) {
4043 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01004044 if (!alc_auto_is_dac_reachable(codec, nid, dac))
4045 dac = 0;
4046 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004047 if (hardwired)
4048 dac = get_dac_if_single(codec, nid);
4049 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01004050 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004051 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01004052 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004053 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004054 }
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004055 if (!add_new_out_path(codec, nid, dac)) {
4056 badness++;
4057 continue;
4058 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004059 spec->multi_io[spec->multi_ios].pin = nid;
4060 spec->multi_io[spec->multi_ios].dac = dac;
4061 spec->multi_ios++;
4062 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004063 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004064 }
4065 }
Takashi Iwai276dd702012-02-17 16:17:03 +01004066 end_fill:
4067 if (badness)
4068 badness = BAD_MULTI_IO;
4069 if (old_pins == spec->multi_ios) {
4070 if (hardwired)
4071 return 1; /* nothing found */
4072 else
4073 return badness; /* no badness if nothing found */
4074 }
4075 if (!hardwired && spec->multi_ios < 2) {
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004076 /* cancel newly assigned paths */
4077 spec->out_path.used -= spec->multi_ios - old_pins;
Takashi Iwai276dd702012-02-17 16:17:03 +01004078 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004079 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02004080 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01004081
Takashi Iwai792cf2f2012-12-10 16:04:30 +01004082 /* assign volume and mute controls */
4083 for (i = old_pins; i < spec->multi_ios; i++)
4084 badness += assign_out_path_ctls(codec, spec->multi_io[i].pin,
4085 spec->multi_io[i].dac);
4086
4087 return badness;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004088}
4089
4090static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
4091 struct snd_ctl_elem_info *uinfo)
4092{
4093 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4094 struct alc_spec *spec = codec->spec;
4095
4096 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4097 uinfo->count = 1;
4098 uinfo->value.enumerated.items = spec->multi_ios + 1;
4099 if (uinfo->value.enumerated.item > spec->multi_ios)
4100 uinfo->value.enumerated.item = spec->multi_ios;
4101 sprintf(uinfo->value.enumerated.name, "%dch",
4102 (uinfo->value.enumerated.item + 1) * 2);
4103 return 0;
4104}
4105
4106static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4107 struct snd_ctl_elem_value *ucontrol)
4108{
4109 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4110 struct alc_spec *spec = codec->spec;
4111 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4112 return 0;
4113}
4114
4115static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4116{
4117 struct alc_spec *spec = codec->spec;
4118 hda_nid_t nid = spec->multi_io[idx].pin;
4119
4120 if (!spec->multi_io[idx].ctl_in)
4121 spec->multi_io[idx].ctl_in =
4122 snd_hda_codec_read(codec, nid, 0,
4123 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4124 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004125 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004126 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4127 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4128 HDA_AMP_MUTE, 0);
Takashi Iwai78e635c2012-12-10 17:07:16 +01004129 alc_auto_set_output_and_unmute(codec, nid, PIN_OUT,
4130 spec->multi_io[idx].dac, false);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004131 } else {
4132 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4133 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4134 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004135 snd_hda_set_pin_ctl_cache(codec, nid,
4136 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02004137 }
4138 return 0;
4139}
4140
4141static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4142 struct snd_ctl_elem_value *ucontrol)
4143{
4144 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4145 struct alc_spec *spec = codec->spec;
4146 int i, ch;
4147
4148 ch = ucontrol->value.enumerated.item[0];
4149 if (ch < 0 || ch > spec->multi_ios)
4150 return -EINVAL;
4151 if (ch == (spec->ext_channel_count - 1) / 2)
4152 return 0;
4153 spec->ext_channel_count = (ch + 1) * 2;
4154 for (i = 0; i < spec->multi_ios; i++)
4155 alc_set_multi_io(codec, i, i < ch);
Takashi Iwaib6adb572012-12-03 10:30:58 +01004156 spec->multiout.max_channels = max(spec->ext_channel_count,
4157 spec->const_channel_count);
4158 if (spec->need_dac_fix)
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004159 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004160 return 1;
4161}
4162
Takashi Iwaia9111322011-05-02 11:30:18 +02004163static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004164 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4165 .name = "Channel Mode",
4166 .info = alc_auto_ch_mode_info,
4167 .get = alc_auto_ch_mode_get,
4168 .put = alc_auto_ch_mode_put,
4169};
4170
Takashi Iwai23c09b02011-08-19 09:05:35 +02004171static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004172{
4173 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004174
Takashi Iwaic2674682011-08-24 17:57:44 +02004175 if (spec->multi_ios > 0) {
Takashi Iwai668d1e92012-11-29 14:10:17 +01004176 if (!alc_kcontrol_new(spec, "Channel Mode",
4177 &alc_auto_channel_mode_enum))
Takashi Iwaice764ab2011-04-27 16:35:23 +02004178 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004179 }
4180 return 0;
4181}
4182
Takashi Iwai1d045db2011-07-07 18:23:21 +02004183/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4184 * active input pins
4185 */
4186static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4187{
4188 struct alc_spec *spec = codec->spec;
4189 const struct hda_input_mux *imux;
4190 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4191 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4192 int i, n, nums;
4193
4194 imux = spec->input_mux;
4195 if (!imux)
4196 return;
4197 if (spec->dyn_adc_switch)
4198 return;
4199
Takashi Iwai26acaf02012-03-22 14:36:50 +01004200 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004201 nums = 0;
4202 for (n = 0; n < spec->num_adc_nids; n++) {
4203 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004204 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004205 for (i = 0; i < imux->num_items; i++) {
4206 hda_nid_t pin = spec->imux_pins[i];
4207 if (pin) {
4208 if (get_connection_index(codec, cap, pin) < 0)
4209 break;
4210 } else if (num_conns <= imux->items[i].index)
4211 break;
4212 }
4213 if (i >= imux->num_items) {
4214 adc_nids[nums] = spec->private_adc_nids[n];
4215 capsrc_nids[nums++] = cap;
4216 }
4217 }
4218 if (!nums) {
4219 /* check whether ADC-switch is possible */
4220 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004221 if (spec->shared_mic_hp) {
4222 spec->shared_mic_hp = 0;
4223 spec->private_imux[0].num_items = 1;
4224 goto again;
4225 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004226 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4227 " using fallback 0x%x\n",
4228 codec->chip_name, spec->private_adc_nids[0]);
4229 spec->num_adc_nids = 1;
4230 spec->auto_mic = 0;
4231 return;
4232 }
4233 } else if (nums != spec->num_adc_nids) {
4234 memcpy(spec->private_adc_nids, adc_nids,
4235 nums * sizeof(hda_nid_t));
4236 memcpy(spec->private_capsrc_nids, capsrc_nids,
4237 nums * sizeof(hda_nid_t));
4238 spec->num_adc_nids = nums;
4239 }
4240
4241 if (spec->auto_mic)
4242 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004243 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004244 spec->num_adc_nids = 1; /* reduce to a single ADC */
4245}
4246
4247/*
4248 * initialize ADC paths
4249 */
4250static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4251{
4252 struct alc_spec *spec = codec->spec;
4253 hda_nid_t nid;
4254
4255 nid = spec->adc_nids[adc_idx];
4256 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004257 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004258 snd_hda_codec_write(codec, nid, 0,
4259 AC_VERB_SET_AMP_GAIN_MUTE,
4260 AMP_IN_MUTE(0));
4261 return;
4262 }
4263 if (!spec->capsrc_nids)
4264 return;
4265 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004266 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004267 snd_hda_codec_write(codec, nid, 0,
4268 AC_VERB_SET_AMP_GAIN_MUTE,
4269 AMP_OUT_MUTE);
4270}
4271
4272static void alc_auto_init_input_src(struct hda_codec *codec)
4273{
4274 struct alc_spec *spec = codec->spec;
4275 int c, nums;
4276
4277 for (c = 0; c < spec->num_adc_nids; c++)
4278 alc_auto_init_adc(codec, c);
4279 if (spec->dyn_adc_switch)
4280 nums = 1;
4281 else
4282 nums = spec->num_adc_nids;
4283 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004284 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004285}
4286
4287/* add mic boosts if needed */
4288static int alc_auto_add_mic_boost(struct hda_codec *codec)
4289{
4290 struct alc_spec *spec = codec->spec;
4291 struct auto_pin_cfg *cfg = &spec->autocfg;
4292 int i, err;
4293 int type_idx = 0;
4294 hda_nid_t nid;
4295 const char *prev_label = NULL;
4296
4297 for (i = 0; i < cfg->num_inputs; i++) {
4298 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4299 break;
4300 nid = cfg->inputs[i].pin;
4301 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4302 const char *label;
4303 char boost_label[32];
4304
4305 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004306 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4307 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004308 if (prev_label && !strcmp(label, prev_label))
4309 type_idx++;
4310 else
4311 type_idx = 0;
4312 prev_label = label;
4313
4314 snprintf(boost_label, sizeof(boost_label),
4315 "%s Boost Volume", label);
4316 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4317 boost_label, type_idx,
4318 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4319 if (err < 0)
4320 return err;
4321 }
4322 }
4323 return 0;
4324}
4325
4326/* select or unmute the given capsrc route */
4327static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4328 int idx)
4329{
4330 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4331 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4332 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004333 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004334 snd_hda_codec_write_cache(codec, cap, 0,
4335 AC_VERB_SET_CONNECT_SEL, idx);
4336 }
4337}
4338
4339/* set the default connection to that pin */
4340static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4341{
4342 struct alc_spec *spec = codec->spec;
4343 int i;
4344
4345 if (!pin)
4346 return 0;
4347 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004348 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004349 int idx;
4350
4351 idx = get_connection_index(codec, cap, pin);
4352 if (idx < 0)
4353 continue;
4354 select_or_unmute_capsrc(codec, cap, idx);
4355 return i; /* return the found index */
4356 }
4357 return -1; /* not found */
4358}
4359
4360/* initialize some special cases for input sources */
4361static void alc_init_special_input_src(struct hda_codec *codec)
4362{
4363 struct alc_spec *spec = codec->spec;
4364 int i;
4365
4366 for (i = 0; i < spec->autocfg.num_inputs; i++)
4367 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4368}
4369
4370/* assign appropriate capture mixers */
4371static void set_capture_mixer(struct hda_codec *codec)
4372{
4373 struct alc_spec *spec = codec->spec;
4374 static const struct snd_kcontrol_new *caps[2][3] = {
4375 { alc_capture_mixer_nosrc1,
4376 alc_capture_mixer_nosrc2,
4377 alc_capture_mixer_nosrc3 },
4378 { alc_capture_mixer1,
4379 alc_capture_mixer2,
4380 alc_capture_mixer3 },
4381 };
4382
4383 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004384 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385 if (!spec->capsrc_nids)
4386 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004387 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004388 return; /* no volume in capsrc, too */
4389 spec->vol_in_capsrc = 1;
4390 }
4391
4392 if (spec->num_adc_nids > 0) {
4393 int mux = 0;
4394 int num_adcs = 0;
4395
4396 if (spec->input_mux && spec->input_mux->num_items > 1)
4397 mux = 1;
4398 if (spec->auto_mic) {
4399 num_adcs = 1;
4400 mux = 0;
4401 } else if (spec->dyn_adc_switch)
4402 num_adcs = 1;
4403 if (!num_adcs) {
4404 if (spec->num_adc_nids > 3)
4405 spec->num_adc_nids = 3;
4406 else if (!spec->num_adc_nids)
4407 return;
4408 num_adcs = spec->num_adc_nids;
4409 }
4410 spec->cap_mixer = caps[mux][num_adcs - 1];
4411 }
4412}
4413
4414/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004415 * standard auto-parser initializations
4416 */
4417static void alc_auto_init_std(struct hda_codec *codec)
4418{
Takashi Iwaie4770622011-07-08 11:11:35 +02004419 alc_auto_init_multi_out(codec);
4420 alc_auto_init_extra_out(codec);
4421 alc_auto_init_analog_input(codec);
4422 alc_auto_init_input_src(codec);
4423 alc_auto_init_digital(codec);
David Henningssona7a0a642012-07-05 12:00:12 +02004424 alc_inithook(codec);
Takashi Iwaie4770622011-07-08 11:11:35 +02004425}
4426
4427/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004428 * Digital-beep handlers
4429 */
4430#ifdef CONFIG_SND_HDA_INPUT_BEEP
4431#define set_beep_amp(spec, nid, idx, dir) \
4432 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4433
4434static const struct snd_pci_quirk beep_white_list[] = {
Duncan Roe71100052012-10-10 14:19:50 +02004435 SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004436 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4437 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4438 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4439 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004440 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004441 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4442 {}
4443};
4444
4445static inline int has_cdefine_beep(struct hda_codec *codec)
4446{
4447 struct alc_spec *spec = codec->spec;
4448 const struct snd_pci_quirk *q;
4449 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4450 if (q)
4451 return q->value;
4452 return spec->cdefine.enable_pcbeep;
4453}
4454#else
4455#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4456#define has_cdefine_beep(codec) 0
4457#endif
4458
4459/* parse the BIOS configuration and set up the alc_spec */
4460/* return 1 if successful, 0 if the proper config is not found,
4461 * or a negative error code
4462 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004463static int alc_parse_auto_config(struct hda_codec *codec,
4464 const hda_nid_t *ignore_nids,
4465 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004466{
4467 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004468 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004469 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004470
Takashi Iwai53c334a2011-08-23 18:27:14 +02004471 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4472 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004473 if (err < 0)
4474 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004475 if (!cfg->line_outs) {
4476 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004477 spec->multiout.max_channels = 2;
4478 spec->no_analog = 1;
4479 goto dig_only;
4480 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004481 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004482 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004483
Takashi Iwaie427c232012-07-29 10:04:08 +02004484 if (!spec->no_primary_hp &&
4485 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
Takashi Iwai06503672011-10-06 08:27:19 +02004486 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004487 /* use HP as primary out */
4488 cfg->speaker_outs = cfg->line_outs;
4489 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4490 sizeof(cfg->speaker_pins));
4491 cfg->line_outs = cfg->hp_outs;
4492 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4493 cfg->hp_outs = 0;
4494 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4495 cfg->line_out_type = AUTO_PIN_HP_OUT;
4496 }
4497
Takashi Iwai1d045db2011-07-07 18:23:21 +02004498 err = alc_auto_fill_dac_nids(codec);
4499 if (err < 0)
4500 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004501 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004502 if (err < 0)
4503 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004504 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004505 if (err < 0)
4506 return err;
4507 err = alc_auto_create_hp_out(codec);
4508 if (err < 0)
4509 return err;
4510 err = alc_auto_create_speaker_out(codec);
4511 if (err < 0)
4512 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004513 err = alc_auto_create_shared_input(codec);
4514 if (err < 0)
4515 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004516 err = alc_auto_create_input_ctls(codec);
4517 if (err < 0)
4518 return err;
4519
Takashi Iwaib6adb572012-12-03 10:30:58 +01004520 /* check the multiple speaker pins */
4521 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
4522 spec->const_channel_count = cfg->line_outs * 2;
4523 else
4524 spec->const_channel_count = cfg->speaker_outs * 2;
4525
4526 if (spec->multi_ios > 0)
4527 spec->multiout.max_channels = max(spec->ext_channel_count,
4528 spec->const_channel_count);
4529 else
4530 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004531
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004532 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004533 alc_auto_parse_digital(codec);
4534
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004535 if (!spec->no_analog)
4536 alc_remove_invalid_adc_nids(codec);
4537
4538 if (ssid_nids)
4539 alc_ssid_check(codec, ssid_nids);
4540
4541 if (!spec->no_analog) {
Takashi Iwai475c3d22012-11-30 08:31:30 +01004542 err = alc_auto_check_switches(codec);
4543 if (err < 0)
4544 return err;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004545 err = alc_auto_add_mic_boost(codec);
4546 if (err < 0)
4547 return err;
4548 }
4549
Takashi Iwai1d045db2011-07-07 18:23:21 +02004550 if (spec->kctls.list)
4551 add_mixer(spec, spec->kctls.list);
4552
Takashi Iwai070cff42012-02-21 12:54:17 +01004553 if (!spec->no_analog && !spec->cap_mixer)
4554 set_capture_mixer(codec);
4555
Takashi Iwai1d045db2011-07-07 18:23:21 +02004556 return 1;
4557}
4558
Takashi Iwai3de95172012-05-07 18:03:15 +02004559/* common preparation job for alc_spec */
4560static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4561{
4562 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4563 int err;
4564
4565 if (!spec)
4566 return -ENOMEM;
4567 codec->spec = spec;
Takashi Iwai1098b7c2012-12-17 20:03:15 +01004568 codec->single_adc_amp = 1;
Takashi Iwai3de95172012-05-07 18:03:15 +02004569 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004570 snd_hda_gen_init(&spec->gen);
Takashi Iwai361dab32012-05-09 14:35:27 +02004571 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
4572 snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
Takashi Iwai30dcd3b2012-12-06 15:45:38 +01004573 snd_array_init(&spec->out_path, sizeof(struct nid_path), 8);
Takashi Iwai36f0fd52012-12-12 17:25:00 +01004574 snd_array_init(&spec->in_path, sizeof(struct nid_path), 8);
Takashi Iwai3de95172012-05-07 18:03:15 +02004575
4576 err = alc_codec_rename_from_preset(codec);
4577 if (err < 0) {
4578 kfree(spec);
4579 return err;
4580 }
4581 return 0;
4582}
4583
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004584static int alc880_parse_auto_config(struct hda_codec *codec)
4585{
4586 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004587 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004588 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4589}
4590
Takashi Iwai1d045db2011-07-07 18:23:21 +02004591/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004592 * ALC880 fix-ups
4593 */
4594enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004595 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004596 ALC880_FIXUP_GPIO2,
4597 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004598 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004599 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004600 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004601 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004602 ALC880_FIXUP_VOL_KNOB,
4603 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004604 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004605 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004606 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004607 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004608 ALC880_FIXUP_3ST_BASE,
4609 ALC880_FIXUP_3ST,
4610 ALC880_FIXUP_3ST_DIG,
4611 ALC880_FIXUP_5ST_BASE,
4612 ALC880_FIXUP_5ST,
4613 ALC880_FIXUP_5ST_DIG,
4614 ALC880_FIXUP_6ST_BASE,
4615 ALC880_FIXUP_6ST,
4616 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004617};
4618
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004619/* enable the volume-knob widget support on NID 0x21 */
4620static void alc880_fixup_vol_knob(struct hda_codec *codec,
4621 const struct alc_fixup *fix, int action)
4622{
4623 if (action == ALC_FIXUP_ACT_PROBE)
David Henningsson29adc4b2012-09-25 11:31:00 +02004624 snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004625}
4626
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004627static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004628 [ALC880_FIXUP_GPIO1] = {
4629 .type = ALC_FIXUP_VERBS,
4630 .v.verbs = alc_gpio1_init_verbs,
4631 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004632 [ALC880_FIXUP_GPIO2] = {
4633 .type = ALC_FIXUP_VERBS,
4634 .v.verbs = alc_gpio2_init_verbs,
4635 },
4636 [ALC880_FIXUP_MEDION_RIM] = {
4637 .type = ALC_FIXUP_VERBS,
4638 .v.verbs = (const struct hda_verb[]) {
4639 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4640 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4641 { }
4642 },
4643 .chained = true,
4644 .chain_id = ALC880_FIXUP_GPIO2,
4645 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004646 [ALC880_FIXUP_LG] = {
4647 .type = ALC_FIXUP_PINS,
4648 .v.pins = (const struct alc_pincfg[]) {
4649 /* disable bogus unused pins */
4650 { 0x16, 0x411111f0 },
4651 { 0x18, 0x411111f0 },
4652 { 0x1a, 0x411111f0 },
4653 { }
4654 }
4655 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004656 [ALC880_FIXUP_W810] = {
4657 .type = ALC_FIXUP_PINS,
4658 .v.pins = (const struct alc_pincfg[]) {
4659 /* disable bogus unused pins */
4660 { 0x17, 0x411111f0 },
4661 { }
4662 },
4663 .chained = true,
4664 .chain_id = ALC880_FIXUP_GPIO2,
4665 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004666 [ALC880_FIXUP_EAPD_COEF] = {
4667 .type = ALC_FIXUP_VERBS,
4668 .v.verbs = (const struct hda_verb[]) {
4669 /* change to EAPD mode */
4670 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4671 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4672 {}
4673 },
4674 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004675 [ALC880_FIXUP_TCL_S700] = {
4676 .type = ALC_FIXUP_VERBS,
4677 .v.verbs = (const struct hda_verb[]) {
4678 /* change to EAPD mode */
4679 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4680 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4681 {}
4682 },
4683 .chained = true,
4684 .chain_id = ALC880_FIXUP_GPIO2,
4685 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004686 [ALC880_FIXUP_VOL_KNOB] = {
4687 .type = ALC_FIXUP_FUNC,
4688 .v.func = alc880_fixup_vol_knob,
4689 },
4690 [ALC880_FIXUP_FUJITSU] = {
4691 /* override all pins as BIOS on old Amilo is broken */
4692 .type = ALC_FIXUP_PINS,
4693 .v.pins = (const struct alc_pincfg[]) {
4694 { 0x14, 0x0121411f }, /* HP */
4695 { 0x15, 0x99030120 }, /* speaker */
4696 { 0x16, 0x99030130 }, /* bass speaker */
4697 { 0x17, 0x411111f0 }, /* N/A */
4698 { 0x18, 0x411111f0 }, /* N/A */
4699 { 0x19, 0x01a19950 }, /* mic-in */
4700 { 0x1a, 0x411111f0 }, /* N/A */
4701 { 0x1b, 0x411111f0 }, /* N/A */
4702 { 0x1c, 0x411111f0 }, /* N/A */
4703 { 0x1d, 0x411111f0 }, /* N/A */
4704 { 0x1e, 0x01454140 }, /* SPDIF out */
4705 { }
4706 },
4707 .chained = true,
4708 .chain_id = ALC880_FIXUP_VOL_KNOB,
4709 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004710 [ALC880_FIXUP_F1734] = {
4711 /* almost compatible with FUJITSU, but no bass and SPDIF */
4712 .type = ALC_FIXUP_PINS,
4713 .v.pins = (const struct alc_pincfg[]) {
4714 { 0x14, 0x0121411f }, /* HP */
4715 { 0x15, 0x99030120 }, /* speaker */
4716 { 0x16, 0x411111f0 }, /* N/A */
4717 { 0x17, 0x411111f0 }, /* N/A */
4718 { 0x18, 0x411111f0 }, /* N/A */
4719 { 0x19, 0x01a19950 }, /* mic-in */
4720 { 0x1a, 0x411111f0 }, /* N/A */
4721 { 0x1b, 0x411111f0 }, /* N/A */
4722 { 0x1c, 0x411111f0 }, /* N/A */
4723 { 0x1d, 0x411111f0 }, /* N/A */
4724 { 0x1e, 0x411111f0 }, /* N/A */
4725 { }
4726 },
4727 .chained = true,
4728 .chain_id = ALC880_FIXUP_VOL_KNOB,
4729 },
Takashi Iwai817de922012-02-20 17:20:48 +01004730 [ALC880_FIXUP_UNIWILL] = {
4731 /* need to fix HP and speaker pins to be parsed correctly */
4732 .type = ALC_FIXUP_PINS,
4733 .v.pins = (const struct alc_pincfg[]) {
4734 { 0x14, 0x0121411f }, /* HP */
4735 { 0x15, 0x99030120 }, /* speaker */
4736 { 0x16, 0x99030130 }, /* bass speaker */
4737 { }
4738 },
4739 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004740 [ALC880_FIXUP_UNIWILL_DIG] = {
4741 .type = ALC_FIXUP_PINS,
4742 .v.pins = (const struct alc_pincfg[]) {
4743 /* disable bogus unused pins */
4744 { 0x17, 0x411111f0 },
4745 { 0x19, 0x411111f0 },
4746 { 0x1b, 0x411111f0 },
4747 { 0x1f, 0x411111f0 },
4748 { }
4749 }
4750 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004751 [ALC880_FIXUP_Z71V] = {
4752 .type = ALC_FIXUP_PINS,
4753 .v.pins = (const struct alc_pincfg[]) {
4754 /* set up the whole pins as BIOS is utterly broken */
4755 { 0x14, 0x99030120 }, /* speaker */
4756 { 0x15, 0x0121411f }, /* HP */
4757 { 0x16, 0x411111f0 }, /* N/A */
4758 { 0x17, 0x411111f0 }, /* N/A */
4759 { 0x18, 0x01a19950 }, /* mic-in */
4760 { 0x19, 0x411111f0 }, /* N/A */
4761 { 0x1a, 0x01813031 }, /* line-in */
4762 { 0x1b, 0x411111f0 }, /* N/A */
4763 { 0x1c, 0x411111f0 }, /* N/A */
4764 { 0x1d, 0x411111f0 }, /* N/A */
4765 { 0x1e, 0x0144111e }, /* SPDIF */
4766 { }
4767 }
4768 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004769 [ALC880_FIXUP_3ST_BASE] = {
4770 .type = ALC_FIXUP_PINS,
4771 .v.pins = (const struct alc_pincfg[]) {
4772 { 0x14, 0x01014010 }, /* line-out */
4773 { 0x15, 0x411111f0 }, /* N/A */
4774 { 0x16, 0x411111f0 }, /* N/A */
4775 { 0x17, 0x411111f0 }, /* N/A */
4776 { 0x18, 0x01a19c30 }, /* mic-in */
4777 { 0x19, 0x0121411f }, /* HP */
4778 { 0x1a, 0x01813031 }, /* line-in */
4779 { 0x1b, 0x02a19c40 }, /* front-mic */
4780 { 0x1c, 0x411111f0 }, /* N/A */
4781 { 0x1d, 0x411111f0 }, /* N/A */
4782 /* 0x1e is filled in below */
4783 { 0x1f, 0x411111f0 }, /* N/A */
4784 { }
4785 }
4786 },
4787 [ALC880_FIXUP_3ST] = {
4788 .type = ALC_FIXUP_PINS,
4789 .v.pins = (const struct alc_pincfg[]) {
4790 { 0x1e, 0x411111f0 }, /* N/A */
4791 { }
4792 },
4793 .chained = true,
4794 .chain_id = ALC880_FIXUP_3ST_BASE,
4795 },
4796 [ALC880_FIXUP_3ST_DIG] = {
4797 .type = ALC_FIXUP_PINS,
4798 .v.pins = (const struct alc_pincfg[]) {
4799 { 0x1e, 0x0144111e }, /* SPDIF */
4800 { }
4801 },
4802 .chained = true,
4803 .chain_id = ALC880_FIXUP_3ST_BASE,
4804 },
4805 [ALC880_FIXUP_5ST_BASE] = {
4806 .type = ALC_FIXUP_PINS,
4807 .v.pins = (const struct alc_pincfg[]) {
4808 { 0x14, 0x01014010 }, /* front */
4809 { 0x15, 0x411111f0 }, /* N/A */
4810 { 0x16, 0x01011411 }, /* CLFE */
4811 { 0x17, 0x01016412 }, /* surr */
4812 { 0x18, 0x01a19c30 }, /* mic-in */
4813 { 0x19, 0x0121411f }, /* HP */
4814 { 0x1a, 0x01813031 }, /* line-in */
4815 { 0x1b, 0x02a19c40 }, /* front-mic */
4816 { 0x1c, 0x411111f0 }, /* N/A */
4817 { 0x1d, 0x411111f0 }, /* N/A */
4818 /* 0x1e is filled in below */
4819 { 0x1f, 0x411111f0 }, /* N/A */
4820 { }
4821 }
4822 },
4823 [ALC880_FIXUP_5ST] = {
4824 .type = ALC_FIXUP_PINS,
4825 .v.pins = (const struct alc_pincfg[]) {
4826 { 0x1e, 0x411111f0 }, /* N/A */
4827 { }
4828 },
4829 .chained = true,
4830 .chain_id = ALC880_FIXUP_5ST_BASE,
4831 },
4832 [ALC880_FIXUP_5ST_DIG] = {
4833 .type = ALC_FIXUP_PINS,
4834 .v.pins = (const struct alc_pincfg[]) {
4835 { 0x1e, 0x0144111e }, /* SPDIF */
4836 { }
4837 },
4838 .chained = true,
4839 .chain_id = ALC880_FIXUP_5ST_BASE,
4840 },
4841 [ALC880_FIXUP_6ST_BASE] = {
4842 .type = ALC_FIXUP_PINS,
4843 .v.pins = (const struct alc_pincfg[]) {
4844 { 0x14, 0x01014010 }, /* front */
4845 { 0x15, 0x01016412 }, /* surr */
4846 { 0x16, 0x01011411 }, /* CLFE */
4847 { 0x17, 0x01012414 }, /* side */
4848 { 0x18, 0x01a19c30 }, /* mic-in */
4849 { 0x19, 0x02a19c40 }, /* front-mic */
4850 { 0x1a, 0x01813031 }, /* line-in */
4851 { 0x1b, 0x0121411f }, /* HP */
4852 { 0x1c, 0x411111f0 }, /* N/A */
4853 { 0x1d, 0x411111f0 }, /* N/A */
4854 /* 0x1e is filled in below */
4855 { 0x1f, 0x411111f0 }, /* N/A */
4856 { }
4857 }
4858 },
4859 [ALC880_FIXUP_6ST] = {
4860 .type = ALC_FIXUP_PINS,
4861 .v.pins = (const struct alc_pincfg[]) {
4862 { 0x1e, 0x411111f0 }, /* N/A */
4863 { }
4864 },
4865 .chained = true,
4866 .chain_id = ALC880_FIXUP_6ST_BASE,
4867 },
4868 [ALC880_FIXUP_6ST_DIG] = {
4869 .type = ALC_FIXUP_PINS,
4870 .v.pins = (const struct alc_pincfg[]) {
4871 { 0x1e, 0x0144111e }, /* SPDIF */
4872 { }
4873 },
4874 .chained = true,
4875 .chain_id = ALC880_FIXUP_6ST_BASE,
4876 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004877};
4878
4879static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004880 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004881 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004882 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4883 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004884 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004885 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004886 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004887 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004888 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004889 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004890 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004891 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004892 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004893 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004894 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004895 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4896 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4897 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004898 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004899
4900 /* Below is the copied entries from alc880_quirks.c.
4901 * It's not quite sure whether BIOS sets the correct pin-config table
4902 * on these machines, thus they are kept to be compatible with
4903 * the old static quirks. Once when it's confirmed to work without
4904 * these overrides, it'd be better to remove.
4905 */
4906 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4907 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4908 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4909 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4910 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4911 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4912 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4913 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4914 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4915 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4916 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4917 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4918 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4919 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4920 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4921 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4922 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4923 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4924 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4925 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4926 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4927 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4928 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4929 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4930 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4931 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4932 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4933 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4934 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4935 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4936 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4937 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4938 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4939 /* default Intel */
4940 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4941 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4942 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4943 {}
4944};
4945
4946static const struct alc_model_fixup alc880_fixup_models[] = {
4947 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4948 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4949 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4950 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4951 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4952 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004953 {}
4954};
4955
4956
4957/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004958 * OK, here we have finally the patch for ALC880
4959 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960static int patch_alc880(struct hda_codec *codec)
4961{
4962 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004963 int err;
4964
Takashi Iwai3de95172012-05-07 18:03:15 +02004965 err = alc_alloc_spec(codec, 0x0b);
4966 if (err < 0)
4967 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004968
Takashi Iwai3de95172012-05-07 18:03:15 +02004969 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004970 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004971
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004972 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4973 alc880_fixups);
4974 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004975
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004976 /* automatic parse from the BIOS config */
4977 err = alc880_parse_auto_config(codec);
4978 if (err < 0)
4979 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004980
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004981 if (!spec->no_analog) {
4982 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004983 if (err < 0)
4984 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004985 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4986 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004987
Takashi Iwai1d045db2011-07-07 18:23:21 +02004988 codec->patch_ops = alc_patch_ops;
David Henningsson29adc4b2012-09-25 11:31:00 +02004989 codec->patch_ops.unsol_event = alc880_unsol_event;
4990
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991
Takashi Iwai589876e2012-02-20 15:47:55 +01004992 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4993
Takashi Iwai1d045db2011-07-07 18:23:21 +02004994 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004995
4996 error:
4997 alc_free(codec);
4998 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004999}
5000
5001
5002/*
5003 * ALC260 support
5004 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005static int alc260_parse_auto_config(struct hda_codec *codec)
5006{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005007 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005008 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
5009 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005010}
5011
Takashi Iwai1d045db2011-07-07 18:23:21 +02005012/*
5013 * Pin config fixes
5014 */
5015enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005016 ALC260_FIXUP_HP_DC5750,
5017 ALC260_FIXUP_HP_PIN_0F,
5018 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01005019 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01005020 ALC260_FIXUP_GPIO1_TOGGLE,
5021 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005022 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005023 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005024};
5025
Takashi Iwai20f7d922012-02-16 12:35:16 +01005026static void alc260_gpio1_automute(struct hda_codec *codec)
5027{
5028 struct alc_spec *spec = codec->spec;
5029 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
5030 spec->hp_jack_present);
5031}
5032
5033static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
5034 const struct alc_fixup *fix, int action)
5035{
5036 struct alc_spec *spec = codec->spec;
5037 if (action == ALC_FIXUP_ACT_PROBE) {
5038 /* although the machine has only one output pin, we need to
5039 * toggle GPIO1 according to the jack state
5040 */
5041 spec->automute_hook = alc260_gpio1_automute;
5042 spec->detect_hp = 1;
5043 spec->automute_speaker = 1;
5044 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
David Henningsson29adc4b2012-09-25 11:31:00 +02005045 snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
5046 alc_hp_automute);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005047 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01005048 }
5049}
5050
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005051static void alc260_fixup_kn1(struct hda_codec *codec,
5052 const struct alc_fixup *fix, int action)
5053{
5054 struct alc_spec *spec = codec->spec;
5055 static const struct alc_pincfg pincfgs[] = {
5056 { 0x0f, 0x02214000 }, /* HP/speaker */
5057 { 0x12, 0x90a60160 }, /* int mic */
5058 { 0x13, 0x02a19000 }, /* ext mic */
5059 { 0x18, 0x01446000 }, /* SPDIF out */
5060 /* disable bogus I/O pins */
5061 { 0x10, 0x411111f0 },
5062 { 0x11, 0x411111f0 },
5063 { 0x14, 0x411111f0 },
5064 { 0x15, 0x411111f0 },
5065 { 0x16, 0x411111f0 },
5066 { 0x17, 0x411111f0 },
5067 { 0x19, 0x411111f0 },
5068 { }
5069 };
5070
5071 switch (action) {
5072 case ALC_FIXUP_ACT_PRE_PROBE:
5073 alc_apply_pincfgs(codec, pincfgs);
5074 break;
5075 case ALC_FIXUP_ACT_PROBE:
5076 spec->init_amp = ALC_INIT_NONE;
5077 break;
5078 }
5079}
5080
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01005082 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005083 .type = ALC_FIXUP_PINS,
5084 .v.pins = (const struct alc_pincfg[]) {
5085 { 0x11, 0x90130110 }, /* speaker */
5086 { }
5087 }
5088 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01005089 [ALC260_FIXUP_HP_PIN_0F] = {
5090 .type = ALC_FIXUP_PINS,
5091 .v.pins = (const struct alc_pincfg[]) {
5092 { 0x0f, 0x01214000 }, /* HP */
5093 { }
5094 }
5095 },
5096 [ALC260_FIXUP_COEF] = {
5097 .type = ALC_FIXUP_VERBS,
5098 .v.verbs = (const struct hda_verb[]) {
5099 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5100 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
5101 { }
5102 },
5103 .chained = true,
5104 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5105 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01005106 [ALC260_FIXUP_GPIO1] = {
5107 .type = ALC_FIXUP_VERBS,
5108 .v.verbs = alc_gpio1_init_verbs,
5109 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01005110 [ALC260_FIXUP_GPIO1_TOGGLE] = {
5111 .type = ALC_FIXUP_FUNC,
5112 .v.func = alc260_fixup_gpio1_toggle,
5113 .chained = true,
5114 .chain_id = ALC260_FIXUP_HP_PIN_0F,
5115 },
5116 [ALC260_FIXUP_REPLACER] = {
5117 .type = ALC_FIXUP_VERBS,
5118 .v.verbs = (const struct hda_verb[]) {
5119 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5120 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5121 { }
5122 },
5123 .chained = true,
5124 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
5125 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005126 [ALC260_FIXUP_HP_B1900] = {
5127 .type = ALC_FIXUP_FUNC,
5128 .v.func = alc260_fixup_gpio1_toggle,
5129 .chained = true,
5130 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005131 },
5132 [ALC260_FIXUP_KN1] = {
5133 .type = ALC_FIXUP_FUNC,
5134 .v.func = alc260_fixup_kn1,
5135 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005136};
5137
5138static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01005139 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005140 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01005141 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005142 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01005143 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01005144 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02005145 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01005146 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01005147 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005148 {}
5149};
5150
5151/*
5152 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005153static int patch_alc260(struct hda_codec *codec)
5154{
5155 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005156 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005157
Takashi Iwai3de95172012-05-07 18:03:15 +02005158 err = alc_alloc_spec(codec, 0x07);
5159 if (err < 0)
5160 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005161
Takashi Iwai3de95172012-05-07 18:03:15 +02005162 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005163
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005164 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5165 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005166
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005167 /* automatic parse from the BIOS config */
5168 err = alc260_parse_auto_config(codec);
5169 if (err < 0)
5170 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005171
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005172 if (!spec->no_analog) {
5173 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005174 if (err < 0)
5175 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005176 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5177 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005178
Takashi Iwai1d045db2011-07-07 18:23:21 +02005179 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005180 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005181
Takashi Iwai589876e2012-02-20 15:47:55 +01005182 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5183
Takashi Iwai1d045db2011-07-07 18:23:21 +02005184 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005185
5186 error:
5187 alc_free(codec);
5188 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005189}
5190
5191
5192/*
5193 * ALC882/883/885/888/889 support
5194 *
5195 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5196 * configuration. Each pin widget can choose any input DACs and a mixer.
5197 * Each ADC is connected from a mixer of all inputs. This makes possible
5198 * 6-channel independent captures.
5199 *
5200 * In addition, an independent DAC for the multi-playback (not used in this
5201 * driver yet).
5202 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005203
5204/*
5205 * Pin config fixes
5206 */
5207enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005208 ALC882_FIXUP_ABIT_AW9D_MAX,
5209 ALC882_FIXUP_LENOVO_Y530,
5210 ALC882_FIXUP_PB_M5210,
5211 ALC882_FIXUP_ACER_ASPIRE_7736,
5212 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005213 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005214 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005215 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005216 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005217 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005218 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005219 ALC882_FIXUP_GPIO1,
5220 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005221 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005222 ALC889_FIXUP_COEF,
5223 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005224 ALC882_FIXUP_ACER_ASPIRE_4930G,
5225 ALC882_FIXUP_ACER_ASPIRE_8930G,
5226 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005227 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005228 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005229 ALC889_FIXUP_MBP_VREF,
5230 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005231 ALC882_FIXUP_INV_DMIC,
Takashi Iwaie427c232012-07-29 10:04:08 +02005232 ALC882_FIXUP_NO_PRIMARY_HP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005233};
5234
Takashi Iwai68ef0562011-11-09 18:24:44 +01005235static void alc889_fixup_coef(struct hda_codec *codec,
5236 const struct alc_fixup *fix, int action)
5237{
5238 if (action != ALC_FIXUP_ACT_INIT)
5239 return;
5240 alc889_coef_init(codec);
5241}
5242
Takashi Iwai56710872011-11-14 17:42:11 +01005243/* toggle speaker-output according to the hp-jack state */
5244static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5245{
5246 unsigned int gpiostate, gpiomask, gpiodir;
5247
5248 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5249 AC_VERB_GET_GPIO_DATA, 0);
5250
5251 if (!muted)
5252 gpiostate |= (1 << pin);
5253 else
5254 gpiostate &= ~(1 << pin);
5255
5256 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5257 AC_VERB_GET_GPIO_MASK, 0);
5258 gpiomask |= (1 << pin);
5259
5260 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5261 AC_VERB_GET_GPIO_DIRECTION, 0);
5262 gpiodir |= (1 << pin);
5263
5264
5265 snd_hda_codec_write(codec, codec->afg, 0,
5266 AC_VERB_SET_GPIO_MASK, gpiomask);
5267 snd_hda_codec_write(codec, codec->afg, 0,
5268 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5269
5270 msleep(1);
5271
5272 snd_hda_codec_write(codec, codec->afg, 0,
5273 AC_VERB_SET_GPIO_DATA, gpiostate);
5274}
5275
5276/* set up GPIO at initialization */
5277static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5278 const struct alc_fixup *fix, int action)
5279{
5280 if (action != ALC_FIXUP_ACT_INIT)
5281 return;
5282 alc882_gpio_mute(codec, 0, 0);
5283 alc882_gpio_mute(codec, 1, 0);
5284}
5285
Takashi Iwai02a237b2012-02-13 15:25:07 +01005286/* Fix the connection of some pins for ALC889:
5287 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5288 * work correctly (bko#42740)
5289 */
5290static void alc889_fixup_dac_route(struct hda_codec *codec,
5291 const struct alc_fixup *fix, int action)
5292{
5293 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005294 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005295 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5296 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5297 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5298 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5299 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5300 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005301 } else if (action == ALC_FIXUP_ACT_PROBE) {
5302 /* restore the connections */
5303 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5304 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5305 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5306 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5307 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005308 }
5309}
5310
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005311/* Set VREF on HP pin */
5312static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5313 const struct alc_fixup *fix, int action)
5314{
5315 struct alc_spec *spec = codec->spec;
5316 static hda_nid_t nids[2] = { 0x14, 0x15 };
5317 int i;
5318
5319 if (action != ALC_FIXUP_ACT_INIT)
5320 return;
5321 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5322 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5323 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5324 continue;
5325 val = snd_hda_codec_read(codec, nids[i], 0,
5326 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5327 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005328 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005329 spec->keep_vref_in_automute = 1;
5330 break;
5331 }
5332}
5333
5334/* Set VREF on speaker pins on imac91 */
5335static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5336 const struct alc_fixup *fix, int action)
5337{
5338 struct alc_spec *spec = codec->spec;
5339 static hda_nid_t nids[2] = { 0x18, 0x1a };
5340 int i;
5341
5342 if (action != ALC_FIXUP_ACT_INIT)
5343 return;
5344 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5345 unsigned int val;
5346 val = snd_hda_codec_read(codec, nids[i], 0,
5347 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5348 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005349 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005350 }
5351 spec->keep_vref_in_automute = 1;
5352}
5353
Takashi Iwaie427c232012-07-29 10:04:08 +02005354/* Don't take HP output as primary
5355 * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
5356 */
5357static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
5358 const struct alc_fixup *fix, int action)
5359{
5360 struct alc_spec *spec = codec->spec;
5361 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5362 spec->no_primary_hp = 1;
5363}
5364
Takashi Iwai1d045db2011-07-07 18:23:21 +02005365static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005366 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005367 .type = ALC_FIXUP_PINS,
5368 .v.pins = (const struct alc_pincfg[]) {
5369 { 0x15, 0x01080104 }, /* side */
5370 { 0x16, 0x01011012 }, /* rear */
5371 { 0x17, 0x01016011 }, /* clfe */
5372 { }
5373 }
5374 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005375 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005376 .type = ALC_FIXUP_PINS,
5377 .v.pins = (const struct alc_pincfg[]) {
5378 { 0x15, 0x99130112 }, /* rear int speakers */
5379 { 0x16, 0x99130111 }, /* subwoofer */
5380 { }
5381 }
5382 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005383 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005384 .type = ALC_FIXUP_VERBS,
5385 .v.verbs = (const struct hda_verb[]) {
5386 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5387 {}
5388 }
5389 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005390 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005391 .type = ALC_FIXUP_FUNC,
5392 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005393 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005394 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005395 .type = ALC_FIXUP_PINS,
5396 .v.pins = (const struct alc_pincfg[]) {
5397 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5398 { }
5399 }
5400 },
Marton Balint8f239212012-03-05 21:33:23 +01005401 [ALC889_FIXUP_CD] = {
5402 .type = ALC_FIXUP_PINS,
5403 .v.pins = (const struct alc_pincfg[]) {
5404 { 0x1c, 0x993301f0 }, /* CD */
5405 { }
5406 }
5407 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005408 [ALC889_FIXUP_VAIO_TT] = {
5409 .type = ALC_FIXUP_PINS,
5410 .v.pins = (const struct alc_pincfg[]) {
5411 { 0x17, 0x90170111 }, /* hidden surround speaker */
5412 { }
5413 }
5414 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005415 [ALC888_FIXUP_EEE1601] = {
5416 .type = ALC_FIXUP_VERBS,
5417 .v.verbs = (const struct hda_verb[]) {
5418 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5419 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5420 { }
5421 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005422 },
5423 [ALC882_FIXUP_EAPD] = {
5424 .type = ALC_FIXUP_VERBS,
5425 .v.verbs = (const struct hda_verb[]) {
5426 /* change to EAPD mode */
5427 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5428 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5429 { }
5430 }
5431 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005432 [ALC883_FIXUP_EAPD] = {
5433 .type = ALC_FIXUP_VERBS,
5434 .v.verbs = (const struct hda_verb[]) {
5435 /* change to EAPD mode */
5436 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5437 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5438 { }
5439 }
5440 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005441 [ALC883_FIXUP_ACER_EAPD] = {
5442 .type = ALC_FIXUP_VERBS,
5443 .v.verbs = (const struct hda_verb[]) {
5444 /* eanable EAPD on Acer laptops */
5445 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5446 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5447 { }
5448 }
5449 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005450 [ALC882_FIXUP_GPIO1] = {
5451 .type = ALC_FIXUP_VERBS,
5452 .v.verbs = alc_gpio1_init_verbs,
5453 },
5454 [ALC882_FIXUP_GPIO2] = {
5455 .type = ALC_FIXUP_VERBS,
5456 .v.verbs = alc_gpio2_init_verbs,
5457 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005458 [ALC882_FIXUP_GPIO3] = {
5459 .type = ALC_FIXUP_VERBS,
5460 .v.verbs = alc_gpio3_init_verbs,
5461 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005462 [ALC882_FIXUP_ASUS_W2JC] = {
5463 .type = ALC_FIXUP_VERBS,
5464 .v.verbs = alc_gpio1_init_verbs,
5465 .chained = true,
5466 .chain_id = ALC882_FIXUP_EAPD,
5467 },
5468 [ALC889_FIXUP_COEF] = {
5469 .type = ALC_FIXUP_FUNC,
5470 .v.func = alc889_fixup_coef,
5471 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005472 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5473 .type = ALC_FIXUP_PINS,
5474 .v.pins = (const struct alc_pincfg[]) {
5475 { 0x16, 0x99130111 }, /* CLFE speaker */
5476 { 0x17, 0x99130112 }, /* surround speaker */
5477 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005478 },
5479 .chained = true,
5480 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005481 },
5482 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5483 .type = ALC_FIXUP_PINS,
5484 .v.pins = (const struct alc_pincfg[]) {
5485 { 0x16, 0x99130111 }, /* CLFE speaker */
5486 { 0x1b, 0x99130112 }, /* surround speaker */
5487 { }
5488 },
5489 .chained = true,
5490 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5491 },
5492 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5493 /* additional init verbs for Acer Aspire 8930G */
5494 .type = ALC_FIXUP_VERBS,
5495 .v.verbs = (const struct hda_verb[]) {
5496 /* Enable all DACs */
5497 /* DAC DISABLE/MUTE 1? */
5498 /* setting bits 1-5 disables DAC nids 0x02-0x06
5499 * apparently. Init=0x38 */
5500 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5501 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5502 /* DAC DISABLE/MUTE 2? */
5503 /* some bit here disables the other DACs.
5504 * Init=0x4900 */
5505 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5506 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5507 /* DMIC fix
5508 * This laptop has a stereo digital microphone.
5509 * The mics are only 1cm apart which makes the stereo
5510 * useless. However, either the mic or the ALC889
5511 * makes the signal become a difference/sum signal
5512 * instead of standard stereo, which is annoying.
5513 * So instead we flip this bit which makes the
5514 * codec replicate the sum signal to both channels,
5515 * turning it into a normal mono mic.
5516 */
5517 /* DMIC_CONTROL? Init value = 0x0001 */
5518 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5519 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5520 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5521 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5522 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005523 },
5524 .chained = true,
5525 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005526 },
Takashi Iwai56710872011-11-14 17:42:11 +01005527 [ALC885_FIXUP_MACPRO_GPIO] = {
5528 .type = ALC_FIXUP_FUNC,
5529 .v.func = alc885_fixup_macpro_gpio,
5530 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005531 [ALC889_FIXUP_DAC_ROUTE] = {
5532 .type = ALC_FIXUP_FUNC,
5533 .v.func = alc889_fixup_dac_route,
5534 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005535 [ALC889_FIXUP_MBP_VREF] = {
5536 .type = ALC_FIXUP_FUNC,
5537 .v.func = alc889_fixup_mbp_vref,
5538 .chained = true,
5539 .chain_id = ALC882_FIXUP_GPIO1,
5540 },
5541 [ALC889_FIXUP_IMAC91_VREF] = {
5542 .type = ALC_FIXUP_FUNC,
5543 .v.func = alc889_fixup_imac91_vref,
5544 .chained = true,
5545 .chain_id = ALC882_FIXUP_GPIO1,
5546 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005547 [ALC882_FIXUP_INV_DMIC] = {
5548 .type = ALC_FIXUP_FUNC,
5549 .v.func = alc_fixup_inv_dmic_0x12,
5550 },
Takashi Iwaie427c232012-07-29 10:04:08 +02005551 [ALC882_FIXUP_NO_PRIMARY_HP] = {
5552 .type = ALC_FIXUP_FUNC,
5553 .v.func = alc882_fixup_no_primary_hp,
5554 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005555};
5556
5557static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005558 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5559 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5560 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5561 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5562 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5563 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005564 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5565 ALC882_FIXUP_ACER_ASPIRE_4930G),
5566 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5567 ALC882_FIXUP_ACER_ASPIRE_4930G),
5568 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5569 ALC882_FIXUP_ACER_ASPIRE_8930G),
5570 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5571 ALC882_FIXUP_ACER_ASPIRE_8930G),
5572 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5573 ALC882_FIXUP_ACER_ASPIRE_4930G),
5574 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5575 ALC882_FIXUP_ACER_ASPIRE_4930G),
5576 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5577 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005578 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005579 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5580 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005581 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005582 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005583 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005584 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005585 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005586 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005587 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005588 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwaie427c232012-07-29 10:04:08 +02005589 SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
Takashi Iwai56710872011-11-14 17:42:11 +01005590
5591 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005592 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5593 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5594 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005595 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5596 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5597 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005598 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5599 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005600 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005601 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5602 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5603 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5604 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005605 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005606 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5607 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5608 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005609 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai05193632012-11-12 10:07:36 +01005610 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005611 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5612 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5613 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005614
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005615 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005616 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005617 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005618 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005619 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005620 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5621 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005622 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005623 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005624 {}
5625};
5626
Takashi Iwai912093b2012-04-11 14:03:41 +02005627static const struct alc_model_fixup alc882_fixup_models[] = {
5628 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5629 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5630 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005631 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaie427c232012-07-29 10:04:08 +02005632 {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005633 {}
5634};
5635
Takashi Iwai1d045db2011-07-07 18:23:21 +02005636/*
5637 * BIOS auto configuration
5638 */
5639/* almost identical with ALC880 parser... */
5640static int alc882_parse_auto_config(struct hda_codec *codec)
5641{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005642 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005643 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5644 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645}
5646
Takashi Iwai1d045db2011-07-07 18:23:21 +02005647/*
5648 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649static int patch_alc882(struct hda_codec *codec)
5650{
5651 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005652 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005653
Takashi Iwai3de95172012-05-07 18:03:15 +02005654 err = alc_alloc_spec(codec, 0x0b);
5655 if (err < 0)
5656 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657
Takashi Iwai3de95172012-05-07 18:03:15 +02005658 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005659
5660 switch (codec->vendor_id) {
5661 case 0x10ec0882:
5662 case 0x10ec0885:
5663 break;
5664 default:
5665 /* ALC883 and variants */
5666 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5667 break;
5668 }
5669
Takashi Iwai912093b2012-04-11 14:03:41 +02005670 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5671 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005672 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005673
5674 alc_auto_parse_customize_define(codec);
5675
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005676 /* automatic parse from the BIOS config */
5677 err = alc882_parse_auto_config(codec);
5678 if (err < 0)
5679 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005680
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005681 if (!spec->no_analog && has_cdefine_beep(codec)) {
5682 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005683 if (err < 0)
5684 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005686 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005687
Takashi Iwai1d045db2011-07-07 18:23:21 +02005688 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005689
Takashi Iwai589876e2012-02-20 15:47:55 +01005690 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5691
Takashi Iwai1d045db2011-07-07 18:23:21 +02005692 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005693
5694 error:
5695 alc_free(codec);
5696 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005697}
5698
5699
5700/*
5701 * ALC262 support
5702 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005703static int alc262_parse_auto_config(struct hda_codec *codec)
5704{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005705 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005706 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5707 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005708}
5709
5710/*
5711 * Pin config fixes
5712 */
5713enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005714 ALC262_FIXUP_FSC_H270,
5715 ALC262_FIXUP_HP_Z200,
5716 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005717 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005718 ALC262_FIXUP_BENQ,
5719 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005720 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721};
5722
5723static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005724 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005725 .type = ALC_FIXUP_PINS,
5726 .v.pins = (const struct alc_pincfg[]) {
5727 { 0x14, 0x99130110 }, /* speaker */
5728 { 0x15, 0x0221142f }, /* front HP */
5729 { 0x1b, 0x0121141f }, /* rear HP */
5730 { }
5731 }
5732 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005733 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734 .type = ALC_FIXUP_PINS,
5735 .v.pins = (const struct alc_pincfg[]) {
5736 { 0x16, 0x99130120 }, /* internal speaker */
5737 { }
5738 }
5739 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005740 [ALC262_FIXUP_TYAN] = {
5741 .type = ALC_FIXUP_PINS,
5742 .v.pins = (const struct alc_pincfg[]) {
5743 { 0x14, 0x1993e1f0 }, /* int AUX */
5744 { }
5745 }
5746 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005747 [ALC262_FIXUP_LENOVO_3000] = {
5748 .type = ALC_FIXUP_VERBS,
5749 .v.verbs = (const struct hda_verb[]) {
5750 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005751 {}
5752 },
5753 .chained = true,
5754 .chain_id = ALC262_FIXUP_BENQ,
5755 },
5756 [ALC262_FIXUP_BENQ] = {
5757 .type = ALC_FIXUP_VERBS,
5758 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005759 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5760 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5761 {}
5762 }
5763 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005764 [ALC262_FIXUP_BENQ_T31] = {
5765 .type = ALC_FIXUP_VERBS,
5766 .v.verbs = (const struct hda_verb[]) {
5767 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5768 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5769 {}
5770 }
5771 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005772 [ALC262_FIXUP_INV_DMIC] = {
5773 .type = ALC_FIXUP_FUNC,
5774 .v.func = alc_fixup_inv_dmic_0x12,
5775 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005776};
5777
5778static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005779 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005780 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5781 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005782 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5783 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005784 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005785 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5786 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787 {}
5788};
5789
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005790static const struct alc_model_fixup alc262_fixup_models[] = {
5791 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5792 {}
5793};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005794
Takashi Iwai1d045db2011-07-07 18:23:21 +02005795/*
5796 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005797static int patch_alc262(struct hda_codec *codec)
5798{
5799 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005800 int err;
5801
Takashi Iwai3de95172012-05-07 18:03:15 +02005802 err = alc_alloc_spec(codec, 0x0b);
5803 if (err < 0)
5804 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005805
Takashi Iwai3de95172012-05-07 18:03:15 +02005806 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005807
5808#if 0
5809 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5810 * under-run
5811 */
5812 {
5813 int tmp;
5814 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5815 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5816 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5817 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5818 }
5819#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005820 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5821
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005822 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5823 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005824 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005825
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005826 alc_auto_parse_customize_define(codec);
5827
Takashi Iwai42399f72011-11-07 17:18:44 +01005828 /* automatic parse from the BIOS config */
5829 err = alc262_parse_auto_config(codec);
5830 if (err < 0)
5831 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005832
Takashi Iwai1d045db2011-07-07 18:23:21 +02005833 if (!spec->no_analog && has_cdefine_beep(codec)) {
5834 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005835 if (err < 0)
5836 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005837 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005838 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005839
Takashi Iwai1d045db2011-07-07 18:23:21 +02005840 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005841 spec->shutup = alc_eapd_shutup;
5842
Takashi Iwai589876e2012-02-20 15:47:55 +01005843 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5844
Takashi Iwai1d045db2011-07-07 18:23:21 +02005845 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005846
5847 error:
5848 alc_free(codec);
5849 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005850}
5851
5852/*
5853 * ALC268
5854 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005855/* bind Beep switches of both NID 0x0f and 0x10 */
5856static const struct hda_bind_ctls alc268_bind_beep_sw = {
5857 .ops = &snd_hda_bind_sw,
5858 .values = {
5859 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5860 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5861 0
5862 },
5863};
5864
5865static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5866 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5867 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5868 { }
5869};
5870
5871/* set PCBEEP vol = 0, mute connections */
5872static const struct hda_verb alc268_beep_init_verbs[] = {
5873 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5874 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5875 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5876 { }
5877};
5878
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005879enum {
5880 ALC268_FIXUP_INV_DMIC,
Takashi Iwaicb766402012-10-20 10:55:21 +02005881 ALC268_FIXUP_HP_EAPD,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005882};
5883
5884static const struct alc_fixup alc268_fixups[] = {
5885 [ALC268_FIXUP_INV_DMIC] = {
5886 .type = ALC_FIXUP_FUNC,
5887 .v.func = alc_fixup_inv_dmic_0x12,
5888 },
Takashi Iwaicb766402012-10-20 10:55:21 +02005889 [ALC268_FIXUP_HP_EAPD] = {
5890 .type = ALC_FIXUP_VERBS,
5891 .v.verbs = (const struct hda_verb[]) {
5892 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
5893 {}
5894 }
5895 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005896};
5897
5898static const struct alc_model_fixup alc268_fixup_models[] = {
5899 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwaicb766402012-10-20 10:55:21 +02005900 {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
5901 {}
5902};
5903
5904static const struct snd_pci_quirk alc268_fixup_tbl[] = {
5905 /* below is codec SSID since multiple Toshiba laptops have the
5906 * same PCI SSID 1179:ff00
5907 */
5908 SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005909 {}
5910};
5911
Takashi Iwai1d045db2011-07-07 18:23:21 +02005912/*
5913 * BIOS auto configuration
5914 */
5915static int alc268_parse_auto_config(struct hda_codec *codec)
5916{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005917 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005918 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005919 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5920 if (err > 0) {
5921 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5922 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005923 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005924 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005925 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005926 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005927}
5928
Takashi Iwai1d045db2011-07-07 18:23:21 +02005929/*
5930 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005931static int patch_alc268(struct hda_codec *codec)
5932{
5933 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005934 int i, has_beep, err;
5935
Takashi Iwai1d045db2011-07-07 18:23:21 +02005936 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005937 err = alc_alloc_spec(codec, 0);
5938 if (err < 0)
5939 return err;
5940
5941 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005942
Takashi Iwaicb766402012-10-20 10:55:21 +02005943 alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005944 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5945
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005946 /* automatic parse from the BIOS config */
5947 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005948 if (err < 0)
5949 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005950
Takashi Iwai1d045db2011-07-07 18:23:21 +02005951 has_beep = 0;
5952 for (i = 0; i < spec->num_mixers; i++) {
5953 if (spec->mixers[i] == alc268_beep_mixer) {
5954 has_beep = 1;
5955 break;
5956 }
5957 }
5958
5959 if (has_beep) {
5960 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005961 if (err < 0)
5962 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005963 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5964 /* override the amp caps for beep generator */
5965 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5966 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5967 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5968 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5969 (0 << AC_AMPCAP_MUTE_SHIFT));
5970 }
5971
Takashi Iwai1d045db2011-07-07 18:23:21 +02005972 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005973 spec->shutup = alc_eapd_shutup;
5974
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005975 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5976
Takashi Iwai1d045db2011-07-07 18:23:21 +02005977 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005978
5979 error:
5980 alc_free(codec);
5981 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005982}
5983
5984/*
5985 * ALC269
5986 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005987static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5988 .substreams = 1,
5989 .channels_min = 2,
5990 .channels_max = 8,
5991 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5992 /* NID is set in alc_build_pcms */
5993 .ops = {
5994 .open = alc_playback_pcm_open,
5995 .prepare = alc_playback_pcm_prepare,
5996 .cleanup = alc_playback_pcm_cleanup
5997 },
5998};
5999
6000static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
6001 .substreams = 1,
6002 .channels_min = 2,
6003 .channels_max = 2,
6004 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
6005 /* NID is set in alc_build_pcms */
6006};
6007
Takashi Iwai1d045db2011-07-07 18:23:21 +02006008/* different alc269-variants */
6009enum {
6010 ALC269_TYPE_ALC269VA,
6011 ALC269_TYPE_ALC269VB,
6012 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02006013 ALC269_TYPE_ALC269VD,
Kailang Yang065380f2013-01-10 10:25:48 +01006014 ALC269_TYPE_ALC280,
6015 ALC269_TYPE_ALC282,
6016 ALC269_TYPE_ALC284,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006017};
6018
6019/*
6020 * BIOS auto configuration
6021 */
6022static int alc269_parse_auto_config(struct hda_codec *codec)
6023{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006024 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006025 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
6026 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6027 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006028 const hda_nid_t *ssids;
6029
6030 switch (spec->codec_variant) {
6031 case ALC269_TYPE_ALC269VA:
6032 case ALC269_TYPE_ALC269VC:
Kailang Yang065380f2013-01-10 10:25:48 +01006033 case ALC269_TYPE_ALC280:
6034 case ALC269_TYPE_ALC284:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006035 ssids = alc269va_ssids;
6036 break;
6037 case ALC269_TYPE_ALC269VB:
6038 case ALC269_TYPE_ALC269VD:
Kailang Yang065380f2013-01-10 10:25:48 +01006039 case ALC269_TYPE_ALC282:
Kailang Yangadcc70b2012-05-25 08:08:38 +02006040 ssids = alc269_ssids;
6041 break;
6042 default:
6043 ssids = alc269_ssids;
6044 break;
6045 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006046
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006047 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006048}
6049
Kailang Yang1387e2d2012-11-08 10:23:18 +01006050static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006051{
6052 int val = alc_read_coef_idx(codec, 0x04);
6053 if (power_up)
6054 val |= 1 << 11;
6055 else
6056 val &= ~(1 << 11);
6057 alc_write_coef_idx(codec, 0x04, val);
6058}
6059
6060static void alc269_shutup(struct hda_codec *codec)
6061{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006062 struct alc_spec *spec = codec->spec;
6063
6064 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
6065 return;
6066
Kailang Yang1387e2d2012-11-08 10:23:18 +01006067 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6068 alc269vb_toggle_power_output(codec, 0);
6069 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
6070 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006071 msleep(150);
6072 }
6073}
6074
Takashi Iwai2a439522011-07-26 09:52:50 +02006075#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006076static int alc269_resume(struct hda_codec *codec)
6077{
Kailang Yangadcc70b2012-05-25 08:08:38 +02006078 struct alc_spec *spec = codec->spec;
6079
Kailang Yang1387e2d2012-11-08 10:23:18 +01006080 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6081 alc269vb_toggle_power_output(codec, 0);
6082 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006083 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006084 msleep(150);
6085 }
6086
6087 codec->patch_ops.init(codec);
6088
Kailang Yang1387e2d2012-11-08 10:23:18 +01006089 if (spec->codec_variant == ALC269_TYPE_ALC269VB)
6090 alc269vb_toggle_power_output(codec, 1);
6091 if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
Kailang Yangadcc70b2012-05-25 08:08:38 +02006092 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006093 msleep(200);
6094 }
6095
Takashi Iwai1d045db2011-07-07 18:23:21 +02006096 snd_hda_codec_resume_amp(codec);
6097 snd_hda_codec_resume_cache(codec);
6098 hda_call_check_power_status(codec, 0x01);
6099 return 0;
6100}
Takashi Iwai2a439522011-07-26 09:52:50 +02006101#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006102
David Henningsson108cc102012-07-20 10:37:25 +02006103static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
6104 const struct alc_fixup *fix, int action)
6105{
6106 struct alc_spec *spec = codec->spec;
6107
6108 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6109 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6110}
6111
Takashi Iwai1d045db2011-07-07 18:23:21 +02006112static void alc269_fixup_hweq(struct hda_codec *codec,
6113 const struct alc_fixup *fix, int action)
6114{
6115 int coef;
6116
6117 if (action != ALC_FIXUP_ACT_INIT)
6118 return;
6119 coef = alc_read_coef_idx(codec, 0x1e);
6120 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
6121}
6122
6123static void alc271_fixup_dmic(struct hda_codec *codec,
6124 const struct alc_fixup *fix, int action)
6125{
6126 static const struct hda_verb verbs[] = {
6127 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
6128 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
6129 {}
6130 };
6131 unsigned int cfg;
6132
6133 if (strcmp(codec->chip_name, "ALC271X"))
6134 return;
6135 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
6136 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
6137 snd_hda_sequence_write(codec, verbs);
6138}
6139
Takashi Iwai017f2a12011-07-09 14:42:25 +02006140static void alc269_fixup_pcm_44k(struct hda_codec *codec,
6141 const struct alc_fixup *fix, int action)
6142{
6143 struct alc_spec *spec = codec->spec;
6144
6145 if (action != ALC_FIXUP_ACT_PROBE)
6146 return;
6147
6148 /* Due to a hardware problem on Lenovo Ideadpad, we need to
6149 * fix the sample rate of analog I/O to 44.1kHz
6150 */
6151 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
6152 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
6153}
6154
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006155static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
6156 const struct alc_fixup *fix, int action)
6157{
6158 int coef;
6159
6160 if (action != ALC_FIXUP_ACT_INIT)
6161 return;
6162 /* The digital-mic unit sends PDM (differential signal) instead of
6163 * the standard PCM, thus you can't record a valid mono stream as is.
6164 * Below is a workaround specific to ALC269 to control the dmic
6165 * signal source as mono.
6166 */
6167 coef = alc_read_coef_idx(codec, 0x07);
6168 alc_write_coef_idx(codec, 0x07, coef | 0x80);
6169}
6170
Takashi Iwai24519912011-08-16 15:08:49 +02006171static void alc269_quanta_automute(struct hda_codec *codec)
6172{
David Henningsson42cf0d02011-09-20 12:04:56 +02006173 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02006174
6175 snd_hda_codec_write(codec, 0x20, 0,
6176 AC_VERB_SET_COEF_INDEX, 0x0c);
6177 snd_hda_codec_write(codec, 0x20, 0,
6178 AC_VERB_SET_PROC_COEF, 0x680);
6179
6180 snd_hda_codec_write(codec, 0x20, 0,
6181 AC_VERB_SET_COEF_INDEX, 0x0c);
6182 snd_hda_codec_write(codec, 0x20, 0,
6183 AC_VERB_SET_PROC_COEF, 0x480);
6184}
6185
6186static void alc269_fixup_quanta_mute(struct hda_codec *codec,
6187 const struct alc_fixup *fix, int action)
6188{
6189 struct alc_spec *spec = codec->spec;
6190 if (action != ALC_FIXUP_ACT_PROBE)
6191 return;
6192 spec->automute_hook = alc269_quanta_automute;
6193}
6194
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006195/* update mute-LED according to the speaker mute state via mic1 VREF pin */
6196static void alc269_fixup_mic1_mute_hook(void *private_data, int enabled)
6197{
6198 struct hda_codec *codec = private_data;
6199 unsigned int pinval = AC_PINCTL_IN_EN + (enabled ?
6200 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_80);
6201 snd_hda_set_pin_ctl_cache(codec, 0x18, pinval);
6202}
6203
6204static void alc269_fixup_mic1_mute(struct hda_codec *codec,
6205 const struct alc_fixup *fix, int action)
6206{
6207 struct alc_spec *spec = codec->spec;
6208 switch (action) {
6209 case ALC_FIXUP_ACT_BUILD:
6210 spec->vmaster_mute.hook = alc269_fixup_mic1_mute_hook;
6211 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
6212 /* fallthru */
6213 case ALC_FIXUP_ACT_INIT:
6214 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
6215 break;
6216 }
6217}
6218
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006219/* update mute-LED according to the speaker mute state via mic2 VREF pin */
6220static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
6221{
6222 struct hda_codec *codec = private_data;
6223 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006224 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006225}
6226
6227static void alc269_fixup_mic2_mute(struct hda_codec *codec,
6228 const struct alc_fixup *fix, int action)
6229{
6230 struct alc_spec *spec = codec->spec;
6231 switch (action) {
6232 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006233 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01006234 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006235 /* fallthru */
6236 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006237 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006238 break;
6239 }
6240}
6241
Dylan Reid08a978d2012-11-18 22:56:40 -08006242static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
6243 const struct alc_fixup *fix,
6244 int action)
6245{
6246 struct alc_spec *spec = codec->spec;
6247
6248 if (action == ALC_FIXUP_ACT_PROBE)
6249 snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
6250 spec->autocfg.hp_pins[0]);
6251}
David Henningsson693b6132012-06-22 19:12:10 +02006252
Takashi Iwai1d045db2011-07-07 18:23:21 +02006253enum {
6254 ALC269_FIXUP_SONY_VAIO,
6255 ALC275_FIXUP_SONY_VAIO_GPIO2,
6256 ALC269_FIXUP_DELL_M101Z,
6257 ALC269_FIXUP_SKU_IGNORE,
6258 ALC269_FIXUP_ASUS_G73JW,
6259 ALC269_FIXUP_LENOVO_EAPD,
6260 ALC275_FIXUP_SONY_HWEQ,
6261 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006262 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006263 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006264 ALC269_FIXUP_QUANTA_MUTE,
6265 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006266 ALC269_FIXUP_AMIC,
6267 ALC269_FIXUP_DMIC,
6268 ALC269VB_FIXUP_AMIC,
6269 ALC269VB_FIXUP_DMIC,
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006270 ALC269_FIXUP_MIC1_MUTE_LED,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006271 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006272 ALC269_FIXUP_INV_DMIC,
David Henningsson108cc102012-07-20 10:37:25 +02006273 ALC269_FIXUP_LENOVO_DOCK,
6274 ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
Dylan Reid08a978d2012-11-18 22:56:40 -08006275 ALC271_FIXUP_AMIC_MIC2,
6276 ALC271_FIXUP_HP_GATE_MIC_JACK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006277};
6278
6279static const struct alc_fixup alc269_fixups[] = {
6280 [ALC269_FIXUP_SONY_VAIO] = {
6281 .type = ALC_FIXUP_VERBS,
6282 .v.verbs = (const struct hda_verb[]) {
6283 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6284 {}
6285 }
6286 },
6287 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6288 .type = ALC_FIXUP_VERBS,
6289 .v.verbs = (const struct hda_verb[]) {
6290 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6291 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6292 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6293 { }
6294 },
6295 .chained = true,
6296 .chain_id = ALC269_FIXUP_SONY_VAIO
6297 },
6298 [ALC269_FIXUP_DELL_M101Z] = {
6299 .type = ALC_FIXUP_VERBS,
6300 .v.verbs = (const struct hda_verb[]) {
6301 /* Enables internal speaker */
6302 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6303 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6304 {}
6305 }
6306 },
6307 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006308 .type = ALC_FIXUP_FUNC,
6309 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006310 },
6311 [ALC269_FIXUP_ASUS_G73JW] = {
6312 .type = ALC_FIXUP_PINS,
6313 .v.pins = (const struct alc_pincfg[]) {
6314 { 0x17, 0x99130111 }, /* subwoofer */
6315 { }
6316 }
6317 },
6318 [ALC269_FIXUP_LENOVO_EAPD] = {
6319 .type = ALC_FIXUP_VERBS,
6320 .v.verbs = (const struct hda_verb[]) {
6321 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6322 {}
6323 }
6324 },
6325 [ALC275_FIXUP_SONY_HWEQ] = {
6326 .type = ALC_FIXUP_FUNC,
6327 .v.func = alc269_fixup_hweq,
6328 .chained = true,
6329 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6330 },
6331 [ALC271_FIXUP_DMIC] = {
6332 .type = ALC_FIXUP_FUNC,
6333 .v.func = alc271_fixup_dmic,
6334 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006335 [ALC269_FIXUP_PCM_44K] = {
6336 .type = ALC_FIXUP_FUNC,
6337 .v.func = alc269_fixup_pcm_44k,
David Henningsson012e7eb2012-08-08 08:43:37 +02006338 .chained = true,
6339 .chain_id = ALC269_FIXUP_QUANTA_MUTE
Takashi Iwai017f2a12011-07-09 14:42:25 +02006340 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006341 [ALC269_FIXUP_STEREO_DMIC] = {
6342 .type = ALC_FIXUP_FUNC,
6343 .v.func = alc269_fixup_stereo_dmic,
6344 },
Takashi Iwai24519912011-08-16 15:08:49 +02006345 [ALC269_FIXUP_QUANTA_MUTE] = {
6346 .type = ALC_FIXUP_FUNC,
6347 .v.func = alc269_fixup_quanta_mute,
6348 },
6349 [ALC269_FIXUP_LIFEBOOK] = {
6350 .type = ALC_FIXUP_PINS,
6351 .v.pins = (const struct alc_pincfg[]) {
6352 { 0x1a, 0x2101103f }, /* dock line-out */
6353 { 0x1b, 0x23a11040 }, /* dock mic-in */
6354 { }
6355 },
6356 .chained = true,
6357 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6358 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006359 [ALC269_FIXUP_AMIC] = {
6360 .type = ALC_FIXUP_PINS,
6361 .v.pins = (const struct alc_pincfg[]) {
6362 { 0x14, 0x99130110 }, /* speaker */
6363 { 0x15, 0x0121401f }, /* HP out */
6364 { 0x18, 0x01a19c20 }, /* mic */
6365 { 0x19, 0x99a3092f }, /* int-mic */
6366 { }
6367 },
6368 },
6369 [ALC269_FIXUP_DMIC] = {
6370 .type = ALC_FIXUP_PINS,
6371 .v.pins = (const struct alc_pincfg[]) {
6372 { 0x12, 0x99a3092f }, /* int-mic */
6373 { 0x14, 0x99130110 }, /* speaker */
6374 { 0x15, 0x0121401f }, /* HP out */
6375 { 0x18, 0x01a19c20 }, /* mic */
6376 { }
6377 },
6378 },
6379 [ALC269VB_FIXUP_AMIC] = {
6380 .type = ALC_FIXUP_PINS,
6381 .v.pins = (const struct alc_pincfg[]) {
6382 { 0x14, 0x99130110 }, /* speaker */
6383 { 0x18, 0x01a19c20 }, /* mic */
6384 { 0x19, 0x99a3092f }, /* int-mic */
6385 { 0x21, 0x0121401f }, /* HP out */
6386 { }
6387 },
6388 },
David Henningsson2267ea92012-01-03 08:45:56 +01006389 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006390 .type = ALC_FIXUP_PINS,
6391 .v.pins = (const struct alc_pincfg[]) {
6392 { 0x12, 0x99a3092f }, /* int-mic */
6393 { 0x14, 0x99130110 }, /* speaker */
6394 { 0x18, 0x01a19c20 }, /* mic */
6395 { 0x21, 0x0121401f }, /* HP out */
6396 { }
6397 },
6398 },
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006399 [ALC269_FIXUP_MIC1_MUTE_LED] = {
6400 .type = ALC_FIXUP_FUNC,
6401 .v.func = alc269_fixup_mic1_mute,
6402 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006403 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6404 .type = ALC_FIXUP_FUNC,
6405 .v.func = alc269_fixup_mic2_mute,
6406 },
David Henningsson693b6132012-06-22 19:12:10 +02006407 [ALC269_FIXUP_INV_DMIC] = {
6408 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006409 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006410 },
David Henningsson108cc102012-07-20 10:37:25 +02006411 [ALC269_FIXUP_LENOVO_DOCK] = {
6412 .type = ALC_FIXUP_PINS,
6413 .v.pins = (const struct alc_pincfg[]) {
6414 { 0x19, 0x23a11040 }, /* dock mic */
6415 { 0x1b, 0x2121103f }, /* dock headphone */
6416 { }
6417 },
6418 .chained = true,
6419 .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
6420 },
6421 [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
6422 .type = ALC_FIXUP_FUNC,
6423 .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
6424 },
Dylan Reid08a978d2012-11-18 22:56:40 -08006425 [ALC271_FIXUP_AMIC_MIC2] = {
6426 .type = ALC_FIXUP_PINS,
6427 .v.pins = (const struct alc_pincfg[]) {
6428 { 0x14, 0x99130110 }, /* speaker */
6429 { 0x19, 0x01a19c20 }, /* mic */
6430 { 0x1b, 0x99a7012f }, /* int-mic */
6431 { 0x21, 0x0121401f }, /* HP out */
6432 { }
6433 },
6434 },
6435 [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
6436 .type = ALC_FIXUP_FUNC,
6437 .v.func = alc271_hp_gate_mic_jack,
6438 .chained = true,
6439 .chain_id = ALC271_FIXUP_AMIC_MIC2,
6440 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006441};
6442
6443static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006444 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6445 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006446 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson6d3cd5d2013-01-07 12:03:47 +01006447 SND_PCI_QUIRK(0x103c, 0x1972, "HP Pavilion 17", ALC269_FIXUP_MIC1_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006448 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Oleksij Rempel148728f2012-09-21 17:44:58 +02006449 SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006450 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006451 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006452 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6453 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6454 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6455 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6456 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006457 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6458 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6459 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6460 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6461 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
Dylan Reid08a978d2012-11-18 22:56:40 -08006462 SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006463 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006464 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006465 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6466 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6467 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6468 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6469 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai707fba32012-08-02 09:04:39 +02006470 SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
Felix Kaechelec8415a42012-08-06 23:02:01 +02006471 SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
Stefán Freyr84f98fd2012-10-19 22:46:00 +02006472 SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
Philipp A. Mohrenweiser4407be62012-08-06 13:14:18 +02006473 SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson108cc102012-07-20 10:37:25 +02006474 SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
David Henningsson012e7eb2012-08-08 08:43:37 +02006475 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006476 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006477
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006478#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006479 /* Below is a quirk table taken from the old code.
6480 * Basically the device should work as is without the fixup table.
6481 * If BIOS doesn't give a proper info, enable the corresponding
6482 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006483 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006484 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6485 ALC269_FIXUP_AMIC),
6486 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006487 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6488 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6489 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6490 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6491 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6492 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6493 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6494 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6495 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6496 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6497 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6498 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6499 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6500 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6501 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6502 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6503 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6504 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6505 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6506 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6507 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6508 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6509 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6510 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6511 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6512 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6513 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6514 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6515 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6516 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6517 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6518 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6519 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6520 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6521 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6522 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6523 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6524 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6525#endif
6526 {}
6527};
6528
6529static const struct alc_model_fixup alc269_fixup_models[] = {
6530 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6531 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006532 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6533 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6534 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
David Henningsson108cc102012-07-20 10:37:25 +02006535 {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006536 {}
6537};
6538
6539
Takashi Iwai546bb672012-03-07 08:37:19 +01006540static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006541{
Kailang Yang526af6e2012-03-07 08:25:20 +01006542 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006543 int val;
6544
Kailang Yang526af6e2012-03-07 08:25:20 +01006545 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006546 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006547
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006548 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006549 alc_write_coef_idx(codec, 0xf, 0x960b);
6550 alc_write_coef_idx(codec, 0xe, 0x8817);
6551 }
6552
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006553 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006554 alc_write_coef_idx(codec, 0xf, 0x960b);
6555 alc_write_coef_idx(codec, 0xe, 0x8814);
6556 }
6557
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006558 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006559 val = alc_read_coef_idx(codec, 0x04);
6560 /* Power up output pin */
6561 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6562 }
6563
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006564 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006565 val = alc_read_coef_idx(codec, 0xd);
6566 if ((val & 0x0c00) >> 10 != 0x1) {
6567 /* Capless ramp up clock control */
6568 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6569 }
6570 val = alc_read_coef_idx(codec, 0x17);
6571 if ((val & 0x01c0) >> 6 != 0x4) {
6572 /* Class D power on reset */
6573 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6574 }
6575 }
6576
6577 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6578 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6579
6580 val = alc_read_coef_idx(codec, 0x4); /* HP */
6581 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006582}
6583
6584/*
6585 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006586static int patch_alc269(struct hda_codec *codec)
6587{
6588 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006589 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006590
Takashi Iwai3de95172012-05-07 18:03:15 +02006591 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006592 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006593 return err;
6594
6595 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006596
Herton Ronaldo Krzesinski9f720bb2012-09-27 10:38:14 -03006597 alc_pick_fixup(codec, alc269_fixup_models,
6598 alc269_fixup_tbl, alc269_fixups);
6599 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6600
6601 alc_auto_parse_customize_define(codec);
6602
Kailang Yang065380f2013-01-10 10:25:48 +01006603 switch (codec->vendor_id) {
6604 case 0x10ec0269:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006605 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006606 switch (alc_get_coef0(codec) & 0x00f0) {
6607 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006608 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006609 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006610 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006611 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006612 break;
6613 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006614 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6615 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006616 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006617 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006618 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006619 case 0x0030:
6620 spec->codec_variant = ALC269_TYPE_ALC269VD;
6621 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006622 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006623 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006624 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006625 if (err < 0)
6626 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006627 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006628 alc269_fill_coef(codec);
Kailang Yang065380f2013-01-10 10:25:48 +01006629 break;
6630
6631 case 0x10ec0280:
6632 case 0x10ec0290:
6633 spec->codec_variant = ALC269_TYPE_ALC280;
6634 break;
6635 case 0x10ec0282:
6636 case 0x10ec0283:
6637 spec->codec_variant = ALC269_TYPE_ALC282;
6638 break;
6639 case 0x10ec0284:
6640 case 0x10ec0292:
6641 spec->codec_variant = ALC269_TYPE_ALC284;
6642 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006643 }
6644
Takashi Iwaia4297b52011-08-23 18:40:12 +02006645 /* automatic parse from the BIOS config */
6646 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006647 if (err < 0)
6648 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006649
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006650 if (!spec->no_analog && has_cdefine_beep(codec)) {
6651 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006652 if (err < 0)
6653 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006654 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006655 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006656
Takashi Iwai1d045db2011-07-07 18:23:21 +02006657 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006658#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006659 codec->patch_ops.resume = alc269_resume;
6660#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006661 spec->shutup = alc269_shutup;
6662
Takashi Iwai589876e2012-02-20 15:47:55 +01006663 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6664
Takashi Iwai1d045db2011-07-07 18:23:21 +02006665 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006666
6667 error:
6668 alc_free(codec);
6669 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006670}
6671
6672/*
6673 * ALC861
6674 */
6675
Takashi Iwai1d045db2011-07-07 18:23:21 +02006676static int alc861_parse_auto_config(struct hda_codec *codec)
6677{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006678 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006679 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6680 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006681}
6682
Takashi Iwai1d045db2011-07-07 18:23:21 +02006683/* Pin config fixes */
6684enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006685 ALC861_FIXUP_FSC_AMILO_PI1505,
6686 ALC861_FIXUP_AMP_VREF_0F,
6687 ALC861_FIXUP_NO_JACK_DETECT,
6688 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006689};
6690
Takashi Iwai31150f22012-01-30 10:54:08 +01006691/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6692static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6693 const struct alc_fixup *fix, int action)
6694{
6695 struct alc_spec *spec = codec->spec;
6696 unsigned int val;
6697
6698 if (action != ALC_FIXUP_ACT_INIT)
6699 return;
6700 val = snd_hda_codec_read(codec, 0x0f, 0,
6701 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6702 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6703 val |= AC_PINCTL_IN_EN;
6704 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006705 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006706 spec->keep_vref_in_automute = 1;
6707}
6708
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006709/* suppress the jack-detection */
6710static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6711 const struct alc_fixup *fix, int action)
6712{
6713 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6714 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006715}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006716
Takashi Iwai1d045db2011-07-07 18:23:21 +02006717static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006718 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006719 .type = ALC_FIXUP_PINS,
6720 .v.pins = (const struct alc_pincfg[]) {
6721 { 0x0b, 0x0221101f }, /* HP */
6722 { 0x0f, 0x90170310 }, /* speaker */
6723 { }
6724 }
6725 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006726 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006727 .type = ALC_FIXUP_FUNC,
6728 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006729 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006730 [ALC861_FIXUP_NO_JACK_DETECT] = {
6731 .type = ALC_FIXUP_FUNC,
6732 .v.func = alc_fixup_no_jack_detect,
6733 },
6734 [ALC861_FIXUP_ASUS_A6RP] = {
6735 .type = ALC_FIXUP_FUNC,
6736 .v.func = alc861_fixup_asus_amp_vref_0f,
6737 .chained = true,
6738 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6739 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006740};
6741
6742static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006743 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6744 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6745 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6746 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6747 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6748 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006749 {}
6750};
6751
6752/*
6753 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006754static int patch_alc861(struct hda_codec *codec)
6755{
6756 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006757 int err;
6758
Takashi Iwai3de95172012-05-07 18:03:15 +02006759 err = alc_alloc_spec(codec, 0x15);
6760 if (err < 0)
6761 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006762
Takashi Iwai3de95172012-05-07 18:03:15 +02006763 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006764
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006765 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6766 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006767
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006768 /* automatic parse from the BIOS config */
6769 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006770 if (err < 0)
6771 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006772
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006773 if (!spec->no_analog) {
6774 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006775 if (err < 0)
6776 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006777 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6778 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006779
Takashi Iwai1d045db2011-07-07 18:23:21 +02006780 codec->patch_ops = alc_patch_ops;
Takashi Iwai83012a72012-08-24 18:38:08 +02006781#ifdef CONFIG_PM
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006782 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006783#endif
6784
Takashi Iwai589876e2012-02-20 15:47:55 +01006785 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6786
Takashi Iwai1d045db2011-07-07 18:23:21 +02006787 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006788
6789 error:
6790 alc_free(codec);
6791 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006792}
6793
6794/*
6795 * ALC861-VD support
6796 *
6797 * Based on ALC882
6798 *
6799 * In addition, an independent DAC
6800 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006801static int alc861vd_parse_auto_config(struct hda_codec *codec)
6802{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006803 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006804 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6805 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006806}
6807
Takashi Iwai1d045db2011-07-07 18:23:21 +02006808enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006809 ALC660VD_FIX_ASUS_GPIO1,
6810 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006811};
6812
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006813/* exclude VREF80 */
6814static void alc861vd_fixup_dallas(struct hda_codec *codec,
6815 const struct alc_fixup *fix, int action)
6816{
6817 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaib78562b2012-12-17 20:06:49 +01006818 snd_hda_override_pin_caps(codec, 0x18, 0x00000734);
6819 snd_hda_override_pin_caps(codec, 0x19, 0x0000073c);
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006820 }
6821}
6822
Takashi Iwai1d045db2011-07-07 18:23:21 +02006823static const struct alc_fixup alc861vd_fixups[] = {
6824 [ALC660VD_FIX_ASUS_GPIO1] = {
6825 .type = ALC_FIXUP_VERBS,
6826 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006827 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006828 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6829 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6830 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6831 { }
6832 }
6833 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006834 [ALC861VD_FIX_DALLAS] = {
6835 .type = ALC_FIXUP_FUNC,
6836 .v.func = alc861vd_fixup_dallas,
6837 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006838};
6839
6840static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006841 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006842 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006843 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006844 {}
6845};
6846
Takashi Iwai1d045db2011-07-07 18:23:21 +02006847/*
6848 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006849static int patch_alc861vd(struct hda_codec *codec)
6850{
6851 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006852 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006853
Takashi Iwai3de95172012-05-07 18:03:15 +02006854 err = alc_alloc_spec(codec, 0x0b);
6855 if (err < 0)
6856 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006857
Takashi Iwai3de95172012-05-07 18:03:15 +02006858 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006859
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006860 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6861 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006862
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006863 /* automatic parse from the BIOS config */
6864 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006865 if (err < 0)
6866 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006867
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006868 if (!spec->no_analog) {
6869 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006870 if (err < 0)
6871 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006872 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6873 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006874
Takashi Iwai1d045db2011-07-07 18:23:21 +02006875 codec->patch_ops = alc_patch_ops;
6876
Takashi Iwai1d045db2011-07-07 18:23:21 +02006877 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006878
Takashi Iwai589876e2012-02-20 15:47:55 +01006879 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6880
Takashi Iwai1d045db2011-07-07 18:23:21 +02006881 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006882
6883 error:
6884 alc_free(codec);
6885 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006886}
6887
6888/*
6889 * ALC662 support
6890 *
6891 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6892 * configuration. Each pin widget can choose any input DACs and a mixer.
6893 * Each ADC is connected from a mixer of all inputs. This makes possible
6894 * 6-channel independent captures.
6895 *
6896 * In addition, an independent DAC for the multi-playback (not used in this
6897 * driver yet).
6898 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006899
6900/*
6901 * BIOS auto configuration
6902 */
6903
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006904static int alc662_parse_auto_config(struct hda_codec *codec)
6905{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006906 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006907 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6908 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6909 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006910
Kailang Yang6227cdc2010-02-25 08:36:52 +01006911 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6912 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006913 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006914 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006915 ssids = alc662_ssids;
6916 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006917}
6918
Todd Broch6be79482010-12-07 16:51:05 -08006919static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006920 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006921{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006922 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006923 return;
Todd Broch6be79482010-12-07 16:51:05 -08006924 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6925 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6926 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6927 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6928 (0 << AC_AMPCAP_MUTE_SHIFT)))
6929 printk(KERN_WARNING
6930 "hda_codec: failed to override amp caps for NID 0x2\n");
6931}
6932
David Henningsson6cb3b702010-09-09 08:51:44 +02006933enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006934 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006935 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006936 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006937 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006938 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006939 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006940 ALC662_FIXUP_ASUS_MODE1,
6941 ALC662_FIXUP_ASUS_MODE2,
6942 ALC662_FIXUP_ASUS_MODE3,
6943 ALC662_FIXUP_ASUS_MODE4,
6944 ALC662_FIXUP_ASUS_MODE5,
6945 ALC662_FIXUP_ASUS_MODE6,
6946 ALC662_FIXUP_ASUS_MODE7,
6947 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006948 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006949 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006950 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006951};
6952
6953static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006954 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006955 .type = ALC_FIXUP_PINS,
6956 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006957 { 0x15, 0x99130112 }, /* subwoofer */
6958 { }
6959 }
6960 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006961 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006962 .type = ALC_FIXUP_PINS,
6963 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006964 { 0x17, 0x99130112 }, /* subwoofer */
6965 { }
6966 }
6967 },
Todd Broch6be79482010-12-07 16:51:05 -08006968 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006969 .type = ALC_FIXUP_FUNC,
6970 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006971 },
6972 [ALC662_FIXUP_CZC_P10T] = {
6973 .type = ALC_FIXUP_VERBS,
6974 .v.verbs = (const struct hda_verb[]) {
6975 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6976 {}
6977 }
6978 },
David Henningsson94024cd2011-04-29 14:10:55 +02006979 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006980 .type = ALC_FIXUP_FUNC,
6981 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006982 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006983 [ALC662_FIXUP_HP_RP5800] = {
6984 .type = ALC_FIXUP_PINS,
6985 .v.pins = (const struct alc_pincfg[]) {
6986 { 0x14, 0x0221201f }, /* HP out */
6987 { }
6988 },
6989 .chained = true,
6990 .chain_id = ALC662_FIXUP_SKU_IGNORE
6991 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006992 [ALC662_FIXUP_ASUS_MODE1] = {
6993 .type = ALC_FIXUP_PINS,
6994 .v.pins = (const struct alc_pincfg[]) {
6995 { 0x14, 0x99130110 }, /* speaker */
6996 { 0x18, 0x01a19c20 }, /* mic */
6997 { 0x19, 0x99a3092f }, /* int-mic */
6998 { 0x21, 0x0121401f }, /* HP out */
6999 { }
7000 },
7001 .chained = true,
7002 .chain_id = ALC662_FIXUP_SKU_IGNORE
7003 },
7004 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007005 .type = ALC_FIXUP_PINS,
7006 .v.pins = (const struct alc_pincfg[]) {
7007 { 0x14, 0x99130110 }, /* speaker */
7008 { 0x18, 0x01a19820 }, /* mic */
7009 { 0x19, 0x99a3092f }, /* int-mic */
7010 { 0x1b, 0x0121401f }, /* HP out */
7011 { }
7012 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02007013 .chained = true,
7014 .chain_id = ALC662_FIXUP_SKU_IGNORE
7015 },
7016 [ALC662_FIXUP_ASUS_MODE3] = {
7017 .type = ALC_FIXUP_PINS,
7018 .v.pins = (const struct alc_pincfg[]) {
7019 { 0x14, 0x99130110 }, /* speaker */
7020 { 0x15, 0x0121441f }, /* HP */
7021 { 0x18, 0x01a19840 }, /* mic */
7022 { 0x19, 0x99a3094f }, /* int-mic */
7023 { 0x21, 0x01211420 }, /* HP2 */
7024 { }
7025 },
7026 .chained = true,
7027 .chain_id = ALC662_FIXUP_SKU_IGNORE
7028 },
7029 [ALC662_FIXUP_ASUS_MODE4] = {
7030 .type = ALC_FIXUP_PINS,
7031 .v.pins = (const struct alc_pincfg[]) {
7032 { 0x14, 0x99130110 }, /* speaker */
7033 { 0x16, 0x99130111 }, /* speaker */
7034 { 0x18, 0x01a19840 }, /* mic */
7035 { 0x19, 0x99a3094f }, /* int-mic */
7036 { 0x21, 0x0121441f }, /* HP */
7037 { }
7038 },
7039 .chained = true,
7040 .chain_id = ALC662_FIXUP_SKU_IGNORE
7041 },
7042 [ALC662_FIXUP_ASUS_MODE5] = {
7043 .type = ALC_FIXUP_PINS,
7044 .v.pins = (const struct alc_pincfg[]) {
7045 { 0x14, 0x99130110 }, /* speaker */
7046 { 0x15, 0x0121441f }, /* HP */
7047 { 0x16, 0x99130111 }, /* speaker */
7048 { 0x18, 0x01a19840 }, /* mic */
7049 { 0x19, 0x99a3094f }, /* int-mic */
7050 { }
7051 },
7052 .chained = true,
7053 .chain_id = ALC662_FIXUP_SKU_IGNORE
7054 },
7055 [ALC662_FIXUP_ASUS_MODE6] = {
7056 .type = ALC_FIXUP_PINS,
7057 .v.pins = (const struct alc_pincfg[]) {
7058 { 0x14, 0x99130110 }, /* speaker */
7059 { 0x15, 0x01211420 }, /* HP2 */
7060 { 0x18, 0x01a19840 }, /* mic */
7061 { 0x19, 0x99a3094f }, /* int-mic */
7062 { 0x1b, 0x0121441f }, /* HP */
7063 { }
7064 },
7065 .chained = true,
7066 .chain_id = ALC662_FIXUP_SKU_IGNORE
7067 },
7068 [ALC662_FIXUP_ASUS_MODE7] = {
7069 .type = ALC_FIXUP_PINS,
7070 .v.pins = (const struct alc_pincfg[]) {
7071 { 0x14, 0x99130110 }, /* speaker */
7072 { 0x17, 0x99130111 }, /* speaker */
7073 { 0x18, 0x01a19840 }, /* mic */
7074 { 0x19, 0x99a3094f }, /* int-mic */
7075 { 0x1b, 0x01214020 }, /* HP */
7076 { 0x21, 0x0121401f }, /* HP */
7077 { }
7078 },
7079 .chained = true,
7080 .chain_id = ALC662_FIXUP_SKU_IGNORE
7081 },
7082 [ALC662_FIXUP_ASUS_MODE8] = {
7083 .type = ALC_FIXUP_PINS,
7084 .v.pins = (const struct alc_pincfg[]) {
7085 { 0x14, 0x99130110 }, /* speaker */
7086 { 0x12, 0x99a30970 }, /* int-mic */
7087 { 0x15, 0x01214020 }, /* HP */
7088 { 0x17, 0x99130111 }, /* speaker */
7089 { 0x18, 0x01a19840 }, /* mic */
7090 { 0x21, 0x0121401f }, /* HP */
7091 { }
7092 },
7093 .chained = true,
7094 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02007095 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01007096 [ALC662_FIXUP_NO_JACK_DETECT] = {
7097 .type = ALC_FIXUP_FUNC,
7098 .v.func = alc_fixup_no_jack_detect,
7099 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02007100 [ALC662_FIXUP_ZOTAC_Z68] = {
7101 .type = ALC_FIXUP_PINS,
7102 .v.pins = (const struct alc_pincfg[]) {
7103 { 0x1b, 0x02214020 }, /* Front HP */
7104 { }
7105 }
7106 },
Takashi Iwai125821a2012-06-22 14:30:29 +02007107 [ALC662_FIXUP_INV_DMIC] = {
7108 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007109 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02007110 },
David Henningsson6cb3b702010-09-09 08:51:44 +02007111};
7112
Takashi Iwaia9111322011-05-02 11:30:18 +02007113static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02007114 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01007115 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02007116 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02007117 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04007118 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02007119 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01007120 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007121 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05007122 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06007123 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02007124 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02007125 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01007126 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02007127
7128#if 0
7129 /* Below is a quirk table taken from the old code.
7130 * Basically the device should work as is without the fixup table.
7131 * If BIOS doesn't give a proper info, enable the corresponding
7132 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02007133 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02007134 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
7135 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
7136 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
7137 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
7138 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7139 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7140 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7141 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
7142 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
7143 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7144 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
7145 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
7146 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
7147 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
7148 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
7149 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7150 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
7151 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
7152 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7153 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7154 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7155 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7156 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
7157 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
7158 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
7159 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7160 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
7161 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
7162 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7163 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
7164 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7165 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7166 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
7167 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
7168 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
7169 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
7170 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
7171 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
7172 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
7173 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
7174 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
7175 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
7176 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7177 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
7178 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
7179 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
7180 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
7181 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
7182 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
7183 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
7184#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02007185 {}
7186};
7187
Todd Broch6be79482010-12-07 16:51:05 -08007188static const struct alc_model_fixup alc662_fixup_models[] = {
7189 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02007190 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
7191 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
7192 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
7193 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
7194 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
7195 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
7196 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
7197 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02007198 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08007199 {}
7200};
David Henningsson6cb3b702010-09-09 08:51:44 +02007201
Kailang Yang8663ff72012-06-29 09:35:52 +02007202static void alc662_fill_coef(struct hda_codec *codec)
7203{
7204 int val, coef;
7205
7206 coef = alc_get_coef0(codec);
7207
7208 switch (codec->vendor_id) {
7209 case 0x10ec0662:
7210 if ((coef & 0x00f0) == 0x0030) {
7211 val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
7212 alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
7213 }
7214 break;
7215 case 0x10ec0272:
7216 case 0x10ec0273:
7217 case 0x10ec0663:
7218 case 0x10ec0665:
7219 case 0x10ec0670:
7220 case 0x10ec0671:
7221 case 0x10ec0672:
7222 val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
7223 alc_write_coef_idx(codec, 0xd, val | (1<<14));
7224 break;
7225 }
7226}
David Henningsson6cb3b702010-09-09 08:51:44 +02007227
Takashi Iwai1d045db2011-07-07 18:23:21 +02007228/*
7229 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007230static int patch_alc662(struct hda_codec *codec)
7231{
7232 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02007233 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007234
Takashi Iwai3de95172012-05-07 18:03:15 +02007235 err = alc_alloc_spec(codec, 0x0b);
7236 if (err < 0)
7237 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007238
Takashi Iwai3de95172012-05-07 18:03:15 +02007239 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007240
Takashi Iwai53c334a2011-08-23 18:27:14 +02007241 /* handle multiple HPs as is */
7242 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
7243
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02007244 alc_fix_pll_init(codec, 0x20, 0x04, 15);
7245
Kailang Yang8663ff72012-06-29 09:35:52 +02007246 spec->init_hook = alc662_fill_coef;
7247 alc662_fill_coef(codec);
7248
Takashi Iwai8e5a0502012-06-21 15:49:33 +02007249 alc_pick_fixup(codec, alc662_fixup_models,
7250 alc662_fixup_tbl, alc662_fixups);
7251 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
7252
7253 alc_auto_parse_customize_define(codec);
7254
Takashi Iwai1bb7e432011-10-17 16:50:59 +02007255 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007256 codec->bus->pci->subsystem_vendor == 0x1025 &&
7257 spec->cdefine.platform_type == 1) {
7258 if (alc_codec_rename(codec, "ALC272X") < 0)
7259 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02007260 }
Kailang Yang274693f2009-12-03 10:07:50 +01007261
Takashi Iwaib9c51062011-08-24 18:08:07 +02007262 /* automatic parse from the BIOS config */
7263 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007264 if (err < 0)
7265 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007266
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007267 if (!spec->no_analog && has_cdefine_beep(codec)) {
7268 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007269 if (err < 0)
7270 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01007271 switch (codec->vendor_id) {
7272 case 0x10ec0662:
7273 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7274 break;
7275 case 0x10ec0272:
7276 case 0x10ec0663:
7277 case 0x10ec0665:
7278 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
7279 break;
7280 case 0x10ec0273:
7281 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
7282 break;
7283 }
Kailang Yangcec27c82010-02-04 14:18:18 +01007284 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01007285
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007286 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02007287 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02007288
Takashi Iwai589876e2012-02-20 15:47:55 +01007289 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
7290
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007291 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007292
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007293 error:
7294 alc_free(codec);
7295 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02007296}
7297
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007298/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007299 * ALC680 support
7300 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007301
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007302static int alc680_parse_auto_config(struct hda_codec *codec)
7303{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02007304 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007305}
7306
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007307/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007308 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007309static int patch_alc680(struct hda_codec *codec)
7310{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007311 int err;
7312
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007313 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02007314 err = alc_alloc_spec(codec, 0);
7315 if (err < 0)
7316 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02007317
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02007318 /* automatic parse from the BIOS config */
7319 err = alc680_parse_auto_config(codec);
7320 if (err < 0) {
7321 alc_free(codec);
7322 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007323 }
7324
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007325 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007326
7327 return 0;
7328}
7329
7330/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07007331 * patch entries
7332 */
Takashi Iwaia9111322011-05-02 11:30:18 +02007333static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007334 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007335 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007336 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007337 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007338 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007339 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007340 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007341 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007342 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007343 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007344 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
David Henningsson4e01ec62012-07-18 07:38:46 +02007345 { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007346 { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
Kailang Yang065380f2013-01-10 10:25:48 +01007347 { .id = 0x10ec0284, .name = "ALC284", .patch = patch_alc269 },
Kailang Yang7ff34ad2012-10-06 17:02:30 +02007348 { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
David Henningssonaf02dde2012-11-21 08:57:58 +01007349 { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007350 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007351 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007352 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7353 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7354 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007355 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007356 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007357 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7358 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007359 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7360 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007361 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007362 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang19a62822012-11-08 10:25:37 +01007363 { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007364 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007365 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007366 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007367 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007368 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007369 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007370 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007371 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007372 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007373 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007374 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007375 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007376 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007377 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007378 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007379 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007380 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Kailang Yang19a62822012-11-08 10:25:37 +01007381 { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007382 {} /* terminator */
7383};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007384
7385MODULE_ALIAS("snd-hda-codec-id:10ec*");
7386
7387MODULE_LICENSE("GPL");
7388MODULE_DESCRIPTION("Realtek HD-audio codec");
7389
7390static struct hda_codec_preset_list realtek_list = {
7391 .preset = snd_hda_preset_realtek,
7392 .owner = THIS_MODULE,
7393};
7394
7395static int __init patch_realtek_init(void)
7396{
7397 return snd_hda_add_codec_preset(&realtek_list);
7398}
7399
7400static void __exit patch_realtek_exit(void)
7401{
7402 snd_hda_delete_codec_preset(&realtek_list);
7403}
7404
7405module_init(patch_realtek_init)
7406module_exit(patch_realtek_exit)